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