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 mEglImplementation->SetGlesVersion(glesVersion);
60 mGLES->SetGlesVersion(glesVersion);
63 void EglGraphics::SetIsSurfacelessContextSupported(const bool isSupported)
65 mGLES->SetIsSurfacelessContextSupported(isSupported);
68 void EglGraphics::ActivateResourceContext()
70 if(mEglImplementation->IsSurfacelessContextSupported())
72 // Make the shared surfaceless context as current before rendering
73 mEglImplementation->MakeContextCurrent(EGL_NO_SURFACE, mEglImplementation->GetContext());
77 void EglGraphics::SetFirstFrameAfterResume()
79 mEglImplementation->SetFirstFrameAfterResume();
82 void EglGraphics::Initialize()
86 // Sync and context helper require EGL to be initialized first (can't execute in the constructor)
87 mGraphicsController.Initialize(*mEglSync.get(), *mEglContextHelper.get());
90 void EglGraphics::Initialize(bool depth, bool stencil, bool partialRendering, int msaa)
92 mDepthBufferRequired = static_cast<Integration::DepthBufferAvailable>(depth);
93 mStencilBufferRequired = static_cast<Integration::StencilBufferAvailable>(stencil);
94 mPartialUpdateRequired = static_cast<Integration::PartialUpdateAvailable>(partialRendering);
95 mMultiSamplingLevel = msaa;
100 void EglGraphics::EglInitialize()
102 mEglSync = Utils::MakeUnique<EglSyncImplementation>();
103 mEglContextHelper = Utils::MakeUnique<EglContextHelperImplementation>();
104 mEglImplementation = Utils::MakeUnique<EglImplementation>(mMultiSamplingLevel, mDepthBufferRequired, mStencilBufferRequired, mPartialUpdateRequired);
105 mEglImageExtensions = Utils::MakeUnique<EglImageExtensions>(mEglImplementation.get());
107 mEglSync->Initialize(mEglImplementation.get()); // The sync impl needs the EglDisplay
108 mEglContextHelper->Initialize(mEglImplementation.get()); // The context helper impl needs the EglContext
111 void EglGraphics::ConfigureSurface(Dali::RenderSurfaceInterface* surface)
113 // Try to use OpenGL es 3.0
114 // ChooseConfig returns false here when the device only support gles 2.0.
115 // Because eglChooseConfig with gles 3.0 setting fails when the device only support gles 2.0 and Our default setting is gles 3.0.
116 if(!mEglImplementation->ChooseConfig(true, COLOR_DEPTH_32))
118 // Retry to use OpenGL es 2.0
120 mEglImplementation->ChooseConfig(true, COLOR_DEPTH_32);
123 // Check whether surfaceless context is supported
124 bool isSurfacelessContextSupported = mEglImplementation->IsSurfacelessContextSupported();
125 SetIsSurfacelessContextSupported(isSurfacelessContextSupported);
127 RenderSurfaceInterface* currentSurface = nullptr;
128 if(isSurfacelessContextSupported)
130 // Create a surfaceless OpenGL context for shared resources
131 mEglImplementation->CreateContext();
132 mEglImplementation->MakeContextCurrent(EGL_NO_SURFACE, mEglImplementation->GetContext());
136 currentSurface = surface;
139 currentSurface->InitializeGraphics();
140 currentSurface->MakeContextCurrent();
144 mGLES->ContextCreated();
145 SetGlesVersion(mGLES->GetGlesVersion());
148 void EglGraphics::Shutdown()
150 mEglImplementation->TerminateGles();
153 void EglGraphics::Destroy()
157 GlImplementation& EglGraphics::GetGlesInterface()
162 Integration::GlAbstraction& EglGraphics::GetGlAbstraction() const
164 DALI_ASSERT_DEBUG(mGLES && "GLImplementation not created");
168 EglImplementation& EglGraphics::GetEglImplementation() const
170 DALI_ASSERT_DEBUG(mEglImplementation && "EGLImplementation not created");
171 return *mEglImplementation;
174 EglInterface& EglGraphics::GetEglInterface() const
176 DALI_ASSERT_DEBUG(mEglImplementation && "EGLImplementation not created");
177 EglInterface* eglInterface = mEglImplementation.get();
178 return *eglInterface;
181 EglSyncImplementation& EglGraphics::GetSyncImplementation()
183 DALI_ASSERT_DEBUG(mEglSync && "EglSyncImplementation not created");
187 EglContextHelperImplementation& EglGraphics::GetContextHelperImplementation()
189 DALI_ASSERT_DEBUG(mEglContextHelper && "EglContextHelperImplementation not created");
190 return *mEglContextHelper;
193 EglImageExtensions* EglGraphics::GetImageExtensions()
195 DALI_ASSERT_DEBUG(mEglImageExtensions && "EglImageExtensions not created");
196 return mEglImageExtensions.get();
199 Graphics::Controller& EglGraphics::GetController()
201 return mGraphicsController;
204 void EglGraphics::CacheConfigurations(ConfigurationManager& configurationManager)
206 mGLES->SetIsAdvancedBlendEquationSupported(configurationManager.IsAdvancedBlendEquationSupported());
207 mGLES->SetShadingLanguageVersion(configurationManager.GetShadingLanguageVersion());
210 } // namespace Adaptor
211 } // namespace Internal