[dali_1.0.1] Merge branch 'tizen'
[platform/core/uifw/dali-adaptor.git] / adaptors / common / gl / egl-implementation.h
1 #ifndef __DALI_INTERNAL_EGL_IMPLEMENTATION_H__
2 #define __DALI_INTERNAL_EGL_IMPLEMENTATION_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 <EGL/egl.h>
23 #include <EGL/eglext.h>
24 #include <boost/any.hpp>
25 #include <dali/public-api/common/dali-vector.h>
26
27 // INTERNAL INCLUDES
28 #include <base/interfaces/egl-interface.h>
29
30 namespace Dali
31 {
32 namespace Internal
33 {
34 namespace Adaptor
35 {
36
37 enum ColorDepth
38 {
39   COLOR_DEPTH_24 = 24,
40   COLOR_DEPTH_32 = 32
41 };
42
43 /**
44  * EglImplementation class provides an EGL implementation.
45  */
46 class EglImplementation : public EglInterface
47 {
48 public:
49   /**
50    * Constructor
51    */
52   EglImplementation();
53
54   /**
55    * Destructor
56    */
57   virtual ~EglImplementation();
58
59 public:
60
61  /**
62    * (Called from  ECoreX::RenderSurface, not RenderThread, so not in i/f, hence, not virtual)
63    * Initialize GL
64    * @param display The display
65    * @param isOwnSurface whether the surface is own or not
66    * @return true on success, false on failure
67    */
68   bool InitializeGles( EGLNativeDisplayType display, bool isOwnSurface = true );
69
70   /**
71     * Create the OpenGL context.
72     * @return true if successful
73     */
74   virtual bool CreateContext();
75
76   /**
77     * Destroy the OpenGL context.
78     */
79   void DestroyContext();
80
81   /**
82     * Destroy the OpenGL surface.
83     */
84   void DestroySurface();
85
86   /**
87    * Make the OpenGL context current
88    */
89   virtual void MakeContextCurrent();
90
91   /**
92    * clear the OpenGL context
93    */
94   void MakeContextNull();
95
96   /**
97    * Terminate GL
98    */
99   virtual void TerminateGles();
100
101   /**
102    * Checks if GL is initialised
103    * @return true if it is
104    */
105   bool IsGlesInitialized() const;
106
107   /**
108    * Sets the refresh sync mode.
109    * @see SyncMode
110    */
111   virtual bool SetRefreshSync( SyncMode mode );
112
113   /**
114    * Performs an OpenGL swap buffers command
115    */
116   virtual void SwapBuffers();
117
118   /**
119    * Performs an OpenGL copy buffers command
120    */
121   virtual void CopyBuffers();
122
123   /**
124    * Performs an EGL wait GL command
125    */
126   virtual void WaitGL();
127
128   /**
129    * Choose config of egl
130    * @param isWindowType whether the config for window or pixmap
131    * @param colorDepth Bit per pixel value (ex. 32 or 24)
132   */
133   void ChooseConfig( bool isWindowType, ColorDepth depth );
134
135   /**
136     * Create an OpenGL surface using a window
137     * @param window The window to create the surface on
138     * @param colorDepth Bit per pixel value (ex. 32 or 24)
139     * @return true on success, false on failure
140     */
141   void CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth );
142
143   /**
144    * Create the OpenGL surface using a pixmap
145    * @param pixmap The pixmap to create the surface on
146    * @param colorDepth Bit per pixel value (ex. 32 or 24)
147    * @return true on success, false on failure
148    */
149   void CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth );
150
151   /**
152    * Replaces the render surface
153    * @param[in] window, the window to create the new surface on
154    * @param[in] display, the display
155    * @return true if the context was lost due to a change in display
156    *         between old surface and new surface
157    */
158   bool ReplaceSurfaceWindow( EGLNativeWindowType window, EGLNativeDisplayType display );
159
160   /**
161    * Replaces the render surface
162    * @param[in] pixmap, the pixmap to create the new surface on
163    * @param[in] display, the display
164    * @return true if the context was lost due to a change in x-display
165    *         between old surface and new surface
166    */
167   bool ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLNativeDisplayType display );
168
169   /**
170    * returns the display with which this object was initialized
171    * @return the EGL Display.
172    */
173   EGLDisplay GetDisplay() const;
174
175   /**
176    * Returns the EGL context
177    * @return the EGL context.
178    */
179   EGLContext GetContext() const;
180
181 private:
182
183   Vector<EGLint>       mContextAttribs;
184
185   EGLNativeDisplayType mEglNativeDisplay;
186   EGLNativeWindowType  mEglNativeWindow;
187   EGLNativePixmapType  mEglNativePixmap;
188
189   EGLDisplay           mEglDisplay;
190   EGLConfig            mEglConfig;
191   EGLContext           mEglContext;
192   EGLSurface           mEglSurface;
193
194   bool                 mGlesInitialized;
195   bool                 mIsOwnSurface;
196   SyncMode             mSyncMode;
197   bool                 mContextCurrent;
198   bool                 mIsWindow;
199   ColorDepth           mColorDepth;
200 };
201
202 } // namespace Adaptor
203
204 } // namespace Internal
205
206 } // namespace Dali
207
208 #endif // __DALI_INTERNAL_EGL_IMPLEMENTATION_H__