OSDN Git Service

minigbm: Ensure DRM_FORMAT_YVU420_ANDROID meets Android requirements.
[android-x86/external-minigbm.git] / cros_gralloc / cros_gralloc_helpers.h
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 #ifndef CROS_GRALLOC_HELPERS_H
8 #define CROS_GRALLOC_HELPERS_H
9
10 #include "../drv.h"
11 #include "cros_gralloc_handle.h"
12
13 #include <hardware/gralloc.h>
14 #include <system/graphics.h>
15
16 /* Use these error codes derived from gralloc1 to make transition easier when
17  * it happens
18  */
19 typedef enum {
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;
29
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.
35  */
36 // clang-format off
37 enum {
38         GRALLOC_DRM_GET_STRIDE,
39         GRALLOC_DRM_GET_FORMAT,
40         GRALLOC_DRM_GET_DIMENSIONS,
41         GRALLOC_DRM_GET_BACKING_STORE,
42 };
43 // clang-format on
44
45 constexpr uint32_t cros_gralloc_magic = 0xABCDDCBA;
46
47 constexpr uint32_t handle_data_size =
48     ((sizeof(struct cros_gralloc_handle) - offsetof(cros_gralloc_handle, fds[0])) / sizeof(int));
49
50 constexpr uint32_t sw_access = GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK;
51
52 uint64_t cros_gralloc_convert_flags(int flags);
53
54 uint32_t cros_gralloc_convert_format(int format);
55
56 int32_t cros_gralloc_rendernode_open(struct driver **drv);
57
58 int32_t cros_gralloc_validate_handle(struct cros_gralloc_handle *hnd);
59
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, ...);
63
64 #define cros_gralloc_error(...)                                                                    \
65         do {                                                                                       \
66                 cros_gralloc_log("CROS_GRALLOC_ERROR", __FILE__, __LINE__, __VA_ARGS__);           \
67         } while (0)
68
69 #endif