Direct Rendering 34/276534/7
authorAdam Bialogonski <adam.b@samsung.com>
Fri, 17 Jun 2022 09:31:04 +0000 (10:31 +0100)
committerAdam Bialogonski <adam.b@samsung.com>
Mon, 4 Jul 2022 13:47:37 +0000 (14:47 +0100)
- Added passing the shared context to the callback
- The context created by the draw call now can share the GL resources

Change-Id: I20933ec4fbc7812b6589124bcd452ee7a7e317a6

automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.cpp
dali/internal/graphics/gles-impl/egl-graphics-controller.cpp
dali/internal/graphics/gles-impl/egl-graphics-controller.h
dali/internal/graphics/gles-impl/gles-context.cpp
dali/internal/window-system/common/gl-window-render-thread.cpp
dali/internal/window-system/tizen-wayland/native-image-surface-impl-ecore-wl.cpp

index 6a8eab4..fc176e5 100644 (file)
@@ -32,6 +32,8 @@
 #include <iostream>
 #include <sstream>
 
+#include <any>
+
 namespace Dali
 {
 std::ostream& operator<<(std::ostream& o, const Graphics::BufferCreateInfo& bufferCreateInfo)
@@ -696,6 +698,13 @@ void TestGraphicsController::ProcessCommandBuffer(TestGraphicsCommandBuffer& com
       case CommandType::DRAW_NATIVE:
       {
         auto info = &cmd.data.draw.drawNative.drawNativeInfo;
+
+        if(info->glesNativeInfo.eglSharedContextStoragePointer)
+        {
+          auto* anyContext = reinterpret_cast<std::any*>(info->glesNativeInfo.eglSharedContextStoragePointer);
+          *anyContext      = reinterpret_cast<void*>(0x12345678u);
+        }
+
         CallbackBase::ExecuteReturn<bool>(*info->callback, info->userData);
         break;
       }
index 0a22d9c..d7b8d33 100644 (file)
 #include <dali/internal/graphics/gles/egl-sync-implementation.h>
 #include <dali/public-api/common/dali-common.h>
 
+#include <dali/internal/graphics/gles/egl-graphics.h>
+
+#include <any>
+
 // Uncomment the following define to turn on frame dumping
 //#define ENABLE_COMMAND_BUFFER_FRAME_DUMP 1
 #include <dali/internal/graphics/gles-impl/egl-graphics-controller-debug.h>
@@ -308,6 +312,12 @@ void EglGraphicsController::ActivateResourceContext()
 {
   mCurrentContext = mContext.get();
   mCurrentContext->GlContextCreated();
+
+  if(!mSharedContext)
+  {
+    auto eglGraphics = dynamic_cast<Dali::Internal::Adaptor::EglGraphics*>(mGraphics);
+    mSharedContext   = eglGraphics->GetEglImplementation().GetContext();
+  }
 }
 
 void EglGraphicsController::ActivateSurfaceContext(Dali::RenderSurfaceInterface* surface)
@@ -589,6 +599,12 @@ void EglGraphicsController::ProcessCommandBuffer(const GLES::CommandBuffer& comm
 
         mCurrentContext->PrepareForNativeRendering();
 
+        if(info->glesNativeInfo.eglSharedContextStoragePointer)
+        {
+          auto* anyContext = reinterpret_cast<std::any*>(info->glesNativeInfo.eglSharedContextStoragePointer);
+          *anyContext      = mSharedContext;
+        }
+
         CallbackBase::ExecuteReturn<bool>(*info->callback, info->userData);
 
         mCurrentContext->RestoreFromNativeRendering();
index 6af7383..fd944d3 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_EGL_GRAPHICS_CONTROLLER_H
 
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -756,6 +756,16 @@ public:
     return mCurrentContext;
   }
 
+  /**
+   * @brief Returns EGL shared context
+   *
+   * @return valid EGL shared context
+   */
+  void* GetSharedContext() const
+  {
+    return mSharedContext;
+  }
+
 private:
   Integration::GlAbstraction*              mGlAbstraction{nullptr};
   Integration::GlContextHelperAbstraction* mGlContextHelperAbstraction{nullptr};
@@ -799,6 +809,8 @@ private:
   bool mIsShuttingDown{false}; ///< Indicates whether the controller is shutting down
 
   std::queue<const GLES::CommandBuffer*> mPresentationCommandBuffers{}; ///< Queue of reusable command buffers used by presentation engine
+
+  void* mSharedContext{nullptr}; ///< Shared EGL context
 };
 
 } // namespace Graphics
index f38ed4a..06de56a 100644 (file)
@@ -32,7 +32,6 @@
 #include <EGL/eglext.h>
 #include <map>
 
-
 namespace Dali::Graphics::GLES
 {
 struct Context::Impl
@@ -593,11 +592,23 @@ void Context::ResolveUniformBuffers()
 void Context::ResolveStandaloneUniforms()
 {
   // Find reflection for program
-  const auto program = static_cast<const GLES::Program*>(mImpl->mNewPipeline->GetCreateInfo().programState->program);
-  const auto ptr     = reinterpret_cast<const char*>(mImpl->mCurrentStandaloneUBOBinding.buffer->GetCPUAllocatedAddress()) + mImpl->mCurrentStandaloneUBOBinding.offset;
+  const GLES::Program* program{nullptr};
 
-  // Update program uniforms
-  program->GetImplementation()->UpdateStandaloneUniformBlock(ptr);
+  if(mImpl->mNewPipeline)
+  {
+    program = static_cast<const GLES::Program*>(mImpl->mNewPipeline->GetCreateInfo().programState->program);
+  }
+  else if(mImpl->mCurrentPipeline)
+  {
+    program = static_cast<const GLES::Program*>(mImpl->mCurrentPipeline->GetCreateInfo().programState->program);
+  }
+
+  if(program)
+  {
+    const auto ptr = reinterpret_cast<const char*>(mImpl->mCurrentStandaloneUBOBinding.buffer->GetCPUAllocatedAddress()) + mImpl->mCurrentStandaloneUBOBinding.offset;
+    // Update program uniforms
+    program->GetImplementation()->UpdateStandaloneUniformBlock(ptr);
+  }
 }
 
 void Context::BeginRenderPass(const BeginRenderPassDescriptor& renderPassBegin)
@@ -1008,7 +1019,7 @@ void Context::PrepareForNativeRendering()
     attribs.push_back(version % 10);
     attribs.push_back(EGL_NONE);
 
-    mImpl->mNativeDrawContext = eglCreateContext(display, configs[configId], EGL_NO_CONTEXT, attribs.data());
+    mImpl->mNativeDrawContext = eglCreateContext(display, configs[configId], mImpl->mController.GetSharedContext(), attribs.data());
   }
 
   eglMakeCurrent(display, drawSurface, readSurface, mImpl->mNativeDrawContext);
index 9ed0a54..532d61d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -117,8 +117,8 @@ void GlWindowRenderThread::Stop()
 }
 
 void GlWindowRenderThread::RegisterGlCallbacks(CallbackBase* initCallback,
-                                              CallbackBase* renderFrameCallback,
-                                              CallbackBase* terminateCallback)
+                                               CallbackBase* renderFrameCallback,
+                                               CallbackBase* terminateCallback)
 {
   mGLInitCallback        = std::unique_ptr<CallbackBase>(initCallback);
   mGLRenderFrameCallback = std::unique_ptr<CallbackBase>(renderFrameCallback);
index 770072a..52fe66d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -65,46 +65,22 @@ NativeImageSurfaceEcoreWl::NativeImageSurfaceEcoreWl(Dali::NativeImageSourceQueu
 
 bool NativeImageSurfaceEcoreWl::SetGraphicsConfig(bool depth, bool stencil, int msaa, int version)
 {
-  bool featureFlag = false;
-  int  error       = SYSTEM_INFO_ERROR_NONE;
-
-  if(version == 30)
-  {
-    error = system_info_get_platform_bool("http://tizen.org/feature/opengles.version.3_0", &featureFlag);
-  }
-  else if(version == 20)
+  // Setup the configuration
+  // The GLES version support is done by the caller
+  mDepth   = depth;
+  mStencil = stencil;
+  if(mMSAA == 0)
   {
-    error = system_info_get_platform_bool("http://tizen.org/feature/opengles.version.2_0", &featureFlag);
+    //EGL_DONT_CARE is -1
+    mMSAA = -1;
   }
   else
   {
-    DALI_LOG_ERROR("version is not valid");
-    return false;
-  }
-
-  if(error != SYSTEM_INFO_ERROR_NONE)
-  {
-    DALI_LOG_ERROR("Can't check platform feature.\n");
-    return false;
-  }
-
-  if(featureFlag)
-  {
-    mDepth   = depth;
-    mStencil = stencil;
-    if(mMSAA == 0)
-    {
-      //EGL_DONT_CARE is -1
-      mMSAA = -1;
-    }
-    else
-    {
-      mMSAA = msaa;
-    }
-    mGLESVersion = version;
+    mMSAA = msaa;
   }
+  mGLESVersion = version;
 
-  return featureFlag;
+  return true;
 }
 
 Any NativeImageSurfaceEcoreWl::GetNativeRenderable()