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/public-api/common/list-wrapper.h>
23 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/internal/graphics/common/egl-include.h>
26 #include <dali/public-api/common/dali-vector.h>
27 #include <dali/public-api/common/vector-wrapper.h>
28 #include <dali/public-api/math/rect.h>
29 #include <dali/integration-api/core-enumerations.h>
32 #include <dali/integration-api/adaptor-framework/egl-interface.h>
42 * EglImplementation class provides an EGL implementation.
44 class EglImplementation : public EglInterface
50 * @param[in] multiSamplingLevel The Multi-sampling level required
51 * @param[in] depthBufferRequired Whether the depth buffer is required
52 * @param[in] stencilBufferRequired Whether the stencil buffer is required
53 * @param[in] partialUpdatedRequired Whether the partial update is required
55 EglImplementation( int multiSamplingLevel,
56 Integration::DepthBufferAvailable depthBufferRequired,
57 Integration::StencilBufferAvailable stencilBufferRequired,
58 Integration::PartialUpdateAvailable partialUpdateRequired );
63 ~EglImplementation() override;
68 * (Called from ECoreX::RenderSurface, not RenderThread, so not in i/f, hence, not virtual)
70 * @param display The display
71 * @param isOwnSurface whether the surface is own or not
72 * @return true on success, false on failure
74 bool InitializeGles( EGLNativeDisplayType display, bool isOwnSurface = true );
77 * Create the OpenGL context for the shared resource.
78 * @return true if successful
80 bool CreateContext() override;
83 * Create the OpenGL context for the window.
84 * @return true if successful
86 bool CreateWindowContext( EGLContext& mEglContext );
89 * Destroy the OpenGL context.
91 void DestroyContext( EGLContext& eglContext );
94 * Destroy the OpenGL surface.
96 void DestroySurface( EGLSurface& eglSurface );
99 * Make the OpenGL context current
101 void MakeContextCurrent( EGLSurface eglSurface, EGLContext eglContext ) override;
104 * clear the OpenGL context
106 void MakeContextNull();
109 * @brief Make the OpenGL surface current
111 * @param pixmap The pixmap to replace the current surface
112 * @param eglSurface The eglSurface to replace the current OpenGL surface.
114 void MakeCurrent( EGLNativePixmapType pixmap, EGLSurface eglSurface );
119 void TerminateGles() override;
122 * Checks if GL is initialised
123 * @return true if it is
125 bool IsGlesInitialized() const;
128 * Performs an OpenGL swap buffers command
130 void SwapBuffers( EGLSurface& eglSurface ) override;
133 * Gets current back buffer age
135 EGLint GetBufferAge( EGLSurface& eglSurface ) const;
138 * Performs an OpenGL set damage command with damaged rects
140 void SetDamageRegion( EGLSurface& eglSurface, std::vector< Rect< int > >& damagedRects );
143 * Performs an OpenGL swap buffers command with damaged rects
145 virtual void SwapBuffers( EGLSurface& eglSurface, const std::vector<Rect<int>>& damagedRects );
148 * Performs an OpenGL copy buffers command
150 void CopyBuffers( EGLSurface& eglSurface ) override;
153 * Performs an EGL wait GL command
155 void WaitGL() override;
158 * Choose config of egl
159 * @param isWindowType whether the config for window or pixmap
160 * @param colorDepth Bit per pixel value (ex. 32 or 24)
161 * @return true if the eglChooseConfig is succeed.
163 bool ChooseConfig( bool isWindowType, ColorDepth depth );
166 * Create an OpenGL surface using a window
167 * @param window The window to create the surface on
168 * @param colorDepth Bit per pixel value (ex. 32 or 24)
169 * @return Handle to an on-screen EGL window surface (the requester has an ownership of this egl surface)
171 EGLSurface CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth );
174 * Create the OpenGL surface using a pixmap
175 * @param pixmap The pixmap to create the surface on
176 * @param colorDepth Bit per pixel value (ex. 32 or 24)
177 * @return Handle to an off-screen EGL pixmap surface (the requester has an ownership of this egl surface)
179 EGLSurface CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth );
182 * Replaces the render surface
183 * @param[in] window, the window to create the new surface on
184 * @return true if the context was lost due to a change in display
185 * between old surface and new surface
187 bool ReplaceSurfaceWindow( EGLNativeWindowType window, EGLSurface& eglSurface, EGLContext& eglContext );
190 * Replaces the render surface
191 * @param[in] pixmap, the pixmap to replace the new surface on
192 * @param[out] eglSurface, the eglSurface is created using a pixmap.
193 * @return true if the context was lost due to a change in x-display
194 * between old surface and new surface
196 bool ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLSurface& eglSurface );
201 void SetGlesVersion( const int32_t glesVersion );
204 * Sets Whether the frame is the first after Resume.
206 void SetFirstFrameAfterResume();
209 * returns the display with which this object was initialized
210 * @return the EGL Display.
212 EGLDisplay GetDisplay() const;
215 * Returns the EGL context
216 * @return the EGL context.
218 EGLContext GetContext() const;
221 * Returns the gles version
222 * @return the gles version
224 int32_t GetGlesVersion() const;
227 * Returns whether the surfaceless context is supported
228 * @return true if the surfaceless context is supported
230 bool IsSurfacelessContextSupported() const;
233 * @brief Wait until all rendering calls for the currently context are executed
238 * @brief Returns whether the partial update is required.
239 * @return true if the partial update is required.
241 bool IsPartialUpdateRequired() const;
245 Vector<EGLint> mContextAttribs;
247 EGLNativeDisplayType mEglNativeDisplay;
249 EGLNativeWindowType mEglNativeWindow;
251 EGLNativePixmapType mCurrentEglNativePixmap;
253 EGLDisplay mEglDisplay;
254 EGLConfig mEglConfig;
255 EGLContext mEglContext; ///< The resource context holding assets such as textures to be shared
257 typedef std::vector<EGLContext> EglWindowContextContainer;
258 EglWindowContextContainer mEglWindowContexts; ///< The EGL context for the window
260 EGLSurface mCurrentEglSurface;
261 EGLContext mCurrentEglContext;
263 typedef std::vector<EGLSurface> EglWindowSurfaceContainer;
264 EglWindowSurfaceContainer mEglWindowSurfaces; ///< The EGL surface for the window
266 int32_t mMultiSamplingLevel;
267 int32_t mGlesVersion;
269 ColorDepth mColorDepth;
271 bool mGlesInitialized;
274 bool mDepthBufferRequired;
275 bool mStencilBufferRequired;
276 bool mPartialUpdateRequired;
277 bool mIsSurfacelessContextSupported;
278 bool mIsKhrCreateContextSupported;
280 uint32_t mSwapBufferCountAfterResume;
281 PFNEGLSETDAMAGEREGIONKHRPROC mEglSetDamageRegionKHR;
282 PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC mEglSwapBuffersWithDamageKHR;
286 } // namespace Adaptor
288 } // namespace Internal
292 #endif // DALI_INTERNAL_EGL_IMPLEMENTATION_H