1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HI_GBM_H
17 #define HI_GBM_H
18 #include <cstdint>
19 
20 namespace OHOS {
21 namespace HDI {
22 namespace DISPLAY {
23 struct gbm_device;
24 struct gbm_bo;
25 
26 enum gbm_bo_flags {
27     /* *
28      * Buffer is going to be presented to the screen using an API such as KMS
29      */
30     GBM_BO_USE_SCANOUT = (1 << 0),
31     /* *
32      * Buffer is going to be used as cursor
33      */
34     GBM_BO_USE_CURSOR = (1 << 1),
35     /* *
36      * Deprecated
37      */
38     GBM_BO_USE_CURSOR_64X64 = GBM_BO_USE_CURSOR,
39     /* *
40      * Buffer is to be used for rendering - for example it is going to be used
41      * as the storage for a color buffer
42      */
43     GBM_BO_USE_RENDERING = (1 << 2),
44     /* *
45      * Deprecated
46      */
47     GBM_BO_USE_WRITE = (1 << 3),
48     /* *
49      * Buffer is guaranteed to be laid out linearly in memory. That is, the
50      * buffer is laid out as an array with 'height' blocks, each block with
51      * length 'stride'. Each stride is in the same order as the rows of the
52      * buffer. This is intended to be used with buffers that will be accessed
53      * via dma-buf mmap().
54      */
55     GBM_BO_USE_LINEAR = (1 << 4),
56     /* *
57      * The buffer will be used as a texture that will be sampled from.
58      */
59     GBM_BO_USE_TEXTURING = (1 << 5),
60     /* *
61      * The buffer will be written to by a camera subsystem.
62      */
63     GBM_BO_USE_CAMERA_WRITE = (1 << 6),
64     /* *
65      * The buffer will be read from by a camera subsystem.
66      */
67     GBM_BO_USE_CAMERA_READ = (1 << 7),
68     /* *
69      * Buffer inaccessible to unprivileged users.
70      */
71     GBM_BO_USE_PROTECTED = (1 << 8),
72     /* *
73      * These flags specify the frequency of software access. These flags do not
74      * guarantee the buffer is linear, but do guarantee gbm_bo_map(..) will
75      * present a linear view.
76      */
77     GBM_BO_USE_SW_READ_OFTEN = (1 << 9),
78     GBM_BO_USE_SW_READ_RARELY = (1 << 10),
79     GBM_BO_USE_SW_WRITE_OFTEN = (1 << 11),
80     GBM_BO_USE_SW_WRITE_RARELY = (1 << 12),
81     /* *
82      * The buffer will be written by a video decode accelerator.
83      */
84     GBM_BO_USE_HW_VIDEO_DECODER = (1 << 13),
85 };
86 
87 struct gbm_device *HdiGbmCreateDevice(int fd);
88 void HdiGbmDeviceDestroy(struct gbm_device *gbm);
89 struct gbm_bo *HdiGbmBoCreate(struct gbm_device *gbm, uint32_t width, uint32_t height,
90     uint32_t format, uint32_t usage);
91 uint32_t HdiGbmBoGetStride(struct gbm_bo *bo);
92 uint32_t HdiGbmBoGetWidth(struct gbm_bo *bo);
93 uint32_t HdiGbmBoGetHeight(struct gbm_bo *bo);
94 uint32_t HdiGbmBoGetSize(struct gbm_bo *bo);
95 void HdiGbmBoDestroy(struct gbm_bo *bo);
96 int HdiGbmBoGetFd(struct gbm_bo *bo);
97 } // namespace DISPLAY
98 } // namespace HDI
99 } // namespace OHOS
100 #endif // HI_GBM_H
101