399ff1acb96f0e751bd291fd705f0de525c47389
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles / egl-graphics.h
1 #ifndef DALI_INTERNAL_BASE_GRAPHICS_IMPLEMENTATION_H
2 #define DALI_INTERNAL_BASE_GRAPHICS_IMPLEMENTATION_H
3
4 /*
5  * Copyright (c) 2021 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 // INTERNAL INCLUDES
22 #include <dali/integration-api/adaptor-framework/egl-interface.h>
23 #include <dali/internal/graphics/common/egl-image-extensions.h>
24 #include <dali/internal/graphics/common/graphics-interface.h>
25 #include <dali/internal/graphics/gles-impl/egl-graphics-controller.h>
26 #include <dali/internal/graphics/gles/egl-context-helper-implementation.h>
27 #include <dali/internal/graphics/gles/egl-implementation.h>
28 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
29 #include <dali/internal/graphics/gles/gl-implementation.h>
30 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
31
32 namespace Dali
33 {
34 namespace Internal
35 {
36 namespace Adaptor
37 {
38 class EnvironmentOptions;
39 class ConfigurationManager;
40
41 class EglGraphics : public GraphicsInterface
42 {
43 public:
44   /**
45    * Constructor
46    */
47   EglGraphics(EnvironmentOptions& environmentOptions);
48
49   /**
50    * Destructor
51    */
52   virtual ~EglGraphics();
53
54   /**
55    * @copydoc Dali::Internal::Adaptor::GraphicsInterface::Initialize()
56    */
57   void Initialize() override;
58
59   /**
60    * @copydoc Dali::Internal::Adaptor::GraphicsInterface::Initialize(bool,bool,bool,int)
61    */
62   void Initialize(bool depth, bool stencil, bool partialRendering, int msaa);
63
64   /**
65    * @copydoc Dali::Internal::Adaptor::GraphicsInterface::ConfigureSurface()
66    */
67   void ConfigureSurface(Dali::RenderSurfaceInterface* surface) override;
68
69   /**
70    * Set gles version
71    * Default version is gles 3.0
72    */
73   void SetGlesVersion(const int32_t glesVersion);
74
75   /**
76    * Set whether the surfaceless context is supported
77    * @param[in] isSupported Whether the surfaceless context is supported
78    */
79   void SetIsSurfacelessContextSupported(const bool isSupported);
80
81   /**
82    * Activate the resource context (shared surfaceless context)
83    */
84   void ActivateResourceContext() override;
85
86   /**
87    * Activate the surface context
88    *
89    * @param[in] surface The surface whose context to be switched to.
90    */
91   void ActivateSurfaceContext(Dali::RenderSurfaceInterface* surface) override;
92
93   /**
94    * This is called after all the surfaces have been rendered.
95    *
96    * @note This should not be called if uploading resource only without rendering any surface.
97    */
98   void PostRender() override;
99
100   /**
101    * Inform graphics interface that this is the first frame after a resume.
102    * (For debug only)
103    */
104   void SetFirstFrameAfterResume() override;
105
106   /**
107    * Gets the GL abstraction
108    * @return The GL abstraction
109    */
110   Integration::GlAbstraction& GetGlAbstraction() const;
111
112   /**
113    * Gets the implementation of EGL
114    * @return The implementation of EGL
115    */
116   EglImplementation& GetEglImplementation() const;
117
118   /**
119    * Gets the graphics interface for EGL
120    * @return The graphics interface for EGL
121    */
122   EglInterface& GetEglInterface() const;
123
124   /**
125    * @copydoc Dali::Integration::GlAbstraction& GetGlesInterface()
126    */
127   GlImplementation& GetGlesInterface();
128
129   /**
130    * Gets the implementation of GlSyncAbstraction for EGL.
131    * @return The implementation of GlSyncAbstraction for EGL.
132    */
133   EglSyncImplementation& GetSyncImplementation();
134
135   /**
136    * Gets the implementation of GlContextHelperAbstraction for EGL.
137    * @return The implementation of GlContextHelperAbstraction for EGL.
138    */
139   EglContextHelperImplementation& GetContextHelperImplementation();
140
141   /**
142    * @copydoc Dali::Internal::Adaptor::GraphicsInterface::GetDepthBufferRequired()
143    */
144   Integration::DepthBufferAvailable& GetDepthBufferRequired();
145
146   /**
147    * @copydoc Dali::Internal::Adaptor::GraphicsInterface::GetStencilBufferRequired()
148    */
149   Integration::StencilBufferAvailable GetStencilBufferRequired();
150
151   /**
152    * Gets the EGL image extension
153    * @return The EGL image extension
154    */
155   EglImageExtensions* GetImageExtensions();
156
157   /**
158    * @copydoc Dali::Internal::Adaptor::GraphicsInterface::Shutdown()
159    */
160   void Shutdown() override;
161
162   /**
163    * @copydoc Dali::Internal::Adaptor::GraphicsInterface::Destroy()
164    */
165   void Destroy() override;
166
167   Graphics::Controller& GetController() override;
168
169   bool IsAdvancedBlendEquationSupported() override
170   {
171     return mGLES->IsAdvancedBlendEquationSupported();
172   }
173
174   /**
175    * @return true if graphics subsystem is initialized
176    */
177   bool IsInitialized() override
178   {
179     return mEglImplementation && mEglImplementation->IsGlesInitialized();
180   }
181
182   bool IsResourceContextSupported() override
183   {
184     return mEglImplementation && mEglImplementation->IsSurfacelessContextSupported();
185   }
186
187   uint32_t GetMaxTextureSize() override
188   {
189     return mGLES->GetMaxTextureSize();
190   }
191
192   uint32_t GetShaderLanguageVersion() override
193   {
194     return mGLES->GetShadingLanguageVersion();
195   }
196
197   bool ApplyNativeFragmentShader(std::string& shader, const char* customSamplerType)
198   {
199     return mGLES->ApplyNativeFragmentShader(shader, customSamplerType);
200   }
201
202   void CacheConfigurations(ConfigurationManager& configurationManager) override;
203
204 private:
205   // Eliminate copy and assigned operations
206   EglGraphics(const EglGraphics& rhs) = delete;
207   EglGraphics& operator=(const EglGraphics& rhs) = delete;
208
209   /**
210    * Initialize graphics subsystems
211    */
212   void EglInitialize();
213
214 private:
215   Graphics::EglGraphicsController                 mGraphicsController; ///< Graphics Controller for Dali Core
216   std::unique_ptr<GlImplementation>               mGLES;               ///< GL implementation
217   std::unique_ptr<EglImplementation>              mEglImplementation;  ///< EGL implementation
218   std::unique_ptr<EglImageExtensions>             mEglImageExtensions; ///< EGL image extension
219   std::unique_ptr<EglSyncImplementation>          mEglSync;            ///< GlSyncAbstraction implementation for EGL
220   std::unique_ptr<EglContextHelperImplementation> mEglContextHelper;   ///< GlContextHelperAbstraction implementation for EGL
221
222   int mMultiSamplingLevel; ///< The multiple sampling level
223 };
224
225 } // namespace Adaptor
226
227 } // namespace Internal
228
229 } // namespace Dali
230
231 #endif // DALI_INTERNAL_BASE_GRAPHICS_IMPLEMENTATION_H