1 /*
2 * Copyright 2016 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 "../../helpers.h"
8 #include "../../util.h"
9 #include "../cros_gralloc_driver.h"
10
11 #include <cassert>
12 #include <hardware/gralloc.h>
13 #include <memory.h>
14
15 struct gralloc0_module {
16 gralloc_module_t base;
17 std::unique_ptr<alloc_device_t> alloc;
18 std::unique_ptr<cros_gralloc_driver> driver;
19 bool initialized;
20 std::mutex initialization_mutex;
21 };
22
23 struct cros_gralloc0_buffer_info {
24 uint32_t drm_fourcc;
25 int num_fds;
26 int fds[4];
27 uint64_t modifier;
28 uint32_t offset[4];
29 uint32_t stride[4];
30 };
31
32 /* This enumeration must match the one in <gralloc_drm.h>.
33 * The functions supported by this gralloc's temporary private API are listed
34 * below. Use of these functions is highly discouraged and should only be
35 * reserved for cases where no alternative to get same information (such as
36 * querying ANativeWindow) exists.
37 */
38 // clang-format off
39 enum {
40 GRALLOC_DRM_GET_STRIDE,
41 GRALLOC_DRM_GET_FORMAT,
42 GRALLOC_DRM_GET_DIMENSIONS,
43 GRALLOC_DRM_GET_BACKING_STORE,
44 GRALLOC_DRM_GET_BUFFER_INFO,
45 GRALLOC_DRM_GET_USAGE,
46 };
47
48 /* This enumeration corresponds to the GRALLOC_DRM_GET_USAGE query op, which
49 * defines a set of bit flags used by the client to query vendor usage bits.
50 *
51 * Here is the common flow:
52 * 1) EGL/Vulkan calls GRALLOC_DRM_GET_USAGE to append one or multiple vendor
53 * usage bits to the existing usage and sets onto the ANativeWindow.
54 * 2) Some implicit GL draw cmd or the explicit vkCreateSwapchainKHR kicks off
55 * the next dequeueBuffer on the ANativeWindow with the combined usage.
56 * 3) dequeueBuffer then asks gralloc hal for an allocation/re-allocation, and
57 * calls into the below `gralloc0_alloc(...)` api.
58 */
59 enum {
60 GRALLOC_DRM_GET_USAGE_FRONT_RENDERING_BIT = 0x00000001,
61 };
62 // clang-format on
63
64 // Gralloc0 doesn't define a video decoder flag. However, the IAllocator gralloc0
65 // passthrough gives the low 32-bits of the BufferUsage flags to gralloc0 in their
66 // entirety, so we can detect the video decoder flag passed by IAllocator clients.
67 #define BUFFER_USAGE_VIDEO_DECODER (1 << 22)
68
69 // Reserve the GRALLOC_USAGE_PRIVATE_0 bit for buffers used for front rendering.
70 // minigbm backend later decides to use BO_USE_FRONT_RENDERING or BO_USE_LINEAR
71 // upon buffer allocaton.
72 #define BUFFER_USAGE_FRONT_RENDERING GRALLOC_USAGE_PRIVATE_0
73
gralloc0_convert_usage(int usage)74 static uint64_t gralloc0_convert_usage(int usage)
75 {
76 uint64_t use_flags = BO_USE_NONE;
77
78 if (usage & GRALLOC_USAGE_CURSOR)
79 use_flags |= BO_USE_NONE;
80 if ((usage & GRALLOC_USAGE_SW_READ_MASK) == GRALLOC_USAGE_SW_READ_RARELY)
81 use_flags |= BO_USE_SW_READ_RARELY;
82 if ((usage & GRALLOC_USAGE_SW_READ_MASK) == GRALLOC_USAGE_SW_READ_OFTEN)
83 use_flags |= BO_USE_SW_READ_OFTEN;
84 if ((usage & GRALLOC_USAGE_SW_WRITE_MASK) == GRALLOC_USAGE_SW_WRITE_RARELY)
85 use_flags |= BO_USE_SW_WRITE_RARELY;
86 if ((usage & GRALLOC_USAGE_SW_WRITE_MASK) == GRALLOC_USAGE_SW_WRITE_OFTEN)
87 use_flags |= BO_USE_SW_WRITE_OFTEN;
88 if (usage & GRALLOC_USAGE_HW_TEXTURE)
89 use_flags |= BO_USE_TEXTURE;
90 if (usage & GRALLOC_USAGE_HW_RENDER)
91 use_flags |= BO_USE_RENDERING;
92 if (usage & GRALLOC_USAGE_HW_2D)
93 use_flags |= BO_USE_RENDERING;
94 if (usage & GRALLOC_USAGE_HW_COMPOSER)
95 /* HWC wants to use display hardware, but can defer to OpenGL. */
96 use_flags |= BO_USE_SCANOUT | BO_USE_TEXTURE;
97 if (usage & GRALLOC_USAGE_HW_FB)
98 use_flags |= BO_USE_NONE;
99 if (usage & GRALLOC_USAGE_EXTERNAL_DISP)
100 /*
101 * This flag potentially covers external display for the normal drivers (i915,
102 * rockchip) and usb monitors (evdi/udl). It's complicated so ignore it.
103 * */
104 use_flags |= BO_USE_NONE;
105 /* Map this flag to linear until real HW protection is available on Android. */
106 if (usage & GRALLOC_USAGE_PROTECTED)
107 use_flags |= BO_USE_LINEAR;
108 if (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) {
109 use_flags |= BO_USE_HW_VIDEO_ENCODER;
110 /*HACK: See b/30054495 */
111 use_flags |= BO_USE_SW_READ_OFTEN;
112 }
113 if (usage & GRALLOC_USAGE_HW_CAMERA_WRITE)
114 use_flags |= BO_USE_CAMERA_WRITE;
115 if (usage & GRALLOC_USAGE_HW_CAMERA_READ)
116 use_flags |= BO_USE_CAMERA_READ;
117 if (usage & GRALLOC_USAGE_RENDERSCRIPT)
118 use_flags |= BO_USE_RENDERSCRIPT;
119 if (usage & BUFFER_USAGE_VIDEO_DECODER)
120 use_flags |= BO_USE_HW_VIDEO_DECODER;
121 if (usage & BUFFER_USAGE_FRONT_RENDERING)
122 use_flags |= BO_USE_FRONT_RENDERING;
123
124 return use_flags;
125 }
126
gralloc0_convert_map_usage(int map_usage)127 static uint32_t gralloc0_convert_map_usage(int map_usage)
128 {
129 uint32_t map_flags = BO_MAP_NONE;
130
131 if (map_usage & GRALLOC_USAGE_SW_READ_MASK)
132 map_flags |= BO_MAP_READ;
133 if (map_usage & GRALLOC_USAGE_SW_WRITE_MASK)
134 map_flags |= BO_MAP_WRITE;
135
136 return map_flags;
137 }
138
gralloc0_droid_yuv_format(int droid_format)139 static int gralloc0_droid_yuv_format(int droid_format)
140 {
141
142 return (droid_format == HAL_PIXEL_FORMAT_YCbCr_420_888 ||
143 droid_format == HAL_PIXEL_FORMAT_YV12);
144 }
145
gralloc0_alloc(alloc_device_t * dev,int w,int h,int format,int usage,buffer_handle_t * handle,int * stride)146 static int gralloc0_alloc(alloc_device_t *dev, int w, int h, int format, int usage,
147 buffer_handle_t *handle, int *stride)
148 {
149 int32_t ret;
150 bool supported;
151 struct cros_gralloc_buffer_descriptor descriptor;
152 auto mod = (struct gralloc0_module const *)dev->common.module;
153
154 descriptor.width = w;
155 descriptor.height = h;
156 descriptor.droid_format = format;
157 descriptor.droid_usage = usage;
158 descriptor.drm_format = cros_gralloc_convert_format(format);
159 descriptor.use_flags = gralloc0_convert_usage(usage);
160 descriptor.reserved_region_size = 0;
161
162 supported = mod->driver->is_supported(&descriptor);
163 if (!supported && (usage & GRALLOC_USAGE_HW_COMPOSER)) {
164 descriptor.use_flags &= ~BO_USE_SCANOUT;
165 supported = mod->driver->is_supported(&descriptor);
166 }
167 if (!supported && (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) &&
168 format != HAL_PIXEL_FORMAT_YCbCr_420_888) {
169 // Unmask BO_USE_HW_VIDEO_ENCODER for other formats. They are mostly
170 // intermediate formats not passed directly to the encoder (e.g.
171 // camera). YV12 is passed to the encoder component, but it is converted
172 // to YCbCr_420_888 before being passed to the hw encoder.
173 descriptor.use_flags &= ~BO_USE_HW_VIDEO_ENCODER;
174 drv_log("Retrying format %u allocation without encoder flag", format);
175 supported = mod->driver->is_supported(&descriptor);
176 }
177 if (!supported && (usage & BUFFER_USAGE_FRONT_RENDERING)) {
178 descriptor.use_flags &= ~BO_USE_FRONT_RENDERING;
179 descriptor.use_flags |= BO_USE_LINEAR;
180 supported = mod->driver->is_supported(&descriptor);
181 }
182
183 if (!supported) {
184 drv_log("Unsupported combination -- HAL format: %u, HAL usage: %u, "
185 "drv_format: %4.4s, use_flags: %llu\n",
186 format, usage, reinterpret_cast<char *>(&descriptor.drm_format),
187 static_cast<unsigned long long>(descriptor.use_flags));
188 return -EINVAL;
189 }
190
191 ret = mod->driver->allocate(&descriptor, handle);
192 if (ret)
193 return ret;
194
195 auto hnd = cros_gralloc_convert_handle(*handle);
196 *stride = hnd->pixel_stride;
197
198 return 0;
199 }
200
gralloc0_free(alloc_device_t * dev,buffer_handle_t handle)201 static int gralloc0_free(alloc_device_t *dev, buffer_handle_t handle)
202 {
203 auto mod = (struct gralloc0_module const *)dev->common.module;
204 return mod->driver->release(handle);
205 }
206
gralloc0_close(struct hw_device_t * dev)207 static int gralloc0_close(struct hw_device_t *dev)
208 {
209 /* Memory is freed by managed pointers on process close. */
210 return 0;
211 }
212
gralloc0_init(struct gralloc0_module * mod,bool initialize_alloc)213 static int gralloc0_init(struct gralloc0_module *mod, bool initialize_alloc)
214 {
215 std::lock_guard<std::mutex> lock(mod->initialization_mutex);
216
217 if (mod->initialized)
218 return 0;
219
220 mod->driver = std::make_unique<cros_gralloc_driver>();
221 if (mod->driver->init()) {
222 drv_log("Failed to initialize driver.\n");
223 return -ENODEV;
224 }
225
226 if (initialize_alloc) {
227 mod->alloc = std::make_unique<alloc_device_t>();
228 mod->alloc->alloc = gralloc0_alloc;
229 mod->alloc->free = gralloc0_free;
230 mod->alloc->common.tag = HARDWARE_DEVICE_TAG;
231 mod->alloc->common.version = 0;
232 mod->alloc->common.module = (hw_module_t *)mod;
233 mod->alloc->common.close = gralloc0_close;
234 }
235
236 mod->initialized = true;
237 return 0;
238 }
239
gralloc0_open(const struct hw_module_t * mod,const char * name,struct hw_device_t ** dev)240 static int gralloc0_open(const struct hw_module_t *mod, const char *name, struct hw_device_t **dev)
241 {
242 auto const_module = reinterpret_cast<const struct gralloc0_module *>(mod);
243 auto module = const_cast<struct gralloc0_module *>(const_module);
244
245 if (module->initialized) {
246 *dev = &module->alloc->common;
247 return 0;
248 }
249
250 if (strcmp(name, GRALLOC_HARDWARE_GPU0)) {
251 drv_log("Incorrect device name - %s.\n", name);
252 return -EINVAL;
253 }
254
255 if (gralloc0_init(module, true))
256 return -ENODEV;
257
258 *dev = &module->alloc->common;
259 return 0;
260 }
261
gralloc0_register_buffer(struct gralloc_module_t const * module,buffer_handle_t handle)262 static int gralloc0_register_buffer(struct gralloc_module_t const *module, buffer_handle_t handle)
263 {
264 auto const_module = reinterpret_cast<const struct gralloc0_module *>(module);
265 auto mod = const_cast<struct gralloc0_module *>(const_module);
266
267 if (!mod->initialized) {
268 if (gralloc0_init(mod, false))
269 return -ENODEV;
270 }
271
272 return mod->driver->retain(handle);
273 }
274
gralloc0_unregister_buffer(struct gralloc_module_t const * module,buffer_handle_t handle)275 static int gralloc0_unregister_buffer(struct gralloc_module_t const *module, buffer_handle_t handle)
276 {
277 auto mod = (struct gralloc0_module const *)module;
278 return mod->driver->release(handle);
279 }
280
gralloc0_lock(struct gralloc_module_t const * module,buffer_handle_t handle,int usage,int l,int t,int w,int h,void ** vaddr)281 static int gralloc0_lock(struct gralloc_module_t const *module, buffer_handle_t handle, int usage,
282 int l, int t, int w, int h, void **vaddr)
283 {
284 return module->lockAsync(module, handle, usage, l, t, w, h, vaddr, -1);
285 }
286
gralloc0_unlock(struct gralloc_module_t const * module,buffer_handle_t handle)287 static int gralloc0_unlock(struct gralloc_module_t const *module, buffer_handle_t handle)
288 {
289 int32_t fence_fd, ret;
290 auto mod = (struct gralloc0_module const *)module;
291 ret = mod->driver->unlock(handle, &fence_fd);
292 if (ret)
293 return ret;
294
295 ret = cros_gralloc_sync_wait(fence_fd, /*close_acquire_fence=*/true);
296 if (ret)
297 return ret;
298
299 return 0;
300 }
301
gralloc0_perform(struct gralloc_module_t const * module,int op,...)302 static int gralloc0_perform(struct gralloc_module_t const *module, int op, ...)
303 {
304 va_list args;
305 int32_t *out_format, ret;
306 uint64_t *out_store;
307 buffer_handle_t handle;
308 cros_gralloc_handle_t hnd;
309 uint32_t *out_width, *out_height, *out_stride;
310 uint32_t strides[DRV_MAX_PLANES] = { 0, 0, 0, 0 };
311 uint32_t offsets[DRV_MAX_PLANES] = { 0, 0, 0, 0 };
312 uint64_t format_modifier = 0;
313 struct cros_gralloc0_buffer_info *info;
314 auto const_module = reinterpret_cast<const struct gralloc0_module *>(module);
315 auto mod = const_cast<struct gralloc0_module *>(const_module);
316 uint32_t req_usage;
317 uint32_t gralloc_usage = 0;
318 uint32_t *out_gralloc_usage;
319
320 if (!mod->initialized) {
321 if (gralloc0_init(mod, false))
322 return -ENODEV;
323 }
324
325 va_start(args, op);
326
327 switch (op) {
328 case GRALLOC_DRM_GET_STRIDE:
329 case GRALLOC_DRM_GET_FORMAT:
330 case GRALLOC_DRM_GET_DIMENSIONS:
331 case GRALLOC_DRM_GET_BACKING_STORE:
332 case GRALLOC_DRM_GET_BUFFER_INFO:
333 /* retrieve handles for ops with buffer_handle_t */
334 handle = va_arg(args, buffer_handle_t);
335 hnd = cros_gralloc_convert_handle(handle);
336 if (!hnd) {
337 va_end(args);
338 drv_log("Invalid handle.\n");
339 return -EINVAL;
340 }
341 break;
342 case GRALLOC_DRM_GET_USAGE:
343 break;
344 default:
345 va_end(args);
346 return -EINVAL;
347 }
348
349 ret = 0;
350 switch (op) {
351 case GRALLOC_DRM_GET_STRIDE:
352 out_stride = va_arg(args, uint32_t *);
353 ret = mod->driver->resource_info(handle, strides, offsets, &format_modifier);
354 if (ret)
355 break;
356
357 if (strides[0] != hnd->strides[0]) {
358 uint32_t bytes_per_pixel = drv_bytes_per_pixel_from_format(hnd->format, 0);
359 *out_stride = DIV_ROUND_UP(strides[0], bytes_per_pixel);
360 } else {
361 *out_stride = hnd->pixel_stride;
362 }
363
364 break;
365 case GRALLOC_DRM_GET_FORMAT:
366 out_format = va_arg(args, int32_t *);
367 *out_format = hnd->droid_format;
368 break;
369 case GRALLOC_DRM_GET_DIMENSIONS:
370 out_width = va_arg(args, uint32_t *);
371 out_height = va_arg(args, uint32_t *);
372 *out_width = hnd->width;
373 *out_height = hnd->height;
374 break;
375 case GRALLOC_DRM_GET_BACKING_STORE:
376 out_store = va_arg(args, uint64_t *);
377 ret = mod->driver->get_backing_store(handle, out_store);
378 break;
379 case GRALLOC_DRM_GET_BUFFER_INFO:
380 info = va_arg(args, struct cros_gralloc0_buffer_info *);
381 memset(info, 0, sizeof(*info));
382 info->drm_fourcc = drv_get_standard_fourcc(hnd->format);
383 info->num_fds = hnd->num_planes;
384 ret = mod->driver->resource_info(handle, strides, offsets, &format_modifier);
385 if (ret)
386 break;
387
388 info->modifier = format_modifier ? format_modifier : hnd->format_modifier;
389 for (uint32_t i = 0; i < hnd->num_planes; i++) {
390 info->fds[i] = hnd->fds[i];
391 if (strides[i]) {
392 info->stride[i] = strides[i];
393 info->offset[i] = offsets[i];
394 } else {
395 info->stride[i] = hnd->strides[i];
396 info->offset[i] = hnd->offsets[i];
397 }
398 }
399 break;
400 case GRALLOC_DRM_GET_USAGE:
401 req_usage = va_arg(args, uint32_t);
402 out_gralloc_usage = va_arg(args, uint32_t *);
403 if (req_usage & GRALLOC_DRM_GET_USAGE_FRONT_RENDERING_BIT)
404 gralloc_usage |= BUFFER_USAGE_FRONT_RENDERING;
405 *out_gralloc_usage = gralloc_usage;
406 break;
407 default:
408 ret = -EINVAL;
409 }
410
411 va_end(args);
412
413 return ret;
414 }
415
gralloc0_lock_ycbcr(struct gralloc_module_t const * module,buffer_handle_t handle,int usage,int l,int t,int w,int h,struct android_ycbcr * ycbcr)416 static int gralloc0_lock_ycbcr(struct gralloc_module_t const *module, buffer_handle_t handle,
417 int usage, int l, int t, int w, int h, struct android_ycbcr *ycbcr)
418 {
419 return module->lockAsync_ycbcr(module, handle, usage, l, t, w, h, ycbcr, -1);
420 }
421
gralloc0_lock_async(struct gralloc_module_t const * module,buffer_handle_t handle,int usage,int l,int t,int w,int h,void ** vaddr,int fence_fd)422 static int gralloc0_lock_async(struct gralloc_module_t const *module, buffer_handle_t handle,
423 int usage, int l, int t, int w, int h, void **vaddr, int fence_fd)
424 {
425 int32_t ret;
426 uint32_t map_flags;
427 uint8_t *addr[DRV_MAX_PLANES];
428 auto const_module = reinterpret_cast<const struct gralloc0_module *>(module);
429 auto mod = const_cast<struct gralloc0_module *>(const_module);
430 struct rectangle rect = { .x = static_cast<uint32_t>(l),
431 .y = static_cast<uint32_t>(t),
432 .width = static_cast<uint32_t>(w),
433 .height = static_cast<uint32_t>(h) };
434
435 if (!mod->initialized) {
436 if (gralloc0_init(mod, false))
437 return -ENODEV;
438 }
439
440 auto hnd = cros_gralloc_convert_handle(handle);
441 if (!hnd) {
442 drv_log("Invalid handle.\n");
443 return -EINVAL;
444 }
445
446 if (hnd->droid_format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
447 drv_log("HAL_PIXEL_FORMAT_YCbCr_*_888 format not compatible.\n");
448 return -EINVAL;
449 }
450
451 assert(l >= 0);
452 assert(t >= 0);
453 assert(w >= 0);
454 assert(h >= 0);
455
456 map_flags = gralloc0_convert_map_usage(usage);
457 ret = mod->driver->lock(handle, fence_fd, true, &rect, map_flags, addr);
458 *vaddr = addr[0];
459 return ret;
460 }
461
gralloc0_unlock_async(struct gralloc_module_t const * module,buffer_handle_t handle,int * fence_fd)462 static int gralloc0_unlock_async(struct gralloc_module_t const *module, buffer_handle_t handle,
463 int *fence_fd)
464 {
465 auto mod = (struct gralloc0_module const *)module;
466 return mod->driver->unlock(handle, fence_fd);
467 }
468
gralloc0_lock_async_ycbcr(struct gralloc_module_t const * module,buffer_handle_t handle,int usage,int l,int t,int w,int h,struct android_ycbcr * ycbcr,int fence_fd)469 static int gralloc0_lock_async_ycbcr(struct gralloc_module_t const *module, buffer_handle_t handle,
470 int usage, int l, int t, int w, int h,
471 struct android_ycbcr *ycbcr, int fence_fd)
472 {
473 int32_t ret;
474 uint32_t map_flags;
475 uint32_t strides[DRV_MAX_PLANES] = { 0, 0, 0, 0 };
476 uint32_t offsets[DRV_MAX_PLANES] = { 0, 0, 0, 0 };
477 uint64_t format_modifier = 0;
478 uint8_t *addr[DRV_MAX_PLANES] = { nullptr, nullptr, nullptr, nullptr };
479 auto const_module = reinterpret_cast<const struct gralloc0_module *>(module);
480 auto mod = const_cast<struct gralloc0_module *>(const_module);
481 struct rectangle rect = { .x = static_cast<uint32_t>(l),
482 .y = static_cast<uint32_t>(t),
483 .width = static_cast<uint32_t>(w),
484 .height = static_cast<uint32_t>(h) };
485
486 if (!mod->initialized) {
487 if (gralloc0_init(mod, false))
488 return -ENODEV;
489 }
490
491 auto hnd = cros_gralloc_convert_handle(handle);
492 if (!hnd) {
493 drv_log("Invalid handle.\n");
494 return -EINVAL;
495 }
496
497 if (!gralloc0_droid_yuv_format(hnd->droid_format) &&
498 hnd->droid_format != HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
499 drv_log("Non-YUV format not compatible.\n");
500 return -EINVAL;
501 }
502
503 assert(l >= 0);
504 assert(t >= 0);
505 assert(w >= 0);
506 assert(h >= 0);
507
508 map_flags = gralloc0_convert_map_usage(usage);
509 ret = mod->driver->lock(handle, fence_fd, true, &rect, map_flags, addr);
510 if (ret)
511 return ret;
512
513 if (!map_flags) {
514 ret = mod->driver->resource_info(handle, strides, offsets, &format_modifier);
515 if (ret)
516 return ret;
517
518 for (uint32_t plane = 0; plane < DRV_MAX_PLANES; plane++)
519 addr[plane] =
520 reinterpret_cast<uint8_t *>(static_cast<uintptr_t>(offsets[plane]));
521 }
522
523 switch (hnd->format) {
524 case DRM_FORMAT_NV12:
525 ycbcr->y = addr[0];
526 ycbcr->cb = addr[1];
527 ycbcr->cr = addr[1] + 1;
528 ycbcr->ystride = (!map_flags) ? strides[0] : hnd->strides[0];
529 ycbcr->cstride = (!map_flags) ? strides[1] : hnd->strides[1];
530 ycbcr->chroma_step = 2;
531 break;
532 case DRM_FORMAT_YVU420:
533 case DRM_FORMAT_YVU420_ANDROID:
534 ycbcr->y = addr[0];
535 ycbcr->cb = addr[2];
536 ycbcr->cr = addr[1];
537 ycbcr->ystride = (!map_flags) ? strides[0] : hnd->strides[0];
538 ycbcr->cstride = (!map_flags) ? strides[1] : hnd->strides[1];
539 ycbcr->chroma_step = 1;
540 break;
541 default:
542 module->unlock(module, handle);
543 return -EINVAL;
544 }
545
546 return 0;
547 }
548
549 // clang-format off
550 static struct hw_module_methods_t gralloc0_module_methods = { .open = gralloc0_open };
551 // clang-format on
552
553 struct gralloc0_module HAL_MODULE_INFO_SYM = {
554 .base =
555 {
556 .common =
557 {
558 .tag = HARDWARE_MODULE_TAG,
559 .module_api_version = GRALLOC_MODULE_API_VERSION_0_3,
560 .hal_api_version = 0,
561 .id = GRALLOC_HARDWARE_MODULE_ID,
562 .name = "CrOS Gralloc",
563 .author = "Chrome OS",
564 .methods = &gralloc0_module_methods,
565 },
566
567 .registerBuffer = gralloc0_register_buffer,
568 .unregisterBuffer = gralloc0_unregister_buffer,
569 .lock = gralloc0_lock,
570 .unlock = gralloc0_unlock,
571 .perform = gralloc0_perform,
572 .lock_ycbcr = gralloc0_lock_ycbcr,
573 .lockAsync = gralloc0_lock_async,
574 .unlockAsync = gralloc0_unlock_async,
575 .lockAsync_ycbcr = gralloc0_lock_async_ycbcr,
576 .validateBufferSize = NULL,
577 .getTransportSize = NULL,
578 },
579
580 .alloc = nullptr,
581 .driver = nullptr,
582 .initialized = false,
583 };
584