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"
9 #include "i915_private_android.h"
12 #include <cutils/log.h>
13 #include <sync/sync.h>
17 const char* drmFormat2Str(int drm_format)
20 char *pDrmFormat = (char*) &drm_format;
21 snprintf(buf, sizeof(buf), "%c%c%c%c", *pDrmFormat, *(pDrmFormat + 1),
22 *(pDrmFormat + 2), *(pDrmFormat + 3));
26 uint32_t cros_gralloc_convert_format(int format)
29 * Conversion from HAL to fourcc-based DRV formats based on
30 * platform_android.c in mesa.
34 case HAL_PIXEL_FORMAT_BGRA_8888:
35 return DRM_FORMAT_ARGB8888;
36 case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
37 return DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED;
38 case HAL_PIXEL_FORMAT_RGB_565:
39 return DRM_FORMAT_RGB565;
40 case HAL_PIXEL_FORMAT_RGB_888:
41 return DRM_FORMAT_RGB888;
42 case HAL_PIXEL_FORMAT_RGBA_8888:
43 return DRM_FORMAT_ABGR8888;
44 case HAL_PIXEL_FORMAT_RGBX_8888:
45 return DRM_FORMAT_XBGR8888;
46 case HAL_PIXEL_FORMAT_YCbCr_420_888:
47 return DRM_FORMAT_FLEX_YCbCr_420_888;
48 case HAL_PIXEL_FORMAT_YV12:
49 return DRM_FORMAT_YVU420_ANDROID;
51 * Choose DRM_FORMAT_R8 because <system/graphics.h> requires the buffers
52 * with a format HAL_PIXEL_FORMAT_BLOB have a height of 1, and width
53 * equal to their size in bytes.
55 case HAL_PIXEL_FORMAT_BLOB:
59 return i915_private_convert_format(format);
62 cros_gralloc_handle_t cros_gralloc_convert_handle(buffer_handle_t handle)
64 auto hnd = reinterpret_cast<cros_gralloc_handle_t>(handle);
65 if (!hnd || hnd->magic != cros_gralloc_magic)
71 int32_t cros_gralloc_sync_wait(int32_t acquire_fence)
73 if (acquire_fence < 0)
77 * Wait initially for 1000 ms, and then wait indefinitely. The SYNC_IOC_WAIT
78 * documentation states the caller waits indefinitely on the fence if timeout < 0.
80 int err = sync_wait(acquire_fence, 1000);
82 cros_gralloc_error("Timed out on sync wait, err = %s", strerror(errno));
83 err = sync_wait(acquire_fence, -1);
85 cros_gralloc_error("sync wait error = %s", strerror(errno));
90 err = close(acquire_fence);
92 cros_gralloc_error("Unable to close fence fd, err = %s", strerror(errno));
99 void cros_gralloc_log(const char *prefix, const char *file, int line, const char *format, ...)
102 snprintf(buf, sizeof(buf), "[%s:%s(%d)]", prefix, basename(file), line);
105 va_start(args, format);
106 __android_log_vprint(ANDROID_LOG_ERROR, buf, format, args);