1 /*
2 * Copyright 2017 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 #include <ui/DebugUtils.h>
18 #include <ui/DeviceProductInfo.h>
19 #include <ui/PixelFormat.h>
20 #include <ui/Rect.h>
21
22 #include <android-base/stringprintf.h>
23 #include <string>
24
25 using android::base::StringPrintf;
26 using android::ui::ColorMode;
27 using android::ui::RenderIntent;
28
decodeStandardOnly(uint32_t dataspaceStandard)29 std::string decodeStandardOnly(uint32_t dataspaceStandard) {
30 switch (dataspaceStandard) {
31 case HAL_DATASPACE_STANDARD_BT709:
32 return std::string("BT709");
33
34 case HAL_DATASPACE_STANDARD_BT601_625:
35 return std::string("BT601_625");
36
37 case HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED:
38 return std::string("BT601_625_UNADJUSTED");
39
40 case HAL_DATASPACE_STANDARD_BT601_525:
41 return std::string("BT601_525");
42
43 case HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED:
44 return std::string("BT601_525_UNADJUSTED");
45
46 case HAL_DATASPACE_STANDARD_BT2020:
47 return std::string("BT2020");
48
49 case HAL_DATASPACE_STANDARD_BT2020_CONSTANT_LUMINANCE:
50 return std::string("BT2020 (constant luminance)");
51
52 case HAL_DATASPACE_STANDARD_BT470M:
53 return std::string("BT470M");
54
55 case HAL_DATASPACE_STANDARD_FILM:
56 return std::string("FILM");
57
58 case HAL_DATASPACE_STANDARD_DCI_P3:
59 return std::string("DCI-P3");
60
61 case HAL_DATASPACE_STANDARD_ADOBE_RGB:
62 return std::string("AdobeRGB");
63 }
64
65 return StringPrintf("Unknown dataspace code %d", dataspaceStandard);
66 }
67
decodeStandard(android_dataspace dataspace)68 std::string decodeStandard(android_dataspace dataspace) {
69 const uint32_t dataspaceStandard = (dataspace & HAL_DATASPACE_STANDARD_MASK);
70 if (dataspaceStandard == 0) {
71 switch (dataspace & 0xffff) {
72 case HAL_DATASPACE_JFIF:
73 return std::string("(deprecated) JFIF (BT601_625)");
74
75 case HAL_DATASPACE_BT601_625:
76 return std::string("(deprecated) BT601_625");
77
78 case HAL_DATASPACE_BT601_525:
79 return std::string("(deprecated) BT601_525");
80
81 case HAL_DATASPACE_SRGB_LINEAR:
82 case HAL_DATASPACE_SRGB:
83 return std::string("(deprecated) sRGB");
84
85 case HAL_DATASPACE_BT709:
86 return std::string("(deprecated) BT709");
87
88 case HAL_DATASPACE_ARBITRARY:
89 return std::string("ARBITRARY");
90
91 case HAL_DATASPACE_UNKNOWN:
92 // Fallthrough
93 default:
94 return StringPrintf("Unknown deprecated dataspace code %d", dataspace);
95 }
96 }
97 return decodeStandardOnly(dataspaceStandard);
98 }
99
decodeTransferOnly(uint32_t dataspaceTransfer)100 std::string decodeTransferOnly(uint32_t dataspaceTransfer) {
101 switch (dataspaceTransfer) {
102 case HAL_DATASPACE_TRANSFER_UNSPECIFIED:
103 return std::string("Unspecified");
104
105 case HAL_DATASPACE_TRANSFER_LINEAR:
106 return std::string("Linear");
107
108 case HAL_DATASPACE_TRANSFER_SRGB:
109 return std::string("sRGB");
110
111 case HAL_DATASPACE_TRANSFER_SMPTE_170M:
112 return std::string("SMPTE_170M");
113
114 case HAL_DATASPACE_TRANSFER_GAMMA2_2:
115 return std::string("gamma 2.2");
116
117 case HAL_DATASPACE_TRANSFER_GAMMA2_6:
118 return std::string("gamma 2.6");
119
120 case HAL_DATASPACE_TRANSFER_GAMMA2_8:
121 return std::string("gamma 2.8");
122
123 case HAL_DATASPACE_TRANSFER_ST2084:
124 return std::string("SMPTE 2084");
125
126 case HAL_DATASPACE_TRANSFER_HLG:
127 return std::string("STD-B67");
128 }
129
130 return StringPrintf("Unknown dataspace transfer %d", dataspaceTransfer);
131 }
132
decodeTransfer(android_dataspace dataspace)133 std::string decodeTransfer(android_dataspace dataspace) {
134 const uint32_t dataspaceSelect = (dataspace & HAL_DATASPACE_STANDARD_MASK);
135 if (dataspaceSelect == 0) {
136 switch (dataspace & 0xffff) {
137 case HAL_DATASPACE_JFIF:
138 case HAL_DATASPACE_BT601_625:
139 case HAL_DATASPACE_BT601_525:
140 case HAL_DATASPACE_BT709:
141 return std::string("SMPTE_170M");
142
143 case HAL_DATASPACE_SRGB_LINEAR:
144 case HAL_DATASPACE_ARBITRARY:
145 return std::string("Linear");
146
147 case HAL_DATASPACE_SRGB:
148 return std::string("sRGB");
149
150 case HAL_DATASPACE_UNKNOWN:
151 // Fallthrough
152 default:
153 return std::string("");
154 }
155 }
156
157 const uint32_t dataspaceTransfer = (dataspace & HAL_DATASPACE_TRANSFER_MASK);
158 return decodeTransferOnly(dataspaceTransfer);
159 }
160
decodeRangeOnly(uint32_t dataspaceRange)161 std::string decodeRangeOnly(uint32_t dataspaceRange) {
162 switch (dataspaceRange) {
163 case HAL_DATASPACE_RANGE_UNSPECIFIED:
164 return std::string("Range Unspecified");
165
166 case HAL_DATASPACE_RANGE_FULL:
167 return std::string("Full range");
168
169 case HAL_DATASPACE_RANGE_LIMITED:
170 return std::string("Limited range");
171
172 case HAL_DATASPACE_RANGE_EXTENDED:
173 return std::string("Extended range");
174 }
175
176 return StringPrintf("Unknown dataspace range %d", dataspaceRange);
177 }
178
decodeRange(android_dataspace dataspace)179 std::string decodeRange(android_dataspace dataspace) {
180 const uint32_t dataspaceSelect = (dataspace & HAL_DATASPACE_STANDARD_MASK);
181 if (dataspaceSelect == 0) {
182 switch (dataspace & 0xffff) {
183 case HAL_DATASPACE_JFIF:
184 case HAL_DATASPACE_SRGB_LINEAR:
185 case HAL_DATASPACE_SRGB:
186 return std::string("Full range");
187
188 case HAL_DATASPACE_BT601_625:
189 case HAL_DATASPACE_BT601_525:
190 case HAL_DATASPACE_BT709:
191 return std::string("Limited range");
192
193 case HAL_DATASPACE_ARBITRARY:
194 case HAL_DATASPACE_UNKNOWN:
195 // Fallthrough
196 default:
197 return std::string("unspecified range");
198 }
199 }
200
201 const uint32_t dataspaceRange = (dataspace & HAL_DATASPACE_RANGE_MASK);
202 return decodeRangeOnly(dataspaceRange);
203 }
204
dataspaceDetails(android_dataspace dataspace)205 std::string dataspaceDetails(android_dataspace dataspace) {
206 if (dataspace == 0) {
207 return "Default";
208 }
209 return StringPrintf("%s %s %s", decodeStandard(dataspace).c_str(),
210 decodeTransfer(dataspace).c_str(), decodeRange(dataspace).c_str());
211 }
212
decodeColorMode(ColorMode colorMode)213 std::string decodeColorMode(ColorMode colorMode) {
214 switch (colorMode) {
215 case ColorMode::NATIVE:
216 return std::string("ColorMode::NATIVE");
217
218 case ColorMode::STANDARD_BT601_625:
219 return std::string("ColorMode::BT601_625");
220
221 case ColorMode::STANDARD_BT601_625_UNADJUSTED:
222 return std::string("ColorMode::BT601_625_UNADJUSTED");
223
224 case ColorMode::STANDARD_BT601_525:
225 return std::string("ColorMode::BT601_525");
226
227 case ColorMode::STANDARD_BT601_525_UNADJUSTED:
228 return std::string("ColorMode::BT601_525_UNADJUSTED");
229
230 case ColorMode::STANDARD_BT709:
231 return std::string("ColorMode::BT709");
232
233 case ColorMode::DCI_P3:
234 return std::string("ColorMode::DCI_P3");
235
236 case ColorMode::SRGB:
237 return std::string("ColorMode::SRGB");
238
239 case ColorMode::ADOBE_RGB:
240 return std::string("ColorMode::ADOBE_RGB");
241
242 case ColorMode::DISPLAY_P3:
243 return std::string("ColorMode::DISPLAY_P3");
244
245 case ColorMode::BT2020:
246 return std::string("ColorMode::BT2020");
247
248 case ColorMode::DISPLAY_BT2020:
249 return std::string("ColorMode::DISPLAY_BT2020");
250
251 case ColorMode::BT2100_PQ:
252 return std::string("ColorMode::BT2100_PQ");
253
254 case ColorMode::BT2100_HLG:
255 return std::string("ColorMode::BT2100_HLG");
256 }
257
258 return StringPrintf("Unknown color mode %d", colorMode);
259 }
260
decodeColorTransform(android_color_transform colorTransform)261 std::string decodeColorTransform(android_color_transform colorTransform) {
262 switch (colorTransform) {
263 case HAL_COLOR_TRANSFORM_IDENTITY:
264 return std::string("Identity");
265
266 case HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX:
267 return std::string("Arbitrary matrix");
268
269 case HAL_COLOR_TRANSFORM_VALUE_INVERSE:
270 return std::string("Inverse value");
271
272 case HAL_COLOR_TRANSFORM_GRAYSCALE:
273 return std::string("Grayscale");
274
275 case HAL_COLOR_TRANSFORM_CORRECT_PROTANOPIA:
276 return std::string("Correct protanopia");
277
278 case HAL_COLOR_TRANSFORM_CORRECT_DEUTERANOPIA:
279 return std::string("Correct deuteranopia");
280
281 case HAL_COLOR_TRANSFORM_CORRECT_TRITANOPIA:
282 return std::string("Correct tritanopia");
283 }
284
285 return StringPrintf("Unknown color transform %d", colorTransform);
286 }
287
288 // Converts a PixelFormat to a human-readable string. Max 11 chars.
289 // (Could use a table of prefab String8 objects.)
decodePixelFormat(android::PixelFormat format)290 std::string decodePixelFormat(android::PixelFormat format) {
291 switch (format) {
292 case android::PIXEL_FORMAT_UNKNOWN:
293 return std::string("Unknown/None");
294 case android::PIXEL_FORMAT_CUSTOM:
295 return std::string("Custom");
296 case android::PIXEL_FORMAT_TRANSLUCENT:
297 return std::string("Translucent");
298 case android::PIXEL_FORMAT_TRANSPARENT:
299 return std::string("Transparent");
300 case android::PIXEL_FORMAT_OPAQUE:
301 return std::string("Opaque");
302 case android::PIXEL_FORMAT_RGBA_8888:
303 return std::string("RGBA_8888");
304 case android::PIXEL_FORMAT_RGBX_8888:
305 return std::string("RGBx_8888");
306 case android::PIXEL_FORMAT_RGBA_FP16:
307 return std::string("RGBA_FP16");
308 case android::PIXEL_FORMAT_RGBA_1010102:
309 return std::string("RGBA_1010102");
310 case android::PIXEL_FORMAT_RGB_888:
311 return std::string("RGB_888");
312 case android::PIXEL_FORMAT_RGB_565:
313 return std::string("RGB_565");
314 case android::PIXEL_FORMAT_BGRA_8888:
315 return std::string("BGRA_8888");
316 case android::PIXEL_FORMAT_R_8:
317 return std::string("R_8");
318 case android::PIXEL_FORMAT_R_16_UINT:
319 return std::string("R_16_UINT");
320 case android::PIXEL_FORMAT_RG_1616_UINT:
321 return std::string("RG_1616_UINT");
322 case android::PIXEL_FORMAT_RGBA_10101010:
323 return std::string("RGBA_10101010");
324 default:
325 return StringPrintf("Unknown %#08x", format);
326 }
327 }
328
decodeRenderIntent(RenderIntent renderIntent)329 std::string decodeRenderIntent(RenderIntent renderIntent) {
330 switch(renderIntent) {
331 case RenderIntent::COLORIMETRIC:
332 return std::string("RenderIntent::COLORIMETRIC");
333 case RenderIntent::ENHANCE:
334 return std::string("RenderIntent::ENHANCE");
335 case RenderIntent::TONE_MAP_COLORIMETRIC:
336 return std::string("RenderIntent::TONE_MAP_COLORIMETRIC");
337 case RenderIntent::TONE_MAP_ENHANCE:
338 return std::string("RenderIntent::TONE_MAP_ENHANCE");
339 }
340 return std::string("Unknown RenderIntent");
341 }
342
toString(const android::DeviceProductInfo::ManufactureOrModelDate & date)343 std::string toString(const android::DeviceProductInfo::ManufactureOrModelDate& date) {
344 using ModelYear = android::DeviceProductInfo::ModelYear;
345 using ManufactureYear = android::DeviceProductInfo::ManufactureYear;
346 using ManufactureWeekAndYear = android::DeviceProductInfo::ManufactureWeekAndYear;
347
348 if (const auto* model = std::get_if<ModelYear>(&date)) {
349 return StringPrintf("ModelYear{%d}", model->year);
350 } else if (const auto* manufacture = std::get_if<ManufactureYear>(&date)) {
351 return StringPrintf("ManufactureDate{year=%d}", manufacture->year);
352 } else if (const auto* manufacture = std::get_if<ManufactureWeekAndYear>(&date)) {
353 return StringPrintf("ManufactureDate{week=%d, year=%d}", manufacture->week,
354 manufacture->year);
355 } else {
356 LOG_FATAL("Unknown alternative for variant DeviceProductInfo::ManufactureOrModelDate");
357 return {};
358 }
359 }
360
toString(const android::DeviceProductInfo & info)361 std::string toString(const android::DeviceProductInfo& info) {
362 return StringPrintf("DeviceProductInfo{name=%s, productId=%s, manufacturerPnpId=%s, "
363 "manufactureOrModelDate=%s}",
364 info.name.data(), info.productId.data(), info.manufacturerPnpId.data(),
365 toString(info.manufactureOrModelDate).c_str());
366 }
367