blob: 5e37b7e127d143c796f8791f5be4cec86a803d7f [file] [log] [blame]
Jason Macnak2a77d942020-09-10 10:57:46 -07001/*
2 * Copyright 2020 The Chromium OS Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7#include "cros_gralloc/gralloc4/CrosGralloc4Utils.h"
8
9#include <array>
10#include <unordered_map>
11
12#include <aidl/android/hardware/graphics/common/PlaneLayoutComponent.h>
13#include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h>
14#include <android-base/stringprintf.h>
15#include <android-base/strings.h>
16#include <cutils/native_handle.h>
17#include <gralloctypes/Gralloc4.h>
18
19#include "cros_gralloc/cros_gralloc_helpers.h"
20
21using aidl::android::hardware::graphics::common::PlaneLayout;
22using aidl::android::hardware::graphics::common::PlaneLayoutComponent;
23using aidl::android::hardware::graphics::common::PlaneLayoutComponentType;
24using android::hardware::hidl_bitfield;
25using android::hardware::hidl_handle;
26using android::hardware::graphics::common::V1_2::BufferUsage;
27using android::hardware::graphics::common::V1_2::PixelFormat;
28
29using BufferDescriptorInfo =
30 android::hardware::graphics::mapper::V4_0::IMapper::BufferDescriptorInfo;
31
Jason Macnak2a77d942020-09-10 10:57:46 -070032std::string getPixelFormatString(PixelFormat format) {
33 switch (format) {
34 case PixelFormat::BGRA_8888:
35 return "PixelFormat::BGRA_8888";
36 case PixelFormat::BLOB:
37 return "PixelFormat::BLOB";
38 case PixelFormat::DEPTH_16:
39 return "PixelFormat::DEPTH_16";
40 case PixelFormat::DEPTH_24:
41 return "PixelFormat::DEPTH_24";
42 case PixelFormat::DEPTH_24_STENCIL_8:
43 return "PixelFormat::DEPTH_24_STENCIL_8";
44 case PixelFormat::DEPTH_32F:
45 return "PixelFormat::DEPTH_24";
46 case PixelFormat::DEPTH_32F_STENCIL_8:
47 return "PixelFormat::DEPTH_24_STENCIL_8";
48 case PixelFormat::HSV_888:
49 return "PixelFormat::HSV_888";
50 case PixelFormat::IMPLEMENTATION_DEFINED:
51 return "PixelFormat::IMPLEMENTATION_DEFINED";
52 case PixelFormat::RAW10:
53 return "PixelFormat::RAW10";
54 case PixelFormat::RAW12:
55 return "PixelFormat::RAW12";
56 case PixelFormat::RAW16:
57 return "PixelFormat::RAW16";
58 case PixelFormat::RAW_OPAQUE:
59 return "PixelFormat::RAW_OPAQUE";
60 case PixelFormat::RGBA_1010102:
61 return "PixelFormat::RGBA_1010102";
62 case PixelFormat::RGBA_8888:
63 return "PixelFormat::RGBA_8888";
64 case PixelFormat::RGBA_FP16:
65 return "PixelFormat::RGBA_FP16";
66 case PixelFormat::RGBX_8888:
67 return "PixelFormat::RGBX_8888";
68 case PixelFormat::RGB_565:
69 return "PixelFormat::RGB_565";
70 case PixelFormat::RGB_888:
71 return "PixelFormat::RGB_888";
72 case PixelFormat::STENCIL_8:
73 return "PixelFormat::STENCIL_8";
74 case PixelFormat::Y16:
75 return "PixelFormat::Y16";
76 case PixelFormat::Y8:
77 return "PixelFormat::Y8";
78 case PixelFormat::YCBCR_420_888:
79 return "PixelFormat::YCBCR_420_888";
80 case PixelFormat::YCBCR_422_I:
81 return "PixelFormat::YCBCR_422_I";
82 case PixelFormat::YCBCR_422_SP:
83 return "PixelFormat::YCBCR_422_SP";
84 case PixelFormat::YCBCR_P010:
85 return "PixelFormat::YCBCR_P010";
86 case PixelFormat::YCRCB_420_SP:
87 return "PixelFormat::YCRCB_420_SP";
88 case PixelFormat::YV12:
89 return "PixelFormat::YV12";
90 }
91 return android::base::StringPrintf("PixelFormat::Unknown(%d)", static_cast<uint32_t>(format));
92}
93
94std::string getUsageString(hidl_bitfield<BufferUsage> bufferUsage) {
95 using Underlying = typename std::underlying_type<BufferUsage>::type;
96
97 Underlying usage = static_cast<Underlying>(bufferUsage);
98
99 std::vector<std::string> usages;
100 if (usage & BufferUsage::CAMERA_INPUT) {
101 usage &= ~static_cast<Underlying>(BufferUsage::CAMERA_INPUT);
102 usages.push_back("BufferUsage::CAMERA_INPUT");
103 }
104 if (usage & BufferUsage::CAMERA_OUTPUT) {
105 usage &= ~static_cast<Underlying>(BufferUsage::CAMERA_OUTPUT);
106 usages.push_back("BufferUsage::CAMERA_OUTPUT");
107 }
108 if (usage & BufferUsage::COMPOSER_CURSOR) {
109 usage &= ~static_cast<Underlying>(BufferUsage::COMPOSER_CURSOR);
110 usages.push_back("BufferUsage::COMPOSER_CURSOR");
111 }
112 if (usage & BufferUsage::COMPOSER_OVERLAY) {
113 usage &= ~static_cast<Underlying>(BufferUsage::COMPOSER_OVERLAY);
114 usages.push_back("BufferUsage::COMPOSER_OVERLAY");
115 }
116 if (usage & BufferUsage::CPU_READ_OFTEN) {
117 usage &= ~static_cast<Underlying>(BufferUsage::CPU_READ_OFTEN);
118 usages.push_back("BufferUsage::CPU_READ_OFTEN");
119 }
120 if (usage & BufferUsage::CPU_READ_NEVER) {
121 usage &= ~static_cast<Underlying>(BufferUsage::CPU_READ_NEVER);
122 usages.push_back("BufferUsage::CPU_READ_NEVER");
123 }
124 if (usage & BufferUsage::CPU_READ_RARELY) {
125 usage &= ~static_cast<Underlying>(BufferUsage::CPU_READ_RARELY);
126 usages.push_back("BufferUsage::CPU_READ_RARELY");
127 }
128 if (usage & BufferUsage::CPU_WRITE_NEVER) {
129 usage &= ~static_cast<Underlying>(BufferUsage::CPU_WRITE_NEVER);
130 usages.push_back("BufferUsage::CPU_WRITE_NEVER");
131 }
132 if (usage & BufferUsage::CPU_WRITE_OFTEN) {
133 usage &= ~static_cast<Underlying>(BufferUsage::CPU_WRITE_OFTEN);
134 usages.push_back("BufferUsage::CPU_WRITE_OFTEN");
135 }
136 if (usage & BufferUsage::CPU_WRITE_RARELY) {
137 usage &= ~static_cast<Underlying>(BufferUsage::CPU_WRITE_RARELY);
138 usages.push_back("BufferUsage::CPU_WRITE_RARELY");
139 }
140 if (usage & BufferUsage::GPU_RENDER_TARGET) {
141 usage &= ~static_cast<Underlying>(BufferUsage::GPU_RENDER_TARGET);
142 usages.push_back("BufferUsage::GPU_RENDER_TARGET");
143 }
144 if (usage & BufferUsage::GPU_TEXTURE) {
145 usage &= ~static_cast<Underlying>(BufferUsage::GPU_TEXTURE);
146 usages.push_back("BufferUsage::GPU_TEXTURE");
147 }
148 if (usage & BufferUsage::PROTECTED) {
149 usage &= ~static_cast<Underlying>(BufferUsage::PROTECTED);
150 usages.push_back("BufferUsage::PROTECTED");
151 }
152 if (usage & BufferUsage::RENDERSCRIPT) {
153 usage &= ~static_cast<Underlying>(BufferUsage::RENDERSCRIPT);
154 usages.push_back("BufferUsage::RENDERSCRIPT");
155 }
156 if (usage & BufferUsage::VIDEO_DECODER) {
157 usage &= ~static_cast<Underlying>(BufferUsage::VIDEO_DECODER);
158 usages.push_back("BufferUsage::VIDEO_DECODER");
159 }
160 if (usage & BufferUsage::VIDEO_ENCODER) {
161 usage &= ~static_cast<Underlying>(BufferUsage::VIDEO_ENCODER);
162 usages.push_back("BufferUsage::VIDEO_ENCODER");
163 }
164
165 if (usage) {
166 usages.push_back(android::base::StringPrintf("UnknownUsageBits-%" PRIu64, usage));
167 }
168
169 return android::base::Join(usages, '|');
170}
171
172int convertToDrmFormat(PixelFormat format, uint32_t* outDrmFormat) {
173 switch (format) {
174 case PixelFormat::BGRA_8888:
175 *outDrmFormat = DRM_FORMAT_ARGB8888;
176 return 0;
177 /**
178 * Choose DRM_FORMAT_R8 because <system/graphics.h> requires the buffers
179 * with a format HAL_PIXEL_FORMAT_BLOB have a height of 1, and width
180 * equal to their size in bytes.
181 */
182 case PixelFormat::BLOB:
183 *outDrmFormat = DRM_FORMAT_R8;
184 return 0;
185 case PixelFormat::DEPTH_16:
186 return -EINVAL;
187 case PixelFormat::DEPTH_24:
188 return -EINVAL;
189 case PixelFormat::DEPTH_24_STENCIL_8:
190 return -EINVAL;
191 case PixelFormat::DEPTH_32F:
192 return -EINVAL;
193 case PixelFormat::DEPTH_32F_STENCIL_8:
194 return -EINVAL;
195 case PixelFormat::HSV_888:
196 return -EINVAL;
197 case PixelFormat::IMPLEMENTATION_DEFINED:
198 *outDrmFormat = DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED;
199 return 0;
200 case PixelFormat::RAW10:
201 return -EINVAL;
202 case PixelFormat::RAW12:
203 return -EINVAL;
204 case PixelFormat::RAW16:
205 *outDrmFormat = DRM_FORMAT_R16;
206 return 0;
207 /* TODO use blob */
208 case PixelFormat::RAW_OPAQUE:
209 return -EINVAL;
210 case PixelFormat::RGBA_1010102:
211 *outDrmFormat = DRM_FORMAT_ABGR2101010;
212 return 0;
213 case PixelFormat::RGBA_8888:
214 *outDrmFormat = DRM_FORMAT_ABGR8888;
215 return 0;
216 case PixelFormat::RGBA_FP16:
217 *outDrmFormat = DRM_FORMAT_ABGR16161616F;
218 return 0;
219 case PixelFormat::RGBX_8888:
220 *outDrmFormat = DRM_FORMAT_XBGR8888;
221 return 0;
222 case PixelFormat::RGB_565:
223 *outDrmFormat = DRM_FORMAT_RGB565;
224 return 0;
225 case PixelFormat::RGB_888:
226 *outDrmFormat = DRM_FORMAT_RGB888;
227 return 0;
228 case PixelFormat::STENCIL_8:
229 return -EINVAL;
230 case PixelFormat::Y16:
231 *outDrmFormat = DRM_FORMAT_R16;
232 return 0;
233 case PixelFormat::Y8:
234 *outDrmFormat = DRM_FORMAT_R8;
235 return 0;
236 case PixelFormat::YCBCR_420_888:
237 *outDrmFormat = DRM_FORMAT_FLEX_YCbCr_420_888;
238 return 0;
239 case PixelFormat::YCBCR_422_SP:
240 return -EINVAL;
241 case PixelFormat::YCBCR_422_I:
242 return -EINVAL;
243 case PixelFormat::YCBCR_P010:
244 *outDrmFormat = DRM_FORMAT_P010;
245 return 0;
246 case PixelFormat::YCRCB_420_SP:
247 *outDrmFormat = DRM_FORMAT_NV21;
248 return 0;
249 case PixelFormat::YV12:
250 *outDrmFormat = DRM_FORMAT_YVU420_ANDROID;
251 return 0;
252 };
253 return -EINVAL;
254}
255
256int convertToBufferUsage(uint64_t grallocUsage, uint64_t* outBufferUsage) {
257 uint64_t bufferUsage = BO_USE_NONE;
258
259 if ((grallocUsage & BufferUsage::CPU_READ_MASK) ==
260 static_cast<uint64_t>(BufferUsage::CPU_READ_RARELY)) {
261 bufferUsage |= BO_USE_SW_READ_RARELY;
262 }
263 if ((grallocUsage & BufferUsage::CPU_READ_MASK) ==
264 static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN)) {
265 bufferUsage |= BO_USE_SW_READ_OFTEN;
266 }
267 if ((grallocUsage & BufferUsage::CPU_WRITE_MASK) ==
268 static_cast<uint64_t>(BufferUsage::CPU_WRITE_RARELY)) {
269 bufferUsage |= BO_USE_SW_WRITE_RARELY;
270 }
271 if ((grallocUsage & BufferUsage::CPU_WRITE_MASK) ==
272 static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN)) {
273 bufferUsage |= BO_USE_SW_WRITE_OFTEN;
274 }
275 if (grallocUsage & BufferUsage::GPU_TEXTURE) {
276 bufferUsage |= BO_USE_TEXTURE;
277 }
278 if (grallocUsage & BufferUsage::GPU_RENDER_TARGET) {
279 bufferUsage |= BO_USE_RENDERING;
280 }
281 if (grallocUsage & BufferUsage::COMPOSER_OVERLAY) {
282 /* HWC wants to use display hardware, but can defer to OpenGL. */
283 bufferUsage |= BO_USE_SCANOUT | BO_USE_TEXTURE;
284 }
Gurchetan Singhb7edf5d2020-10-16 10:28:04 -0700285 /* Map this flag to linear until real HW protection is available on Android. */
Jason Macnak2a77d942020-09-10 10:57:46 -0700286 if (grallocUsage & BufferUsage::PROTECTED) {
Gurchetan Singhb7edf5d2020-10-16 10:28:04 -0700287 bufferUsage |= BO_USE_LINEAR;
Jason Macnak2a77d942020-09-10 10:57:46 -0700288 }
289 if (grallocUsage & BufferUsage::COMPOSER_CURSOR) {
290 bufferUsage |= BO_USE_NONE;
291 }
292 if (grallocUsage & BufferUsage::VIDEO_ENCODER) {
293 /*HACK: See b/30054495 */
294 bufferUsage |= BO_USE_SW_READ_OFTEN;
295 }
296 if (grallocUsage & BufferUsage::CAMERA_OUTPUT) {
297 bufferUsage |= BO_USE_CAMERA_WRITE;
298 }
299 if (grallocUsage & BufferUsage::CAMERA_INPUT) {
300 bufferUsage |= BO_USE_CAMERA_READ;
301 }
302 if (grallocUsage & BufferUsage::RENDERSCRIPT) {
303 bufferUsage |= BO_USE_RENDERSCRIPT;
304 }
305 if (grallocUsage & BufferUsage::VIDEO_DECODER) {
306 bufferUsage |= BO_USE_HW_VIDEO_DECODER;
307 }
308
309 *outBufferUsage = bufferUsage;
310 return 0;
311}
312
313int convertToCrosDescriptor(const BufferDescriptorInfo& descriptor,
314 struct cros_gralloc_buffer_descriptor* outCrosDescriptor) {
315 outCrosDescriptor->name = descriptor.name;
316 outCrosDescriptor->width = descriptor.width;
317 outCrosDescriptor->height = descriptor.height;
318 outCrosDescriptor->droid_format = static_cast<int32_t>(descriptor.format);
319 outCrosDescriptor->droid_usage = descriptor.usage;
320 outCrosDescriptor->reserved_region_size = descriptor.reservedSize;
Jason Macnak07f62092020-12-10 11:42:54 -0800321 if (descriptor.layerCount > 1) {
322 drv_log("Failed to convert descriptor. Unsupported layerCount: %d\n",
323 descriptor.layerCount);
324 return -1;
325 }
Jason Macnak2a77d942020-09-10 10:57:46 -0700326 if (convertToDrmFormat(descriptor.format, &outCrosDescriptor->drm_format)) {
327 std::string pixelFormatString = getPixelFormatString(descriptor.format);
Jason Macnak07f62092020-12-10 11:42:54 -0800328 drv_log("Failed to convert descriptor. Unsupported format %s\n", pixelFormatString.c_str());
Jason Macnak2a77d942020-09-10 10:57:46 -0700329 return -1;
330 }
331 if (convertToBufferUsage(descriptor.usage, &outCrosDescriptor->use_flags)) {
332 std::string usageString = getUsageString(descriptor.usage);
333 drv_log("Failed to convert descriptor. Unsupported usage flags %s\n", usageString.c_str());
334 return -1;
335 }
336 return 0;
337}
338
339int convertToMapUsage(uint64_t grallocUsage, uint32_t* outMapUsage) {
340 uint32_t mapUsage = BO_MAP_NONE;
341
342 if (grallocUsage & BufferUsage::CPU_READ_MASK) {
343 mapUsage |= BO_MAP_READ;
344 }
345 if (grallocUsage & BufferUsage::CPU_WRITE_MASK) {
346 mapUsage |= BO_MAP_WRITE;
347 }
348
349 *outMapUsage = mapUsage;
350 return 0;
351}
352
353int convertToFenceFd(const hidl_handle& fenceHandle, int* outFenceFd) {
354 if (!outFenceFd) {
355 return -EINVAL;
356 }
357
358 const native_handle_t* nativeHandle = fenceHandle.getNativeHandle();
359 if (nativeHandle && nativeHandle->numFds > 1) {
360 return -EINVAL;
361 }
362
363 *outFenceFd = (nativeHandle && nativeHandle->numFds == 1) ? nativeHandle->data[0] : -1;
364 return 0;
365}
366
367int convertToFenceHandle(int fenceFd, hidl_handle* outFenceHandle) {
368 if (!outFenceHandle) {
369 return -EINVAL;
370 }
371 if (fenceFd < 0) {
372 return 0;
373 }
374
375 NATIVE_HANDLE_DECLARE_STORAGE(handleStorage, 1, 0);
376 auto fenceHandle = native_handle_init(handleStorage, 1, 0);
377 fenceHandle->data[0] = fenceFd;
378
379 *outFenceHandle = fenceHandle;
380 return 0;
381}
382
383const std::unordered_map<uint32_t, std::vector<PlaneLayout>>& GetPlaneLayoutsMap() {
384 static const auto* kPlaneLayoutsMap =
385 new std::unordered_map<uint32_t, std::vector<PlaneLayout>>({
386 {DRM_FORMAT_ABGR8888,
387 {{
388 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
389 .offsetInBits = 0,
390 .sizeInBits = 8},
391 {.type = android::gralloc4::PlaneLayoutComponentType_G,
392 .offsetInBits = 8,
393 .sizeInBits = 8},
394 {.type = android::gralloc4::PlaneLayoutComponentType_B,
395 .offsetInBits = 16,
396 .sizeInBits = 8},
397 {.type = android::gralloc4::PlaneLayoutComponentType_A,
398 .offsetInBits = 24,
399 .sizeInBits = 8}},
400 .sampleIncrementInBits = 32,
401 .horizontalSubsampling = 1,
402 .verticalSubsampling = 1,
403 }}},
404
405 {DRM_FORMAT_ABGR2101010,
406 {{
407 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
408 .offsetInBits = 0,
409 .sizeInBits = 10},
410 {.type = android::gralloc4::PlaneLayoutComponentType_G,
411 .offsetInBits = 10,
412 .sizeInBits = 10},
413 {.type = android::gralloc4::PlaneLayoutComponentType_B,
414 .offsetInBits = 20,
415 .sizeInBits = 10},
416 {.type = android::gralloc4::PlaneLayoutComponentType_A,
417 .offsetInBits = 30,
418 .sizeInBits = 2}},
419 .sampleIncrementInBits = 32,
420 .horizontalSubsampling = 1,
421 .verticalSubsampling = 1,
422 }}},
423
424 {DRM_FORMAT_ABGR16161616F,
425 {{
426 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
427 .offsetInBits = 0,
428 .sizeInBits = 16},
429 {.type = android::gralloc4::PlaneLayoutComponentType_G,
430 .offsetInBits = 16,
431 .sizeInBits = 16},
432 {.type = android::gralloc4::PlaneLayoutComponentType_B,
433 .offsetInBits = 32,
434 .sizeInBits = 16},
435 {.type = android::gralloc4::PlaneLayoutComponentType_A,
436 .offsetInBits = 48,
437 .sizeInBits = 16}},
438 .sampleIncrementInBits = 64,
439 .horizontalSubsampling = 1,
440 .verticalSubsampling = 1,
441 }}},
442
443 {DRM_FORMAT_ARGB8888,
444 {{
445 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_B,
446 .offsetInBits = 0,
447 .sizeInBits = 8},
448 {.type = android::gralloc4::PlaneLayoutComponentType_G,
449 .offsetInBits = 8,
450 .sizeInBits = 8},
451 {.type = android::gralloc4::PlaneLayoutComponentType_R,
452 .offsetInBits = 16,
453 .sizeInBits = 8},
454 {.type = android::gralloc4::PlaneLayoutComponentType_A,
455 .offsetInBits = 24,
456 .sizeInBits = 8}},
457 .sampleIncrementInBits = 32,
458 .horizontalSubsampling = 1,
459 .verticalSubsampling = 1,
460 }}},
461
462 {DRM_FORMAT_NV12,
463 {{
464 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_Y,
465 .offsetInBits = 0,
466 .sizeInBits = 8}},
467 .sampleIncrementInBits = 8,
468 .horizontalSubsampling = 1,
469 .verticalSubsampling = 1,
470 },
471 {
472 .components =
473 {{.type = android::gralloc4::PlaneLayoutComponentType_CB,
474 .offsetInBits = 0,
475 .sizeInBits = 8},
476 {.type = android::gralloc4::PlaneLayoutComponentType_CR,
477 .offsetInBits = 8,
478 .sizeInBits = 8}},
479 .sampleIncrementInBits = 16,
480 .horizontalSubsampling = 2,
481 .verticalSubsampling = 2,
482 }}},
483
484 {DRM_FORMAT_NV21,
485 {{
486 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_Y,
487 .offsetInBits = 0,
488 .sizeInBits = 8}},
489 .sampleIncrementInBits = 8,
490 .horizontalSubsampling = 1,
491 .verticalSubsampling = 1,
492 },
493 {
494 .components =
495 {{.type = android::gralloc4::PlaneLayoutComponentType_CR,
496 .offsetInBits = 0,
497 .sizeInBits = 8},
498 {.type = android::gralloc4::PlaneLayoutComponentType_CB,
499 .offsetInBits = 8,
500 .sizeInBits = 8}},
501 .sampleIncrementInBits = 16,
502 .horizontalSubsampling = 2,
503 .verticalSubsampling = 2,
504 }}},
505
506 {DRM_FORMAT_P010,
507 {{
508 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_Y,
509 .offsetInBits = 6,
510 .sizeInBits = 10}},
511 .sampleIncrementInBits = 16,
512 .horizontalSubsampling = 1,
513 .verticalSubsampling = 1,
514 },
515 {
516 .components =
517 {{.type = android::gralloc4::PlaneLayoutComponentType_CB,
518 .offsetInBits = 6,
519 .sizeInBits = 10},
520 {.type = android::gralloc4::PlaneLayoutComponentType_CR,
521 .offsetInBits = 22,
522 .sizeInBits = 10}},
523 .sampleIncrementInBits = 32,
524 .horizontalSubsampling = 2,
525 .verticalSubsampling = 2,
526 }}},
527
528 {DRM_FORMAT_R8,
529 {{
530 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
531 .offsetInBits = 0,
532 .sizeInBits = 8}},
533 .sampleIncrementInBits = 8,
534 .horizontalSubsampling = 1,
535 .verticalSubsampling = 1,
536 }}},
537
538 {DRM_FORMAT_R16,
539 {{
540 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
541 .offsetInBits = 0,
542 .sizeInBits = 16}},
543 .sampleIncrementInBits = 16,
544 .horizontalSubsampling = 1,
545 .verticalSubsampling = 1,
546 }}},
547
548 {DRM_FORMAT_RGB565,
549 {{
550 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
551 .offsetInBits = 0,
552 .sizeInBits = 5},
553 {.type = android::gralloc4::PlaneLayoutComponentType_G,
554 .offsetInBits = 5,
555 .sizeInBits = 6},
556 {.type = android::gralloc4::PlaneLayoutComponentType_B,
557 .offsetInBits = 11,
558 .sizeInBits = 5}},
559 .sampleIncrementInBits = 16,
560 .horizontalSubsampling = 1,
561 .verticalSubsampling = 1,
562 }}},
563
564 {DRM_FORMAT_RGB888,
565 {{
566 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
567 .offsetInBits = 0,
568 .sizeInBits = 8},
569 {.type = android::gralloc4::PlaneLayoutComponentType_G,
570 .offsetInBits = 8,
571 .sizeInBits = 8},
572 {.type = android::gralloc4::PlaneLayoutComponentType_B,
573 .offsetInBits = 16,
574 .sizeInBits = 8}},
575 .sampleIncrementInBits = 24,
576 .horizontalSubsampling = 1,
577 .verticalSubsampling = 1,
578 }}},
579
580 {DRM_FORMAT_XBGR8888,
581 {{
582 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_B,
583 .offsetInBits = 0,
584 .sizeInBits = 8},
585 {.type = android::gralloc4::PlaneLayoutComponentType_G,
586 .offsetInBits = 8,
587 .sizeInBits = 8},
588 {.type = android::gralloc4::PlaneLayoutComponentType_R,
589 .offsetInBits = 16,
590 .sizeInBits = 8}},
591 .sampleIncrementInBits = 32,
592 .horizontalSubsampling = 1,
593 .verticalSubsampling = 1,
594 }}},
595
596 {DRM_FORMAT_YVU420,
597 {
598 {
599 .components = {{.type = android::gralloc4::
600 PlaneLayoutComponentType_Y,
601 .offsetInBits = 0,
602 .sizeInBits = 8}},
603 .sampleIncrementInBits = 8,
604 .horizontalSubsampling = 1,
605 .verticalSubsampling = 1,
606 },
607 {
608 .components = {{.type = android::gralloc4::
609 PlaneLayoutComponentType_CB,
610 .offsetInBits = 0,
611 .sizeInBits = 8}},
612 .sampleIncrementInBits = 8,
613 .horizontalSubsampling = 2,
614 .verticalSubsampling = 2,
615 },
616 {
617 .components = {{.type = android::gralloc4::
618 PlaneLayoutComponentType_CR,
619 .offsetInBits = 0,
620 .sizeInBits = 8}},
621 .sampleIncrementInBits = 8,
622 .horizontalSubsampling = 2,
623 .verticalSubsampling = 2,
624 },
625 }},
626
627 {DRM_FORMAT_YVU420_ANDROID,
628 {
629 {
630 .components = {{.type = android::gralloc4::
631 PlaneLayoutComponentType_Y,
632 .offsetInBits = 0,
633 .sizeInBits = 8}},
634 .sampleIncrementInBits = 8,
635 .horizontalSubsampling = 1,
636 .verticalSubsampling = 1,
637 },
638 {
639 .components = {{.type = android::gralloc4::
640 PlaneLayoutComponentType_CR,
641 .offsetInBits = 0,
642 .sizeInBits = 8}},
643 .sampleIncrementInBits = 8,
644 .horizontalSubsampling = 2,
645 .verticalSubsampling = 2,
646 },
647 {
648 .components = {{.type = android::gralloc4::
649 PlaneLayoutComponentType_CB,
650 .offsetInBits = 0,
651 .sizeInBits = 8}},
652 .sampleIncrementInBits = 8,
653 .horizontalSubsampling = 2,
654 .verticalSubsampling = 2,
655 },
656 }},
657 });
658 return *kPlaneLayoutsMap;
659}
660
661int getPlaneLayouts(uint32_t drmFormat, std::vector<PlaneLayout>* outPlaneLayouts) {
662 const auto& planeLayoutsMap = GetPlaneLayoutsMap();
663 const auto it = planeLayoutsMap.find(drmFormat);
664 if (it == planeLayoutsMap.end()) {
665 drv_log("Unknown plane layout for format %d\n", drmFormat);
666 return -1;
667 }
668
669 *outPlaneLayouts = it->second;
670 return 0;
Gurchetan Singh2d482e02020-10-05 17:17:13 -0700671}