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