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