blob: 7aae08b2500e1389ceb0785f545d78245b4e5217 [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 }
Yiwei Zhangbb9d4af2021-06-20 19:23:38 +0000164 if (usage & BufferUsage::GPU_DATA_BUFFER) {
165 usage &= ~static_cast<Underlying>(BufferUsage::GPU_DATA_BUFFER);
166 usages.push_back("BufferUsage::GPU_DATA_BUFFER");
167 }
Yiwei Zhangb03d0212021-07-07 21:54:10 +0000168 if (usage & BUFFER_USAGE_FRONT_RENDERING) {
169 usage &= ~static_cast<Underlying>(BUFFER_USAGE_FRONT_RENDERING);
170 usages.push_back("BUFFER_USAGE_FRONT_RENDERING");
171 }
Jason Macnak2a77d942020-09-10 10:57:46 -0700172
173 if (usage) {
174 usages.push_back(android::base::StringPrintf("UnknownUsageBits-%" PRIu64, usage));
175 }
176
177 return android::base::Join(usages, '|');
178}
179
180int convertToDrmFormat(PixelFormat format, uint32_t* outDrmFormat) {
181 switch (format) {
182 case PixelFormat::BGRA_8888:
183 *outDrmFormat = DRM_FORMAT_ARGB8888;
184 return 0;
185 /**
186 * Choose DRM_FORMAT_R8 because <system/graphics.h> requires the buffers
187 * with a format HAL_PIXEL_FORMAT_BLOB have a height of 1, and width
188 * equal to their size in bytes.
189 */
190 case PixelFormat::BLOB:
191 *outDrmFormat = DRM_FORMAT_R8;
192 return 0;
193 case PixelFormat::DEPTH_16:
194 return -EINVAL;
195 case PixelFormat::DEPTH_24:
196 return -EINVAL;
197 case PixelFormat::DEPTH_24_STENCIL_8:
198 return -EINVAL;
199 case PixelFormat::DEPTH_32F:
200 return -EINVAL;
201 case PixelFormat::DEPTH_32F_STENCIL_8:
202 return -EINVAL;
203 case PixelFormat::HSV_888:
204 return -EINVAL;
205 case PixelFormat::IMPLEMENTATION_DEFINED:
206 *outDrmFormat = DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED;
207 return 0;
208 case PixelFormat::RAW10:
209 return -EINVAL;
210 case PixelFormat::RAW12:
211 return -EINVAL;
212 case PixelFormat::RAW16:
213 *outDrmFormat = DRM_FORMAT_R16;
214 return 0;
215 /* TODO use blob */
216 case PixelFormat::RAW_OPAQUE:
217 return -EINVAL;
218 case PixelFormat::RGBA_1010102:
219 *outDrmFormat = DRM_FORMAT_ABGR2101010;
220 return 0;
221 case PixelFormat::RGBA_8888:
222 *outDrmFormat = DRM_FORMAT_ABGR8888;
223 return 0;
224 case PixelFormat::RGBA_FP16:
225 *outDrmFormat = DRM_FORMAT_ABGR16161616F;
226 return 0;
227 case PixelFormat::RGBX_8888:
228 *outDrmFormat = DRM_FORMAT_XBGR8888;
229 return 0;
230 case PixelFormat::RGB_565:
231 *outDrmFormat = DRM_FORMAT_RGB565;
232 return 0;
233 case PixelFormat::RGB_888:
234 *outDrmFormat = DRM_FORMAT_RGB888;
235 return 0;
236 case PixelFormat::STENCIL_8:
237 return -EINVAL;
238 case PixelFormat::Y16:
239 *outDrmFormat = DRM_FORMAT_R16;
240 return 0;
241 case PixelFormat::Y8:
242 *outDrmFormat = DRM_FORMAT_R8;
243 return 0;
244 case PixelFormat::YCBCR_420_888:
245 *outDrmFormat = DRM_FORMAT_FLEX_YCbCr_420_888;
246 return 0;
247 case PixelFormat::YCBCR_422_SP:
248 return -EINVAL;
249 case PixelFormat::YCBCR_422_I:
250 return -EINVAL;
251 case PixelFormat::YCBCR_P010:
252 *outDrmFormat = DRM_FORMAT_P010;
253 return 0;
254 case PixelFormat::YCRCB_420_SP:
255 *outDrmFormat = DRM_FORMAT_NV21;
256 return 0;
257 case PixelFormat::YV12:
258 *outDrmFormat = DRM_FORMAT_YVU420_ANDROID;
259 return 0;
260 };
261 return -EINVAL;
262}
263
264int convertToBufferUsage(uint64_t grallocUsage, uint64_t* outBufferUsage) {
Yiwei Zhang6b894b12021-09-16 22:28:22 +0000265 *outBufferUsage = cros_gralloc_convert_usage(grallocUsage);
Jason Macnak2a77d942020-09-10 10:57:46 -0700266 return 0;
267}
268
269int convertToCrosDescriptor(const BufferDescriptorInfo& descriptor,
270 struct cros_gralloc_buffer_descriptor* outCrosDescriptor) {
271 outCrosDescriptor->name = descriptor.name;
272 outCrosDescriptor->width = descriptor.width;
273 outCrosDescriptor->height = descriptor.height;
274 outCrosDescriptor->droid_format = static_cast<int32_t>(descriptor.format);
275 outCrosDescriptor->droid_usage = descriptor.usage;
276 outCrosDescriptor->reserved_region_size = descriptor.reservedSize;
Jason Macnak07f62092020-12-10 11:42:54 -0800277 if (descriptor.layerCount > 1) {
278 drv_log("Failed to convert descriptor. Unsupported layerCount: %d\n",
279 descriptor.layerCount);
Gurchetan Singhcadc54f2021-02-01 12:03:11 -0800280 return -EINVAL;
Jason Macnak07f62092020-12-10 11:42:54 -0800281 }
Jason Macnak2a77d942020-09-10 10:57:46 -0700282 if (convertToDrmFormat(descriptor.format, &outCrosDescriptor->drm_format)) {
283 std::string pixelFormatString = getPixelFormatString(descriptor.format);
Jason Macnak07f62092020-12-10 11:42:54 -0800284 drv_log("Failed to convert descriptor. Unsupported format %s\n", pixelFormatString.c_str());
Gurchetan Singhcadc54f2021-02-01 12:03:11 -0800285 return -EINVAL;
Jason Macnak2a77d942020-09-10 10:57:46 -0700286 }
287 if (convertToBufferUsage(descriptor.usage, &outCrosDescriptor->use_flags)) {
288 std::string usageString = getUsageString(descriptor.usage);
289 drv_log("Failed to convert descriptor. Unsupported usage flags %s\n", usageString.c_str());
Gurchetan Singhcadc54f2021-02-01 12:03:11 -0800290 return -EINVAL;
Jason Macnak2a77d942020-09-10 10:57:46 -0700291 }
292 return 0;
293}
294
295int convertToMapUsage(uint64_t grallocUsage, uint32_t* outMapUsage) {
296 uint32_t mapUsage = BO_MAP_NONE;
297
298 if (grallocUsage & BufferUsage::CPU_READ_MASK) {
299 mapUsage |= BO_MAP_READ;
300 }
301 if (grallocUsage & BufferUsage::CPU_WRITE_MASK) {
302 mapUsage |= BO_MAP_WRITE;
303 }
304
305 *outMapUsage = mapUsage;
306 return 0;
307}
308
309int convertToFenceFd(const hidl_handle& fenceHandle, int* outFenceFd) {
310 if (!outFenceFd) {
311 return -EINVAL;
312 }
313
314 const native_handle_t* nativeHandle = fenceHandle.getNativeHandle();
315 if (nativeHandle && nativeHandle->numFds > 1) {
316 return -EINVAL;
317 }
318
319 *outFenceFd = (nativeHandle && nativeHandle->numFds == 1) ? nativeHandle->data[0] : -1;
320 return 0;
321}
322
323int convertToFenceHandle(int fenceFd, hidl_handle* outFenceHandle) {
324 if (!outFenceHandle) {
325 return -EINVAL;
326 }
327 if (fenceFd < 0) {
328 return 0;
329 }
330
331 NATIVE_HANDLE_DECLARE_STORAGE(handleStorage, 1, 0);
332 auto fenceHandle = native_handle_init(handleStorage, 1, 0);
333 fenceHandle->data[0] = fenceFd;
334
335 *outFenceHandle = fenceHandle;
336 return 0;
337}
338
339const std::unordered_map<uint32_t, std::vector<PlaneLayout>>& GetPlaneLayoutsMap() {
340 static const auto* kPlaneLayoutsMap =
341 new std::unordered_map<uint32_t, std::vector<PlaneLayout>>({
342 {DRM_FORMAT_ABGR8888,
343 {{
344 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
345 .offsetInBits = 0,
346 .sizeInBits = 8},
347 {.type = android::gralloc4::PlaneLayoutComponentType_G,
348 .offsetInBits = 8,
349 .sizeInBits = 8},
350 {.type = android::gralloc4::PlaneLayoutComponentType_B,
351 .offsetInBits = 16,
352 .sizeInBits = 8},
353 {.type = android::gralloc4::PlaneLayoutComponentType_A,
354 .offsetInBits = 24,
355 .sizeInBits = 8}},
356 .sampleIncrementInBits = 32,
357 .horizontalSubsampling = 1,
358 .verticalSubsampling = 1,
359 }}},
360
361 {DRM_FORMAT_ABGR2101010,
362 {{
363 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
364 .offsetInBits = 0,
365 .sizeInBits = 10},
366 {.type = android::gralloc4::PlaneLayoutComponentType_G,
367 .offsetInBits = 10,
368 .sizeInBits = 10},
369 {.type = android::gralloc4::PlaneLayoutComponentType_B,
370 .offsetInBits = 20,
371 .sizeInBits = 10},
372 {.type = android::gralloc4::PlaneLayoutComponentType_A,
373 .offsetInBits = 30,
374 .sizeInBits = 2}},
375 .sampleIncrementInBits = 32,
376 .horizontalSubsampling = 1,
377 .verticalSubsampling = 1,
378 }}},
379
380 {DRM_FORMAT_ABGR16161616F,
381 {{
382 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
383 .offsetInBits = 0,
384 .sizeInBits = 16},
385 {.type = android::gralloc4::PlaneLayoutComponentType_G,
386 .offsetInBits = 16,
387 .sizeInBits = 16},
388 {.type = android::gralloc4::PlaneLayoutComponentType_B,
389 .offsetInBits = 32,
390 .sizeInBits = 16},
391 {.type = android::gralloc4::PlaneLayoutComponentType_A,
392 .offsetInBits = 48,
393 .sizeInBits = 16}},
394 .sampleIncrementInBits = 64,
395 .horizontalSubsampling = 1,
396 .verticalSubsampling = 1,
397 }}},
398
399 {DRM_FORMAT_ARGB8888,
400 {{
401 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_B,
402 .offsetInBits = 0,
403 .sizeInBits = 8},
404 {.type = android::gralloc4::PlaneLayoutComponentType_G,
405 .offsetInBits = 8,
406 .sizeInBits = 8},
407 {.type = android::gralloc4::PlaneLayoutComponentType_R,
408 .offsetInBits = 16,
409 .sizeInBits = 8},
410 {.type = android::gralloc4::PlaneLayoutComponentType_A,
411 .offsetInBits = 24,
412 .sizeInBits = 8}},
413 .sampleIncrementInBits = 32,
414 .horizontalSubsampling = 1,
415 .verticalSubsampling = 1,
416 }}},
417
418 {DRM_FORMAT_NV12,
419 {{
420 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_Y,
421 .offsetInBits = 0,
422 .sizeInBits = 8}},
423 .sampleIncrementInBits = 8,
424 .horizontalSubsampling = 1,
425 .verticalSubsampling = 1,
426 },
427 {
428 .components =
429 {{.type = android::gralloc4::PlaneLayoutComponentType_CB,
430 .offsetInBits = 0,
431 .sizeInBits = 8},
432 {.type = android::gralloc4::PlaneLayoutComponentType_CR,
433 .offsetInBits = 8,
434 .sizeInBits = 8}},
435 .sampleIncrementInBits = 16,
436 .horizontalSubsampling = 2,
437 .verticalSubsampling = 2,
438 }}},
439
440 {DRM_FORMAT_NV21,
441 {{
442 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_Y,
443 .offsetInBits = 0,
444 .sizeInBits = 8}},
445 .sampleIncrementInBits = 8,
446 .horizontalSubsampling = 1,
447 .verticalSubsampling = 1,
448 },
449 {
450 .components =
451 {{.type = android::gralloc4::PlaneLayoutComponentType_CR,
452 .offsetInBits = 0,
453 .sizeInBits = 8},
454 {.type = android::gralloc4::PlaneLayoutComponentType_CB,
455 .offsetInBits = 8,
456 .sizeInBits = 8}},
457 .sampleIncrementInBits = 16,
458 .horizontalSubsampling = 2,
459 .verticalSubsampling = 2,
460 }}},
461
462 {DRM_FORMAT_P010,
463 {{
464 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_Y,
465 .offsetInBits = 6,
466 .sizeInBits = 10}},
467 .sampleIncrementInBits = 16,
468 .horizontalSubsampling = 1,
469 .verticalSubsampling = 1,
470 },
471 {
472 .components =
473 {{.type = android::gralloc4::PlaneLayoutComponentType_CB,
474 .offsetInBits = 6,
475 .sizeInBits = 10},
476 {.type = android::gralloc4::PlaneLayoutComponentType_CR,
477 .offsetInBits = 22,
478 .sizeInBits = 10}},
479 .sampleIncrementInBits = 32,
480 .horizontalSubsampling = 2,
481 .verticalSubsampling = 2,
482 }}},
483
484 {DRM_FORMAT_R8,
485 {{
486 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
487 .offsetInBits = 0,
488 .sizeInBits = 8}},
489 .sampleIncrementInBits = 8,
490 .horizontalSubsampling = 1,
491 .verticalSubsampling = 1,
492 }}},
493
494 {DRM_FORMAT_R16,
495 {{
496 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
497 .offsetInBits = 0,
498 .sizeInBits = 16}},
499 .sampleIncrementInBits = 16,
500 .horizontalSubsampling = 1,
501 .verticalSubsampling = 1,
502 }}},
503
504 {DRM_FORMAT_RGB565,
505 {{
506 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
507 .offsetInBits = 0,
508 .sizeInBits = 5},
509 {.type = android::gralloc4::PlaneLayoutComponentType_G,
510 .offsetInBits = 5,
511 .sizeInBits = 6},
512 {.type = android::gralloc4::PlaneLayoutComponentType_B,
513 .offsetInBits = 11,
514 .sizeInBits = 5}},
515 .sampleIncrementInBits = 16,
516 .horizontalSubsampling = 1,
517 .verticalSubsampling = 1,
518 }}},
519
520 {DRM_FORMAT_RGB888,
521 {{
522 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_R,
523 .offsetInBits = 0,
524 .sizeInBits = 8},
525 {.type = android::gralloc4::PlaneLayoutComponentType_G,
526 .offsetInBits = 8,
527 .sizeInBits = 8},
528 {.type = android::gralloc4::PlaneLayoutComponentType_B,
529 .offsetInBits = 16,
530 .sizeInBits = 8}},
531 .sampleIncrementInBits = 24,
532 .horizontalSubsampling = 1,
533 .verticalSubsampling = 1,
534 }}},
535
536 {DRM_FORMAT_XBGR8888,
537 {{
538 .components = {{.type = android::gralloc4::PlaneLayoutComponentType_B,
539 .offsetInBits = 0,
540 .sizeInBits = 8},
541 {.type = android::gralloc4::PlaneLayoutComponentType_G,
542 .offsetInBits = 8,
543 .sizeInBits = 8},
544 {.type = android::gralloc4::PlaneLayoutComponentType_R,
545 .offsetInBits = 16,
546 .sizeInBits = 8}},
547 .sampleIncrementInBits = 32,
548 .horizontalSubsampling = 1,
549 .verticalSubsampling = 1,
550 }}},
551
552 {DRM_FORMAT_YVU420,
553 {
554 {
555 .components = {{.type = android::gralloc4::
556 PlaneLayoutComponentType_Y,
557 .offsetInBits = 0,
558 .sizeInBits = 8}},
559 .sampleIncrementInBits = 8,
560 .horizontalSubsampling = 1,
561 .verticalSubsampling = 1,
562 },
563 {
564 .components = {{.type = android::gralloc4::
565 PlaneLayoutComponentType_CB,
566 .offsetInBits = 0,
567 .sizeInBits = 8}},
568 .sampleIncrementInBits = 8,
569 .horizontalSubsampling = 2,
570 .verticalSubsampling = 2,
571 },
572 {
573 .components = {{.type = android::gralloc4::
574 PlaneLayoutComponentType_CR,
575 .offsetInBits = 0,
576 .sizeInBits = 8}},
577 .sampleIncrementInBits = 8,
578 .horizontalSubsampling = 2,
579 .verticalSubsampling = 2,
580 },
581 }},
582
583 {DRM_FORMAT_YVU420_ANDROID,
584 {
585 {
586 .components = {{.type = android::gralloc4::
587 PlaneLayoutComponentType_Y,
588 .offsetInBits = 0,
589 .sizeInBits = 8}},
590 .sampleIncrementInBits = 8,
591 .horizontalSubsampling = 1,
592 .verticalSubsampling = 1,
593 },
594 {
595 .components = {{.type = android::gralloc4::
596 PlaneLayoutComponentType_CR,
597 .offsetInBits = 0,
598 .sizeInBits = 8}},
599 .sampleIncrementInBits = 8,
600 .horizontalSubsampling = 2,
601 .verticalSubsampling = 2,
602 },
603 {
604 .components = {{.type = android::gralloc4::
605 PlaneLayoutComponentType_CB,
606 .offsetInBits = 0,
607 .sizeInBits = 8}},
608 .sampleIncrementInBits = 8,
609 .horizontalSubsampling = 2,
610 .verticalSubsampling = 2,
611 },
612 }},
613 });
614 return *kPlaneLayoutsMap;
615}
616
617int getPlaneLayouts(uint32_t drmFormat, std::vector<PlaneLayout>* outPlaneLayouts) {
618 const auto& planeLayoutsMap = GetPlaneLayoutsMap();
619 const auto it = planeLayoutsMap.find(drmFormat);
620 if (it == planeLayoutsMap.end()) {
621 drv_log("Unknown plane layout for format %d\n", drmFormat);
Gurchetan Singhcadc54f2021-02-01 12:03:11 -0800622 return -EINVAL;
Jason Macnak2a77d942020-09-10 10:57:46 -0700623 }
624
625 *outPlaneLayouts = it->second;
626 return 0;
Gurchetan Singh2d482e02020-10-05 17:17:13 -0700627}