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