(Visual) Lazy initialize for transform data 69/323969/4
authorEunki Hong <eunkiki.hong@samsung.com>
Sat, 10 May 2025 17:34:21 +0000 (02:34 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Sat, 17 May 2025 12:00:23 +0000 (12:00 +0000)
Let we initialize Visual's Transform data only if we use it

Change-Id: I8891287434b9d868227542dab37be41a06c8bbcb
Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp
dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp
dali-toolkit/internal/visuals/arc/arc-visual.cpp
dali-toolkit/internal/visuals/image/image-visual.cpp
dali-toolkit/internal/visuals/svg/svg-visual.cpp
dali-toolkit/internal/visuals/text/text-visual.cpp
dali-toolkit/internal/visuals/visual-base-data-impl.cpp
dali-toolkit/internal/visuals/visual-base-data-impl.h
dali-toolkit/internal/visuals/visual-base-impl.cpp

index cb6055a27ff14f5d3a63be01d1e6cd69432a3056..9b03709910c11ba79597a1e12db6a70333270bfd 100644 (file)
@@ -205,7 +205,7 @@ Vector4 GetAlphaPreMultipliedColor(const Vector4& color)
   return Vector4(color.r * color.a, color.g * color.a, color.b * color.a, color.a);
 }
 
-} //namespace
+} // namespace
 
 void dali_visual_startup(void)
 {
@@ -266,7 +266,7 @@ int UtcDaliVisualCopyAndAssignment(void)
   emptyVisualEquals = emptyVisual;
   DALI_TEST_CHECK(emptyVisual == emptyVisualEquals);
 
-  //self assignment
+  // self assignment
   visual = visual;
   DALI_TEST_CHECK(visual = visualCopy);
 
@@ -432,7 +432,7 @@ int UtcDaliVisualSize(void)
   // The height returned for a particular width should also be greater for the large text visual
   DALI_TEST_CHECK(smallTextVisual.GetHeightForWidth(40.f) < largeTextVisual.GetHeightForWidth(40.f));
 
-  //AnimatedImageVisual
+  // AnimatedImageVisual
   Visual::Base animatedImageVisual = factory.CreateVisual(TEST_GIF_FILE_NAME, ImageDimensions());
   animatedImageVisual.SetTransformAndSize(DefaultTransform(), controlSize);
   animatedImageVisual.GetNaturalSize(naturalSize);
@@ -1123,13 +1123,13 @@ int UtcDaliVisualGetPropertyMap7(void)
   END_TEST;
 }
 
-//Mesh visual
+// Mesh visual
 int UtcDaliVisualGetPropertyMap8(void)
 {
   ToolkitTestApplication application;
   tet_infoline("UtcDaliVisualGetPropertyMap8: MeshVisual");
 
-  //Request MeshVisual using a property map.
+  // Request MeshVisual using a property map.
   VisualFactory factory = VisualFactory::Get();
   Property::Map propertyMap;
   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::MESH);
@@ -1145,7 +1145,7 @@ int UtcDaliVisualGetPropertyMap8(void)
   meshVisual.CreatePropertyMap(resultMap);
   TestMixColor(meshVisual, Visual::Property::MIX_COLOR, Color::BLUE);
 
-  //Check values in the result map are identical to the initial map's values.
+  // Check values in the result map are identical to the initial map's values.
   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
   DALI_TEST_CHECK(value);
   DALI_TEST_EQUALS(value->Get<int>(), (int)Visual::MESH, TEST_LOCATION);
@@ -1173,7 +1173,7 @@ int UtcDaliVisualGetPropertyMap8(void)
   END_TEST;
 }
 
-//Primitive shape visual
+// Primitive shape visual
 int UtcDaliVisualGetPropertyMap9(void)
 {
   ToolkitTestApplication application;
@@ -1182,7 +1182,7 @@ int UtcDaliVisualGetPropertyMap9(void)
   Vector4 color      = Vector4(1.0, 0.8, 0.6, 1.0);
   Vector3 dimensions = Vector3(1.0, 2.0, 3.0);
 
-  //Request PrimitiveVisual using a property map.
+  // Request PrimitiveVisual using a property map.
   VisualFactory factory = VisualFactory::Get();
   Property::Map propertyMap;
   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE);
@@ -1203,7 +1203,7 @@ int UtcDaliVisualGetPropertyMap9(void)
   Property::Map resultMap;
   primitiveVisual.CreatePropertyMap(resultMap);
 
-  //Check values in the result map are identical to the initial map's values.
+  // Check values in the result map are identical to the initial map's values.
   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
   DALI_TEST_CHECK(value);
   DALI_TEST_EQUALS(value->Get<int>(), (int)Visual::PRIMITIVE, TEST_LOCATION);
@@ -1287,13 +1287,13 @@ int UtcDaliVisualGetPropertyMap9(void)
   END_TEST;
 }
 
-//Text shape visual
+// Text shape visual
 int UtcDaliVisualGetPropertyMap10(void)
 {
   ToolkitTestApplication application;
   tet_infoline("UtcDaliVisualGetPropertyMap10: TextVisual");
 
-  //Request PrimitiveVisual using a property map.
+  // Request PrimitiveVisual using a property map.
   VisualFactory factory = VisualFactory::Get();
 
   Property::Map propertyMap;
@@ -1331,7 +1331,7 @@ int UtcDaliVisualGetPropertyMap10(void)
   Property::Map resultMap;
   textVisual.CreatePropertyMap(resultMap);
 
-  //Check values in the result map are identical to the initial map's values.
+  // Check values in the result map are identical to the initial map's values.
   Property::Value* value = resultMap.Find(Toolkit::Visual::Property::TYPE, Property::INTEGER);
   DALI_TEST_CHECK(value);
   DALI_TEST_EQUALS(value->Get<int>(), (int)Visual::TEXT, TEST_LOCATION);
@@ -1524,7 +1524,8 @@ int UtcDaliVisualGetPropertyMap12(void)
       int motion     = DevelAnimatedGradientVisual::AnimationParameter::MotionType::MIRROR;
       int easing     = DevelAnimatedGradientVisual::AnimationParameter::EasingType::OUT;
 
-      auto buildAnimatedMap = [&animationMap, &direction, &duration, &delay, &loop_count, &repeat_delay, &motion, &easing](const Property::Value& start, const Property::Value& target) -> Property::Map& {
+      auto buildAnimatedMap = [&animationMap, &direction, &duration, &delay, &loop_count, &repeat_delay, &motion, &easing](const Property::Value& start, const Property::Value& target) -> Property::Map&
+      {
         animationMap.Clear();
         animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::START, start);
         animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET, target);
@@ -1590,7 +1591,8 @@ int UtcDaliVisualGetPropertyMap12(void)
       DALI_TEST_CHECK(value);
       DALI_TEST_CHECK(value->Get<int>() == DevelAnimatedGradientVisual::SpreadType::REPEAT);
 
-      auto checkAnimatedMap = [&value, &resultMap, &direction, &duration, &delay, &loop_count, &repeat_delay, &motion, &easing](const Property::Index& index, const Property::Value& start, const Property::Value& target, int line_num) -> void {
+      auto checkAnimatedMap = [&value, &resultMap, &direction, &duration, &delay, &loop_count, &repeat_delay, &motion, &easing](const Property::Index& index, const Property::Value& start, const Property::Value& target, int line_num) -> void
+      {
         tet_printf("Check value at %d\n", line_num);
         value = resultMap.Find(index, Property::MAP);
         DALI_TEST_CHECK(value);
@@ -1598,7 +1600,8 @@ int UtcDaliVisualGetPropertyMap12(void)
         Property::Map* temp_map = value->GetMap();
         DALI_TEST_CHECK(temp_map);
 
-        auto checkMapValue = [&temp_map](const Property::Index index) -> Property::Value {
+        auto checkMapValue = [&temp_map](const Property::Index index) -> Property::Value
+        {
           Property::Value* res = temp_map->Find(index);
           DALI_TEST_CHECK(res);
           return *res;
@@ -1650,7 +1653,8 @@ int UtcDaliVisualGetPropertyMap12(void)
       int motion     = DevelAnimatedGradientVisual::AnimationParameter::MotionType::MIRROR;
       int easing     = DevelAnimatedGradientVisual::AnimationParameter::EasingType::IN_OUT;
 
-      auto buildAnimatedMap = [&animationMap, &duration, &delay, &loop_count, &repeat_delay](const Property::Value& start, const Property::Value& target) -> Property::Map& {
+      auto buildAnimatedMap = [&animationMap, &duration, &delay, &loop_count, &repeat_delay](const Property::Value& start, const Property::Value& target) -> Property::Map&
+      {
         animationMap.Clear();
         animationMap.Insert("startValue", start);
         animationMap.Insert("targetValue", target);
@@ -1718,7 +1722,8 @@ int UtcDaliVisualGetPropertyMap12(void)
       DALI_TEST_CHECK(value);
       DALI_TEST_CHECK(value->Get<int>() == DevelAnimatedGradientVisual::SpreadType::REFLECT);
 
-      auto checkAnimatedMap = [&value, &resultMap, &direction, &duration, &delay, &loop_count, &repeat_delay, &motion, &easing](const Property::Index& index, const Property::Value& start, const Property::Value& target, int line_num) -> void {
+      auto checkAnimatedMap = [&value, &resultMap, &direction, &duration, &delay, &loop_count, &repeat_delay, &motion, &easing](const Property::Index& index, const Property::Value& start, const Property::Value& target, int line_num) -> void
+      {
         tet_printf("Check value at %d\n", line_num);
         value = resultMap.Find(index, Property::MAP);
         DALI_TEST_CHECK(value);
@@ -1726,7 +1731,8 @@ int UtcDaliVisualGetPropertyMap12(void)
         Property::Map* temp_map = value->GetMap();
         DALI_TEST_CHECK(temp_map);
 
-        auto checkMapValue = [&temp_map](const Property::Index index) -> Property::Value {
+        auto checkMapValue = [&temp_map](const Property::Index index) -> Property::Value
+        {
           Property::Value* res = temp_map->Find(index);
           DALI_TEST_CHECK(res);
           return *res;
@@ -1782,7 +1788,8 @@ int UtcDaliVisualGetPropertyMap13(void)
       int motion     = DevelAnimatedGradientVisual::AnimationParameter::MotionType::LOOP;
       int easing     = DevelAnimatedGradientVisual::AnimationParameter::EasingType::IN;
 
-      auto buildAnimatedMap = [&animationMap, &direction, &duration, &delay, &loop_count, &repeat_delay, &motion, &easing](const Property::Value& start, const Property::Value& target) -> Property::Map& {
+      auto buildAnimatedMap = [&animationMap, &direction, &duration, &delay, &loop_count, &repeat_delay, &motion, &easing](const Property::Value& start, const Property::Value& target) -> Property::Map&
+      {
         animationMap.Clear();
         animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::START, start);
         animationMap.Insert(DevelAnimatedGradientVisual::AnimationParameter::Property::TARGET, target);
@@ -2434,7 +2441,7 @@ int UtcDaliVisualAnimatedGradientVisual01(void)
       DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<float>("gradient_offset", 0.5f * step_iter + 0.5f), true, TEST_LOCATION);
     }
 
-    //Not check here. cause gradient_offset value can be 2.0f or 0.0f
+    // Not check here. cause gradient_offset value can be 2.0f or 0.0f
     application.Render(750u); // go to end
     application.SendNotification();
 
@@ -2497,7 +2504,8 @@ int UtcDaliVisualAnimatedGradientVisual02(void)
       int unit_type     = DevelAnimatedGradientVisual::UnitType::USER_SPACE;
       int spread_type   = DevelAnimatedGradientVisual::SpreadType::REPEAT;
 
-      auto buildAnimatedMap = [&animationMap, &_direction, &_duration, &_delay, &_loop_count, &_repeat_delay, &_motion, &_easing, &test_case](const Property::Value& start, const Property::Value& target, int tc_offset) -> Property::Map& {
+      auto buildAnimatedMap = [&animationMap, &_direction, &_duration, &_delay, &_loop_count, &_repeat_delay, &_motion, &_easing, &test_case](const Property::Value& start, const Property::Value& target, int tc_offset) -> Property::Map&
+      {
         int tc         = (test_case + tc_offset);
         int idx_easing = tc % 4;
         tc /= 4;
@@ -2609,8 +2617,9 @@ int UtcDaliVisualAnimatedGradientVisual02(void)
 
       application.SendNotification();
 
-      //Compare between CPU calculated value and Shader Visual calculated value
-      auto testProperty = [&application, &_direction, &_duration, &_delay, &_loop_count, &_repeat_delay, &_motion, &_easing, &test_case](const char* name, const Property::Value& start, const Property::Value& target, int tc_offset, int value_type, float progress) -> void {
+      // Compare between CPU calculated value and Shader Visual calculated value
+      auto testProperty = [&application, &_direction, &_duration, &_delay, &_loop_count, &_repeat_delay, &_motion, &_easing, &test_case](const char* name, const Property::Value& start, const Property::Value& target, int tc_offset, int value_type, float progress) -> void
+      {
         int tc         = (test_case + tc_offset);
         int idx_easing = tc % 4;
         tc /= 4;
@@ -2793,7 +2802,8 @@ int UtcDaliVisualAnimatedGradientVisual03(void)
       Property::Map animationMap;
       propertyMap.Insert(Visual::Property::TYPE, DevelVisual::ANIMATED_GRADIENT);
 
-      auto buildAnimatedMap = [&animationMap, &_direction, &_duration, &_delay, &_loop_count, &_repeat_delay, &_motion, &_easing, &test_case](const Property::Value& start, const Property::Value& target, int tc_offset) -> Property::Map& {
+      auto buildAnimatedMap = [&animationMap, &_direction, &_duration, &_delay, &_loop_count, &_repeat_delay, &_motion, &_easing, &test_case](const Property::Value& start, const Property::Value& target, int tc_offset) -> Property::Map&
+      {
         int tc         = (test_case + tc_offset);
         int idx_easing = tc % 4;
         tc /= 4;
@@ -2905,8 +2915,9 @@ int UtcDaliVisualAnimatedGradientVisual03(void)
 
       application.SendNotification();
 
-      //Compare between CPU calculated value and Shader Visual calculated value
-      auto testProperty = [&application, &_direction, &_duration, &_delay, &_loop_count, &_repeat_delay, &_motion, &_easing, &test_case](const char* name, const Property::Value& start, const Property::Value& target, int tc_offset, int value_type, float progress) -> void {
+      // Compare between CPU calculated value and Shader Visual calculated value
+      auto testProperty = [&application, &_direction, &_duration, &_delay, &_loop_count, &_repeat_delay, &_motion, &_easing, &test_case](const char* name, const Property::Value& start, const Property::Value& target, int tc_offset, int value_type, float progress) -> void
+      {
         int tc         = (test_case + tc_offset);
         int idx_easing = tc % 4;
         tc /= 4;
@@ -3087,7 +3098,7 @@ int UtcDaliVisualGetTransform(void)
   Dali::Property::Map* map   = value->GetMap();
   DALI_TEST_CHECK(map);
 
-  //Test default values
+  // Test default values
   {
     Property::Value* typeValue = map->Find(Toolkit::Visual::Transform::Property::OFFSET);
     DALI_TEST_CHECK(typeValue);
@@ -3127,6 +3138,8 @@ int UtcDaliVisualGetTransform(void)
   END_TEST;
 }
 
+namespace
+{
 static void TestTransform(ToolkitTestApplication& application, Visual::Base visual)
 {
   Property::Map transform;
@@ -3181,7 +3194,7 @@ static void TestTransform(ToolkitTestApplication& application, Visual::Base visu
     DALI_TEST_EQUALS(typeValue->Get<Vector2>(), Vector2(50.0f, 50.0f), TEST_LOCATION);
   }
 
-  //Put the visual on the stage
+  // Put the visual on the stage
   DummyControl        actor     = DummyControl::New(true);
   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
   actor.SetProperty(Actor::Property::SIZE, Vector2(2000.f, 2000.f));
@@ -3213,7 +3226,7 @@ static void TestTransform(ToolkitTestApplication& application, Visual::Base visu
   Vector2 extraSize = renderer.GetProperty<Vector2>(VisualRenderer::Property::EXTRA_SIZE);
   DALI_TEST_EQUALS(extraSize, Vector2(50.0f, 50.0f), TEST_LOCATION);
 
-  //Set a new transform
+  // Set a new transform
   transform.Clear();
   transform = DefaultTransform();
   transform.Insert(Visual::Transform::Property::OFFSET, Vector2(20.0f, 20.0f));
@@ -3224,7 +3237,7 @@ static void TestTransform(ToolkitTestApplication& application, Visual::Base visu
   application.SendNotification();
   application.Render(0);
 
-  //Check that the values have changed in the renderer
+  // Check that the values have changed in the renderer
   offset = renderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_OFFSET);
   DALI_TEST_EQUALS(offset, Vector2(20.0f, 20.0f), TEST_LOCATION);
 
@@ -3234,7 +3247,7 @@ static void TestTransform(ToolkitTestApplication& application, Visual::Base visu
   offsetSizeMode = renderer.GetProperty<Vector4>(VisualRenderer::Property::TRANSFORM_OFFSET_SIZE_MODE);
   DALI_TEST_EQUALS(offsetSizeMode, Vector4(0.0f, 0.0f, 1.0f, 1.0f), TEST_LOCATION);
 
-  //Parent origin and anchor point should have the default values
+  // Parent origin and anchor point should have the default values
   parentOrigin = renderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_ORIGIN);
   DALI_TEST_EQUALS(parentOrigin, Vector2(-0.5f, -0.5f), TEST_LOCATION);
 
@@ -3244,6 +3257,7 @@ static void TestTransform(ToolkitTestApplication& application, Visual::Base visu
   extraSize = renderer.GetProperty<Vector2>(VisualRenderer::Property::EXTRA_SIZE);
   DALI_TEST_EQUALS(extraSize, Vector2(0.5f, 0.5f), TEST_LOCATION);
 }
+} // namespace
 
 int UtcDaliVisualSetTransform01(void)
 {
@@ -5267,7 +5281,8 @@ int UtcDaliVisualGetPropertyObject01(void)
 
   DALI_TEST_CHECK(visual.GetType() == Visual::IMAGE);
 
-  auto propertyTest = [](Visual::Base visual, Property::Key key, bool expect) {
+  auto propertyTest = [](Visual::Base visual, Property::Key key, bool expect)
+  {
     {
       std::ostringstream oss;
       oss << "Test for key[" << key << "]";
@@ -5319,7 +5334,8 @@ int UtcDaliVisualGetPropertyObject02(void)
 
   DALI_TEST_CHECK(visual.GetType() == Visual::IMAGE);
 
-  auto propertyTest = [](Visual::Base visual, Property::Key key, bool expect) {
+  auto propertyTest = [](Visual::Base visual, Property::Key key, bool expect)
+  {
     {
       std::ostringstream oss;
       oss << "Test for key[" << key << "]";
@@ -5369,7 +5385,8 @@ int UtcDaliVisualGetPropertyObject03(void)
 
   DALI_TEST_CHECK(visual.GetType() == Visual::COLOR);
 
-  auto propertyTest = [](Visual::Base visual, Property::Key key, bool expect) {
+  auto propertyTest = [](Visual::Base visual, Property::Key key, bool expect)
+  {
     {
       std::ostringstream oss;
       oss << "Test for key[" << key << "]";
@@ -6240,7 +6257,6 @@ int UtcDaliVisualUpdateProperty02(void)
   propertyMap[Visual::Property::TYPE]                      = Visual::Type::IMAGE;
   propertyMap[ImageVisual::Property::URL]                  = TEST_IMAGE_FILE_NAME;
   propertyMap[Visual::Property::MIX_COLOR]                 = Color::BLUE;
-  propertyMap[DevelVisual::Property::VISUAL_FITTING_MODE]  = DevelVisual::FIT_WIDTH;
   propertyMap[DevelVisual::Property::CORNER_RADIUS]        = 0.0f;
   propertyMap[DevelVisual::Property::CORNER_RADIUS_POLICY] = Toolkit::Visual::Transform::Policy::RELATIVE;
   propertyMap[DevelVisual::Property::BORDERLINE_WIDTH]     = 0.0f;
@@ -6275,6 +6291,23 @@ int UtcDaliVisualUpdateProperty02(void)
   targetPropertyMap[DevelVisual::Property::CORNER_RADIUS]    = targetCornerRadius;
   targetPropertyMap[DevelVisual::Property::BORDERLINE_WIDTH] = targetBorderlineWidth;
 
+  Vector2              targetTransformOffset       = Vector2(10.0f, 12.0f);
+  Vector2              targetTransformSize         = Vector2(0.2f, 3.5f);
+  Vector2              targetTransformOffsetPolicy = Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::RELATIVE);
+  Vector2              targetTransformSizePolicy   = Vector2(Toolkit::Visual::Transform::Policy::RELATIVE, Toolkit::Visual::Transform::Policy::ABSOLUTE);
+  Toolkit::Align::Type targetTransformOrigin       = Toolkit::Align::CENTER;
+  Toolkit::Align::Type targetTransformAnchorPoint  = Toolkit::Align::BOTTOM_END;
+  Vector2              targetTransformExtraSize    = Vector2(50.0f, 5.0f);
+  Property::Map        transform;
+  transform.Insert(Visual::Transform::Property::OFFSET, targetTransformOffset);
+  transform.Insert(Visual::Transform::Property::SIZE, targetTransformSize);
+  transform.Insert(Visual::Transform::Property::OFFSET_POLICY, targetTransformOffsetPolicy);
+  transform.Insert(Visual::Transform::Property::SIZE_POLICY, targetTransformSizePolicy);
+  transform.Insert(Visual::Transform::Property::ORIGIN, targetTransformOrigin);
+  transform.Insert(Visual::Transform::Property::ANCHOR_POINT, targetTransformAnchorPoint);
+  transform.Insert(DevelVisual::Transform::Property::EXTRA_SIZE, targetTransformExtraSize);
+  targetPropertyMap[Visual::Property::TRANSFORM] = transform;
+
   // Update Properties
   DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, DevelVisual::Action::UPDATE_PROPERTY, targetPropertyMap);
 
@@ -6305,6 +6338,40 @@ int UtcDaliVisualUpdateProperty02(void)
   DALI_TEST_CHECK(cornerSquarenessValue);
   DALI_TEST_EQUALS(cornerSquarenessValue->Get<Vector4>(), cornerSquareness, TEST_LOCATION);
 
+  // Transform comparision
+  Property::Value* transformValue = resultMap.Find(DevelVisual::Property::TRANSFORM, Property::MAP);
+  DALI_TEST_CHECK(transformValue);
+  Property::Map* transformMap = transformValue->GetMap();
+  DALI_TEST_CHECK(transformMap);
+
+  Property::Value* transformOffsetValue = transformMap->Find(Visual::Transform::Property::OFFSET, Property::VECTOR2);
+  DALI_TEST_CHECK(transformOffsetValue);
+  DALI_TEST_EQUALS(transformOffsetValue->Get<Vector2>(), targetTransformOffset, TEST_LOCATION);
+
+  Property::Value* transformSizeValue = transformMap->Find(Visual::Transform::Property::SIZE, Property::VECTOR2);
+  DALI_TEST_CHECK(transformSizeValue);
+  DALI_TEST_EQUALS(transformSizeValue->Get<Vector2>(), targetTransformSize, TEST_LOCATION);
+
+  Property::Value* transformOffsetPolicyValue = transformMap->Find(Visual::Transform::Property::OFFSET_POLICY, Property::VECTOR2);
+  DALI_TEST_CHECK(transformOffsetPolicyValue);
+  DALI_TEST_EQUALS(transformOffsetPolicyValue->Get<Vector2>(), targetTransformOffsetPolicy, TEST_LOCATION);
+
+  Property::Value* transformSizePolicyValue = transformMap->Find(Visual::Transform::Property::SIZE_POLICY, Property::VECTOR2);
+  DALI_TEST_CHECK(transformSizePolicyValue);
+  DALI_TEST_EQUALS(transformSizePolicyValue->Get<Vector2>(), targetTransformSizePolicy, TEST_LOCATION);
+
+  Property::Value* transformOriginValue = transformMap->Find(Visual::Transform::Property::ORIGIN, Property::INTEGER);
+  DALI_TEST_CHECK(transformOriginValue);
+  DALI_TEST_EQUALS(transformOriginValue->Get<int32_t>(), static_cast<int32_t>(targetTransformOrigin), TEST_LOCATION);
+
+  Property::Value* transformAnchorPointValue = transformMap->Find(Visual::Transform::Property::ANCHOR_POINT, Property::INTEGER);
+  DALI_TEST_CHECK(transformAnchorPointValue);
+  DALI_TEST_EQUALS(transformAnchorPointValue->Get<int32_t>(), static_cast<int32_t>(targetTransformAnchorPoint), TEST_LOCATION);
+
+  Property::Value* transformExtraSizeValue = transformMap->Find(DevelVisual::Transform::Property::EXTRA_SIZE, Property::VECTOR2);
+  DALI_TEST_CHECK(transformExtraSizeValue);
+  DALI_TEST_EQUALS(transformExtraSizeValue->Get<Vector2>(), targetTransformExtraSize, TEST_LOCATION);
+
   END_TEST;
 }
 
@@ -7259,7 +7326,7 @@ int UtcDaliGradientAnimateTest(void)
   ToolkitTestApplication application;
   tet_infoline("UtcDaliGradientAnimateTest");
 
-  Control control = Control::New();
+  Control control                = Control::New();
   control[Actor::Property::SIZE] = Vector2(200.f, 200.f);
 
   // Linear Gradient
index d4ced58aec2a4a2cb293d0ab48e0dca705d2f816..9269b59995cb9eca21b700f743f4c6a289d21070 100644 (file)
@@ -567,7 +567,7 @@ void AnimatedVectorImageVisual::OnSetTransform()
 
   if(IsOnScene())
   {
-    Vector2 visualSize = mImpl->mTransform.GetVisualSize(mImpl->mControlSize);
+    Vector2 visualSize = mImpl->GetTransformVisualSize(mImpl->mControlSize);
 
     if(visualSize != mVisualSize)
     {
index cbd1ccca7361439ad0e7d4e2dc38ba6f1b33e037..48c844887278d29ef0a24d71f387e616f11bd70a 100644 (file)
@@ -21,7 +21,7 @@
 // EXTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
 
-//INTERNAL INCLUDES
+// INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
@@ -180,7 +180,7 @@ void ArcVisual::DoCreateInstancePropertyMap(Property::Map& map) const
 
 void ArcVisual::OnSetTransform()
 {
-  Vector2 visualSize = mImpl->mTransform.GetVisualSize(mImpl->mControlSize);
+  Vector2 visualSize = mImpl->GetTransformVisualSize(mImpl->mControlSize);
   mRadius            = (std::min(visualSize.width, visualSize.height) - mThickness) / 2.0f;
 
   if(mImpl->mRenderer)
index 23b93b4d8ecb7361752c1ee5417feb0a16a62bb4..8dcefdce70f4b2693c77356b36a2f8bd206c35b4 100644 (file)
@@ -681,7 +681,7 @@ void ImageVisual::OnInitialize()
     mPixelAreaIndex = mImpl->mRenderer.RegisterUniqueProperty(Toolkit::ImageVisual::Property::PIXEL_AREA, PIXEL_AREA_UNIFORM_NAME, mPixelArea);
   }
 
-  //Register transform properties
+  // Register transform properties
   mImpl->SetTransformUniforms(mImpl->mRenderer, Direction::LEFT_TO_RIGHT);
   if(mImpl->mCustomShader)
   {
@@ -738,7 +738,8 @@ void ImageVisual::LoadTexture(bool& atlasing, Vector4& atlasRect, TextureSet& te
    * @brief Check whether FastTrackUploading is avaliable or not.
    * @return True if we can use fast track uploading feature. False otherwise.
    */
-  auto IsFastTrackUploadingAvailable = [&]() {
+  auto IsFastTrackUploadingAvailable = [&]()
+  {
     if(mUseFastTrackUploading &&
        mLoadPolicy == Toolkit::ImageVisual::LoadPolicy::ATTACHED &&
        mReleasePolicy == Toolkit::ImageVisual::ReleasePolicy::DETACHED &&
@@ -1107,7 +1108,7 @@ void ImageVisual::OnSetTransform()
   if(mUseSynchronousSizing)
   {
     // Get current visual size
-    Vector2  size                    = mImpl->mTransform.GetVisualSize(mImpl->mControlSize);
+    Vector2  size                    = mImpl->GetTransformVisualSize(mImpl->mControlSize);
     uint32_t maximumNumber           = std::numeric_limits<uint16_t>::max();
     uint32_t sizeWidth               = static_cast<uint32_t>(roundf(size.width));
     sizeWidth                        = std::min(sizeWidth, maximumNumber);
index e74b8e4ab7c910b4bde373e940080c1daab5bcd7..a37943bdb159512a0079d74d1ff4e2de61d40a3a 100644 (file)
@@ -510,7 +510,7 @@ void SvgVisual::OnSetTransform()
     else
     {
       // Use visual size
-      size = mImpl->mTransform.GetVisualSize(mImpl->mControlSize);
+      size = mImpl->GetTransformVisualSize(mImpl->mControlSize);
     }
 
     // roundf and change as integer scale.
index 9bd71fd29f46ca701ccb78d27b01d82449f698d3..814c8188e076be06ed372df2aeb1ea619a7c3b4c 100644 (file)
@@ -543,15 +543,17 @@ void TextVisual::UpdateRenderer()
   // Calculates the size to be used to relayout.
   Vector2 relayoutSize;
 
-  const bool isWidthRelative  = fabsf(mImpl->mTransform.mOffsetSizeMode.z) < Math::MACHINE_EPSILON_1000;
-  const bool isHeightRelative = fabsf(mImpl->mTransform.mOffsetSizeMode.w) < Math::MACHINE_EPSILON_1000;
+  auto& visualTransform = mImpl->GetOrCreateTransform();
+
+  const bool isWidthRelative  = fabsf(visualTransform.mOffsetSizeMode.z) < Math::MACHINE_EPSILON_1000;
+  const bool isHeightRelative = fabsf(visualTransform.mOffsetSizeMode.w) < Math::MACHINE_EPSILON_1000;
 
   const float controlWidth  = mImpl->mControlSize.width;
   const float controlHeight = mImpl->mControlSize.height;
 
   // Round the size and offset to avoid pixel alignement issues.
-  relayoutSize.width  = floorf(0.5f + (isWidthRelative ? controlWidth * mImpl->mTransform.mSize.x : mImpl->mTransform.mSize.width));
-  relayoutSize.height = floorf(0.5f + (isHeightRelative ? controlHeight * mImpl->mTransform.mSize.y : mImpl->mTransform.mSize.height));
+  relayoutSize.width  = floorf(0.5f + (isWidthRelative ? controlWidth * visualTransform.mSize.x : visualTransform.mSize.width));
+  relayoutSize.height = floorf(0.5f + (isHeightRelative ? controlHeight * visualTransform.mSize.y : visualTransform.mSize.height));
 
   auto textLengthUtf32 = mController->GetNumberOfCharacters();
 
@@ -634,16 +636,16 @@ void TextVisual::UpdateRenderer()
         // When Cutout Enabled, the current visual must draw the entire control.
         // so set the size to controlSize and offset to 0.
 
-        relayoutSize                   = Vector2(controlWidth, controlHeight);
-        mImpl->mTransform.mSize.width  = controlWidth;
-        mImpl->mTransform.mSize.height = controlHeight;
+        relayoutSize                 = Vector2(controlWidth, controlHeight);
+        visualTransform.mSize.width  = controlWidth;
+        visualTransform.mSize.height = controlHeight;
 
         // Relayout to the original size has been completed, so save only the offset information and use it in typesetter.
 
-        Vector2 originOffset = Vector2(mImpl->mTransform.mOffset.x, mImpl->mTransform.mOffset.y);
+        Vector2 originOffset = Vector2(visualTransform.mOffset.x, visualTransform.mOffset.y);
         mController->SetOffsetWithCutout(originOffset);
-        mImpl->mTransform.mOffset.x = 0;
-        mImpl->mTransform.mOffset.y = 0;
+        visualTransform.mOffset.x = 0;
+        visualTransform.mOffset.y = 0;
       }
 
       AddRenderer(control, relayoutSize, hasMultipleTextColors, containsColorGlyph, styleEnabled, isOverlayStyle);
@@ -930,11 +932,14 @@ void TextVisual::LoadComplete(bool loadingSuccess, const TextInformation& textIn
 
       // Get the current offset for recalculate the offset when tiling.
       Property::Map retMap;
-      mImpl->mTransform.GetPropertyMap(retMap);
-      Property::Value* offsetValue = retMap.Find(Dali::Toolkit::Visual::Transform::Property::OFFSET);
-      if(offsetValue)
+      if(mImpl->mTransform)
       {
-        offsetValue->Get(info.transformOffset);
+        mImpl->mTransform->GetPropertyMap(retMap);
+        Property::Value* offsetValue = retMap.Find(Dali::Toolkit::Visual::Transform::Property::OFFSET);
+        if(offsetValue)
+        {
+          offsetValue->Get(info.transformOffset);
+        }
       }
 
       // Create a textureset in the default renderer.
@@ -1228,11 +1233,14 @@ void TextVisual::AddRenderer(Actor& actor, const Vector2& size, bool hasMultiple
 
     // Get the current offset for recalculate the offset when tiling.
     Property::Map retMap;
-    mImpl->mTransform.GetPropertyMap(retMap);
-    Property::Value* offsetValue = retMap.Find(Dali::Toolkit::Visual::Transform::Property::OFFSET);
-    if(offsetValue)
+    if(mImpl->mTransform)
     {
-      offsetValue->Get(info.transformOffset);
+      mImpl->mTransform->GetPropertyMap(retMap);
+      Property::Value* offsetValue = retMap.Find(Dali::Toolkit::Visual::Transform::Property::OFFSET);
+      if(offsetValue)
+      {
+        offsetValue->Get(info.transformOffset);
+      }
     }
 
     // Create a textureset in the default renderer.
index 92681f3b60951e3382e8019c1ddc743317d77576..3d16ffe9cba01a3bcc0d48f5706ad6959312f357 100644 (file)
@@ -118,7 +118,7 @@ bool GetPolicyFromValue(const Property::Value& value, Vector2& policy)
 Internal::Visual::Base::Impl::Impl(FittingMode fittingMode, Toolkit::Visual::Type type)
 : mCustomShader(nullptr),
   mEventObserver(nullptr),
-  mTransform(),
+  mTransform(nullptr),
   mMixColor(Color::WHITE),
   mControlSize(Vector2::ZERO),
   mDecorationData(nullptr),
@@ -360,6 +360,21 @@ Vector2 Internal::Visual::Base::Impl::Transform::GetVisualSize(const Vector2& co
          mExtraSize;
 }
 
+const Property::Map& Internal::Visual::Base::Impl::Transform::GetDefaultTransformMap()
+{
+  static const Property::Map sDefaultTransformMap{
+    {Toolkit::Visual::Transform::Property::OFFSET, Vector2::ZERO},
+    {Toolkit::Visual::Transform::Property::SIZE, Vector2::ONE},
+    {Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN},
+    {Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN},
+    {Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2::ZERO},
+    {Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2::ZERO},
+    {Toolkit::DevelVisual::Transform::Property::EXTRA_SIZE, Vector2::ZERO},
+  };
+
+  return sDefaultTransformMap;
+}
+
 } // namespace Internal
 
 } // namespace Toolkit
index affff43aa9290d8df9330b9a647c2dcbd86a0e9e..a299c9de076adc7c9c65bc8c826305157fdea426 100644 (file)
@@ -21,6 +21,7 @@
 // EXTERNAL INCLUDES
 #include <dali/public-api/math/vector2.h>
 #include <dali/public-api/rendering/visual-renderer.h>
+#include <memory> ///< for std::unique_ptr
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
@@ -107,6 +108,11 @@ struct Base::Impl
      */
     Vector2 GetVisualSize(const Vector2& controlSize);
 
+    /**
+     * Get property maps for the default transform.
+     */
+    static const Property::Map& GetDefaultTransformMap();
+
     Vector2              mOffset;
     Vector2              mSize;
     Vector2              mExtraSize;
@@ -115,6 +121,18 @@ struct Base::Impl
     Toolkit::Align::Type mAnchorPoint;
   };
 
+  /**
+   * @brief Ensure to create and get the transform data for the visual.
+   */
+  Transform& GetOrCreateTransform()
+  {
+    if(DALI_UNLIKELY(!mTransform))
+    {
+      mTransform.reset(new Transform());
+    }
+    return *(mTransform.get());
+  }
+
   /**
    * @brief Set the uniform properties onto the renderer.
    * And Register visual transform uniforms if neccessary.
@@ -124,10 +142,23 @@ struct Base::Impl
     if(!mTransformMapUsingDefault || direction != Toolkit::Direction::LEFT_TO_RIGHT)
     {
       renderer.RegisterVisualTransformUniform();
-      mTransform.SetUniforms(renderer, direction);
+      GetOrCreateTransform().SetUniforms(renderer, direction);
     }
   }
 
+  /**
+   * Convert the control size and the transform attributes into the actual
+   * size of the visual.
+   */
+  Vector2 GetTransformVisualSize(const Vector2& controlSize)
+  {
+    if(!mTransformMapUsingDefault && mTransform)
+    {
+      return mTransform->GetVisualSize(controlSize);
+    }
+    return controlSize;
+  }
+
   /**
    * @brief Get decoration data value : borderline width
    *
@@ -252,7 +283,7 @@ struct Base::Impl
   CustomShader*                   mCustomShader;
   EventObserver*                  mEventObserver; ///< Allows controls to observe when the visual has events to notify
   std::string                     mName;
-  Transform                       mTransform;
+  std::unique_ptr<Transform>      mTransform;
   Vector4                         mMixColor;
   Size                            mControlSize;
   DecorationData*                 mDecorationData;
@@ -261,15 +292,16 @@ struct Base::Impl
   int                             mFlags;
   Toolkit::Visual::ResourceStatus mResourceStatus;
   const Toolkit::Visual::Type     mType;
-  bool                            mAlwaysUsingBorderline : 1;         ///< Whether we need the borderline in shader always.
-  bool                            mAlwaysUsingCornerRadius : 1;       ///< Whether we need the corner radius in shader always.
-  bool                            mAlwaysUsingCornerSquareness : 1;   ///< Whether we need the corner squareness in shader always.
-  bool                            mIgnoreFittingMode : 1;             ///< Whether we need to ignore fitting mode.
-  bool                            mPixelAreaSetByFittingMode : 1;     ///< Whether the pixel area is set for fitting mode.
-  bool                            mTransformMapSetForFittingMode : 1; ///< Whether the transformMap is set for fitting mode.
-  bool                            mTransformMapUsingDefault : 1;      ///< Whether we are using the default transformMap not. We'll be false after SetTransform called, or animated.
-                                                                      ///< Note : If it change to false, never be true again.
-  bool mTransformMapChanged : 1;                                      ///< Whether the transformMap is changed or not. We'll be false after SetTransform called.
+
+  bool mAlwaysUsingBorderline : 1;         ///< Whether we need the borderline in shader always.
+  bool mAlwaysUsingCornerRadius : 1;       ///< Whether we need the corner radius in shader always.
+  bool mAlwaysUsingCornerSquareness : 1;   ///< Whether we need the corner squareness in shader always.
+  bool mIgnoreFittingMode : 1;             ///< Whether we need to ignore fitting mode.
+  bool mPixelAreaSetByFittingMode : 1;     ///< Whether the pixel area is set for fitting mode.
+  bool mTransformMapSetForFittingMode : 1; ///< Whether the transformMap is set for fitting mode.
+  bool mTransformMapUsingDefault : 1;      ///< Whether we are using the default transformMap not. We'll be false after SetTransform called, or animated.
+                                           ///< Note : If it change to false, never be true again.
+  bool mTransformMapChanged : 1;           ///< Whether the transformMap is changed or not. We'll be false after SetTransform called.
 };
 
 } // namespace Visual
index d61c1e46e560eef43100ab8c1d2645e80cbf279b..b8a26b6b4844278c5924eb614debdf697a8d1f76 100644 (file)
@@ -27,7 +27,7 @@
 #include <dali/public-api/rendering/decorated-visual-renderer.h>
 #include <dali/public-api/rendering/visual-renderer.h>
 
-//INTERNAL HEARDER
+// INTERNAL HEARDER
 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
 #include <dali-toolkit/devel-api/visuals/color-visual-properties-devel.h>
 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
@@ -242,28 +242,38 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap)
         Property::Map map;
         if(value.Get(map))
         {
-          if(DALI_UNLIKELY(mImpl->mRenderer))
+          if(!map.Empty() &&
+             (!mImpl->mTransformMapUsingDefault ||
+              map.GetHash() != Impl::Transform::GetDefaultTransformMap().GetHash() ||
+              DALI_UNLIKELY(map != Impl::Transform::GetDefaultTransformMap())))
           {
-            // Unusual case. SetProperty called after OnInitialize().
-            // Assume that DoAction call UPDATE_PROPERTY.
-            mImpl->mTransformMapChanged |= !map.Empty();
-            if(mImpl->mTransformMapChanged && mImpl->mTransformMapUsingDefault)
+            if(DALI_UNLIKELY(mImpl->mRenderer))
             {
-              mImpl->mTransformMapUsingDefault = false;
-              mImpl->mRenderer.RegisterVisualTransformUniform();
-            }
-            mImpl->mTransform.UpdatePropertyMap(map);
+              // Unusual case. SetProperty called after OnInitialize().
+              // Assume that DoAction call UPDATE_PROPERTY.
+              mImpl->mTransformMapChanged = true;
+              if(mImpl->mTransformMapUsingDefault)
+              {
+                mImpl->mTransformMapUsingDefault = false;
+                mImpl->mRenderer.RegisterVisualTransformUniform();
+              }
 
-            // Set Renderer uniforms, and change logics for subclasses.
-            OnSetTransform();
+              if(!mImpl->mTransformMapUsingDefault)
+              {
+                mImpl->GetOrCreateTransform().UpdatePropertyMap(map);
 
-            // Reset flag here.
-            mImpl->mTransformMapChanged = false;
-          }
-          else
-          {
-            mImpl->mTransformMapUsingDefault &= map.Empty();
-            mImpl->mTransform.SetPropertyMap(map);
+                // Set Renderer uniforms, and change logics for subclasses.
+                OnSetTransform();
+              }
+
+              // Reset flag here.
+              mImpl->mTransformMapChanged = false;
+            }
+            else
+            {
+              mImpl->mTransformMapUsingDefault = false;
+              mImpl->GetOrCreateTransform().SetPropertyMap(map);
+            }
           }
         }
         break;
@@ -542,7 +552,10 @@ void Visual::Base::SetTransformAndSize(const Property::Map& transform, Size cont
     mImpl->mTransformMapUsingDefault = false;
     mImpl->mRenderer.RegisterVisualTransformUniform();
   }
-  mImpl->mTransform.UpdatePropertyMap(transform);
+  if(!mImpl->mTransformMapUsingDefault)
+  {
+    mImpl->GetOrCreateTransform().UpdatePropertyMap(transform);
+  }
 
 #if defined(DEBUG_ENABLED)
   std::ostringstream oss;
@@ -680,8 +693,14 @@ void Visual::Base::CreatePropertyMap(Property::Map& map) const
     // Update values from Renderer
     mImpl->mMixColor = mImpl->mRenderer.GetProperty<Vector4>(Renderer::Property::MIX_COLOR);
 
-    mImpl->mTransform.mOffset = mImpl->mRenderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_OFFSET);
-    mImpl->mTransform.mSize   = mImpl->mRenderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_SIZE);
+    const auto& rendererOffset = mImpl->mRenderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_OFFSET);
+    const auto& rendererSize   = mImpl->mRenderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_SIZE);
+
+    if(rendererSize != Vector2::ZERO || rendererSize != Vector2::ONE)
+    {
+      mImpl->GetOrCreateTransform().mOffset = rendererOffset;
+      mImpl->GetOrCreateTransform().mSize   = rendererSize;
+    }
 
     if(IsRoundedCornerRequired())
     {
@@ -707,7 +726,14 @@ void Visual::Base::CreatePropertyMap(Property::Map& map) const
   }
 
   Property::Map transform;
-  mImpl->mTransform.GetPropertyMap(transform);
+  if(mImpl->mTransform)
+  {
+    mImpl->mTransform->GetPropertyMap(transform);
+  }
+  else
+  {
+    transform = Impl::Transform::GetDefaultTransformMap();
+  }
   map.Insert(Toolkit::Visual::Property::TRANSFORM, transform);
 
   bool premultipliedAlpha(IsPreMultipliedAlphaEnabled());
@@ -1334,7 +1360,7 @@ void Visual::Base::AnimateRendererProperty(
 
       // Set flag to ignore fitting mode when we set the transform property map
       mImpl->mIgnoreFittingMode = true;
-      mImpl->mTransform.UpdatePropertyMap(map);
+      mImpl->GetOrCreateTransform().UpdatePropertyMap(map);
     }
     SetupTransition(transition, animator, index, animator.initialValue, animator.targetValue);
   }