Support surfaceless context for OpenGL ES 2 52/204552/3
authorRichard Huang <r.huang@samsung.com>
Wed, 24 Apr 2019 09:10:28 +0000 (10:10 +0100)
committerRichard Huang <r.huang@samsung.com>
Wed, 24 Apr 2019 09:46:35 +0000 (10:46 +0100)
Change-Id: I6a40a226231fc640ed9bb3722748dbaa6ef072c4

dali/internal/adaptor/common/combined-update-render-controller.cpp
dali/internal/graphics/gles/egl-graphics.cpp
dali/internal/graphics/gles/egl-graphics.h
dali/internal/graphics/gles/egl-implementation.cpp
dali/internal/graphics/gles/egl-implementation.h
dali/internal/graphics/gles/gl-implementation.h

index 93e1d9e..5c11f02 100644 (file)
@@ -431,18 +431,29 @@ void CombinedUpdateRenderController::UpdateRenderThread()
   EglInterface* eglInterface = &eglGraphics->GetEglInterface();
 
   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( *eglInterface );
   EglInterface* eglInterface = &eglGraphics->GetEglInterface();
 
   Internal::Adaptor::EglImplementation& eglImpl = static_cast<Internal::Adaptor::EglImplementation&>( *eglInterface );
+
   // 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.
   // 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 ) )
+  if( !eglImpl.ChooseConfig( true, COLOR_DEPTH_32 ) )
+  {
+    // Retry to use OpenGL es 2.0
+    eglGraphics->SetGlesVersion( 20 );
+    eglImpl.ChooseConfig( true, COLOR_DEPTH_32 );
+  }
+
+  // Check whether surfaceless context is supported
+  bool isSurfacelessContextSupported = eglImpl.IsSurfacelessContextSupported();
+  eglGraphics->SetIsSurfacelessContextSupported( isSurfacelessContextSupported );
+
+  if ( isSurfacelessContextSupported )
   {
     // Create a surfaceless OpenGL context for shared resources
     eglImpl.CreateContext();
     eglImpl.MakeContextCurrent( EGL_NO_SURFACE, eglImpl.GetContext() );
   }
   {
     // Create a surfaceless OpenGL context for shared resources
     eglImpl.CreateContext();
     eglImpl.MakeContextCurrent( EGL_NO_SURFACE, eglImpl.GetContext() );
   }
-  else // Retry to use OpenGL es 2.0
+  else
   {
   {
-    eglGraphics->SetGlesVersion( 20 );
     currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
     if( currentSurface )
     {
     currentSurface = mAdaptorInterfaces.GetRenderSurfaceInterface();
     if( currentSurface )
     {
@@ -583,7 +594,7 @@ void CombinedUpdateRenderController::UpdateRenderThread()
       }
     }
 
       }
     }
 
-    if( eglImpl.GetGlesVersion() >= 30 )
+    if( eglImpl.IsSurfacelessContextSupported() )
     {
       // Make the shared surfaceless context as current before rendering
       eglImpl.MakeContextCurrent( EGL_NO_SURFACE, eglImpl.GetContext() );
     {
       // Make the shared surfaceless context as current before rendering
       eglImpl.MakeContextCurrent( EGL_NO_SURFACE, eglImpl.GetContext() );
index a54b9ed..ace3e93 100644 (file)
@@ -44,6 +44,11 @@ void EglGraphics::SetGlesVersion( const int32_t glesVersion )
   mGLES->SetGlesVersion( glesVersion );
 }
 
   mGLES->SetGlesVersion( glesVersion );
 }
 
+void EglGraphics::SetIsSurfacelessContextSupported( const bool isSupported )
+{
+  mGLES->SetIsSurfacelessContextSupported( isSupported );
+}
+
 void EglGraphics::Initialize( EnvironmentOptions* environmentOptions )
 {
   if( environmentOptions->GetGlesCallTime() > 0 )
 void EglGraphics::Initialize( EnvironmentOptions* environmentOptions )
 {
   if( environmentOptions->GetGlesCallTime() > 0 )
index 717ffc2..f02d673 100644 (file)
@@ -72,6 +72,12 @@ public:
   void SetGlesVersion( const int32_t glesVersion );
 
   /**
   void SetGlesVersion( const int32_t glesVersion );
 
   /**
+   * Set whether the surfaceless context is supported
+   * @param[in] isSupported Whether the surfaceless context is supported
+   */
+  void SetIsSurfacelessContextSupported( const bool isSupported );
+
+  /**
    * Gets the GL abstraction
    * @return The GL abstraction
    */
    * Gets the GL abstraction
    * @return The GL abstraction
    */
index 6580a6f..91d4fab 100755 (executable)
@@ -20,6 +20,7 @@
 #include <dali/internal/graphics/gles/egl-implementation.h>
 
 // EXTERNAL INCLUDES
 #include <dali/internal/graphics/gles/egl-implementation.h>
 
 // EXTERNAL INCLUDES
+#include <sstream>
 #include <dali/integration-api/debug.h>
 #include <dali/public-api/common/dali-vector.h>
 
 #include <dali/integration-api/debug.h>
 #include <dali/public-api/common/dali-vector.h>
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wold-style-cast"
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wold-style-cast"
 
+namespace
+{
+  const std::string EGL_KHR_SURFACELESS_CONTEXT = "EGL_KHR_surfaceless_context";
+}
+
 namespace Dali
 {
 
 namespace Dali
 {
 
@@ -71,7 +77,8 @@ EglImplementation::EglImplementation( int multiSamplingLevel,
   mIsOwnSurface( true ),
   mIsWindow( true ),
   mDepthBufferRequired( depthBufferRequired == Integration::DepthBufferAvailable::TRUE ),
   mIsOwnSurface( true ),
   mIsWindow( true ),
   mDepthBufferRequired( depthBufferRequired == Integration::DepthBufferAvailable::TRUE ),
-  mStencilBufferRequired( stencilBufferRequired == Integration::StencilBufferAvailable::TRUE )
+  mStencilBufferRequired( stencilBufferRequired == Integration::StencilBufferAvailable::TRUE ),
+  mIsSurfacelessContextSupported( false )
 {
 }
 
 {
 }
 
@@ -107,6 +114,19 @@ bool EglImplementation::InitializeGles( EGLNativeDisplayType display, bool isOwn
     mIsOwnSurface = isOwnSurface;
   }
 
     mIsOwnSurface = isOwnSurface;
   }
 
+  // Query EGL extensions to check whether surfaceless context is supported
+  const char* const extensionStr = eglQueryString( mEglDisplay, EGL_EXTENSIONS );
+  std::istringstream stream(extensionStr);
+  std::string currentExtension;
+  while ( std::getline( stream, currentExtension, ' ' ) )
+  {
+    if ( currentExtension == EGL_KHR_SURFACELESS_CONTEXT )
+    {
+      mIsSurfacelessContextSupported = true;
+      break;
+    }
+  }
+
   // We want to display this information all the time, so use the LogMessage directly
   Integration::Log::LogMessage(Integration::Log::DebugInfo, "EGL Information\n"
       "            Vendor:        %s\n"
   // We want to display this information all the time, so use the LogMessage directly
   Integration::Log::LogMessage(Integration::Log::DebugInfo, "EGL Information\n"
       "            Vendor:        %s\n"
@@ -116,7 +136,7 @@ bool EglImplementation::InitializeGles( EGLNativeDisplayType display, bool isOwn
       eglQueryString( mEglDisplay, EGL_VENDOR ),
       eglQueryString( mEglDisplay, EGL_VERSION ),
       eglQueryString( mEglDisplay, EGL_CLIENT_APIS ),
       eglQueryString( mEglDisplay, EGL_VENDOR ),
       eglQueryString( mEglDisplay, EGL_VERSION ),
       eglQueryString( mEglDisplay, EGL_CLIENT_APIS ),
-      eglQueryString( mEglDisplay, EGL_EXTENSIONS ));
+      extensionStr);
 
   return mGlesInitialized;
 }
 
   return mGlesInitialized;
 }
@@ -538,6 +558,11 @@ int32_t EglImplementation::GetGlesVersion() const
   return mGlesVersion;
 }
 
   return mGlesVersion;
 }
 
+bool EglImplementation::IsSurfacelessContextSupported() const
+{
+  return mIsSurfacelessContextSupported;
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
 } // namespace Adaptor
 
 } // namespace Internal
index 7c2a69b..03c35f4 100644 (file)
@@ -199,6 +199,12 @@ public:
    */
   int32_t GetGlesVersion() const;
 
    */
   int32_t GetGlesVersion() const;
 
+  /**
+   * Returns whether the surfaceless context is supported
+   * @return true if the surfaceless context is supported
+   */
+  bool IsSurfacelessContextSupported() const;
+
 private:
 
   Vector<EGLint>       mContextAttribs;
 private:
 
   Vector<EGLint>       mContextAttribs;
@@ -232,6 +238,7 @@ private:
   bool                 mIsWindow;
   bool                 mDepthBufferRequired;
   bool                 mStencilBufferRequired;
   bool                 mIsWindow;
   bool                 mDepthBufferRequired;
   bool                 mStencilBufferRequired;
+  bool                 mIsSurfacelessContextSupported;
 };
 
 } // namespace Adaptor
 };
 
 } // namespace Adaptor
index be32476..8c279f4 100644 (file)
@@ -48,7 +48,8 @@ class GlImplementation : public Dali::Integration::GlAbstraction
 
 public:
   GlImplementation()
 
 public:
   GlImplementation()
-    : mGlesVersion( 30 )
+    : mGlesVersion( 30 ),
+      mIsSurfacelessContextSupported( false )
   {
     mImpl.reset( new Gles3Implementation() );
   }
   {
     mImpl.reset( new Gles3Implementation() );
   }
@@ -81,9 +82,14 @@ public:
     }
   }
 
     }
   }
 
+  void SetIsSurfacelessContextSupported( const bool isSupported )
+  {
+    mIsSurfacelessContextSupported = isSupported;
+  }
+
   bool IsSurfacelessContextSupported() const
   {
   bool IsSurfacelessContextSupported() const
   {
-    return ( mGlesVersion >= 30 );
+    return mIsSurfacelessContextSupported;
   }
 
   bool TextureRequiresConverting( const GLenum imageGlFormat, const GLenum textureGlFormat, const bool isSubImage ) const
   }
 
   bool TextureRequiresConverting( const GLenum imageGlFormat, const GLenum textureGlFormat, const bool isSubImage ) const
@@ -1333,6 +1339,7 @@ public:
 
 private:
   int32_t mGlesVersion;
 
 private:
   int32_t mGlesVersion;
+  bool mIsSurfacelessContextSupported;
   std::unique_ptr<GlesAbstraction> mImpl;
 };
 
   std::unique_ptr<GlesAbstraction> mImpl;
 };