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
51 * @param[in] partialUpdateAvailable Whether the partial update is available
53 EglImplementation( int multiSamplingLevel,
54 Integration::DepthBufferAvailable depthBufferRequired,
55 Integration::StencilBufferAvailable stencilBufferRequired,
56 Integration::PartialUpdateAvailable partialUpdateAvailable );
61 virtual ~EglImplementation();
66 * (Called from ECoreX::RenderSurface, not RenderThread, so not in i/f, hence, not virtual)
68 * @param display The display
69 * @param isOwnSurface whether the surface is own or not
70 * @return true on success, false on failure
72 bool InitializeGles( EGLNativeDisplayType display, bool isOwnSurface = true );
75 * Create the OpenGL context for the shared resource.
76 * @return true if successful
78 virtual bool CreateContext();
81 * Create the OpenGL context for the window.
82 * @return true if successful
84 bool CreateWindowContext( EGLContext& mEglContext );
87 * Destroy the OpenGL context.
89 void DestroyContext( EGLContext& eglContext );
92 * Destroy the OpenGL surface.
94 void DestroySurface( EGLSurface& eglSurface );
97 * Make the OpenGL context current
99 virtual void MakeContextCurrent( EGLSurface eglSurface, EGLContext eglContext );
102 * clear the OpenGL context
104 void MakeContextNull();
107 * @brief Make the OpenGL surface current
109 * @param pixmap The pixmap to replace the current surface
110 * @param eglSurface The eglSurface to replace the current OpenGL surface.
112 void MakeCurrent( EGLNativePixmapType pixmap, EGLSurface eglSurface );
117 virtual void TerminateGles();
120 * Checks if GL is initialised
121 * @return true if it is
123 bool IsGlesInitialized() const;
126 * Performs an OpenGL swap buffers command
128 virtual void SwapBuffers( EGLSurface& eglSurface );
131 * Get current buffer age
133 virtual int GetBufferAge( EGLSurface& eglSurface );
136 * Set Damaged rect for Partial update
138 virtual void SetDamagedRect( std::vector<int> damagedRectArray, EGLSurface& eglSurface );
141 * Performs an OpenGL copy buffers command
143 virtual void CopyBuffers( EGLSurface& eglSurface );
146 * Performs an EGL wait GL command
148 virtual void WaitGL();
151 * Choose config of egl
152 * @param isWindowType whether the config for window or pixmap
153 * @param colorDepth Bit per pixel value (ex. 32 or 24)
154 * @return true if the eglChooseConfig is succeed.
156 bool ChooseConfig( bool isWindowType, ColorDepth depth );
159 * Create an OpenGL surface using a window
160 * @param window The window to create the surface on
161 * @param colorDepth Bit per pixel value (ex. 32 or 24)
162 * @return Handle to an on-screen EGL window surface (the requester has an ownership of this egl surface)
164 EGLSurface CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth );
167 * Create the OpenGL surface using a pixmap
168 * @param pixmap The pixmap to create the surface on
169 * @param colorDepth Bit per pixel value (ex. 32 or 24)
170 * @return Handle to an off-screen EGL pixmap surface (the requester has an ownership of this egl surface)
172 EGLSurface CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth );
175 * Replaces the render surface
176 * @param[in] window, the window to create the new surface on
177 * @return true if the context was lost due to a change in display
178 * between old surface and new surface
180 bool ReplaceSurfaceWindow( EGLNativeWindowType window, EGLSurface& eglSurface, EGLContext& eglContext );
183 * Replaces the render surface
184 * @param[in] pixmap, the pixmap to replace the new surface on
185 * @param[out] eglSurface, the eglSurface is created using a pixmap.
186 * @return true if the context was lost due to a change in x-display
187 * between old surface and new surface
189 bool ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLSurface& eglSurface );
194 void SetGlesVersion( const int32_t glesVersion );
197 * Sets Whether the frame is the first after Resume.
199 void SetFirstFrameAfterResume();
202 * returns the display with which this object was initialized
203 * @return the EGL Display.
205 EGLDisplay GetDisplay() const;
208 * Returns the EGL context
209 * @return the EGL context.
211 EGLContext GetContext() const;
214 * Returns the gles version
215 * @return the gles version
217 int32_t GetGlesVersion() const;
220 * Returns whether the surfaceless context is supported
221 * @return true if the surfaceless context is supported
223 bool IsSurfacelessContextSupported() const;
226 * @brief Wait until all rendering calls for the currently context are executed
232 Vector<EGLint> mContextAttribs;
234 EGLNativeDisplayType mEglNativeDisplay;
236 EGLNativeWindowType mEglNativeWindow;
238 EGLNativePixmapType mCurrentEglNativePixmap;
240 EGLDisplay mEglDisplay;
241 EGLConfig mEglConfig;
242 EGLContext mEglContext; ///< The resource context holding assets such as textures to be shared
244 typedef std::vector<EGLContext> EglWindowContextContainer;
245 EglWindowContextContainer mEglWindowContexts; ///< The EGL context for the window
247 EGLSurface mCurrentEglSurface;
248 EGLContext mCurrentEglContext;
250 typedef std::vector<EGLSurface> EglWindowSurfaceContainer;
251 EglWindowSurfaceContainer mEglWindowSurfaces; ///< The EGL surface for the window
253 int32_t mMultiSamplingLevel;
254 int32_t mGlesVersion;
255 std::vector<int> mDamagedRectArray;
257 ColorDepth mColorDepth;
259 bool mGlesInitialized;
262 bool mDepthBufferRequired;
263 bool mStencilBufferRequired;
264 bool mIsSurfacelessContextSupported;
265 bool mIsKhrCreateContextSupported;
266 bool mIsFirstFrameAfterResume;
267 bool mIsKhrPartialUpdateSupported;
268 bool mPartialUpdateAvailable;
270 PFNEGLSETDAMAGEREGIONKHRPROC mEglSetDamageRegionKHR;
271 PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC mSwapBuffersWithDamage;
274 } // namespace Adaptor
276 } // namespace Internal
280 #endif // DALI_INTERNAL_EGL_IMPLEMENTATION_H