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