1 #ifndef DALI_NATIVE_IMAGE_SOURCE_QUEUE_H
2 #define DALI_NATIVE_IMAGE_SOURCE_QUEUE_H
5 * Copyright (c) 2024 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/images/native-image-interface.h>
23 #include <dali/public-api/object/any.h>
27 #include <dali/public-api/dali-adaptor-common.h>
32 * @addtogroup dali_adaptor_framework
36 namespace Internal DALI_INTERNAL
40 class NativeImageSourceQueue;
42 } // namespace DALI_INTERNAL
44 class NativeImageSourceQueue;
47 * @brief Pointer to Dali::NativeImageSourceQueue.
49 typedef Dali::IntrusivePtr<Dali::NativeImageSourceQueue> NativeImageSourceQueuePtr;
52 * @brief Used for displaying native images.
54 * NativeImage is a platform specific way of providing pixel data to the GPU for rendering,for example via an EGL image.
55 * NativeImageSourceQueue can be created internally or externally by native image source.
56 * It has a queue which handles some image buffers.
57 * Someone should fill the buffers and enqueue them, then DALi will show them.
59 class DALI_ADAPTOR_API NativeImageSourceQueue : public NativeImageInterface
63 * @brief Enumeration for the instance when creating a native image, the color depth has to be specified.
64 * @note This ColorFormat follows pixel byte order.
66 enum class ColorFormat
68 BGR888 = 0, /// 8 blue bits, 8 green bits, 8 red bits
69 BGRA8888 = 1, /// 8 blue bits, 8 green bits, 8 red bits, alpha 8 bits
70 BGRX8888 = 2, /// 8 blue bits, 8 green bits, 8 red bits, and 8 ignored bits
71 RGB888 = 3, /// 8 red bits, 8 green bits, 8 blue bits
72 RGBA8888 = 4, /// 8 red bits, 8 green bits, 8 blue bits, alpha 8 bits
73 RGBX8888 = 5, /// 8 red bits, 8 green bits, 8 blue bits, and 8 ignored bits
77 * @brief Creates a new NativeImageSourceQueue.
78 * Depending on hardware, the width and height may have to be a power of two.
79 * It will use 3, or defined by DALI_TBM_SURFACE_QUEUE_SIZE as default.
80 * @param[in] width The width of the image
81 * @param[in] height The height of the image
82 * @param[in] colorFormat The color format of the image
83 * @return A smart-pointer to a newly allocated image
85 static NativeImageSourceQueuePtr New(uint32_t width, uint32_t height, ColorFormat colorFormat);
88 * @brief Creates a new NativeImageSourceQueue with the queue size.
89 * Depending on hardware, the width and height may have to be a power of two.
90 * @note Since queueCount can increase the memory usage, we recommened queueCount value is less or equal than 3.
91 * @param[in] queueCount The number of queue of the image. If it is 0, will use default.
92 * @param[in] width The width of the image
93 * @param[in] height The height of the image
94 * @param[in] colorFormat The color format of the image
95 * @return A smart-pointer to a newly allocated image
97 static NativeImageSourceQueuePtr New(uint32_t queueCount, uint32_t width, uint32_t height, ColorFormat colorFormat);
100 * @brief Creates a new NativeImageSourceQueue from an existing native image source.
102 * @param[in] nativeImageSourceQueue NativeImageSourceQueue must be a any handle with native image source
103 * @return A smart-pointer to a newly allocated image
104 * @see NativeImageInterface
106 static NativeImageSourceQueuePtr New(Any nativeImageSourceQueue);
109 * @brief Retrieves the internal native image.
111 * @return Any object containing the internal native image source queue
113 Any GetNativeImageSourceQueue();
116 * @brief Sets the size of the image.
118 * @param[in] width The width of the image
119 * @param[in] height The height of the image
121 void SetSize(uint32_t width, uint32_t height);
124 * @brief Ignores a source image which is inserted to the queue.
126 * @note This can be called from worker threads.
128 void IgnoreSourceImage();
131 * @brief Checks if the buffer can be got from the queue.
133 * Check the available buffer using this API before call DequeueBuffer()
134 * @return True if the buffer can be got from the queue.
136 bool CanDequeueBuffer();
139 * @brief Dequeue buffer from the queue.
141 * Acquire buffer and information of the queue.
142 * it returns the information of the buffer.
143 * @param[out] width The width of buffer
144 * @param[out] height The height of buffer
145 * @param[out] stride The stride of buffer
146 * @return A pointer of buffer
148 uint8_t* DequeueBuffer(uint32_t& width, uint32_t& height, uint32_t& stride);
151 * @brief Enqueue buffer to the queue.
153 * Enqueue buffer to the queue
154 * this requests the release of the buffer internally.
155 * @param[in] buffer A pointer of buffer
156 * @return True if success
158 bool EnqueueBuffer(uint8_t* buffer);
161 * @brief Free all released buffers.
163 void FreeReleasedBuffers();
166 * @copydoc Dali::NativeImageInterface::GetTextureTarget()
168 int GetTextureTarget() const override;
171 * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
173 bool ApplyNativeFragmentShader(std::string& shader) override;
176 * @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
178 const char* GetCustomSamplerTypename() const override;
181 * @brief Get the number of queue count for this image.
183 * @return The number of queue count.
185 uint32_t GetQueueCount() const;
187 private: // native image
189 * @copydoc Dali::NativeImageInterface::CreateResource()
191 bool CreateResource() override;
194 * @copydoc Dali::NativeImageInterface::DestroyResource()
196 void DestroyResource() override;
199 * @copydoc Dali::NativeImageInterface::TargetTexture()
201 uint32_t TargetTexture() override;
204 * @copydoc Dali::NativeImageInterface::PrepareTexture()
206 void PrepareTexture() override;
209 * @copydoc Dali::NativeImageInterface::GetWidth()
211 uint32_t GetWidth() const override;
214 * @copydoc Dali::NativeImageInterface::GetHeight()
216 uint32_t GetHeight() const override;
219 * @copydoc Dali::NativeImageInterface::RequiresBlending()
221 bool RequiresBlending() const override;
224 * @copydoc Dali::NativeImageInterface::GetNativeImageHandle()
226 Any GetNativeImageHandle() const override;
229 * @copydoc Dali::NativeImageInterface::SourceChanged()
231 bool SourceChanged() const override;
234 * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
236 Rect<uint32_t> GetUpdatedArea() override;
239 * @copydoc Dali::NativeImageInterface::GetExtension()
241 NativeImageInterface::Extension* GetExtension() override;
246 * @brief Private constructor.
247 * @param[in] queueCount The number of queue of the image. If it is 0, will use default.
248 * @param[in] width The width of the image
249 * @param[in] height The height of the image
250 * @param[in] colorFormat The color format of the image
251 * @param[in] nativeImageSourceQueue contains either: native image source or is empty
253 DALI_INTERNAL NativeImageSourceQueue(uint32_t queueCount, uint32_t width, uint32_t height, ColorFormat colorFormat, Any nativeImageSourceQueue);
256 * @brief A reference counted object may only be deleted by calling Unreference().
258 * The implementation should destroy the NativeImage resources.
260 DALI_INTERNAL ~NativeImageSourceQueue() override;
263 * @brief Undefined copy constructor.
265 * This avoids accidental calls to a default copy constructor.
266 * @param[in] nativeImageSourceQueue A reference to the object to copy
268 DALI_INTERNAL NativeImageSourceQueue(const NativeImageSourceQueue& nativeImageSourceQueue);
271 * @brief Undefined assignment operator.
273 * This avoids accidental calls to a default assignment operator.
274 * @param[in] rhs A reference to the object to copy
276 DALI_INTERNAL NativeImageSourceQueue& operator=(const NativeImageSourceQueue& rhs);
281 std::unique_ptr<Internal::Adaptor::NativeImageSourceQueue> mImpl; ///< Implementation pointer
290 #endif // DALI_NATIVE_IMAGE_SOURCE_QUEUE_H