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