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