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 HDI_IDISPLAY_GRALLOC_V1_0_H 17 #define HDI_IDISPLAY_GRALLOC_V1_0_H 18 19 #include <vector> 20 #include "display_type.h" 21 #include "buffer_handle.h" 22 23 namespace OHOS { 24 namespace HDI { 25 namespace Display { 26 namespace V1_0 { 27 using AllocatorDeathCallback = void (*)(void *); 28 class IDisplayGralloc { 29 public: 30 virtual ~IDisplayGralloc() = default; 31 virtual int32_t RegAllocatorDeathCallback(AllocatorDeathCallback func, void* data) = 0; 32 /** 33 * @brief Obtains all interfaces of IDisplayGralloc. 34 * 35 * @return Returns <b>IDisplayGralloc*</b> if the operation is successful; returns an null point otherwise. 36 * @since 1.0 37 * @version 1.0 38 */ 39 static IDisplayGralloc* Get(); 40 /** 41 * @brief Allocates memory based on the parameters passed by the GUI. 42 * 43 * @param info Indicates the description of the memory to allocate. 44 * 45 * @param handle Indicates the pointer to the buffer of the memory to allocate. 46 * 47 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 48 * otherwise. 49 * @since 1.0 50 * @version 1.0 51 */ 52 virtual int32_t AllocMem(const AllocInfo &info, BufferHandle *&handle) const = 0; 53 54 /** 55 * @brief Releases memory. 56 * 57 * @param handle Indicates the reference to the buffer of the memory to release. 58 * 59 * @since 1.0 60 * @version 1.0 61 */ 62 virtual void FreeMem(const BufferHandle &handle) const = 0; 63 64 /** 65 * @brief Maps memory to memory without cache in the process's address space. 66 * 67 * @param handle Indicates the reference to the buffer of the memory to map. 68 * 69 * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise. 70 * @since 1.0 71 * @version 1.0 72 */ 73 virtual void *Mmap(const BufferHandle &handle) const = 0; 74 75 /** 76 * @brief Maps memory to memory with cache in the process's address space. 77 * 78 * @param handle Indicates the reference to the buffer of the memory to map. 79 * 80 * @return Returns the pointer to a valid address if the operation is successful; returns <b>NULL</b> otherwise. 81 * @since 1.0 82 * @version 1.0 83 */ 84 virtual void *MmapCache(const BufferHandle &buffer) const = 0; 85 86 /** 87 * @brief Unmaps memory, that is, removes mappings from the process's address space. 88 * 89 * @param handle Indicates the reference to the buffer of the memory to unmap. 90 * 91 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 92 * otherwise. 93 * @since 1.0 94 * @version 1.0 95 */ 96 virtual int32_t Unmap(const BufferHandle &handle) const = 0; 97 98 /** 99 * @brief Flushes data from the cache to memory and invalidates the data in the cache. 100 * 101 * @param handle Indicates the reference to the buffer of the cache to flush. 102 * 103 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 104 * otherwise. 105 * @since 1.0 106 * @version 1.0 107 */ 108 virtual int32_t FlushCache(const BufferHandle &handle) const = 0; 109 110 /** 111 * @brief Flushes data from the cache mapped via {@link Mmap} to memory and invalidates the data in the cache. 112 * 113 * @param handle Indicates the reference to the buffer of the cache to flush. 114 * 115 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 116 * otherwise. 117 * @since 1.0 118 * @version 1.0 119 */ 120 virtual int32_t FlushMCache(const BufferHandle &buffer) const = 0; 121 122 /** 123 * @brief Invalidates the cache to update it from memory. 124 * 125 * @param handle Indicates the reference to the buffer of the cache, which will be invalidated. 126 * 127 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 128 * otherwise. 129 * @since 1.0 130 * @version 1.0 131 */ 132 virtual int32_t InvalidateCache(const BufferHandle &handle) const = 0; 133 134 /** 135 * @brief Checks whether the given VerifyAllocInfo array is allocatable. 136 * 137 * @param infos Indicates the VerifyAllocInfo array. 138 * @param supporteds Indicates whether the array is allocatable. 139 * 140 * @return Returns <b>0</b> if the operation is successful; returns an error code defined in {@link DispErrCode} 141 * otherwise. 142 * @since 1.0 143 * @version 1.0 144 */ 145 virtual int32_t IsSupportedAlloc(const std::vector<VerifyAllocInfo> &infos, 146 std::vector<bool> &supporteds) const = 0; 147 }; 148 } // namespace V1_0 149 } // namespace Display 150 } // namespace HDI 151 } // namespace OHOS 152 153 #endif // HDI_IDISPLAY_GRALLOC_V1_0_H 154