summaryrefslogtreecommitdiff
path: root/hwc2/include/PhysicalDevice.h (plain)
blob: 57e181f3e5b5e0d4d0a09e0c06ab7aea4f8bd9e9
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 <IComposer.h>
27#include <DisplayHdmi.h>
28
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 DeviceControlFactory {
50public:
51 virtual ~DeviceControlFactory(){}
52public:
53 // virtual IHdcpControl* createHdcpControl() = 0;
54 virtual IComposer* createComposer(IDisplayDevice& disp) = 0;
55};
56
57class FBContext {
58public:
59 FBContext()
60 : mStatus(false)
61 {
62 mFBInfo = new framebuffer_info_t();
63 }
64 virtual ~FBContext(){}
65
66 virtual framebuffer_info_t* getInfo() { return mFBInfo; }
67 virtual bool getStatus() { return mStatus; }
68 virtual void setStatus(bool status) { mStatus = status; }
69private:
70 framebuffer_info_t *mFBInfo;
71 bool mStatus;
72};
73
74class Hwcomposer;
75class SoftVsyncObserver;
76
77class PhysicalDevice : public IDisplayDevice {
78public:
79 PhysicalDevice(hwc2_display_t id, Hwcomposer& hwc, DeviceControlFactory* controlFactory);
80 ~PhysicalDevice();
81
82 friend class Hwcomposer;
83 friend class HwcLayer;
84
85 // typedef sp<ISystemControlService> IScs;
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 mIsConnected; }
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
146 //events
147 virtual void onVsync(int64_t timestamp);
148 virtual void dump(Dump& d);
149 DisplayHdmi* getDisplayHdmi() const { return mDisplayHdmi; };
150
151private:
152 // For use by Device
153 int32_t initDisplay();
154 int32_t postFramebuffer(int32_t* outRetireFence, bool hasVideoOverlay);
155 int32_t getLineValue(const char *lineStr, const char *magicStr);
156
157 int32_t parseHdrCapabilities();
158 void directCompose(framebuffer_info_t * fbInfo);
159 void ge2dCompose(framebuffer_info_t * fbInfo, bool hasVideoOverlay);
160 int32_t setOSD0Blank(bool blank);
161 bool layersStateCheck(int32_t renderMode, KeyedVector<hwc2_layer_t, HwcLayer*> & composeLayers);
162 int32_t composersFilter(KeyedVector<hwc2_layer_t, HwcLayer*>& composeLayers);
163
164 //swap the mHwcCurReleaseFence and mHwcPriorReleaseFence;
165 void swapReleaseFence();
166 //this function will take contorl of fencefd, if you need use it also, please dup it before call.
167 void addReleaseFence(hwc2_layer_t layerId, int32_t fenceFd);
168 void clearFenceList(KeyedVector<hwc2_layer_t, int32_t> * fenceList);
169 void dumpFenceList(KeyedVector<hwc2_layer_t, int32_t> * fenceList);
170 void dumpLayers(Vector < hwc2_layer_t > layerIds);
171 void dumpLayers(KeyedVector<hwc2_layer_t, HwcLayer*> layers);
172 void clearFramebuffer();
173
174 sp<ISystemControlService> getSystemControlService();
175 static void hdcpEventListener(void *data, bool status);
176 void setSecureStatus(bool status);
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 mIsConnected;
191 bool mSecure;
192 Hwcomposer& mHwc;
193 DisplayHdmi* mDisplayHdmi;
194 DeviceControlFactory *mControlFactory;
195
196 SoftVsyncObserver *mVsyncObserver;
197 IComposer *mComposer;
198
199 // DeviceControlFactory *mControlFactory;
200
201 // framebuffer_info_t *mFramebufferInfo;
202 private_handle_t *mFramebufferHnd;
203 FBContext *mCursorContext;
204 FBContext *mFramebufferContext;
205 int32_t mFbSlot;
206
207 sp<ISystemControlService> mSystemControl;
208
209 int32_t /*android_color_mode_t*/ mColorMode;
210
211 int32_t /*hwc2_power_mode_t*/ mPowerMode;
212
213 // client target layer.
214 buffer_handle_t mClientTargetHnd;
215 hwc_region_t mClientTargetDamageRegion;
216 int32_t mTargetAcquireFence;
217 int32_t mGE2DComposeFrameCount;
218 int32_t mDirectComposeFrameCount;
219 int32_t mPriorFrameRetireFence;
220 int32_t mRenderMode;
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#ifdef HWC_ENABLE_SECURE_LAYER
238 KeyedVector<hwc2_layer_t, HwcLayer*> mHwcSecureLayers;
239#endif
240
241 // HDR Capabilities
242 hdr_capabilities_t mHdrCapabilities;
243
244 // fb sync requests.
245 hwc_fb_sync_request_t mFbSyncRequest;
246
247 // record the release fence of layer.
248 KeyedVector<hwc2_layer_t, int32_t> mLayerReleaseFences[2];
249 KeyedVector<hwc2_layer_t, int32_t> * mHwcCurReleaseFences;
250 KeyedVector<hwc2_layer_t, int32_t> * mHwcPriorReleaseFences;
251
252 // lock
253 Mutex mLock;
254 bool mInitialized;
255};
256
257
258}
259}
260
261#endif /* PHYSICAL_DEVICE_H */
262