eac50562d0bb54c92bbe191be4d8b34c7c33c484
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles / egl-implementation.h
1 #ifndef DALI_INTERNAL_EGL_IMPLEMENTATION_H
2 #define DALI_INTERNAL_EGL_IMPLEMENTATION_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <EGL/egl.h>
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>
27
28 // INTERNAL INCLUDES
29 #include <dali/integration-api/adaptor-framework/egl-interface.h>
30
31 namespace Dali
32 {
33 namespace Internal
34 {
35 namespace Adaptor
36 {
37
38 /**
39  * EglImplementation class provides an EGL implementation.
40  */
41 class EglImplementation : public EglInterface
42 {
43 public:
44
45   /**
46    * Constructor
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
51    */
52   EglImplementation( int multiSamplingLevel,
53                      Integration::DepthBufferAvailable depthBufferRequired,
54                      Integration::StencilBufferAvailable stencilBufferRequired,
55                      Integration::PartialUpdateAvailable partialUpdateAvailable );
56
57   /**
58    * Destructor
59    */
60   virtual ~EglImplementation();
61
62 public:
63
64   /**
65    * (Called from  ECoreX::RenderSurface, not RenderThread, so not in i/f, hence, not virtual)
66    * Initialize GL
67    * @param display The display
68    * @param isOwnSurface whether the surface is own or not
69    * @return true on success, false on failure
70    */
71   bool InitializeGles( EGLNativeDisplayType display, bool isOwnSurface = true );
72
73   /**
74     * Create the OpenGL context for the shared resource.
75     * @return true if successful
76     */
77   virtual bool CreateContext();
78
79   /**
80     * Create the OpenGL context for the window.
81     * @return true if successful
82     */
83   bool CreateWindowContext( EGLContext& mEglContext );
84
85   /**
86     * Destroy the OpenGL context.
87     */
88   void DestroyContext( EGLContext& eglContext );
89
90   /**
91     * Destroy the OpenGL surface.
92     */
93   void DestroySurface( EGLSurface& eglSurface );
94
95   /**
96    * Make the OpenGL context current
97    */
98   virtual void MakeContextCurrent( EGLSurface eglSurface, EGLContext eglContext );
99
100   /**
101    * clear the OpenGL context
102    */
103   void MakeContextNull();
104
105   /**
106    * @brief Make the OpenGL surface current
107    *
108    * @param pixmap The pixmap to replace the current surface
109    * @param eglSurface The eglSurface to replace the current OpenGL surface.
110    */
111   void MakeCurrent( EGLNativePixmapType pixmap, EGLSurface eglSurface );
112
113   /**
114    * Terminate GL
115    */
116   virtual void TerminateGles();
117
118   /**
119    * Checks if GL is initialised
120    * @return true if it is
121    */
122   bool IsGlesInitialized() const;
123
124   /**
125    * Performs an OpenGL swap buffers command
126    */
127   virtual void SwapBuffers( EGLSurface& eglSurface );
128
129  /**
130   * Get current buffer age
131   */
132   virtual int GetBufferAge( EGLSurface& eglSurface );
133
134   /**
135    * Set Damaged rect for Partial update
136   */
137   virtual void SetDamagedRect( std::vector<int> damagedRectArray, EGLSurface& eglSurface );
138
139   /**
140    * Performs an OpenGL copy buffers command
141    */
142   virtual void CopyBuffers( EGLSurface& eglSurface );
143
144   /**
145    * Performs an EGL wait GL command
146    */
147   virtual void WaitGL();
148
149   /**
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.
154   */
155   bool ChooseConfig( bool isWindowType, ColorDepth depth );
156
157   /**
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)
162     */
163   EGLSurface CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth );
164
165   /**
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)
170    */
171   EGLSurface CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth );
172
173   /**
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
178    */
179   bool ReplaceSurfaceWindow( EGLNativeWindowType window, EGLSurface& eglSurface, EGLContext& eglContext );
180
181   /**
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
187    */
188   bool ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLSurface& eglSurface );
189
190   /**
191    * Sets gles version
192    */
193   void SetGlesVersion( const int32_t glesVersion );
194
195   /**
196    * Sets Whether the frame is the first after Resume.
197    */
198   void SetFirstFrameAfterResume();
199
200   /**
201    * returns the display with which this object was initialized
202    * @return the EGL Display.
203    */
204   EGLDisplay GetDisplay() const;
205
206   /**
207    * Returns the EGL context
208    * @return the EGL context.
209    */
210   EGLContext GetContext() const;
211
212   /**
213    * Returns the gles version
214    * @return the gles version
215    */
216   int32_t GetGlesVersion() const;
217
218   /**
219    * Returns whether the surfaceless context is supported
220    * @return true if the surfaceless context is supported
221    */
222   bool IsSurfacelessContextSupported() const;
223
224   /**
225    * @brief Wait until all rendering calls for the currently context are executed
226    */
227   void WaitClient();
228
229 private:
230
231   Vector<EGLint>       mContextAttribs;
232
233   EGLNativeDisplayType mEglNativeDisplay;
234
235   EGLNativeWindowType  mEglNativeWindow;
236
237   EGLNativePixmapType  mCurrentEglNativePixmap;
238
239   EGLDisplay           mEglDisplay;
240   EGLConfig            mEglConfig;
241   EGLContext           mEglContext;                            ///< The resource context holding assets such as textures to be shared
242
243   typedef std::vector<EGLContext> EglWindowContextContainer;
244   EglWindowContextContainer mEglWindowContexts;                ///< The EGL context for the window
245
246   EGLSurface           mCurrentEglSurface;
247   EGLContext           mCurrentEglContext;
248
249   typedef std::vector<EGLSurface> EglWindowSurfaceContainer;
250   EglWindowSurfaceContainer mEglWindowSurfaces;                ///< The EGL surface for the window
251
252   int32_t              mMultiSamplingLevel;
253   int32_t              mGlesVersion;
254   std::vector<int>     mDamagedRectArray;
255
256   ColorDepth           mColorDepth;
257
258   bool                 mGlesInitialized;
259   bool                 mIsOwnSurface;
260   bool                 mIsWindow;
261   bool                 mDepthBufferRequired;
262   bool                 mStencilBufferRequired;
263   bool                 mIsSurfacelessContextSupported;
264   bool                 mIsKhrCreateContextSupported;
265   uint32_t             mSwapBufferCountAfterResume;
266   bool                 mIsKhrPartialUpdateSupported;
267   bool                 mPartialUpdateAvailable;
268
269   PFNEGLSETDAMAGEREGIONKHRPROC mEglSetDamageRegionKHR;
270   PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC mSwapBuffersWithDamage;
271 };
272
273 } // namespace Adaptor
274
275 } // namespace Internal
276
277 } // namespace Dali
278
279 #endif // DALI_INTERNAL_EGL_IMPLEMENTATION_H