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