4081ed3df199bfa147c553c0a8811f23639e2be2
[platform/core/uifw/dali-adaptor.git] / adaptors / common / gl / egl-implementation.h
1 #ifndef __DALI_INTERNAL_EGL_IMPLEMENTATION_H__
2 #define __DALI_INTERNAL_EGL_IMPLEMENTATION_H__
3
4 /*
5  * Copyright (c) 2017 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
26 // INTERNAL INCLUDES
27 #include <adaptors/integration-api/egl-interface.h>
28
29 namespace Dali
30 {
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    * Constructor
45    * @param environmentOptions To check the envirionment options
46    */
47   EglImplementation( int multiSamplingLevel );
48
49   /**
50    * Destructor
51    */
52   virtual ~EglImplementation();
53
54 public:
55
56   /**
57    * (Called from  ECoreX::RenderSurface, not RenderThread, so not in i/f, hence, not virtual)
58    * Initialize GL
59    * @param display The display
60    * @param isOwnSurface whether the surface is own or not
61    * @return true on success, false on failure
62    */
63   bool InitializeGles( EGLNativeDisplayType display, bool isOwnSurface = true );
64
65   /**
66     * Create the OpenGL context.
67     * @return true if successful
68     */
69   virtual bool CreateContext();
70
71   /**
72     * Destroy the OpenGL context.
73     */
74   void DestroyContext();
75
76   /**
77     * Destroy the OpenGL surface.
78     */
79   void DestroySurface();
80
81   /**
82    * Make the OpenGL context current
83    */
84   virtual void MakeContextCurrent();
85
86   /**
87    * clear the OpenGL context
88    */
89   void MakeContextNull();
90
91   /**
92    * @brief Make the OpenGL surface current
93    *
94    * @param pixmap The pixmap to replace the current surface
95    * @param eglSurface The eglSurface to replace the current OpenGL surface.
96    */
97   void MakeCurrent( EGLNativePixmapType pixmap, EGLSurface eglSurface );
98
99   /**
100    * Terminate GL
101    */
102   virtual void TerminateGles();
103
104   /**
105    * Checks if GL is initialised
106    * @return true if it is
107    */
108   bool IsGlesInitialized() const;
109
110   /**
111    * Performs an OpenGL swap buffers command
112    */
113   virtual void SwapBuffers();
114
115   /**
116    * Performs an OpenGL copy buffers command
117    */
118   virtual void CopyBuffers();
119
120   /**
121    * Performs an EGL wait GL command
122    */
123   virtual void WaitGL();
124
125   /**
126    * Choose config of egl
127    * @param isWindowType whether the config for window or pixmap
128    * @param colorDepth Bit per pixel value (ex. 32 or 24)
129   */
130   void ChooseConfig( bool isWindowType, ColorDepth depth );
131
132   /**
133     * Create an OpenGL surface using a window
134     * @param window The window to create the surface on
135     * @param colorDepth Bit per pixel value (ex. 32 or 24)
136     * @return true on success, false on failure
137     */
138   void CreateSurfaceWindow( EGLNativeWindowType window, ColorDepth depth );
139
140   /**
141    * Create the OpenGL surface using a pixmap
142    * @param pixmap The pixmap to create the surface on
143    * @param colorDepth Bit per pixel value (ex. 32 or 24)
144    * @return Handle to an off-screen EGL pixmap surface (the requester has an ownership of this egl surface)
145    */
146   EGLSurface CreateSurfacePixmap( EGLNativePixmapType pixmap, ColorDepth depth );
147
148   /**
149    * Replaces the render surface
150    * @param[in] window, the window to create the new surface on
151    * @return true if the context was lost due to a change in display
152    *         between old surface and new surface
153    */
154   bool ReplaceSurfaceWindow( EGLNativeWindowType window );
155
156   /**
157    * Replaces the render surface
158    * @param[in] pixmap, the pixmap to replace the new surface on
159    * @param[out] eglSurface, the eglSurface is created using a pixmap.
160    * @return true if the context was lost due to a change in x-display
161    *         between old surface and new surface
162    */
163   bool ReplaceSurfacePixmap( EGLNativePixmapType pixmap, EGLSurface& eglSurface );
164
165   /**
166    * returns the display with which this object was initialized
167    * @return the EGL Display.
168    */
169   EGLDisplay GetDisplay() const;
170
171   /**
172    * Returns the EGL context
173    * @return the EGL context.
174    */
175   EGLContext GetContext() const;
176
177 private:
178
179   Vector<EGLint>       mContextAttribs;
180
181   EGLNativeDisplayType mEglNativeDisplay;
182
183   EGLNativeWindowType  mEglNativeWindow;
184
185   EGLNativePixmapType  mCurrentEglNativePixmap;
186
187   EGLDisplay           mEglDisplay;
188   EGLConfig            mEglConfig;
189   EGLContext           mEglContext;
190   EGLSurface           mCurrentEglSurface;
191
192   bool                 mGlesInitialized;
193   bool                 mIsOwnSurface;
194   bool                 mContextCurrent;
195   bool                 mIsWindow;
196   ColorDepth           mColorDepth;
197
198   int                  mMultiSamplingLevel;
199 };
200
201 } // namespace Adaptor
202
203 } // namespace Internal
204
205 } // namespace Dali
206
207 #endif // __DALI_INTERNAL_EGL_IMPLEMENTATION_H__