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.
7 #include "cros_gralloc_helpers.h"
11 uint32_t cros_gralloc_convert_format(int format)
14 * Conversion from HAL to fourcc-based DRV formats based on
15 * platform_android.c in mesa.
19 case HAL_PIXEL_FORMAT_BGRA_8888:
20 return DRM_FORMAT_ARGB8888;
21 case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
22 return DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED;
23 case HAL_PIXEL_FORMAT_RGB_565:
24 return DRM_FORMAT_RGB565;
25 case HAL_PIXEL_FORMAT_RGB_888:
26 return DRM_FORMAT_BGR888;
27 case HAL_PIXEL_FORMAT_RGBA_8888:
28 return DRM_FORMAT_ABGR8888;
29 case HAL_PIXEL_FORMAT_RGBX_8888:
30 return DRM_FORMAT_XBGR8888;
31 case HAL_PIXEL_FORMAT_YCbCr_420_888:
32 return DRM_FORMAT_FLEX_YCbCr_420_888;
33 case HAL_PIXEL_FORMAT_YV12:
34 return DRM_FORMAT_YVU420_ANDROID;
36 * Choose DRM_FORMAT_R8 because <system/graphics.h> requires the buffers
37 * with a format HAL_PIXEL_FORMAT_BLOB have a height of 1, and width
38 * equal to their size in bytes.
40 case HAL_PIXEL_FORMAT_BLOB:
44 return DRM_FORMAT_NONE;
47 cros_gralloc_handle_t cros_gralloc_convert_handle(buffer_handle_t handle)
49 auto hnd = reinterpret_cast<cros_gralloc_handle_t>(handle);
50 if (!hnd || hnd->magic != cros_gralloc_magic)
56 int32_t cros_gralloc_sync_wait(int32_t acquire_fence)
58 if (acquire_fence < 0)
62 * Wait initially for 1000 ms, and then wait indefinitely. The SYNC_IOC_WAIT
63 * documentation states the caller waits indefinitely on the fence if timeout < 0.
65 int err = sync_wait(acquire_fence, 1000);
67 drv_log("Timed out on sync wait, err = %s\n", strerror(errno));
68 err = sync_wait(acquire_fence, -1);
70 drv_log("sync wait error = %s\n", strerror(errno));
75 err = close(acquire_fence);
77 drv_log("Unable to close fence fd, err = %s\n", strerror(errno));