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 "display_type.h" 20 #include "buffer_handle.h" 21 22 namespace OHOS { 23 namespace HDI { 24 namespace Display { 25 namespace V1_0 { 26 class IDisplayGralloc { 27 public: 28 virtual ~IDisplayGralloc() = default; 29 30 /** 31 * @brief Get all interfaces of display gralloc. 32 * 33 * @return Returns <b>IDisplayGralloc* </b> if the operation is successful; returns an Null point otherwise. 34 * @since 1.0 35 * @version 1.0 36 */ 37 // static sptr<IDisplayGralloc> Get(); 38 static IDisplayGralloc* Get(); 39 40 /** 41 * @brief Allocates memory based on the parameters passed by the GUI. 42 * 43 * @param info Indicates the reference to the description info of the memory to allocate. 44 * 45 * @param handle Indicates the reference of 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 any mappings in 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 Invalidate the Cache, it will update the cache from memory. 124 * 125 * @param handle Indicates the reference to the buffer of the cache which will been 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 } // namespace V1_0 135 } // namespace Display 136 } // namespace HDI 137 } // namespace OHOS 138 139 #endif // HDI_IDISPLAY_GRALLOC_V1_0_H 140