aa81ad41bf2abb8eabb09a34a36df43667febca0
[platform/core/uifw/dali-adaptor.git] / adaptors / 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) 2018 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 #include <native-image-source-impl.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 namespace Adaptor
37 {
38
39 class EglFactory;
40 class EglImageExtensions;
41
42 /**
43  * Dali internal NativeImageSource.
44  */
45 class NativeImageSourceTizen: public Internal::Adaptor::NativeImageSource, public NativeImageInterface::Extension
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(unsigned int width,
59                           unsigned int 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, unsigned int &width, unsigned int &height, Pixel::Format& pixelFormat ) const  override;
72
73   /**
74    * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& )
75    */
76   bool EncodeToFile(const std::string& filename) const override;
77
78   /**
79    * @copydoc Dali::NativeImageSource::SetSource( Any source )
80    */
81   void SetSource( Any source ) override;
82
83   /**
84    * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
85    */
86   bool IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ) override;
87
88   /**
89    * destructor
90    */
91   ~NativeImageSourceTizen() override;
92
93   /**
94    * @copydoc Dali::NativeImageSource::GlExtensionCreate()
95    */
96   bool GlExtensionCreate() override;
97
98   /**
99    * @copydoc Dali::NativeImageSource::GlExtensionDestroy()
100    */
101   void GlExtensionDestroy() override;
102
103   /**
104    * @copydoc Dali::NativeImageSource::TargetTexture()
105    */
106   unsigned int TargetTexture() override;
107
108   /**
109    * @copydoc Dali::NativeImageSource::PrepareTexture()
110    */
111   void PrepareTexture() override;
112
113   /**
114    * @copydoc Dali::NativeImageSource::GetWidth()
115    */
116   unsigned int GetWidth() const override
117   {
118     return mWidth;
119   }
120
121   /**
122    * @copydoc Dali::NativeImageSource::GetHeight()
123    */
124   unsigned int GetHeight() const override
125   {
126     return mHeight;
127   }
128
129   /**
130    * @copydoc Dali::NativeImageSource::RequiresBlending()
131    */
132   bool RequiresBlending() const override
133   {
134     return mBlendingRequired;
135   }
136
137   /**
138    * @copydoc Dali::NativeImageInterface::GetExtension()
139    */
140   NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
141   {
142     return this;
143   }
144
145   /**
146    * @copydoc Dali::NativeImageInterface::Extension::GetCustomFragmentPreFix()
147    */
148   const char* GetCustomFragmentPreFix() override;
149
150   /**
151    * @copydoc Dali::NativeImageInterface::Extension::GetCustomSamplerTypename()
152    */
153   const char* GetCustomSamplerTypename() override;
154
155   /**
156    * @copydoc Dali::NativeImageInterface::Extension::GetEglImageTextureTarget()
157    */
158   int GetEglImageTextureTarget() override;
159
160   /**
161    * @copydoc Dali::NativeImageInterface::Extension::SetDestructorNotification((void *notification)
162    */
163   void SetDestructorNotification(void* notification) override;
164
165 private:
166
167   /**
168    * Private constructor; @see NativeImageSource::New()
169    * @param[in] width The width of the image.
170    * @param[in] height The height of the image.
171    * @param[in] colour depth of the image.
172    * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
173    */
174   NativeImageSourceTizen(unsigned int width,
175               unsigned  int height,
176               Dali::NativeImageSource::ColorDepth depth,
177               Any nativeImageSource);
178
179   void Initialize();
180
181   tbm_surface_h GetSurfaceFromAny( Any source ) const;
182
183   bool CheckBlending( tbm_format format );
184
185 private:
186
187   unsigned int mWidth;                        ///< image width
188   unsigned int mHeight;                       ///< image height
189   bool mOwnTbmSurface;                        ///< Whether we created pixmap or not
190   tbm_surface_h mTbmSurface;
191   tbm_format mTbmFormat;
192   bool mBlendingRequired;                      ///< Whether blending is required
193   Dali::NativeImageSource::ColorDepth mColorDepth;  ///< color depth of image
194   void* mEglImageKHR;                         ///< From EGL extension
195   EglFactory* mEglFactory;                    ///< EGL Factory
196   EglImageExtensions* mEglImageExtensions;    ///< The EGL Image Extensions
197   bool mSetSource;
198   void *mNotification;
199 };
200
201 } // namespace Adaptor
202
203 } // namespace Internal
204
205 } // namespace Dali
206
207 #endif // DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_TIZEN_H