FBO/Texture access synchronization for multiple contexts 92/210092/6
authorRichard Huang <r.huang@samsung.com>
Thu, 11 Jul 2019 14:39:22 +0000 (15:39 +0100)
committerRichard Huang <r.huang@samsung.com>
Wed, 17 Jul 2019 13:56:41 +0000 (14:56 +0100)
Change-Id: I5fde582e2da41542931a9c62dae6fc188f44b4e6

12 files changed:
automated-tests/src/dali-adaptor/dali-test-suite-utils/test-application.cpp
automated-tests/src/dali-adaptor/dali-test-suite-utils/test-application.h
automated-tests/src/dali-adaptor/dali-test-suite-utils/test-gl-context-helper-abstraction.h [new file with mode: 0644]
dali/internal/adaptor/common/adaptor-impl.cpp
dali/internal/graphics/file.list
dali/internal/graphics/gles/egl-context-helper-implementation.cpp [new file with mode: 0644]
dali/internal/graphics/gles/egl-context-helper-implementation.h [new file with mode: 0644]
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/window-system/common/window-render-surface.cpp

index d457916..6e41c42 100644 (file)
@@ -58,6 +58,7 @@ void TestApplication::CreateCore()
                                         mPlatformAbstraction,
                                         mGlAbstraction,
                                         mGlSyncAbstraction,
+                                        mGlContextHelperAbstraction,
                                         mDataRetentionPolicy,
                                         Integration::RenderToFrameBuffer::FALSE,
                                         Integration::DepthBufferAvailable::TRUE,
@@ -156,6 +157,11 @@ TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
   return mGlSyncAbstraction;
 }
 
+TestGlContextHelperAbstraction& TestApplication::GetGlContextHelperAbstraction()
+{
+  return mGlContextHelperAbstraction;
+}
+
 void TestApplication::ProcessEvent(const Integration::Event& event)
 {
   mCore->QueueEvent(event);
index 32447d6..cc694df 100644 (file)
@@ -22,6 +22,7 @@
 #include <test-platform-abstraction.h>
 #include "test-gl-sync-abstraction.h"
 #include "test-gl-abstraction.h"
+#include "test-gl-context-helper-abstraction.h"
 #include "test-render-controller.h"
 #include "test-render-surface.h"
 #include <dali/public-api/common/dali-common.h>
@@ -66,6 +67,7 @@ public:
   TestRenderController& GetRenderController();
   TestGlAbstraction& GetGlAbstraction();
   TestGlSyncAbstraction& GetGlSyncAbstraction();
+  TestGlContextHelperAbstraction& GetGlContextHelperAbstraction();
   void ProcessEvent(const Integration::Event& event);
   void SendNotification();
   bool Render( uint32_t intervalMilliseconds = DEFAULT_RENDER_INTERVAL, const char* location=NULL );
@@ -93,6 +95,7 @@ protected:
   TestRenderController      mRenderController;
   TestGlAbstraction         mGlAbstraction;
   TestGlSyncAbstraction     mGlSyncAbstraction;
+  TestGlContextHelperAbstraction mGlContextHelperAbstraction;
   TestRenderSurface*        mRenderSurface;
 
   Integration::UpdateStatus mStatus;
diff --git a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-gl-context-helper-abstraction.h b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-gl-context-helper-abstraction.h
new file mode 100644 (file)
index 0000000..0442f0d
--- /dev/null
@@ -0,0 +1,71 @@
+#ifndef TEST_GL_CONTEXT_HELPER_ABSTRACTION_H
+#define TEST_GL_CONTEXT_HELPER_ABSTRACTION_H
+
+/*
+ * Copyright (c) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali/integration-api/gl-context-helper-abstraction.h>
+
+namespace Dali
+{
+
+/**
+ * Class to emulate the GL context helper
+ */
+class DALI_CORE_API TestGlContextHelperAbstraction: public Integration::GlContextHelperAbstraction
+{
+public:
+  /**
+   * Constructor
+   */
+  TestGlContextHelperAbstraction() {};
+
+  /**
+   * Destructor
+   */
+  ~TestGlContextHelperAbstraction() {};
+
+  /**
+   * @brief Switch to the surfaceless GL context
+   */
+  virtual void MakeSurfacelessContextCurrent() {};
+
+  /**
+   * @brief Switch to the GL context of the specific render surface
+   * @param[in] surface The render surface
+   */
+  virtual void MakeContextCurrent( Integration::RenderSurface* surface ) {};
+
+  /**
+   * @brief Clear the GL context
+   */
+  virtual void MakeContextNull() {};
+
+  /**
+   * @brief Wait until all GL rendering calls for the current GL context are executed
+   */
+  virtual void WaitClient() {};
+private:
+
+  TestGlContextHelperAbstraction( const TestGlContextHelperAbstraction& ); ///< Undefined
+  TestGlContextHelperAbstraction& operator=( const TestGlContextHelperAbstraction& ); ///< Undefined
+};
+
+} // Dali
+
+#endif // TEST_GL_CONTEXT_HELPER_ABSTRACTION_H
index a4ab857..3588f3c 100755 (executable)
@@ -169,11 +169,13 @@ void Adaptor::Initialize( GraphicsFactory& graphicsFactory, Dali::Configuration:
 
   GlImplementation& mGLES = eglGraphics->GetGlesInterface();
   EglSyncImplementation& eglSyncImpl = eglGraphics->GetSyncImplementation();
+  EglContextHelperImplementation& eglContextHelperImpl = eglGraphics->GetContextHelperImplementation();
 
   mCore = Integration::Core::New( *this,
                                   *mPlatformAbstraction,
                                   mGLES,
                                   eglSyncImpl,
+                                  eglContextHelperImpl,
                                   dataRetentionPolicy ,
                                   ( 0u != mEnvironmentOptions->GetRenderToFboInterval() ) ? Integration::RenderToFrameBuffer::TRUE : Integration::RenderToFrameBuffer::FALSE,
                                   mGraphics->GetDepthBufferRequired(),
index 2b40768..0b8ef82 100644 (file)
@@ -5,6 +5,7 @@ adaptor_graphics_gles_src_files=\
     ${adaptor_graphics_dir}/gles/egl-debug.cpp \
     ${adaptor_graphics_dir}/gles/egl-implementation.cpp \
     ${adaptor_graphics_dir}/gles/egl-sync-implementation.cpp \
+    ${adaptor_graphics_dir}/gles/egl-context-helper-implementation.cpp \
     ${adaptor_graphics_dir}/gles/gl-extensions.cpp \
     ${adaptor_graphics_dir}/gles/gl-proxy-implementation.cpp \
     ${adaptor_graphics_dir}/gles/egl-graphics-factory.cpp \
diff --git a/dali/internal/graphics/gles/egl-context-helper-implementation.cpp b/dali/internal/graphics/gles/egl-context-helper-implementation.cpp
new file mode 100644 (file)
index 0000000..7990441
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali/internal/graphics/gles/egl-context-helper-implementation.h>
+
+// EXTERNAL INCLUDES
+
+#include <dali/integration-api/debug.h>
+
+// INTERNAL INCLUDES
+#include <dali/internal/graphics/gles/egl-implementation.h>
+
+namespace Dali
+{
+namespace Internal
+{
+namespace Adaptor
+{
+
+EglContextHelperImplementation::EglContextHelperImplementation()
+: mEglImplementation( NULL )
+{
+}
+
+void EglContextHelperImplementation::Initialize( EglImplementation* eglImpl )
+{
+  mEglImplementation = eglImpl;
+}
+
+void EglContextHelperImplementation::MakeSurfacelessContextCurrent()
+{
+  if ( mEglImplementation && mEglImplementation->IsSurfacelessContextSupported() )
+  {
+    mEglImplementation->MakeContextCurrent( EGL_NO_SURFACE, mEglImplementation->GetContext() );
+  }
+}
+
+void EglContextHelperImplementation::MakeContextCurrent( Integration::RenderSurface* surface )
+{
+  if ( mEglImplementation && surface )
+  {
+    surface->MakeContextCurrent();
+  }
+}
+
+void EglContextHelperImplementation::MakeContextNull()
+{
+  if ( mEglImplementation )
+  {
+    mEglImplementation->MakeContextNull();
+  }
+}
+
+void EglContextHelperImplementation::WaitClient()
+{
+  if ( mEglImplementation )
+  {
+    mEglImplementation->WaitClient();
+  }
+}
+
+} // namespace Dali
+} // namespace Internal
+} // namespace Adaptor
diff --git a/dali/internal/graphics/gles/egl-context-helper-implementation.h b/dali/internal/graphics/gles/egl-context-helper-implementation.h
new file mode 100644 (file)
index 0000000..ecdd772
--- /dev/null
@@ -0,0 +1,95 @@
+#ifndef DALI_INTERNAL_ADAPTOR_EGL_CONTEXT_HELPER_IMPLEMENTATION_H
+#define DALI_INTERNAL_ADAPTOR_EGL_CONTEXT_HELPER_IMPLEMENTATION_H
+
+/*
+ * Copyright (c) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <EGL/egl.h>
+#include <dali/integration-api/gl-context-helper-abstraction.h>
+
+// INTERNAL INCLUDES
+#include <dali/public-api/dali-adaptor-common.h>
+
+namespace Dali
+{
+
+namespace Integration
+{
+class RenderSurface;
+}
+
+namespace Internal
+{
+namespace Adaptor
+{
+
+class EglImplementation;
+
+/**
+ * EglContextHelperImplementation is a concrete implementation for GlContextHelperAbstraction.
+ * It provides helper functions to access EGL context APIs
+ */
+class EglContextHelperImplementation : public Integration::GlContextHelperAbstraction
+{
+public:
+  /**
+   * Constructor
+   */
+  EglContextHelperImplementation();
+
+  /**
+   * Destructor
+   */
+  virtual ~EglContextHelperImplementation() = default;
+
+  /**
+   * Initialize with the Egl implementation.
+   * @param[in] impl The EGL implementation (to access the EGL context)
+   */
+  void Initialize( EglImplementation* impl );
+
+  /**
+   * @copydoc Dali::Integration::GlContextHelperAbstraction::MakeSurfacelessContextCurrent()
+   */
+  virtual void MakeSurfacelessContextCurrent() override;
+
+  /**
+   * @copydoc Dali::Integration::GlContextHelperAbstraction::MakeContextCurrent()
+   */
+  virtual void MakeContextCurrent( Integration::RenderSurface* surface ) override;
+
+  /**
+   * @copydoc Dali::Integration::GlContextHelperAbstraction::MakeContextNull()
+   */
+  virtual void MakeContextNull() override;
+
+  /**
+   * @copydoc Dali::Integration::GlContextHelperAbstraction::WaitClient()
+   */
+  virtual void WaitClient() override;
+
+private:
+
+  EglImplementation* mEglImplementation; ///< Egl implementation (to access the EGL context)
+};
+
+} // namespace Adaptor
+} // namespace Internal
+} // namespace Dali
+
+#endif // DALI_INTERNAL_ADAPTOR_EGL_CONTEXT_HELPER_IMPLEMENTATION_H
index ace3e93..406e69c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
@@ -66,6 +66,8 @@ void EglGraphics::Initialize( EnvironmentOptions* environmentOptions )
   mMultiSamplingLevel = environmentOptions->GetMultiSamplingLevel();
 
   mEglSync = Utils::MakeUnique< EglSyncImplementation >();
+
+  mEglContextHelper = Utils::MakeUnique< EglContextHelperImplementation >();
 }
 
 EglInterface* EglGraphics::Create()
@@ -75,6 +77,8 @@ EglInterface* EglGraphics::Create()
 
   mEglSync->Initialize( mEglImplementation.get() ); // The sync impl needs the EglDisplay
 
+  mEglContextHelper->Initialize( mEglImplementation.get() ); // The context helper impl needs the EglContext
+
   return mEglImplementation.get();
 }
 
@@ -112,6 +116,12 @@ 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" );
index 45a6aca..ca98ca0 100644 (file)
@@ -29,7 +29,7 @@
 #include <dali/internal/graphics/gles/egl-implementation.h>
 #include <dali/internal/graphics/common/egl-image-extensions.h>
 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
-
+#include <dali/internal/graphics/gles/egl-context-helper-implementation.h>
 
 namespace Dali
 {
@@ -107,6 +107,12 @@ public:
   EglSyncImplementation& GetSyncImplementation();
 
   /**
+   * Gets the implementation of GlContextHelperAbstraction for EGL.
+   * @return The implementation of GlContextHelperAbstraction for EGL.
+   */
+  EglContextHelperImplementation& GetContextHelperImplementation();
+
+  /**
    * @copydoc Dali::Internal::Adaptor::GraphicsInterface::GetDepthBufferRequired()
    */
   Integration::DepthBufferAvailable& GetDepthBufferRequired();
@@ -138,6 +144,7 @@ private:
   std::unique_ptr< EglImplementation > mEglImplementation;      ///< EGL implementation
   std::unique_ptr< EglImageExtensions > mEglImageExtensions;    ///< EGL image extension
   std::unique_ptr< EglSyncImplementation > mEglSync;            ///< GlSyncAbstraction implementation for EGL
+  std::unique_ptr< EglContextHelperImplementation > mEglContextHelper; ///< GlContextHelperAbstraction implementation for EGL
 
   int mMultiSamplingLevel;                                      ///< The multiple sampling level
 };
index 68d7925..7004f17 100755 (executable)
@@ -220,11 +220,6 @@ void EglImplementation::MakeContextCurrent( EGLSurface eglSurface, EGLContext eg
 
   if(mIsOwnSurface)
   {
-    if( mCurrentEglContext != EGL_NO_CONTEXT )
-    {
-      glFinish();
-    }
-
     eglMakeCurrent( mEglDisplay, eglSurface, eglSurface, eglContext );
 
     mCurrentEglContext = eglContext;
@@ -252,11 +247,6 @@ void EglImplementation::MakeCurrent( EGLNativePixmapType pixmap, EGLSurface eglS
 
   if(mIsOwnSurface)
   {
-    if( mCurrentEglContext != EGL_NO_CONTEXT )
-    {
-      glFinish();
-    }
-
     eglMakeCurrent( mEglDisplay, eglSurface, eglSurface, mEglContext );
 
     mCurrentEglContext = mEglContext;
@@ -577,6 +567,15 @@ bool EglImplementation::IsSurfacelessContextSupported() const
   return mIsSurfacelessContextSupported;
 }
 
+void EglImplementation::WaitClient()
+{
+  // Wait for EGL to finish executing all rendering calls for the current context
+  if ( eglWaitClient() != EGL_TRUE )
+  {
+    TEST_EGL_ERROR("eglWaitClient");
+  }
+}
+
 } // namespace Adaptor
 
 } // namespace Internal
index 2901b9e..1c9cab3 100644 (file)
@@ -205,6 +205,11 @@ public:
    */
   bool IsSurfacelessContextSupported() const;
 
+  /**
+   * @brief Wait until all rendering calls for the currently context are executed
+   */
+  void WaitClient();
+
 private:
 
   Vector<EGLint>       mContextAttribs;
index f9eb552..82dccec 100644 (file)
@@ -416,12 +416,6 @@ void WindowRenderSurface::PostRender( bool renderToFbo, bool replacingSurface, b
     {
       mRenderNotification->Trigger();
     }
-
-    if ( eglImpl.IsSurfacelessContextSupported() )
-    {
-      // Switch to the shared context after rendering this surface
-      eglImpl.MakeContextCurrent( EGL_NO_SURFACE, eglImpl.GetContext() );
-    }
   }
 }