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