Support multiple surfaces for partial update
[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 <dali/public-api/common/list-wrapper.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24
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>
30
31 // INTERNAL INCLUDES
32 #include <dali/integration-api/adaptor-framework/egl-interface.h>
33
34 namespace Dali
35 {
36 namespace Internal
37 {
38 namespace Adaptor
39 {
40
41 /**
42  * EglImplementation class provides an EGL implementation.
43  */
44 class EglImplementation : public EglInterface
45 {
46 public:
47
48   /**
49    * Constructor
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
54    */
55   EglImplementation( int multiSamplingLevel,
56                      Integration::DepthBufferAvailable depthBufferRequired,
57                      Integration::StencilBufferAvailable stencilBufferRequired,
58                      Integration::PartialUpdateAvailable partialUpdateRequired );
59
60   /**
61    * Destructor
62    */
63   virtual ~EglImplementation();
64
65 public:
66
67   /**
68    * (Called from  ECoreX::RenderSurface, not RenderThread, so not in i/f, hence, not virtual)
69    * Initialize GL
70    * @param display The display
71    * @param isOwnSurface whether the surface is own or not
72    * @return true on success, false on failure
73    */
74   bool InitializeGles( EGLNativeDisplayType display, bool isOwnSurface = true );
75
76   /**
77     * Create the OpenGL context for the shared resource.
78     * @return true if successful
79     */
80   virtual bool CreateContext();
81
82   /**
83     * Create the OpenGL context for the window.
84     * @return true if successful
85     */
86   bool CreateWindowContext( EGLContext& mEglContext );
87
88   /**
89     * Destroy the OpenGL context.
90     */
91   void DestroyContext( EGLContext& eglContext );
92
93   /**
94     * Destroy the OpenGL surface.
95     */
96   void DestroySurface( EGLSurface& eglSurface );
97
98   /**
99    * Make the OpenGL context current
100    */
101   virtual void MakeContextCurrent( EGLSurface eglSurface, EGLContext eglContext );
102
103   /**
104    * clear the OpenGL context
105    */
106   void MakeContextNull();
107
108   /**
109    * @brief Make the OpenGL surface current
110    *
111    * @param pixmap The pixmap to replace the current surface
112    * @param eglSurface The eglSurface to replace the current OpenGL surface.
113    */
114   void MakeCurrent( EGLNativePixmapType pixmap, EGLSurface eglSurface );
115
116   /**
117    * Terminate GL
118    */
119   virtual void TerminateGles();
120
121   /**
122    * Checks if GL is initialised
123    * @return true if it is
124    */
125   bool IsGlesInitialized() const;
126
127   /**
128    * Performs an OpenGL swap buffers command
129    */
130   virtual void SwapBuffers( EGLSurface& eglSurface );
131
132   /**
133    * Gets current back buffer age
134    */
135   EGLint GetBufferAge( EGLSurface& eglSurface ) const;
136
137   /**
138    * Performs an OpenGL set damage command with damaged rects
139    */
140   void SetDamageRegion( EGLSurface& eglSurface, std::vector< Rect< int > >& damagedRects );
141
142   /**
143    * Performs an OpenGL swap buffers command with damaged rects
144    */
145   virtual void SwapBuffers( EGLSurface& eglSurface, const std::vector<Rect<int>>& damagedRects );
146
147   /**
148    * Performs an OpenGL copy buffers command
149    */
150   virtual void CopyBuffers( EGLSurface& eglSurface );
151
152   /**
153    * Performs an EGL wait GL command
154    */
155   virtual void WaitGL();
156
157   /**
158    * Choose config of egl
159    * @param isWindowType whether the config for window or pixmap
160    * @param colorDepth Bit per pixel value (ex. 32 or 24)
161    * @return true if the eglChooseConfig is succeed.
162   */
163   bool ChooseConfig( bool isWindowType, ColorDepth depth );
164
165   /**
166     * Create an OpenGL surface using a window
167     * @param window The window to create the surface on
168     * @param colorDepth Bit per pixel value (ex. 32 or 24)
169     * @return Handle to an on-screen EGL window surface (the requester has an ownership of this egl surface)
170     */
171   EGLSurface CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth );
172
173   /**
174    * Create the OpenGL surface using a pixmap
175    * @param pixmap The pixmap to create the surface on
176    * @param colorDepth Bit per pixel value (ex. 32 or 24)
177    * @return Handle to an off-screen EGL pixmap surface (the requester has an ownership of this egl surface)
178    */
179   EGLSurface CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth );
180
181   /**
182    * Replaces the render surface
183    * @param[in] window, the window to create the new surface on
184    * @return true if the context was lost due to a change in display
185    *         between old surface and new surface
186    */
187   bool ReplaceSurfaceWindow( EGLNativeWindowType window, EGLSurface& eglSurface, EGLContext& eglContext );
188
189   /**
190    * Replaces the render surface
191    * @param[in] pixmap, the pixmap to replace the new surface on
192    * @param[out] eglSurface, the eglSurface is created using a pixmap.
193    * @return true if the context was lost due to a change in x-display
194    *         between old surface and new surface
195    */
196   bool ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLSurface& eglSurface );
197
198   /**
199    * Sets gles version
200    */
201   void SetGlesVersion( const int32_t glesVersion );
202
203   /**
204    * Sets Whether the frame is the first after Resume.
205    */
206   void SetFirstFrameAfterResume();
207
208   /**
209    * returns the display with which this object was initialized
210    * @return the EGL Display.
211    */
212   EGLDisplay GetDisplay() const;
213
214   /**
215    * Returns the EGL context
216    * @return the EGL context.
217    */
218   EGLContext GetContext() const;
219
220   /**
221    * Returns the gles version
222    * @return the gles version
223    */
224   int32_t GetGlesVersion() const;
225
226   /**
227    * Returns whether the surfaceless context is supported
228    * @return true if the surfaceless context is supported
229    */
230   bool IsSurfacelessContextSupported() const;
231
232   /**
233    * @brief Wait until all rendering calls for the currently context are executed
234    */
235   void WaitClient();
236
237   /**
238    * @brief Returns whether the partial update is required.
239    * @return true if the partial update is required.
240    */
241   bool IsPartialUpdateRequired() const;
242
243 private:
244
245   Vector<EGLint>       mContextAttribs;
246
247   EGLNativeDisplayType mEglNativeDisplay;
248
249   EGLNativeWindowType  mEglNativeWindow;
250
251   EGLNativePixmapType  mCurrentEglNativePixmap;
252
253   EGLDisplay           mEglDisplay;
254   EGLConfig            mEglConfig;
255   EGLContext           mEglContext;                            ///< The resource context holding assets such as textures to be shared
256
257   typedef std::vector<EGLContext> EglWindowContextContainer;
258   EglWindowContextContainer mEglWindowContexts;                ///< The EGL context for the window
259
260   EGLSurface           mCurrentEglSurface;
261   EGLContext           mCurrentEglContext;
262
263   typedef std::vector<EGLSurface> EglWindowSurfaceContainer;
264   EglWindowSurfaceContainer mEglWindowSurfaces;                ///< The EGL surface for the window
265
266   int32_t              mMultiSamplingLevel;
267   int32_t              mGlesVersion;
268
269   ColorDepth           mColorDepth;
270
271   bool                 mGlesInitialized;
272   bool                 mIsOwnSurface;
273   bool                 mIsWindow;
274   bool                 mDepthBufferRequired;
275   bool                 mStencilBufferRequired;
276   bool                 mPartialUpdateRequired;
277   bool                 mIsSurfacelessContextSupported;
278   bool                 mIsKhrCreateContextSupported;
279
280   uint32_t              mSwapBufferCountAfterResume;
281   PFNEGLSETDAMAGEREGIONKHRPROC mEglSetDamageRegionKHR;
282   PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC mEglSwapBuffersWithDamageKHR;
283
284 };
285
286 } // namespace Adaptor
287
288 } // namespace Internal
289
290 } // namespace Dali
291
292 #endif // DALI_INTERNAL_EGL_IMPLEMENTATION_H