• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
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 
17 #ifndef _EXYNOSDEVICE_H
18 #define _EXYNOSDEVICE_H
19 
20 #include <aidl/com/google/hardware/pixel/display/BnDisplay.h>
21 #include <cutils/atomic.h>
22 #include <displaycolor/displaycolor.h>
23 #include <hardware/hwcomposer2.h>
24 #include <hardware_legacy/uevent.h>
25 #include <sys/resource.h>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 #include <unistd.h>
29 #include <utils/Condition.h>
30 #include <utils/Mutex.h>
31 #include <utils/Trace.h>
32 #include <utils/Vector.h>
33 
34 #include <atomic>
35 #include <map>
36 #include <thread>
37 
38 #include "ExynosHWC.h"
39 #include "ExynosHWCHelper.h"
40 #include "ExynosHWCModule.h"
41 
42 #define MAX_DEV_NAME 128
43 #define ERROR_LOG_PATH0 "/data/vendor/log/hwc"
44 #define ERROR_LOG_PATH1 "/data/log"
45 #define ERR_LOG_SIZE    (1024*1024)     // 1MB
46 #define FENCE_ERR_LOG_SIZE    (1024*1024)     // 1MB
47 
48 #ifndef DOZE_VSYNC_PERIOD
49 #define DOZE_VSYNC_PERIOD 33333333 // 30fps
50 #endif
51 
52 #ifndef DRM_DEVICE_PATH
53 #define DRM_DEVICE_PATH "/dev/dri/card0"
54 #endif
55 
56 #ifndef WRITEBACK_CAPTURE_PATH
57 #define WRITEBACK_CAPTURE_PATH "/data/vendor/log/hwc"
58 #endif
59 
60 using HbmState = ::aidl::com::google::hardware::pixel::display::HbmState;
61 using LbeState = ::aidl::com::google::hardware::pixel::display::LbeState;
62 using PanelCalibrationStatus = ::aidl::com::google::hardware::pixel::display::PanelCalibrationStatus;
63 
64 using namespace android;
65 
66 struct exynos_callback_info_t {
67     hwc2_callback_data_t callbackData;
68     hwc2_function_pointer_t funcPointer;
69 };
70 
71 typedef struct exynos_hwc_control {
72     uint32_t forceGpu;
73     uint32_t windowUpdate;
74     uint32_t forcePanic;
75     uint32_t skipStaticLayers;
76     uint32_t skipM2mProcessing;
77     uint32_t skipResourceAssign;
78     uint32_t multiResolution;
79     uint32_t dumpMidBuf;
80     uint32_t displayMode;
81     uint32_t setDDIScaler;
82     uint32_t useDynamicRecomp;
83     uint32_t skipWinConfig;
84     uint32_t skipValidate;
85     uint32_t doFenceFileDump;
86     uint32_t fenceTracer;
87     uint32_t sysFenceLogging;
88 } exynos_hwc_control_t;
89 
90 typedef struct update_time_info {
91     struct timeval lastUeventTime;
92     struct timeval lastEnableVsyncTime;
93     struct timeval lastDisableVsyncTime;
94     struct timeval lastValidateTime;
95     struct timeval lastPresentTime;
96 } update_time_info_t;
97 
98 enum {
99     GEOMETRY_LAYER_TYPE_CHANGED               = 1ULL << 0,
100     GEOMETRY_LAYER_DATASPACE_CHANGED          = 1ULL << 1,
101     GEOMETRY_LAYER_DISPLAYFRAME_CHANGED       = 1ULL << 2,
102     GEOMETRY_LAYER_SOURCECROP_CHANGED         = 1ULL << 3,
103     GEOMETRY_LAYER_TRANSFORM_CHANGED          = 1ULL << 4,
104     GEOMETRY_LAYER_ZORDER_CHANGED             = 1ULL << 5,
105     GEOMETRY_LAYER_FPS_CHANGED                = 1ULL << 6,
106     GEOMETRY_LAYER_FLAG_CHANGED               = 1ULL << 7,
107     GEOMETRY_LAYER_PRIORITY_CHANGED           = 1ULL << 8,
108     GEOMETRY_LAYER_COMPRESSED_CHANGED         = 1ULL << 9,
109     GEOMETRY_LAYER_BLEND_CHANGED              = 1ULL << 10,
110     GEOMETRY_LAYER_FORMAT_CHANGED             = 1ULL << 11,
111     GEOMETRY_LAYER_DRM_CHANGED                = 1ULL << 12,
112     GEOMETRY_LAYER_IGNORE_CHANGED             = 1ULL << 13,
113     GEOMETRY_LAYER_WHITEPOINT_CHANGED         = 1ULL << 14,
114     GEOMETRY_LAYER_FRONT_BUFFER_USAGE_CHANGED = 1ULL << 15,
115     GEOMETRY_LAYER_UNKNOWN_CHANGED            = 1ULL << 16,
116     /* 1ULL << 17 */
117     /* 1ULL << 18 */
118     /* 1ULL << 19 */
119     GEOMETRY_DISPLAY_LAYER_ADDED              = 1ULL << 20,
120     GEOMETRY_DISPLAY_LAYER_REMOVED            = 1ULL << 21,
121     GEOMETRY_DISPLAY_CONFIG_CHANGED           = 1ULL << 22,
122     GEOMETRY_DISPLAY_RESOLUTION_CHANGED       = 1ULL << 23,
123     GEOMETRY_DISPLAY_SINGLEBUF_CHANGED        = 1ULL << 24,
124     GEOMETRY_DISPLAY_FORCE_VALIDATE           = 1ULL << 25,
125     GEOMETRY_DISPLAY_COLOR_MODE_CHANGED       = 1ULL << 26,
126     GEOMETRY_DISPLAY_DYNAMIC_RECOMPOSITION    = 1ULL << 27,
127     GEOMETRY_DISPLAY_POWER_ON                 = 1ULL << 28,
128     GEOMETRY_DISPLAY_POWER_OFF                = 1ULL << 29,
129     GEOMETRY_DISPLAY_COLOR_TRANSFORM_CHANGED  = 1ULL << 30,
130     GEOMETRY_DISPLAY_DATASPACE_CHANGED        = 1ULL << 31,
131     /* 1ULL << 32 */
132     /* 1ULL << 33 */
133     /* 1ULL << 34 */
134     /* 1ULL << 35 */
135     GEOMETRY_DEVICE_DISPLAY_ADDED             = 1ULL << 36,
136     GEOMETRY_DEVICE_DISPLAY_REMOVED           = 1ULL << 37,
137     GEOMETRY_DEVICE_CONFIG_CHANGED            = 1ULL << 38,
138     GEOMETRY_DEVICE_DISP_MODE_CHAGED          = 1ULL << 39,
139     GEOMETRY_DEVICE_SCENARIO_CHANGED          = 1ULL << 40,
140 
141     GEOMETRY_ERROR_CASE                       = 1ULL << 63,
142 };
143 
144 class ExynosDevice;
145 class ExynosDisplay;
146 class ExynosResourceManager;
147 class ExynosDeviceInterface;
148 
149 class ExynosDevice {
150     public:
151         /**
152          * TODO : Should be defined as ExynosDisplay type
153          * Display list that managed by Device.
154          */
155         android::Vector< ExynosDisplay* > mDisplays;
156 
157         int mNumVirtualDisplay;
158 
159         /**
160          * Resource manager object that is used to manage HW resources and assign resources to each layers
161          */
162         ExynosResourceManager *mResourceManager;
163 
164         /**
165          * Geometry change will be saved by bit map.
166          * ex) Display create/destory.
167          */
168         uint64_t mGeometryChanged;
169 
170         /**
171          * If Panel has not self-refresh feature, dynamic recomposition will be enabled.
172          */
173         std::thread mDRThread;
174         volatile int32_t mDRThreadStatus;
175         std::atomic<bool> mDRLoopStatus;
176         bool mPrimaryBlank;
177         std::mutex mDRWakeUpMutex;
178         std::condition_variable mDRWakeUpCondition;
179 
180         /**
181          * Callback informations those are used by SurfaceFlinger.
182          * - VsyncCallback: Vsync detect callback.
183          * - RefreshCallback: Callback by refresh request from HWC.
184          * - HotplugCallback: Hot plug event by new display hardware.
185          */
186 
187         /** TODO : Array size shuld be checked */
188         exynos_callback_info_t mCallbackInfos[HWC2_CALLBACK_SEAMLESS_POSSIBLE + 1];
189 
190         std::map<uint32_t, exynos_callback_info_t> mHwc3CallbackInfos;
191         Mutex mDeviceCallbackMutex;
192 
193         /**
194          * Thread variables
195          */
196         int mVsyncFd;
197         int mExtVsyncFd;
198 
199         /**
200          * mDisplayId of display that has the slowest fps.
201          * HWC uses vsync of display that has the slowest fps to main vsync.
202          */
203         uint32_t mVsyncDisplayId;
204         uint64_t mTimestamp;
205 
206         uint32_t mDisplayMode;
207 
208         // Variable for fence tracer
209         std::map<int, HwcFenceInfo> mFenceInfos GUARDED_BY(mFenceMutex);
210         std::mutex mFenceMutex;
211 
212         /**
213          * This will be initialized with differnt class
214          * that inherits ExynosDeviceInterface according to
215          * interface type.
216          */
217         std::unique_ptr<ExynosDeviceInterface> mDeviceInterface;
218 
219         // Con/Destructors
220         ExynosDevice();
221         virtual ~ExynosDevice();
222 
223         bool isFirstValidate();
224         bool isLastValidate(ExynosDisplay *display);
225 
226         /**
227          * @param outSize
228          * @param * outBuffer
229          */
230 
231         void dynamicRecompositionThreadCreate();
232         static void* dynamicRecompositionThreadLoop(void *data);
233 
234 
235         /**
236          * @param display
237          */
238         ExynosDisplay* getDisplay(uint32_t display);
239 
240         /**
241          * Device Functions for HWC 2.0
242          */
243 
244         /**
245          * Descriptor: HWC2_FUNCTION_CREATE_VIRTUAL_DISPLAY
246          * HWC2_PFN_CREATE_VIRTUAL_DISPLAY
247          */
248         int32_t createVirtualDisplay(
249                 uint32_t width, uint32_t height, int32_t *format, ExynosDisplay *display);
250 
251         /**
252          * Descriptor: HWC2_FUNCTION_DESTROY_VIRTUAL_DISPLAY
253          * HWC2_PFN_DESTROY_VIRTUAL_DISPLAY
254          */
255         int32_t destroyVirtualDisplay(
256                 ExynosDisplay *display);
257 
258         /**
259          * Descriptor: HWC2_FUNCTION_DUMP
260          * HWC2_PFN_DUMP
261          */
262         void dump(uint32_t *outSize, char *outBuffer);
263 
264         /**
265          * Descriptor: HWC2_FUNCTION_GET_MAX_VIRTUAL_DISPLAY_COUNT
266          * HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT
267          */
268         /* TODO overide check!! */
269         uint32_t getMaxVirtualDisplayCount();
270 
271          /* Descriptor: HWC2_FUNCTION_GET_LAYER_GENERIC_METADATA_KEY
272          */
273         void getLayerGenericMetadataKey(uint32_t __unused keyIndex,
274                 uint32_t* __unused outKeyLength, char* __unused outKey, bool* __unused outMandatory);
275 
276         /**
277          * Descriptor: HWC2_FUNCTION_REGISTER_CALLBACK
278          * HWC2_PFN_REGISTER_CALLBACK
279          */
280         int32_t registerCallback (
281                 int32_t descriptor, hwc2_callback_data_t callbackData, hwc2_function_pointer_t point);
282         bool isCallbackAvailable(int32_t descriptor);
283         void onHotPlug(uint32_t displayId, bool status);
284         void onRefresh(uint32_t displayId);
285         void onRefreshDisplays();
286 
287         void onVsync(uint32_t displayId, int64_t timestamp);
288         bool onVsync_2_4(uint32_t displayId, int64_t timestamp, uint32_t vsyncPeriod);
289         void onVsyncPeriodTimingChanged(uint32_t displayId,
290                                         hwc_vsync_period_change_timeline_t *timeline);
291 
292         void setHWCDebug(unsigned int debug);
293         uint32_t getHWCDebug();
294         void setHWCFenceDebug(uint32_t ipNum, uint32_t typeNum, uint32_t mode);
295         void getHWCFenceDebug();
296         void setHWCControl(uint32_t display, uint32_t ctrl, int32_t val);
297         void setDisplayMode(uint32_t displayMode);
298         bool checkDisplayConnection(uint32_t displayId);
299         bool checkNonInternalConnection();
300         void getCapabilities(uint32_t *outCount, int32_t* outCapabilities);
setGeometryChanged(uint64_t changedBit)301         void setGeometryChanged(uint64_t changedBit) { mGeometryChanged|= changedBit;};
302         void clearGeometryChanged();
303         void setDynamicRecomposition(uint32_t displayId, unsigned int on);
304         bool canSkipValidate();
305         bool validateFences(ExynosDisplay *display);
306         void compareVsyncPeriod();
307         bool isDynamicRecompositionThreadAlive();
308         void checkDynamicRecompositionThread();
309         int32_t setDisplayDeviceMode(int32_t display_id, int32_t mode);
310         int32_t setPanelGammaTableSource(int32_t display_id, int32_t type, int32_t source);
311         void dump(String8 &result);
312 
313         class captureReadbackClass {
314             public:
315                 captureReadbackClass(ExynosDevice *device);
316                 ~captureReadbackClass();
317                 int32_t allocBuffer(uint32_t format, uint32_t w, uint32_t h);
getBuffer()318                 buffer_handle_t& getBuffer() { return mBuffer; };
319                 void saveToFile(const String8 &fileName);
320             private:
321                 buffer_handle_t mBuffer = nullptr;
322                 ExynosDevice* mDevice = nullptr;
323         };
324         void captureScreenWithReadback(uint32_t displayType);
325         void cleanupCaptureScreen(void *buffer);
326         void signalReadbackDone();
clearWaitingReadbackReqDone()327         void clearWaitingReadbackReqDone() {
328             mIsWaitingReadbackReqDone = false;
329         };
330 
331         uint32_t getWindowPlaneNum();
332         uint32_t getSpecialPlaneNum();
333         uint32_t getSpecialPlaneNum(uint32_t displayId);
334         uint32_t getSpecialPlaneId(uint32_t index);
335         uint64_t getSpecialPlaneAttr(uint32_t index);
336 
337         int32_t registerHwc3Callback(uint32_t descriptor, hwc2_callback_data_t callbackData,
338                                      hwc2_function_pointer_t point);
339         void onVsyncIdle(hwc2_display_t displayId);
isDispOffAsyncSupported()340         bool isDispOffAsyncSupported() { return mDisplayOffAsync; };
341 
342     protected:
343         void initDeviceInterface(uint32_t interfaceType);
344     protected:
345         uint32_t mInterfaceType;
346     private:
347         Mutex mCaptureMutex;
348         Condition mCaptureCondition;
349         std::atomic<bool> mIsWaitingReadbackReqDone = false;
350         void setVBlankOffDelay(int vblankOffDelay);
351         bool isCallbackRegisteredLocked(int32_t descriptor);
352 
353     public:
enterToTUI()354         void enterToTUI() { mIsInTUI = true; };
exitFromTUI()355         void exitFromTUI() { mIsInTUI = false; };
isInTUI()356         bool isInTUI() { return mIsInTUI; };
357 
358     private:
359         bool mIsInTUI;
360         bool mDisplayOffAsync;
361 };
362 
363 #endif //_EXYNOSDEVICE_H
364