Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / pixmap-image-impl.h
1 #ifndef __DALI_INTERNAL_PIXMAP_IMAGE_H__
2 #define __DALI_INTERNAL_PIXMAP_IMAGE_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 <pixmap-image.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace Adaptor
34 {
35 class EglImageExtensions;
36
37 /**
38  * Dali internal PixmapImage.
39  */
40 class PixmapImage
41 {
42 public:
43
44   /**
45    * Create a new PixmapImage internally.
46    * Depending on hardware the width and height may have to be a power of two.
47    * @param[in] width The width of the image.
48    * @param[in] height The height of the image.
49    * @param[in] depth color depth of the pixmap
50    * @param[in] pixmap contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
51    * @return A smart-pointer to a newly allocated image.
52    */
53   static PixmapImage* New(unsigned int width,
54                           unsigned int height,
55                           Dali::PixmapImage::ColorDepth depth,
56                           Any pixmap);
57
58   /**
59    * @copydoc Dali::PixmapImage::GetPixels()
60    */
61   bool GetPixels(std::vector<unsigned char> &pixbuf, unsigned int &width, unsigned int &height, Pixel::Format& pixelFormat ) const;
62
63   /**
64    * @copydoc Dali::PixmapImage::EncodeToFile(const std::string& )
65    */
66   bool EncodeToFile(const std::string& filename) const;
67
68   /**
69    * destructor
70    */
71   ~PixmapImage();
72
73   /**
74    * @copydoc Dali::PixmapImage::GlExtensionCreate()
75    */
76   bool GlExtensionCreate();
77
78   /**
79    * @copydoc Dali::PixmapImage::GlExtensionDestroy()
80    */
81   void GlExtensionDestroy();
82
83   /**
84    * @copydoc Dali::PixmapImage::TargetTexture()
85    */
86   unsigned int TargetTexture();
87
88   /**
89    * @copydoc Dali::PixmapImage::GetWidth()
90    */
91   unsigned int GetWidth() const
92   {
93     return mWidth;
94   }
95
96   /**
97    * @copydoc Dali::PixmapImage::GetHeight()
98    */
99   unsigned int GetHeight() const
100   {
101     return mHeight;
102   }
103
104   /**
105    * @copydoc Dali::PixmapImage::GetPixelFormat()
106    */
107   Pixel::Format GetPixelFormat() const
108   {
109     return mPixelFormat;
110   }
111
112 private:
113
114   /**
115    * Private constructor; @see PixmapImage::New()
116    * @param[in] width The width of the image.
117    * @param[in] height The height of the image.
118    * @param[in] colour depth of the pixmap
119    * @param[in] pixmap contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
120    */
121   PixmapImage(unsigned int width,
122               unsigned  int height,
123               Dali::PixmapImage::ColorDepth depth,
124               Any pixmap);
125
126   /**
127    * 2nd phase construction.
128    */
129   void Initialize();
130
131   /**
132    * Uses X11 to get the default depth.
133    * @param depth the PixelImage depth enum
134    * @return default x11 pixel depth
135    */
136   int GetPixelDepth(Dali::PixmapImage::ColorDepth depth) const;
137
138   /**
139    * Sets the pixel format based on the bit depth
140    * @param depth depth in bytes
141    */
142   void SetPixelFormat(int depth);
143
144   /**
145    * Gets the pixmap from the Any parameter
146    * @param pixmap contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
147    * @return pixmap x11 pixmap
148    */
149   Ecore_X_Pixmap GetPixmapFromAny(Any pixmap) const;
150
151   /**
152    * Given an existing pixmap, the function uses X to find out
153    * the width, heigth and depth of that pixmap.
154    */
155   void GetPixmapDetails();
156
157 private:
158
159   unsigned int mWidth;                        ///< pixmap width
160   unsigned int mHeight;                       ///< pixmap heights
161   bool mOwnPixmap;                            ///< Whether we created pixmap or not
162   Ecore_X_Pixmap mPixmap;                     ///< From Xlib
163   Pixel::Format mPixelFormat;                 ///< pixmap pixel format
164   Dali::PixmapImage::ColorDepth mColorDepth;  ///< color depth of pixmap
165   void* mEglImageKHR;                         ///< From EGL extension
166   EglImageExtensions* mEglImageExtensions;    ///< The EGL Image Extensions
167 };
168
169 } // namespace Adaptor
170
171 } // namespace Internal
172
173 } // namespace Dali
174
175 #endif // __DALI_INTERNAL_PIXMAP_IMAGE_H__