Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 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 "../cros_gralloc_driver.h" |
| 8 | |
| 9 | #include <hardware/gralloc.h> |
| 10 | #include <memory.h> |
| 11 | |
| 12 | struct gralloc0_module { |
| 13 | gralloc_module_t base; |
| 14 | std::unique_ptr<alloc_device_t> alloc; |
| 15 | std::unique_ptr<cros_gralloc_driver> driver; |
Gurchetan Singh | bcfd758 | 2017-08-01 15:02:24 -0700 | [diff] [blame] | 16 | bool initialized; |
| 17 | std::mutex initialization_mutex; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 18 | }; |
| 19 | |
| 20 | /* This enumeration must match the one in <gralloc_drm.h>. |
| 21 | * The functions supported by this gralloc's temporary private API are listed |
| 22 | * below. Use of these functions is highly discouraged and should only be |
| 23 | * reserved for cases where no alternative to get same information (such as |
| 24 | * querying ANativeWindow) exists. |
| 25 | */ |
| 26 | // clang-format off |
| 27 | enum { |
| 28 | GRALLOC_DRM_GET_STRIDE, |
| 29 | GRALLOC_DRM_GET_FORMAT, |
| 30 | GRALLOC_DRM_GET_DIMENSIONS, |
| 31 | GRALLOC_DRM_GET_BACKING_STORE, |
| 32 | }; |
| 33 | // clang-format on |
| 34 | |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 35 | static uint64_t gralloc0_convert_usage(int usage) |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 36 | { |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 37 | uint64_t use_flags = BO_USE_NONE; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 38 | |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 39 | if (usage & GRALLOC_USAGE_CURSOR) |
| 40 | use_flags |= BO_USE_NONE; |
| 41 | if ((usage & GRALLOC_USAGE_SW_READ_MASK) == GRALLOC_USAGE_SW_READ_RARELY) |
| 42 | use_flags |= BO_USE_SW_READ_RARELY; |
| 43 | if ((usage & GRALLOC_USAGE_SW_READ_MASK) == GRALLOC_USAGE_SW_READ_OFTEN) |
| 44 | use_flags |= BO_USE_SW_READ_OFTEN; |
| 45 | if ((usage & GRALLOC_USAGE_SW_WRITE_MASK) == GRALLOC_USAGE_SW_WRITE_RARELY) |
| 46 | use_flags |= BO_USE_SW_WRITE_RARELY; |
| 47 | if ((usage & GRALLOC_USAGE_SW_WRITE_MASK) == GRALLOC_USAGE_SW_WRITE_OFTEN) |
| 48 | use_flags |= BO_USE_SW_WRITE_OFTEN; |
| 49 | if (usage & GRALLOC_USAGE_HW_TEXTURE) |
| 50 | use_flags |= BO_USE_TEXTURE; |
| 51 | if (usage & GRALLOC_USAGE_HW_RENDER) |
| 52 | use_flags |= BO_USE_RENDERING; |
| 53 | if (usage & GRALLOC_USAGE_HW_2D) |
| 54 | use_flags |= BO_USE_RENDERING; |
| 55 | if (usage & GRALLOC_USAGE_HW_COMPOSER) |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 56 | /* HWC wants to use display hardware, but can defer to OpenGL. */ |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 57 | use_flags |= BO_USE_SCANOUT | BO_USE_TEXTURE; |
| 58 | if (usage & GRALLOC_USAGE_HW_FB) |
| 59 | use_flags |= BO_USE_NONE; |
| 60 | if (usage & GRALLOC_USAGE_EXTERNAL_DISP) |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 61 | /* |
| 62 | * This flag potentially covers external display for the normal drivers (i915, |
| 63 | * rockchip) and usb monitors (evdi/udl). It's complicated so ignore it. |
| 64 | * */ |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 65 | use_flags |= BO_USE_NONE; |
| 66 | if (usage & GRALLOC_USAGE_PROTECTED) |
| 67 | use_flags |= BO_USE_PROTECTED; |
| 68 | if (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 69 | /*HACK: See b/30054495 */ |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 70 | use_flags |= BO_USE_SW_READ_OFTEN; |
| 71 | if (usage & GRALLOC_USAGE_HW_CAMERA_WRITE) |
| 72 | use_flags |= BO_USE_CAMERA_WRITE; |
| 73 | if (usage & GRALLOC_USAGE_HW_CAMERA_READ) |
| 74 | use_flags |= BO_USE_CAMERA_READ; |
| 75 | if (usage & GRALLOC_USAGE_RENDERSCRIPT) |
| 76 | use_flags |= BO_USE_RENDERSCRIPT; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 77 | |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 78 | return use_flags; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Gurchetan Singh | f7f633a | 2017-09-28 17:02:12 -0700 | [diff] [blame^] | 81 | static uint32_t gralloc0_convert_map_usage(int map_usage) |
| 82 | { |
| 83 | uint32_t map_flags = BO_MAP_NONE; |
| 84 | |
| 85 | if (map_usage & GRALLOC_USAGE_SW_READ_MASK) |
| 86 | map_flags |= BO_MAP_READ; |
| 87 | if (map_usage & GRALLOC_USAGE_SW_WRITE_MASK) |
| 88 | map_flags |= BO_MAP_WRITE; |
| 89 | |
| 90 | return map_flags; |
| 91 | } |
| 92 | |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 93 | static int gralloc0_alloc(alloc_device_t *dev, int w, int h, int format, int usage, |
| 94 | buffer_handle_t *handle, int *stride) |
| 95 | { |
| 96 | int32_t ret; |
| 97 | bool supported; |
| 98 | struct cros_gralloc_buffer_descriptor descriptor; |
| 99 | auto mod = (struct gralloc0_module *)dev->common.module; |
| 100 | |
| 101 | descriptor.width = w; |
| 102 | descriptor.height = h; |
| 103 | descriptor.droid_format = format; |
| 104 | descriptor.producer_usage = descriptor.consumer_usage = usage; |
| 105 | descriptor.drm_format = cros_gralloc_convert_format(format); |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 106 | descriptor.use_flags = gralloc0_convert_usage(usage); |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 107 | |
| 108 | supported = mod->driver->is_supported(&descriptor); |
| 109 | if (!supported && (usage & GRALLOC_USAGE_HW_COMPOSER)) { |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 110 | descriptor.use_flags &= ~BO_USE_SCANOUT; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 111 | supported = mod->driver->is_supported(&descriptor); |
| 112 | } |
| 113 | |
| 114 | if (!supported) { |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 115 | cros_gralloc_error("Unsupported combination -- HAL format: %u, HAL usage: %u, " |
| 116 | "drv_format: %4.4s, use_flags: %llu", |
Tomasz Figa | 23b85cb | 2017-07-11 18:07:11 +0900 | [diff] [blame] | 117 | format, usage, reinterpret_cast<char *>(&descriptor.drm_format), |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 118 | static_cast<unsigned long long>(descriptor.use_flags)); |
Tomasz Figa | 90bb743 | 2017-07-21 17:54:05 +0900 | [diff] [blame] | 119 | return -EINVAL; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | ret = mod->driver->allocate(&descriptor, handle); |
| 123 | if (ret) |
| 124 | return ret; |
| 125 | |
| 126 | auto hnd = cros_gralloc_convert_handle(*handle); |
| 127 | *stride = hnd->pixel_stride; |
| 128 | |
Tomasz Figa | 90bb743 | 2017-07-21 17:54:05 +0900 | [diff] [blame] | 129 | return 0; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | static int gralloc0_free(alloc_device_t *dev, buffer_handle_t handle) |
| 133 | { |
| 134 | auto mod = (struct gralloc0_module *)dev->common.module; |
| 135 | return mod->driver->release(handle); |
| 136 | } |
| 137 | |
| 138 | static int gralloc0_close(struct hw_device_t *dev) |
| 139 | { |
| 140 | /* Memory is freed by managed pointers on process close. */ |
Tomasz Figa | 90bb743 | 2017-07-21 17:54:05 +0900 | [diff] [blame] | 141 | return 0; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Gurchetan Singh | bcfd758 | 2017-08-01 15:02:24 -0700 | [diff] [blame] | 144 | static int gralloc0_init(struct gralloc0_module *mod, bool initialize_alloc) |
| 145 | { |
| 146 | std::lock_guard<std::mutex> lock(mod->initialization_mutex); |
| 147 | |
| 148 | if (mod->initialized) |
| 149 | return 0; |
| 150 | |
| 151 | mod->driver = std::make_unique<cros_gralloc_driver>(); |
| 152 | if (mod->driver->init()) { |
| 153 | cros_gralloc_error("Failed to initialize driver."); |
| 154 | return -ENODEV; |
| 155 | } |
| 156 | |
| 157 | if (initialize_alloc) { |
| 158 | mod->alloc = std::make_unique<alloc_device_t>(); |
| 159 | mod->alloc->alloc = gralloc0_alloc; |
| 160 | mod->alloc->free = gralloc0_free; |
| 161 | mod->alloc->common.tag = HARDWARE_DEVICE_TAG; |
| 162 | mod->alloc->common.version = 0; |
| 163 | mod->alloc->common.module = (hw_module_t *)mod; |
| 164 | mod->alloc->common.close = gralloc0_close; |
| 165 | } |
| 166 | |
| 167 | mod->initialized = true; |
| 168 | return 0; |
| 169 | } |
| 170 | |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 171 | static int gralloc0_open(const struct hw_module_t *mod, const char *name, struct hw_device_t **dev) |
| 172 | { |
| 173 | auto module = (struct gralloc0_module *)mod; |
| 174 | |
Gurchetan Singh | bcfd758 | 2017-08-01 15:02:24 -0700 | [diff] [blame] | 175 | if (module->initialized) { |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 176 | *dev = &module->alloc->common; |
Tomasz Figa | 90bb743 | 2017-07-21 17:54:05 +0900 | [diff] [blame] | 177 | return 0; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | if (strcmp(name, GRALLOC_HARDWARE_GPU0)) { |
| 181 | cros_gralloc_error("Incorrect device name - %s.", name); |
Tomasz Figa | 90bb743 | 2017-07-21 17:54:05 +0900 | [diff] [blame] | 182 | return -EINVAL; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Gurchetan Singh | bcfd758 | 2017-08-01 15:02:24 -0700 | [diff] [blame] | 185 | if (gralloc0_init(module, true)) |
| 186 | return -ENODEV; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 187 | |
| 188 | *dev = &module->alloc->common; |
Tomasz Figa | 90bb743 | 2017-07-21 17:54:05 +0900 | [diff] [blame] | 189 | return 0; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | static int gralloc0_register_buffer(struct gralloc_module_t const *module, buffer_handle_t handle) |
| 193 | { |
| 194 | auto mod = (struct gralloc0_module *)module; |
| 195 | |
Gurchetan Singh | bcfd758 | 2017-08-01 15:02:24 -0700 | [diff] [blame] | 196 | if (!mod->initialized) |
| 197 | if (gralloc0_init(mod, false)) |
| 198 | return -ENODEV; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 199 | |
| 200 | return mod->driver->retain(handle); |
| 201 | } |
| 202 | |
| 203 | static int gralloc0_unregister_buffer(struct gralloc_module_t const *module, buffer_handle_t handle) |
| 204 | { |
| 205 | auto mod = (struct gralloc0_module *)module; |
| 206 | return mod->driver->release(handle); |
| 207 | } |
| 208 | |
| 209 | static int gralloc0_lock(struct gralloc_module_t const *module, buffer_handle_t handle, int usage, |
| 210 | int l, int t, int w, int h, void **vaddr) |
| 211 | { |
Gurchetan Singh | 4b5d0bf | 2017-06-22 18:38:37 -0700 | [diff] [blame] | 212 | return module->lockAsync(module, handle, usage, l, t, w, h, vaddr, -1); |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static int gralloc0_unlock(struct gralloc_module_t const *module, buffer_handle_t handle) |
| 216 | { |
Gurchetan Singh | 4b5d0bf | 2017-06-22 18:38:37 -0700 | [diff] [blame] | 217 | int32_t fence_fd, ret; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 218 | auto mod = (struct gralloc0_module *)module; |
Gurchetan Singh | 4b5d0bf | 2017-06-22 18:38:37 -0700 | [diff] [blame] | 219 | ret = mod->driver->unlock(handle, &fence_fd); |
| 220 | if (ret) |
| 221 | return ret; |
| 222 | |
| 223 | ret = cros_gralloc_sync_wait(fence_fd); |
| 224 | if (ret) |
| 225 | return ret; |
| 226 | |
| 227 | return 0; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static int gralloc0_perform(struct gralloc_module_t const *module, int op, ...) |
| 231 | { |
| 232 | va_list args; |
| 233 | int32_t *out_format, ret; |
| 234 | uint64_t *out_store; |
| 235 | buffer_handle_t handle; |
| 236 | uint32_t *out_width, *out_height, *out_stride; |
| 237 | auto mod = (struct gralloc0_module *)module; |
| 238 | |
| 239 | switch (op) { |
| 240 | case GRALLOC_DRM_GET_STRIDE: |
| 241 | case GRALLOC_DRM_GET_FORMAT: |
| 242 | case GRALLOC_DRM_GET_DIMENSIONS: |
| 243 | case GRALLOC_DRM_GET_BACKING_STORE: |
| 244 | break; |
| 245 | default: |
Tomasz Figa | 90bb743 | 2017-07-21 17:54:05 +0900 | [diff] [blame] | 246 | return -EINVAL; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | va_start(args, op); |
| 250 | |
Tomasz Figa | 90bb743 | 2017-07-21 17:54:05 +0900 | [diff] [blame] | 251 | ret = 0; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 252 | handle = va_arg(args, buffer_handle_t); |
| 253 | auto hnd = cros_gralloc_convert_handle(handle); |
| 254 | if (!hnd) { |
| 255 | cros_gralloc_error("Invalid handle."); |
Tomasz Figa | 90bb743 | 2017-07-21 17:54:05 +0900 | [diff] [blame] | 256 | return -EINVAL; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | switch (op) { |
| 260 | case GRALLOC_DRM_GET_STRIDE: |
| 261 | out_stride = va_arg(args, uint32_t *); |
| 262 | *out_stride = hnd->pixel_stride; |
| 263 | break; |
| 264 | case GRALLOC_DRM_GET_FORMAT: |
| 265 | out_format = va_arg(args, int32_t *); |
| 266 | *out_format = hnd->droid_format; |
| 267 | break; |
| 268 | case GRALLOC_DRM_GET_DIMENSIONS: |
| 269 | out_width = va_arg(args, uint32_t *); |
| 270 | out_height = va_arg(args, uint32_t *); |
| 271 | *out_width = hnd->width; |
| 272 | *out_height = hnd->height; |
| 273 | break; |
| 274 | case GRALLOC_DRM_GET_BACKING_STORE: |
| 275 | out_store = va_arg(args, uint64_t *); |
| 276 | ret = mod->driver->get_backing_store(handle, out_store); |
| 277 | break; |
| 278 | default: |
Tomasz Figa | 90bb743 | 2017-07-21 17:54:05 +0900 | [diff] [blame] | 279 | ret = -EINVAL; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | va_end(args); |
| 283 | |
| 284 | return ret; |
| 285 | } |
| 286 | |
| 287 | static int gralloc0_lock_ycbcr(struct gralloc_module_t const *module, buffer_handle_t handle, |
| 288 | int usage, int l, int t, int w, int h, struct android_ycbcr *ycbcr) |
| 289 | { |
Gurchetan Singh | 4b5d0bf | 2017-06-22 18:38:37 -0700 | [diff] [blame] | 290 | return module->lockAsync_ycbcr(module, handle, usage, l, t, w, h, ycbcr, -1); |
| 291 | } |
| 292 | |
| 293 | static int gralloc0_lock_async(struct gralloc_module_t const *module, buffer_handle_t handle, |
| 294 | int usage, int l, int t, int w, int h, void **vaddr, int fence_fd) |
| 295 | { |
| 296 | int32_t ret; |
Gurchetan Singh | f7f633a | 2017-09-28 17:02:12 -0700 | [diff] [blame^] | 297 | uint32_t map_flags; |
Gurchetan Singh | 4b5d0bf | 2017-06-22 18:38:37 -0700 | [diff] [blame] | 298 | uint8_t *addr[DRV_MAX_PLANES]; |
| 299 | auto mod = (struct gralloc0_module *)module; |
| 300 | |
| 301 | auto hnd = cros_gralloc_convert_handle(handle); |
| 302 | if (!hnd) { |
| 303 | cros_gralloc_error("Invalid handle."); |
| 304 | return -EINVAL; |
| 305 | } |
| 306 | |
| 307 | if (hnd->droid_format == HAL_PIXEL_FORMAT_YCbCr_420_888) { |
| 308 | cros_gralloc_error("HAL_PIXEL_FORMAT_YCbCr_*_888 format not compatible."); |
| 309 | return -EINVAL; |
| 310 | } |
| 311 | |
Gurchetan Singh | f7f633a | 2017-09-28 17:02:12 -0700 | [diff] [blame^] | 312 | map_flags = gralloc0_convert_map_usage(usage); |
| 313 | ret = mod->driver->lock(handle, fence_fd, map_flags, addr); |
Gurchetan Singh | 4b5d0bf | 2017-06-22 18:38:37 -0700 | [diff] [blame] | 314 | *vaddr = addr[0]; |
| 315 | return ret; |
| 316 | } |
| 317 | |
| 318 | static int gralloc0_unlock_async(struct gralloc_module_t const *module, buffer_handle_t handle, |
| 319 | int *fence_fd) |
| 320 | { |
| 321 | auto mod = (struct gralloc0_module *)module; |
| 322 | return mod->driver->unlock(handle, fence_fd); |
| 323 | } |
| 324 | |
| 325 | static int gralloc0_lock_async_ycbcr(struct gralloc_module_t const *module, buffer_handle_t handle, |
| 326 | int usage, int l, int t, int w, int h, |
| 327 | struct android_ycbcr *ycbcr, int fence_fd) |
| 328 | { |
Gurchetan Singh | 4b5d0bf | 2017-06-22 18:38:37 -0700 | [diff] [blame] | 329 | int32_t ret; |
Gurchetan Singh | f7f633a | 2017-09-28 17:02:12 -0700 | [diff] [blame^] | 330 | uint32_t map_flags; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 331 | uint8_t *addr[DRV_MAX_PLANES] = { nullptr, nullptr, nullptr, nullptr }; |
| 332 | auto mod = (struct gralloc0_module *)module; |
| 333 | |
| 334 | auto hnd = cros_gralloc_convert_handle(handle); |
| 335 | if (!hnd) { |
| 336 | cros_gralloc_error("Invalid handle."); |
Tomasz Figa | 90bb743 | 2017-07-21 17:54:05 +0900 | [diff] [blame] | 337 | return -EINVAL; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | if ((hnd->droid_format != HAL_PIXEL_FORMAT_YCbCr_420_888) && |
Tomasz Figa | aff29fd | 2017-07-05 17:50:18 +0900 | [diff] [blame] | 341 | (hnd->droid_format != HAL_PIXEL_FORMAT_YV12) && |
| 342 | (hnd->droid_format != HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED)) { |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 343 | cros_gralloc_error("Non-YUV format not compatible."); |
Tomasz Figa | 90bb743 | 2017-07-21 17:54:05 +0900 | [diff] [blame] | 344 | return -EINVAL; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Gurchetan Singh | f7f633a | 2017-09-28 17:02:12 -0700 | [diff] [blame^] | 347 | map_flags = gralloc0_convert_map_usage(usage); |
| 348 | ret = mod->driver->lock(handle, fence_fd, map_flags, addr); |
Tomasz Figa | addd5f2 | 2017-07-05 17:50:18 +0900 | [diff] [blame] | 349 | if (ret) |
| 350 | return ret; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 351 | |
| 352 | switch (hnd->format) { |
| 353 | case DRM_FORMAT_NV12: |
| 354 | ycbcr->y = addr[0]; |
| 355 | ycbcr->cb = addr[1]; |
| 356 | ycbcr->cr = addr[1] + 1; |
| 357 | ycbcr->ystride = hnd->strides[0]; |
| 358 | ycbcr->cstride = hnd->strides[1]; |
| 359 | ycbcr->chroma_step = 2; |
| 360 | break; |
| 361 | case DRM_FORMAT_YVU420: |
| 362 | case DRM_FORMAT_YVU420_ANDROID: |
| 363 | ycbcr->y = addr[0]; |
| 364 | ycbcr->cb = addr[2]; |
| 365 | ycbcr->cr = addr[1]; |
| 366 | ycbcr->ystride = hnd->strides[0]; |
| 367 | ycbcr->cstride = hnd->strides[1]; |
| 368 | ycbcr->chroma_step = 1; |
| 369 | break; |
| 370 | default: |
Gurchetan Singh | 4b5d0bf | 2017-06-22 18:38:37 -0700 | [diff] [blame] | 371 | module->unlock(module, handle); |
Tomasz Figa | 90bb743 | 2017-07-21 17:54:05 +0900 | [diff] [blame] | 372 | return -EINVAL; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Tomasz Figa | 90bb743 | 2017-07-21 17:54:05 +0900 | [diff] [blame] | 375 | return 0; |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Tomasz Figa | 4df286c | 2017-08-02 19:35:40 +0900 | [diff] [blame] | 378 | // clang-format off |
| 379 | static struct hw_module_methods_t gralloc0_module_methods = { .open = gralloc0_open }; |
| 380 | // clang-format on |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 381 | |
| 382 | struct gralloc0_module HAL_MODULE_INFO_SYM = { |
| 383 | .base = |
| 384 | { |
| 385 | .common = |
| 386 | { |
| 387 | .tag = HARDWARE_MODULE_TAG, |
Gurchetan Singh | 4b5d0bf | 2017-06-22 18:38:37 -0700 | [diff] [blame] | 388 | .module_api_version = GRALLOC_MODULE_API_VERSION_0_3, |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 389 | .hal_api_version = 0, |
| 390 | .id = GRALLOC_HARDWARE_MODULE_ID, |
| 391 | .name = "CrOS Gralloc", |
| 392 | .author = "Chrome OS", |
| 393 | .methods = &gralloc0_module_methods, |
| 394 | }, |
| 395 | |
| 396 | .registerBuffer = gralloc0_register_buffer, |
| 397 | .unregisterBuffer = gralloc0_unregister_buffer, |
| 398 | .lock = gralloc0_lock, |
| 399 | .unlock = gralloc0_unlock, |
| 400 | .perform = gralloc0_perform, |
| 401 | .lock_ycbcr = gralloc0_lock_ycbcr, |
Gurchetan Singh | 4b5d0bf | 2017-06-22 18:38:37 -0700 | [diff] [blame] | 402 | .lockAsync = gralloc0_lock_async, |
| 403 | .unlockAsync = gralloc0_unlock_async, |
| 404 | .lockAsync_ycbcr = gralloc0_lock_async_ycbcr, |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 405 | }, |
| 406 | |
| 407 | .alloc = nullptr, |
| 408 | .driver = nullptr, |
Gurchetan Singh | bcfd758 | 2017-08-01 15:02:24 -0700 | [diff] [blame] | 409 | .initialized = false, |
Gurchetan Singh | d6b8b03 | 2017-05-31 14:31:31 -0700 | [diff] [blame] | 410 | }; |