2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/graphics/gles/egl-graphics.h>
22 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
23 #include <dali/internal/system/common/configuration-manager.h>
24 #include <dali/internal/system/common/environment-options.h>
25 #include <dali/internal/window-system/common/display-utils.h> // For Utils::MakeUnique
33 EglGraphics::EglGraphics(EnvironmentOptions& environmentOptions)
34 : mMultiSamplingLevel(0)
36 mDepthBufferRequired = static_cast<Integration::DepthBufferAvailable>(environmentOptions.DepthBufferRequired());
37 mStencilBufferRequired = static_cast<Integration::StencilBufferAvailable>(environmentOptions.StencilBufferRequired());
38 mPartialUpdateRequired = static_cast<Integration::PartialUpdateAvailable>(environmentOptions.PartialUpdateRequired());
39 mMultiSamplingLevel = environmentOptions.GetMultiSamplingLevel();
41 if(environmentOptions.GetGlesCallTime() > 0)
43 mGLES = Utils::MakeUnique<GlProxyImplementation>(environmentOptions);
47 mGLES.reset(new GlImplementation());
50 mGraphicsController.InitializeGLES(*mGLES.get());
53 EglGraphics::~EglGraphics()
57 void EglGraphics::SetGlesVersion(const int32_t glesVersion)
59 if(mEglImplementation)
61 mEglImplementation->SetGlesVersion(glesVersion);
64 mGLES->SetGlesVersion(glesVersion);
66 mGraphicsController.SetGLESVersion(static_cast<Graphics::GLES::GLESVersion>(glesVersion));
69 void EglGraphics::SetIsSurfacelessContextSupported(const bool isSupported)
71 mGLES->SetIsSurfacelessContextSupported(isSupported);
74 void EglGraphics::ActivateResourceContext()
76 mGraphicsController.ActivateResourceContext();
78 if(mEglImplementation && mEglImplementation->IsSurfacelessContextSupported())
80 // Make the shared surfaceless context as current before rendering
81 mEglImplementation->MakeContextCurrent(EGL_NO_SURFACE, mEglImplementation->GetContext());
85 void EglGraphics::ActivateSurfaceContext(Dali::RenderSurfaceInterface* surface)
87 mGraphicsController.ActivateSurfaceContext(surface);
91 surface->InitializeGraphics();
92 surface->MakeContextCurrent();
96 void EglGraphics::SetFirstFrameAfterResume()
98 if(mEglImplementation)
100 mEglImplementation->SetFirstFrameAfterResume();
104 void EglGraphics::Initialize()
108 // Sync and context helper require EGL to be initialized first (can't execute in the constructor)
109 mGraphicsController.Initialize(*mEglSync.get(), *mEglContextHelper.get(), *this);
112 void EglGraphics::Initialize(bool depth, bool stencil, bool partialRendering, int msaa)
114 mDepthBufferRequired = static_cast<Integration::DepthBufferAvailable>(depth);
115 mStencilBufferRequired = static_cast<Integration::StencilBufferAvailable>(stencil);
116 mPartialUpdateRequired = static_cast<Integration::PartialUpdateAvailable>(partialRendering);
117 mMultiSamplingLevel = msaa;
122 void EglGraphics::EglInitialize()
124 mEglSync = Utils::MakeUnique<EglSyncImplementation>();
125 mEglContextHelper = Utils::MakeUnique<EglContextHelperImplementation>();
126 mEglImplementation = Utils::MakeUnique<EglImplementation>(mMultiSamplingLevel, mDepthBufferRequired, mStencilBufferRequired, mPartialUpdateRequired);
127 mEglImageExtensions = Utils::MakeUnique<EglImageExtensions>(mEglImplementation.get());
129 mEglSync->Initialize(mEglImplementation.get()); // The sync impl needs the EglDisplay
130 mEglContextHelper->Initialize(mEglImplementation.get()); // The context helper impl needs the EglContext
133 void EglGraphics::ConfigureSurface(Dali::RenderSurfaceInterface* surface)
135 DALI_ASSERT_ALWAYS(mEglImplementation && "EGLImplementation not created");
137 // Try to use OpenGL es 3.0
138 // ChooseConfig returns false here when the device only support gles 2.0.
139 // Because eglChooseConfig with gles 3.0 setting fails when the device only support gles 2.0 and Our default setting is gles 3.0.
140 if(!mEglImplementation->ChooseConfig(true, COLOR_DEPTH_32))
142 // Retry to use OpenGL es 2.0
144 mEglImplementation->ChooseConfig(true, COLOR_DEPTH_32);
147 // Check whether surfaceless context is supported
148 bool isSurfacelessContextSupported = mEglImplementation->IsSurfacelessContextSupported();
149 SetIsSurfacelessContextSupported(isSurfacelessContextSupported);
151 RenderSurfaceInterface* currentSurface = nullptr;
152 if(isSurfacelessContextSupported)
154 // Create a surfaceless OpenGL context for shared resources
155 mEglImplementation->CreateContext();
156 mEglImplementation->MakeContextCurrent(EGL_NO_SURFACE, mEglImplementation->GetContext());
160 currentSurface = surface;
163 currentSurface->InitializeGraphics();
164 currentSurface->MakeContextCurrent();
168 mGLES->ContextCreated();
169 SetGlesVersion(mGLES->GetGlesVersion());
172 void EglGraphics::Shutdown()
174 if(mEglImplementation)
176 // Shutdown controller
177 mGraphicsController.Shutdown();
180 mEglImplementation->TerminateGles();
184 void EglGraphics::Destroy()
186 mGraphicsController.Destroy();
189 GlImplementation& EglGraphics::GetGlesInterface()
194 Integration::GlAbstraction& EglGraphics::GetGlAbstraction() const
196 DALI_ASSERT_DEBUG(mGLES && "GLImplementation not created");
200 EglImplementation& EglGraphics::GetEglImplementation() const
202 DALI_ASSERT_ALWAYS(mEglImplementation && "EGLImplementation not created");
203 return *mEglImplementation;
206 EglInterface& EglGraphics::GetEglInterface() const
208 DALI_ASSERT_ALWAYS(mEglImplementation && "EGLImplementation not created");
209 EglInterface* eglInterface = mEglImplementation.get();
210 return *eglInterface;
213 EglSyncImplementation& EglGraphics::GetSyncImplementation()
215 DALI_ASSERT_DEBUG(mEglSync && "EglSyncImplementation not created");
219 EglContextHelperImplementation& EglGraphics::GetContextHelperImplementation()
221 DALI_ASSERT_DEBUG(mEglContextHelper && "EglContextHelperImplementation not created");
222 return *mEglContextHelper;
225 EglImageExtensions* EglGraphics::GetImageExtensions()
227 DALI_ASSERT_DEBUG(mEglImageExtensions && "EglImageExtensions not created");
228 return mEglImageExtensions.get();
231 Graphics::Controller& EglGraphics::GetController()
233 return mGraphicsController;
236 void EglGraphics::CacheConfigurations(ConfigurationManager& configurationManager)
238 mGLES->SetIsAdvancedBlendEquationSupported(configurationManager.IsAdvancedBlendEquationSupported());
239 mGLES->SetShadingLanguageVersion(configurationManager.GetShadingLanguageVersion());
242 } // namespace Adaptor
243 } // namespace Internal