Do not allow to add duplicated renderer into actor 06/310606/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 2 May 2024 13:19:52 +0000 (22:19 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Thu, 2 May 2024 13:25:38 +0000 (22:25 +0900)
Internal::Actor allow to add same renderer, but SceneGraph::Node doesn't allow.

If we do something like this, the logic might be breakdown.

actor.AddRenderer(renderer);
actor.AddRenderer(renderer);
actor.RemoveRenderer(renderer);

///< actor will have renderer, but actor's node doesn't have renderer.

To match with node's logic, let we don't allow to push-back the duplicated renderer.
Instead, just check the duplication and return the index.

Change-Id: I689896171b3df5d140089c3b99f44e1d3f0f8722
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali/utc-Dali-Actor.cpp
dali/internal/event/actors/actor-renderer-container.cpp
dali/public-api/actors/actor.h

index a245c5c..4eb8f54 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
@@ -304,9 +304,9 @@ struct InheritedVisibilityChangedFunctorData
     DALI_TEST_EQUALS(called, compareCalled, TEST_INNER_LOCATION(location));
   }
 
-  Actor                              actor;
-  bool                               visible;
-  bool                               called;
+  Actor actor;
+  bool  visible;
+  bool  called;
 };
 
 struct InheritedVisibilityChangedFunctor
@@ -4660,6 +4660,50 @@ int UtcDaliActorAddRendererP(void)
   END_TEST;
 }
 
+int UtcDaliActorAddSameRenderer(void)
+{
+  tet_infoline("Testing Actor::AddRenderer");
+  TestApplication application;
+
+  Actor actor = Actor::New();
+
+  DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
+
+  Geometry geometry  = CreateQuadGeometry();
+  Shader   shader    = CreateShader();
+  Renderer renderer1 = Renderer::New(geometry, shader);
+  Renderer renderer2 = Renderer::New(geometry, shader);
+  Renderer renderer3 = Renderer::New(geometry, shader);
+
+  DALI_TEST_EQUALS(actor.AddRenderer(renderer1), 0U, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererAt(0), renderer1, TEST_LOCATION);
+
+  DALI_TEST_EQUALS(actor.AddRenderer(renderer2), 1U, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererAt(0), renderer1, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererAt(1), renderer2, TEST_LOCATION);
+
+  DALI_TEST_EQUALS(actor.AddRenderer(renderer1), 0U, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererCount(), 2u, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererAt(0), renderer1, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererAt(1), renderer2, TEST_LOCATION);
+
+  DALI_TEST_EQUALS(actor.AddRenderer(renderer3), 2U, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererCount(), 3u, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererAt(0), renderer1, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererAt(1), renderer2, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererAt(2), renderer3, TEST_LOCATION);
+
+  DALI_TEST_EQUALS(actor.AddRenderer(renderer2), 1U, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererCount(), 3u, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererAt(0), renderer1, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererAt(1), renderer2, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetRendererAt(2), renderer3, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliActorAddRendererN01(void)
 {
   tet_infoline("Testing Actor::AddRenderer");
@@ -5407,7 +5451,7 @@ int UtcDaliActorPropertyScissorClippingActorWihtoutRenderer(void)
   clippingActorA[Actor::Property::SIZE] = actorSize;
 
   // Add dummy actor, to make application would be rendering.
-  Actor dummyActor = CreateRenderableActor();
+  Actor dummyActor                  = CreateRenderableActor();
   dummyActor[Actor::Property::SIZE] = actorSize;
   clippingActorA.Add(dummyActor);
 
@@ -5471,7 +5515,7 @@ int UtcDaliActorPropertyScissorClippingActorWihtoutRendererUnderLayer3D(void)
   clippingActorA[Actor::Property::SIZE] = actorSize;
 
   // Add dummy actor, to make application would be rendering.
-  Actor dummyActor = CreateRenderableActor();
+  Actor dummyActor                  = CreateRenderableActor();
   dummyActor[Actor::Property::SIZE] = actorSize;
   clippingActorA.Add(dummyActor);
 
@@ -6813,7 +6857,6 @@ int UtcDaliActorGeoTouchRaiseAbove(void)
   END_TEST;
 }
 
-
 int UtcDaliActorRaiseAbove2(void)
 {
   tet_infoline("UtcDaliActor RaiseToAbove test using SIBLING_ORDER property\n");
@@ -9867,7 +9910,7 @@ int utcDaliActorInheritedVisibilityChangeSignal1(void)
   tet_infoline("Check that the inherited visibility change signal is called when the visibility changes for the actor itself");
 
   Actor parentActor = Actor::New();
-  Actor actor = Actor::New();
+  Actor actor       = Actor::New();
 
   InheritedVisibilityChangedFunctorData data;
   actor.InheritedVisibilityChangedSignal().Connect(&application, InheritedVisibilityChangedFunctor(data));
@@ -9904,7 +9947,7 @@ int utcDaliActorInheritedVisibilityChangeSignal2(void)
   tet_infoline("Check that the inherited visibility change signal is called when the actor or one of the parent become on scene or off scene");
 
   Actor parentActor = Actor::New();
-  Actor childActor = Actor::New();
+  Actor childActor  = Actor::New();
 
   InheritedVisibilityChangedFunctorData dataP, dataC;
   parentActor.InheritedVisibilityChangedSignal().Connect(&application, InheritedVisibilityChangedFunctor(dataP));
@@ -9985,7 +10028,7 @@ int utcDaliActorInheritedVisibilityChangeSignal3(void)
   tet_infoline("Check that the inherited visibility change signal is called when the visibility changes for the parent actor");
 
   Actor parentActor = Actor::New();
-  Actor actor = Actor::New();
+  Actor actor       = Actor::New();
   parentActor.Add(actor);
 
   InheritedVisibilityChangedFunctorData data;
@@ -10010,7 +10053,6 @@ int utcDaliActorInheritedVisibilityChangeSignal3(void)
   actor.SetProperty(Actor::Property::VISIBLE, true);
   data.Check(false, TEST_LOCATION);
 
-
   // Prepare Case 2
   // Parent : false
   // actor : false
@@ -10025,7 +10067,6 @@ int utcDaliActorInheritedVisibilityChangeSignal3(void)
   parentActor.SetProperty(Actor::Property::VISIBLE, true);
   data.Check(false, TEST_LOCATION);
 
-
   // Prepare Case 3
   // parent : false
   // actor : true
@@ -10048,16 +10089,16 @@ int utcDaliActorInheritedVisibilityChangeSignal3(void)
 
 namespace
 {
-  InheritedVisibilityChangedFunctorData dataPA, dataPB, dataCA, dataCB, dataCC;
-  void ResetInheritedVisibilityChangedFunctorData()
-  {
-    dataPA.Reset();
-    dataPB.Reset();
-    dataCA.Reset();
-    dataCB.Reset();
-    dataCC.Reset();
-  }
+InheritedVisibilityChangedFunctorData dataPA, dataPB, dataCA, dataCB, dataCC;
+void                                  ResetInheritedVisibilityChangedFunctorData()
+{
+  dataPA.Reset();
+  dataPB.Reset();
+  dataCA.Reset();
+  dataCB.Reset();
+  dataCC.Reset();
 }
+} // namespace
 
 int utcDaliActorInheritedVisibilityChangeSignal4(void)
 {
@@ -10074,9 +10115,9 @@ int utcDaliActorInheritedVisibilityChangeSignal4(void)
 
   Actor parentA = Actor::New();
   Actor parentB = Actor::New();
-  Actor childA = Actor::New();
-  Actor childB = Actor::New();
-  Actor childC = Actor::New();
+  Actor childA  = Actor::New();
+  Actor childB  = Actor::New();
+  Actor childC  = Actor::New();
   parentA.Add(parentB);
   parentB.Add(childA);
   parentB.Add(childB);
@@ -10092,17 +10133,17 @@ int utcDaliActorInheritedVisibilityChangeSignal4(void)
   application.GetScene().Add(parentA);
   dataPA.Check(true, parentA, true, TEST_LOCATION);
   dataPB.Check(true, parentB, true, TEST_LOCATION);
-  dataCA.Check(true, childA,  true, TEST_LOCATION);
-  dataCB.Check(true, childB,  true, TEST_LOCATION);
-  dataCC.Check(true, childC,  true, TEST_LOCATION);
+  dataCA.Check(true, childA, true, TEST_LOCATION);
+  dataCB.Check(true, childB, true, TEST_LOCATION);
+  dataCC.Check(true, childC, true, TEST_LOCATION);
 
   ResetInheritedVisibilityChangedFunctorData();
   parentA.SetProperty(Actor::Property::VISIBLE, false);
   dataPA.Check(true, parentA, false, TEST_LOCATION);
   dataPB.Check(true, parentB, false, TEST_LOCATION);
-  dataCA.Check(true, childA,  false, TEST_LOCATION);
-  dataCB.Check(true, childB,  false, TEST_LOCATION);
-  dataCC.Check(true, childC,  false, TEST_LOCATION);
+  dataCA.Check(true, childA, false, TEST_LOCATION);
+  dataCB.Check(true, childB, false, TEST_LOCATION);
+  dataCC.Check(true, childC, false, TEST_LOCATION);
 
   ResetInheritedVisibilityChangedFunctorData();
   childA.SetProperty(Actor::Property::VISIBLE, false);
@@ -10133,8 +10174,8 @@ int utcDaliActorInheritedVisibilityChangeSignal4(void)
   dataPA.Check(false, TEST_LOCATION);
   dataPB.Check(true, parentB, true, TEST_LOCATION);
   dataCA.Check(false, TEST_LOCATION);
-  dataCB.Check(true, childB,  true, TEST_LOCATION);
-  dataCC.Check(true, childC,  true, TEST_LOCATION);
+  dataCB.Check(true, childB, true, TEST_LOCATION);
+  dataCC.Check(true, childC, true, TEST_LOCATION);
 
   END_TEST;
 }
index e47c495..4661226 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
@@ -31,7 +31,17 @@ uint32_t RendererContainer::Add(const SceneGraph::Node& node, Renderer& renderer
     renderer.SetBlendEquation(blendEquation);
   }
 
-  uint32_t    index       = static_cast<uint32_t>(mRenderers.size());
+  uint32_t index = 0u;
+
+  // Duplication check
+  auto end = mRenderers.end();
+  for(auto iter = mRenderers.begin(); iter != end; ++iter, ++index)
+  {
+    if((*iter).Get() == &renderer)
+    {
+      return index;
+    }
+  }
   RendererPtr rendererPtr = RendererPtr(&renderer);
   mRenderers.push_back(rendererPtr);
   AttachRendererMessage(mEventThreadServices.GetUpdateManager(), node, renderer.GetRendererSceneObject());
index c12c6bc..87a3a35 100644 (file)
@@ -1127,6 +1127,7 @@ public:
 public: // Renderer
   /**
    * @brief Adds a renderer to this actor.
+   * @note We don't allow to add duplicated renderers. If we add the same renderer twice, it will just return the index of renderer.
    *
    * @SINCE_1_0.0
    * @param[in] renderer Renderer to add to the actor