1 /* 2 * Copyright (c) 2021 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 SHARED_SIMPLE_GBM_H 17 #define SHARED_SIMPLE_GBM_H 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 struct gbm_device; 24 25 // gbm device 26 struct gbm_device *gbm_create_device(int fd); 27 void gbm_device_destroy(struct gbm_device *gbm); 28 29 // gbm bo 30 struct gbm_bo * gbm_bo_create(struct gbm_device *gbm, 31 uint32_t width, uint32_t height, 32 uint32_t format, uint32_t flags); 33 struct gbm_bo * gbm_bo_import(struct gbm_device *gbm, uint32_t type, void *buffer, uint32_t usage); 34 void * gbm_bo_get_user_data(struct gbm_bo *bo); 35 union gbm_bo_handle { 36 void *ptr; 37 int32_t s32; 38 uint32_t u32; 39 int64_t s64; 40 uint64_t u64; 41 }; 42 union gbm_bo_handle gbm_bo_get_handle(struct gbm_bo *bo); 43 void gbm_bo_destroy(struct gbm_bo *bo); 44 45 // gbm surface 46 struct gbm_surface * gbm_surface_create(struct gbm_device *gbm, 47 uint32_t width, uint32_t height, 48 uint32_t format, uint32_t flags); 49 50 51 enum gbm_bo_flags { 52 /** 53 * Buffer is going to be presented to the screen using an API such as KMS 54 */ 55 GBM_BO_USE_SCANOUT = (1 << 0), 56 /** 57 * Buffer is going to be used as cursor 58 */ 59 GBM_BO_USE_CURSOR = (1 << 1), 60 /** 61 * Deprecated 62 */ 63 GBM_BO_USE_CURSOR_64X64 = GBM_BO_USE_CURSOR, 64 /** 65 * Buffer is to be used for rendering - for example it is going to be used 66 * as the storage for a color buffer 67 */ 68 GBM_BO_USE_RENDERING = (1 << 2), 69 /** 70 * Buffer can be used for gbm_bo_write. This is guaranteed to work 71 * with GBM_BO_USE_CURSOR, but may not work for other combinations. 72 */ 73 GBM_BO_USE_WRITE = (1 << 3), 74 /** 75 * Buffer is linear, i.e. not tiled. 76 */ 77 GBM_BO_USE_LINEAR = (1 << 4), 78 /** 79 * Buffer is protected, i.e. encrypted and not readable by CPU or any 80 * other non-secure / non-trusted components nor by non-trusted OpenGL, 81 * OpenCL, and Vulkan applications. 82 */ 83 GBM_BO_USE_PROTECTED = (1 << 5), 84 }; 85 86 struct gbm_import_fd_data { 87 int fd; 88 uint32_t width; 89 uint32_t height; 90 uint32_t stride; 91 uint32_t format; 92 }; 93 94 #define GBM_BO_IMPORT_WL_BUFFER 0x5501 95 #define GBM_BO_IMPORT_EGL_IMAGE 0x5502 96 #define GBM_BO_IMPORT_FD 0x5503 97 #define GBM_BO_IMPORT_FD_MODIFIER 0x5504 98 99 #define __gbm_fourcc_code(a,b,c,d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \ 100 ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24)) 101 #define GBM_FORMAT_ARGB8888 __gbm_fourcc_code('A', 'R', '2', '4') /* [31:0] A:R:G:B 8:8:8:8 little endian */ 102 103 #ifdef __cplusplus 104 } 105 #endif 106 107 #endif // SHARED_SIMPLE_GBM_H 108