efb9754cdfb63d35808a7203f1436248c850cf7e
[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) 2019 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 <dali/internal/graphics/common/egl-include.h>
23 #include <dali/public-api/common/dali-vector.h>
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/integration-api/core-enumerations.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/integration-api/adaptor-framework/egl-interface.h>
29
30 namespace Dali
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   /**
45    * Constructor
46    * @param[in] multiSamplingLevel The Multi-sampling level required
47    * @param[in] depthBufferRequired Whether the depth buffer is required
48    * @param[in] stencilBufferRequired Whether the stencil buffer is required
49    */
50   EglImplementation( int multiSamplingLevel,
51                      Integration::DepthBufferAvailable depthBufferRequired,
52                      Integration::StencilBufferAvailable stencilBufferRequired );
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 for the shared resource.
72     * @return true if successful
73     */
74   virtual bool CreateContext();
75
76   /**
77     * Create the OpenGL context for the window.
78     * @return true if successful
79     */
80   bool CreateWindowContext( EGLContext& mEglContext );
81
82   /**
83     * Destroy the OpenGL context.
84     */
85   void DestroyContext( EGLContext& eglContext );
86
87   /**
88     * Destroy the OpenGL surface.
89     */
90   void DestroySurface( EGLSurface& eglSurface );
91
92   /**
93    * Make the OpenGL context current
94    */
95   virtual void MakeContextCurrent( EGLSurface eglSurface, EGLContext eglContext );
96
97   /**
98    * clear the OpenGL context
99    */
100   void MakeContextNull();
101
102   /**
103    * @brief Make the OpenGL surface current
104    *
105    * @param pixmap The pixmap to replace the current surface
106    * @param eglSurface The eglSurface to replace the current OpenGL surface.
107    */
108   void MakeCurrent( EGLNativePixmapType pixmap, EGLSurface eglSurface );
109
110   /**
111    * Terminate GL
112    */
113   virtual void TerminateGles();
114
115   /**
116    * Checks if GL is initialised
117    * @return true if it is
118    */
119   bool IsGlesInitialized() const;
120
121   /**
122    * Performs an OpenGL swap buffers command
123    */
124   virtual void SwapBuffers( EGLSurface& eglSurface );
125
126   /**
127    * Performs an OpenGL copy buffers command
128    */
129   virtual void CopyBuffers( EGLSurface& eglSurface );
130
131   /**
132    * Performs an EGL wait GL command
133    */
134   virtual void WaitGL();
135
136   /**
137    * Choose config of egl
138    * @param isWindowType whether the config for window or pixmap
139    * @param colorDepth Bit per pixel value (ex. 32 or 24)
140    * @return true if the eglChooseConfig is succeed.
141   */
142   bool ChooseConfig( bool isWindowType, ColorDepth depth );
143
144   /**
145     * Create an OpenGL surface using a window
146     * @param window The window to create the surface on
147     * @param colorDepth Bit per pixel value (ex. 32 or 24)
148     * @return Handle to an on-screen EGL window surface (the requester has an ownership of this egl surface)
149     */
150   EGLSurface CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth );
151
152   /**
153    * Create the OpenGL surface using a pixmap
154    * @param pixmap The pixmap to create the surface on
155    * @param colorDepth Bit per pixel value (ex. 32 or 24)
156    * @return Handle to an off-screen EGL pixmap surface (the requester has an ownership of this egl surface)
157    */
158   EGLSurface CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth );
159
160   /**
161    * Replaces the render surface
162    * @param[in] window, the window to create the new surface on
163    * @return true if the context was lost due to a change in display
164    *         between old surface and new surface
165    */
166   bool ReplaceSurfaceWindow( EGLNativeWindowType window, EGLSurface& eglSurface, EGLContext& eglContext );
167
168   /**
169    * Replaces the render surface
170    * @param[in] pixmap, the pixmap to replace the new surface on
171    * @param[out] eglSurface, the eglSurface is created using a pixmap.
172    * @return true if the context was lost due to a change in x-display
173    *         between old surface and new surface
174    */
175   bool ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLSurface& eglSurface );
176
177   /**
178    * Sets gles version
179    */
180   void SetGlesVersion( const int32_t glesVersion );
181
182   /**
183    * Sets Whether the frame is the first after Resume.
184    */
185   void SetFirstFrameAfterResume();
186
187   /**
188    * returns the display with which this object was initialized
189    * @return the EGL Display.
190    */
191   EGLDisplay GetDisplay() const;
192
193   /**
194    * Returns the EGL context
195    * @return the EGL context.
196    */
197   EGLContext GetContext() const;
198
199   /**
200    * Returns the gles version
201    * @return the gles version
202    */
203   int32_t GetGlesVersion() const;
204
205   /**
206    * Returns whether the surfaceless context is supported
207    * @return true if the surfaceless context is supported
208    */
209   bool IsSurfacelessContextSupported() const;
210
211   /**
212    * @brief Wait until all rendering calls for the currently context are executed
213    */
214   void WaitClient();
215
216 private:
217
218   Vector<EGLint>       mContextAttribs;
219
220   EGLNativeDisplayType mEglNativeDisplay;
221
222   EGLNativeWindowType  mEglNativeWindow;
223
224   EGLNativePixmapType  mCurrentEglNativePixmap;
225
226   EGLDisplay           mEglDisplay;
227   EGLConfig            mEglConfig;
228   EGLContext           mEglContext;                            ///< The resource context holding assets such as textures to be shared
229
230   typedef std::vector<EGLContext> EglWindowContextContainer;
231   EglWindowContextContainer mEglWindowContexts;                ///< The EGL context for the window
232
233   EGLSurface           mCurrentEglSurface;
234   EGLContext           mCurrentEglContext;
235
236   typedef std::vector<EGLSurface> EglWindowSurfaceContainer;
237   EglWindowSurfaceContainer mEglWindowSurfaces;                ///< The EGL surface for the window
238
239   int32_t              mMultiSamplingLevel;
240   int32_t              mGlesVersion;
241
242   ColorDepth           mColorDepth;
243
244   bool                 mGlesInitialized;
245   bool                 mIsOwnSurface;
246   bool                 mIsWindow;
247   bool                 mDepthBufferRequired;
248   bool                 mStencilBufferRequired;
249   bool                 mIsSurfacelessContextSupported;
250   bool                 mIsKhrCreateContextSupported;
251
252   uint32_t              mSwapBufferCountAfterResume;
253 };
254
255 } // namespace Adaptor
256
257 } // namespace Internal
258
259 } // namespace Dali
260
261 #endif // DALI_INTERNAL_EGL_IMPLEMENTATION_H