Add API for NativeImageQueue
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / native-image-source-queue.h
1 #ifndef DALI_NATIVE_IMAGE_SOURCE_QUEUE_H
2 #define DALI_NATIVE_IMAGE_SOURCE_QUEUE_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/images/native-image-interface.h>
23 #include <dali/public-api/object/any.h>
24 #include <memory>
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/dali-adaptor-common.h>
28
29 namespace Dali
30 {
31 /**
32  * @addtogroup dali_adaptor_framework
33  * @{
34  */
35
36 namespace Internal DALI_INTERNAL
37 {
38 namespace Adaptor
39 {
40 class NativeImageSourceQueue;
41 }
42 } // namespace DALI_INTERNAL
43
44 class NativeImageSourceQueue;
45
46 /**
47  * @brief Pointer to Dali::NativeImageSourceQueue.
48  */
49 typedef Dali::IntrusivePtr<Dali::NativeImageSourceQueue> NativeImageSourceQueuePtr;
50
51 /**
52  * @brief Used for displaying native images.
53  *
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.
58  */
59 class DALI_ADAPTOR_API NativeImageSourceQueue : public NativeImageInterface
60 {
61 public:
62   /**
63     * @brief Enumeration for the instance when creating a native image, the color depth has to be specified.
64     */
65   enum ColorDepth
66   {
67     COLOR_DEPTH_DEFAULT, ///< Uses the current screen default depth (recommended)
68     COLOR_DEPTH_24,      ///< 24 bits per pixel
69     COLOR_DEPTH_32       ///< 32 bits per pixel
70   };
71
72   /**
73    * @brief Creates a new NativeImageSourceQueue.
74    *        Depending on hardware, the width and height may have to be a power of two.
75    * @param[in] width The width of the image
76    * @param[in] height The height of the image
77    * @param[in] depth color depth of the image
78    * @return A smart-pointer to a newly allocated image
79    */
80   static NativeImageSourceQueuePtr New(uint32_t width, uint32_t height, ColorDepth depth);
81
82   /**
83    * @brief Creates a new NativeImageSourceQueue from an existing native image source.
84    *
85    * @param[in] nativeImageSourceQueue NativeImageSourceQueue must be a any handle with native image source
86    * @return A smart-pointer to a newly allocated image
87    * @see NativeImageInterface
88    */
89   static NativeImageSourceQueuePtr New(Any nativeImageSourceQueue);
90
91   /**
92    * @brief Retrieves the internal native image.
93    *
94    * @return Any object containing the internal native image source queue
95    */
96   Any GetNativeImageSourceQueue();
97
98   /**
99    * @brief Sets the size of the image.
100    *
101    * @param[in] width The width of the image
102    * @param[in] height The height of the image
103    */
104   void SetSize(uint32_t width, uint32_t height);
105
106   /**
107    * @brief Ignores a source image which is inserted to the queue.
108    *
109    * @note This can be called from worker threads.
110    */
111   void IgnoreSourceImage();
112
113   /**
114    * @brief Checks if the buffer can be got from the queue.
115    *
116    * Check the available buffer using this API before call DequeueBuffer()
117    * @return True if the buffer can be got from the queue.
118    */
119   bool CanDequeueBuffer();
120
121   /**
122    * @brief Dequeue buffer from the queue.
123    *
124    * Acquire buffer and information of the queue.
125    * it returns the information of the buffer.
126    * @param[out] width The width of buffer
127    * @param[out] height The height of buffer
128    * @param[out] stride The stride of buffer
129    * @return A pointer of buffer
130    */
131   uint8_t* DequeueBuffer(uint32_t& width, uint32_t& height, uint32_t& stride);
132
133   /**
134    * @brief Enqueue buffer to the queue.
135    *
136    * Enqueue buffer to the queue
137    * this requests the release of the buffer internally.
138    * @param[in] buffer A pointer of buffer
139    * @return True if success
140    */
141   bool EnqueueBuffer(uint8_t* buffer);
142
143   /**
144    * @copydoc Dali::NativeImageInterface::GetTextureTarget()
145    */
146   int GetTextureTarget() const override;
147
148   /**
149    * @copydoc Dali::NativeImageInterface::GetCustomFragmentPrefix()
150    */
151   const char* GetCustomFragmentPrefix() const override;
152
153   /**
154    * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
155    */
156   bool ApplyNativeFragmentShader(std::string& shader) override;
157
158   /**
159    * @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
160    */
161   const char* GetCustomSamplerTypename() const override;
162
163 private: // native image
164   /**
165    * @copydoc Dali::NativeImageInterface::CreateResource()
166    */
167   bool CreateResource() override;
168
169   /**
170    * @copydoc Dali::NativeImageInterface::DestroyResource()
171    */
172   void DestroyResource() override;
173
174   /**
175    * @copydoc Dali::NativeImageInterface::TargetTexture()
176    */
177   uint32_t TargetTexture() override;
178
179   /**
180    * @copydoc Dali::NativeImageInterface::PrepareTexture()
181    */
182   void PrepareTexture() override;
183
184   /**
185    * @copydoc Dali::NativeImageInterface::GetWidth()
186    */
187   uint32_t GetWidth() const override;
188
189   /**
190    * @copydoc Dali::NativeImageInterface::GetHeight()
191    */
192   uint32_t GetHeight() const override;
193
194   /**
195    * @copydoc Dali::NativeImageInterface::RequiresBlending()
196    */
197   bool RequiresBlending() const override;
198
199   /**
200    * @copydoc Dali::NativeImageInterface::GetNativeImageHandle()
201    */
202   Any GetNativeImageHandle() const override;
203
204   /**
205    * @copydoc Dali::NativeImageInterface::SourceChanged()
206    */
207   bool SourceChanged() const override;
208
209   /**
210    * @copydoc Dali::NativeImageInterface::GetExtension()
211    */
212   NativeImageInterface::Extension* GetExtension() override;
213
214 private:
215   /// @cond internal
216   /**
217    * @brief Private constructor.
218    * @param[in] width The width of the image
219    * @param[in] height The height of the image
220    * @param[in] depth color depth of the image
221    * @param[in] nativeImageSourceQueue contains either: native image source or is empty
222    */
223   DALI_INTERNAL NativeImageSourceQueue(uint32_t width, uint32_t height, ColorDepth depth, Any nativeImageSourceQueue);
224
225   /**
226    * @brief A reference counted object may only be deleted by calling Unreference().
227    *
228    * The implementation should destroy the NativeImage resources.
229    */
230   DALI_INTERNAL ~NativeImageSourceQueue() override;
231
232   /**
233    * @brief Undefined copy constructor.
234    *
235    * This avoids accidental calls to a default copy constructor.
236    * @param[in] nativeImageSourceQueue A reference to the object to copy
237    */
238   DALI_INTERNAL NativeImageSourceQueue(const NativeImageSourceQueue& nativeImageSourceQueue);
239
240   /**
241    * @brief Undefined assignment operator.
242    *
243    * This avoids accidental calls to a default assignment operator.
244    * @param[in] rhs A reference to the object to copy
245    */
246   DALI_INTERNAL NativeImageSourceQueue& operator=(const NativeImageSourceQueue& rhs);
247   /// @endcond
248
249 private:
250   /// @cond internal
251   std::unique_ptr<Internal::Adaptor::NativeImageSourceQueue> mImpl; ///< Implementation pointer
252   /// @endcond
253 };
254
255 /**
256  * @}
257  */
258 } // namespace Dali
259
260 #endif // DALI_NATIVE_IMAGE_SOURCE_QUEUE_H