blob: 0608d13d7f7f3c1bebf1a1dbf3ad3b42b6eabfd7
1 | /* |
2 | * Copyright (c) 2017 Amlogic, Inc. All rights reserved. |
3 | * |
4 | * This source code is subject to the terms and conditions defined in the |
5 | * file 'LICENSE' which is part of this source code package. |
6 | * |
7 | * Description: |
8 | */ |
9 | |
10 | #ifndef HWC2_DISPLAY_H |
11 | #define HWC2_DISPLAY_H |
12 | |
13 | #include <map> |
14 | #include <vector> |
15 | #include <unordered_map> |
16 | #include <hardware/hwcomposer2.h> |
17 | |
18 | #include <BitsMap.h> |
19 | #include <HwcDisplay.h> |
20 | #include <HwcPowerMode.h> |
21 | #include <HwcVsync.h> |
22 | |
23 | #include <ComposerFactory.h> |
24 | #include <IComposer.h> |
25 | #include <ICompositionStrategy.h> |
26 | #include <EventThread.h> |
27 | |
28 | #include "Hwc2Layer.h" |
29 | #include "MesonHwc2Defs.h" |
30 | #include "HwcModeMgr.h" |
31 | |
32 | class Hwc2DisplayObserver { |
33 | public: |
34 | Hwc2DisplayObserver(){}; |
35 | virtual ~Hwc2DisplayObserver(){}; |
36 | virtual void refresh() = 0; |
37 | virtual void onVsync(int64_t timestamp) = 0; |
38 | virtual void onHotplug(bool connected) = 0; |
39 | }; |
40 | |
41 | class Hwc2Display |
42 | : public HwcDisplay, public HwcVsyncObserver { |
43 | public: |
44 | Hwc2Display(std::shared_ptr<Hwc2DisplayObserver> observer); |
45 | virtual ~Hwc2Display(); |
46 | |
47 | virtual void dump(String8 & dumpstr); |
48 | |
49 | /*HWC2 interfaces.*/ |
50 | public: |
51 | /*Connector releated.*/ |
52 | virtual const char * getName(); |
53 | virtual const drm_hdr_capabilities_t * getHdrCapabilities(); |
54 | #ifdef HWC_HDR_METADATA_SUPPORT |
55 | virtual hwc2_error_t getFrameMetadataKeys ( |
56 | uint32_t* outNumKeys, int32_t* outKeys); |
57 | #endif |
58 | |
59 | /*Vsync*/ |
60 | virtual hwc2_error_t setVsyncEnable(hwc2_vsync_t enabled); |
61 | |
62 | /*Layer releated.*/ |
63 | virtual std::shared_ptr<Hwc2Layer> getLayerById(hwc2_layer_t id); |
64 | virtual hwc2_error_t createLayer(hwc2_layer_t * outLayer); |
65 | virtual hwc2_error_t destroyLayer(hwc2_layer_t inLayer); |
66 | virtual hwc2_error_t setCursorPosition(hwc2_layer_t layer, |
67 | int32_t x, int32_t y); |
68 | |
69 | virtual hwc2_error_t setColorTransform(const float* matrix, |
70 | android_color_transform_t hint); |
71 | virtual hwc2_error_t setPowerMode(hwc2_power_mode_t mode); |
72 | |
73 | /*Compose flow*/ |
74 | virtual hwc2_error_t validateDisplay(uint32_t* outNumTypes, |
75 | uint32_t* outNumRequests); |
76 | virtual hwc2_error_t presentDisplay(int32_t* outPresentFence); |
77 | virtual hwc2_error_t acceptDisplayChanges(); |
78 | virtual hwc2_error_t getChangedCompositionTypes( |
79 | uint32_t* outNumElements, hwc2_layer_t* outLayers, |
80 | int32_t* outTypes); |
81 | virtual hwc2_error_t getDisplayRequests( |
82 | int32_t* outDisplayRequests, uint32_t* outNumElements, |
83 | hwc2_layer_t* outLayers,int32_t* outLayerRequests); |
84 | virtual hwc2_error_t setClientTarget( buffer_handle_t target, |
85 | int32_t acquireFence, int32_t dataspace, hwc_region_t damage); |
86 | virtual hwc2_error_t getReleaseFences(uint32_t* outNumElements, |
87 | hwc2_layer_t* outLayers, int32_t* outFences); |
88 | |
89 | /*display attrbuites*/ |
90 | virtual hwc2_error_t getDisplayConfigs( |
91 | uint32_t* outNumConfigs, hwc2_config_t* outConfigs); |
92 | virtual hwc2_error_t getDisplayAttribute( |
93 | hwc2_config_t config, int32_t attribute, int32_t* outValue); |
94 | virtual hwc2_error_t getActiveConfig(hwc2_config_t* outConfig); |
95 | virtual hwc2_error_t setActiveConfig(hwc2_config_t config); |
96 | virtual hwc2_error_t setCalibrateInfo(int32_t caliX,int32_t caliY,int32_t caliW,int32_t caliH); |
97 | virtual int32_t getDisplayIdentificationData(uint32_t &outPort, |
98 | std::vector<uint8_t> &outData); |
99 | virtual hwc2_error_t getDisplayCapabilities( |
100 | uint32_t* outNumCapabilities, uint32_t* outCapabilities); |
101 | |
102 | /*HwcDisplay interface*/ |
103 | public: |
104 | virtual int32_t initialize(); |
105 | |
106 | virtual int32_t setDisplayResource( |
107 | std::shared_ptr<HwDisplayCrtc> & crtc, |
108 | std::shared_ptr<HwDisplayConnector> & connector, |
109 | std::vector<std::shared_ptr<HwDisplayPlane>> & planes); |
110 | virtual int32_t setModeMgr(std::shared_ptr<HwcModeMgr> & mgr); |
111 | virtual int32_t setPostProcessor( |
112 | std::shared_ptr<HwcPostProcessor> processor); |
113 | virtual int32_t setVsync(std::shared_ptr<HwcVsync> vsync); |
114 | virtual int32_t blankDisplay(); |
115 | |
116 | virtual void onVsync(int64_t timestamp); |
117 | virtual void onHotplug(bool connected); |
118 | virtual void onUpdate(bool bHdcp); |
119 | virtual void onModeChanged(int stage); |
120 | virtual void getDispMode(drm_mode_info_t & dispMode); |
121 | |
122 | protected: |
123 | /* For compose. */ |
124 | hwc2_error_t collectLayersForPresent(); |
125 | hwc2_error_t collectComposersForPresent(); |
126 | hwc2_error_t collectPlanesForPresent(); |
127 | hwc2_error_t collectCompositionStgForPresent(); |
128 | hwc2_error_t collectCompositionRequest( |
129 | uint32_t* outNumTypes, uint32_t* outNumRequests); |
130 | |
131 | /*for calibrate display frame.*/ |
132 | int32_t loadCalibrateInfo(); |
133 | int32_t adjustDisplayFrame(); |
134 | |
135 | /*Layer id sequence no.*/ |
136 | void initLayerIdGenerator(); |
137 | hwc2_layer_t createLayerId(); |
138 | void destroyLayerId(hwc2_layer_t id); |
139 | |
140 | /*For debug*/ |
141 | void dumpPresentLayers(String8 & dumpstr); |
142 | bool isLayerHideForDebug(hwc2_layer_t id); |
143 | void dumpHwDisplayPlane(String8 &dumpstr); |
144 | |
145 | protected: |
146 | std::unordered_map<hwc2_layer_t, std::shared_ptr<Hwc2Layer>> mLayers; |
147 | std::shared_ptr<Hwc2DisplayObserver> mObserver; |
148 | drm_hdr_capabilities_t mHdrCaps; |
149 | |
150 | /*hw releated components*/ |
151 | std::shared_ptr<HwDisplayCrtc> mCrtc; |
152 | std::shared_ptr<HwDisplayConnector> mConnector; |
153 | std::vector<std::shared_ptr<HwDisplayPlane>> mPlanes; |
154 | |
155 | /*composition releated components*/ |
156 | std::map<meson_composer_t, std::shared_ptr<IComposer>> mComposers; |
157 | std::shared_ptr<ICompositionStrategy> mCompositionStrategy; |
158 | bool mFailedDeviceComp; |
159 | |
160 | /*display configs*/ |
161 | std::shared_ptr<HwcModeMgr> mModeMgr; |
162 | std::shared_ptr<HwcVsync> mVsync; |
163 | |
164 | /*layer id generate*/ |
165 | std::shared_ptr<BitsMap> mLayersBitmap; |
166 | int32_t mLayerSeq; |
167 | |
168 | /* members used in present.*/ |
169 | std::vector<std::shared_ptr<DrmFramebuffer>> mPresentLayers; |
170 | std::vector<std::shared_ptr<IComposer>> mPresentComposers; |
171 | std::vector<std::shared_ptr<HwDisplayPlane>> mPresentPlanes; |
172 | std::shared_ptr<ICompositionStrategy> mPresentCompositionStg; |
173 | |
174 | std::vector<hwc2_layer_t> mChangedLayers; |
175 | std::vector<hwc2_layer_t> mOverlayLayers; |
176 | |
177 | /*all go to client composer*/ |
178 | bool mForceClientComposer; |
179 | float mColorMatrix[16]; |
180 | |
181 | std::shared_ptr<HwcPowerMode> mPowerMode; |
182 | bool mSkipComposition; |
183 | bool mSignalHpd; |
184 | bool mValidateDisplay; |
185 | |
186 | drm_mode_info_t mDisplayMode; |
187 | display_zoom_info_t mCalibrateInfo; |
188 | int mCalibrateCoordinates[4]; |
189 | |
190 | std::shared_ptr<HwcPostProcessor> mPostProcessor; |
191 | int32_t mProcessorFlags; |
192 | |
193 | #ifdef HWC_HDR_METADATA_SUPPORT |
194 | std::vector<drm_hdr_meatadata_t> mHdrKeys; |
195 | #endif |
196 | std::mutex mMutex; |
197 | |
198 | bool mVsyncState; |
199 | }; |
200 | |
201 | #endif/*HWC2_DISPLAY_H*/ |
202 |