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