xref: /aosp_15_r20/external/mesa3d/src/util/u_gralloc/u_gralloc.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 2022 Roman Stratiienko ([email protected])
5  * SPDX-License-Identifier: MIT
6  */
7 
8 #ifndef U_GRALLOC_H
9 #define U_GRALLOC_H
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 #include <cutils/native_handle.h>
16 
17 #include <stdbool.h>
18 
19 #include "util/macros.h"
20 #include "gallium/include/mesa_interface.h"
21 
22 struct u_gralloc;
23 
24 /* Both Vulkan and EGL API exposes HAL format / pixel stride which is required
25  * by the fallback implementation.
26  */
27 struct u_gralloc_buffer_handle {
28    const native_handle_t *handle;
29    int hal_format;
30    int pixel_stride;
31 };
32 
33 struct u_gralloc_buffer_basic_info {
34    uint32_t drm_fourcc;
35    uint64_t modifier;
36 
37    int num_planes;
38    int fds[4];
39    int offsets[4];
40    int strides[4];
41 };
42 
43 struct u_gralloc_buffer_color_info {
44    enum __DRIYUVColorSpace yuv_color_space;
45    enum __DRISampleRange sample_range;
46    enum __DRIChromaSiting horizontal_siting;
47    enum __DRIChromaSiting vertical_siting;
48 };
49 
50 enum u_gralloc_type {
51    U_GRALLOC_TYPE_AUTO,
52    U_GRALLOC_TYPE_GRALLOC4,
53    U_GRALLOC_TYPE_CROS,
54    U_GRALLOC_TYPE_LIBDRM,
55    U_GRALLOC_TYPE_QCOM,
56    U_GRALLOC_TYPE_FALLBACK,
57    U_GRALLOC_TYPE_COUNT,
58 };
59 
60 struct u_gralloc *u_gralloc_create(enum u_gralloc_type type);
61 
62 void u_gralloc_destroy(struct u_gralloc **gralloc);
63 
64 int u_gralloc_get_buffer_basic_info(
65    struct u_gralloc *gralloc,
66    struct u_gralloc_buffer_handle *hnd,
67    struct u_gralloc_buffer_basic_info *out);
68 
69 int u_gralloc_get_buffer_color_info(
70    struct u_gralloc *gralloc,
71    struct u_gralloc_buffer_handle *hnd,
72    struct u_gralloc_buffer_color_info *out);
73 
74 int u_gralloc_get_front_rendering_usage(struct u_gralloc *gralloc,
75                                         uint64_t *out_usage);
76 
77 int u_gralloc_get_type(struct u_gralloc *gralloc);
78 
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 #endif /* U_GRALLOC_H */
84