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 DISPLAY_GRALLOC_GBM_H 17 #define DISPLAY_GRALLOC_GBM_H 18 #include "display_type.h" 19 #include "hdf_dlist.h" 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 enum { 25 AW_YUV_NO_INFO, 26 AW_YUV_BT601_NARROW, 27 AW_YUV_BT601_WIDE, 28 AW_YUV_BT709_NARROW, 29 AW_YUV_BT709_WIDE 30 }; 31 32 typedef struct { 33 struct gbm_device *gbmDevice; 34 int drmFd; 35 struct DListHead gbmBoHead; 36 int32_t referCount; 37 } GrallocManager; 38 39 typedef struct { 40 struct DListHead entry; 41 struct gbm_bo *bo; 42 int fd; 43 } GbmBoList; 44 45 int32_t GbmAllocMem(const AllocInfo *info, BufferHandle **buffer); 46 void GbmFreeMem(BufferHandle *buffer); 47 void *GbmMmap(BufferHandle *buffer); 48 int32_t GbmUnmap(BufferHandle *buffer); 49 int32_t GbmInvalidateCache(BufferHandle *buffer); 50 int32_t GbmFlushCache(BufferHandle *buffer); 51 int32_t GbmGrallocUninitialize(void); 52 int32_t GbmGrallocInitialize(void); 53 54 #ifdef GRALLOC_LOCK_DEBUG 55 #define GRALLOC_LOCK(format, ...) \ 56 do { \ 57 HDF_LOGD("[%{public}s@%{public}s:%{public}d]" format "\n", __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \ 58 pthread_mutex_lock(&g_lock); \ 59 } while (0) 60 61 #define GRALLOC_UNLOCK(format, ...) \ 62 do { \ 63 HDF_LOGD("[%{public}s@%{public}s:%{public}d]" format "\n", __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \ 64 pthread_mutex_unlock(&g_lock); \ 65 } while (0) 66 #else 67 #define GRALLOC_LOCK(format, ...) \ 68 do { \ 69 pthread_mutex_lock(&g_lock); \ 70 } while (0) 71 72 #define GRALLOC_UNLOCK(format, ...) \ 73 do { \ 74 pthread_mutex_unlock(&g_lock); \ 75 } while (0) 76 #endif 77 78 #ifdef __cplusplus 79 } 80 #endif 81 82 #endif // DISPLAY_GRALLOC_GBM_H