[Tizen] CleanUp gles version setter + Get exact FBO MSAA sample level
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles / egl-graphics.cpp
index d19f824..d1f79e9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -54,18 +54,6 @@ EglGraphics::~EglGraphics()
 {
 }
 
-void EglGraphics::SetGlesVersion(const int32_t glesVersion)
-{
-  if(mEglImplementation)
-  {
-    mEglImplementation->SetGlesVersion(glesVersion);
-  }
-
-  mGLES->SetGlesVersion(glesVersion);
-
-  mGraphicsController.SetGLESVersion(static_cast<Graphics::GLES::GLESVersion>(glesVersion));
-}
-
 void EglGraphics::SetIsSurfacelessContextSupported(const bool isSupported)
 {
   mGLES->SetIsSurfacelessContextSupported(isSupported);
@@ -73,24 +61,36 @@ void EglGraphics::SetIsSurfacelessContextSupported(const bool isSupported)
 
 void EglGraphics::ActivateResourceContext()
 {
-  mGraphicsController.ActivateResourceContext();
-
   if(mEglImplementation && mEglImplementation->IsSurfacelessContextSupported())
   {
     // Make the shared surfaceless context as current before rendering
     mEglImplementation->MakeContextCurrent(EGL_NO_SURFACE, mEglImplementation->GetContext());
   }
+
+  mGraphicsController.ActivateResourceContext();
 }
 
 void EglGraphics::ActivateSurfaceContext(Dali::RenderSurfaceInterface* surface)
 {
-  mGraphicsController.ActivateSurfaceContext(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()
@@ -140,7 +140,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);
   }
 
@@ -153,20 +158,24 @@ 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()
@@ -236,6 +245,7 @@ Graphics::Controller& EglGraphics::GetController()
 void EglGraphics::CacheConfigurations(ConfigurationManager& configurationManager)
 {
   mGLES->SetIsAdvancedBlendEquationSupported(configurationManager.IsAdvancedBlendEquationSupported());
+  mGLES->SetIsMultisampledRenderToTextureSupported(configurationManager.IsMultisampledRenderToTextureSupported());
   mGLES->SetShadingLanguageVersion(configurationManager.GetShadingLanguageVersion());
 }