[dali_2.3.28] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles / egl-graphics.cpp
index 9688fba..0d46a0c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
 
 // INTERNAL INCLUDES
 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
+#include <dali/integration-api/debug.h>
 #include <dali/internal/system/common/configuration-manager.h>
 #include <dali/internal/system/common/environment-options.h>
 #include <dali/internal/window-system/common/display-utils.h> // For Utils::MakeUnique
@@ -54,16 +55,6 @@ EglGraphics::~EglGraphics()
 {
 }
 
-void EglGraphics::SetGlesVersion(const int32_t glesVersion)
-{
-  if(mEglImplementation)
-  {
-    mEglImplementation->SetGlesVersion(glesVersion);
-  }
-
-  mGLES->SetGlesVersion(glesVersion);
-}
-
 void EglGraphics::SetIsSurfacelessContextSupported(const bool isSupported)
 {
   mGLES->SetIsSurfacelessContextSupported(isSupported);
@@ -76,6 +67,31 @@ void EglGraphics::ActivateResourceContext()
     // Make the shared surfaceless context as current before rendering
     mEglImplementation->MakeContextCurrent(EGL_NO_SURFACE, mEglImplementation->GetContext());
   }
+
+  mGraphicsController.ActivateResourceContext();
+}
+
+void EglGraphics::ActivateSurfaceContext(Dali::RenderSurfaceInterface* surface)
+{
+  if(surface)
+  {
+    surface->InitializeGraphics();
+    surface->MakeContextCurrent();
+  }
+
+  mGraphicsController.ActivateSurfaceContext(surface);
+}
+
+void EglGraphics::PostRender()
+{
+  ActivateResourceContext();
+
+  if(mGraphicsController.GetCurrentContext())
+  {
+    mGraphicsController.GetCurrentContext()->InvalidateDepthStencilBuffers();
+  }
+
+  mGraphicsController.PostRender();
 }
 
 void EglGraphics::SetFirstFrameAfterResume()
@@ -91,7 +107,7 @@ void EglGraphics::Initialize()
   EglInitialize();
 
   // Sync and context helper require EGL to be initialized first (can't execute in the constructor)
-  mGraphicsController.Initialize(*mEglSync.get(), *mEglContextHelper.get());
+  mGraphicsController.Initialize(*mEglSync.get(), *this);
 }
 
 void EglGraphics::Initialize(bool depth, bool stencil, bool partialRendering, int msaa)
@@ -107,12 +123,10 @@ void EglGraphics::Initialize(bool depth, bool stencil, bool partialRendering, in
 void EglGraphics::EglInitialize()
 {
   mEglSync            = Utils::MakeUnique<EglSyncImplementation>();
-  mEglContextHelper   = Utils::MakeUnique<EglContextHelperImplementation>();
   mEglImplementation  = Utils::MakeUnique<EglImplementation>(mMultiSamplingLevel, mDepthBufferRequired, mStencilBufferRequired, mPartialUpdateRequired);
   mEglImageExtensions = Utils::MakeUnique<EglImageExtensions>(mEglImplementation.get());
 
-  mEglSync->Initialize(mEglImplementation.get());          // The sync impl needs the EglDisplay
-  mEglContextHelper->Initialize(mEglImplementation.get()); // The context helper impl needs the EglContext
+  mEglSync->Initialize(mEglImplementation.get()); // The sync impl needs the EglDisplay
 }
 
 void EglGraphics::ConfigureSurface(Dali::RenderSurfaceInterface* surface)
@@ -125,7 +139,12 @@ void EglGraphics::ConfigureSurface(Dali::RenderSurfaceInterface* surface)
   if(!mEglImplementation->ChooseConfig(true, COLOR_DEPTH_32))
   {
     // Retry to use OpenGL es 2.0
-    SetGlesVersion(20);
+    mEglImplementation->SetGlesVersion(20);
+
+    // Mark gles that we will use gles 2.0 version.
+    // After this call, we will not change mGLES version anymore.
+    mGLES->SetGlesVersion(20);
+
     mEglImplementation->ChooseConfig(true, COLOR_DEPTH_32);
   }
 
@@ -138,32 +157,41 @@ void EglGraphics::ConfigureSurface(Dali::RenderSurfaceInterface* surface)
   {
     // Create a surfaceless OpenGL context for shared resources
     mEglImplementation->CreateContext();
-    mEglImplementation->MakeContextCurrent(EGL_NO_SURFACE, mEglImplementation->GetContext());
+    ActivateResourceContext();
   }
   else
   {
     currentSurface = surface;
     if(currentSurface)
     {
-      currentSurface->InitializeGraphics();
-      currentSurface->MakeContextCurrent();
+      ActivateSurfaceContext(currentSurface);
     }
   }
 
-  mGLES->ContextCreated();
-  SetGlesVersion(mGLES->GetGlesVersion());
+  mGLES->ContextCreated(); // After this call, we can know exact gles version.
+  auto glesVersion = mGLES->GetGlesVersion();
+
+  // Set more detail GLES version to egl and graphics controller.
+  // Note. usually we don't need EGL client's minor version. So don't need to choose config one more time.
+  mEglImplementation->SetGlesVersion(glesVersion);
+  mGraphicsController.SetGLESVersion(static_cast<Graphics::GLES::GLESVersion>(glesVersion));
 }
 
 void EglGraphics::Shutdown()
 {
   if(mEglImplementation)
   {
+    // Shutdown controller
+    mGraphicsController.Shutdown();
+
+    // Terminate GLES
     mEglImplementation->TerminateGles();
   }
 }
 
 void EglGraphics::Destroy()
 {
+  mGraphicsController.Destroy();
 }
 
 GlImplementation& EglGraphics::GetGlesInterface()
@@ -196,12 +224,6 @@ EglSyncImplementation& EglGraphics::GetSyncImplementation()
   return *mEglSync;
 }
 
-EglContextHelperImplementation& EglGraphics::GetContextHelperImplementation()
-{
-  DALI_ASSERT_DEBUG(mEglContextHelper && "EglContextHelperImplementation not created");
-  return *mEglContextHelper;
-}
-
 EglImageExtensions* EglGraphics::GetImageExtensions()
 {
   DALI_ASSERT_DEBUG(mEglImageExtensions && "EglImageExtensions not created");
@@ -216,9 +238,24 @@ Graphics::Controller& EglGraphics::GetController()
 void EglGraphics::CacheConfigurations(ConfigurationManager& configurationManager)
 {
   mGLES->SetIsAdvancedBlendEquationSupported(configurationManager.IsAdvancedBlendEquationSupported());
+  mGLES->SetIsMultisampledRenderToTextureSupported(configurationManager.IsMultisampledRenderToTextureSupported());
   mGLES->SetShadingLanguageVersion(configurationManager.GetShadingLanguageVersion());
 }
 
+void EglGraphics::FrameStart()
+{
+  mGraphicsController.FrameStart();
+}
+
+void EglGraphics::LogMemoryPools()
+{
+  std::size_t graphicsCapacity = mGraphicsController.GetCapacity();
+  DALI_LOG_RELEASE_INFO(
+    "EglGraphics:\n"
+    "  GraphicsController Capacity: %lu\n",
+    graphicsCapacity);
+}
+
 } // namespace Adaptor
 } // namespace Internal
 } // namespace Dali