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) 2021 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/threading/mutex.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <tbm_surface.h>
25 #include <tbm_surface_queue.h>
28 #include <dali/internal/imaging/common/native-image-source-queue-impl.h>
37 class EglImageExtensions;
40 * Dali internal NativeImageSource.
42 class NativeImageSourceQueueTizen : public Internal::Adaptor::NativeImageSourceQueue
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.
54 static NativeImageSourceQueueTizen* New(uint32_t width, uint32_t height, Dali::NativeImageSourceQueue::ColorFormat colorFormat, Any nativeImageSourceQueue);
57 * @copydoc Dali::NativeImageSourceQueue::GetNativeImageSourceQueue()
59 Any GetNativeImageSourceQueue() const override;
62 * @copydoc Dali::NativeImageSourceQueue::SetSize
64 void SetSize(uint32_t width, uint32_t height) override;
67 * @copydoc Dali::NativeImageSourceQueue::IgnoreSourceImage
69 void IgnoreSourceImage() override;
72 * @copydoc Dali::NativeImageSourceQueue::CanDequeueBuffer
74 bool CanDequeueBuffer() override;
77 * @copydoc Dali::NativeImageSourceQueue::DequeueBuffer
79 uint8_t* DequeueBuffer(uint32_t& width, uint32_t& height, uint32_t& stride) override;
82 * @copydoc Dali::NativeImageSourceQueue::EnqueueBuffer
84 bool EnqueueBuffer(uint8_t* buffer) override;
89 ~NativeImageSourceQueueTizen() override;
92 * @copydoc Dali::NativeImageInterface::CreateResource
94 bool CreateResource() override;
97 * @copydoc Dali::NativeImageInterface::DestroyResource()
99 void DestroyResource() override;
102 * @copydoc Dali::NativeImageInterface::TargetTexture()
104 uint32_t TargetTexture() override;
107 * @copydoc Dali::NativeImageInterface::PrepareTexture()
109 void PrepareTexture() override;
112 * @copydoc Dali::NativeImageInterface::GetWidth()
114 uint32_t GetWidth() const override
120 * @copydoc Dali::NativeImageInterface::GetHeight()
122 uint32_t GetHeight() const override
128 * @copydoc Dali::NativeImageInterface::RequiresBlending()
130 bool RequiresBlending() const override
132 return mBlendingRequired;
136 * @copydoc Dali::NativeImageInterface::GetCustomFragmentPrefix()
138 const char* GetCustomFragmentPrefix() const override;
141 * @copydoc Dali::NativeImageInterface::ApplyNativeFragmentShader()
143 bool ApplyNativeFragmentShader(std::string& shader) override;
146 * @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
148 const char* GetCustomSamplerTypename() const override;
151 * @copydoc Dali::NativeImageInterface::GetTextureTarget()
153 int GetTextureTarget() const override;
156 * @copydoc Dali::NativeImageInterface::GetNativeImageHandle()
158 Any GetNativeImageHandle() const override;
161 * @copydoc Dali::NativeImageInterface::SourceChanged()
163 bool SourceChanged() const override;
166 * @copydoc Dali::NativeImageInterface::GetExtension()
168 NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
175 * Private constructor; @see NativeImageSourceQueue::New()
176 * @param[in] width The width of the image.
177 * @param[in] height The height of the image.
178 * @param[in] colorFormat The format of the image.
179 * @param[in] nativeImageSourceQueue contains tbm_surface_queue_h or is empty
181 NativeImageSourceQueueTizen(uint32_t width, uint32_t height, Dali::NativeImageSourceQueue::ColorFormat colorFormat, Any nativeImageSourceQueue);
183 void Initialize(Dali::NativeImageSourceQueue::ColorFormat colorFormat);
185 void ResetEglImageList();
187 tbm_surface_queue_h GetSurfaceFromAny(Any source) const;
189 bool CheckBlending(int format);
192 typedef std::pair<tbm_surface_h, void*> EglImagePair;
193 typedef std::pair<tbm_surface_h, void*> BufferPair;
195 Dali::Mutex mMutex; ///< Mutex
196 uint32_t mWidth; ///< image width
197 uint32_t mHeight; ///< image height
198 tbm_surface_queue_h mTbmQueue; ///< Tbm surface queue handle
199 tbm_surface_h mConsumeSurface; ///< The current tbm surface
200 std::vector<EglImagePair> mEglImages; ///< EGL Image vector
201 std::vector<BufferPair> mBuffers; ///< Buffer vector
202 EglGraphics* mEglGraphics; ///< EGL Graphics
203 EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions
204 bool mOwnTbmQueue; ///< Whether we created tbm queue
205 bool mBlendingRequired; ///< Whether blending is required
208 } // namespace Adaptor
210 } // namespace Internal
214 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_QUEUE_IMPL_TIZEN_H