Revert "[Tizen] Ensure we don't touch shutdowned EglGraphicsController"
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 10 Oct 2024 07:15:31 +0000 (16:15 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Thu, 10 Oct 2024 07:15:31 +0000 (16:15 +0900)
This reverts commit 8e50e717164686f6fd9bb0af2f3d93cbc302c7a1.

15 files changed:
dali/internal/graphics/gles-impl/egl-graphics-controller.cpp
dali/internal/graphics/gles-impl/egl-graphics-controller.h
dali/internal/graphics/gles-impl/egl-sync-object.cpp
dali/internal/graphics/gles-impl/gles-graphics-buffer.cpp
dali/internal/graphics/gles-impl/gles-graphics-framebuffer.cpp
dali/internal/graphics/gles-impl/gles-graphics-pipeline-cache.cpp
dali/internal/graphics/gles-impl/gles-graphics-pipeline.cpp
dali/internal/graphics/gles-impl/gles-graphics-program.cpp
dali/internal/graphics/gles-impl/gles-graphics-shader.cpp
dali/internal/graphics/gles-impl/gles-graphics-texture.cpp
dali/internal/graphics/gles-impl/gles-sync-object.cpp
dali/internal/graphics/gles-impl/gles-sync-pool.cpp
dali/internal/graphics/gles-impl/gles2-graphics-memory.cpp
dali/internal/graphics/gles-impl/gles3-graphics-memory.cpp
dali/internal/graphics/tizen/egl-sync-implementation-tizen.cpp

index 178d22de6e9767aa1d1341f600b5df2364862a75..3478d680eed475066a153b1b0d04f7b0bf2e6828 100644 (file)
@@ -70,21 +70,8 @@ struct GLESDeleter
 
   void operator()(T* object)
   {
-    // GLES object deleter should skip discard queue if controller shutting down
-    if(DALI_LIKELY(!EglGraphicsController::IsShuttingDown()))
-    {
-      // Discard resource (add it to discard queue)
-      object->DiscardResource();
-    }
-    else
-    {
-      // Destroy and delete object otherwise
-      if(DALI_LIKELY(object))
-      {
-        object->DestroyResource();
-      }
-      delete object;
-    }
+    // Discard resource (add it to discard queue)
+    object->DiscardResource();
   }
 };
 
@@ -143,15 +130,8 @@ T0* CastObject(T1* apiObject)
 const uint32_t TEXTURE_UPLOAD_MAX_BUFER_SIZE_MB = 1;
 
 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_EGL, false);
-
-bool gIsShuttingDown = true; ///< Global static flag to ensure that we have single graphics controller instance per each UpdateRender thread loop.
 } // namespace
 
-bool EglGraphicsController::IsShuttingDown()
-{
-  return gIsShuttingDown;
-}
-
 EglGraphicsController::EglGraphicsController()
 : mTextureDependencyChecker(*this),
   mSyncPool(*this)
@@ -171,7 +151,6 @@ EglGraphicsController::~EglGraphicsController()
 void EglGraphicsController::InitializeGLES(Integration::GlAbstraction& glAbstraction)
 {
   DALI_LOG_RELEASE_INFO("Initializing Graphics Controller Phase 1\n");
-
   mGlAbstraction  = &glAbstraction;
   mContext        = std::make_unique<GLES::Context>(*this, mGlAbstraction);
   mCurrentContext = mContext.get();
@@ -183,9 +162,6 @@ void EglGraphicsController::Initialize(Integration::GraphicsSyncAbstraction& syn
   DALI_LOG_RELEASE_INFO("Initializing Graphics Controller Phase 2\n");
   auto* syncImplPtr = static_cast<Internal::Adaptor::EglSyncImplementation*>(&syncImplementation);
 
-  DALI_ASSERT_ALWAYS(gIsShuttingDown && "Don't initialize Phase 2 EglGraphicsController twice");
-  gIsShuttingDown = false;
-
   mEglSyncImplementation = syncImplPtr;
   mGraphics              = &graphicsInterface;
 }
@@ -217,28 +193,6 @@ void EglGraphicsController::WaitIdle()
   Flush();
 }
 
-void EglGraphicsController::Shutdown()
-{
-  DALI_ASSERT_ALWAYS(!gIsShuttingDown && "Don't call EglGraphicsController::Shutdown twice");
-  gIsShuttingDown = true;
-
-  // Final flush
-  Flush();
-
-  if(mContext)
-  {
-    mContext->GlContextDestroyed();
-  }
-
-  for(auto&& context : mSurfaceContexts)
-  {
-    if(context.second)
-    {
-      context.second->GlContextDestroyed();
-    }
-  }
-}
-
 void EglGraphicsController::PresentRenderTarget(RenderTarget* renderTarget)
 {
   GLES::CommandBuffer* presentCommandBuffer{nullptr};
index 95a3b06480f5f768a24413a83499e139b743cfdd..54a4e8e89615cd9d4258888bd1b18e9f41e778c9 100644 (file)
@@ -68,11 +68,6 @@ class TextureDependencyChecker;
 class EglGraphicsController : public Graphics::Controller
 {
 public:
-  /**
-   * @brief Get whether is graphics controller shutting down or not.
-   */
-  static bool IsShuttingDown();
-
   /**
    * @brief Constructor
    */
@@ -147,7 +142,26 @@ public:
   /**
    * @copydoc Dali::Graphics::Shutdown()
    */
-  void Shutdown() override;
+  void Shutdown() override
+  {
+    mIsShuttingDown = true;
+
+    // Final flush
+    Flush();
+
+    if(mContext)
+    {
+      mContext->GlContextDestroyed();
+    }
+
+    for(auto&& context : mSurfaceContexts)
+    {
+      if(context.second)
+      {
+        context.second->GlContextDestroyed();
+      }
+    }
+  }
 
   /**
    * @copydoc Dali::Graphics::Destroy()
@@ -336,7 +350,7 @@ public: // ResourceId relative API.
 public:
   [[nodiscard]] Integration::GlAbstraction* GetGL() const
   {
-    if(DALI_UNLIKELY(IsShuttingDown()))
+    if(mIsShuttingDown)
     {
       return nullptr;
     }
@@ -726,6 +740,11 @@ public:
     mGLESVersion = glesVersion;
   }
 
+  bool IsShuttingDown() const
+  {
+    return mIsShuttingDown;
+  }
+
   /**
    * @brief Reset texture cache in the contexts
    */
@@ -872,6 +891,8 @@ private:
   GLES::GLESVersion mGLESVersion{GLES::GLESVersion::GLES_20}; ///< Runtime supported GLES version
   uint32_t          mTextureUploadTotalCPUMemoryUsed{0u};
 
+  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
index bfcccd6a10db0ffbccd66fc9dec9f544cf1c8968..44dd8f41444bf5494bceb2eb12c5a0197b0f44ac 100644 (file)
@@ -38,12 +38,6 @@ SyncObject::~SyncObject()
 
 void SyncObject::DestroyResource()
 {
-  if(DALI_UNLIKELY(EglGraphicsController::IsShuttingDown()))
-  {
-    return;
-  }
-  mEglSyncImplementation.DestroySyncObject(mEglSyncObject);
-  mEglSyncObject = nullptr;
 }
 
 bool SyncObject::InitializeResource()
@@ -57,7 +51,8 @@ void SyncObject::DiscardResource()
 {
   // Called from custom deleter.
   // Don't use discard queue, drop immediately.
-  DestroyResource();
+  mEglSyncImplementation.DestroySyncObject(mEglSyncObject);
+  mEglSyncObject = nullptr;
 }
 
 bool SyncObject::IsSynced()
index 107e4212b69dedd0e04d4da0ddf8aa5048098001..d2fbaaf32823e12114c4a7e2afccffbde481f950 100644 (file)
@@ -125,11 +125,6 @@ void Buffer::InitializeCPUBuffer()
 
 void Buffer::InitializeGPUBuffer()
 {
-  if(DALI_UNLIKELY(EglGraphicsController::IsShuttingDown()))
-  {
-    return;
-  }
-
   auto context = mController.GetCurrentContext();
   auto gl      = mController.GetGL();
   if(!gl || !context)
@@ -165,13 +160,10 @@ void Buffer::DestroyResource()
   // Deestroy GPU allocation
   else
   {
-    if(DALI_LIKELY(!EglGraphicsController::IsShuttingDown()))
+    auto gl = mController.GetGL();
+    if(gl)
     {
-      auto gl = mController.GetGL();
-      if(gl)
-      {
-        gl->DeleteBuffers(1, &mBufferId);
-      }
+      gl->DeleteBuffers(1, &mBufferId);
     }
   }
 }
index e7b83313887947eba79987c03b1d7f9fc1d78e96..6695fbf7cfec87bc9631f7663ef9e4de438a57a0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 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.
@@ -179,26 +179,23 @@ bool Framebuffer::InitializeResource()
 
 void Framebuffer::DestroyResource()
 {
-  if(DALI_LIKELY(!EglGraphicsController::IsShuttingDown()))
+  auto context = mController.GetCurrentContext();
+  auto gl      = mController.GetGL();
+  if(gl && context && mInitialized)
   {
-    auto context = mController.GetCurrentContext();
-    auto gl      = mController.GetGL();
-    if(gl && context && mInitialized)
+    if(mDepthBufferId)
     {
-      if(mDepthBufferId)
-      {
-        gl->DeleteRenderbuffers(1, &mDepthBufferId);
-      }
-      if(mStencilBufferId)
-      {
-        gl->DeleteRenderbuffers(1, &mStencilBufferId);
-      }
+      gl->DeleteRenderbuffers(1, &mDepthBufferId);
+    }
+    if(mStencilBufferId)
+    {
+      gl->DeleteRenderbuffers(1, &mStencilBufferId);
+    }
 
-      context->DeleteFramebuffers(1, &mFramebufferId);
+    context->DeleteFramebuffers(1, &mFramebufferId);
 
-      mFramebufferId = 0u;
-      mInitialized   = false;
-    }
+    mFramebufferId = 0u;
+    mInitialized   = false;
   }
 }
 
index fdbd2a5c60e2bdb6c726b3e3015a0185697a5ed8..183efb6e02e1222fc82c6abdbd92d7312e13ce9c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 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.
@@ -39,18 +39,26 @@ struct CachedObjectDeleter
 
   void operator()(T* object)
   {
-    // Discard resource (add it to discard queue) if controller is not shutting down
-    if(DALI_LIKELY(!EglGraphicsController::IsShuttingDown()))
+    // Discard resource (add it to discard queue)
+    object->DiscardResource();
+  }
+};
+
+template<>
+struct CachedObjectDeleter<GLES::Program>
+{
+  CachedObjectDeleter() = default;
+
+  void operator()(GLES::Program* object)
+  {
+    // Program deleter should skip discard queue if controller shutting down
+    if(!object->GetController().IsShuttingDown())
     {
       object->DiscardResource();
     }
     else
     {
-      // Destroy and delete object otherwise
-      if(DALI_LIKELY(object))
-      {
-        object->DestroyResource();
-      }
+      // delete object otherwise
       delete object;
     }
   }
index 19d9a7dca3467659d0fd280f24bf2186ae86cfe7..a927fadc81123c830f7c3842fcbf9018a070d41e 100644 (file)
@@ -91,11 +91,6 @@ auto& PipelineImpl::GetController() const
 
 void PipelineImpl::Bind(const uint32_t glProgram) const
 {
-  if(DALI_UNLIKELY(EglGraphicsController::IsShuttingDown()))
-  {
-    return; // Early out if shutting down
-  }
-
   if(auto gl = GetController().GetGL())
   {
     gl->UseProgram(glProgram);
index ec3f3afdb7eca500d718ba56799879c4529e9a6a..0da8eb0d0d0f6087e54125b0819b3238b305e609 100644 (file)
@@ -122,11 +122,6 @@ ProgramImpl::~ProgramImpl() = default;
 
 bool ProgramImpl::Destroy()
 {
-  if(DALI_UNLIKELY(EglGraphicsController::IsShuttingDown()))
-  {
-    return false; // Early out if shutting down
-  }
-
   if(mImpl->glProgram)
   {
     auto gl = mImpl->controller.GetGL();
@@ -357,11 +352,6 @@ void ProgramImpl::UpdateStandaloneUniformBlock(const char* ptr)
 
   const auto& extraInfos = reflection.GetStandaloneUniformExtraInfo();
 
-  if(DALI_UNLIKELY(EglGraphicsController::IsShuttingDown()))
-  {
-    return; // Early out if shutting down
-  }
-
   auto* gl = GetController().GetGL();
   if(!gl)
   {
index 740d907893735e0556bf14de6659c9f5cbd24834..2ee3020fd36a31ebe3ccfec2d2512ab9323f64d4 100644 (file)
@@ -168,7 +168,7 @@ ShaderImpl::ShaderImpl(const Graphics::ShaderCreateInfo& createInfo, Graphics::E
 
 ShaderImpl::~ShaderImpl()
 {
-  if(DALI_LIKELY(!EglGraphicsController::IsShuttingDown()))
+  if(!mImpl->controller.IsShuttingDown())
   {
     mImpl->Destroy();
   }
@@ -283,11 +283,6 @@ Shader::~Shader()
 {
   if(!mShader->Release())
   {
-    if(DALI_UNLIKELY(EglGraphicsController::IsShuttingDown()))
-    {
-      return; // Early out if shutting down
-    }
-
     GetImplementation()->GetController().GetPipelineCache().MarkShaderCacheFlushRequired();
   }
 }
@@ -299,7 +294,11 @@ Shader::~Shader()
 
 void Shader::DiscardResource()
 {
-  GetImplementation()->GetController().DiscardResource(this);
+  auto& controller = GetImplementation()->GetController();
+  if(!controller.IsShuttingDown())
+  {
+    controller.DiscardResource(this);
+  }
 }
 
 uint32_t Shader::GetGLSLVersion() const
index 7471f5c6c6888fd95283c07b062fa2cb23c72b51..cd4b66d0c8226f7658e0342093e2d8aba325281b 100644 (file)
@@ -310,26 +310,20 @@ bool Texture::InitializeTexture()
 
 void Texture::DestroyResource()
 {
-  if(DALI_LIKELY(!EglGraphicsController::IsShuttingDown()))
+  auto gl = mController.GetGL();
+  if(!gl)
   {
-    auto gl = mController.GetGL();
-    if(!gl)
-    {
-      return;
-    }
-
-    // This is a proper destructor
-    if(mTextureId)
-    {
-      gl->DeleteTextures(1, &mTextureId);
-    }
+    return;
+  }
 
-    // TODO : Shouldn't we call DestroyResource even if shutting down?
-    // For now, we use EglExtensions API at DestroyResource. So just block for now.
-    if(mCreateInfo.nativeImagePtr)
-    {
-      mCreateInfo.nativeImagePtr->DestroyResource();
-    }
+  // This is a proper destructor
+  if(mTextureId)
+  {
+    gl->DeleteTextures(1, &mTextureId);
+  }
+  if(mCreateInfo.nativeImagePtr)
+  {
+    mCreateInfo.nativeImagePtr->DestroyResource();
   }
 }
 
index bfaccecf43cf18ea35756d89ee87c08d675c409e..1d1bc1197d43c8adfd3e987c27de0fbc3e4113a8 100644 (file)
@@ -36,15 +36,6 @@ SyncObject::~SyncObject()
 
 void SyncObject::DestroyResource()
 {
-  if(DALI_LIKELY(!EglGraphicsController::IsShuttingDown()))
-  {
-    auto gl = mController.GetGL();
-    if(gl)
-    {
-      gl->DeleteSync(mGlSyncObject);
-    }
-    mGlSyncObject = 0;
-  }
 }
 
 bool SyncObject::InitializeResource()
@@ -62,7 +53,12 @@ void SyncObject::DiscardResource()
 {
   // Called from custom deleter.
   // Don't use discard queue, drop immediately.
-  DestroyResource();
+  auto gl = mController.GetGL();
+  if(gl)
+  {
+    gl->DeleteSync(mGlSyncObject);
+  }
+  mGlSyncObject = 0;
 }
 
 bool SyncObject::IsSynced()
index 6077414f47cc86cf88636c74df336922ede1f578..c4cd3991697fadc14fee037395b80660b8c03fc1 100644 (file)
@@ -52,7 +52,7 @@ AgingSyncObject::AgingSyncObject(Graphics::EglGraphicsController& controller, co
 
 AgingSyncObject::~AgingSyncObject()
 {
-  if(DALI_LIKELY(!EglGraphicsController::IsShuttingDown()))
+  if(!controller.IsShuttingDown())
   {
     if(egl)
     {
index 6d3f1492b766780fdd3ebec4b0149c63aa719053..6ad22f8c47d06af32bf59e0986272bcec640a9c2 100644 (file)
@@ -78,31 +78,28 @@ void* Memory2::LockRegion(uint32_t offset, uint32_t size)
 
 void Memory2::Unlock(bool flush)
 {
-  if(DALI_LIKELY(!EglGraphicsController::IsShuttingDown()))
+  if(auto gl = mController.GetGL())
   {
-    if(auto gl = mController.GetGL())
+    // for buffer...
+    if(mMapObjectType == MapObjectType::BUFFER && mMappedPointer)
     {
-      // for buffer...
-      if(mMapObjectType == MapObjectType::BUFFER && mMappedPointer)
+      auto buffer = static_cast<GLES::Buffer*>(mMapBufferInfo.buffer);
+      if(!buffer->IsCPUAllocated())
       {
-        auto buffer = static_cast<GLES::Buffer*>(mMapBufferInfo.buffer);
-        if(!buffer->IsCPUAllocated())
-        {
-          buffer->Bind(BufferUsage::VERTEX_BUFFER);
-          gl->BufferSubData(GL_ARRAY_BUFFER, GLintptr(mMapBufferInfo.offset), GLsizeiptr(mMapBufferInfo.size), mMappedPointer);
-        }
+        buffer->Bind(BufferUsage::VERTEX_BUFFER);
+        gl->BufferSubData(GL_ARRAY_BUFFER, GLintptr(mMapBufferInfo.offset), GLsizeiptr(mMapBufferInfo.size), mMappedPointer);
       }
+    }
 
-      if(mIsAllocatedLocally)
-      {
-        free(mMappedPointer);
-        mMappedPointer = nullptr;
-      }
+    if(mIsAllocatedLocally)
+    {
+      free(mMappedPointer);
+      mMappedPointer = nullptr;
+    }
 
-      if(flush)
-      {
-        Flush();
-      }
+    if(flush)
+    {
+      Flush();
     }
   }
 }
index c0aec279bbc3707dd7674216ddbe250c0812f093..18e78616a7f19669b3ff21f32746ecc7d4295ba2 100644 (file)
@@ -49,28 +49,25 @@ Memory3::~Memory3()
 
 void* Memory3::LockRegion(uint32_t offset, uint32_t size)
 {
-  if(DALI_LIKELY(!EglGraphicsController::IsShuttingDown()))
+  if(auto gl = mController.GetGL())
   {
-    if(auto gl = mController.GetGL())
+    if(mMapObjectType == MapObjectType::BUFFER)
     {
-      if(mMapObjectType == MapObjectType::BUFFER)
-      {
-        auto buffer = static_cast<GLES::Buffer*>(mMapBufferInfo.buffer);
+      auto buffer = static_cast<GLES::Buffer*>(mMapBufferInfo.buffer);
 
-        if(buffer->IsCPUAllocated())
-        {
-          using Ptr      = char*;
-          mMappedPointer = Ptr(buffer->GetCPUAllocatedAddress()) + offset;
-        }
-        else
-        {
-          gl->BindBuffer(GL_COPY_WRITE_BUFFER, buffer->GetGLBuffer());
-          void* ptr      = nullptr;
-          ptr            = gl->MapBufferRange(GL_COPY_WRITE_BUFFER, GLintptr(mMapBufferInfo.offset), GLsizeiptr(mMapBufferInfo.size), GL_MAP_WRITE_BIT);
-          mMappedPointer = ptr;
-        }
-        return mMappedPointer;
+      if(buffer->IsCPUAllocated())
+      {
+        using Ptr      = char*;
+        mMappedPointer = Ptr(buffer->GetCPUAllocatedAddress()) + offset;
+      }
+      else
+      {
+        gl->BindBuffer(GL_COPY_WRITE_BUFFER, buffer->GetGLBuffer());
+        void* ptr      = nullptr;
+        ptr            = gl->MapBufferRange(GL_COPY_WRITE_BUFFER, GLintptr(mMapBufferInfo.offset), GLsizeiptr(mMapBufferInfo.size), GL_MAP_WRITE_BIT);
+        mMappedPointer = ptr;
       }
+      return mMappedPointer;
     }
   }
   return nullptr;
@@ -78,24 +75,21 @@ void* Memory3::LockRegion(uint32_t offset, uint32_t size)
 
 void Memory3::Unlock(bool flush)
 {
-  if(DALI_LIKELY(!EglGraphicsController::IsShuttingDown()))
+  if(auto gl = mController.GetGL())
   {
-    if(auto gl = mController.GetGL())
+    if(mMapObjectType == MapObjectType::BUFFER && mMappedPointer)
     {
-      if(mMapObjectType == MapObjectType::BUFFER && mMappedPointer)
+      auto buffer = static_cast<GLES::Buffer*>(mMapBufferInfo.buffer);
+      if(!buffer->IsCPUAllocated())
       {
-        auto buffer = static_cast<GLES::Buffer*>(mMapBufferInfo.buffer);
-        if(!buffer->IsCPUAllocated())
-        {
-          gl->BindBuffer(GL_COPY_WRITE_BUFFER, buffer->GetGLBuffer());
-          gl->UnmapBuffer(GL_COPY_WRITE_BUFFER);
-        }
+        gl->BindBuffer(GL_COPY_WRITE_BUFFER, buffer->GetGLBuffer());
+        gl->UnmapBuffer(GL_COPY_WRITE_BUFFER);
       }
+    }
 
-      if(flush)
-      {
-        Flush();
-      }
+    if(flush)
+    {
+      Flush();
     }
 
     mMappedPointer = nullptr;
index a334a91d94318bc3922a0b39235eb975f8d69267..41c771a3ced6c4ce19521a639129148cc550911a 100644 (file)
@@ -158,11 +158,6 @@ EglSyncImplementation::EglSyncImplementation()
 
 EglSyncImplementation::~EglSyncImplementation()
 {
-  for(auto& syncObject : mSyncObjects)
-  {
-    delete static_cast<EglSyncObject*>(syncObject);
-  }
-  mSyncObjects.Clear();
 }
 
 void EglSyncImplementation::Initialize(EglImplementation* eglImpl)