Support surfaceless context for OpenGL ES 2
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / combined-update-render-controller.cpp
index ace0a18..5c11f02 100644 (file)
@@ -424,8 +424,6 @@ void CombinedUpdateRenderController::UpdateRenderThread()
 
   RenderSurfaceInterface* currentSurface = nullptr;
 
-#if DALI_GLES_VERSION >= 30
-
   GraphicsInterface& graphics = mAdaptorInterfaces.GetGraphicsInterface();
   EglGraphics* eglGraphics = static_cast<EglGraphics *>(&graphics);
 
@@ -433,22 +431,36 @@ void CombinedUpdateRenderController::UpdateRenderThread()
   EglInterface* eglInterface = &eglGraphics->GetEglInterface();
 
   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( *eglInterface );
-  eglImpl.ChooseConfig( true, COLOR_DEPTH_32 ); // Always use this for shared context???
 
-  // Create a surfaceless OpenGL context for shared resources
-  eglImpl.CreateContext();
-  eglImpl.MakeContextCurrent( EGL_NO_SURFACE, eglImpl.GetContext() );
+  // Try to use OpenGL es 3.0
+  // ChooseConfig returns false here when the device only support gles 2.0.
+  // Because eglChooseConfig with gles 3.0 setting fails when the device only support gles 2.0 and Our default setting is gles 3.0.
+  if( !eglImpl.ChooseConfig( true, COLOR_DEPTH_32 ) )
+  {
+    // Retry to use OpenGL es 2.0
+    eglGraphics->SetGlesVersion( 20 );
+    eglImpl.ChooseConfig( true, COLOR_DEPTH_32 );
+  }
 
-#else // DALI_GLES_VERSION >= 30
+  // Check whether surfaceless context is supported
+  bool isSurfacelessContextSupported = eglImpl.IsSurfacelessContextSupported();
+  eglGraphics->SetIsSurfacelessContextSupported( isSurfacelessContextSupported );
 
-  currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
-  if( currentSurface )
+  if ( isSurfacelessContextSupported )
   {
-    currentSurface->InitializeGraphics();
-    currentSurface->MakeContextCurrent();
+    // Create a surfaceless OpenGL context for shared resources
+    eglImpl.CreateContext();
+    eglImpl.MakeContextCurrent( EGL_NO_SURFACE, eglImpl.GetContext() );
+  }
+  else
+  {
+    currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
+    if( currentSurface )
+    {
+      currentSurface->InitializeGraphics();
+      currentSurface->MakeContextCurrent();
+    }
   }
-
-#endif
 
   // Tell core it has a context
   mCore.ContextCreated();
@@ -582,10 +594,11 @@ void CombinedUpdateRenderController::UpdateRenderThread()
       }
     }
 
-#if DALI_GLES_VERSION >= 30
-    // Make the shared surfaceless context as current before rendering
-    eglImpl.MakeContextCurrent( EGL_NO_SURFACE, eglImpl.GetContext() );
-#endif
+    if( eglImpl.IsSurfacelessContextSupported() )
+    {
+      // Make the shared surfaceless context as current before rendering
+      eglImpl.MakeContextCurrent( EGL_NO_SURFACE, eglImpl.GetContext() );
+    }
 
     Integration::RenderStatus renderStatus;