9264a25dd330e34cf0bf5368b4cfa926e98affd7
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / tizen / native-image-source-impl-tizen.h
1 #ifndef DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_TIZEN_H
2 #define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_TIZEN_H
3
4 /*
5  * Copyright (c) 2020 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 <tbm_surface.h>
23 #include <dali/devel-api/images/native-image-interface-extension.h>
24 #include <dali/devel-api/threading/mutex.h>
25 #include <dali/public-api/common/dali-vector.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/public-api/adaptor-framework/native-image-source.h>
29 #include <dali/internal/imaging/common/native-image-source-impl.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace Adaptor
38 {
39
40 class EglGraphics;
41 class EglImageExtensions;
42
43 /**
44  * Dali internal NativeImageSource.
45  */
46 class NativeImageSourceTizen: public Internal::Adaptor::NativeImageSource, public NativeImageInterface::Extension
47 {
48 public:
49
50   /**
51    * Create a new NativeImageSource internally.
52    * Depending on hardware the width and height may have to be a power of two.
53    * @param[in] width The width of the image.
54    * @param[in] height The height of the image.
55    * @param[in] depth color depth of the image.
56    * @param[in] nativeImageSource contains tbm_surface_h or is empty
57    * @return A smart-pointer to a newly allocated image.
58    */
59   static NativeImageSourceTizen* New(uint32_t width,
60                           uint32_t height,
61                           Dali::NativeImageSource::ColorDepth depth,
62                           Any nativeImageSource);
63
64   /**
65    * @copydoc Dali::NativeImageSource::GetNativeImageSource()
66    */
67   Any GetNativeImageSource() const override;
68
69   /**
70    * @copydoc Dali::NativeImageSource::GetPixels()
71    */
72   bool GetPixels(std::vector<unsigned char> &pixbuf, uint32_t &width, uint32_t &height, Pixel::Format& pixelFormat ) const override;
73
74   /**
75    * @copydoc Dali::NativeImageSource::SetSource( Any source )
76    */
77   void SetSource( Any source ) override;
78
79   /**
80    * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
81    */
82   bool IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ) override;
83
84   /**
85    * destructor
86    */
87   ~NativeImageSourceTizen() override;
88
89   /**
90    * @copydoc Dali::NativeImageSource::GlExtensionCreate()
91    */
92   bool GlExtensionCreate() override;
93
94   /**
95    * @copydoc Dali::NativeImageSource::GlExtensionDestroy()
96    */
97   void GlExtensionDestroy() override;
98
99   /**
100    * @copydoc Dali::NativeImageSource::TargetTexture()
101    */
102   uint32_t TargetTexture() override;
103
104   /**
105    * @copydoc Dali::NativeImageSource::PrepareTexture()
106    */
107   void PrepareTexture() override;
108
109   /**
110    * @copydoc Dali::NativeImageSource::GetWidth()
111    */
112   uint32_t GetWidth() const override
113   {
114     return mWidth;
115   }
116
117   /**
118    * @copydoc Dali::NativeImageSource::GetHeight()
119    */
120   uint32_t GetHeight() const override
121   {
122     return mHeight;
123   }
124
125   /**
126    * @copydoc Dali::NativeImageSource::RequiresBlending()
127    */
128   bool RequiresBlending() const override
129   {
130     return mBlendingRequired;
131   }
132
133   /**
134    * @copydoc Dali::NativeImageInterface::GetExtension()
135    */
136   NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
137   {
138     return this;
139   }
140
141   /**
142    * @copydoc Dali::NativeImageInterface::Extension::GetCustomFragmentPreFix()
143    */
144   const char* GetCustomFragmentPreFix() override;
145
146   /**
147    * @copydoc Dali::NativeImageInterface::Extension::GetCustomSamplerTypename()
148    */
149   const char* GetCustomSamplerTypename() override;
150
151   /**
152    * @copydoc Dali::NativeImageInterface::Extension::GetEglImageTextureTarget()
153    */
154   int GetEglImageTextureTarget() override;
155
156   /**
157    * @copydoc Dali::Internal::Adaptor::NativeImageSource::AcquireBuffer()
158    */
159   uint8_t* AcquireBuffer( uint16_t& width, uint16_t& height, uint16_t& stride ) override;
160
161   /**
162    * @copydoc Dali::Internal::Adaptor::NativeImageSource::ReleaseBuffer()
163    */
164   bool ReleaseBuffer() override;
165
166 private:
167
168   /**
169    * Private constructor; @see NativeImageSource::New()
170    * @param[in] width The width of the image.
171    * @param[in] height The height of the image.
172    * @param[in] colour depth of the image.
173    * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
174    */
175   NativeImageSourceTizen(uint32_t width,
176               unsigned  int height,
177               Dali::NativeImageSource::ColorDepth depth,
178               Any nativeImageSource);
179
180   void Initialize();
181
182   tbm_surface_h GetSurfaceFromAny( Any source ) const;
183
184   bool CheckBlending( tbm_format format );
185
186   void DestroySurface();
187
188 private:
189
190   uint32_t mWidth;                        ///< image width
191   uint32_t mHeight;                       ///< image height
192   bool mOwnTbmSurface;                        ///< Whether we created pixmap or not
193   tbm_surface_h mTbmSurface;
194   tbm_format mTbmFormat;
195   bool mBlendingRequired;                      ///< Whether blending is required
196   Dali::NativeImageSource::ColorDepth mColorDepth;  ///< color depth of image
197   void* mEglImageKHR;                         ///< From EGL extension
198   EglGraphics* mEglGraphics;                  ///< EGL Graphics
199   EglImageExtensions* mEglImageExtensions;    ///< The EGL Image Extensions
200   bool mSetSource;
201   mutable Dali::Mutex mMutex;
202   bool mIsBufferAcquired;                      ///< Whether AcquireBuffer is called
203 };
204
205 } // namespace Adaptor
206
207 } // namespace Internal
208
209 } // namespace Dali
210
211 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_TIZEN_H