1 /* 2 * Copyright (c) 2020-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 /** 17 * @addtogroup Display 18 * @{ 19 * 20 * @brief Defines driver functions of the display module. 21 * 22 * This module provides driver functions for the graphics subsystem, including graphics layer management, 23 * device control, graphics hardware acceleration, display memory management, and callbacks. 24 * @since 1.0 25 * @version 2.0 26 */ 27 28 29 /** 30 * @file display_gralloc.h 31 * 32 * @brief Declares the driver functions for memory. 33 * 34 * @since 1.0 35 * @version 2.0 36 */ 37 38 #ifndef DISPLAY_GRALLOC_H 39 #define DISPLAY_GRALLOC_H 40 #include "display_type.h" 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 /** 47 * @brief Defines pointers to the memory driver functions. 48 */ 49 typedef struct { 50 /** 51 * @brief Allocates memory based on the parameters passed by the GUI. 52 * 53 * @param info Indicates the pointer to the description info of the memory to allocate. 54 * 55 * @param handle Indicates the double pointer to the buffer of the memory to allocate. 56 * 57 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 58 * otherwise. 59 * @since 1.0 60 * @version 1.0 61 */ 62 int32_t (*AllocMem)(const AllocInfo* info, BufferHandle** handle); 63 64 /** 65 * @brief Releases memory. 66 * 67 * @param handle Indicates the pointer to the buffer of the memory to release. 68 * 69 * @since 1.0 70 * @version 1.0 71 */ 72 void (*FreeMem)(BufferHandle *handle); 73 74 /** 75 * @brief Maps memory to memory without cache in the process's address space. 76 * 77 * @param handle Indicates the pointer to the buffer of the memory to map. 78 * 79 * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise. 80 * @since 1.0 81 * @version 1.0 82 */ 83 void *(*Mmap)(BufferHandle *handle); 84 85 /** 86 * @brief Maps memory to memory with cache in the process's address space. 87 * 88 * @param handle Indicates the pointer to the buffer of the memory to map. 89 * 90 * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise. 91 * @since 1.0 92 * @version 1.0 93 */ 94 void *(*MmapCache)(BufferHandle *handle); 95 96 /** 97 * @brief Unmaps memory, that is, removes any mappings in the process's address space. 98 * 99 * @param handle Indicates the pointer to the buffer of the memory to unmap. 100 * 101 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 102 * otherwise. 103 * @since 1.0 104 * @version 1.0 105 */ 106 int32_t (*Unmap)(BufferHandle *handle); 107 108 /** 109 * @brief Flushes data from the cache to memory and invalidates the data in the cache. 110 * 111 * @param handle Indicates the pointer to the buffer of the cache to flush. 112 * 113 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 114 * otherwise. 115 * @since 1.0 116 * @version 1.0 117 */ 118 int32_t (*FlushCache)(BufferHandle *handle); 119 120 /** 121 * @brief Flushes data from the cache mapped via {@link Mmap} to memory and invalidates the data in the cache. 122 * 123 * @param handle Indicates the pointer to the buffer of the cache to flush. 124 * 125 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 126 * otherwise. 127 * @since 1.0 128 * @version 1.0 129 */ 130 int32_t (*FlushMCache)(BufferHandle *handle); 131 132 /** 133 * @brief Invalidate the Cache, it will update the cache from memory. 134 * 135 * @param handle Indicates the pointer to the buffer of the cache which will been invalidated 136 * 137 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 138 * otherwise. 139 * @since 1.0 140 * @version 1.0 141 */ 142 int32_t (*InvalidateCache)(BufferHandle* handle); 143 } GrallocFuncs; 144 145 /** 146 * @brief Initializes the memory module to obtain the pointer to functions for memory operations. 147 * 148 * @param funcs Indicates the double pointer to functions for memory operations. Memory is allocated automatically when 149 * you initiate the memory module initialization, so you can simply use the pointer to gain access to the functions. 150 * 151 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 152 * otherwise. 153 * @since 1.0 154 * @version 1.0 155 */ 156 int32_t GrallocInitialize(GrallocFuncs **funcs); 157 158 /** 159 * @brief Deinitializes the memory module to release the memory allocated to the pointer to functions for memory 160 * operations. 161 * 162 * @param funcs Indicates the pointer to functions for memory operations. 163 * 164 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 165 * otherwise. 166 * @since 1.0 167 * @version 1.0 168 */ 169 int32_t GrallocUninitialize(GrallocFuncs *funcs); 170 171 #ifdef __cplusplus 172 } 173 #endif 174 #endif 175 /** @} */ 176