Merge "Redesigning render sync to handle reduced frequency" into 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    * Performs an OpenGL swap buffers command
109    */
110   virtual void SwapBuffers();
111
112   /**
113    * Performs an OpenGL copy buffers command
114    */
115   virtual void CopyBuffers();
116
117   /**
118    * Performs an EGL wait GL command
119    */
120   virtual void WaitGL();
121
122   /**
123    * Choose config of egl
124    * @param isWindowType whether the config for window or pixmap
125    * @param colorDepth Bit per pixel value (ex. 32 or 24)
126   */
127   void ChooseConfig( bool isWindowType, ColorDepth depth );
128
129   /**
130     * Create an OpenGL surface using a window
131     * @param window The window to create the surface on
132     * @param colorDepth Bit per pixel value (ex. 32 or 24)
133     * @return true on success, false on failure
134     */
135   void CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth );
136
137   /**
138    * Create the OpenGL surface using a pixmap
139    * @param pixmap The pixmap to create the surface on
140    * @param colorDepth Bit per pixel value (ex. 32 or 24)
141    * @return true on success, false on failure
142    */
143   void CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth );
144
145   /**
146    * Replaces the render surface
147    * @param[in] window, the window to create the new surface on
148    * @param[in] display, the display
149    * @return true if the context was lost due to a change in display
150    *         between old surface and new surface
151    */
152   bool ReplaceSurfaceWindow( EGLNativeWindowType window, EGLNativeDisplayType display );
153
154   /**
155    * Replaces the render surface
156    * @param[in] pixmap, the pixmap to create the new surface on
157    * @param[in] display, the display
158    * @return true if the context was lost due to a change in x-display
159    *         between old surface and new surface
160    */
161   bool ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLNativeDisplayType display );
162
163   /**
164    * returns the display with which this object was initialized
165    * @return the EGL Display.
166    */
167   EGLDisplay GetDisplay() const;
168
169   /**
170    * Returns the EGL context
171    * @return the EGL context.
172    */
173   EGLContext GetContext() const;
174
175 private:
176
177   Vector<EGLint>       mContextAttribs;
178
179   EGLNativeDisplayType mEglNativeDisplay;
180   EGLNativeWindowType  mEglNativeWindow;
181   EGLNativePixmapType  mEglNativePixmap;
182
183   EGLDisplay           mEglDisplay;
184   EGLConfig            mEglConfig;
185   EGLContext           mEglContext;
186   EGLSurface           mEglSurface;
187
188   bool                 mGlesInitialized;
189   bool                 mIsOwnSurface;
190   bool                 mContextCurrent;
191   bool                 mIsWindow;
192   ColorDepth           mColorDepth;
193 };
194
195 } // namespace Adaptor
196
197 } // namespace Internal
198
199 } // namespace Dali
200
201 #endif // __DALI_INTERNAL_EGL_IMPLEMENTATION_H__