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 #ifndef _EXYNOSHWCHELPER_H
17 #define _EXYNOSHWCHELPER_H
18
19 #include <sstream>
20 #include <string>
21 #include <vector>
22
23 #include <drm/drm_fourcc.h>
24 #include <hardware/hwcomposer2.h>
25 #include <utils/String8.h>
26
27 #include <optional>
28
29 #include "DeconCommonHeader.h"
30 #include "VendorVideoAPI.h"
31 #include "exynos_sync.h"
32
33 #include "VendorGraphicBuffer.h"
34 #include "exynos_format.h"
35 #include "mali_gralloc_formats.h"
36
37 #define MAX_FENCE_NAME 64
38 #define MAX_FENCE_THRESHOLD 500
39 #define MAX_FD_NUM 1024
40
41 #define MAX_USE_FORMAT 27
42 #ifndef P010M_Y_SIZE
43 #define P010M_Y_SIZE(w,h) (__ALIGN_UP((w), 16) * 2 * __ALIGN_UP((h), 16) + 256)
44 #endif
45 #ifndef P010M_CBCR_SIZE
46 #define P010M_CBCR_SIZE(w,h) ((__ALIGN_UP((w), 16) * 2 * __ALIGN_UP((h), 16) / 2) + 256)
47 #endif
48 #ifndef P010_Y_SIZE
49 #define P010_Y_SIZE(w, h) ((w) * (h) * 2)
50 #endif
51 #ifndef P010_CBCR_SIZE
52 #define P010_CBCR_SIZE(w, h) ((w) * (h))
53 #endif
54 #ifndef DRM_FORMAT_YUV420_8BIT
55 #define DRM_FORMAT_YUV420_8BIT fourcc_code('Y', 'U', '0', '8')
56 #endif
57 #ifndef DRM_FORMAT_YUV420_10BIT
58 #define DRM_FORMAT_YUV420_10BIT fourcc_code('Y', 'U', '1', '0')
59 #endif
60
61 static constexpr uint32_t DISPLAYID_MASK_LEN = 8;
62
max(T a,T b)63 template<typename T> inline T max(T a, T b) { return (a > b) ? a : b; }
min(T a,T b)64 template<typename T> inline T min(T a, T b) { return (a < b) ? a : b; }
65
66 class ExynosLayer;
67 class ExynosDisplay;
68
69 using namespace android;
70
71 static constexpr uint32_t TRANSFORM_MAT_SIZE = 4*4;
72
73 enum {
74 EXYNOS_HWC_DIM_LAYER = 1 << 0,
75 EXYNOS_HWC_IGNORE_LAYER = 1 << 1,
76 };
77
78 enum {
79 INTERFACE_TYPE_NONE = 0,
80 INTERFACE_TYPE_FB = 1,
81 INTERFACE_TYPE_DRM = 2,
82 };
83
84 typedef enum format_type {
85 TYPE_UNDEF = 0,
86
87 /* format */
88 FORMAT_SHIFT = 0,
89 FORMAT_MASK = 0x00000fff,
90 RGB = 0x00000001,
91 YUV420 = 0x00000002,
92 YUV422 = 0x00000004,
93 P010 = 0x00000008,
94
95 /* bit */
96 BIT_SHIFT = 12,
97 BIT_MASK = 0x000ff000,
98 BIT8 = 0x00001000,
99 BIT10 = 0x00002000,
100 BIT8_2 = 0x00004000,
101
102 /* compression */
103 /*
104 * COMP_ANY: Compression type doesn't affect any other
105 * descriptions of format (ex: drmFormat, bufferNum, bpp...)
106 * in format_description
107 */
108 COMP_SHIFT = 20,
109 COMP_MASK = 0x0ff00000,
110 COMP_ANY = 0x08000000, /* the highest bit */
111 AFBC = 0x00100000,
112 SBWC = 0x00200000,
113 SBWC_LOSSY = 0x00400000,
114
115 } format_type_t;
116
117 typedef struct format_description {
getFormatformat_description118 inline uint32_t getFormat() const { return type & FORMAT_MASK; }
getBitformat_description119 inline uint32_t getBit() const { return type & BIT_MASK; }
getCompressionformat_description120 inline uint32_t getCompression() const { return type & COMP_MASK; }
121 int halFormat;
122 decon_pixel_format s3cFormat;
123 int drmFormat;
124 uint32_t planeNum;
125 uint32_t bufferNum;
126 uint8_t bpp;
127 uint32_t type;
128 bool hasAlpha;
129 String8 name;
130 uint32_t reserved;
131 } format_description_t;
132
133 constexpr int HAL_PIXEL_FORMAT_EXYNOS_UNDEFINED = 0;
134 constexpr int DRM_FORMAT_UNDEFINED = 0;
135
136 const format_description_t exynos_format_desc[] = {
137 /* RGB */
138 {HAL_PIXEL_FORMAT_RGBA_8888, DECON_PIXEL_FORMAT_RGBA_8888, DRM_FORMAT_RGBA8888,
139 1, 1, 32, RGB|BIT8|COMP_ANY, true, String8("RGBA_8888"), 0},
140 {HAL_PIXEL_FORMAT_RGBX_8888, DECON_PIXEL_FORMAT_RGBX_8888, DRM_FORMAT_RGBX8888,
141 1, 1, 32, RGB|BIT8|COMP_ANY, false, String8("RGBx_8888"), 0},
142 {HAL_PIXEL_FORMAT_RGB_888, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_RGB888,
143 1, 1, 24, RGB|BIT8|COMP_ANY, false, String8("RGB_888"), 0},
144 {HAL_PIXEL_FORMAT_RGB_565, DECON_PIXEL_FORMAT_RGB_565, DRM_FORMAT_BGR565,
145 1, 1, 16, RGB, false, String8("RGB_565"), 0},
146 {HAL_PIXEL_FORMAT_RGB_565, DECON_PIXEL_FORMAT_RGB_565, DRM_FORMAT_RGB565,
147 1, 1, 16, RGB|AFBC, false, String8("RGB_565_AFBC"), 0},
148 {HAL_PIXEL_FORMAT_BGRA_8888, DECON_PIXEL_FORMAT_BGRA_8888, DRM_FORMAT_BGRA8888,
149 1, 1, 32, RGB|BIT8|COMP_ANY, true, String8("BGRA_8888"), 0},
150 {HAL_PIXEL_FORMAT_RGBA_1010102, DECON_PIXEL_FORMAT_ABGR_2101010, DRM_FORMAT_RGBA1010102,
151 1, 1, 32, RGB|BIT10|COMP_ANY, true, String8("RGBA_1010102"), 0},
152 {HAL_PIXEL_FORMAT_EXYNOS_ARGB_8888, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_ARGB8888,
153 1, 1, 32, RGB|BIT8|COMP_ANY, true, String8("EXYNOS_ARGB_8888"), 0},
154
155 /* YUV 420 */
156 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_P_M, DECON_PIXEL_FORMAT_YUV420M, DRM_FORMAT_UNDEFINED,
157 3, 3, 12, YUV420|BIT8, false, String8("EXYNOS_YCbCr_420_P_M"), 0},
158 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M, DECON_PIXEL_FORMAT_NV12M, DRM_FORMAT_NV12,
159 2, 2, 12, YUV420|BIT8, false, String8("EXYNOS_YCbCr_420_SP_M"), 0},
160 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_TILED, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
161 2, 2, 12, YUV420|BIT8, false, String8("EXYNOS_YCbCr_420_SP_M_TILED"), 0},
162 {HAL_PIXEL_FORMAT_EXYNOS_YV12_M, DECON_PIXEL_FORMAT_YVU420M, DRM_FORMAT_UNDEFINED,
163 3, 3, 12, YUV420|BIT8, false, String8("EXYNOS_YV12_M"), 0},
164 {HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M, DECON_PIXEL_FORMAT_NV21M, DRM_FORMAT_NV21,
165 2, 2, 12, YUV420|BIT8, false, String8("EXYNOS_YCrCb_420_SP_M"), 0},
166 {HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_FULL, DECON_PIXEL_FORMAT_NV21M, DRM_FORMAT_NV21,
167 2, 2, 12, YUV420|BIT8, false, String8("EXYNOS_YCrCb_420_SP_M_FULL"), 0},
168 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_P, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
169 3, 1, 0, YUV420|BIT8, false, String8("EXYNOS_YCbCr_420_P"), 0},
170 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
171 2, 1, 0, YUV420|BIT8, false, String8("EXYNOS_YCbCr_420_SP"), 0},
172 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_PRIV, DECON_PIXEL_FORMAT_NV12M, DRM_FORMAT_NV12,
173 2, 2, 12, YUV420|BIT8, false, String8("EXYNOS_YCbCr_420_SP_M_PRIV"), 0},
174 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_PN, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
175 3, 1, 12, YUV420|BIT8, false, String8("EXYNOS_YCbCr_420_PN"), 0},
176 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN, DECON_PIXEL_FORMAT_NV12N, DRM_FORMAT_NV12,
177 2, 1, 12, YUV420|BIT8, false, String8("EXYNOS_YCbCr_420_SPN"), 0},
178 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_TILED, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
179 2, 1, 12, YUV420|BIT8, false, String8("EXYNOS_YCbCr_420_SPN_TILED"), 0},
180 {HAL_PIXEL_FORMAT_YCrCb_420_SP, DECON_PIXEL_FORMAT_NV21, DRM_FORMAT_NV21,
181 2, 1, 12, YUV420|BIT8, false, String8("YCrCb_420_SP"), 0},
182 {HAL_PIXEL_FORMAT_YV12, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
183 3, 1, 12, YUV420|BIT8, false, String8("YV12"), 0},
184 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_S10B, DECON_PIXEL_FORMAT_NV12M_S10B, DRM_FORMAT_UNDEFINED,
185 2, 2, 12, YUV420|BIT10|BIT8_2, false, String8("EXYNOS_YCbCr_420_SP_M_S10B"), 0},
186 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_S10B, DECON_PIXEL_FORMAT_NV12N_10B, DRM_FORMAT_UNDEFINED,
187 2, 1, 12, YUV420|BIT10|BIT8_2, false, String8("EXYNOS_YCbCr_420_SPN_S10B"), 0},
188 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_P010_M, DECON_PIXEL_FORMAT_NV12M_P010, DRM_FORMAT_P010,
189 2, 2, 24, YUV420|BIT10|P010, false, String8("EXYNOS_YCbCr_P010_M"), 0},
190 {HAL_PIXEL_FORMAT_YCBCR_P010, DECON_PIXEL_FORMAT_NV12_P010, DRM_FORMAT_P010,
191 2, 1, 24, YUV420|BIT10|P010, false, String8("EXYNOS_YCbCr_P010"), 0},
192
193 {HAL_PIXEL_FORMAT_GOOGLE_NV12_SP, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_NV12,
194 2, 1, 12, YUV420|BIT8, false, String8("GOOGLE_YCbCr_420_SP"), 0},
195 {HAL_PIXEL_FORMAT_GOOGLE_NV12_SP_10B, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_P010,
196 2, 1, 24, YUV420|BIT10, false, String8("GOOGLE_YCbCr_P010"), 0},
197 {MALI_GRALLOC_FORMAT_INTERNAL_YUV420_8BIT_I, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_YUV420_8BIT,
198 1, 1, 12, YUV420|BIT8|AFBC, false, String8("MALI_GRALLOC_FORMAT_INTERNAL_YUV420_8BIT_I"), 0},
199 {MALI_GRALLOC_FORMAT_INTERNAL_YUV420_10BIT_I, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_YUV420_10BIT,
200 1, 1, 15, YUV420|BIT10|AFBC, false, String8("MALI_GRALLOC_FORMAT_INTERNAL_YUV420_10BIT_I"), 0},
201
202 /* YUV 422 */
203 {HAL_PIXEL_FORMAT_EXYNOS_CbYCrY_422_I, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
204 0, 0, 0, YUV422|BIT8, false, String8("EXYNOS_CbYCrY_422_I"), 0},
205 {HAL_PIXEL_FORMAT_EXYNOS_YCrCb_422_SP, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
206 0, 0, 0, YUV422|BIT8, false, String8("EXYNOS_YCrCb_422_SP"), 0},
207 {HAL_PIXEL_FORMAT_EXYNOS_YCrCb_422_I, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
208 0, 0, 0, YUV422|BIT8, false, String8("EXYNOS_YCrCb_422_I"), 0},
209 {HAL_PIXEL_FORMAT_EXYNOS_CrYCbY_422_I, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
210 0, 0, 0, YUV422|BIT8, false, String8("EXYNOS_CrYCbY_422_I"), 0},
211
212 /* SBWC formats */
213 /* NV12, YCbCr, Multi */
214 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC, DECON_PIXEL_FORMAT_NV12M_SBWC_8B, DRM_FORMAT_NV12,
215 2, 2, 12, YUV420|BIT8|SBWC, false, String8("EXYNOS_YCbCr_420_SP_M_SBWC"), 0},
216 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L50, DECON_PIXEL_FORMAT_NV12M_SBWC_8B_L50, DRM_FORMAT_NV12,
217 2, 2, 12, YUV420|BIT8|SBWC_LOSSY, false, String8("EXYNOS_YCbCr_420_SP_M_SBWC_L50"), 0},
218 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L75, DECON_PIXEL_FORMAT_NV12M_SBWC_8B_L75, DRM_FORMAT_NV12,
219 2, 2, 12, YUV420|BIT8|SBWC_LOSSY, false, String8("EXYNOS_YCbCr_420_SP_M_SBWC_L75"), 0},
220 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC, DECON_PIXEL_FORMAT_NV12M_SBWC_10B, DRM_FORMAT_UNDEFINED,
221 2, 2, 12, YUV420|BIT10|SBWC, false, String8("EXYNOS_YCbCr_420_SP_M_10B_SBWC"), 0},
222 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L40, DECON_PIXEL_FORMAT_NV12M_SBWC_10B_L40, DRM_FORMAT_UNDEFINED,
223 2, 2, 12, YUV420|BIT10|SBWC_LOSSY, false, String8("EXYNOS_YCbCr_420_SP_M_10B_SBWC_L40"), 0},
224 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L60, DECON_PIXEL_FORMAT_NV12M_SBWC_10B_L60, DRM_FORMAT_UNDEFINED,
225 2, 2, 12, YUV420|BIT10|SBWC_LOSSY, false, String8("EXYNOS_YCbCr_420_SP_M_10B_SBWC_L60"), 0},
226 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L80, DECON_PIXEL_FORMAT_NV12M_SBWC_10B_L80, DRM_FORMAT_UNDEFINED,
227 2, 2, 12, YUV420|BIT10|SBWC_LOSSY, false, String8("EXYNOS_YCbCr_420_SP_M_10B_SBWC_L80"), 0},
228
229 /* NV12, YCbCr, Single */
230 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC, DECON_PIXEL_FORMAT_NV12N_SBWC_8B, DRM_FORMAT_NV12,
231 2, 1, 12, YUV420|BIT8|SBWC, false, String8("EXYNOS_YCbCr_420_SPN_SBWC"), 0},
232 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC_L50, DECON_PIXEL_FORMAT_NV12N_SBWC_8B_L50, DRM_FORMAT_NV12,
233 2, 1, 12, YUV420|BIT8|SBWC_LOSSY, false, String8("EXYNOS_YCbCr_420_SPN_SBWC_L50"), 0},
234 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC_L75, DECON_PIXEL_FORMAT_NV12N_SBWC_8B_L75, DRM_FORMAT_NV12,
235 2, 1, 12, YUV420|BIT8|SBWC_LOSSY, false, String8("EXYNOS_YCbCr_420_SPN_SBWC_75"), 0},
236 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC, DECON_PIXEL_FORMAT_NV12N_SBWC_10B, DRM_FORMAT_UNDEFINED,
237 2, 1, 12, YUV420|BIT10|SBWC, false, String8("EXYNOS_YCbCr_420_SPN_10B_SBWC"), 0},
238 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L40, DECON_PIXEL_FORMAT_NV12N_SBWC_10B_L40, DRM_FORMAT_UNDEFINED,
239 2, 1, 12, YUV420|BIT10|SBWC_LOSSY, false, String8("EXYNOS_YCbCr_420_SPN_10B_SBWC_L40"), 0},
240 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L60, DECON_PIXEL_FORMAT_NV12N_SBWC_10B_L60, DRM_FORMAT_UNDEFINED,
241 2, 1, 12, YUV420|BIT10|SBWC_LOSSY, false, String8("EXYNOS_YCbCr_420_SPN_10B_SBWC_L60"), 0},
242 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L80, DECON_PIXEL_FORMAT_NV12N_SBWC_10B_L80, DRM_FORMAT_UNDEFINED,
243 2, 1, 12, YUV420|BIT10|SBWC_LOSSY, false, String8("EXYNOS_YCbCr_420_SPN_10B_SBWC_L80"), 0},
244
245 /* NV12, YCrCb */
246 {HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_SBWC, DECON_PIXEL_FORMAT_NV21M_SBWC_8B, DRM_FORMAT_UNDEFINED,
247 2, 2, 12, YUV420|BIT8|SBWC, false, String8("EXYNOS_YCrCb_420_SP_M_SBWC"), 0},
248 {HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_10B_SBWC, DECON_PIXEL_FORMAT_NV21M_SBWC_10B, DRM_FORMAT_UNDEFINED,
249 2, 2, 12, YUV420|BIT10|SBWC, false, String8("EXYNOS_YCrbCb_420_SP_M_10B_SBWC"), 0},
250
251 {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
252 0, 0, 0, TYPE_UNDEF, false, String8("ImplDef"), 0}
253 };
254
255 constexpr size_t FORMAT_MAX_CNT = sizeof(exynos_format_desc) / sizeof(format_description);
256
257 typedef enum hwc_fdebug_fence_type_t {
258 FENCE_TYPE_SRC_RELEASE = 1,
259 FENCE_TYPE_SRC_ACQUIRE = 2,
260 FENCE_TYPE_DST_RELEASE = 3,
261 FENCE_TYPE_DST_ACQUIRE = 4,
262 FENCE_TYPE_FREE_RELEASE = 5,
263 FENCE_TYPE_FREE_ACQUIRE = 6,
264 FENCE_TYPE_HW_STATE = 7,
265 FENCE_TYPE_RETIRE = 8,
266 FENCE_TYPE_READBACK_ACQUIRE = 9,
267 FENCE_TYPE_READBACK_RELEASE = 10,
268 FENCE_TYPE_ALL = 11,
269 FENCE_TYPE_UNDEFINED = 100
270 } hwc_fdebug_fence_type;
271
272 typedef enum hwc_fdebug_ip_type_t {
273 FENCE_IP_DPP = 0,
274 FENCE_IP_MSC = 1,
275 FENCE_IP_G2D = 2,
276 FENCE_IP_FB = 3,
277 FENCE_IP_LAYER = 4,
278 FENCE_IP_ALL = 5,
279 FENCE_IP_UNDEFINED = 100
280 } hwc_fdebug_ip_type;
281
282 typedef enum hwc_fence_type_t {
283 FENCE_LAYER_RELEASE_DPP = 0,
284 FENCE_LAYER_RELEASE_MPP = 1,
285 FENCE_LAYER_RELEASE_MSC = 2,
286 FENCE_LAYER_RELEASE_G2D = 3,
287 FENCE_DPP_HW_STATE = 4,
288 FENCE_MSC_HW_STATE = 5,
289 FENCE_G2D_HW_STATE = 6,
290 FENCE_MSC_SRC_LAYER = 7,
291 FENCE_G2D_SRC_LAYER = 8,
292 FENCE_MPP_DST_DPP = 9,
293 FENCE_MSC_DST_DPP = 10,
294 FENCE_G2D_DST_DPP = 11,
295 FENCE_DPP_SRC_MPP = 12,
296 FENCE_DPP_SRC_MSC = 13,
297 FENCE_DPP_SRC_G2D = 14,
298 FENCE_DPP_SRC_LAYER = 15,
299 FENCE_MPP_FREE_BUF_ACQUIRE = 16,
300 FENCE_MPP_FREE_BUF_RELEASE = 17,
301 FENCE_RETIRE = 18,
302 FENCE_MAX
303 } hwc_fence_type;
304
305 enum {
306 EXYNOS_ERROR_NONE = 0,
307 EXYNOS_ERROR_CHANGED = 1
308 };
309
310 enum {
311 eSkipLayer = 0x00000001,
312 eInvalidHandle = 0x00000002,
313 eHasFloatSrcCrop = 0x00000004,
314 eUpdateExynosComposition = 0x00000008,
315 eDynamicRecomposition = 0x00000010,
316 eForceFbEnabled = 0x00000020,
317 eSandwitchedBetweenGLES = 0x00000040,
318 eSandwitchedBetweenEXYNOS = 0x00000080,
319 eInsufficientWindow = 0x00000100,
320 eInsufficientMPP = 0x00000200,
321 eSkipStaticLayer = 0x00000400,
322 eUnSupportedUseCase = 0x00000800,
323 eDimLayer = 0x00001000,
324 eResourcePendingWork = 0x00002000,
325 eSkipRotateAnim = 0x00004000,
326 eUnSupportedColorTransform = 0x00008000,
327 eLowFpsLayer = 0x00010000,
328 eReallocOnGoingForDDI = 0x00020000,
329 eInvalidDispFrame = 0x00040000,
330 eExceedMaxLayerNum = 0x00080000,
331 eResourceAssignFail = 0x20000000,
332 eMPPUnsupported = 0x40000000,
333 eUnknown = 0x80000000,
334 };
335
336 enum regionType {
337 eTransparentRegion = 0,
338 eCoveredOpaqueRegion = 1,
339 eDamageRegionByDamage = 2,
340 eDamageRegionByLayer = 3,
341 };
342
343 enum {
344 eDamageRegionFull = 0,
345 eDamageRegionPartial,
346 eDamageRegionSkip,
347 eDamageRegionError,
348 };
349
350 /*
351 * bufferHandle can be NULL if it is not allocated yet
352 * or size or format information can be different between other field values and
353 * member of bufferHandle. This means bufferHandle should be reallocated.
354 * */
355 typedef struct exynos_image {
356 uint32_t fullWidth = 0;
357 uint32_t fullHeight = 0;
358 uint32_t x = 0;
359 uint32_t y = 0;
360 uint32_t w = 0;
361 uint32_t h = 0;
362 uint32_t format= 0;
363 uint64_t usageFlags = 0;
364 uint32_t layerFlags = 0;
365 int acquireFenceFd = -1;
366 int releaseFenceFd = -1;
367 buffer_handle_t bufferHandle = NULL;
368 android_dataspace dataSpace = HAL_DATASPACE_UNKNOWN;
369 uint32_t blending = 0;
370 uint32_t transform = 0;
371 uint32_t compressed = 0;
372 float planeAlpha = 0;
373 uint32_t zOrder = 0;
374 /* refer
375 * frameworks/native/include/media/hardware/VideoAPI.h
376 * frameworks/native/include/media/hardware/HardwareAPI.h */
377 bool hasMetaParcel = false;
378 ExynosVideoMeta metaParcel;
379 ExynosVideoInfoType metaType = VIDEO_INFO_TYPE_INVALID;
380 bool needColorTransform = false;
381
isDimLayerexynos_image382 bool isDimLayer()
383 {
384 if (layerFlags & EXYNOS_HWC_DIM_LAYER)
385 return true;
386 return false;
387 };
388 } exynos_image_t;
389
390 uint32_t getHWC1CompType(int32_t /*hwc2_composition_t*/ type);
391
392 uint32_t getDrmMode(uint64_t flags);
393 uint32_t getDrmMode(const buffer_handle_t handle);
394
WIDTH(const hwc_rect & rect)395 inline int WIDTH(const hwc_rect &rect) { return rect.right - rect.left; }
HEIGHT(const hwc_rect & rect)396 inline int HEIGHT(const hwc_rect &rect) { return rect.bottom - rect.top; }
WIDTH(const hwc_frect_t & rect)397 inline int WIDTH(const hwc_frect_t &rect) { return (int)(rect.right - rect.left); }
HEIGHT(const hwc_frect_t & rect)398 inline int HEIGHT(const hwc_frect_t &rect) { return (int)(rect.bottom - rect.top); }
399
400 const format_description_t *halFormatToExynosFormat(int format, uint32_t compressType);
401
402 uint32_t halDataSpaceToV4L2ColorSpace(android_dataspace data_space);
403 enum decon_pixel_format halFormatToDpuFormat(int format, uint32_t compressType);
404 uint32_t DpuFormatToHalFormat(int format, uint32_t compressType);
405 int halFormatToDrmFormat(int format, uint32_t compressType);
406 int32_t drmFormatToHalFormats(int format, std::vector<uint32_t> *halFormats);
407 int drmFormatToHalFormat(int format);
408 uint8_t formatToBpp(int format);
409 uint8_t DpuFormatToBpp(decon_pixel_format format);
410 uint64_t halTransformToDrmRot(uint32_t halTransform);
411 uint32_t getCompressionType(const buffer_handle_t handle);
412
413 bool isFormatRgb(int format);
414 bool isFormatYUV(int format);
415 bool isFormatYUV420(int format);
416 bool isFormatYUV422(int format);
417 bool isFormatYCrCb(int format);
418 bool isFormatYUV8_2(int format);
419 bool isFormat10BitYUV420(int format);
420 bool isFormatLossy(int format);
421 bool isFormatSBWC(int format);
422 bool isFormatP010(int format);
423 bool formatHasAlphaChannel(int format);
424 unsigned int isNarrowRgb(int format, android_dataspace data_space);
425 bool isAFBCCompressed(const buffer_handle_t handle);
426 bool isSrcCropFloat(hwc_frect &frect);
427 bool isScaled(exynos_image &src, exynos_image &dst);
428 bool isScaledDown(exynos_image &src, exynos_image &dst);
429 bool hasHdrInfo(const exynos_image &img);
430 bool hasHdrInfo(android_dataspace dataSpace);
431 bool hasHdr10Plus(exynos_image &img);
432
433 void dumpExynosImage(uint32_t type, exynos_image &img);
434 void dumpExynosImage(String8& result, exynos_image &img);
435 void dumpHandle(uint32_t type, buffer_handle_t h);
436 void printExynosLayer(const ExynosLayer *layer);
437 String8 getFormatStr(int format, uint32_t compressType);
438 String8 getMPPStr(int typeId);
439 void adjustRect(hwc_rect_t &rect, int32_t width, int32_t height);
440 uint32_t getBufferNumOfFormat(int format, uint32_t compressType);
441 uint32_t getPlaneNumOfFormat(int format, uint32_t compressType);
442 uint32_t getBytePerPixelOfPrimaryPlane(int format);
443
444 int fence_close(int fence, ExynosDisplay* display,
445 hwc_fdebug_fence_type type, hwc_fdebug_ip_type ip);
446 bool fence_valid(int fence);
447
448 int hwcFdClose(int fd);
449 int hwc_dup(int fd, ExynosDisplay *display, hwc_fdebug_fence_type type, hwc_fdebug_ip_type ip,
450 bool pendingAllowed = false);
451 int hwc_print_stack();
452
expand(const hwc_rect & r1,const hwc_rect & r2)453 inline hwc_rect expand(const hwc_rect &r1, const hwc_rect &r2)
454 {
455 hwc_rect i;
456 i.top = min(r1.top, r2.top);
457 i.bottom = max(r1.bottom, r2.bottom);
458 i.left = min(r1.left, r2.left);
459 i.right = max(r1.right, r2.right);
460 return i;
461 }
462
463 template <typename T>
pixel_align_down(const T x,const uint32_t a)464 inline T pixel_align_down(const T x, const uint32_t a) {
465 static_assert(std::numeric_limits<T>::is_integer,
466 "Integer type is expected as the alignment input");
467 return a ? (x / a) * a : x;
468 }
469
470 template <typename T>
pixel_align(const T x,const uint32_t a)471 inline T pixel_align(const T x, const uint32_t a) {
472 static_assert(std::numeric_limits<T>::is_integer,
473 "Integer type is expected as the alignment input");
474 return a ? ((x + a - 1) / a) * a : x;
475 }
476
477 uint32_t getExynosBufferYLength(uint32_t width, uint32_t height, int format);
478 int getBufLength(buffer_handle_t handle, uint32_t planer_num, size_t *length, int format, uint32_t width, uint32_t height);
479
480 //class hwc_fence_info(sync_fence_info_data* data, sync_pt_info* info) {
481 struct tm* getHwcFenceTime();
482
483 enum {
484 FENCE_FROM = 0,
485 FENCE_TO,
486 FENCE_DUP,
487 FENCE_CLOSE,
488 };
489
490 typedef struct fenceTrace {
491 hwc_fdebug_fence_type type;
492 hwc_fdebug_ip_type ip;
493 struct timeval time;
494 int32_t curFlag;
495 } fenceTrace_t;
496
497 typedef struct hwc_fence_info {
498 uint32_t displayId;
499 struct sync_fence_info_data* sync_data;
500 struct sync_pt_info* pt_info;
501 fenceTrace_t from;
502 fenceTrace_t to;
503 fenceTrace_t dup;
504 fenceTrace_t close;
505 int32_t usage;
506 int32_t curFlag;
507 uint32_t last_dir;
508 bool pendingAllowed = false;
509 bool leaking = false;
510 } hwc_fence_info_t;
511
512 class funcReturnCallback {
513 public:
funcReturnCallback(const std::function<void (void)> cb)514 funcReturnCallback(const std::function<void(void)> cb) : mCb(cb) {}
~funcReturnCallback()515 ~funcReturnCallback() { mCb(); }
516 private:
517 const std::function<void(void)> mCb;
518 };
519
520 void setFenceName(int fenceFd, hwc_fence_type fenceType);
521 void setFenceName(uint32_t fd, ExynosDisplay *display,
522 hwc_fdebug_fence_type type, hwc_fdebug_ip_type ip,
523 uint32_t direction, bool pendingAllowed = false);
524 void setFenceInfo(uint32_t fd, ExynosDisplay *display,
525 hwc_fdebug_fence_type type, hwc_fdebug_ip_type ip,
526 uint32_t direction, bool pendingAllowed = false);
527 void printFenceInfo(uint32_t fd, hwc_fence_info_t* info);
528 void dumpFenceInfo(ExynosDisplay *display, int32_t __unused depth);
529 bool fenceWarn(hwc_fence_info_t **info, uint32_t threshold);
530 void resetFenceCurFlag(ExynosDisplay *display);
531 bool fenceWarn(ExynosDisplay *display, uint32_t threshold);
532 void printLeakFds(ExynosDisplay *display);
533 bool validateFencePerFrame(ExynosDisplay *display);
534 android_dataspace colorModeToDataspace(android_color_mode_t mode);
535 bool hasPPC(uint32_t physicalType, uint32_t formatIndex, uint32_t rotIndex);
536
537 class TableBuilder {
538 public:
539 template <typename T>
add(const std::string & key,const T & value)540 TableBuilder& add(const std::string& key, const T& value) {
541 std::stringstream v;
542 v << value;
543 data.emplace_back(std::make_pair(key, v.str()));
544 return *this;
545 }
546
547 template <typename T>
add(const std::string & key,const std::vector<T> & values)548 TableBuilder& add(const std::string& key, const std::vector<T>& values) {
549 std::stringstream value;
550 for (int i = 0; i < values.size(); i++) {
551 if (i) value << ", ";
552 value << values[i];
553 }
554
555 data.emplace_back(std::make_pair(key, value.str()));
556 return *this;
557 }
558
559 // Template overrides for hex integers
560 TableBuilder& add(const std::string& key, const uint64_t& value, bool toHex);
561 TableBuilder& add(const std::string& key, const std::vector<uint64_t>& values, bool toHex);
562
563 std::string build();
564
565 private:
566 std::string buildPaddedString(const std::string& str, int size);
567
568 using StringPairVec = std::vector<std::pair<std::string, std::string>>;
569 StringPairVec data;
570 };
571
572 void writeFileNode(FILE *fd, int value);
573 int32_t writeIntToFile(const char *file, uint32_t value);
574 uint32_t getDisplayId(int32_t displayType, int32_t displayIndex = 0);
575 int32_t load_png_image(const char *filepath, buffer_handle_t buffer);
576
577 template <typename T>
578 struct CtrlValue {
579 public:
storeCtrlValue580 void store(T value) {
581 if (value == value_) return;
582 dirty_ = true;
583 value_ = value;
584 };
getCtrlValue585 const T &get() { return value_; };
is_dirtyCtrlValue586 bool is_dirty() { return dirty_; };
clear_dirtyCtrlValue587 void clear_dirty() { dirty_ = false; };
set_dirtyCtrlValue588 void set_dirty() { dirty_ = true; };
589
590 private:
591 T value_;
592 bool dirty_;
593 };
594
595 #endif
596