summaryrefslogtreecommitdiff
path: root/hwc2/include/PhysicalDevice.h (plain)
blob: 708b6ee32a034b152d39822b871e79387ab5e11c
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
137 // events
138 virtual void onVsync(int64_t timestamp);
139 virtual void onHotplug(int disp, bool connected);
140 virtual void dump(Dump& d);
141 DisplayHdmi* getDisplayHdmi() const { return mDisplayHdmi; };
142
143private:
144 // For use by Device
145 int32_t initDisplay();
146 int32_t postFramebuffer(int32_t* outRetireFence, bool hasVideoOverlay);
147 int32_t getLineValue(const char *lineStr, const char *magicStr);
148
149 int32_t clearLayersStats();
150 int32_t preValidate();
151 int32_t parseHdrCapabilities();
152 void directCompose(framebuffer_info_t * fbInfo);
153 void ge2dCompose(framebuffer_info_t * fbInfo, bool hasVideoOverlay);
154 int32_t setOSD0Blank(bool blank);
155 bool layersStateCheck(int32_t renderMode, KeyedVector<hwc2_layer_t, HwcLayer*> & composeLayers);
156 int32_t composersFilter(KeyedVector<hwc2_layer_t, HwcLayer*>& composeLayers);
157
158 int32_t beginCompose();
159 int32_t finishCompose();
160
161 //swap the mHwcCurReleaseFence and mHwcPriorReleaseFence;
162 void swapReleaseFence();
163 //this function will take contorl of fencefd, if you need use it also, please dup it before call.
164 void addReleaseFence(hwc2_layer_t layerId, int32_t fenceFd);
165 void clearFenceList(KeyedVector<hwc2_layer_t, int32_t> * fenceList);
166 void dumpFenceList(KeyedVector<hwc2_layer_t, int32_t> * fenceList);
167 void dumpLayers(Vector < hwc2_layer_t > layerIds);
168 void dumpLayers(KeyedVector<hwc2_layer_t, HwcLayer*> layers);
169 void clearFramebuffer();
170
171 static void hdcpEventListener(void *data, bool status);
172 void setSecureStatus(bool status);
173
174 // for vpp post scale.
175 bool calReverseScale();
176
177 template <typename T, typename S>
178 static inline bool compareSize(T a, S b) {
179 if ((int32_t)(a.right - a.left) == (int32_t)(b.right - b.left)
180 && (int32_t)(a.bottom - a.top) == (int32_t)(b.bottom - b.top)) {
181 return true;
182 }
183 return false;
184 }
185
186 // Member variables
187 hwc2_display_t mId;
188 const char *mName;
189 bool mSecure;
190 Hwcomposer& mHwc;
191 DisplayHdmi* mDisplayHdmi;
192 IComposeDeviceFactory *mControlFactory;
193 SoftVsyncObserver *mVsyncObserver;
194
195 IComposeDevice *mComposer;
196
197 // DeviceControlFactory *mControlFactory;
198
199 // framebuffer_info_t *mFramebufferInfo;
200 private_handle_t *mFramebufferHnd;
201 FBContext *mCursorContext;
202 FBContext *mFramebufferContext;
203 int32_t mFbSlot;
204
205 sp<ISystemControlService> mSystemControl;
206
207 int32_t /*android_color_mode_t*/ mColorMode;
208
209 int32_t /*hwc2_power_mode_t*/ mPowerMode;
210
211 // client target layer.
212 buffer_handle_t mClientTargetHnd;
213 hwc_region_t mClientTargetDamageRegion;
214 int32_t mTargetAcquireFence;
215 int32_t mGE2DComposeFrameCount;
216 int32_t mDirectComposeFrameCount;
217 int32_t mPriorFrameRetireFence;
218 int32_t mRenderMode;
219 int32_t mPreviousRenderMode;
220 bool mIsValidated;
221 bool mIsContinuousBuf;
222
223 // num of composition type changed layer.
224 uint32_t mNumLayersChangetype;
225 uint32_t mNumLayerChangerequest;
226
227 // layer
228 hwc2_layer_t mDirectRenderLayerId;
229 hwc2_layer_t mVideoOverlayLayerId;
230 int32_t mGE2DClearVideoRegionCount;
231 Vector< hwc2_layer_t > mGE2DRenderSortedLayerIds;
232 KeyedVector<hwc2_layer_t, HwcLayer*> mHwcLayersChangeType;
233 KeyedVector<hwc2_layer_t, HwcLayer*> mHwcLayersChangeRequest;
234 KeyedVector<hwc2_layer_t, HwcLayer*> mHwcGlesLayers;
235 KeyedVector<hwc2_layer_t, HwcLayer*> mHwcLayers;
236 KeyedVector<hwc2_layer_t, HwcLayer*> mHwcSecureLayers;
237
238 // HDR Capabilities
239 hdr_capabilities_t mHdrCapabilities;
240
241 // fb sync requests.
242 hwc_fb_sync_request_t mFbSyncRequest;
243
244 // record the release fence of layer.
245 KeyedVector<hwc2_layer_t, int32_t> mLayerReleaseFences[2];
246 KeyedVector<hwc2_layer_t, int32_t> * mHwcCurReleaseFences;
247 KeyedVector<hwc2_layer_t, int32_t> * mHwcPriorReleaseFences;
248
249 // lock
250 Mutex mLock;
251 bool mInitialized;
252
253 // status of display connector.(hdmi, cvbs, panel)
254 bool mGetInitState;
255 bool mConnectorPresent;
256
257 //rever the scaled displayframe, for we use the vpp scale.
258 float mReverseScaleX;
259 float mReverseScaleY;
260
261 //omx handle for set omx pts
262 int32_t mOmxVideoHandle;
263};
264
265
266}
267}
268
269#endif /* PHYSICAL_DEVICE_H */
270