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