1 /* 2 * Copyright (c) 2021-2022 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 * @param handle Indicates the double pointer to the buffer of the memory to allocate. 55 * 56 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 57 * otherwise. 58 * @since 1.0 59 * @version 1.0 60 */ 61 int32_t (*AllocMem)(const AllocInfo* info, BufferHandle** handle); 62 63 /** 64 * @brief Releases memory. 65 * 66 * @param handle Indicates the pointer to the buffer of the memory to release. 67 * 68 * @since 1.0 69 * @version 1.0 70 */ 71 void (*FreeMem)(BufferHandle *handle); 72 73 /** 74 * @brief Maps memory to memory without cache in the process's address space. 75 * 76 * @param handle Indicates the pointer to the buffer of the memory to map. 77 * 78 * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise. 79 * @since 1.0 80 * @version 1.0 81 */ 82 void *(*Mmap)(BufferHandle *handle); 83 84 /** 85 * @brief Maps memory to memory with cache in the process's address space. 86 * 87 * @param handle Indicates the pointer to the buffer of the memory to map. 88 * 89 * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise. 90 * @since 1.0 91 * @version 1.0 92 */ 93 void *(*MmapCache)(BufferHandle *handle); 94 95 /** 96 * @brief Unmaps memory, that is, removes any mappings from the process's address space. 97 * 98 * @param handle Indicates the pointer to the buffer of the memory to unmap. 99 * 100 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 101 * otherwise. 102 * @since 1.0 103 * @version 1.0 104 */ 105 int32_t (*Unmap)(BufferHandle *handle); 106 107 /** 108 * @brief Flushes data from the cache to memory and invalidates the data in the cache. 109 * 110 * @param handle Indicates the pointer to the buffer of the cache to flush. 111 * 112 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 113 * otherwise. 114 * @since 1.0 115 * @version 1.0 116 */ 117 int32_t (*FlushCache)(BufferHandle *handle); 118 119 /** 120 * @brief Flushes data from the cache mapped via {@link Mmap} to memory and invalidates the data in the cache. 121 * 122 * @param handle Indicates the pointer to the buffer of the cache to flush. 123 * 124 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 125 * otherwise. 126 * @since 1.0 127 * @version 1.0 128 */ 129 int32_t (*FlushMCache)(BufferHandle *handle); 130 131 /** 132 * @brief Invalidates the cache to update it from memory. 133 * 134 * @param handle Indicates the pointer to the buffer of the cache, which will been invalidated. 135 * 136 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 137 * otherwise. 138 * @since 1.0 139 * @version 1.0 140 */ 141 int32_t (*InvalidateCache)(BufferHandle* handle); 142 143 /** 144 * @brief Checks whether the given VerifyAllocInfo array is allocatable. 145 * 146 * @param num Indicates the size of infos array. 147 * @param infos Indicates the pointer to the VerifyAllocInfo array. 148 * @param supporteds Indicates the pointer to the array that can be allocated. 149 * 150 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 151 * otherwise. 152 * @since 1.0 153 * @version 1.0 154 */ 155 int32_t (*IsSupportedAlloc)(uint32_t num, const VerifyAllocInfo *infos, bool *supporteds); 156 157 /** 158 * @brief Maps memory for YUV. 159 * 160 * @param handle Indicates the pointer to the buffer of the memory to map. 161 * @param info Indicates the pointer to the YUVDescInfo of the memory to map. 162 * 163 * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise. 164 * @since 3.2 165 * @version 1.0 166 */ 167 void *(*MmapYUV)(BufferHandle *handle, YUVDescInfo *info); 168 } GrallocFuncs; 169 170 /** 171 * @brief Initializes the memory module to obtain the pointer to functions for memory operations. 172 * 173 * @param funcs Indicates the double pointer to functions for memory operations. Memory is allocated automatically when 174 * you initiate the memory module initialization, so you can simply use the pointer to gain access to the functions. 175 * 176 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 177 * otherwise. 178 * @since 1.0 179 * @version 1.0 180 */ 181 int32_t GrallocInitialize(GrallocFuncs **funcs); 182 183 /** 184 * @brief Deinitializes the memory module to release the memory allocated to the pointer to functions for memory 185 * operations. 186 * 187 * @param funcs Indicates the pointer to functions for memory operations. 188 * 189 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 190 * otherwise. 191 * @since 1.0 192 * @version 1.0 193 */ 194 int32_t GrallocUninitialize(GrallocFuncs *funcs); 195 196 #ifdef __cplusplus 197 } 198 #endif 199 #endif 200 /** @} */ 201