14ed2deddSopenharmony_ci/* 24ed2deddSopenharmony_ci * Copyright (c) 2020-2022 Huawei Device Co., Ltd. 34ed2deddSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44ed2deddSopenharmony_ci * you may not use this file except in compliance with the License. 54ed2deddSopenharmony_ci * You may obtain a copy of the License at 64ed2deddSopenharmony_ci * 74ed2deddSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84ed2deddSopenharmony_ci * 94ed2deddSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104ed2deddSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114ed2deddSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124ed2deddSopenharmony_ci * See the License for the specific language governing permissions and 134ed2deddSopenharmony_ci * limitations under the License. 144ed2deddSopenharmony_ci */ 154ed2deddSopenharmony_ci 164ed2deddSopenharmony_ci#ifndef GRAPHIC_LITE_BUFFER_PRODUCER_H 174ed2deddSopenharmony_ci#define GRAPHIC_LITE_BUFFER_PRODUCER_H 184ed2deddSopenharmony_ci 194ed2deddSopenharmony_ci#include "buffer_queue.h" 204ed2deddSopenharmony_ci#include "surface_buffer.h" 214ed2deddSopenharmony_ci 224ed2deddSopenharmony_ci#include <string> 234ed2deddSopenharmony_ci 244ed2deddSopenharmony_cinamespace OHOS { 254ed2deddSopenharmony_ciextern "C" { 264ed2deddSopenharmony_citypedef enum { 274ed2deddSopenharmony_ci REQUEST_BUFFER = 0, 284ed2deddSopenharmony_ci FLUSH_BUFFER, 294ed2deddSopenharmony_ci CANCEL_BUFFER, 304ed2deddSopenharmony_ci SET_QUEUE_SIZE, 314ed2deddSopenharmony_ci GET_QUEUE_SIZE, 324ed2deddSopenharmony_ci SET_WIDTH_AND_HEIGHT, 334ed2deddSopenharmony_ci GET_WIDTH, 344ed2deddSopenharmony_ci GET_HEIGHT, 354ed2deddSopenharmony_ci SET_FORMAT, 364ed2deddSopenharmony_ci GET_FORMAT, 374ed2deddSopenharmony_ci SET_STRIDE_ALIGNMENT, 384ed2deddSopenharmony_ci GET_STRIDE_ALIGNMENT, 394ed2deddSopenharmony_ci GET_STRIDE, 404ed2deddSopenharmony_ci SET_SIZE, 414ed2deddSopenharmony_ci GET_SIZE, 424ed2deddSopenharmony_ci SET_USAGE, 434ed2deddSopenharmony_ci GET_USAGE, 444ed2deddSopenharmony_ci SET_USER_DATA, 454ed2deddSopenharmony_ci GET_USER_DATA, 464ed2deddSopenharmony_ci MAX_REQUEST_CODE, 474ed2deddSopenharmony_ci} SURFACE_REQUEST_CODE; 484ed2deddSopenharmony_ci} // end extern 494ed2deddSopenharmony_ci 504ed2deddSopenharmony_ci/** 514ed2deddSopenharmony_ci * @brief Surface producer abstract class. Provide request, flush, cancel and set buffer attr ability. 524ed2deddSopenharmony_ci * In multi process, the producer is BufferClientProducer; In single process, it is BufferQueueProducer. 534ed2deddSopenharmony_ci * Using in multi media and graphic for multi process. 544ed2deddSopenharmony_ci */ 554ed2deddSopenharmony_ciclass BufferProducer { 564ed2deddSopenharmony_cipublic: 574ed2deddSopenharmony_ci /** 584ed2deddSopenharmony_ci * @brief Surface Buffer Producer Destructor. 594ed2deddSopenharmony_ci */ 604ed2deddSopenharmony_ci virtual ~BufferProducer() {} 614ed2deddSopenharmony_ci 624ed2deddSopenharmony_ci /** 634ed2deddSopenharmony_ci * @brief Request buffer. Surface producer requests buffer. 644ed2deddSopenharmony_ci * Waiting until some buffer could used. 654ed2deddSopenharmony_ci * @param [in] whether waiting or not. 664ed2deddSopenharmony_ci * wait = 1. waiting util get surface buffer. 674ed2deddSopenharmony_ci * wait = 0. No wait to get surface buffer. 684ed2deddSopenharmony_ci * @returns buffer pointer. 694ed2deddSopenharmony_ci */ 704ed2deddSopenharmony_ci virtual SurfaceBufferImpl* RequestBuffer(uint8_t wait) = 0; 714ed2deddSopenharmony_ci 724ed2deddSopenharmony_ci /** 734ed2deddSopenharmony_ci * @brief Flush buffer for consumer acquire. When producer flush buffer, to 744ed2deddSopenharmony_ci * push to dirty list, and call back to consumer that buffer is available to acquire. 754ed2deddSopenharmony_ci * @param [in] SurfaceBufferImpl pointer, Which buffer could acquire for consumer. 764ed2deddSopenharmony_ci * @returns Flush buffer succeed or not. 774ed2deddSopenharmony_ci * 0 is succeed; other is failed. 784ed2deddSopenharmony_ci */ 794ed2deddSopenharmony_ci virtual int32_t FlushBuffer(SurfaceBufferImpl* buffer) = 0; 804ed2deddSopenharmony_ci 814ed2deddSopenharmony_ci /** 824ed2deddSopenharmony_ci * @brief Cancel buffer. Producer cancel this buffer, buffer will push to free list for request it. 834ed2deddSopenharmony_ci * @param [in] SurfaceBufferImpl pointer, Which buffer will push back to free list for request it. 844ed2deddSopenharmony_ci */ 854ed2deddSopenharmony_ci virtual void Cancel(SurfaceBufferImpl* buffer) = 0; 864ed2deddSopenharmony_ci 874ed2deddSopenharmony_ci /** 884ed2deddSopenharmony_ci * @brief Set queue size, the surface could alloc max buffer count. 894ed2deddSopenharmony_ci * Default is 1. Max count is 10. 904ed2deddSopenharmony_ci * @param [in] queueSize. Could allocate buffer count. 914ed2deddSopenharmony_ci */ 924ed2deddSopenharmony_ci virtual void SetQueueSize(uint8_t queueSize) = 0; 934ed2deddSopenharmony_ci 944ed2deddSopenharmony_ci /** 954ed2deddSopenharmony_ci * @brief Get queue size, the surface could alloc max buffer count. 964ed2deddSopenharmony_ci * @returns queue size. 974ed2deddSopenharmony_ci */ 984ed2deddSopenharmony_ci virtual uint8_t GetQueueSize() = 0; 994ed2deddSopenharmony_ci 1004ed2deddSopenharmony_ci /** 1014ed2deddSopenharmony_ci * @brief Set width and height to calculate the buffer size. 1024ed2deddSopenharmony_ci * @param [in] width, Buffer width. 1034ed2deddSopenharmony_ci * @param [in] height, Buffer height. 1044ed2deddSopenharmony_ci */ 1054ed2deddSopenharmony_ci virtual void SetWidthAndHeight(uint32_t width, uint32_t height) = 0; 1064ed2deddSopenharmony_ci 1074ed2deddSopenharmony_ci /** 1084ed2deddSopenharmony_ci * @brief Get width, buffer width to calculate the buffer size.. 1094ed2deddSopenharmony_ci * @returns width, Buffer width. 1104ed2deddSopenharmony_ci */ 1114ed2deddSopenharmony_ci virtual uint32_t GetWidth() = 0; 1124ed2deddSopenharmony_ci 1134ed2deddSopenharmony_ci /** 1144ed2deddSopenharmony_ci * @brief Get height, buffer height to calculate the buffer size.. 1154ed2deddSopenharmony_ci * @returns height, Buffer height. 1164ed2deddSopenharmony_ci */ 1174ed2deddSopenharmony_ci virtual uint32_t GetHeight() = 0; 1184ed2deddSopenharmony_ci 1194ed2deddSopenharmony_ci /** 1204ed2deddSopenharmony_ci * @brief Set format, to calculate the buffer size. 1214ed2deddSopenharmony_ci * Default is IMAGE_PIXEL_FORMAT_RGB565. See all formats in OHOS::ImageFormat 1224ed2deddSopenharmony_ci * @param [in] format, Buffer format. 1234ed2deddSopenharmony_ci */ 1244ed2deddSopenharmony_ci virtual void SetFormat(uint32_t format) = 0; 1254ed2deddSopenharmony_ci 1264ed2deddSopenharmony_ci /** 1274ed2deddSopenharmony_ci * @brief Get format, buffer format to calculate the buffer size.. 1284ed2deddSopenharmony_ci * @returns format, Buffer format. 1294ed2deddSopenharmony_ci */ 1304ed2deddSopenharmony_ci virtual uint32_t GetFormat() = 0; 1314ed2deddSopenharmony_ci 1324ed2deddSopenharmony_ci /** 1334ed2deddSopenharmony_ci * @brief Set stride alignment bytes. Default alignment is 4 bytes. 1344ed2deddSopenharmony_ci * @param [in] strideAlignment, Buffer stride alignment 1354ed2deddSopenharmony_ci */ 1364ed2deddSopenharmony_ci virtual void SetStrideAlignment(uint32_t strideAlignment) = 0; 1374ed2deddSopenharmony_ci 1384ed2deddSopenharmony_ci /** 1394ed2deddSopenharmony_ci * @brief Get stride alignment bytes. Default alignment is 4 bytes. 1404ed2deddSopenharmony_ci * @returns strideAlignment, Buffer stride alignment. 1414ed2deddSopenharmony_ci */ 1424ed2deddSopenharmony_ci virtual uint32_t GetStrideAlignment() = 0; 1434ed2deddSopenharmony_ci 1444ed2deddSopenharmony_ci /** 1454ed2deddSopenharmony_ci * @brief Get bytes of one stride which calculate by width, format and stride alignment. 1464ed2deddSopenharmony_ci * @returns The stride 1474ed2deddSopenharmony_ci */ 1484ed2deddSopenharmony_ci virtual uint32_t GetStride() = 0; 1494ed2deddSopenharmony_ci 1504ed2deddSopenharmony_ci /** 1514ed2deddSopenharmony_ci * @brief Set buffer size. Surface alloc buffer size, no need to calculate by width, height, format... 1524ed2deddSopenharmony_ci * @param [in] The buffer size 1534ed2deddSopenharmony_ci */ 1544ed2deddSopenharmony_ci virtual void SetSize(uint32_t size) = 0; 1554ed2deddSopenharmony_ci 1564ed2deddSopenharmony_ci /** 1574ed2deddSopenharmony_ci * @brief Get buffer size. Surface alloc buffer size. 1584ed2deddSopenharmony_ci * The size is setted by SetSize() or calculated by width, height, format... 1594ed2deddSopenharmony_ci * @returns The buffer size. 1604ed2deddSopenharmony_ci */ 1614ed2deddSopenharmony_ci virtual uint32_t GetSize() = 0; 1624ed2deddSopenharmony_ci 1634ed2deddSopenharmony_ci /** 1644ed2deddSopenharmony_ci * @brief Set buffer usage. Surface alloc physical or virtual memory buffer. 1654ed2deddSopenharmony_ci * Support usage see detail in OHOS::BUFFER_CONSUMER_USAGE. 1664ed2deddSopenharmony_ci * Default is BUFFER_CONSUMER_USAGE_SORTWARE, which will alloc virtual memory buffer. 1674ed2deddSopenharmony_ci * @param [in] The buffer usage. 1684ed2deddSopenharmony_ci */ 1694ed2deddSopenharmony_ci virtual void SetUsage(uint32_t usage) = 0; 1704ed2deddSopenharmony_ci 1714ed2deddSopenharmony_ci /** 1724ed2deddSopenharmony_ci * @brief Get buffer usage. Surface alloc physical or virtual memory buffer. 1734ed2deddSopenharmony_ci * All usage sees detail in OHOS::BUFFER_CONSUMER_USAGE. 1744ed2deddSopenharmony_ci * @returns The buffer usage. 1754ed2deddSopenharmony_ci */ 1764ed2deddSopenharmony_ci virtual uint32_t GetUsage() = 0; 1774ed2deddSopenharmony_ci 1784ed2deddSopenharmony_ci /** 1794ed2deddSopenharmony_ci * @brief Set user data. Construct a local map to store all the user-data. 1804ed2deddSopenharmony_ci * @param [in] key. 1814ed2deddSopenharmony_ci * @param [in] value. 1824ed2deddSopenharmony_ci */ 1834ed2deddSopenharmony_ci virtual void SetUserData(const std::string& key, const std::string& value) = 0; 1844ed2deddSopenharmony_ci 1854ed2deddSopenharmony_ci /** 1864ed2deddSopenharmony_ci * @brief Get user data. Get the value from local map. 1874ed2deddSopenharmony_ci * @returns value refers to the key. 1884ed2deddSopenharmony_ci */ 1894ed2deddSopenharmony_ci virtual std::string GetUserData(const std::string& key) = 0; 1904ed2deddSopenharmony_ci}; 1914ed2deddSopenharmony_ci} // namespace OHOS 1924ed2deddSopenharmony_ci#endif 193