1 #ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_TIZEN_H
2 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_TIZEN_H
5 * Copyright (c) 2020 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 <tbm_surface.h>
23 #include <dali/devel-api/threading/mutex.h>
24 #include <dali/public-api/common/dali-vector.h>
27 #include <dali/public-api/adaptor-framework/native-image-source.h>
28 #include <dali/internal/imaging/common/native-image-source-impl.h>
40 class EglImageExtensions;
43 * Dali internal NativeImageSource.
45 class NativeImageSourceTizen: public Internal::Adaptor::NativeImageSource
50 * Create a new NativeImageSource internally.
51 * Depending on hardware the width and height may have to be a power of two.
52 * @param[in] width The width of the image.
53 * @param[in] height The height of the image.
54 * @param[in] depth color depth of the image.
55 * @param[in] nativeImageSource contains tbm_surface_h or is empty
56 * @return A smart-pointer to a newly allocated image.
58 static NativeImageSourceTizen* New(uint32_t width,
60 Dali::NativeImageSource::ColorDepth depth,
61 Any nativeImageSource);
64 * @copydoc Dali::NativeImageSource::GetNativeImageSource()
66 Any GetNativeImageSource() const override;
69 * @copydoc Dali::NativeImageSource::GetPixels()
71 bool GetPixels(std::vector<unsigned char> &pixbuf, uint32_t &width, uint32_t &height, Pixel::Format& pixelFormat ) const override;
74 * @copydoc Dali::NativeImageSource::SetSource( Any source )
76 void SetSource( Any source ) override;
79 * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
81 bool IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ) override;
86 ~NativeImageSourceTizen() override;
89 * @copydoc Dali::NativeImageSource::CreateResource()
91 bool CreateResource() override;
94 * @copydoc Dali::NativeImageSource::DestroyResource()
96 void DestroyResource() override;
99 * @copydoc Dali::NativeImageSource::TargetTexture()
101 uint32_t TargetTexture() override;
104 * @copydoc Dali::NativeImageSource::PrepareTexture()
106 void PrepareTexture() override;
109 * @copydoc Dali::NativeImageSource::GetWidth()
111 uint32_t GetWidth() const override
117 * @copydoc Dali::NativeImageSource::GetHeight()
119 uint32_t GetHeight() const override
125 * @copydoc Dali::NativeImageSource::RequiresBlending()
127 bool RequiresBlending() const override
129 return mBlendingRequired;
133 * @copydoc Dali::NativeImageInterface::GetCustomFragmentPrefix()
135 const char* GetCustomFragmentPrefix() const override;
138 * @copydoc Dali::NativeImageInterface::GetCustomSamplerTypename()
140 const char* GetCustomSamplerTypename() const override;
143 * @copydoc Dali::NativeImageInterface::GetTextureTarget()
145 int GetTextureTarget() const override;
148 * @copydoc Dali::NativeImageInterface::GetNativeImageHandle()
150 Any GetNativeImageHandle() const override;
153 * @copydoc Dali::NativeImageInterface::SourceChanged()
155 bool SourceChanged() const override;
158 * @copydoc Dali::NativeImageInterface::GetExtension()
160 NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
166 * @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
168 uint8_t* AcquireBuffer( uint16_t& width, uint16_t& height, uint16_t& stride ) override;
171 * @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
173 bool ReleaseBuffer() override;
176 * @copydoc Dali::NativeImageSource::SetResourceDestructionCallback()
178 void SetResourceDestructionCallback(EventThreadCallback* callback) override;
183 * Private constructor; @see NativeImageSource::New()
184 * @param[in] width The width of the image.
185 * @param[in] height The height of the image.
186 * @param[in] colour depth of the image.
187 * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
189 NativeImageSourceTizen(uint32_t width,
191 Dali::NativeImageSource::ColorDepth depth,
192 Any nativeImageSource);
196 tbm_surface_h GetSurfaceFromAny( Any source ) const;
198 bool CheckBlending( tbm_format format );
200 void DestroySurface();
203 uint32_t mWidth; ///< image width
204 uint32_t mHeight; ///< image height
205 bool mOwnTbmSurface; ///< Whether we created pixmap or not
206 tbm_surface_h mTbmSurface;
207 tbm_format mTbmFormat;
208 bool mBlendingRequired; ///< Whether blending is required
209 Dali::NativeImageSource::ColorDepth mColorDepth; ///< color depth of image
210 void* mEglImageKHR; ///< From EGL extension
211 EglGraphics* mEglGraphics; ///< EGL Graphics
212 EglImageExtensions* mEglImageExtensions; ///< The EGL Image Extensions
214 mutable Dali::Mutex mMutex;
215 bool mIsBufferAcquired; ///< Whether AcquireBuffer is called
216 std::unique_ptr<EventThreadCallback> mResourceDestructionCallback;
219 } // namespace Adaptor
221 } // namespace Internal
225 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_TIZEN_H