Fix crash issue when RenderEffect applied control is scene off 75/319675/4
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 30 Oct 2024 04:29:31 +0000 (13:29 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 30 Oct 2024 05:32:02 +0000 (14:32 +0900)
Change-Id: Ia2ff8a271cccfe7a1b4d8975e38cc17993678d95
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-RenderEffect.cpp
dali-toolkit/internal/controls/render-effects/blur-effect-impl.cpp
dali-toolkit/internal/controls/render-effects/blur-effect-impl.h

index f283741f25eb28e099160047fcea09e8cb45b097..e48f6f0e022e8614e2d4791eba8a36e25f63bee1 100644 (file)
@@ -531,8 +531,8 @@ int UtcDaliRenderEffectRenderTaskOrdering(void)
   ToolkitTestApplication application;
   tet_infoline("UtcDaliRenderEffectRenderTaskOrdering");
 
-  Integration::Scene scene = application.GetScene();
-  RenderTaskList taskList = scene.GetRenderTaskList();
+  Integration::Scene scene    = application.GetScene();
+  RenderTaskList     taskList = scene.GetRenderTaskList();
 
   Control control1 = Control::New();
   control1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
@@ -551,9 +551,9 @@ int UtcDaliRenderEffectRenderTaskOrdering(void)
   tet_printf("render task cnt after add : %d\n", taskList.GetTaskCount());
   DALI_TEST_EQUALS(4, taskList.GetTaskCount(), TEST_LOCATION);
 
-  Dali::RenderTask sourceTaskControl1 = taskList.GetTask(taskList.GetTaskCount() - 3);
+  Dali::RenderTask sourceTaskControl1         = taskList.GetTask(taskList.GetTaskCount() - 3);
   Dali::RenderTask horizontalBlurTaskControl1 = taskList.GetTask(taskList.GetTaskCount() - 2);
-  Dali::RenderTask verticalBlurTaskControl1 = taskList.GetTask(taskList.GetTaskCount() - 1);
+  Dali::RenderTask verticalBlurTaskControl1   = taskList.GetTask(taskList.GetTaskCount() - 1);
 
   tet_printf("order : %d\n", sourceTaskControl1.GetOrderIndex());
   tet_printf("order : %d\n", horizontalBlurTaskControl1.GetOrderIndex());
@@ -562,7 +562,7 @@ int UtcDaliRenderEffectRenderTaskOrdering(void)
   DALI_TEST_EQUALS(0, sourceTaskControl1.GetOrderIndex(), TEST_LOCATION);
   DALI_TEST_EQUALS(0, horizontalBlurTaskControl1.GetOrderIndex(), TEST_LOCATION);
   DALI_TEST_EQUALS(0, verticalBlurTaskControl1.GetOrderIndex(), TEST_LOCATION);
-  
+
   application.SendNotification();
 
   tet_printf("order af : %d\n", sourceTaskControl1.GetOrderIndex());
@@ -590,10 +590,9 @@ int UtcDaliRenderEffectRenderTaskOrdering(void)
 
   tet_printf("render task cnt after add : %d\n", taskList.GetTaskCount());
 
-  Dali::RenderTask sourceTaskControl2 = taskList.GetTask(taskList.GetTaskCount() - 3);
+  Dali::RenderTask sourceTaskControl2         = taskList.GetTask(taskList.GetTaskCount() - 3);
   Dali::RenderTask horizontalBlurTaskControl2 = taskList.GetTask(taskList.GetTaskCount() - 2);
-  Dali::RenderTask verticalBlurTaskControl2 = taskList.GetTask(taskList.GetTaskCount() - 1);
-
+  Dali::RenderTask verticalBlurTaskControl2   = taskList.GetTask(taskList.GetTaskCount() - 1);
 
   tet_printf("order after1 : %d\n", sourceTaskControl1.GetOrderIndex());
   tet_printf("order after1 : %d\n", horizontalBlurTaskControl1.GetOrderIndex());
@@ -606,7 +605,7 @@ int UtcDaliRenderEffectRenderTaskOrdering(void)
   DALI_TEST_EQUALS(0, sourceTaskControl2.GetOrderIndex(), TEST_LOCATION);
   DALI_TEST_EQUALS(0, horizontalBlurTaskControl2.GetOrderIndex(), TEST_LOCATION);
   DALI_TEST_EQUALS(0, verticalBlurTaskControl2.GetOrderIndex(), TEST_LOCATION);
-  
+
   application.SendNotification();
 
   tet_printf("order after2 : %d\n", sourceTaskControl1.GetOrderIndex());
@@ -627,9 +626,9 @@ int UtcDaliRenderEffectRenderTaskOrdering(void)
 
   control2.Add(control1);
 
-  sourceTaskControl1 = taskList.GetTask(taskList.GetTaskCount() - 3);
+  sourceTaskControl1         = taskList.GetTask(taskList.GetTaskCount() - 3);
   horizontalBlurTaskControl1 = taskList.GetTask(taskList.GetTaskCount() - 2);
-  verticalBlurTaskControl1 = taskList.GetTask(taskList.GetTaskCount() - 1);
+  verticalBlurTaskControl1   = taskList.GetTask(taskList.GetTaskCount() - 1);
 
   tet_printf("order after3 : %d\n", sourceTaskControl1.GetOrderIndex());
   tet_printf("order after3 : %d\n", horizontalBlurTaskControl1.GetOrderIndex());
@@ -665,6 +664,105 @@ int UtcDaliRenderEffectRenderTaskOrdering(void)
   DALI_TEST_EQUALS(INT32_MIN + 1, horizontalBlurTaskControl2.GetOrderIndex(), TEST_LOCATION);
   DALI_TEST_EQUALS(INT32_MIN + 2, verticalBlurTaskControl2.GetOrderIndex(), TEST_LOCATION);
 
+  control1.SetProperty(Actor::Property::VISIBLE, false);
+  control2.Unparent();
+
+  tet_printf("render task cnt after unparent : %d\n", taskList.GetTaskCount());
+
+  // The order index is not defined now.
+  tet_printf("order after5 : %d\n", sourceTaskControl1.GetOrderIndex());
+  tet_printf("order after5 : %d\n", horizontalBlurTaskControl1.GetOrderIndex());
+  tet_printf("order after5 : %d\n", verticalBlurTaskControl1.GetOrderIndex());
+
+  tet_printf("order after5 : %d\n", sourceTaskControl2.GetOrderIndex());
+  tet_printf("order after5 : %d\n", horizontalBlurTaskControl2.GetOrderIndex());
+  tet_printf("order after5 : %d\n", verticalBlurTaskControl2.GetOrderIndex());
+
+  application.SendNotification();
+
+  tet_printf("order after6 : %d\n", sourceTaskControl1.GetOrderIndex());
+  tet_printf("order after6 : %d\n", horizontalBlurTaskControl1.GetOrderIndex());
+  tet_printf("order after6 : %d\n", verticalBlurTaskControl1.GetOrderIndex());
+
+  tet_printf("order after6 : %d\n", sourceTaskControl2.GetOrderIndex());
+  tet_printf("order after6 : %d\n", horizontalBlurTaskControl2.GetOrderIndex());
+  tet_printf("order after6 : %d\n", verticalBlurTaskControl2.GetOrderIndex());
+
+  scene.Add(control2);
+
+  tet_printf("render task cnt after re-add : %d\n", taskList.GetTaskCount());
+
+  sourceTaskControl2         = taskList.GetTask(taskList.GetTaskCount() - 3);
+  horizontalBlurTaskControl2 = taskList.GetTask(taskList.GetTaskCount() - 2);
+  verticalBlurTaskControl2   = taskList.GetTask(taskList.GetTaskCount() - 1);
+
+  tet_printf("order after7 : %d\n", sourceTaskControl1.GetOrderIndex());
+  tet_printf("order after7 : %d\n", horizontalBlurTaskControl1.GetOrderIndex());
+  tet_printf("order after7 : %d\n", verticalBlurTaskControl1.GetOrderIndex());
+
+  tet_printf("order after7 : %d\n", sourceTaskControl2.GetOrderIndex());
+  tet_printf("order after7 : %d\n", horizontalBlurTaskControl2.GetOrderIndex());
+  tet_printf("order after7 : %d\n", verticalBlurTaskControl2.GetOrderIndex());
+
+  DALI_TEST_EQUALS(0, sourceTaskControl2.GetOrderIndex(), TEST_LOCATION);
+  DALI_TEST_EQUALS(0, horizontalBlurTaskControl2.GetOrderIndex(), TEST_LOCATION);
+  DALI_TEST_EQUALS(0, verticalBlurTaskControl2.GetOrderIndex(), TEST_LOCATION);
+
+  application.SendNotification();
+
+  tet_printf("order after8 : %d\n", sourceTaskControl1.GetOrderIndex());
+  tet_printf("order after8 : %d\n", horizontalBlurTaskControl1.GetOrderIndex());
+  tet_printf("order after8 : %d\n", verticalBlurTaskControl1.GetOrderIndex());
+
+  tet_printf("order after8 : %d\n", sourceTaskControl2.GetOrderIndex());
+  tet_printf("order after8 : %d\n", horizontalBlurTaskControl2.GetOrderIndex());
+  tet_printf("order after8 : %d\n", verticalBlurTaskControl2.GetOrderIndex());
+
+  DALI_TEST_EQUALS(INT32_MIN, sourceTaskControl2.GetOrderIndex(), TEST_LOCATION);
+  DALI_TEST_EQUALS(INT32_MIN + 1, horizontalBlurTaskControl2.GetOrderIndex(), TEST_LOCATION);
+  DALI_TEST_EQUALS(INT32_MIN + 2, verticalBlurTaskControl2.GetOrderIndex(), TEST_LOCATION);
+
+  control1.SetProperty(Actor::Property::VISIBLE, true);
+
+  tet_printf("render task cnt after change visible : %d\n", taskList.GetTaskCount());
+
+  sourceTaskControl1         = taskList.GetTask(taskList.GetTaskCount() - 3);
+  horizontalBlurTaskControl1 = taskList.GetTask(taskList.GetTaskCount() - 2);
+  verticalBlurTaskControl1   = taskList.GetTask(taskList.GetTaskCount() - 1);
+
+  tet_printf("order after9 : %d\n", sourceTaskControl1.GetOrderIndex());
+  tet_printf("order after9 : %d\n", horizontalBlurTaskControl1.GetOrderIndex());
+  tet_printf("order after9 : %d\n", verticalBlurTaskControl1.GetOrderIndex());
+
+  tet_printf("order after9 : %d\n", sourceTaskControl2.GetOrderIndex());
+  tet_printf("order after9 : %d\n", horizontalBlurTaskControl2.GetOrderIndex());
+  tet_printf("order after9 : %d\n", verticalBlurTaskControl2.GetOrderIndex());
+
+  DALI_TEST_EQUALS(0, sourceTaskControl1.GetOrderIndex(), TEST_LOCATION);
+  DALI_TEST_EQUALS(0, horizontalBlurTaskControl1.GetOrderIndex(), TEST_LOCATION);
+  DALI_TEST_EQUALS(0, verticalBlurTaskControl1.GetOrderIndex(), TEST_LOCATION);
+
+  DALI_TEST_EQUALS(INT32_MIN, sourceTaskControl2.GetOrderIndex(), TEST_LOCATION);
+  DALI_TEST_EQUALS(INT32_MIN + 1, horizontalBlurTaskControl2.GetOrderIndex(), TEST_LOCATION);
+  DALI_TEST_EQUALS(INT32_MIN + 2, verticalBlurTaskControl2.GetOrderIndex(), TEST_LOCATION);
+
+  application.SendNotification();
+
+  tet_printf("order after10 : %d\n", sourceTaskControl1.GetOrderIndex());
+  tet_printf("order after10 : %d\n", horizontalBlurTaskControl1.GetOrderIndex());
+  tet_printf("order after10 : %d\n", verticalBlurTaskControl1.GetOrderIndex());
+
+  tet_printf("order after10 : %d\n", sourceTaskControl2.GetOrderIndex());
+  tet_printf("order after10 : %d\n", horizontalBlurTaskControl2.GetOrderIndex());
+  tet_printf("order after10 : %d\n", verticalBlurTaskControl2.GetOrderIndex());
+
+  DALI_TEST_EQUALS(INT32_MIN + 3, sourceTaskControl1.GetOrderIndex(), TEST_LOCATION);
+  DALI_TEST_EQUALS(INT32_MIN + 4, horizontalBlurTaskControl1.GetOrderIndex(), TEST_LOCATION);
+  DALI_TEST_EQUALS(INT32_MIN + 5, verticalBlurTaskControl1.GetOrderIndex(), TEST_LOCATION);
+
+  DALI_TEST_EQUALS(INT32_MIN, sourceTaskControl2.GetOrderIndex(), TEST_LOCATION);
+  DALI_TEST_EQUALS(INT32_MIN + 1, horizontalBlurTaskControl2.GetOrderIndex(), TEST_LOCATION);
+  DALI_TEST_EQUALS(INT32_MIN + 2, verticalBlurTaskControl2.GetOrderIndex(), TEST_LOCATION);
+
   END_TEST;
 }
-
index fa64963d37625f507d389555f20bd17eb1e40f97..d006a35962514e382498a49489cadab506c5d3ba 100644 (file)
 #include <dali/devel-api/actors/actor-devel.h>
 #include <dali/devel-api/adaptor-framework/image-loading.h>
 #include <dali/integration-api/debug.h>
+#include <dali/public-api/actors/custom-actor-impl.h>
 #include <dali/public-api/images/image-operations.h>
 #include <dali/public-api/render-tasks/render-task-list.h>
 #include <dali/public-api/rendering/renderer.h>
 #include <dali/public-api/rendering/shader.h>
-#include <dali/public-api/actors/custom-actor-impl.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
@@ -152,24 +152,11 @@ void BlurEffectImpl::GetOffScreenRenderTasks(std::vector<Dali::RenderTask>& task
   tasks.clear();
   if(!isForward && mIsBackground)
   {
-    bool isExclusiveRequired = false;
-    Dali::Actor sourceActor = GetOwnerControl();
-    while(sourceActor.GetParent())
-    {
-      sourceActor = sourceActor.GetParent();
-      Toolkit::Control control = Toolkit::Control::DownCast(sourceActor);
-      if(control && GetImplementation(control).GetOffScreenRenderableType() == OffScreenRenderable::Type::FORWARD)
-      {
-        sourceActor = GetImplementation(control).GetOffScreenRenderableSourceActor();
-        isExclusiveRequired = GetImplementation(control).IsOffScreenRenderTaskExclusive();
-        break;
-      }
-    }
-    mSourceRenderTask.SetSourceActor(sourceActor);
-    mSourceRenderTask.SetExclusive(isExclusiveRequired);
-
     if(mSourceRenderTask)
     {
+      // Re-initialize source actor of rendertask since it might be changed.
+      // TODO : Should it be required always? Couldn't we skip it?
+      ApplyRenderTaskSourceActor(mSourceRenderTask, GetOwnerControl());
       tasks.push_back(mSourceRenderTask);
     }
     if(mHorizontalBlurTask)
@@ -316,6 +303,10 @@ void BlurEffectImpl::OnActivate()
   SetRendererTexture(renderer, mSourceFrameBuffer);
 
   ownerControl.Add(mInternalRoot);
+
+  // Reorder render task
+  // TODO : Can we remove this GetImplementation?
+  GetImplementation(ownerControl).RequestRenderTaskReorder();
 }
 
 void BlurEffectImpl::OnDeactivate()
@@ -381,19 +372,11 @@ void BlurEffectImpl::CreateRenderTasks(Integration::SceneHolder sceneHolder, con
 
   // draw input texture
   mSourceRenderTask = taskList.CreateTask();
-  if(mIsBackground)
-  {
-    mSourceRenderTask.SetSourceActor(sceneHolder.GetRootLayer());
-    mSourceRenderTask.RenderUntil(sourceControl);
-  }
-  else
-  {
-    mSourceRenderTask.SetSourceActor(sourceControl);
-  }
   mSourceRenderTask.SetCameraActor(mRenderFullSizeCamera);
   mSourceRenderTask.SetFrameBuffer(mInputBackgroundFrameBuffer);
   mSourceRenderTask.SetInputEnabled(false);
-  mSourceRenderTask.SetExclusive(false);
+
+  ApplyRenderTaskSourceActor(mSourceRenderTask, sourceControl);
 
   // Clear inputBackgroundTexture as scene holder background.
   mSourceRenderTask.SetClearEnabled(true);
@@ -426,6 +409,38 @@ void BlurEffectImpl::CreateRenderTasks(Integration::SceneHolder sceneHolder, con
   mVerticalBlurTask.SetClearColor(Color::TRANSPARENT);
 }
 
+void BlurEffectImpl::ApplyRenderTaskSourceActor(RenderTask sourceRenderTask, const Toolkit::Control sourceControl)
+{
+  if(DALI_UNLIKELY(!sourceRenderTask || !sourceControl))
+  {
+    return;
+  }
+
+  bool        isExclusiveRequired = false;
+  Dali::Actor sourceActor         = sourceControl;
+  Dali::Actor stopperActor        = Dali::Actor(); // Give empty handle to invalidate previous render until option.
+
+  if(mIsBackground)
+  {
+    stopperActor = sourceControl;
+    while(sourceActor && sourceActor.GetParent())
+    {
+      sourceActor              = sourceActor.GetParent();
+      Toolkit::Control control = Toolkit::Control::DownCast(sourceActor);
+      if(control && GetImplementation(control).GetOffScreenRenderableType() == OffScreenRenderable::Type::FORWARD)
+      {
+        sourceActor         = GetImplementation(control).GetOffScreenRenderableSourceActor();
+        isExclusiveRequired = GetImplementation(control).IsOffScreenRenderTaskExclusive();
+        break;
+      }
+    }
+  }
+
+  sourceRenderTask.SetExclusive(isExclusiveRequired);
+  sourceRenderTask.SetSourceActor(sourceActor);
+  sourceRenderTask.RenderUntil(stopperActor);
+}
+
 Vector2 BlurEffectImpl::GetTargetSizeForValidTexture() const
 {
   Vector2 size = GetTargetSize();
index def332405b35e899dac6841ec2dab72647bb32e4..647e4b2892aba1edbdb19a6b03fc3b9f5e20b59e 100644 (file)
@@ -131,6 +131,13 @@ private:
    */
   void CreateRenderTasks(Integration::SceneHolder sceneHolder, const Toolkit::Control sourceControl);
 
+  /**
+   * @brief Apply render tasks source actor, and some other options.
+   * @param[in] renderTask Target render task to change source actor and exclusiveness
+   * @param[in] sourceControl Input source control
+   */
+  void ApplyRenderTaskSourceActor(RenderTask sourceRenderTask, const Toolkit::Control sourceControl);
+
   /**
    * @brief Gets or Calculates a valid target size for texture.
    * Invalid cases include: zero vector, minus numbers or large numbers(larger than the maximum).