Improved visual base property registration speed 49/269649/1
authorDavid Steele <david.steele@samsung.com>
Wed, 19 Jan 2022 13:57:27 +0000 (13:57 +0000)
committerDavid Steele <david.steele@samsung.com>
Wed, 19 Jan 2022 14:00:19 +0000 (14:00 +0000)
Time taken to register visual properties was longer than needed
(No need to perform string matching to check for unique names)

Used new RegisterUniqueProperty API to remove unneeded check.

Change-Id: I2f12a8deb55bc118c0472871e872d1eb29b801a5
Signed-off-by: David Steele <david.steele@samsung.com>
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 8106899..654bb89 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 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.
@@ -385,12 +385,32 @@ void Internal::Visual::Base::Impl::Transform::GetPropertyMap(Property::Map& map)
 
 void Internal::Visual::Base::Impl::Transform::RegisterUniforms(Dali::Renderer renderer, Toolkit::Direction::Type direction)
 {
-  mSizeIndex   = renderer.RegisterProperty(SIZE, mSize);
-  mOffsetIndex = renderer.RegisterProperty(OFFSET, direction == Toolkit::Direction::LEFT_TO_RIGHT ? mOffset : mOffset * Vector2(-1.0f, 1.0f));
-  renderer.RegisterProperty(OFFSET_SIZE_MODE, mOffsetSizeMode);
-  renderer.RegisterProperty(ORIGIN, PointToVector2(mOrigin, direction) - Vector2(0.5, 0.5));
-  renderer.RegisterProperty(ANCHOR_POINT, Vector2(0.5, 0.5) - PointToVector2(mAnchorPoint, direction));
-  renderer.RegisterProperty(EXTRA_SIZE, mExtraSize);
+  // have to test if one of these properties has already been registered on the renderer; as some visuals use more than one renderer, so can't use stored property index.
+  //
+  if(Property::INVALID_INDEX == renderer.GetPropertyIndex(SIZE))
+  {
+    mSizeIndex   = renderer.RegisterUniqueProperty(SIZE, mSize);
+    mOffsetIndex = renderer.RegisterUniqueProperty(OFFSET, direction == Toolkit::Direction::LEFT_TO_RIGHT ? mOffset : mOffset * Vector2(-1.0f, 1.0f));
+    renderer.RegisterUniqueProperty(OFFSET_SIZE_MODE, mOffsetSizeMode);
+    renderer.RegisterUniqueProperty(ORIGIN, PointToVector2(mOrigin, direction) - Vector2(0.5, 0.5));
+    renderer.RegisterUniqueProperty(ANCHOR_POINT, Vector2(0.5, 0.5) - PointToVector2(mAnchorPoint, direction));
+    renderer.RegisterUniqueProperty(EXTRA_SIZE, mExtraSize);
+  }
+  else
+  {
+    SetUniforms(renderer, direction);
+  }
+}
+
+void Internal::Visual::Base::Impl::Transform::SetUniforms(Dali::Renderer renderer, Toolkit::Direction::Type direction)
+{
+  renderer.SetProperty(mSizeIndex, mSize);
+  renderer.SetProperty(mOffsetIndex, direction == Toolkit::Direction::LEFT_TO_RIGHT ? mOffset : mOffset * Vector2(-1.0f, 1.0f));
+
+  renderer.SetProperty(renderer.GetPropertyIndex(OFFSET_SIZE_MODE), mOffsetSizeMode);
+  renderer.SetProperty(renderer.GetPropertyIndex(ORIGIN), PointToVector2(mOrigin, direction) - Vector2(0.5, 0.5));
+  renderer.SetProperty(renderer.GetPropertyIndex(ANCHOR_POINT), Vector2(0.5, 0.5) - PointToVector2(mAnchorPoint, direction));
+  renderer.SetProperty(renderer.GetPropertyIndex(EXTRA_SIZE), mExtraSize);
 }
 
 Vector2 Internal::Visual::Base::Impl::Transform::GetVisualSize(const Vector2& controlSize)
index 64ab52f..3c8f072 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_VISUAL_BASE_DATA_IMPL_H
 
 /*
- * Copyright (c) 2021 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.
@@ -96,11 +96,16 @@ struct Base::Impl
     void UpdatePropertyMap(const Property::Map& map);
 
     /**
-     * Register or set the uniform properties onto the renderer
+     * Register the uniform properties onto the renderer
      */
     void RegisterUniforms(Renderer renderer, Toolkit::Direction::Type direction);
 
     /**
+     * Set the uniform properties onto the renderer
+     */
+    void SetUniforms(Renderer renderer, Toolkit::Direction::Type direction);
+
+    /**
      * Convert the control size and the transform attributes into the actual
      * size of the visual.
      */
@@ -112,8 +117,8 @@ struct Base::Impl
     Vector4              mOffsetSizeMode;
     Toolkit::Align::Type mOrigin;
     Toolkit::Align::Type mAnchorPoint;
-    Property::Index      mOffsetIndex;
-    Property::Index      mSizeIndex;
+    Property::Index      mOffsetIndex{Property::INVALID_INDEX};
+    Property::Index      mSizeIndex{Property::INVALID_INDEX};
   };
 
   Renderer                        mRenderer;
index 2841655..004d201 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 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.
@@ -135,16 +135,16 @@ void Visual::Base::Initialize()
 
     if(IsRoundedCornerRequired())
     {
-      mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
-      mImpl->mRenderer.RegisterProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
+      mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
+      mImpl->mRenderer.RegisterUniqueProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
 
       mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
     }
     if(IsBorderlineRequired())
     {
-      mImpl->mBorderlineWidthIndex  = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_WIDTH,  BORDERLINE_WIDTH,  mImpl->mBorderlineWidth);
-      mImpl->mBorderlineColorIndex  = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_COLOR,  BORDERLINE_COLOR,  mImpl->mBorderlineColor);
-      mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
+      mImpl->mBorderlineWidthIndex  = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
+      mImpl->mBorderlineColorIndex  = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor);
+      mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
 
       mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
     }
@@ -307,10 +307,10 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap)
           // Assume that DoAction call UPDATE_PROPERTY.
           // We must regist properies into renderer, and update shader.
 
-          // Borderline added by this action. Regist property to renderer.
-          mImpl->mBorderlineWidthIndex  = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
-          mImpl->mBorderlineColorIndex  = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor);
-          mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
+          // Borderline added by this action. Register property to renderer.
+          mImpl->mBorderlineWidthIndex  = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
+          mImpl->mBorderlineColorIndex  = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor);
+          mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
 
           // Make Blend mode ON_WITHOUT_CULL for transparent mix color.
           mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
@@ -386,8 +386,8 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap)
           // We must regist properies into renderer, and update shader.
 
           // CornerRadius added by this action. Regist property to renderer.
-          mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
-          mImpl->mRenderer.RegisterProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
+          mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
+          mImpl->mRenderer.RegisterUniqueProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
 
           // Change the shader must not be occured many times. we always have to use corner radius feature.
           mImpl->mAlwaysUsingCornerRadius = true;
@@ -706,7 +706,7 @@ void Visual::Base::RegisterMixColor()
   // (Color and Primitive visuals will register their own and save to this index)
   if(mImpl->mMixColorIndex == Property::INVALID_INDEX)
   {
-    mImpl->mMixColorIndex = mImpl->mRenderer.RegisterProperty(
+    mImpl->mMixColorIndex = mImpl->mRenderer.RegisterUniqueProperty(
       Toolkit::Visual::Property::MIX_COLOR,
       MIX_COLOR,
       Vector3(mImpl->mMixColor));
@@ -1050,16 +1050,16 @@ Dali::Property Visual::Base::GetPropertyObject(Dali::Property::Key key)
   if(index == Property::INVALID_INDEX)
   {
     if(IsTypeAvailableForBorderline(mImpl->mType) &&
-       ((key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_WIDTH)  || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_WIDTH) ||
-        (key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_COLOR)  || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_COLOR) ||
+       ((key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_WIDTH) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_WIDTH) ||
+        (key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_COLOR) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_COLOR) ||
         (key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::BORDERLINE_OFFSET) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_OFFSET)))
     {
       mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
 
       // Register borderline properties
-      mImpl->mBorderlineWidthIndex  = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
-      mImpl->mBorderlineColorIndex  = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor);
-      mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
+      mImpl->mBorderlineWidthIndex  = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_WIDTH, BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
+      mImpl->mBorderlineColorIndex  = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_COLOR, BORDERLINE_COLOR, mImpl->mBorderlineColor);
+      mImpl->mBorderlineOffsetIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::BORDERLINE_OFFSET, BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
 
       // Borderline is animated now. we always have to use borderline feature.
       mImpl->mAlwaysUsingBorderline = true;
@@ -1072,10 +1072,10 @@ Dali::Property Visual::Base::GetPropertyObject(Dali::Property::Key key)
     else if(IsTypeAvailableForCornerRadius(mImpl->mType) && ((key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::CORNER_RADIUS) || (key.type == Property::Key::STRING && key.stringKey == CORNER_RADIUS)))
     {
       // Register CORNER_RADIUS property
-      mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
-      mImpl->mRenderer.RegisterProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
+      mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterUniqueProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
+      mImpl->mRenderer.RegisterUniqueProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
 
-      // ConerRadius is animated now. we always have to use corner radius feature.
+      // CornerRadius is animated now. we always have to use corner radius feature.
       mImpl->mAlwaysUsingCornerRadius = true;
 
       if(!IsBorderlineRequired())