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