1 /* 2 * Copyright (c) 2020-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 #ifndef GRAPHIC_LITE_BUFFER_PRODUCER_H 17 #define GRAPHIC_LITE_BUFFER_PRODUCER_H 18 19 #include "buffer_queue.h" 20 #include "surface_buffer.h" 21 22 #include <string> 23 24 namespace OHOS { 25 extern "C" { 26 typedef enum { 27 REQUEST_BUFFER = 0, 28 FLUSH_BUFFER, 29 CANCEL_BUFFER, 30 SET_QUEUE_SIZE, 31 GET_QUEUE_SIZE, 32 SET_WIDTH_AND_HEIGHT, 33 GET_WIDTH, 34 GET_HEIGHT, 35 SET_FORMAT, 36 GET_FORMAT, 37 SET_STRIDE_ALIGNMENT, 38 GET_STRIDE_ALIGNMENT, 39 GET_STRIDE, 40 SET_SIZE, 41 GET_SIZE, 42 SET_USAGE, 43 GET_USAGE, 44 SET_USER_DATA, 45 GET_USER_DATA, 46 MAX_REQUEST_CODE, 47 } SURFACE_REQUEST_CODE; 48 } // end extern 49 50 /** 51 * @brief Surface producer abstract class. Provide request, flush, cancel and set buffer attr ability. 52 * In multi process, the producer is BufferClientProducer; In single process, it is BufferQueueProducer. 53 * Using in multi media and graphic for multi process. 54 */ 55 class BufferProducer { 56 public: 57 /** 58 * @brief Surface Buffer Producer Destructor. 59 */ ~BufferProducer()60 virtual ~BufferProducer() {} 61 62 /** 63 * @brief Request buffer. Surface producer requests buffer. 64 * Waiting until some buffer could used. 65 * @param [in] whether waiting or not. 66 * wait = 1. waiting util get surface buffer. 67 * wait = 0. No wait to get surface buffer. 68 * @returns buffer pointer. 69 */ 70 virtual SurfaceBufferImpl* RequestBuffer(uint8_t wait) = 0; 71 72 /** 73 * @brief Flush buffer for consumer acquire. When producer flush buffer, to 74 * push to dirty list, and call back to consumer that buffer is available to acquire. 75 * @param [in] SurfaceBufferImpl pointer, Which buffer could acquire for consumer. 76 * @returns Flush buffer succeed or not. 77 * 0 is succeed; other is failed. 78 */ 79 virtual int32_t FlushBuffer(SurfaceBufferImpl* buffer) = 0; 80 81 /** 82 * @brief Cancel buffer. Producer cancel this buffer, buffer will push to free list for request it. 83 * @param [in] SurfaceBufferImpl pointer, Which buffer will push back to free list for request it. 84 */ 85 virtual void Cancel(SurfaceBufferImpl* buffer) = 0; 86 87 /** 88 * @brief Set queue size, the surface could alloc max buffer count. 89 * Default is 1. Max count is 10. 90 * @param [in] queueSize. Could allocate buffer count. 91 */ 92 virtual void SetQueueSize(uint8_t queueSize) = 0; 93 94 /** 95 * @brief Get queue size, the surface could alloc max buffer count. 96 * @returns queue size. 97 */ 98 virtual uint8_t GetQueueSize() = 0; 99 100 /** 101 * @brief Set width and height to calculate the buffer size. 102 * @param [in] width, Buffer width. 103 * @param [in] height, Buffer height. 104 */ 105 virtual void SetWidthAndHeight(uint32_t width, uint32_t height) = 0; 106 107 /** 108 * @brief Get width, buffer width to calculate the buffer size.. 109 * @returns width, Buffer width. 110 */ 111 virtual uint32_t GetWidth() = 0; 112 113 /** 114 * @brief Get height, buffer height to calculate the buffer size.. 115 * @returns height, Buffer height. 116 */ 117 virtual uint32_t GetHeight() = 0; 118 119 /** 120 * @brief Set format, to calculate the buffer size. 121 * Default is IMAGE_PIXEL_FORMAT_RGB565. See all formats in OHOS::ImageFormat 122 * @param [in] format, Buffer format. 123 */ 124 virtual void SetFormat(uint32_t format) = 0; 125 126 /** 127 * @brief Get format, buffer format to calculate the buffer size.. 128 * @returns format, Buffer format. 129 */ 130 virtual uint32_t GetFormat() = 0; 131 132 /** 133 * @brief Set stride alignment bytes. Default alignment is 4 bytes. 134 * @param [in] strideAlignment, Buffer stride alignment 135 */ 136 virtual void SetStrideAlignment(uint32_t strideAlignment) = 0; 137 138 /** 139 * @brief Get stride alignment bytes. Default alignment is 4 bytes. 140 * @returns strideAlignment, Buffer stride alignment. 141 */ 142 virtual uint32_t GetStrideAlignment() = 0; 143 144 /** 145 * @brief Get bytes of one stride which calculate by width, format and stride alignment. 146 * @returns The stride 147 */ 148 virtual uint32_t GetStride() = 0; 149 150 /** 151 * @brief Set buffer size. Surface alloc buffer size, no need to calculate by width, height, format... 152 * @param [in] The buffer size 153 */ 154 virtual void SetSize(uint32_t size) = 0; 155 156 /** 157 * @brief Get buffer size. Surface alloc buffer size. 158 * The size is setted by SetSize() or calculated by width, height, format... 159 * @returns The buffer size. 160 */ 161 virtual uint32_t GetSize() = 0; 162 163 /** 164 * @brief Set buffer usage. Surface alloc physical or virtual memory buffer. 165 * Support usage see detail in OHOS::BUFFER_CONSUMER_USAGE. 166 * Default is BUFFER_CONSUMER_USAGE_SORTWARE, which will alloc virtual memory buffer. 167 * @param [in] The buffer usage. 168 */ 169 virtual void SetUsage(uint32_t usage) = 0; 170 171 /** 172 * @brief Get buffer usage. Surface alloc physical or virtual memory buffer. 173 * All usage sees detail in OHOS::BUFFER_CONSUMER_USAGE. 174 * @returns The buffer usage. 175 */ 176 virtual uint32_t GetUsage() = 0; 177 178 /** 179 * @brief Set user data. Construct a local map to store all the user-data. 180 * @param [in] key. 181 * @param [in] value. 182 */ 183 virtual void SetUserData(const std::string& key, const std::string& value) = 0; 184 185 /** 186 * @brief Get user data. Get the value from local map. 187 * @returns value refers to the key. 188 */ 189 virtual std::string GetUserData(const std::string& key) = 0; 190 }; 191 } // namespace OHOS 192 #endif 193