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 <aidl/android/hardware/graphics/common/Transform.h>
20 #include <aidl/android/hardware/graphics/composer3/Composition.h>
21 #include <drm/drm_fourcc.h>
22 #include <drm/samsung_drm.h>
23 #include <hardware/hwcomposer2.h>
24 #include <utils/String8.h>
25
26 #include <fstream>
27 #include <list>
28 #include <optional>
29 #include <sstream>
30 #include <string>
31 #include <unordered_map>
32 #include <vector>
33
34 #include "DeconCommonHeader.h"
35 #include "VendorGraphicBuffer.h"
36 #include "VendorVideoAPI.h"
37 #include "exynos_format.h"
38 #include "exynos_sync.h"
39 #include "mali_gralloc_formats.h"
40
41 #define MAX_FENCE_NAME 64
42 #define MAX_FENCE_THRESHOLD 500
43 #define MAX_FD_NUM 1024
44
45 #define MAX_USE_FORMAT 27
46 #ifndef P010M_Y_SIZE
47 #define P010M_Y_SIZE(w,h) (__ALIGN_UP((w), 16) * 2 * __ALIGN_UP((h), 16) + 256)
48 #endif
49 #ifndef P010M_CBCR_SIZE
50 #define P010M_CBCR_SIZE(w,h) ((__ALIGN_UP((w), 16) * 2 * __ALIGN_UP((h), 16) / 2) + 256)
51 #endif
52 #ifndef P010_Y_SIZE
53 #define P010_Y_SIZE(w, h) ((w) * (h) * 2)
54 #endif
55 #ifndef P010_CBCR_SIZE
56 #define P010_CBCR_SIZE(w, h) ((w) * (h))
57 #endif
58 #ifndef DRM_FORMAT_YUV420_8BIT
59 #define DRM_FORMAT_YUV420_8BIT fourcc_code('Y', 'U', '0', '8')
60 #endif
61 #ifndef DRM_FORMAT_YUV420_10BIT
62 #define DRM_FORMAT_YUV420_10BIT fourcc_code('Y', 'U', '1', '0')
63 #endif
64
65 using AidlTransform = ::aidl::android::hardware::graphics::common::Transform;
66
67 static constexpr uint32_t DISPLAYID_MASK_LEN = 8;
68
max(T a,T b)69 template<typename T> inline T max(T a, T b) { return (a > b) ? a : b; }
min(T a,T b)70 template<typename T> inline T min(T a, T b) { return (a < b) ? a : b; }
71
72 class ExynosLayer;
73 class ExynosDisplay;
74
75 using namespace android;
76
77 static constexpr uint32_t TRANSFORM_MAT_SIZE = 4*4;
78
79 enum {
80 EXYNOS_HWC_DIM_LAYER = 1 << 0,
81 EXYNOS_HWC_IGNORE_LAYER = 1 << 1,
82 };
83
84 enum {
85 INTERFACE_TYPE_NONE = 0,
86 INTERFACE_TYPE_FB = 1,
87 INTERFACE_TYPE_DRM = 2,
88 };
89
90 typedef enum format_type {
91 TYPE_UNDEF = 0,
92
93 /* format */
94 FORMAT_SHIFT = 0,
95 FORMAT_MASK = 0x00000fff,
96
97 FORMAT_RGB_MASK = 0x0000000f,
98 RGB = 0x00000001,
99
100 FORMAT_YUV_MASK = 0x000000f0,
101 YUV420 = 0x00000010,
102 YUV422 = 0x00000020,
103 P010 = 0x00000030,
104
105 FORMAT_SBWC_MASK = 0x00000f00,
106 SBWC_LOSSLESS = 0x00000100,
107 SBWC_LOSSY_40 = 0x00000200,
108 SBWC_LOSSY_50 = 0x00000300,
109 SBWC_LOSSY_60 = 0x00000400,
110 SBWC_LOSSY_75 = 0x00000500,
111 SBWC_LOSSY_80 = 0x00000600,
112
113 /* bit */
114 BIT_SHIFT = 16,
115 BIT_MASK = 0x000f0000,
116 BIT8 = 0x00010000,
117 BIT10 = 0x00020000,
118 BIT8_2 = 0x00030000,
119 BIT16 = 0x00040000,
120
121 /* Compression types */
122 /* Caution : This field use bit operations */
123 COMP_SHIFT = 20,
124 COMP_TYPE_MASK = 0x0ff00000,
125 COMP_TYPE_NONE = 0x08000000,
126 COMP_TYPE_AFBC = 0x00100000,
127 COMP_TYPE_SBWC = 0x00200000,
128 } format_type_t;
129
130 typedef struct format_description {
getFormatformat_description131 inline uint32_t getFormat() const { return type & FORMAT_MASK; }
getBitformat_description132 inline uint32_t getBit() const { return type & BIT_MASK; }
isCompressionSupportedformat_description133 inline bool isCompressionSupported(uint32_t inType) const {
134 return (type & inType) != 0 ? true : false;
135 }
136 int halFormat;
137 decon_pixel_format s3cFormat;
138 int drmFormat;
139 uint32_t planeNum;
140 uint32_t bufferNum;
141 uint8_t bpp;
142 uint32_t type;
143 bool hasAlpha;
144 String8 name;
145 uint32_t reserved;
146 } format_description_t;
147
148 constexpr int HAL_PIXEL_FORMAT_EXYNOS_UNDEFINED = 0;
149 constexpr int DRM_FORMAT_UNDEFINED = 0;
150
151 // clang-format off
152 const format_description_t exynos_format_desc[] = {
153 /* RGB */
154 {HAL_PIXEL_FORMAT_RGBA_8888, DECON_PIXEL_FORMAT_RGBA_8888, DRM_FORMAT_RGBA8888,
155 1, 1, 32, RGB | BIT8 | COMP_TYPE_NONE | COMP_TYPE_AFBC, true, String8("RGBA_8888"), 0},
156 {HAL_PIXEL_FORMAT_RGBX_8888, DECON_PIXEL_FORMAT_RGBX_8888, DRM_FORMAT_RGBX8888,
157 1, 1, 32, RGB | BIT8 | COMP_TYPE_NONE | COMP_TYPE_AFBC, false, String8("RGBx_8888"), 0},
158 {HAL_PIXEL_FORMAT_RGB_888, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_RGB888,
159 1, 1, 24, RGB | BIT8 | COMP_TYPE_NONE | COMP_TYPE_AFBC, false, String8("RGB_888"), 0},
160 {HAL_PIXEL_FORMAT_RGB_565, DECON_PIXEL_FORMAT_RGB_565, DRM_FORMAT_BGR565,
161 1, 1, 16, RGB | COMP_TYPE_NONE, false, String8("RGB_565"), 0},
162 {HAL_PIXEL_FORMAT_RGB_565, DECON_PIXEL_FORMAT_RGB_565, DRM_FORMAT_RGB565,
163 1, 1, 16, RGB | COMP_TYPE_AFBC, false, String8("RGB_565_AFBC"), 0},
164 {HAL_PIXEL_FORMAT_BGRA_8888, DECON_PIXEL_FORMAT_BGRA_8888, DRM_FORMAT_BGRA8888,
165 1, 1, 32, RGB | BIT8 | COMP_TYPE_NONE | COMP_TYPE_AFBC, true, String8("BGRA_8888"), 0},
166 {HAL_PIXEL_FORMAT_RGBA_1010102, DECON_PIXEL_FORMAT_ABGR_2101010, DRM_FORMAT_RGBA1010102,
167 1, 1, 32, RGB | BIT10 | COMP_TYPE_NONE | COMP_TYPE_AFBC, true, String8("RGBA_1010102"), 0},
168 {HAL_PIXEL_FORMAT_EXYNOS_ARGB_8888, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_ARGB8888,
169 1, 1, 32, RGB | BIT8 | COMP_TYPE_NONE | COMP_TYPE_AFBC, true, String8("EXYNOS_ARGB_8888"), 0},
170 //FIXME: can't support FP16 with extended. remove it for now. b/320584418
171 /* {HAL_PIXEL_FORMAT_RGBA_FP16, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_ABGR16161616F,
172 1, 1, 64, RGB | BIT16 | COMP_TYPE_NONE | COMP_TYPE_AFBC, true, String8("RGBA_FP16"), 0},*/
173
174 /* YUV 420 */
175 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_P_M, DECON_PIXEL_FORMAT_YUV420M, DRM_FORMAT_UNDEFINED,
176 3, 3, 12, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_YCbCr_420_P_M"), 0},
177 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M, DECON_PIXEL_FORMAT_NV12M, DRM_FORMAT_NV12,
178 2, 2, 12, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_YCbCr_420_SP_M"), 0},
179 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_TILED, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
180 2, 2, 12, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_YCbCr_420_SP_M_TILED"), 0},
181 {HAL_PIXEL_FORMAT_EXYNOS_YV12_M, DECON_PIXEL_FORMAT_YVU420M, DRM_FORMAT_UNDEFINED,
182 3, 3, 12, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_YV12_M"), 0},
183 {HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M, DECON_PIXEL_FORMAT_NV21M, DRM_FORMAT_NV21,
184 2, 2, 12, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_YCrCb_420_SP_M"), 0},
185 {HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_FULL, DECON_PIXEL_FORMAT_NV21M, DRM_FORMAT_NV21,
186 2, 2, 12, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_YCrCb_420_SP_M_FULL"), 0},
187 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_P, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
188 3, 1, 0, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_YCbCr_420_P"), 0},
189 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
190 2, 1, 0, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_YCbCr_420_SP"), 0},
191 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_PRIV, DECON_PIXEL_FORMAT_NV12M, DRM_FORMAT_NV12,
192 2, 2, 12, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_YCbCr_420_SP_M_PRIV"), 0},
193 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_PN, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
194 3, 1, 12, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_YCbCr_420_PN"), 0},
195 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN, DECON_PIXEL_FORMAT_NV12N, DRM_FORMAT_NV12,
196 2, 1, 12, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_YCbCr_420_SPN"), 0},
197 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_TILED, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
198 2, 1, 12, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_YCbCr_420_SPN_TILED"), 0},
199 {HAL_PIXEL_FORMAT_YCrCb_420_SP, DECON_PIXEL_FORMAT_NV21, DRM_FORMAT_NV21,
200 2, 1, 12, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("YCrCb_420_SP"), 0},
201 {HAL_PIXEL_FORMAT_YV12, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
202 3, 1, 12, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("YV12"), 0},
203 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_S10B, DECON_PIXEL_FORMAT_NV12M_S10B, DRM_FORMAT_UNDEFINED,
204 2, 2, 12, YUV420 | BIT10 | BIT8_2 | COMP_TYPE_NONE, false, String8("EXYNOS_YCbCr_420_SP_M_S10B"), 0},
205 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_S10B, DECON_PIXEL_FORMAT_NV12N_10B, DRM_FORMAT_UNDEFINED,
206 2, 1, 12, YUV420 | BIT10 | BIT8_2 | COMP_TYPE_NONE, false, String8("EXYNOS_YCbCr_420_SPN_S10B"), 0},
207 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_P010_M, DECON_PIXEL_FORMAT_NV12M_P010, DRM_FORMAT_P010,
208 2, 2, 24, YUV420 | BIT10 | P010 | COMP_TYPE_NONE, false, String8("EXYNOS_YCbCr_P010_M"), 0},
209 {HAL_PIXEL_FORMAT_YCBCR_P010, DECON_PIXEL_FORMAT_NV12_P010, DRM_FORMAT_P010,
210 2, 1, 24, YUV420 | BIT10 | P010 | COMP_TYPE_NONE, false, String8("EXYNOS_YCbCr_P010"), 0},
211 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_P010_SPN, DECON_PIXEL_FORMAT_NV12_P010, DRM_FORMAT_P010,
212 2, 1, 24, YUV420 | BIT10 | P010 | COMP_TYPE_NONE, false, String8("EXYNOS_YCbCr_P010_SPN"), 0},
213 {MALI_GRALLOC_FORMAT_INTERNAL_P010, DECON_PIXEL_FORMAT_NV12_P010, DRM_FORMAT_P010,
214 2, 1, 24, YUV420 | BIT10 | P010 | COMP_TYPE_NONE, false, String8("MALI_GRALLOC_FORMAT_INTERNAL_P010"), 0},
215
216 {HAL_PIXEL_FORMAT_GOOGLE_NV12_SP, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_NV12,
217 2, 1, 12, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("GOOGLE_YCbCr_420_SP"), 0},
218 {HAL_PIXEL_FORMAT_GOOGLE_NV12_SP_10B, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_P010,
219 2, 1, 24, YUV420 | BIT10 | COMP_TYPE_NONE, false, String8("GOOGLE_YCbCr_P010"), 0},
220 {MALI_GRALLOC_FORMAT_INTERNAL_YUV420_8BIT_I, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_YUV420_8BIT,
221 1, 1, 12, YUV420 | BIT8 | COMP_TYPE_AFBC, false, String8("MALI_GRALLOC_FORMAT_INTERNAL_YUV420_8BIT_I"), 0},
222 {MALI_GRALLOC_FORMAT_INTERNAL_YUV420_10BIT_I, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_YUV420_10BIT,
223 1, 1, 15, YUV420 | BIT10 | COMP_TYPE_AFBC, false, String8("MALI_GRALLOC_FORMAT_INTERNAL_YUV420_10BIT_I"), 0},
224 {MALI_GRALLOC_FORMAT_INTERNAL_NV21, DECON_PIXEL_FORMAT_NV21, DRM_FORMAT_NV21,
225 2, 1, 12, YUV420 | BIT8 | COMP_TYPE_NONE, false, String8("MALI_GRALLOC_FORMAT_INTERNAL_NV21"), 0},
226
227 /* YUV 422 */
228 {HAL_PIXEL_FORMAT_EXYNOS_CbYCrY_422_I, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
229 0, 0, 0, YUV422 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_CbYCrY_422_I"), 0},
230 {HAL_PIXEL_FORMAT_EXYNOS_YCrCb_422_SP, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
231 0, 0, 0, YUV422 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_YCrCb_422_SP"), 0},
232 {HAL_PIXEL_FORMAT_EXYNOS_YCrCb_422_I, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
233 0, 0, 0, YUV422 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_YCrCb_422_I"), 0},
234 {HAL_PIXEL_FORMAT_EXYNOS_CrYCbY_422_I, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
235 0, 0, 0, YUV422 | BIT8 | COMP_TYPE_NONE, false, String8("EXYNOS_CrYCbY_422_I"), 0},
236
237 /* SBWC formats */
238 /* NV12, YCbCr, Multi */
239 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC, DECON_PIXEL_FORMAT_NV12M_SBWC_8B, DRM_FORMAT_NV12,
240 2, 2, 12, YUV420 | BIT8 | COMP_TYPE_SBWC | SBWC_LOSSLESS, false, String8("EXYNOS_YCbCr_420_SP_M_SBWC"), 0},
241 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L50, DECON_PIXEL_FORMAT_NV12M_SBWC_8B_L50, DRM_FORMAT_NV12,
242 2, 2, 12, YUV420 | BIT8 | COMP_TYPE_SBWC | SBWC_LOSSY_50, false, String8("EXYNOS_YCbCr_420_SP_M_SBWC_L50"), 0},
243 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L75, DECON_PIXEL_FORMAT_NV12M_SBWC_8B_L75, DRM_FORMAT_NV12,
244 2, 2, 12, YUV420 | BIT8 | COMP_TYPE_SBWC | SBWC_LOSSY_75, false, String8("EXYNOS_YCbCr_420_SP_M_SBWC_L75"), 0},
245 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC, DECON_PIXEL_FORMAT_NV12M_SBWC_10B, DRM_FORMAT_UNDEFINED,
246 2, 2, 12, YUV420 | BIT10 | COMP_TYPE_SBWC | SBWC_LOSSLESS, false, String8("EXYNOS_YCbCr_420_SP_M_10B_SBWC"), 0},
247 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L40, DECON_PIXEL_FORMAT_NV12M_SBWC_10B_L40, DRM_FORMAT_UNDEFINED,
248 2, 2, 12, YUV420 | BIT10 | COMP_TYPE_SBWC | SBWC_LOSSY_40, false, String8("EXYNOS_YCbCr_420_SP_M_10B_SBWC_L40"), 0},
249 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L60, DECON_PIXEL_FORMAT_NV12M_SBWC_10B_L60, DRM_FORMAT_UNDEFINED,
250 2, 2, 12, YUV420 | BIT10 | COMP_TYPE_SBWC | SBWC_LOSSY_60, false, String8("EXYNOS_YCbCr_420_SP_M_10B_SBWC_L60"), 0},
251 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L80, DECON_PIXEL_FORMAT_NV12M_SBWC_10B_L80, DRM_FORMAT_UNDEFINED,
252 2, 2, 12, YUV420 | BIT10 | COMP_TYPE_SBWC | SBWC_LOSSY_80, false, String8("EXYNOS_YCbCr_420_SP_M_10B_SBWC_L80"), 0},
253
254 /* NV12, YCbCr, Single */
255 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC, DECON_PIXEL_FORMAT_NV12N_SBWC_8B, DRM_FORMAT_NV12,
256 2, 1, 12, YUV420 | BIT8 | COMP_TYPE_SBWC | SBWC_LOSSLESS, false, String8("EXYNOS_YCbCr_420_SPN_SBWC"), 0},
257 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC_L50, DECON_PIXEL_FORMAT_NV12N_SBWC_8B_L50, DRM_FORMAT_NV12,
258 2, 1, 12, YUV420 | BIT8 | COMP_TYPE_SBWC | SBWC_LOSSY_50, false, String8("EXYNOS_YCbCr_420_SPN_SBWC_L50"), 0},
259 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_SBWC_L75, DECON_PIXEL_FORMAT_NV12N_SBWC_8B_L75, DRM_FORMAT_NV12,
260 2, 1, 12, YUV420 | BIT8 | COMP_TYPE_SBWC | SBWC_LOSSY_75, false, String8("EXYNOS_YCbCr_420_SPN_SBWC_75"), 0},
261 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC, DECON_PIXEL_FORMAT_NV12N_SBWC_10B, DRM_FORMAT_UNDEFINED,
262 2, 1, 12, YUV420 | BIT10 | COMP_TYPE_SBWC | SBWC_LOSSLESS, false, String8("EXYNOS_YCbCr_420_SPN_10B_SBWC"), 0},
263 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L40, DECON_PIXEL_FORMAT_NV12N_SBWC_10B_L40, DRM_FORMAT_UNDEFINED,
264 2, 1, 12, YUV420 | BIT10 | COMP_TYPE_SBWC | SBWC_LOSSY_40, false, String8("EXYNOS_YCbCr_420_SPN_10B_SBWC_L40"), 0},
265 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L60, DECON_PIXEL_FORMAT_NV12N_SBWC_10B_L60, DRM_FORMAT_UNDEFINED,
266 2, 1, 12, YUV420 | BIT10 | COMP_TYPE_SBWC | SBWC_LOSSY_60, false, String8("EXYNOS_YCbCr_420_SPN_10B_SBWC_L60"), 0},
267 {HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_10B_SBWC_L80, DECON_PIXEL_FORMAT_NV12N_SBWC_10B_L80, DRM_FORMAT_UNDEFINED,
268 2, 1, 12, YUV420 | BIT10 | COMP_TYPE_SBWC | SBWC_LOSSY_80, false, String8("EXYNOS_YCbCr_420_SPN_10B_SBWC_L80"), 0},
269
270 /* NV12, YCrCb */
271 {HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_SBWC, DECON_PIXEL_FORMAT_NV21M_SBWC_8B, DRM_FORMAT_UNDEFINED,
272 2, 2, 12, YUV420 | BIT8 | COMP_TYPE_SBWC | SBWC_LOSSLESS, false, String8("EXYNOS_YCrCb_420_SP_M_SBWC"), 0},
273 {HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_10B_SBWC, DECON_PIXEL_FORMAT_NV21M_SBWC_10B, DRM_FORMAT_UNDEFINED,
274 2, 2, 12, YUV420 | BIT10 | COMP_TYPE_SBWC | SBWC_LOSSLESS, false, String8("EXYNOS_YCrbCb_420_SP_M_10B_SBWC"), 0},
275
276 {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_UNDEFINED,
277 0, 0, 0, TYPE_UNDEF | COMP_TYPE_NONE, false, String8("ImplDef"), 0},
278
279 {HAL_PIXEL_FORMAT_GOOGLE_R_8, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_C8,
280 1, 1, 8, RGB | BIT8 | COMP_TYPE_NONE, true, String8("GOOGLE_R_8"), 0},
281 };
282 // clang-format on
283
284 constexpr size_t FORMAT_MAX_CNT = sizeof(exynos_format_desc) / sizeof(format_description);
285
286 enum HwcFdebugFenceType {
287 FENCE_TYPE_SRC_RELEASE = 1,
288 FENCE_TYPE_SRC_ACQUIRE = 2,
289 FENCE_TYPE_DST_RELEASE = 3,
290 FENCE_TYPE_DST_ACQUIRE = 4,
291 FENCE_TYPE_FREE_RELEASE = 5,
292 FENCE_TYPE_FREE_ACQUIRE = 6,
293 FENCE_TYPE_HW_STATE = 7,
294 FENCE_TYPE_RETIRE = 8,
295 FENCE_TYPE_READBACK_ACQUIRE = 9,
296 FENCE_TYPE_READBACK_RELEASE = 10,
297 FENCE_TYPE_ALL = 11,
298 FENCE_TYPE_UNDEFINED = 100
299 };
300
301 enum HwcFdebugIpType {
302 FENCE_IP_DPP = 0,
303 FENCE_IP_MSC = 1,
304 FENCE_IP_G2D = 2,
305 FENCE_IP_FB = 3,
306 FENCE_IP_LAYER = 4,
307 FENCE_IP_ALL = 5,
308 FENCE_IP_UNDEFINED = 100
309 };
310
311 enum HwcFenceType {
312 FENCE_LAYER_RELEASE_DPP = 0,
313 FENCE_LAYER_RELEASE_MPP = 1,
314 FENCE_LAYER_RELEASE_MSC = 2,
315 FENCE_LAYER_RELEASE_G2D = 3,
316 FENCE_DPP_HW_STATE = 4,
317 FENCE_MSC_HW_STATE = 5,
318 FENCE_G2D_HW_STATE = 6,
319 FENCE_MSC_SRC_LAYER = 7,
320 FENCE_G2D_SRC_LAYER = 8,
321 FENCE_MPP_DST_DPP = 9,
322 FENCE_MSC_DST_DPP = 10,
323 FENCE_G2D_DST_DPP = 11,
324 FENCE_DPP_SRC_MPP = 12,
325 FENCE_DPP_SRC_MSC = 13,
326 FENCE_DPP_SRC_G2D = 14,
327 FENCE_DPP_SRC_LAYER = 15,
328 FENCE_MPP_FREE_BUF_ACQUIRE = 16,
329 FENCE_MPP_FREE_BUF_RELEASE = 17,
330 FENCE_RETIRE = 18,
331 FENCE_MAX
332 };
333
334 enum {
335 EXYNOS_ERROR_NONE = 0,
336 EXYNOS_ERROR_CHANGED = 1
337 };
338
339 enum {
340 eForceBySF = 0x00000001,
341 eInvalidHandle = 0x00000002,
342 eHasFloatSrcCrop = 0x00000004,
343 eUpdateExynosComposition = 0x00000008,
344 eDynamicRecomposition = 0x00000010,
345 eForceFbEnabled = 0x00000020,
346 eSandwichedBetweenGLES = 0x00000040,
347 eSandwichedBetweenEXYNOS = 0x00000080,
348 eInsufficientWindow = 0x00000100,
349 eInsufficientMPP = 0x00000200,
350 eSkipStaticLayer = 0x00000400,
351 eUnSupportedUseCase = 0x00000800,
352 eDimLayer = 0x00001000,
353 eResourcePendingWork = 0x00002000,
354 eSkipRotateAnim = 0x00004000,
355 eUnSupportedColorTransform = 0x00008000,
356 eLowFpsLayer = 0x00010000,
357 eReallocOnGoingForDDI = 0x00020000,
358 eInvalidDispFrame = 0x00040000,
359 eExceedMaxLayerNum = 0x00080000,
360 eExceedSdrDimRatio = 0x00100000,
361 eIgnoreLayer = 0x00200000,
362 eSkipStartFrame = 0x008000000,
363 eResourceAssignFail = 0x20000000,
364 eMPPUnsupported = 0x40000000,
365 eUnknown = 0x80000000,
366 };
367
368 enum regionType {
369 eTransparentRegion = 0,
370 eCoveredOpaqueRegion = 1,
371 eDamageRegionByDamage = 2,
372 eDamageRegionByLayer = 3,
373 };
374
375 enum {
376 eDamageRegionFull = 0,
377 eDamageRegionPartial,
378 eDamageRegionSkip,
379 eDamageRegionError,
380 };
381
382 struct CompressionInfo {
383 uint32_t type = COMP_TYPE_NONE;
384 uint64_t modifier = 0;
385 };
386
387 /*
388 * bufferHandle can be NULL if it is not allocated yet
389 * or size or format information can be different between other field values and
390 * member of bufferHandle. This means bufferHandle should be reallocated.
391 * */
392 typedef struct exynos_image {
393 uint32_t fullWidth = 0;
394 uint32_t fullHeight = 0;
395 uint32_t x = 0;
396 uint32_t y = 0;
397 uint32_t w = 0;
398 uint32_t h = 0;
399 uint32_t format= 0;
400 uint64_t usageFlags = 0;
401 uint32_t layerFlags = 0;
402 int acquireFenceFd = -1;
403 int releaseFenceFd = -1;
404 buffer_handle_t bufferHandle = NULL;
405 android_dataspace dataSpace = HAL_DATASPACE_UNKNOWN;
406 uint32_t blending = 0;
407 uint32_t transform = 0;
408 CompressionInfo compressionInfo;
409 float planeAlpha = 0;
410 uint32_t zOrder = 0;
411 /* refer
412 * frameworks/native/include/media/hardware/VideoAPI.h
413 * frameworks/native/include/media/hardware/HardwareAPI.h */
414 bool hasMetaParcel = false;
415 ExynosVideoMeta metaParcel;
416 ExynosVideoInfoType metaType = VIDEO_INFO_TYPE_INVALID;
417 bool needColorTransform = false;
418 bool needPreblending = false;
419
isDimLayerexynos_image420 bool isDimLayer()
421 {
422 if (layerFlags & EXYNOS_HWC_DIM_LAYER)
423 return true;
424 return false;
425 };
426 } exynos_image_t;
427
428 uint32_t getHWC1CompType(int32_t /*hwc2_composition_t*/ type);
429
430 uint32_t getDrmMode(uint64_t flags);
431 uint32_t getDrmMode(const buffer_handle_t handle);
432
WIDTH(const hwc_rect & rect)433 inline int WIDTH(const hwc_rect &rect) { return rect.right - rect.left; }
HEIGHT(const hwc_rect & rect)434 inline int HEIGHT(const hwc_rect &rect) { return rect.bottom - rect.top; }
WIDTH(const hwc_frect_t & rect)435 inline int WIDTH(const hwc_frect_t &rect) { return (int)(rect.right - rect.left); }
HEIGHT(const hwc_frect_t & rect)436 inline int HEIGHT(const hwc_frect_t &rect) { return (int)(rect.bottom - rect.top); }
437
438 const format_description_t *halFormatToExynosFormat(int format, uint32_t compressType);
439
440 uint32_t halDataSpaceToV4L2ColorSpace(android_dataspace data_space);
441 enum decon_pixel_format halFormatToDpuFormat(int format, uint32_t compressType);
442 uint32_t DpuFormatToHalFormat(int format, uint32_t compressType);
443 int halFormatToDrmFormat(int format, uint32_t compressType);
444 int32_t drmFormatToHalFormats(int format, std::vector<uint32_t> *halFormats);
445 int drmFormatToHalFormat(int format);
446 uint8_t formatToBpp(int format);
447 uint8_t DpuFormatToBpp(decon_pixel_format format);
448 uint64_t halTransformToDrmRot(uint32_t halTransform);
449
450 bool isAFBCCompressed(const buffer_handle_t handle);
451 bool isSBWCCompressed(const buffer_handle_t handle);
452 uint32_t getFormat(const buffer_handle_t handle);
453 uint64_t getFormatModifier(const buffer_handle_t handle);
454 uint32_t getCompressionType(const buffer_handle_t handle);
455 CompressionInfo getCompressionInfo(buffer_handle_t handle);
456 String8 getCompressionStr(CompressionInfo compression);
457 bool isAFBC32x8(CompressionInfo compression);
458
459 bool isFormatRgb(int format);
460 bool isFormatYUV(int format);
461 bool isFormatYUV420(int format);
462 bool isFormatYUV422(int format);
463 bool isFormatYCrCb(int format);
464 bool isFormatYUV8_2(int format);
465 bool isFormat10BitYUV420(int format);
466 bool isFormatLossy(int format);
467 bool isFormatSBWC(int format);
468 bool isFormatP010(int format);
469 bool isFormat10Bit(int format);
470 bool isFormat8Bit(int format);
471 bool formatHasAlphaChannel(int format);
472 unsigned int isNarrowRgb(int format, android_dataspace data_space);
473 bool isSrcCropFloat(hwc_frect &frect);
474 bool isScaled(exynos_image &src, exynos_image &dst);
475 bool isScaledDown(exynos_image &src, exynos_image &dst);
476 bool hasHdrInfo(const exynos_image &img);
477 bool hasHdrInfo(android_dataspace dataSpace);
478 bool hasHdr10Plus(exynos_image &img);
479
480 void dumpExynosImage(uint32_t type, exynos_image &img);
481 void dumpExynosImage(String8& result, const exynos_image& img);
482 void dumpHandle(uint32_t type, buffer_handle_t h);
483 void printExynosLayer(const ExynosLayer *layer);
484 String8 getFormatStr(int format, uint32_t compressType);
485 String8 getMPPStr(int typeId);
486 void adjustRect(hwc_rect_t &rect, int32_t width, int32_t height);
487 uint32_t getBufferNumOfFormat(int format, uint32_t compressType);
488 uint32_t getPlaneNumOfFormat(int format, uint32_t compressType);
489 uint32_t getBytePerPixelOfPrimaryPlane(int format);
490
491 int fence_close(int fence, ExynosDisplay *display, HwcFdebugFenceType type, HwcFdebugIpType ip);
492 bool fence_valid(int fence);
493
494 int hwcFdClose(int fd);
495 int hwc_dup(int fd, ExynosDisplay *display, HwcFdebugFenceType type, HwcFdebugIpType ip,
496 bool pendingAllowed = false);
497 int hwc_print_stack();
498
expand(const hwc_rect & r1,const hwc_rect & r2)499 inline hwc_rect expand(const hwc_rect &r1, const hwc_rect &r2)
500 {
501 hwc_rect i;
502 i.top = min(r1.top, r2.top);
503 i.bottom = max(r1.bottom, r2.bottom);
504 i.left = min(r1.left, r2.left);
505 i.right = max(r1.right, r2.right);
506 return i;
507 }
508
509 template <typename T>
pixel_align_down(const T x,const uint32_t a)510 inline T pixel_align_down(const T x, const uint32_t a) {
511 static_assert(std::numeric_limits<T>::is_integer,
512 "Integer type is expected as the alignment input");
513 return a ? (x / a) * a : x;
514 }
515
516 template <typename T>
pixel_align(const T x,const uint32_t a)517 inline T pixel_align(const T x, const uint32_t a) {
518 static_assert(std::numeric_limits<T>::is_integer,
519 "Integer type is expected as the alignment input");
520 return a ? ((x + a - 1) / a) * a : x;
521 }
522
523 uint32_t getExynosBufferYLength(uint32_t width, uint32_t height, int format);
524 int getBufLength(buffer_handle_t handle, uint32_t planer_num, size_t *length, int format, uint32_t width, uint32_t height);
525
526 enum class HwcFenceDirection {
527 FROM = 0,
528 TO,
529 DUP,
530 CLOSE,
531 UPDATE,
532 };
533
534 struct HwcFenceTrace {
535 HwcFenceDirection direction = HwcFenceDirection::FROM;
536 HwcFdebugFenceType type = FENCE_TYPE_UNDEFINED;
537 HwcFdebugIpType ip = FENCE_IP_UNDEFINED;
538 struct timeval time = {0, 0};
539 };
540
541 struct HwcFenceInfo {
542 uint32_t displayId = HWC_DISPLAY_PRIMARY;
543 int32_t usage = 0;
544 int32_t dupFrom = -1;
545 bool pendingAllowed = false;
546 bool leaking = false;
547 std::list<HwcFenceTrace> traces = {};
548 };
549
550 class funcReturnCallback {
551 public:
funcReturnCallback(const std::function<void (void)> cb)552 funcReturnCallback(const std::function<void(void)> cb) : mCb(cb) {}
~funcReturnCallback()553 ~funcReturnCallback() { mCb(); }
554
555 private:
556 const std::function<void(void)> mCb;
557 };
558
559 String8 getLocalTimeStr(struct timeval tv);
560
561 void setFenceName(int fenceFd, HwcFenceType fenceType);
562 void setFenceInfo(uint32_t fd, const ExynosDisplay *display, HwcFdebugFenceType type,
563 HwcFdebugIpType ip, HwcFenceDirection direction, bool pendingAllowed = false,
564 int32_t dupFrom = -1);
565
566 class FenceTracker {
567 public:
568 void updateFenceInfo(uint32_t fd, const ExynosDisplay *display, HwcFdebugFenceType type,
569 HwcFdebugIpType ip, HwcFenceDirection direction,
570 bool pendingAllowed = false, int32_t dupFrom = -1);
571 bool validateFences(ExynosDisplay *display);
572
573 private:
574 void printLastFenceInfoLocked(uint32_t fd) REQUIRES(mFenceMutex);
575 void dumpFenceInfoLocked(int32_t count) REQUIRES(mFenceMutex);
576 void printLeakFdsLocked() REQUIRES(mFenceMutex);
577 void dumpNCheckLeakLocked() REQUIRES(mFenceMutex);
578 bool fenceWarnLocked(uint32_t threshold) REQUIRES(mFenceMutex);
579 bool validateFencePerFrameLocked(const ExynosDisplay *display) REQUIRES(mFenceMutex);
580 int32_t saveFenceTraceLocked(ExynosDisplay *display) REQUIRES(mFenceMutex);
581
582 std::map<int, HwcFenceInfo> mFenceInfos GUARDED_BY(mFenceMutex);
583 mutable std::mutex mFenceMutex;
584 };
585
586 android_dataspace colorModeToDataspace(android_color_mode_t mode);
587 bool hasPPC(uint32_t physicalType, uint32_t formatIndex, uint32_t rotIndex);
588
589 class TableBuilder {
590 public:
recordKeySequence(const std::string & key)591 void recordKeySequence(const std::string& key) {
592 if (kToVs.find(key) == kToVs.end()) keys.push_back(key);
593 }
594 template <typename T>
addKeyValue(const std::string & key,const T & value)595 TableBuilder& addKeyValue(const std::string& key, const T& value) {
596 recordKeySequence(key);
597 std::stringstream v;
598 v << value;
599 kToVs[key].emplace_back(v.str());
600 return *this;
601 }
602
603 template <typename T>
addKeyValue(const std::string & key,const std::vector<T> & values)604 TableBuilder& addKeyValue(const std::string& key, const std::vector<T>& values) {
605 recordKeySequence(key);
606 std::stringstream value;
607 for (int i = 0; i < values.size(); i++) {
608 if (i) value << ", ";
609 value << values[i];
610 }
611
612 kToVs[key].emplace_back(value.str());
613 return *this;
614 }
615
616 // Template overrides for hex integers
617 TableBuilder& addKeyValue(const std::string& key, const uint64_t& value, bool toHex);
618 TableBuilder& addKeyValue(const std::string& key, const std::vector<uint64_t>& values,
619 bool toHex);
620
621 template <typename T>
add(const std::string & key,const T & value)622 TableBuilder& add(const std::string& key, const T& value) {
623 std::stringstream v;
624 v << value;
625 data.emplace_back(std::make_pair(key, v.str()));
626 return *this;
627 }
628
629 template <typename T>
add(const std::string & key,const std::vector<T> & values)630 TableBuilder& add(const std::string& key, const std::vector<T>& values) {
631 std::stringstream value;
632 for (int i = 0; i < values.size(); i++) {
633 if (i) value << ", ";
634 value << values[i];
635 }
636
637 data.emplace_back(std::make_pair(key, value.str()));
638 return *this;
639 }
640
641 // Template overrides for hex integers
642 TableBuilder& add(const std::string& key, const uint64_t& value, bool toHex);
643 TableBuilder& add(const std::string& key, const std::vector<uint64_t>& values, bool toHex);
644
645 std::string build();
646 std::string buildForMiniDump();
647
648 private:
649 std::string buildPaddedString(const std::string& str, int size);
650
651 using StringPairVec = std::vector<std::pair<std::string, std::string>>;
652 StringPairVec data;
653
654 std::vector<std::string> keys;
655 std::map<std::string, std::vector<std::string>> kToVs;
656 };
657
658 void writeFileNode(FILE *fd, int value);
659 int32_t writeIntToFile(const char *file, uint32_t value);
getDisplayId(int32_t displayType,int32_t displayIndex)660 constexpr uint32_t getDisplayId(int32_t displayType, int32_t displayIndex) {
661 return (displayType << DISPLAYID_MASK_LEN) | displayIndex;
662 }
663
664 int32_t load_png_image(const char *filepath, buffer_handle_t buffer);
665 int readLineFromFile(const std::string &filename, std::string &out, char delim);
666
667 template <typename T>
668 struct CtrlValue {
669 public:
CtrlValueCtrlValue670 CtrlValue() : value_(), dirty_(false) {}
CtrlValueCtrlValue671 CtrlValue(const T& value) : value_(value), dirty_(false) {}
672
storeCtrlValue673 void store(const T& value) {
674 if (value == value_) return;
675 dirty_ = true;
676 value_ = value;
677 };
678
storeCtrlValue679 void store(T&& value) {
680 if (value == value_) return;
681 dirty_ = true;
682 value_ = std::move(value);
683 };
684
getCtrlValue685 const T &get() { return value_; };
is_dirtyCtrlValue686 bool is_dirty() { return dirty_; };
clear_dirtyCtrlValue687 void clear_dirty() { dirty_ = false; };
set_dirtyCtrlValue688 void set_dirty() { dirty_ = true; };
resetCtrlValue689 void reset(T value) { value_ = value; dirty_ = false; }
690 private:
691 T value_;
692 bool dirty_;
693 };
694
695 template <typename T>
toUnderlying(T v)696 constexpr typename std::underlying_type<T>::type toUnderlying(T v) {
697 return static_cast<typename std::underlying_type<T>::type>(v);
698 }
699
700 template <size_t bufferSize>
701 struct RollingAverage {
702 std::array<int64_t, bufferSize> buffer{0};
703 int64_t total = 0;
704 int64_t average;
705 size_t elems = 0;
706 size_t buffer_index = 0;
insertRollingAverage707 void insert(int64_t newTime) {
708 total += newTime - buffer[buffer_index];
709 buffer[buffer_index] = newTime;
710 buffer_index = (buffer_index + 1) % bufferSize;
711 elems = std::min(elems + 1, bufferSize);
712 average = total / elems;
713 }
714 };
715
716 // Waits for a given property value, or returns std::nullopt if unavailable
717 std::optional<std::string> waitForPropertyValue(const std::string &property, int64_t timeoutMs);
718
719 uint32_t rectSize(const hwc_rect_t &rect);
720 void assign(decon_win_rect &win_rect, uint32_t left, uint32_t right, uint32_t width,
721 uint32_t height);
722 uint32_t nanoSec2Hz(uint64_t ns);
723
transOvlInfoToString(const int32_t ovlInfo)724 inline std::string transOvlInfoToString(const int32_t ovlInfo) {
725 std::string ret;
726 if (ovlInfo & eForceBySF) ret += "ForceBySF ";
727 if (ovlInfo & eInvalidHandle) ret += "InvalidHandle ";
728 if (ovlInfo & eHasFloatSrcCrop) ret += "FloatSrcCrop ";
729 if (ovlInfo & eUpdateExynosComposition) ret += "ExyComp ";
730 if (ovlInfo & eDynamicRecomposition) ret += "DR ";
731 if (ovlInfo & eForceFbEnabled) ret += "ForceFb ";
732 if (ovlInfo & eSandwichedBetweenGLES) ret += "SandwichGLES ";
733 if (ovlInfo & eSandwichedBetweenEXYNOS) ret += "SandwichExy ";
734 if (ovlInfo & eInsufficientWindow) ret += "NoWin ";
735 if (ovlInfo & eInsufficientMPP) ret += "NoMPP ";
736 if (ovlInfo & eSkipStaticLayer) ret += "SkipStaticLayer ";
737 if (ovlInfo & eUnSupportedUseCase) ret += "OutOfCase ";
738 if (ovlInfo & eDimLayer) ret += "Dim ";
739 if (ovlInfo & eResourcePendingWork) ret += "ResourcePending ";
740 if (ovlInfo & eSkipRotateAnim) ret += "SkipRotAnim ";
741 if (ovlInfo & eUnSupportedColorTransform) ret += "UnsupportedColorTrans ";
742 if (ovlInfo & eLowFpsLayer) ret += "LowFps ";
743 if (ovlInfo & eReallocOnGoingForDDI) ret += "ReallocForDDI ";
744 if (ovlInfo & eInvalidDispFrame) ret += "InvalidDispFrame ";
745 if (ovlInfo & eExceedMaxLayerNum) ret += "OverMaxLayer ";
746 if (ovlInfo & eExceedSdrDimRatio) ret += "OverSdrDimRatio ";
747 if (ovlInfo & eIgnoreLayer) ret += "Ignore ";
748 if (ovlInfo & eSkipStartFrame) ret += "SkipFirstFrame ";
749 if (ovlInfo & eResourceAssignFail) ret += "ResourceAssignFail ";
750 if (ovlInfo & eMPPUnsupported) ret += "MPPUnspported ";
751 if (ovlInfo & eUnknown) ret += "Unknown ";
752
753 if (std::size_t found = ret.find_last_of(" ");
754 found != std::string::npos && found < ret.size()) {
755 ret.erase(found);
756 }
757 return ret;
758 }
759
transDataSpaceToString(const uint32_t & dataspace)760 inline std::string transDataSpaceToString(const uint32_t& dataspace) {
761 std::string ret;
762 const uint32_t standard = dataspace & HAL_DATASPACE_STANDARD_MASK;
763 if (standard == HAL_DATASPACE_STANDARD_UNSPECIFIED)
764 ret += std::string("NA");
765 else if (standard == HAL_DATASPACE_STANDARD_BT709)
766 ret += std::string("BT709");
767 else if (standard == HAL_DATASPACE_STANDARD_BT601_625)
768 ret += std::string("BT601_625");
769 else if (standard == HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED)
770 ret += std::string("BT601_625_UNADJUSTED");
771 else if (standard == HAL_DATASPACE_STANDARD_BT601_525)
772 ret += std::string("BT601_525");
773 else if (standard == HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED)
774 ret += std::string("BT601_525_UNADJUSTED");
775 else if (standard == HAL_DATASPACE_STANDARD_BT2020)
776 ret += std::string("BT2020");
777 else if (standard == HAL_DATASPACE_STANDARD_BT2020_CONSTANT_LUMINANCE)
778 ret += std::string("BT2020_CONSTANT_LUMINANCE");
779 else if (standard == HAL_DATASPACE_STANDARD_BT470M)
780 ret += std::string("BT470M");
781 else if (standard == HAL_DATASPACE_STANDARD_FILM)
782 ret += std::string("FILM");
783 else if (standard == HAL_DATASPACE_STANDARD_DCI_P3)
784 ret += std::string("DCI-P3");
785 else if (standard == HAL_DATASPACE_STANDARD_ADOBE_RGB)
786 ret += std::string("Adobe RGB");
787 else
788 ret += std::string("Unknown");
789
790 const uint32_t transfer = dataspace & HAL_DATASPACE_TRANSFER_MASK;
791 if (transfer == HAL_DATASPACE_TRANSFER_LINEAR)
792 ret += std::string(",Linear");
793 else if (transfer == HAL_DATASPACE_TRANSFER_SRGB)
794 ret += std::string(",SRGB");
795 else if (transfer == HAL_DATASPACE_TRANSFER_SMPTE_170M)
796 ret += std::string(",SMPTE");
797 else if (transfer == HAL_DATASPACE_TRANSFER_GAMMA2_2)
798 ret += std::string(",G2.2");
799 else if (transfer == HAL_DATASPACE_TRANSFER_GAMMA2_6)
800 ret += std::string(",G2.6");
801 else if (transfer == HAL_DATASPACE_TRANSFER_GAMMA2_8)
802 ret += std::string(",G2.8");
803 else if (transfer == HAL_DATASPACE_TRANSFER_ST2084)
804 ret += std::string(",ST2084");
805 else if (transfer == HAL_DATASPACE_TRANSFER_HLG)
806 ret += std::string(",HLG");
807 else
808 ret += std::string(",Unknown");
809
810 const uint32_t range = dataspace & HAL_DATASPACE_RANGE_MASK;
811 if (range == HAL_DATASPACE_RANGE_FULL)
812 ret += std::string(",Full");
813 else if (range == HAL_DATASPACE_RANGE_LIMITED)
814 ret += std::string(",Limited");
815 else if (range == HAL_DATASPACE_RANGE_EXTENDED)
816 ret += std::string(",Extend");
817 else
818 ret += std::string(",Unknown");
819 return ret;
820 }
821
transBlendModeToString(const uint32_t & blend)822 inline std::string transBlendModeToString(const uint32_t& blend) {
823 if (blend == HWC2_BLEND_MODE_NONE)
824 return std::string("None");
825 else if (blend == HWC2_BLEND_MODE_PREMULTIPLIED)
826 return std::string("Premult");
827 else if (blend == HWC2_BLEND_MODE_COVERAGE)
828 return std::string("Coverage");
829 else
830 return std::string("Unknown");
831 }
832
transTransformToString(const uint32_t & tr)833 inline std::string transTransformToString(const uint32_t& tr) {
834 if (tr == toUnderlying(AidlTransform::NONE))
835 return std::string("None");
836 else if (tr == toUnderlying(AidlTransform::FLIP_H))
837 return std::string("FLIP_H");
838 else if (tr == toUnderlying(AidlTransform::FLIP_V))
839 return std::string("FLIP_V");
840 else if (tr == toUnderlying(AidlTransform::ROT_90))
841 return std::string("ROT_90");
842 else if (tr == toUnderlying(AidlTransform::ROT_180))
843 return std::string("ROT_180");
844 else if (tr == toUnderlying(AidlTransform::ROT_270))
845 return std::string("ROT_270");
846 return std::string("Unknown");
847 }
848
849 using ::aidl::android::hardware::graphics::composer3::Composition;
850
851 enum {
852 HWC2_COMPOSITION_DISPLAY_DECORATION = toUnderlying(Composition::DISPLAY_DECORATION),
853 HWC2_COMPOSITION_REFRESH_RATE_INDICATOR = toUnderlying(Composition::REFRESH_RATE_INDICATOR),
854 /*add after hwc2_composition_t, margin number here*/
855 HWC2_COMPOSITION_EXYNOS = 32,
856 };
857
transCompTypeToString(const uint32_t & type)858 inline std::string transCompTypeToString(const uint32_t& type) {
859 if (type == HWC2_COMPOSITION_INVALID)
860 return std::string("Invalid");
861 else if (type == HWC2_COMPOSITION_CLIENT)
862 return std::string("CLI");
863 else if (type == HWC2_COMPOSITION_DEVICE)
864 return std::string("DEV");
865 else if (type == HWC2_COMPOSITION_SOLID_COLOR)
866 return std::string("SOLID");
867 else if (type == HWC2_COMPOSITION_CURSOR)
868 return std::string("CURSOR");
869 else if (type == HWC2_COMPOSITION_SIDEBAND)
870 return std::string("SIDEBAND");
871 else if (type == HWC2_COMPOSITION_DISPLAY_DECORATION)
872 return std::string("RCD");
873 else if (type == HWC2_COMPOSITION_REFRESH_RATE_INDICATOR)
874 return std::string("REFRESH_RATE");
875 else if (type == HWC2_COMPOSITION_EXYNOS)
876 return std::string("EXYNOS");
877 else
878 return std::string("Unknown");
879 }
880
881 static constexpr int64_t SIGNAL_TIME_PENDING = INT64_MAX;
882 static constexpr int64_t SIGNAL_TIME_INVALID = -1;
883
884 nsecs_t getSignalTime(int32_t fd);
885
886 #endif
887