[dali_1.0.7] Merge branch 'tizen'
[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 #include <pixmap-image.h>
24
25 // INTERNAL INCLUDES
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace Adaptor
34 {
35 class Adaptor;
36 class EglImageExtensions;
37
38 /**
39  * Dali internal PixmapImage.
40  */
41 class PixmapImage
42 {
43 public:
44
45   /**
46    * Create a new PixmapImage internally.
47    * Depending on hardware the width and height may have to be a power of two.
48    * @param[in] width The width of the image.
49    * @param[in] height The height of the image.
50    * @param[in] depth color depth of the pixmap
51    * @param[in] adaptor reference to dali adaptor
52    * @param[in] pixmap 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 PixmapImage* New(unsigned int width,
56                           unsigned int height,
57                           Dali::PixmapImage::ColorDepth depth,
58                           Dali::Adaptor& adaptor,
59                           Any pixmap);
60
61    /**
62     * @copydoc Dali::PixmapImage::GetPixmap()
63     */
64   Any GetPixmap(Dali::PixmapImage::PixmapAPI api) const;
65
66   /**
67    * @copydoc Dali::PixmapImage::GetDisplay()
68    */
69   Any GetDisplay() const;
70
71   /**
72    * @copydoc Dali::PixmapImage::GetPixels()
73    */
74   bool GetPixels(std::vector<unsigned char> &pixbuf, unsigned int &width, unsigned int &height, Pixel::Format& pixelFormat ) const;
75
76   /**
77    * @copydoc Dali::PixmapImage::EncodeToFile(const std::string& )
78    */
79   bool EncodeToFile(const std::string& filename) const;
80
81   /**
82    * destructor
83    */
84   ~PixmapImage();
85
86   /**
87    * @copydoc Dali::PixmapImage::GlExtensionCreate()
88    */
89   bool GlExtensionCreate();
90
91   /**
92    * @copydoc Dali::PixmapImage::GlExtensionDestroy()
93    */
94   void GlExtensionDestroy();
95
96   /**
97    * @copydoc Dali::PixmapImage::TargetTexture()
98    */
99   unsigned int TargetTexture();
100
101   /**
102    * @copydoc Dali::PixmapImage::GetWidth()
103    */
104   unsigned int GetWidth() const
105   {
106     return mWidth;
107   }
108
109   /**
110    * @copydoc Dali::PixmapImage::GetHeight()
111    */
112   unsigned int GetHeight() const
113   {
114     return mHeight;
115   }
116
117   /**
118    * @copydoc Dali::PixmapImage::GetPixelFormat()
119    */
120   Pixel::Format GetPixelFormat() const
121   {
122     return mPixelFormat;
123   }
124
125 private:
126
127   /**
128    * Private constructor; @see PixmapImage::New()
129    * @param[in] width The width of the image.
130    * @param[in] height The height of the image.
131    * @param[in] colour depth of the pixmap
132    * @param[in] adaptor a reference to Dali adaptor
133    * @param[in] pixmap contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
134    */
135   PixmapImage(unsigned int width,
136               unsigned  int height,
137               Dali::PixmapImage::ColorDepth depth,
138               Dali::Adaptor &adaptor,
139               Any pixmap);
140
141   /**
142    * 2nd phase construction.
143    */
144   void Initialize();
145
146   /**
147    * Uses X11 to get the default depth.
148    * @param depth the PixelImage depth enum
149    * @return default x11 pixel depth
150    */
151   int GetPixelDepth(Dali::PixmapImage::ColorDepth depth) const;
152
153   /**
154    * Sets the pixel format based on the bit depth
155    * @param depth depth in bytes
156    */
157   void SetPixelFormat(int depth);
158
159   /**
160    * Gets the pixmap from the Any parameter
161    * @param pixmap contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
162    * @return pixmap x11 pixmap
163    */
164   Ecore_X_Pixmap GetPixmapFromAny(Any pixmap) const;
165
166   /**
167    * Given an existing pixmap, the function uses X to find out
168    * the width, heigth and depth of that pixmap.
169    */
170   void GetPixmapDetails();
171
172   /**
173    * Returns the egl image extensions class from the adaptor
174    * @return reference to egl image extensionsa
175    */
176   EglImageExtensions* GetEglImageExtensions() const;
177
178 private:
179
180   unsigned int mWidth;                        ///< pixmap width
181   unsigned int mHeight;                       ///< pixmap heights
182   bool mOwnPixmap;                            ///< Whether we created pixmap or not
183   Ecore_X_Pixmap mPixmap;                     ///< From Xlib
184   Ecore_X_Display* mDisplay;                  ///< x-connection used to create pixmap (if it was not created outside of PixmapImage)
185   Pixel::Format mPixelFormat;                 ///< pixmap pixel format
186   Dali::PixmapImage::ColorDepth mColorDepth;  ///< color depth of pixmap
187   Adaptor& mAdaptor;                          ///< adaptor
188   void* mEglImageKHR;                         ///< From EGL extension
189 };
190
191 } // namespace Adaptor
192
193 } // namespace Internal
194
195 } // namespace Dali
196
197 #endif // __DALI_INTERNAL_PIXMAP_IMAGE_H__