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