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"
10 #include <cutils/log.h>
11 #include <sync/sync.h>
13 uint32_t cros_gralloc_convert_format(int format)
16 * Conversion from HAL to fourcc-based DRV formats based on
17 * platform_android.c in mesa.
21 case HAL_PIXEL_FORMAT_BGRA_8888:
22 return DRM_FORMAT_ARGB8888;
23 case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
24 return DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED;
25 case HAL_PIXEL_FORMAT_RGB_565:
26 return DRM_FORMAT_RGB565;
27 case HAL_PIXEL_FORMAT_RGB_888:
28 return DRM_FORMAT_RGB888;
29 case HAL_PIXEL_FORMAT_RGBA_8888:
30 return DRM_FORMAT_ABGR8888;
31 case HAL_PIXEL_FORMAT_RGBX_8888:
32 return DRM_FORMAT_XBGR8888;
33 case HAL_PIXEL_FORMAT_YCbCr_420_888:
34 return DRM_FORMAT_FLEX_YCbCr_420_888;
35 case HAL_PIXEL_FORMAT_YV12:
36 return DRM_FORMAT_YVU420_ANDROID;
38 * Choose DRM_FORMAT_R8 because <system/graphics.h> requires the buffers
39 * with a format HAL_PIXEL_FORMAT_BLOB have a height of 1, and width
40 * equal to their size in bytes.
42 case HAL_PIXEL_FORMAT_BLOB:
46 return DRM_FORMAT_NONE;
49 cros_gralloc_handle_t cros_gralloc_convert_handle(buffer_handle_t handle)
51 auto hnd = reinterpret_cast<cros_gralloc_handle_t>(handle);
52 if (!hnd || hnd->magic != cros_gralloc_magic)
58 int32_t cros_gralloc_sync_wait(int32_t acquire_fence)
60 if (acquire_fence < 0)
64 * Wait initially for 1000 ms, and then wait indefinitely. The SYNC_IOC_WAIT
65 * documentation states the caller waits indefinitely on the fence if timeout < 0.
67 int err = sync_wait(acquire_fence, 1000);
69 cros_gralloc_error("Timed out on sync wait, err = %s", strerror(errno));
70 err = sync_wait(acquire_fence, -1);
72 cros_gralloc_error("sync wait error = %s", strerror(errno));
77 err = close(acquire_fence);
79 cros_gralloc_error("Unable to close fence fd, err = %s", strerror(errno));
86 void cros_gralloc_log(const char *prefix, const char *file, int line, const char *format, ...)
89 snprintf(buf, sizeof(buf), "[%s:%s(%d)]", prefix, basename(file), line);
92 va_start(args, format);
93 __android_log_vprint(ANDROID_LOG_ERROR, buf, format, args);