[dali_1.3.8] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / ubuntu-x11 / native-image-source-impl-x.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 <Ecore_X.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/adaptor-framework/native-image-source.h>
26
27 #include <dali/internal/imaging/common/native-image-source-impl.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace Adaptor
36 {
37 class EglImageExtensions;
38
39 /**
40  * Dali internal NativeImageSource.
41  */
42 class NativeImageSourceX : public Internal::Adaptor::NativeImageSource
43 {
44 public:
45
46   /**
47    * Create a new NativeImageSource internally.
48    * Depending on hardware the width and height may have to be a power of two.
49    * @param[in] width The width of the image.
50    * @param[in] height The height of the image.
51    * @param[in] depth color depth of the image.
52    * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
53    * @return A smart-pointer to a newly allocated image.
54    */
55   static NativeImageSourceX* New(unsigned int width,
56                           unsigned int height,
57                           Dali::NativeImageSource::ColorDepth depth,
58                           Any nativeImageSource);
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, unsigned int &width, unsigned int &height, Pixel::Format& pixelFormat ) const override;
68
69   /**
70    * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& )
71    */
72   bool EncodeToFile(const std::string& filename) const override;
73
74   /**
75    * @copydoc Dali::NativeImageSource::SetSource( Any source )
76    */
77   void SetSource( Any source ) override;
78
79   /**
80    * @copydoc Dali::NativeImageSource::IsColorDepthSupported( ColorDepth colorDepth )
81    */
82   bool IsColorDepthSupported( Dali::NativeImageSource::ColorDepth colorDepth ) override;
83
84   /**
85    * destructor
86    */
87   ~NativeImageSourceX() override;
88
89   /**
90    * @copydoc Dali::NativeImageSource::GlExtensionCreate()
91    */
92   bool GlExtensionCreate() override;
93
94   /**
95    * @copydoc Dali::NativeImageSource::GlExtensionDestroy()
96    */
97   void GlExtensionDestroy() override;
98
99   /**
100    * @copydoc Dali::NativeImageSource::TargetTexture()
101    */
102   unsigned int TargetTexture() override;
103
104   /**
105    * @copydoc Dali::NativeImageSource::PrepareTexture()
106    */
107   void PrepareTexture() override;
108
109   /**
110    * @copydoc Dali::NativeImageSource::GetWidth()
111    */
112   unsigned int GetWidth() const override
113   {
114     return mWidth;
115   }
116
117   /**
118    * @copydoc Dali::NativeImageSource::GetHeight()
119    */
120   unsigned int GetHeight() const override
121   {
122     return mHeight;
123   }
124
125   /**
126    * @copydoc Dali::NativeImageSource::RequiresBlending()
127    */
128   bool RequiresBlending() const override
129   {
130     return mBlendingRequired;
131   }
132
133   /**
134    * @copydoc Dali::NativeImageInterface::GetExtension()
135    */
136   NativeImageInterface::Extension* GetNativeImageInterfaceExtension() override
137   {
138     return nullptr;
139   }
140
141 private:
142
143   /**
144    * Private constructor; @see NativeImageSource::New()
145    * @param[in] width The width of the image.
146    * @param[in] height The height of the image.
147    * @param[in] colour depth of the image.
148    * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
149    */
150   NativeImageSourceX(unsigned int width,
151               unsigned  int height,
152               Dali::NativeImageSource::ColorDepth depth,
153               Any nativeImageSource);
154
155   /**
156    * 2nd phase construction.
157    */
158   void Initialize();
159
160   /**
161    * Uses X11 to get the default depth.
162    * @param depth the PixelImage depth enum
163    * @return default x11 pixel depth
164    */
165   int GetPixelDepth(Dali::NativeImageSource::ColorDepth depth) const;
166
167   /**
168    * Gets the pixmap from the Any parameter
169    * @param pixmap contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
170    * @return pixmap x11 pixmap
171    */
172   Ecore_X_Pixmap GetPixmapFromAny(Any pixmap) const;
173
174   /**
175    * Given an existing pixmap, the function uses X to find out
176    * the width, heigth and depth of that pixmap.
177    */
178   void GetPixmapDetails();
179
180 private:
181
182   unsigned int mWidth;                        ///< image width
183   unsigned int mHeight;                       ///< image heights
184   bool mOwnPixmap;                            ///< Whether we created pixmap or not
185   Ecore_X_Pixmap mPixmap;                     ///< From Xlib
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 };
191
192 } // namespace Adaptor
193
194 } // namespace Internal
195
196 } // namespace Dali
197
198 #endif // __DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H__