Updates for NativeImageInterface
[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) 2018 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 }
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    /**
64     * @brief Enumeration for the instance when creating a native image, the color depth has to be specified.
65     */
66    enum ColorDepth
67    {
68      COLOR_DEPTH_DEFAULT,     ///< Uses the current screen default depth (recommended)
69      COLOR_DEPTH_24,          ///< 24 bits per pixel
70      COLOR_DEPTH_32           ///< 32 bits per pixel
71    };
72
73   /**
74    * @brief Creates a new NativeImageSourceQueue.
75    *        Depending on hardware, the width and height may have to be a power of two.
76    * @param[in] width The width of the image
77    * @param[in] height The height of the image
78    * @param[in] depth color depth of the image
79    * @return A smart-pointer to a newly allocated image
80    */
81   static NativeImageSourceQueuePtr New( uint32_t width, uint32_t height, ColorDepth depth );
82
83   /**
84    * @brief Creates a new NativeImageSourceQueue from an existing native image source.
85    *
86    * @param[in] nativeImageSourceQueue NativeImageSourceQueue must be a any handle with native image source
87    * @return A smart-pointer to a newly allocated image
88    * @see NativeImageInterface
89    */
90   static NativeImageSourceQueuePtr New( Any nativeImageSourceQueue );
91
92   /**
93    * @brief Retrieves the internal native image.
94    *
95    * @return Any object containing the internal native image source queue
96    */
97   Any GetNativeImageSourceQueue();
98
99   /**
100    * @brief Sets the size of the image.
101    *
102    * @param[in] width The width of the image
103    * @param[in] height The height of the image
104    */
105   void SetSize( uint32_t width, uint32_t height );
106
107   /**
108    * @brief Ignores a source image which is inserted to the queue.
109    *
110    * @note This can be called from worker threads.
111    */
112   void IgnoreSourceImage();
113
114   /**
115    * @copydoc Dali::NativeImageInterface::GetTextureTarget()
116    */
117   int GetTextureTarget() const override;
118
119   /**
120    * @copydoc Dali::NativeImageInterface::GetCustomFragmentPrefix()
121    */
122   const char* GetCustomFragmentPrefix() const override;
123
124   /**
125    * @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
126    */
127   const char* GetCustomSamplerTypename() const override;
128
129
130 private:   // native image
131
132   /**
133    * @copydoc Dali::NativeImageInterface::CreateResource()
134    */
135   bool CreateResource() override;
136
137   /**
138    * @copydoc Dali::NativeImageInterface::DestroyResource()
139    */
140   void DestroyResource() override;
141
142   /**
143    * @copydoc Dali::NativeImageInterface::TargetTexture()
144    */
145   uint32_t TargetTexture() override;
146
147   /**
148    * @copydoc Dali::NativeImageInterface::PrepareTexture()
149    */
150   void PrepareTexture() override;
151
152   /**
153    * @copydoc Dali::NativeImageInterface::GetWidth()
154    */
155   uint32_t GetWidth() const override;
156
157   /**
158    * @copydoc Dali::NativeImageInterface::GetHeight()
159    */
160   uint32_t GetHeight() const override;
161
162   /**
163    * @copydoc Dali::NativeImageInterface::RequiresBlending()
164    */
165   bool RequiresBlending() const override;
166
167   /**
168    * @copydoc Dali::NativeImageInterface::GetNativeImageHandle()
169    */
170   Any GetNativeImageHandle() const override;
171
172   /**
173    * @copydoc Dali::NativeImageInterface::SourceChanged()
174    */
175   bool SourceChanged() const override;
176
177   /**
178    * @copydoc Dali::NativeImageInterface::GetExtension()
179    */
180   NativeImageInterface::Extension* GetExtension();
181
182 private:
183
184   /// @cond internal
185   /**
186    * @brief Private constructor.
187    * @param[in] width The width of the image
188    * @param[in] height The height of the image
189    * @param[in] depth color depth of the image
190    * @param[in] nativeImageSourceQueue contains either: native image source or is empty
191    */
192   DALI_INTERNAL NativeImageSourceQueue( uint32_t width, uint32_t height, ColorDepth depth, Any nativeImageSourceQueue );
193
194   /**
195    * @brief A reference counted object may only be deleted by calling Unreference().
196    *
197    * The implementation should destroy the NativeImage resources.
198    */
199   DALI_INTERNAL virtual ~NativeImageSourceQueue();
200
201   /**
202    * @brief Undefined copy constructor.
203    *
204    * This avoids accidental calls to a default copy constructor.
205    * @param[in] nativeImageSourceQueue A reference to the object to copy
206    */
207   DALI_INTERNAL NativeImageSourceQueue( const NativeImageSourceQueue& nativeImageSourceQueue );
208
209   /**
210    * @brief Undefined assignment operator.
211    *
212    * This avoids accidental calls to a default assignment operator.
213    * @param[in] rhs A reference to the object to copy
214    */
215   DALI_INTERNAL NativeImageSourceQueue& operator=(const NativeImageSourceQueue& rhs);
216   /// @endcond
217
218 private:
219
220   /// @cond internal
221   std::unique_ptr< Internal::Adaptor::NativeImageSourceQueue > mImpl; ///< Implementation pointer
222   /// @endcond
223 };
224
225 /**
226  * @}
227  */
228 } // namespace Dali
229
230 #endif // DALI_NATIVE_IMAGE_SOURCE_QUEUE_H