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