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 virtual ~EglImplementation();
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 virtual bool CreateContext();
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 virtual void MakeContextCurrent( EGLSurface eglSurface, EGLContext eglContext );
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 virtual void TerminateGles();
122 * Checks if GL is initialised
123 * @return true if it is
125 bool IsGlesInitialized() const;
128 * Performs an OpenGL swap buffers command
130 virtual void SwapBuffers( EGLSurface& eglSurface );
133 * Gets current back buffer age
135 EGLint GetBufferAge( EGLSurface& eglSurface ) const;
138 * Gets if user set damaged areas
140 bool DamageAreasSet() const;
143 * Sets damaged areas, overrides auto calculated ones
145 void SetDamageAreas( std::vector<Dali::Rect<int>>& damagedArea );
148 * Forces full surface swap next frame, resets current partial update state.
150 void SetFullSwapNextFrame();
153 * Performs an OpenGL set damage command with damaged rects
155 virtual void SetDamage( EGLSurface& eglSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect );
158 * Performs an OpenGL swap buffers command with damaged rects
160 virtual void SwapBuffers( EGLSurface& eglSurface, const std::vector<Rect<int>>& damagedRects );
163 * Performs an OpenGL copy buffers command
165 virtual void CopyBuffers( EGLSurface& eglSurface );
168 * Performs an EGL wait GL command
170 virtual void WaitGL();
173 * Choose config of egl
174 * @param isWindowType whether the config for window or pixmap
175 * @param colorDepth Bit per pixel value (ex. 32 or 24)
176 * @return true if the eglChooseConfig is succeed.
178 bool ChooseConfig( bool isWindowType, ColorDepth depth );
181 * Create an OpenGL surface using a window
182 * @param window The window to create the surface on
183 * @param colorDepth Bit per pixel value (ex. 32 or 24)
184 * @return Handle to an on-screen EGL window surface (the requester has an ownership of this egl surface)
186 EGLSurface CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth );
189 * Create the OpenGL surface using a pixmap
190 * @param pixmap The pixmap to create the surface on
191 * @param colorDepth Bit per pixel value (ex. 32 or 24)
192 * @return Handle to an off-screen EGL pixmap surface (the requester has an ownership of this egl surface)
194 EGLSurface CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth );
197 * Replaces the render surface
198 * @param[in] window, the window to create the new surface on
199 * @return true if the context was lost due to a change in display
200 * between old surface and new surface
202 bool ReplaceSurfaceWindow( EGLNativeWindowType window, EGLSurface& eglSurface, EGLContext& eglContext );
205 * Replaces the render surface
206 * @param[in] pixmap, the pixmap to replace the new surface on
207 * @param[out] eglSurface, the eglSurface is created using a pixmap.
208 * @return true if the context was lost due to a change in x-display
209 * between old surface and new surface
211 bool ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLSurface& eglSurface );
216 void SetGlesVersion( const int32_t glesVersion );
219 * Sets Whether the frame is the first after Resume.
221 void SetFirstFrameAfterResume();
224 * returns the display with which this object was initialized
225 * @return the EGL Display.
227 EGLDisplay GetDisplay() const;
230 * Returns the EGL context
231 * @return the EGL context.
233 EGLContext GetContext() const;
236 * Returns the gles version
237 * @return the gles version
239 int32_t GetGlesVersion() const;
242 * Returns whether the surfaceless context is supported
243 * @return true if the surfaceless context is supported
245 bool IsSurfacelessContextSupported() const;
248 * @brief Wait until all rendering calls for the currently context are executed
254 Vector<EGLint> mContextAttribs;
256 EGLNativeDisplayType mEglNativeDisplay;
258 EGLNativeWindowType mEglNativeWindow;
260 EGLNativePixmapType mCurrentEglNativePixmap;
262 EGLDisplay mEglDisplay;
263 EGLConfig mEglConfig;
264 EGLContext mEglContext; ///< The resource context holding assets such as textures to be shared
266 typedef std::vector<EGLContext> EglWindowContextContainer;
267 EglWindowContextContainer mEglWindowContexts; ///< The EGL context for the window
269 EGLSurface mCurrentEglSurface;
270 EGLContext mCurrentEglContext;
272 typedef std::vector<EGLSurface> EglWindowSurfaceContainer;
273 EglWindowSurfaceContainer mEglWindowSurfaces; ///< The EGL surface for the window
275 int32_t mMultiSamplingLevel;
276 int32_t mGlesVersion;
278 ColorDepth mColorDepth;
280 bool mGlesInitialized;
283 bool mDepthBufferRequired;
284 bool mStencilBufferRequired;
285 bool mPartialUpdateRequired;
286 bool mIsSurfacelessContextSupported;
287 bool mIsKhrCreateContextSupported;
289 uint32_t mSwapBufferCountAfterResume;
290 PFNEGLSETDAMAGEREGIONKHRPROC mEglSetDamageRegionKHR;
291 PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC mEglSwapBuffersWithDamageKHR;
294 std::list<std::vector<Rect<int>>> mBufferDamagedRects;
295 std::vector<Rect<int>> mCombinedDamagedRects;
296 std::vector<Rect<int>> mDamagedAreas;
297 Rect<int> mSurfaceRect;
298 bool mFullSwapNextFrame;
301 } // namespace Adaptor
303 } // namespace Internal
307 #endif // DALI_INTERNAL_EGL_IMPLEMENTATION_H