3f169267a192d086e9d8e023e4c413fe6f322ae2
[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 private:
158
159   /**
160    * Private constructor; @see NativeImageSource::New()
161    * @param[in] width The width of the image.
162    * @param[in] height The height of the image.
163    * @param[in] colour depth of the image.
164    * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
165    */
166   NativeImageSource(unsigned int width,
167               unsigned  int height,
168               Dali::NativeImageSource::ColorDepth depth,
169               Any nativeImageSource);
170
171   void Initialize();
172
173   int GetPixelDepth(Dali::NativeImageSource::ColorDepth depth) const;
174
175   tbm_surface_h GetSurfaceFromAny( Any source ) const;
176
177 private:
178
179   unsigned int mWidth;                        ///< image width
180   unsigned int mHeight;                       ///< image heights
181   bool mOwnTbmsurface;                            ///< Whether we created pixmap or not
182   tbm_surface_h mTbmsurface;
183   bool mBlendingRequired;                      ///< Whether blending is required
184   Dali::NativeImageSource::ColorDepth mColorDepth;  ///< color depth of image
185   void* mEglImageKHR;                         ///< From EGL extension
186   EglImageExtensions* mEglImageExtensions;    ///< The EGL Image Extensions
187   bool mSetSource;
188   EglImageContainer mEglImageKHRContainer;
189 };
190
191 } // namespace Adaptor
192
193 } // namespace Internal
194
195 } // namespace Dali
196
197 #endif // __DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H__