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