1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_1_EVSGLDISPLAY_H
18 #define ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_1_EVSGLDISPLAY_H
19 
20 #include "GlWrapper.h"
21 
22 #include <android/frameworks/automotive/display/1.0/IAutomotiveDisplayProxyService.h>
23 #include <android/hardware/automotive/evs/1.1/IEvsDisplay.h>
24 #include <ui/GraphicBuffer.h>
25 
26 namespace android {
27 namespace hardware {
28 namespace automotive {
29 namespace evs {
30 namespace V1_1 {
31 namespace implementation {
32 
33 using ::android::hardware::automotive::evs::V1_0::DisplayDesc;
34 using ::android::hardware::automotive::evs::V1_0::DisplayState;
35 using ::android::hardware::automotive::evs::V1_0::EvsResult;
36 using ::android::hardware::automotive::evs::V1_1::IEvsDisplay;
37 using EvsResult = ::android::hardware::automotive::evs::V1_0::EvsResult;
38 using BufferDesc_1_0 = ::android::hardware::automotive::evs::V1_0::BufferDesc;
39 using EvsDisplayState = ::android::hardware::automotive::evs::V1_0::DisplayState;
40 using android::frameworks::automotive::display::V1_0::IAutomotiveDisplayProxyService;
41 
42 class EvsGlDisplay : public IEvsDisplay {
43 public:
44     // Methods from ::android::hardware::automotive::evs::V1_0::IEvsDisplay follow.
45     Return<void> getDisplayInfo(getDisplayInfo_cb _hidl_cb) override;
46     Return<EvsResult> setDisplayState(EvsDisplayState state) override;
47     Return<EvsDisplayState> getDisplayState() override;
48     Return<void> getTargetBuffer(getTargetBuffer_cb _hidl_cb) override;
49     Return<EvsResult> returnTargetBufferForDisplay(const BufferDesc_1_0& buffer) override;
50 
51     // Methods from ::android::hardware::automotive::evs::V1_1::IEvsDisplay follow.
52     Return<void> getDisplayInfo_1_1(getDisplayInfo_1_1_cb _info_cb) override;
53 
54     // Implementation details
55     EvsGlDisplay(sp<IAutomotiveDisplayProxyService> pWindowService, uint64_t displayId);
56     virtual ~EvsGlDisplay() override;
57 
58     void forceShutdown();  // This gets called if another caller "steals" ownership of the display
59 
60 private:
61     DisplayDesc mInfo = {};
62     BufferDesc_1_0 mBuffer = {};  // A graphics buffer into which we'll store images
63 
64     bool mFrameBusy = false;  // A flag telling us our buffer is in use
65     EvsDisplayState mRequestedState = EvsDisplayState::NOT_VISIBLE;
66 
67     GlWrapper mGlWrapper;
68 
69     std::mutex mAccessLock;
70 
71     sp<IAutomotiveDisplayProxyService> mDisplayProxy;
72     uint64_t mDisplayId;
73 };
74 
75 }  // namespace implementation
76 }  // namespace V1_1
77 }  // namespace evs
78 }  // namespace automotive
79 }  // namespace hardware
80 }  // namespace android
81 
82 #endif  // ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_0_EVSGLDISPLAY_H
83