[Tizen] Fix surface deletion order issue 88/289888/1 accepted/tizen/7.0/unified/20230330.014302
authorHeeyong Song <heeyong.song@samsung.com>
Wed, 22 Feb 2023 08:37:31 +0000 (17:37 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Wed, 15 Mar 2023 06:37:48 +0000 (15:37 +0900)
Change-Id: I1fb3a2934ed6a36553421f002d6cc7821abc45dc

dali/integration-api/scene.cpp
dali/integration-api/scene.h
dali/internal/event/common/scene-impl.cpp
dali/internal/event/common/scene-impl.h
dali/internal/render/common/render-manager.cpp
dali/internal/update/common/scene-graph-scene.h
dali/internal/update/manager/update-manager.cpp

index 26d72ac..b1781a9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 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.
@@ -124,6 +124,11 @@ void Scene::SurfaceReplaced()
   GetImplementation(*this).SurfaceReplaced();
 }
 
+void Scene::RemoveSceneObject()
+{
+  GetImplementation(*this).RemoveSceneObject();
+}
+
 void Scene::Discard()
 {
   GetImplementation(*this).Discard();
index 4a851a2..5e4a3e4 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_SCENE_H
 
 /*
- * Copyright (c) 2022 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.
@@ -230,6 +230,11 @@ public:
   void SurfaceReplaced();
 
   /**
+   * @brief Removes the scene graph object.
+   */
+  void RemoveSceneObject();
+
+  /**
    * @brief Discards this Scene from the Core.
    */
   void Discard();
index 56ed507..d60e48b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 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.
@@ -65,12 +65,6 @@ Scene::Scene()
 
 Scene::~Scene()
 {
-  if(EventThreadServices::IsCoreRunning() && mSceneObject)
-  {
-    ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal();
-    RemoveSceneMessage(tls->GetUpdateManager(), *mSceneObject);
-  }
-
   if(mDefaultCamera)
   {
     // its enough to release the handle so the object is released
@@ -241,9 +235,19 @@ void Scene::SurfaceReplaced()
   }
 }
 
+void Scene::RemoveSceneObject()
+{
+  if(EventThreadServices::IsCoreRunning() && mSceneObject)
+  {
+    ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal();
+    RemoveSceneMessage(tls->GetUpdateManager(), *mSceneObject);
+    mSceneObject = nullptr;
+  }
+}
+
 void Scene::Discard()
 {
-  if(ThreadLocalStorage::Created())
+  if(EventThreadServices::IsCoreRunning())
   {
     ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal();
     tls->RemoveScene(this);
@@ -310,22 +314,23 @@ void Scene::SurfaceRotated(float width, float height, int32_t windowOrientation,
 
 int32_t Scene::GetCurrentSurfaceOrientation() const
 {
-  return mSceneObject->GetSurfaceOrientation();
+  return mSceneObject ? mSceneObject->GetSurfaceOrientation() : 0;
 }
 
 int32_t Scene::GetCurrentScreenOrientation() const
 {
-  return mSceneObject->GetScreenOrientation();
+  return mSceneObject ? mSceneObject->GetScreenOrientation() : 0;
 }
 
 const Rect<int32_t>& Scene::GetCurrentSurfaceRect() const
 {
-  return mSceneObject->GetSurfaceRect();
+  static Rect<int32_t> emptyRect{};
+  return mSceneObject ? mSceneObject->GetSurfaceRect() : emptyRect;
 }
 
 void Scene::ChangedSurface(float width, float height, int32_t windowOrientation, int32_t screenOrientation)
 {
-  bool changedOrientation = false;
+  bool          changedOrientation = false;
   Rect<int32_t> newSize(0, 0, static_cast<int32_t>(width), static_cast<int32_t>(height)); // truncated
   mSize.width  = width;
   mSize.height = height;
@@ -336,7 +341,7 @@ void Scene::ChangedSurface(float width, float height, int32_t windowOrientation,
   }
 
   mSurfaceOrientation = windowOrientation;
-  mScreenOrientation = screenOrientation;
+  mScreenOrientation  = screenOrientation;
 
   // Calculates the aspect ratio, near and far clipping planes, field of view and camera Z position.
   mDefaultCamera->SetPerspectiveProjection(mSize);
@@ -372,12 +377,12 @@ void Scene::ChangedSurface(float width, float height, int32_t windowOrientation,
 
 bool Scene::IsSurfaceRectChanged() const
 {
-  return mSceneObject->IsSurfaceRectChanged();
+  return mSceneObject ? mSceneObject->IsSurfaceRectChanged() : false;
 }
 
 bool Scene::IsRotationCompletedAcknowledgementSet() const
 {
-  return mSceneObject->IsRotationCompletedAcknowledgementSet();
+  return mSceneObject ? mSceneObject->IsRotationCompletedAcknowledgementSet() : false;
 }
 
 void Scene::SetRotationCompletedAcknowledgement()
@@ -455,12 +460,18 @@ void Scene::AddFramePresentedCallback(std::unique_ptr<CallbackBase> callback, in
 
 void Scene::GetFrameRenderedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
 {
-  mSceneObject->GetFrameRenderedCallback(callbacks);
+  if(mSceneObject)
+  {
+    mSceneObject->GetFrameRenderedCallback(callbacks);
+  }
 }
 
 void Scene::GetFramePresentedCallback(Dali::Integration::Scene::FrameCallbackContainer& callbacks)
 {
-  mSceneObject->GetFramePresentedCallback(callbacks);
+  if(mSceneObject)
+  {
+    mSceneObject->GetFramePresentedCallback(callbacks);
+  }
 }
 
 Integration::Scene::KeyEventSignalType& Scene::KeyEventSignal()
index cda29a2..c431fee 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_SCENE_H
 
 /*
- * Copyright (c) 2022 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.
@@ -133,6 +133,11 @@ public:
   void SurfaceReplaced();
 
   /**
+   * @copydoc Dali::Integration::Scene::RemoveSceneObject
+   */
+  void RemoveSceneObject();
+
+  /**
    * @copydoc Dali::Integration::Scene::Discard
    */
   void Discard();
index 961830f..2bd20b7 100644 (file)
@@ -486,7 +486,7 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector<Rect<int>>&
   Internal::Scene&   sceneInternal = GetImplementation(scene);
   SceneGraph::Scene* sceneObject   = sceneInternal.GetSceneObject();
 
-  if(sceneObject->IsRenderingSkipped())
+  if(!sceneObject || sceneObject->IsRenderingSkipped())
   {
     // We don't need to calculate dirty rects
     return;
@@ -729,9 +729,13 @@ void RenderManager::PreRender(Integration::Scene& scene, std::vector<Rect<int>>&
 
 void RenderManager::RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo)
 {
-  SceneGraph::Scene* sceneObject  = GetImplementation(scene).GetSceneObject();
-  Rect<int>          clippingRect = sceneObject->GetSurfaceRect();
+  SceneGraph::Scene* sceneObject = GetImplementation(scene).GetSceneObject();
+  if(!sceneObject)
+  {
+    return;
+  }
 
+  Rect<int> clippingRect = sceneObject->GetSurfaceRect();
   RenderScene(status, scene, renderToFbo, clippingRect);
 }
 
@@ -750,6 +754,10 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration::
 
   Internal::Scene&   sceneInternal = GetImplementation(scene);
   SceneGraph::Scene* sceneObject   = sceneInternal.GetSceneObject();
+  if(!sceneObject)
+  {
+    return;
+  }
 
   uint32_t count = sceneObject->GetRenderInstructions().Count(mImpl->renderBufferIndex);
 
index 8d5339e..278d3f8 100644 (file)
@@ -229,6 +229,14 @@ public:
   }
 
   /**
+   * Remove the render target of the surface
+   */
+  void RemoveSurfaceRenderTarget()
+  {
+    mRenderTarget.reset();
+  }
+
+  /**
    * Get the graphics render pass created for the scene
    *
    * @return the graphics render pass
index 1574b5d..c89ecbd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 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.
@@ -538,6 +538,8 @@ void UpdateManager::RemoveScene(Scene* scene)
   // Construct message in the render queue memory; note that delete should not be called on the return value
   new(slot) DerivedType(&mImpl->renderManager, &RenderManager::UninitializeScene, scene);
 
+  scene->RemoveSurfaceRenderTarget();
+
   for(auto&& sceneInfo : mImpl->scenes)
   {
     if(sceneInfo && sceneInfo->scene && sceneInfo->scene.Get() == scene)