1 #ifndef DALI_INTERNAL_EGL_IMPLEMENTATION_H
2 #define DALI_INTERNAL_EGL_IMPLEMENTATION_H
5 * Copyright (c) 2021 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/integration-api/core-enumerations.h>
26 #include <dali/internal/graphics/common/egl-include.h>
27 #include <dali/public-api/common/dali-vector.h>
28 #include <dali/public-api/common/vector-wrapper.h>
29 #include <dali/public-api/math/rect.h>
32 #include <dali/integration-api/adaptor-framework/egl-interface.h>
41 * EglImplementation class provides an EGL implementation.
43 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
51 * @param[in] partialUpdatedRequired Whether the partial update is required
53 EglImplementation(int multiSamplingLevel,
54 Integration::DepthBufferAvailable depthBufferRequired,
55 Integration::StencilBufferAvailable stencilBufferRequired,
56 Integration::PartialUpdateAvailable partialUpdateRequired);
61 ~EglImplementation() override;
65 * (Called from RenderSurface, not RenderThread, so not in i/f, hence, not virtual)
67 * @param display The display
68 * @param isOwnSurface whether the surface is own or not
69 * @return true on success, false on failure
71 bool InitializeGles(EGLNativeDisplayType display, bool isOwnSurface = true);
74 * Create the OpenGL context for the shared resource.
75 * @return true if successful
77 bool CreateContext() override;
80 * Create the OpenGL context for the window.
81 * @return true if successful
83 bool CreateWindowContext(EGLContext& mEglContext);
86 * Destroy the OpenGL context.
88 void DestroyContext(EGLContext& eglContext);
91 * Destroy the OpenGL surface.
93 void DestroySurface(EGLSurface& eglSurface);
96 * Make the OpenGL context current
98 void MakeContextCurrent(EGLSurface eglSurface, EGLContext eglContext) override;
101 * clear the OpenGL context
103 void MakeContextNull();
106 * @brief Make the OpenGL surface current
108 * @param pixmap The pixmap to replace the current surface
109 * @param eglSurface The eglSurface to replace the current OpenGL surface.
111 void MakeCurrent(EGLNativePixmapType pixmap, EGLSurface eglSurface);
116 void TerminateGles() override;
119 * Checks if GL is initialised
120 * @return true if it is
122 bool IsGlesInitialized() const;
125 * Performs an OpenGL swap buffers command
127 void SwapBuffers(EGLSurface& eglSurface) override;
130 * Gets current back buffer age
132 EGLint GetBufferAge(EGLSurface& eglSurface) const;
135 * Performs an OpenGL set damage command with damaged rects
137 void SetDamageRegion(EGLSurface& eglSurface, std::vector<Rect<int>>& damagedRects);
140 * Performs an OpenGL swap buffers command with damaged rects
142 virtual void SwapBuffers(EGLSurface& eglSurface, const std::vector<Rect<int>>& damagedRects);
145 * Performs an OpenGL copy buffers command
147 void CopyBuffers(EGLSurface& eglSurface) override;
150 * Performs an EGL wait GL command
152 void WaitGL() override;
155 * Choose config of egl
156 * @param isWindowType whether the config for window or pixmap
157 * @param colorDepth Bit per pixel value (ex. 32 or 24)
158 * @return true if the eglChooseConfig is succeed.
160 bool ChooseConfig(bool isWindowType, ColorDepth depth);
163 * Create an OpenGL surface using a window
164 * @param window The window to create the surface on
165 * @param colorDepth Bit per pixel value (ex. 32 or 24)
166 * @return Handle to an on-screen EGL window surface (the requester has an ownership of this egl surface)
168 EGLSurface CreateSurfaceWindow(EGLNativeWindowType window, ColorDepth depth);
171 * Create the OpenGL surface using a pixmap
172 * @param pixmap The pixmap to create the surface on
173 * @param colorDepth Bit per pixel value (ex. 32 or 24)
174 * @return Handle to an off-screen EGL pixmap surface (the requester has an ownership of this egl surface)
176 EGLSurface CreateSurfacePixmap(EGLNativePixmapType pixmap, ColorDepth depth);
179 * Replaces the render surface
180 * @param[in] window, the window to create the new surface on
181 * @return true if the context was lost due to a change in display
182 * between old surface and new surface
184 bool ReplaceSurfaceWindow(EGLNativeWindowType window, EGLSurface& eglSurface, EGLContext& eglContext);
187 * Replaces the render surface
188 * @param[in] pixmap, the pixmap to replace the new surface on
189 * @param[out] eglSurface, the eglSurface is created using a pixmap.
190 * @return true if the context was lost due to a change in x-display
191 * between old surface and new surface
193 bool ReplaceSurfacePixmap(EGLNativePixmapType pixmap, EGLSurface& eglSurface);
198 void SetGlesVersion(const int32_t glesVersion);
201 * Sets Whether the frame is the first after Resume.
203 void SetFirstFrameAfterResume();
206 * returns the display with which this object was initialized
207 * @return the EGL Display.
209 EGLDisplay GetDisplay() const;
212 * Returns the EGL context
213 * @return the EGL context.
215 EGLContext GetContext() const;
218 * Returns the gles version
219 * @return the gles version
221 int32_t GetGlesVersion() const;
224 * Returns whether the surfaceless context is supported
225 * @return true if the surfaceless context is supported
227 bool IsSurfacelessContextSupported() const;
230 * @brief Wait until all rendering calls for the currently context are executed
235 * @brief Returns whether the partial update is required.
236 * @return true if the partial update is required.
238 bool IsPartialUpdateRequired() const;
241 Vector<EGLint> mContextAttribs;
243 EGLNativeDisplayType mEglNativeDisplay;
245 EGLNativeWindowType mEglNativeWindow;
247 EGLNativePixmapType mCurrentEglNativePixmap;
249 EGLDisplay mEglDisplay;
250 EGLConfig mEglConfig;
251 EGLContext mEglContext; ///< The resource context holding assets such as textures to be shared
253 typedef std::vector<EGLContext> EglWindowContextContainer;
254 EglWindowContextContainer mEglWindowContexts; ///< The EGL context for the window
256 EGLSurface mCurrentEglSurface;
257 EGLContext mCurrentEglContext;
259 typedef std::vector<EGLSurface> EglWindowSurfaceContainer;
260 EglWindowSurfaceContainer mEglWindowSurfaces; ///< The EGL surface for the window
262 int32_t mMultiSamplingLevel;
263 int32_t mGlesVersion;
265 ColorDepth mColorDepth;
267 bool mGlesInitialized;
270 bool mDepthBufferRequired;
271 bool mStencilBufferRequired;
272 bool mPartialUpdateRequired;
273 bool mIsSurfacelessContextSupported;
274 bool mIsKhrCreateContextSupported;
276 uint32_t mSwapBufferCountAfterResume;
277 PFNEGLSETDAMAGEREGIONKHRPROC mEglSetDamageRegionKHR;
278 PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC mEglSwapBuffersWithDamageKHR;
281 } // namespace Adaptor
283 } // namespace Internal
287 #endif // DALI_INTERNAL_EGL_IMPLEMENTATION_H