1 #ifndef DALI_INTERNAL_EGL_IMPLEMENTATION_H
2 #define DALI_INTERNAL_EGL_IMPLEMENTATION_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
29 #include <dali/integration-api/egl-interface.h>
40 * EglImplementation class provides an EGL implementation.
42 class EglImplementation : public EglInterface
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
52 EglImplementation( int multiSamplingLevel,
53 Integration::DepthBufferAvailable depthBufferRequired,
54 Integration::StencilBufferAvailable stencilBufferRequired );
59 virtual ~EglImplementation();
64 * (Called from ECoreX::RenderSurface, not RenderThread, so not in i/f, hence, not virtual)
66 * @param display The display
67 * @param isOwnSurface whether the surface is own or not
68 * @return true on success, false on failure
70 bool InitializeGles( EGLNativeDisplayType display, bool isOwnSurface = true );
73 * Create the OpenGL context for the shared resource.
74 * @return true if successful
76 virtual bool CreateContext();
79 * Create the OpenGL context for the window.
80 * @return true if successful
82 bool CreateWindowContext( EGLContext& mEglContext );
85 * Destroy the OpenGL context.
87 void DestroyContext( EGLContext& eglContext );
90 * Destroy the OpenGL surface.
92 void DestroySurface( EGLSurface& eglSurface );
95 * Make the OpenGL context current
97 virtual void MakeContextCurrent( EGLSurface eglSurface, EGLContext eglContext );
100 * clear the OpenGL context
102 void MakeContextNull();
105 * @brief Make the OpenGL surface current
107 * @param pixmap The pixmap to replace the current surface
108 * @param eglSurface The eglSurface to replace the current OpenGL surface.
110 void MakeCurrent( EGLNativePixmapType pixmap, EGLSurface eglSurface );
115 virtual void TerminateGles();
118 * Checks if GL is initialised
119 * @return true if it is
121 bool IsGlesInitialized() const;
124 * Performs an OpenGL swap buffers command
126 virtual void SwapBuffers( EGLSurface& eglSurface );
129 * Performs an OpenGL copy buffers command
131 virtual void CopyBuffers( EGLSurface& eglSurface );
134 * Performs an EGL wait GL command
136 virtual void WaitGL();
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 * @return true if the eglChooseConfig is succeed.
144 bool ChooseConfig( bool isWindowType, ColorDepth depth );
147 * Create an OpenGL surface using a window
148 * @param window The window to create the surface on
149 * @param colorDepth Bit per pixel value (ex. 32 or 24)
150 * @return Handle to an on-screen EGL window surface (the requester has an ownership of this egl surface)
152 EGLSurface CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth );
155 * Create the OpenGL surface using a pixmap
156 * @param pixmap The pixmap to create the surface on
157 * @param colorDepth Bit per pixel value (ex. 32 or 24)
158 * @return Handle to an off-screen EGL pixmap surface (the requester has an ownership of this egl surface)
160 EGLSurface CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth );
163 * Replaces the render surface
164 * @param[in] window, the window to create the new surface on
165 * @return true if the context was lost due to a change in display
166 * between old surface and new surface
168 bool ReplaceSurfaceWindow( EGLNativeWindowType window, EGLSurface& eglSurface, EGLContext& eglContext );
171 * Replaces the render surface
172 * @param[in] pixmap, the pixmap to replace the new surface on
173 * @param[out] eglSurface, the eglSurface is created using a pixmap.
174 * @return true if the context was lost due to a change in x-display
175 * between old surface and new surface
177 bool ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLSurface& eglSurface );
182 void SetGlesVersion( const int32_t glesVersion );
185 * returns the display with which this object was initialized
186 * @return the EGL Display.
188 EGLDisplay GetDisplay() const;
191 * Returns the EGL context
192 * @return the EGL context.
194 EGLContext GetContext() const;
197 * Returns the gles version
198 * @return the gles version
200 int32_t GetGlesVersion() const;
203 * Returns whether the surfaceless context is supported
204 * @return true if the surfaceless context is supported
206 bool IsSurfacelessContextSupported() const;
210 Vector<EGLint> mContextAttribs;
212 EGLNativeDisplayType mEglNativeDisplay;
214 EGLNativeWindowType mEglNativeWindow;
216 EGLNativePixmapType mCurrentEglNativePixmap;
218 EGLDisplay mEglDisplay;
219 EGLConfig mEglConfig;
220 EGLContext mEglContext; ///< The resource context holding assets such as textures to be shared
222 typedef std::vector<EGLContext> EglWindowContextContainer;
223 EglWindowContextContainer mEglWindowContexts; ///< The EGL context for the window
225 EGLSurface mCurrentEglSurface;
226 EGLContext mCurrentEglContext;
228 typedef std::vector<EGLSurface> EglWindowSurfaceContainer;
229 EglWindowSurfaceContainer mEglWindowSurfaces; ///< The EGL surface for the window
231 int32_t mMultiSamplingLevel;
232 int32_t mGlesVersion;
234 ColorDepth mColorDepth;
236 bool mGlesInitialized;
239 bool mDepthBufferRequired;
240 bool mStencilBufferRequired;
241 bool mIsSurfacelessContextSupported;
242 bool mIsKhrCreateContextSupported;
245 } // namespace Adaptor
247 } // namespace Internal
251 #endif // DALI_INTERNAL_EGL_IMPLEMENTATION_H