Added UIThreadLoader to GLIB framework
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / tizen / native-image-source-queue-impl-tizen.h
1 #ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H
2 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H
3
4 /*
5  * Copyright (c) 2023 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/devel-api/threading/mutex.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <tbm_surface.h>
25 #include <tbm_surface_queue.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/internal/imaging/common/native-image-source-queue-impl.h>
29
30 namespace Dali
31 {
32 namespace Internal
33 {
34 namespace Adaptor
35 {
36 class EglGraphics;
37 class EglImageExtensions;
38
39 /**
40  * Dali internal NativeImageSource.
41  */
42 class NativeImageSourceQueueTizen : public Internal::Adaptor::NativeImageSourceQueue
43 {
44 public:
45   /**
46    * Create a new NativeImageSourceQueueTizen internally.
47    * Depending on hardware the width and height may have to be a power of two.
48    * @param[in] width The width of the image.
49    * @param[in] height The height of the image.
50    * @param[in] colorFormat The color format of the image.
51    * @param[in] nativeImageSourceQueue contains tbm_surface_queue_h or is empty
52    * @return A smart-pointer to a newly allocated image.
53    */
54   static NativeImageSourceQueueTizen* New(uint32_t width, uint32_t height, Dali::NativeImageSourceQueue::ColorFormat colorFormat, Any nativeImageSourceQueue);
55
56   /**
57    * @copydoc Dali::NativeImageSourceQueue::GetNativeImageSourceQueue()
58    */
59   Any GetNativeImageSourceQueue() const override;
60
61   /**
62    * @copydoc Dali::NativeImageSourceQueue::SetSize
63    */
64   void SetSize(uint32_t width, uint32_t height) override;
65
66   /**
67    * @copydoc Dali::NativeImageSourceQueue::IgnoreSourceImage
68    */
69   void IgnoreSourceImage() override;
70
71   /**
72    * @copydoc Dali::NativeImageSourceQueue::CanDequeueBuffer
73    */
74   bool CanDequeueBuffer() override;
75
76   /**
77    * @copydoc Dali::NativeImageSourceQueue::DequeueBuffer
78    */
79   uint8_t* DequeueBuffer(uint32_t& width, uint32_t& height, uint32_t& stride) override;
80
81   /**
82    * @copydoc Dali::NativeImageSourceQueue::EnqueueBuffer
83    */
84   bool EnqueueBuffer(uint8_t* buffer) override;
85
86   /**
87    * @copydoc Dali::NativeImageSourceQueue::EnqueueBuffer
88    */
89   void FreeReleasedBuffers() override;
90
91   /**
92    * destructor
93    */
94   ~NativeImageSourceQueueTizen() override;
95
96   /**
97    * @copydoc Dali::NativeImageInterface::CreateResource
98    */
99   bool CreateResource() override;
100
101   /**
102    * @copydoc Dali::NativeImageInterface::DestroyResource()
103    */
104   void DestroyResource() override;
105
106   /**
107    * @copydoc Dali::NativeImageInterface::TargetTexture()
108    */
109   uint32_t TargetTexture() override;
110
111   /**
112    * @copydoc Dali::NativeImageInterface::PrepareTexture()
113    */
114   void PrepareTexture() override;
115
116   /**
117    * @copydoc Dali::NativeImageInterface::GetWidth()
118    */
119   uint32_t GetWidth() const override
120   {
121     return mWidth;
122   }
123
124   /**
125    * @copydoc Dali::NativeImageInterface::GetHeight()
126    */
127   uint32_t GetHeight() const override
128   {
129     return mHeight;
130   }
131
132   /**
133    * @copydoc Dali::NativeImageInterface::RequiresBlending()
134    */
135   bool RequiresBlending() const override
136   {
137     return mBlendingRequired;
138   }
139
140   /**
141    * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
142    */
143   bool ApplyNativeFragmentShader(std::string& shader) override;
144
145   /**
146    * @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
147    */
148   const char* GetCustomSamplerTypename() const override;
149
150   /**
151    * @copydoc Dali::NativeImageInterface::GetTextureTarget()
152    */
153   int GetTextureTarget() const override;
154
155   /**
156    * @copydoc Dali::NativeImageInterface::GetNativeImageHandle()
157    */
158   Any GetNativeImageHandle() const override;
159
160   /**
161    * @copydoc Dali::NativeImageInterface::SourceChanged()
162    */
163   bool SourceChanged() const override;
164
165   /**
166    * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
167    */
168   Rect<uint32_t> GetUpdatedArea() override
169   {
170     return Rect<uint32_t>{0, 0, mWidth, mHeight};
171   }
172
173   /**
174    * @copydoc Dali::NativeImageInterface::GetExtension()
175    */
176   NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
177   {
178     return nullptr;
179   }
180
181 private:
182   /**
183    * Private constructor; @see NativeImageSourceQueue::New()
184    * @param[in] width The width of the image.
185    * @param[in] height The height of the image.
186    * @param[in] colorFormat The format of the image.
187    * @param[in] nativeImageSourceQueue contains tbm_surface_queue_h or is empty
188    */
189   NativeImageSourceQueueTizen(uint32_t width, uint32_t height, Dali::NativeImageSourceQueue::ColorFormat colorFormat, Any nativeImageSourceQueue);
190
191   void Initialize(Dali::NativeImageSourceQueue::ColorFormat colorFormat);
192
193   void ResetEglImageList(bool releaseConsumeSurface);
194
195   tbm_surface_queue_h GetSurfaceFromAny(Any source) const;
196
197   bool CheckBlending(int format);
198
199 private:
200   typedef std::pair<tbm_surface_h, void*> EglImagePair;
201   typedef std::pair<tbm_surface_h, void*> BufferPair;
202
203   Dali::Mutex               mMutex;              ///< Mutex
204   uint32_t                  mWidth;              ///< image width
205   uint32_t                  mHeight;             ///< image height
206   tbm_surface_queue_h       mTbmQueue;           ///< Tbm surface queue handle
207   tbm_surface_h             mConsumeSurface;     ///< The current tbm surface
208   std::vector<EglImagePair> mEglImages;          ///< EGL Image vector
209   std::vector<BufferPair>   mBuffers;            ///< Buffer vector
210   EglGraphics*              mEglGraphics;        ///< EGL Graphics
211   EglImageExtensions*       mEglImageExtensions; ///< The EGL Image Extensions
212   bool                      mOwnTbmQueue;        ///< Whether we created tbm queue
213   bool                      mBlendingRequired;   ///< Whether blending is required
214   bool                      mIsResized;          ///< Whether the size has changed
215   bool                      mFreeRequest;        ///< Whether it is requested to free the released buffers
216 };
217
218 } // namespace Adaptor
219
220 } // namespace Internal
221
222 } // namespace Dali
223
224 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H