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 #ifndef CROS_GRALLOC_HELPERS_H
8 #define CROS_GRALLOC_HELPERS_H
11 #include "cros_gralloc_handle.h"
13 #include <hardware/gralloc.h>
14 #include <system/graphics.h>
16 /* Use these error codes derived from gralloc1 to make transition easier when
20 CROS_GRALLOC_ERROR_NONE = 0,
21 CROS_GRALLOC_ERROR_BAD_DESCRIPTOR = 1,
22 CROS_GRALLOC_ERROR_BAD_HANDLE = 2,
23 CROS_GRALLOC_ERROR_BAD_VALUE = 3,
24 CROS_GRALLOC_ERROR_NOT_SHARED = 4,
25 CROS_GRALLOC_ERROR_NO_RESOURCES = 5,
26 CROS_GRALLOC_ERROR_UNDEFINED = 6,
27 CROS_GRALLOC_ERROR_UNSUPPORTED = 7,
28 } cros_gralloc_error_t;
30 /* This enumeration must match the one in <gralloc_drm.h>.
31 * The functions supported by this gralloc's temporary private API are listed
32 * below. Use of these functions is highly discouraged and should only be
33 * reserved for cases where no alternative to get same information (such as
34 * querying ANativeWindow) exists.
38 GRALLOC_DRM_GET_STRIDE,
39 GRALLOC_DRM_GET_FORMAT,
40 GRALLOC_DRM_GET_DIMENSIONS,
41 GRALLOC_DRM_GET_BACKING_STORE,
45 constexpr uint32_t cros_gralloc_magic = 0xABCDDCBA;
47 constexpr uint32_t handle_data_size =
48 ((sizeof(struct cros_gralloc_handle) - offsetof(cros_gralloc_handle, fds[0])) / sizeof(int));
50 constexpr uint32_t sw_access = GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK;
52 uint64_t cros_gralloc_convert_flags(int flags);
54 uint32_t cros_gralloc_convert_format(int format);
56 int32_t cros_gralloc_rendernode_open(struct driver **drv);
58 int32_t cros_gralloc_validate_handle(struct cros_gralloc_handle *hnd);
60 /* Logging code adapted from bsdrm */
61 __attribute__((format(printf, 4, 5))) void cros_gralloc_log(const char *prefix, const char *file,
62 int line, const char *format, ...);
64 #define cros_gralloc_error(...) \
66 cros_gralloc_log("CROS_GRALLOC_ERROR", __FILE__, __LINE__, __VA_ARGS__); \