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