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/adaptor-framework/egl-interface.h>
39 * EglImplementation class provides an EGL implementation.
41 class EglImplementation : public EglInterface
47 * @param[in] multiSamplingLevel The Multi-sampling level required
48 * @param[in] depthBufferRequired Whether the depth buffer is required
49 * @param[in] stencilBufferRequired Whether the stencil buffer is required
50 * @param[in] partialUpdateAvailable Whether the partial update is available
52 EglImplementation( int multiSamplingLevel,
53 Integration::DepthBufferAvailable depthBufferRequired,
54 Integration::StencilBufferAvailable stencilBufferRequired,
55 Integration::PartialUpdateAvailable partialUpdateAvailable );
60 virtual ~EglImplementation();
65 * (Called from ECoreX::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 virtual bool CreateContext();
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 virtual void MakeContextCurrent( EGLSurface eglSurface, EGLContext eglContext );
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 virtual void TerminateGles();
119 * Checks if GL is initialised
120 * @return true if it is
122 bool IsGlesInitialized() const;
125 * Performs an OpenGL swap buffers command
127 virtual void SwapBuffers( EGLSurface& eglSurface );
130 * Get current buffer age
132 virtual int GetBufferAge( EGLSurface& eglSurface );
135 * Set Damaged rect for Partial update
137 virtual void SetDamagedRect( std::vector<int> damagedRectArray, EGLSurface& eglSurface );
140 * Performs an OpenGL copy buffers command
142 virtual void CopyBuffers( EGLSurface& eglSurface );
145 * Performs an EGL wait GL command
147 virtual void WaitGL();
150 * Choose config of egl
151 * @param isWindowType whether the config for window or pixmap
152 * @param colorDepth Bit per pixel value (ex. 32 or 24)
153 * @return true if the eglChooseConfig is succeed.
155 bool ChooseConfig( bool isWindowType, ColorDepth depth );
158 * Create an OpenGL surface using a window
159 * @param window The window to create the surface on
160 * @param colorDepth Bit per pixel value (ex. 32 or 24)
161 * @return Handle to an on-screen EGL window surface (the requester has an ownership of this egl surface)
163 EGLSurface CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth );
166 * Create the OpenGL surface using a pixmap
167 * @param pixmap The pixmap to create the surface on
168 * @param colorDepth Bit per pixel value (ex. 32 or 24)
169 * @return Handle to an off-screen EGL pixmap surface (the requester has an ownership of this egl surface)
171 EGLSurface CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth );
174 * Replaces the render surface
175 * @param[in] window, the window to create the new surface on
176 * @return true if the context was lost due to a change in display
177 * between old surface and new surface
179 bool ReplaceSurfaceWindow( EGLNativeWindowType window, EGLSurface& eglSurface, EGLContext& eglContext );
182 * Replaces the render surface
183 * @param[in] pixmap, the pixmap to replace the new surface on
184 * @param[out] eglSurface, the eglSurface is created using a pixmap.
185 * @return true if the context was lost due to a change in x-display
186 * between old surface and new surface
188 bool ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLSurface& eglSurface );
193 void SetGlesVersion( const int32_t glesVersion );
196 * Sets Whether the frame is the first after Resume.
198 void SetFirstFrameAfterResume();
201 * returns the display with which this object was initialized
202 * @return the EGL Display.
204 EGLDisplay GetDisplay() const;
207 * Returns the EGL context
208 * @return the EGL context.
210 EGLContext GetContext() const;
213 * Returns the gles version
214 * @return the gles version
216 int32_t GetGlesVersion() const;
219 * Returns whether the surfaceless context is supported
220 * @return true if the surfaceless context is supported
222 bool IsSurfacelessContextSupported() const;
225 * @brief Wait until all rendering calls for the currently context are executed
231 Vector<EGLint> mContextAttribs;
233 EGLNativeDisplayType mEglNativeDisplay;
235 EGLNativeWindowType mEglNativeWindow;
237 EGLNativePixmapType mCurrentEglNativePixmap;
239 EGLDisplay mEglDisplay;
240 EGLConfig mEglConfig;
241 EGLContext mEglContext; ///< The resource context holding assets such as textures to be shared
243 typedef std::vector<EGLContext> EglWindowContextContainer;
244 EglWindowContextContainer mEglWindowContexts; ///< The EGL context for the window
246 EGLSurface mCurrentEglSurface;
247 EGLContext mCurrentEglContext;
249 typedef std::vector<EGLSurface> EglWindowSurfaceContainer;
250 EglWindowSurfaceContainer mEglWindowSurfaces; ///< The EGL surface for the window
252 int32_t mMultiSamplingLevel;
253 int32_t mGlesVersion;
254 std::vector<int> mDamagedRectArray;
256 ColorDepth mColorDepth;
258 bool mGlesInitialized;
261 bool mDepthBufferRequired;
262 bool mStencilBufferRequired;
263 bool mIsSurfacelessContextSupported;
264 bool mIsKhrCreateContextSupported;
265 uint32_t mSwapBufferCountAfterResume;
266 bool mIsKhrPartialUpdateSupported;
267 bool mPartialUpdateAvailable;
269 PFNEGLSETDAMAGEREGIONKHRPROC mEglSetDamageRegionKHR;
270 PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC mSwapBuffersWithDamage;
273 } // namespace Adaptor
275 } // namespace Internal
279 #endif // DALI_INTERNAL_EGL_IMPLEMENTATION_H