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 Surface 18 * @{ 19 * 20 * @brief Provides shared memory for multimedia and graphics. 21 * 22 * This module is used to apply for and release shared memory and is used by the multimedia and graphics 23 * modules across processes. 24 * 25 * @since 1.0 26 * @version 1.0 27 */ 28 29 /** 30 * @file surface_buffer.h 31 * 32 * @brief Provides functions such as setting the virtual address, size, and additional attributes of shared memory. 33 * 34 * 35 * 36 * @since 1.0 37 * @version 1.0 38 */ 39 40 #ifndef GRAPHIC_LITE_SURFACE_BUFFER_H 41 #define GRAPHIC_LITE_SURFACE_BUFFER_H 42 43 #include <map> 44 45 namespace OHOS { 46 /** 47 * 48 * @brief Provides functions such as setting the virtual address, size, and additional attributes of shared memory. 49 * 50 * 51 * @since 1.0 52 * @version 1.0 53 */ 54 class SurfaceBuffer { 55 public: 56 /** 57 * @brief Obtains the virtual address of shared memory for producers and consumers. 58 * 59 * @return Returns the virtual address of shared memory. 60 * @since 1.0 61 * @version 1.0 62 */ 63 virtual void* GetVirAddr() const = 0; 64 65 /** 66 * @brief Obtains the physical address of shared memory. 67 * 68 * @return Returns the physical address of shared memory. 69 * @since 1.0 70 * @version 1.0 71 */ 72 virtual uint64_t GetPhyAddr() const = 0; 73 74 /** 75 * @brief Obtains the size of shared memory. 76 * 77 * @return Returns the size of shared memory. 78 * @since 1.0 79 * @version 1.0 80 */ 81 virtual uint32_t GetSize() const = 0; 82 83 /** 84 * @brief Sets the size of shared memory. 85 * 86 * @param size Indicates the size of shared memory to set. 87 * @since 1.0 88 * @version 1.0 89 */ 90 virtual void SetSize(uint32_t size) = 0; 91 92 /** 93 * @brief Sets an extra attribute value of the int32 type. 94 * 95 * Sets an extra attribute value of the int32 type, The extra attribute is stored in the format of <key, value>. 96 * Each key corresponds to a value. If the same keys are used in two calls, \n 97 * the value in the second call overwrites that in the first call. \n 98 * 99 * @param key Indicates the key of a key-value pair to set. 100 * @param value Indicates the value of the key-value pair to set. 101 * @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise. 102 * @since 1.0 103 * @version 1.0 104 */ 105 virtual int32_t SetInt32(uint32_t key, int32_t value) = 0; 106 107 /** 108 * @brief Obtains an extra attribute value of the int32 type. 109 * 110 * Obtains an extra attribute value of the int32 type, The extra attribute is stored in the format of <key, value>. 111 * Each key corresponds to a value. If the key does not exist or the value is not int32, <b>-1</b> is returned. 112 * 113 * @param key Indicates the key of a key-value pair for which the value is to be obtained. 114 * @param value Indicates the value of the key-value pair obtained. 115 * @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise. 116 * @since 1.0 117 * @version 1.0 118 */ 119 virtual int32_t GetInt32(uint32_t key, int32_t& value) = 0; 120 121 /** 122 * @brief Sets an extra attribute value of the int64 type. 123 * 124 * Sets an extra attribute value of the int64 type. The storage mode of the extra attribute is <key, value>. 125 * the value in the second call overwrites that in the first call. 126 * 127 * @param key Indicates the key of a key-value pair to set. 128 * @param value Indicates the value of the key-value pair to set. 129 * @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise. 130 * @since 1.0 131 * @version 1.0 132 */ 133 virtual int32_t SetInt64(uint32_t key, int64_t value) = 0; 134 135 /** 136 * @brief Obtains an extra attribute value of the int64 type. 137 * 138 * Obtains an extra attribute value of the int64 type, The extra attribute is stored in the format of <key, value>. 139 * Each key corresponds to a value. If the key does not exist or the value is not int64, <b>-1</b> is returned. 140 * 141 * @param key Indicates the key of a key-value pair for which the value is to be obtained. 142 * @param value Indicates the value of the key-value pair obtained. 143 * @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise. 144 * @since 1.0 145 * @version 1.0 146 */ 147 virtual int32_t GetInt64(uint32_t key, int64_t& value) = 0; 148 149 protected: SurfaceBuffer()150 SurfaceBuffer() {} ~SurfaceBuffer()151 virtual ~SurfaceBuffer() {} 152 }; 153 } // end namespace 154 #endif 155