b50535252390a3b69ef79de1c811a610dd24918b
[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    * Gets if user set damaged areas
139    */
140   bool DamageAreasSet() const;
141
142   /**
143    * Sets damaged areas, overrides auto calculated ones
144    */
145   void SetDamageAreas( std::vector<Dali::Rect<int>>& damagedArea );
146
147   /**
148    * Forces full surface swap next frame, resets current partial update state.
149    */
150   void SetFullSwapNextFrame();
151
152   /**
153    * Performs an OpenGL set damage command with damaged rects
154    */
155   virtual void SetDamage( EGLSurface& eglSurface, const std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect );
156
157   /**
158    * Performs an OpenGL swap buffers command with damaged rects
159    */
160   virtual void SwapBuffers( EGLSurface& eglSurface, const std::vector<Rect<int>>& damagedRects );
161
162   /**
163    * Performs an OpenGL copy buffers command
164    */
165   virtual void CopyBuffers( EGLSurface& eglSurface );
166
167   /**
168    * Performs an EGL wait GL command
169    */
170   virtual void WaitGL();
171
172   /**
173    * Choose config of egl
174    * @param isWindowType whether the config for window or pixmap
175    * @param colorDepth Bit per pixel value (ex. 32 or 24)
176    * @return true if the eglChooseConfig is succeed.
177   */
178   bool ChooseConfig( bool isWindowType, ColorDepth depth );
179
180   /**
181     * Create an OpenGL surface using a window
182     * @param window The window to create the surface on
183     * @param colorDepth Bit per pixel value (ex. 32 or 24)
184     * @return Handle to an on-screen EGL window surface (the requester has an ownership of this egl surface)
185     */
186   EGLSurface CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth );
187
188   /**
189    * Create the OpenGL surface using a pixmap
190    * @param pixmap The pixmap to create the surface on
191    * @param colorDepth Bit per pixel value (ex. 32 or 24)
192    * @return Handle to an off-screen EGL pixmap surface (the requester has an ownership of this egl surface)
193    */
194   EGLSurface CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth );
195
196   /**
197    * Replaces the render surface
198    * @param[in] window, the window to create the new surface on
199    * @return true if the context was lost due to a change in display
200    *         between old surface and new surface
201    */
202   bool ReplaceSurfaceWindow( EGLNativeWindowType window, EGLSurface& eglSurface, EGLContext& eglContext );
203
204   /**
205    * Replaces the render surface
206    * @param[in] pixmap, the pixmap to replace the new surface on
207    * @param[out] eglSurface, the eglSurface is created using a pixmap.
208    * @return true if the context was lost due to a change in x-display
209    *         between old surface and new surface
210    */
211   bool ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLSurface& eglSurface );
212
213   /**
214    * Sets gles version
215    */
216   void SetGlesVersion( const int32_t glesVersion );
217
218   /**
219    * Sets Whether the frame is the first after Resume.
220    */
221   void SetFirstFrameAfterResume();
222
223   /**
224    * returns the display with which this object was initialized
225    * @return the EGL Display.
226    */
227   EGLDisplay GetDisplay() const;
228
229   /**
230    * Returns the EGL context
231    * @return the EGL context.
232    */
233   EGLContext GetContext() const;
234
235   /**
236    * Returns the gles version
237    * @return the gles version
238    */
239   int32_t GetGlesVersion() const;
240
241   /**
242    * Returns whether the surfaceless context is supported
243    * @return true if the surfaceless context is supported
244    */
245   bool IsSurfacelessContextSupported() const;
246
247   /**
248    * @brief Wait until all rendering calls for the currently context are executed
249    */
250   void WaitClient();
251
252 private:
253
254   Vector<EGLint>       mContextAttribs;
255
256   EGLNativeDisplayType mEglNativeDisplay;
257
258   EGLNativeWindowType  mEglNativeWindow;
259
260   EGLNativePixmapType  mCurrentEglNativePixmap;
261
262   EGLDisplay           mEglDisplay;
263   EGLConfig            mEglConfig;
264   EGLContext           mEglContext;                            ///< The resource context holding assets such as textures to be shared
265
266   typedef std::vector<EGLContext> EglWindowContextContainer;
267   EglWindowContextContainer mEglWindowContexts;                ///< The EGL context for the window
268
269   EGLSurface           mCurrentEglSurface;
270   EGLContext           mCurrentEglContext;
271
272   typedef std::vector<EGLSurface> EglWindowSurfaceContainer;
273   EglWindowSurfaceContainer mEglWindowSurfaces;                ///< The EGL surface for the window
274
275   int32_t              mMultiSamplingLevel;
276   int32_t              mGlesVersion;
277
278   ColorDepth           mColorDepth;
279
280   bool                 mGlesInitialized;
281   bool                 mIsOwnSurface;
282   bool                 mIsWindow;
283   bool                 mDepthBufferRequired;
284   bool                 mStencilBufferRequired;
285   bool                 mPartialUpdateRequired;
286   bool                 mIsSurfacelessContextSupported;
287   bool                 mIsKhrCreateContextSupported;
288
289   uint32_t              mSwapBufferCountAfterResume;
290   PFNEGLSETDAMAGEREGIONKHRPROC mEglSetDamageRegionKHR;
291   PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC mEglSwapBuffersWithDamageKHR;
292
293   EGLint mBufferAge;
294   std::list<std::vector<Rect<int>>> mBufferDamagedRects;
295   std::vector<Rect<int>> mCombinedDamagedRects;
296   std::vector<Rect<int>> mDamagedAreas;
297   Rect<int> mSurfaceRect;
298   bool mFullSwapNextFrame;
299 };
300
301 } // namespace Adaptor
302
303 } // namespace Internal
304
305 } // namespace Dali
306
307 #endif // DALI_INTERNAL_EGL_IMPLEMENTATION_H