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.
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>
28 #include <dali/integration-api/adaptor-framework/egl-interface.h>
38 * EglImplementation class provides an EGL implementation.
40 class EglImplementation : public EglInterface
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
50 EglImplementation( int multiSamplingLevel,
51 Integration::DepthBufferAvailable depthBufferRequired,
52 Integration::StencilBufferAvailable stencilBufferRequired );
57 virtual ~EglImplementation();
62 * (Called from ECoreX::RenderSurface, not RenderThread, so not in i/f, hence, not virtual)
64 * @param display The display
65 * @param isOwnSurface whether the surface is own or not
66 * @return true on success, false on failure
68 bool InitializeGles( EGLNativeDisplayType display, bool isOwnSurface = true );
71 * Create the OpenGL context for the shared resource.
72 * @return true if successful
74 virtual bool CreateContext();
77 * Create the OpenGL context for the window.
78 * @return true if successful
80 bool CreateWindowContext( EGLContext& mEglContext );
83 * Destroy the OpenGL context.
85 void DestroyContext( EGLContext& eglContext );
88 * Destroy the OpenGL surface.
90 void DestroySurface( EGLSurface& eglSurface );
93 * Make the OpenGL context current
95 virtual void MakeContextCurrent( EGLSurface eglSurface, EGLContext eglContext );
98 * clear the OpenGL context
100 void MakeContextNull();
103 * @brief Make the OpenGL surface current
105 * @param pixmap The pixmap to replace the current surface
106 * @param eglSurface The eglSurface to replace the current OpenGL surface.
108 void MakeCurrent( EGLNativePixmapType pixmap, EGLSurface eglSurface );
113 virtual void TerminateGles();
116 * Checks if GL is initialised
117 * @return true if it is
119 bool IsGlesInitialized() const;
122 * Performs an OpenGL swap buffers command
124 virtual void SwapBuffers( EGLSurface& eglSurface );
127 * Performs an OpenGL copy buffers command
129 virtual void CopyBuffers( EGLSurface& eglSurface );
132 * Performs an EGL wait GL command
134 virtual void WaitGL();
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.
142 bool ChooseConfig( bool isWindowType, ColorDepth depth );
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)
150 EGLSurface CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth );
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)
158 EGLSurface CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth );
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
166 bool ReplaceSurfaceWindow( EGLNativeWindowType window, EGLSurface& eglSurface, EGLContext& eglContext );
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
175 bool ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLSurface& eglSurface );
180 void SetGlesVersion( const int32_t glesVersion );
183 * Sets Whether the frame is the first after Resume.
185 void SetFirstFrameAfterResume();
188 * returns the display with which this object was initialized
189 * @return the EGL Display.
191 EGLDisplay GetDisplay() const;
194 * Returns the EGL context
195 * @return the EGL context.
197 EGLContext GetContext() const;
200 * Returns the gles version
201 * @return the gles version
203 int32_t GetGlesVersion() const;
206 * Returns whether the surfaceless context is supported
207 * @return true if the surfaceless context is supported
209 bool IsSurfacelessContextSupported() const;
212 * @brief Wait until all rendering calls for the currently context are executed
218 Vector<EGLint> mContextAttribs;
220 EGLNativeDisplayType mEglNativeDisplay;
222 EGLNativeWindowType mEglNativeWindow;
224 EGLNativePixmapType mCurrentEglNativePixmap;
226 EGLDisplay mEglDisplay;
227 EGLConfig mEglConfig;
228 EGLContext mEglContext; ///< The resource context holding assets such as textures to be shared
230 typedef std::vector<EGLContext> EglWindowContextContainer;
231 EglWindowContextContainer mEglWindowContexts; ///< The EGL context for the window
233 EGLSurface mCurrentEglSurface;
234 EGLContext mCurrentEglContext;
236 typedef std::vector<EGLSurface> EglWindowSurfaceContainer;
237 EglWindowSurfaceContainer mEglWindowSurfaces; ///< The EGL surface for the window
239 int32_t mMultiSamplingLevel;
240 int32_t mGlesVersion;
242 ColorDepth mColorDepth;
244 bool mGlesInitialized;
247 bool mDepthBufferRequired;
248 bool mStencilBufferRequired;
249 bool mIsSurfacelessContextSupported;
250 bool mIsKhrCreateContextSupported;
252 uint32_t mSwapBufferCountAfterResume;
255 } // namespace Adaptor
257 } // namespace Internal
261 #endif // DALI_INTERNAL_EGL_IMPLEMENTATION_H