blob: 5f547e0cd6ecabd8ef37aab856257282d4e5f43c
1 | /* |
2 | // Copyright (c) 2014 Intel Corporation |
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 | // This file is modified by Amlogic, Inc. 2017.01.17. |
17 | */ |
18 | |
19 | #ifndef PHYSICAL_DEVICE_H |
20 | #define PHYSICAL_DEVICE_H |
21 | |
22 | #include <utils/KeyedVector.h> |
23 | #include <SoftVsyncObserver.h> |
24 | #include <IDisplayDevice.h> |
25 | #include <HwcLayer.h> |
26 | #include <IComposer.h> |
27 | #include <DisplayHdmi.h> |
28 | #include <systemcontrol/ISystemControlService.h> |
29 | #include <systemcontrol/DisplayMode.h> |
30 | #include <binder/Binder.h> |
31 | #include <binder/IServiceManager.h> |
32 | #include <utils/RefBase.h> |
33 | |
34 | namespace android { |
35 | namespace amlogic { |
36 | |
37 | // class IHdcpControl; |
38 | |
39 | typedef struct hdr_capabilities { |
40 | bool init; |
41 | bool dvSupport; |
42 | bool hdrSupport; |
43 | int maxLuminance; |
44 | int avgLuminance; |
45 | int minLuminance; |
46 | } hdr_capabilities_t; |
47 | |
48 | class DeviceControlFactory { |
49 | public: |
50 | virtual ~DeviceControlFactory(){} |
51 | public: |
52 | // virtual IHdcpControl* createHdcpControl() = 0; |
53 | virtual IComposer* createComposer(IDisplayDevice& disp) = 0; |
54 | }; |
55 | |
56 | class FBContext { |
57 | public: |
58 | FBContext() |
59 | : mStatus(false) |
60 | { |
61 | mFBInfo = new framebuffer_info_t(); |
62 | } |
63 | virtual ~FBContext(){} |
64 | |
65 | virtual framebuffer_info_t* getInfo() { return mFBInfo; } |
66 | virtual bool getStatus() { return mStatus; } |
67 | virtual void setStatus(bool status) { mStatus = status; } |
68 | private: |
69 | framebuffer_info_t *mFBInfo; |
70 | bool mStatus; |
71 | }; |
72 | |
73 | class Hwcomposer; |
74 | class SoftVsyncObserver; |
75 | |
76 | class PhysicalDevice : public IDisplayDevice { |
77 | public: |
78 | PhysicalDevice(hwc2_display_t id, Hwcomposer& hwc, DeviceControlFactory* controlFactory); |
79 | ~PhysicalDevice(); |
80 | |
81 | friend class Hwcomposer; |
82 | friend class HwcLayer; |
83 | |
84 | // Required by HWC2 |
85 | virtual int32_t acceptDisplayChanges(); |
86 | virtual bool createLayer(hwc2_layer_t* outLayer); |
87 | virtual bool destroyLayer(hwc2_layer_t layer); |
88 | virtual int32_t getActiveConfig(hwc2_config_t* outConfig); |
89 | virtual int32_t getChangedCompositionTypes(uint32_t* outNumElements, hwc2_layer_t* outLayers, |
90 | int32_t* /*hwc2_composition_t*/ outTypes); |
91 | virtual int32_t getClientTargetSupport(uint32_t width, |
92 | uint32_t height, int32_t /*android_pixel_format_t*/ format, |
93 | int32_t /*android_dataspace_t*/ dataspace); |
94 | virtual int32_t getColorModes(uint32_t* outNumModes, |
95 | int32_t* /*android_color_mode_t*/ outModes); |
96 | virtual int32_t getDisplayAttribute(hwc2_config_t config, |
97 | int32_t /*hwc2_attribute_t*/ attribute, int32_t* outValue); |
98 | virtual int32_t getDisplayConfigs(uint32_t* outNumConfigs, hwc2_config_t* outConfigs); |
99 | virtual int32_t getDisplayName(uint32_t* outSize,char* outName); |
100 | virtual int32_t getDisplayRequests(int32_t* /*hwc2_display_request_t*/ outDisplayRequests, |
101 | uint32_t* outNumElements, hwc2_layer_t* outLayers, int32_t* /*hwc2_layer_request_t*/ outLayerRequests); |
102 | virtual int32_t getDisplayType(int32_t* /*hwc2_display_type_t*/ outType); |
103 | virtual int32_t getDozeSupport(int32_t* outSupport); |
104 | virtual int32_t getHdrCapabilities(uint32_t* outNumTypes, |
105 | int32_t* /*android_hdr_t*/ outTypes, float* outMaxLuminance, |
106 | float* outMaxAverageLuminance, float* outMinLuminance); |
107 | virtual int32_t getReleaseFences(uint32_t* outNumElements, hwc2_layer_t* outLayers, int32_t* outFences); |
108 | virtual int32_t presentDisplay(int32_t* outRetireFence); |
109 | virtual int32_t setActiveConfig(hwc2_config_t config); |
110 | virtual int32_t setClientTarget(buffer_handle_t target, |
111 | int32_t acquireFence, int32_t /*android_dataspace_t*/ dataspace, hwc_region_t damage); |
112 | virtual int32_t setColorMode(int32_t /*android_color_mode_t*/ mode); |
113 | virtual int32_t setColorTransform(const float* matrix, int32_t /*android_color_transform_t*/ hint); |
114 | |
115 | //virtual int32_t setOutputBuffer(buffer_handle_t buffer, int32_t releaseFence); // virtual display only |
116 | |
117 | virtual int32_t setPowerMode(int32_t /*hwc2_power_mode_t*/ mode); |
118 | virtual bool vsyncControl(bool enabled); // virtual hwc2_error_t setVsyncEnabled(hwc2_display_t display, int32_t /*hwc2_vsync_t*/ enabled); |
119 | virtual int32_t validateDisplay(uint32_t* outNumTypes, uint32_t* outNumRequests); |
120 | virtual int32_t setCursorPosition(hwc2_layer_t layerId, int32_t x, int32_t y); |
121 | |
122 | virtual int32_t createVirtualDisplay(uint32_t width, uint32_t height, int32_t* format, hwc2_display_t* outDisplay) = 0; |
123 | virtual int32_t destroyVirtualDisplay(hwc2_display_t display) = 0; |
124 | virtual int32_t setOutputBuffer(buffer_handle_t buffer, int32_t releaseFence) = 0; |
125 | |
126 | // Other Display methods |
127 | virtual Hwcomposer& getDevice() const { return mHwc; } |
128 | virtual hwc2_display_t getId() const { return mId; } |
129 | virtual bool isConnected() const { return mConnectorPresent; } |
130 | virtual void updateHotplugState(bool connected); |
131 | |
132 | // device related operations |
133 | virtual bool initCheck() const { return mInitialized; } |
134 | virtual bool initialize(); |
135 | virtual void deinitialize(); |
136 | virtual const char* getName() const { return mName; }; |
137 | virtual int getDisplayId() const { return mId; }; |
138 | virtual HwcLayer* getLayerById(hwc2_layer_t layerId); |
139 | |
140 | // display config operations |
141 | virtual bool updateDisplayConfigs(); |
142 | virtual void updateActiveDisplayAttribute(); |
143 | |
144 | // events |
145 | virtual void onVsync(int64_t timestamp); |
146 | virtual void onHotplug(int disp, bool connected); |
147 | virtual void dump(Dump& d); |
148 | DisplayHdmi* getDisplayHdmi() const { return mDisplayHdmi; }; |
149 | |
150 | private: |
151 | // For use by Device |
152 | int32_t initDisplay(); |
153 | int32_t postFramebuffer(int32_t* outRetireFence, bool hasVideoOverlay); |
154 | int32_t getLineValue(const char *lineStr, const char *magicStr); |
155 | |
156 | int32_t clearLayersStats(); |
157 | int32_t preValidate(); |
158 | int32_t parseHdrCapabilities(); |
159 | void directCompose(framebuffer_info_t * fbInfo); |
160 | void ge2dCompose(framebuffer_info_t * fbInfo, bool hasVideoOverlay); |
161 | int32_t setOSD0Blank(bool blank); |
162 | bool layersStateCheck(int32_t renderMode, KeyedVector<hwc2_layer_t, HwcLayer*> & composeLayers); |
163 | int32_t composersFilter(KeyedVector<hwc2_layer_t, HwcLayer*>& composeLayers); |
164 | |
165 | int32_t beginCompose(); |
166 | int32_t finishCompose(); |
167 | |
168 | //swap the mHwcCurReleaseFence and mHwcPriorReleaseFence; |
169 | void swapReleaseFence(); |
170 | //this function will take contorl of fencefd, if you need use it also, please dup it before call. |
171 | void addReleaseFence(hwc2_layer_t layerId, int32_t fenceFd); |
172 | void clearFenceList(KeyedVector<hwc2_layer_t, int32_t> * fenceList); |
173 | void dumpFenceList(KeyedVector<hwc2_layer_t, int32_t> * fenceList); |
174 | void dumpLayers(Vector < hwc2_layer_t > layerIds); |
175 | void dumpLayers(KeyedVector<hwc2_layer_t, HwcLayer*> layers); |
176 | void clearFramebuffer(); |
177 | |
178 | static void hdcpEventListener(void *data, bool status); |
179 | void setSecureStatus(bool status); |
180 | |
181 | // for vpp post scale. |
182 | bool calReverseScale(); |
183 | |
184 | template <typename T, typename S> |
185 | static inline bool compareSize(T a, S b) { |
186 | if ((int32_t)(a.right - a.left) == (int32_t)(b.right - b.left) |
187 | && (int32_t)(a.bottom - a.top) == (int32_t)(b.bottom - b.top)) { |
188 | return true; |
189 | } |
190 | return false; |
191 | } |
192 | |
193 | // Member variables |
194 | hwc2_display_t mId; |
195 | const char *mName; |
196 | bool mSecure; |
197 | Hwcomposer& mHwc; |
198 | DisplayHdmi* mDisplayHdmi; |
199 | DeviceControlFactory *mControlFactory; |
200 | SoftVsyncObserver *mVsyncObserver; |
201 | |
202 | IComposer *mComposer; |
203 | |
204 | // DeviceControlFactory *mControlFactory; |
205 | |
206 | // framebuffer_info_t *mFramebufferInfo; |
207 | private_handle_t *mFramebufferHnd; |
208 | FBContext *mCursorContext; |
209 | FBContext *mFramebufferContext; |
210 | int32_t mFbSlot; |
211 | |
212 | sp<ISystemControlService> mSystemControl; |
213 | |
214 | int32_t /*android_color_mode_t*/ mColorMode; |
215 | |
216 | int32_t /*hwc2_power_mode_t*/ mPowerMode; |
217 | |
218 | // client target layer. |
219 | buffer_handle_t mClientTargetHnd; |
220 | hwc_region_t mClientTargetDamageRegion; |
221 | int32_t mTargetAcquireFence; |
222 | int32_t mGE2DComposeFrameCount; |
223 | int32_t mDirectComposeFrameCount; |
224 | int32_t mPriorFrameRetireFence; |
225 | int32_t mRenderMode; |
226 | int32_t mPreviousRenderMode; |
227 | bool mIsValidated; |
228 | bool mIsContinuousBuf; |
229 | |
230 | // num of composition type changed layer. |
231 | uint32_t mNumLayersChangetype; |
232 | uint32_t mNumLayerChangerequest; |
233 | |
234 | // layer |
235 | hwc2_layer_t mDirectRenderLayerId; |
236 | hwc2_layer_t mVideoOverlayLayerId; |
237 | int32_t mGE2DClearVideoRegionCount; |
238 | Vector< hwc2_layer_t > mGE2DRenderSortedLayerIds; |
239 | KeyedVector<hwc2_layer_t, HwcLayer*> mHwcLayersChangeType; |
240 | KeyedVector<hwc2_layer_t, HwcLayer*> mHwcLayersChangeRequest; |
241 | KeyedVector<hwc2_layer_t, HwcLayer*> mHwcGlesLayers; |
242 | KeyedVector<hwc2_layer_t, HwcLayer*> mHwcLayers; |
243 | KeyedVector<hwc2_layer_t, HwcLayer*> mHwcSecureLayers; |
244 | |
245 | // HDR Capabilities |
246 | hdr_capabilities_t mHdrCapabilities; |
247 | |
248 | // fb sync requests. |
249 | hwc_fb_sync_request_t mFbSyncRequest; |
250 | |
251 | // record the release fence of layer. |
252 | KeyedVector<hwc2_layer_t, int32_t> mLayerReleaseFences[2]; |
253 | KeyedVector<hwc2_layer_t, int32_t> * mHwcCurReleaseFences; |
254 | KeyedVector<hwc2_layer_t, int32_t> * mHwcPriorReleaseFences; |
255 | |
256 | // lock |
257 | Mutex mLock; |
258 | bool mInitialized; |
259 | |
260 | // status of display connector.(hdmi, cvbs, panel) |
261 | bool mGetInitState; |
262 | bool mConnectorPresent; |
263 | |
264 | //rever the scaled displayframe, for we use the vpp scale. |
265 | float mReverseScaleX; |
266 | float mReverseScaleY; |
267 | |
268 | //omx handle for set omx pts |
269 | int32_t mOmxVideoHandle; |
270 | }; |
271 | |
272 | |
273 | } |
274 | } |
275 | |
276 | #endif /* PHYSICAL_DEVICE_H */ |
277 |