Support tbm_surface_queue
[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) 2017 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/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 EglImageExtensions;
40
41 /**
42  * Dali internal NativeImageSource.
43  */
44 class NativeImageSourceTizen: public Internal::Adaptor::NativeImageSource, public NativeImageInterface::Extension
45 {
46 public:
47
48   /**
49    * Create a new NativeImageSource internally.
50    * Depending on hardware the width and height may have to be a power of two.
51    * @param[in] width The width of the image.
52    * @param[in] height The height of the image.
53    * @param[in] depth color depth of the image.
54    * @param[in] nativeImageSource contains tbm_surface_h or is empty
55    * @return A smart-pointer to a newly allocated image.
56    */
57   static NativeImageSourceTizen* New(unsigned int width,
58                           unsigned int height,
59                           Dali::NativeImageSource::ColorDepth depth,
60                           Any nativeImageSource);
61
62   /**
63    * @copydoc Dali::NativeImageSource::GetNativeImageSource()
64    */
65   Any GetNativeImageSource() const override;
66
67   /**
68    * @copydoc Dali::NativeImageSource::GetPixels()
69    */
70   bool GetPixels(std::vector<unsigned char> &pixbuf, unsigned int &width, unsigned int &height, Pixel::Format& pixelFormat ) const  override;
71
72   /**
73    * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& )
74    */
75   bool EncodeToFile(const std::string& filename) const override;
76
77   /**
78    * @copydoc Dali::NativeImageSource::SetSource( Any source )
79    */
80   void SetSource( Any source ) override;
81
82   /**
83    * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
84    */
85   bool IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ) override;
86
87   /**
88    * destructor
89    */
90   ~NativeImageSourceTizen() override;
91
92   /**
93    * @copydoc Dali::NativeImageSource::GlExtensionCreate()
94    */
95   bool GlExtensionCreate() override;
96
97   /**
98    * @copydoc Dali::NativeImageSource::GlExtensionDestroy()
99    */
100   void GlExtensionDestroy() override;
101
102   /**
103    * @copydoc Dali::NativeImageSource::TargetTexture()
104    */
105   unsigned int TargetTexture() override;
106
107   /**
108    * @copydoc Dali::NativeImageSource::PrepareTexture()
109    */
110   void PrepareTexture() override;
111
112   /**
113    * @copydoc Dali::NativeImageSource::GetWidth()
114    */
115   unsigned int GetWidth() const override
116   {
117     return mWidth;
118   }
119
120   /**
121    * @copydoc Dali::NativeImageSource::GetHeight()
122    */
123   unsigned int GetHeight() const override
124   {
125     return mHeight;
126   }
127
128   /**
129    * @copydoc Dali::NativeImageSource::RequiresBlending()
130    */
131   bool RequiresBlending() const override
132   {
133     return mBlendingRequired;
134   }
135
136   /**
137    * @copydoc Dali::NativeImageInterface::GetExtension()
138    */
139   NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
140   {
141     return this;
142   }
143
144   /**
145    * @copydoc Dali::NativeImageInterface::Extension::GetCustomFragmentPreFix()
146    */
147   const char* GetCustomFragmentPreFix() override;
148
149   /**
150    * @copydoc Dali::NativeImageInterface::Extension::GetCustomSamplerTypename()
151    */
152   const char* GetCustomSamplerTypename() override;
153
154   /**
155    * @copydoc Dali::NativeImageInterface::Extension::GetEglImageTextureTarget()
156    */
157   int GetEglImageTextureTarget() override;
158
159 private:
160
161   /**
162    * Private constructor; @see NativeImageSource::New()
163    * @param[in] width The width of the image.
164    * @param[in] height The height of the image.
165    * @param[in] colour depth of the image.
166    * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
167    */
168   NativeImageSourceTizen(unsigned int width,
169               unsigned  int height,
170               Dali::NativeImageSource::ColorDepth depth,
171               Any nativeImageSource);
172
173   void Initialize();
174
175   tbm_surface_h GetSurfaceFromAny( Any source ) const;
176
177   bool CheckBlending( tbm_format format );
178
179 private:
180
181   unsigned int mWidth;                        ///< image width
182   unsigned int mHeight;                       ///< image height
183   bool mOwnTbmSurface;                        ///< Whether we created pixmap or not
184   tbm_surface_h mTbmSurface;
185   tbm_format mTbmFormat;
186   bool mBlendingRequired;                      ///< Whether blending is required
187   Dali::NativeImageSource::ColorDepth mColorDepth;  ///< color depth of image
188   void* mEglImageKHR;                         ///< From EGL extension
189   EglImageExtensions* mEglImageExtensions;    ///< The EGL Image Extensions
190   bool mSetSource;
191 };
192
193 } // namespace Adaptor
194
195 } // namespace Internal
196
197 } // namespace Dali
198
199 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_TIZEN_H