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