32d38059e69de2187bb183d4397f7519681c47a7
[platform/core/uifw/dali-adaptor.git] / adaptors / public-api / adaptor-framework / native-image-source.h
1 #ifndef __DALI_NATIVE_IMAGE_SOURCE_H__
2 #define __DALI_NATIVE_IMAGE_SOURCE_H__
3
4 /*
5  * Copyright (c) 2015 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 <string>
23
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/public-api/images/native-image-interface.h>
26 #include <dali/public-api/images/pixel.h>
27 #include <dali/public-api/object/any.h>
28
29 namespace Dali
30 {
31 /**
32  * @addtogroup dali_adaptor_framework
33  * @{
34  */
35
36 namespace Internal DALI_INTERNAL
37 {
38 namespace Adaptor
39 {
40 class NativeImageSource;
41 }
42 }
43
44 class NativeImageSource;
45 /**
46  * @brief Pointer to Dali::NativeImageSource.
47  * @SINCE_1_0.0
48  */
49 typedef IntrusivePtr<NativeImageSource> NativeImageSourcePtr;
50
51 /**
52  * @brief Used for displaying native images.
53  *
54  * The native image source can be created internally or
55  * externally by X11 or ECORE-X11.
56  *
57  * @SINCE_1_1.4
58  */
59 class DALI_IMPORT_API NativeImageSource : public NativeImageInterface
60 {
61 public:
62
63    /**
64     * @brief When creating a native image the color depth has to be specified.
65     * @SINCE_1_0.0
66     */
67    enum ColorDepth
68    {
69      COLOR_DEPTH_DEFAULT,     ///< Uses the current X screen default depth (recommended) @SINCE_1_0.0
70      COLOR_DEPTH_8,           ///< 8 bits per pixel @SINCE_1_0.0
71      COLOR_DEPTH_16,          ///< 16 bits per pixel @SINCE_1_0.0
72      COLOR_DEPTH_24,          ///< 24 bits per pixel @SINCE_1_0.0
73      COLOR_DEPTH_32           ///< 32 bits per pixel @SINCE_1_0.0
74    };
75
76   /**
77    * @brief Create a new NativeImageSource.
78    *
79    * Depending on hardware the width and height may have to be a power of two.
80    * @SINCE_1_0.0
81    * @param[in] width The width of the image.
82    * @param[in] height The height of the image.
83    * @param[in] depth color depth of the image.
84    * @return A smart-pointer to a newly allocated image.
85    */
86   static NativeImageSourcePtr New( unsigned int width, unsigned int height, ColorDepth depth );
87
88   /**
89    * @brief Create a new NativeImageSource from an existing native image.
90    *
91    * @SINCE_1_0.0
92    * @param[in] nativeImageSource must be a X11 pixmap or a Ecore_X_Pixmap
93    * @return A smart-pointer to a newly allocated image.
94    */
95   static NativeImageSourcePtr New( Any nativeImageSource );
96
97   /**
98    * @brief Retrieve the internal native image.
99    *
100    * @SINCE_1_0.0
101    * @return Any object containing the internal native image.
102    */
103   Any GetNativeImageSource();
104
105   /**
106    * @brief Get a copy of the pixels used by NativeImageSource.
107    *
108    * This is only supported for 24 bit RGB and 32 bit RGBA internal formats
109    * (COLOR_DEPTH_24 and COLOR_DEPTH_32).
110    * @SINCE_1_0.0
111    * @param[out] pixbuf a vector to store the pixels in
112    * @param[out] width  width of image
113    * @param[out] height height of image
114    * @param[out] pixelFormat pixel format used by image
115    * @return     True if the pixels were gotten, and false otherwise.
116    */
117   bool GetPixels( std::vector<unsigned char>& pixbuf, unsigned int& width, unsigned int& height, Pixel::Format& pixelFormat ) const;
118
119   /**
120    * @brief Convert the current pixel contents to either a JPEG or PNG format
121    * and write that to the filesytem.
122    *
123    * @SINCE_1_0.0
124    * @param[in] filename Identify the filesytem location at which to write the
125    *                     encoded image. The extension determines the encoding used.
126    *                     The two valid encoding are (".jpeg"|".jpg") and ".png".
127    * @return    True if the pixels were written, and false otherwise.
128    */
129   bool EncodeToFile(const std::string& filename) const;
130
131 private:   // native image
132
133   /**
134    * @copydoc Dali::NativeImageInterface::GlExtensionCreate()
135    */
136   virtual bool GlExtensionCreate();
137
138   /**
139    * @copydoc Dali::NativeImageInterface::GlExtensionDestroy()
140    */
141   virtual void GlExtensionDestroy();
142
143   /**
144    * @copydoc Dali::NativeImageInterface::TargetTexture()
145    */
146   virtual unsigned int TargetTexture();
147
148   /**
149    * @copydoc Dali::NativeImageInterface::PrepareTexture()
150    */
151   virtual void PrepareTexture();
152
153   /**
154    * @copydoc Dali::NativeImageInterface::GetWidth()
155    */
156   virtual unsigned int GetWidth() const;
157
158   /**
159    * @copydoc Dali::NativeImageInterface::GetHeight()
160    */
161   virtual unsigned int GetHeight() const;
162
163   /**
164    * @copydoc Dali::NativeImageInterface::RequiresBlending()
165    */
166   virtual bool RequiresBlending() const;
167
168 private:
169
170   /**
171    * @brief Private constructor
172    * @SINCE_1_0.0
173    * @param[in] width The width of the image.
174    * @param[in] height The height of the image.
175    * @param[in] depth color depth of the image.
176    * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
177    */
178   DALI_INTERNAL NativeImageSource( unsigned int width, unsigned int height, ColorDepth depth, Any nativeImageSource );
179
180   /**
181    * @brief A reference counted object may only be deleted by calling Unreference().
182    *
183    * The implementation should destroy the NativeImage resources.
184    * @SINCE_1_0.0
185    */
186   DALI_INTERNAL virtual ~NativeImageSource();
187
188   /**
189    * @brief Undefined copy constructor
190    *
191    * This avoids accidental calls to a default copy constructor.
192    * @SINCE_1_0.0
193    * @param[in] nativeImageSource A reference to the object to copy.
194    */
195   DALI_INTERNAL NativeImageSource( const NativeImageSource& nativeImageSource );
196
197   /**
198    * @brief Undefined assignment operator.
199    *
200    * This avoids accidental calls to a default assignment operator.
201    * @SINCE_1_0.0
202    * @param[in] rhs A reference to the object to copy.
203    */
204   DALI_INTERNAL NativeImageSource& operator=(const NativeImageSource& rhs);
205
206 private:
207
208   Internal::Adaptor::NativeImageSource* mImpl; ///< Implementation pointer
209 };
210
211 /**
212  * @}
213  */
214 } // namespace Dali
215
216 #endif // __DALI_NATIVE_IMAGE_SOURCE_H__