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);
67 void EglGraphics::SetIsSurfacelessContextSupported(const bool isSupported)
69 mGLES->SetIsSurfacelessContextSupported(isSupported);
72 void EglGraphics::ActivateResourceContext()
74 if(mEglImplementation && mEglImplementation->IsSurfacelessContextSupported())
76 // Make the shared surfaceless context as current before rendering
77 mEglImplementation->MakeContextCurrent(EGL_NO_SURFACE, mEglImplementation->GetContext());
81 void EglGraphics::SetFirstFrameAfterResume()
83 if(mEglImplementation)
85 mEglImplementation->SetFirstFrameAfterResume();
89 void EglGraphics::Initialize()
93 // Sync and context helper require EGL to be initialized first (can't execute in the constructor)
94 mGraphicsController.Initialize(*mEglSync.get(), *mEglContextHelper.get());
97 void EglGraphics::Initialize(bool depth, bool stencil, bool partialRendering, int msaa)
99 mDepthBufferRequired = static_cast<Integration::DepthBufferAvailable>(depth);
100 mStencilBufferRequired = static_cast<Integration::StencilBufferAvailable>(stencil);
101 mPartialUpdateRequired = static_cast<Integration::PartialUpdateAvailable>(partialRendering);
102 mMultiSamplingLevel = msaa;
107 void EglGraphics::EglInitialize()
109 mEglSync = Utils::MakeUnique<EglSyncImplementation>();
110 mEglContextHelper = Utils::MakeUnique<EglContextHelperImplementation>();
111 mEglImplementation = Utils::MakeUnique<EglImplementation>(mMultiSamplingLevel, mDepthBufferRequired, mStencilBufferRequired, mPartialUpdateRequired);
112 mEglImageExtensions = Utils::MakeUnique<EglImageExtensions>(mEglImplementation.get());
114 mEglSync->Initialize(mEglImplementation.get()); // The sync impl needs the EglDisplay
115 mEglContextHelper->Initialize(mEglImplementation.get()); // The context helper impl needs the EglContext
118 void EglGraphics::ConfigureSurface(Dali::RenderSurfaceInterface* surface)
120 DALI_ASSERT_ALWAYS(mEglImplementation && "EGLImplementation not created");
122 // Try to use OpenGL es 3.0
123 // ChooseConfig returns false here when the device only support gles 2.0.
124 // Because eglChooseConfig with gles 3.0 setting fails when the device only support gles 2.0 and Our default setting is gles 3.0.
125 if(!mEglImplementation->ChooseConfig(true, COLOR_DEPTH_32))
127 // Retry to use OpenGL es 2.0
129 mEglImplementation->ChooseConfig(true, COLOR_DEPTH_32);
132 // Check whether surfaceless context is supported
133 bool isSurfacelessContextSupported = mEglImplementation->IsSurfacelessContextSupported();
134 SetIsSurfacelessContextSupported(isSurfacelessContextSupported);
136 RenderSurfaceInterface* currentSurface = nullptr;
137 if(isSurfacelessContextSupported)
139 // Create a surfaceless OpenGL context for shared resources
140 mEglImplementation->CreateContext();
141 mEglImplementation->MakeContextCurrent(EGL_NO_SURFACE, mEglImplementation->GetContext());
145 currentSurface = surface;
148 currentSurface->InitializeGraphics();
149 currentSurface->MakeContextCurrent();
153 mGLES->ContextCreated();
154 SetGlesVersion(mGLES->GetGlesVersion());
157 void EglGraphics::Shutdown()
159 if(mEglImplementation)
161 // Shutdown controller
162 mGraphicsController.Shutdown();
165 mEglImplementation->TerminateGles();
169 void EglGraphics::Destroy()
171 mGraphicsController.Destroy();
174 GlImplementation& EglGraphics::GetGlesInterface()
179 Integration::GlAbstraction& EglGraphics::GetGlAbstraction() const
181 DALI_ASSERT_DEBUG(mGLES && "GLImplementation not created");
185 EglImplementation& EglGraphics::GetEglImplementation() const
187 DALI_ASSERT_ALWAYS(mEglImplementation && "EGLImplementation not created");
188 return *mEglImplementation;
191 EglInterface& EglGraphics::GetEglInterface() const
193 DALI_ASSERT_ALWAYS(mEglImplementation && "EGLImplementation not created");
194 EglInterface* eglInterface = mEglImplementation.get();
195 return *eglInterface;
198 EglSyncImplementation& EglGraphics::GetSyncImplementation()
200 DALI_ASSERT_DEBUG(mEglSync && "EglSyncImplementation not created");
204 EglContextHelperImplementation& EglGraphics::GetContextHelperImplementation()
206 DALI_ASSERT_DEBUG(mEglContextHelper && "EglContextHelperImplementation not created");
207 return *mEglContextHelper;
210 EglImageExtensions* EglGraphics::GetImageExtensions()
212 DALI_ASSERT_DEBUG(mEglImageExtensions && "EglImageExtensions not created");
213 return mEglImageExtensions.get();
216 Graphics::Controller& EglGraphics::GetController()
218 return mGraphicsController;
221 void EglGraphics::CacheConfigurations(ConfigurationManager& configurationManager)
223 mGLES->SetIsAdvancedBlendEquationSupported(configurationManager.IsAdvancedBlendEquationSupported());
224 mGLES->SetShadingLanguageVersion(configurationManager.GetShadingLanguageVersion());
227 } // namespace Adaptor
228 } // namespace Internal