1 #ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H
2 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_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/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>
30 #include <dali/internal/imaging/common/native-image-source-queue-impl.h>
39 class EglImageExtensions;
42 * Dali internal NativeImageSource.
44 class NativeImageSourceQueueTizen : public Internal::Adaptor::NativeImageSourceQueue
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.
57 static NativeImageSourceQueueTizen* New(uint32_t queueCount, uint32_t width, uint32_t height, Dali::NativeImageSourceQueue::ColorFormat colorFormat, Any nativeImageSourceQueue);
60 * @copydoc Dali::NativeImageSourceQueue::GetNativeImageSourceQueue()
62 Any GetNativeImageSourceQueue() const override;
65 * @copydoc Dali::NativeImageSourceQueue::SetSize
67 void SetSize(uint32_t width, uint32_t height) override;
70 * @copydoc Dali::NativeImageSourceQueue::IgnoreSourceImage
72 void IgnoreSourceImage() override;
75 * @copydoc Dali::NativeImageSourceQueue::CanDequeueBuffer
77 bool CanDequeueBuffer() override;
80 * @copydoc Dali::NativeImageSourceQueue::DequeueBuffer
82 uint8_t* DequeueBuffer(uint32_t& width, uint32_t& height, uint32_t& stride) override;
85 * @copydoc Dali::NativeImageSourceQueue::EnqueueBuffer
87 bool EnqueueBuffer(uint8_t* buffer) override;
90 * @copydoc Dali::NativeImageSourceQueue::EnqueueBuffer
92 void FreeReleasedBuffers() override;
97 ~NativeImageSourceQueueTizen() override;
100 * @copydoc Dali::NativeImageInterface::CreateResource
102 bool CreateResource() override;
105 * @copydoc Dali::NativeImageInterface::DestroyResource()
107 void DestroyResource() override;
110 * @copydoc Dali::NativeImageInterface::TargetTexture()
112 uint32_t TargetTexture() override;
115 * @copydoc Dali::NativeImageInterface::PrepareTexture()
117 void PrepareTexture() override;
120 * @copydoc Dali::NativeImageSourceQueue::GetQueueCount()
122 uint32_t GetQueueCount() const override
128 * @copydoc Dali::NativeImageInterface::GetWidth()
130 uint32_t GetWidth() const override
136 * @copydoc Dali::NativeImageInterface::GetHeight()
138 uint32_t GetHeight() const override
144 * @copydoc Dali::NativeImageInterface::RequiresBlending()
146 bool RequiresBlending() const override
148 return mBlendingRequired;
152 * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
154 bool ApplyNativeFragmentShader(std::string& shader) override;
157 * @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
159 const char* GetCustomSamplerTypename() const override;
162 * @copydoc Dali::NativeImageInterface::GetTextureTarget()
164 int GetTextureTarget() const override;
167 * @copydoc Dali::NativeImageInterface::GetNativeImageHandle()
169 Any GetNativeImageHandle() const override;
172 * @copydoc Dali::NativeImageInterface::SourceChanged()
174 bool SourceChanged() const override;
177 * @copydoc Dali::NativeImageInterface::GetUpdatedArea()
179 Rect<uint32_t> GetUpdatedArea() override
181 return Rect<uint32_t>{0, 0, mWidth, mHeight};
185 * @copydoc Dali::NativeImageInterface::GetExtension()
187 NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
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
201 NativeImageSourceQueueTizen(uint32_t queueCount, uint32_t width, uint32_t height, Dali::NativeImageSourceQueue::ColorFormat colorFormat, Any nativeImageSourceQueue);
203 void Initialize(Dali::NativeImageSourceQueue::ColorFormat colorFormat);
205 void ResetEglImageList(bool releaseConsumeSurface);
207 tbm_surface_queue_h GetSurfaceFromAny(Any source) const;
209 bool CheckBlending(int format);
212 using SurfaceEglContainer = std::unordered_map<tbm_surface_h, void*>;
213 using BufferSurfaceContainer = std::unordered_map<uint8_t*, tbm_surface_h>;
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
231 } // namespace Adaptor
233 } // namespace Internal
237 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H