Fix crash issue at VisualBase (DoAction + AnimateTo)
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-base-impl.cpp
index 443c51c..99b6c38 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.
 #include <dali/devel-api/rendering/renderer-devel.h>
 #include <dali/devel-api/scripting/enum-helper.h>
 #include <dali/integration-api/debug.h>
+#include <dali/public-api/rendering/decorated-visual-renderer.h>
+#include <dali/public-api/rendering/visual-renderer.h>
 
 //INTERNAL HEARDER
+#include <dali-toolkit/devel-api/visuals/color-visual-properties-devel.h>
+#include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include <dali-toolkit/internal/helpers/property-helper.h>
 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
@@ -39,7 +43,9 @@ namespace
 Debug::Filter* gVisualBaseLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VISUAL_BASE");
 #endif
 
-const char* const PRE_MULTIPLIED_ALPHA_PROPERTY("preMultipliedAlpha");
+// visual string constants contains OFFSET_SIZE_MODE instead
+const char* const OFFSET_POLICY("offsetPolicy");
+const char* const SIZE_POLICY("sizePolicy");
 
 } // namespace
 
@@ -131,22 +137,16 @@ void Visual::Base::Initialize()
   if(mImpl->mRenderer)
   {
     RegisterMixColor();
+    RegisterDecoration();
 
-    if(IsRoundedCornerRequired())
-    {
-      mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
-      mImpl->mRenderer.RegisterProperty(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->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
     }
+    else if(IsRoundedCornerRequired())
+    {
+      mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
+    }
   }
 }
 
@@ -167,6 +167,7 @@ void Visual::Base::SetCustomShader(const Property::Map& shaderMap)
 
 void Visual::Base::SetProperties(const Property::Map& propertyMap)
 {
+  bool needUpdateShader = false;
   for(size_t i = 0; i < propertyMap.Count(); ++i)
   {
     const KeyValuePair&    pair  = propertyMap.GetKeyValue(i);
@@ -294,6 +295,30 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap)
         {
           mImpl->mBorderlineWidth = width;
         }
+
+        if(DALI_UNLIKELY(mImpl->mRenderer && IsTypeAvailableForBorderline(mImpl->mType)))
+        {
+          // Unusual case. SetProperty called after OnInitialize().
+          // Assume that DoAction call UPDATE_PROPERTY.
+          DownCast<DecoratedVisualRenderer>(mImpl->mRenderer).RegisterBorderlineUniform();
+          mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
+
+          // Check whether we must update shader.
+          if(!mImpl->mAlwaysUsingBorderline && IsBorderlineRequired())
+          {
+            // Make Blend mode ON_WITHOUT_CULL for transparent mix color.
+            mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
+
+            // Change the shader must not be occured many times. we always have to use borderline feature.
+            mImpl->mAlwaysUsingBorderline = true;
+
+            // Change shader
+            if(!mImpl->mCustomShader)
+            {
+              needUpdateShader = true;
+            }
+          }
+        }
         break;
       }
       case Toolkit::DevelVisual::Property::BORDERLINE_COLOR:
@@ -303,6 +328,13 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap)
         {
           mImpl->mBorderlineColor = color;
         }
+
+        if(DALI_UNLIKELY(mImpl->mRenderer && IsTypeAvailableForBorderline(mImpl->mType)))
+        {
+          // Unusual case. SetProperty called after OnInitialize().
+          // Assume that DoAction call UPDATE_PROPERTY.
+          mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR, mImpl->mBorderlineColor);
+        }
         break;
       }
       case Toolkit::DevelVisual::Property::BORDERLINE_OFFSET:
@@ -312,6 +344,13 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap)
         {
           mImpl->mBorderlineOffset = offset;
         }
+
+        if(DALI_UNLIKELY(mImpl->mRenderer && IsTypeAvailableForBorderline(mImpl->mType)))
+        {
+          // Unusual case. SetProperty called after OnInitialize().
+          // Assume that DoAction call UPDATE_PROPERTY.
+          mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
+        }
         break;
       }
       case Toolkit::DevelVisual::Property::CORNER_RADIUS:
@@ -337,6 +376,34 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap)
             mImpl->mCornerRadius = Vector4(radius, radius, radius, radius);
           }
         }
+
+        if(DALI_UNLIKELY(mImpl->mRenderer && IsTypeAvailableForCornerRadius(mImpl->mType)))
+        {
+          // Unusual case. SetProperty called after OnInitialize().
+          // Assume that DoAction call UPDATE_PROPERTY.
+          DownCast<DecoratedVisualRenderer>(mImpl->mRenderer).RegisterCornerRadiusUniform();
+          mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS, mImpl->mCornerRadius);
+
+          // Check whether we must update shader.
+          if(!mImpl->mAlwaysUsingCornerRadius && IsRoundedCornerRequired())
+          {
+            // Change the shader must not be occured many times. we always have to use corner radius feature.
+            mImpl->mAlwaysUsingCornerRadius = true;
+
+            if(!IsBorderlineRequired())
+            {
+              // If IsBorderlineRequired is true, BLEND_MODE is already BlendMode::ON_WITHOUT_CULL. So we don't overwrite it.
+              mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
+            }
+
+            // Change shader
+            if(!mImpl->mCustomShader)
+            {
+              needUpdateShader = true;
+            }
+          }
+        }
+
         break;
       }
       case Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY:
@@ -350,6 +417,12 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap)
             case Toolkit::Visual::Transform::Policy::ABSOLUTE:
             {
               mImpl->mCornerRadiusPolicy = policy;
+              if(DALI_UNLIKELY(mImpl->mRenderer))
+              {
+                // Unusual case. SetProperty called after OnInitialize().
+                // Assume that DoAction call UPDATE_PROPERTY.
+                mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
+              }
               break;
             }
             default:
@@ -365,6 +438,11 @@ void Visual::Base::SetProperties(const Property::Map& propertyMap)
   }
 
   DoSetProperties(propertyMap);
+
+  if(DALI_UNLIKELY(needUpdateShader))
+  {
+    UpdateShader();
+  }
 }
 
 void Visual::Base::SetTransformAndSize(const Property::Map& transform, Size controlSize)
@@ -423,6 +501,20 @@ void Visual::Base::GetNaturalSize(Vector2& naturalSize)
 void Visual::Base::DoAction(const Property::Index actionId, const Property::Value attributes)
 {
   OnDoAction(actionId, attributes);
+
+  // Check if action is valid for this visual type and perform action if possible
+  switch(actionId)
+  {
+    case DevelVisual::Action::UPDATE_PROPERTY:
+    {
+      const Property::Map* map = attributes.GetMap();
+      if(map)
+      {
+        SetProperties(*map);
+      }
+      break;
+    }
+  }
 }
 
 void Visual::Base::SetDepthIndex(int index)
@@ -471,31 +563,21 @@ void Visual::Base::CreatePropertyMap(Property::Map& map) const
   if(mImpl->mRenderer)
   {
     // Update values from Renderer
-    mImpl->mMixColor   = mImpl->mRenderer.GetProperty<Vector3>(mImpl->mMixColorIndex);
+    mImpl->mMixColor   = mImpl->mRenderer.GetProperty<Vector3>(VisualRenderer::Property::VISUAL_MIX_COLOR);
     mImpl->mMixColor.a = mImpl->mRenderer.GetProperty<float>(DevelRenderer::Property::OPACITY);
-    if(mImpl->mTransform.mOffsetIndex != Property::INVALID_INDEX)
-    {
-      mImpl->mTransform.mOffset = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mOffsetIndex);
-    }
-    if(mImpl->mTransform.mSizeIndex != Property::INVALID_INDEX)
-    {
-      mImpl->mTransform.mSize = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mSizeIndex);
-    }
-    if(mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
-    {
-      mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mCornerRadiusIndex);
-    }
-    if(mImpl->mBorderlineWidthIndex != Property::INVALID_INDEX)
-    {
-      mImpl->mBorderlineWidth = mImpl->mRenderer.GetProperty<float>(mImpl->mBorderlineWidthIndex);
-    }
-    if(mImpl->mBorderlineColorIndex != Property::INVALID_INDEX)
+
+    mImpl->mTransform.mOffset = mImpl->mRenderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_OFFSET);
+    mImpl->mTransform.mSize   = mImpl->mRenderer.GetProperty<Vector2>(VisualRenderer::Property::TRANSFORM_SIZE);
+
+    if(IsTypeAvailableForCornerRadius(mImpl->mType))
     {
-      mImpl->mBorderlineColor = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mBorderlineColorIndex);
+      mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<Vector4>(DecoratedVisualRenderer::Property::CORNER_RADIUS);
     }
-    if(mImpl->mBorderlineOffsetIndex != Property::INVALID_INDEX)
+    if(IsTypeAvailableForBorderline(mImpl->mType))
     {
-      mImpl->mBorderlineOffset = mImpl->mRenderer.GetProperty<float>(mImpl->mBorderlineOffsetIndex);
+      mImpl->mBorderlineWidth  = mImpl->mRenderer.GetProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH);
+      mImpl->mBorderlineColor  = mImpl->mRenderer.GetProperty<Vector4>(DecoratedVisualRenderer::Property::BORDERLINE_COLOR);
+      mImpl->mBorderlineOffset = mImpl->mRenderer.GetProperty<float>(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET);
     }
   }
 
@@ -514,7 +596,7 @@ void Visual::Base::CreatePropertyMap(Property::Map& map) const
   map.Insert(Toolkit::Visual::Property::PREMULTIPLIED_ALPHA, premultipliedAlpha);
 
   // Note, Color and Primitive will also insert their own mix color into the map
-  // which is ok, because they have a different key value range.
+  // which is ok, because they have a different key value range, but uses same cached value anyway.
   map.Insert(Toolkit::Visual::Property::MIX_COLOR, mImpl->mMixColor); // vec4
   map.Insert(Toolkit::Visual::Property::OPACITY, mImpl->mMixColor.a);
 
@@ -522,12 +604,18 @@ void Visual::Base::CreatePropertyMap(Property::Map& map) const
     mImpl->mFittingMode, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT);
   map.Insert(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE, fittingModeString);
 
-  map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
-  map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, mImpl->mBorderlineColor);
-  map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
+  if(IsTypeAvailableForBorderline(mImpl->mType))
+  {
+    map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
+    map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, mImpl->mBorderlineColor);
+    map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
+  }
 
-  map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS, mImpl->mCornerRadius);
-  map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, static_cast<int>(mImpl->mCornerRadiusPolicy));
+  if(IsTypeAvailableForCornerRadius(mImpl->mType))
+  {
+    map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS, mImpl->mCornerRadius);
+    map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, static_cast<int>(mImpl->mCornerRadiusPolicy));
+  }
 }
 
 void Visual::Base::CreateInstancePropertyMap(Property::Map& map) const
@@ -554,7 +642,7 @@ void Visual::Base::EnablePreMultipliedAlpha(bool preMultiplied)
   if(mImpl->mRenderer)
   {
     mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, preMultiplied);
-    mImpl->mRenderer.RegisterProperty(PRE_MULTIPLIED_ALPHA_PROPERTY, static_cast<float>(preMultiplied));
+    mImpl->mRenderer.SetProperty(VisualRenderer::Property::VISUAL_PRE_MULTIPLIED_ALPHA, preMultiplied);
   }
 }
 
@@ -578,12 +666,13 @@ bool Visual::Base::IsRoundedCornerRequired() const
   // If VisualType doesn't support rounded corner, always return false.
   if(IsTypeAvailableForCornerRadius(mImpl->mType))
   {
-    if(mImpl->mRenderer && mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
+    if(mImpl->mRenderer)
     {
       // Update values from Renderer
-      mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<Vector4>(mImpl->mCornerRadiusIndex);
+      Property::Value value = mImpl->mRenderer.GetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS);
+      value.Get(mImpl->mCornerRadius);
     }
-    return !(mImpl->mCornerRadius == Vector4::ZERO) || mImpl->mAlwaysUsingCornerRadius;
+    return mImpl->mAlwaysUsingCornerRadius || !(mImpl->mCornerRadius == Vector4::ZERO);
   }
   return false;
 }
@@ -593,12 +682,13 @@ bool Visual::Base::IsBorderlineRequired() const
   // If VisualType doesn't support borderline, always return false.
   if(IsTypeAvailableForBorderline(mImpl->mType))
   {
-    if(mImpl->mRenderer && mImpl->mBorderlineWidthIndex != Property::INVALID_INDEX)
+    if(mImpl->mRenderer)
     {
       // Update values from Renderer
-      mImpl->mBorderlineWidth = mImpl->mRenderer.GetProperty<float>(mImpl->mBorderlineWidthIndex);
+      Property::Value value = mImpl->mRenderer.GetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH);
+      value.Get(mImpl->mBorderlineWidth);
     }
-    return !EqualsZero(mImpl->mBorderlineWidth) || mImpl->mAlwaysUsingBorderline;
+    return mImpl->mAlwaysUsingBorderline || !EqualsZero(mImpl->mBorderlineWidth);
   }
   return false;
 }
@@ -610,24 +700,45 @@ void Visual::Base::OnDoAction(const Property::Index actionId, const Property::Va
 
 void Visual::Base::RegisterMixColor()
 {
-  // Only register if not already registered.
-  // (Color and Primitive visuals will register their own and save to this index)
-  if(mImpl->mMixColorIndex == Property::INVALID_INDEX)
+  if(mImpl->mRenderer)
   {
-    mImpl->mMixColorIndex = mImpl->mRenderer.RegisterProperty(
-      Toolkit::Visual::Property::MIX_COLOR,
-      MIX_COLOR,
-      Vector3(mImpl->mMixColor));
-  }
+    // All visual renderers now use same mix color / opacity properties.
+    mImpl->mRenderer.SetProperty(VisualRenderer::Property::VISUAL_MIX_COLOR, Vector3(mImpl->mMixColor));
+    mImpl->mRenderer.SetProperty(DevelRenderer::Property::OPACITY, mImpl->mMixColor.a);
 
-  mImpl->mRenderer.SetProperty(DevelRenderer::Property::OPACITY, mImpl->mMixColor.a);
+    float preMultipliedAlpha = 0.0f;
+    if(IsPreMultipliedAlphaEnabled())
+    {
+      preMultipliedAlpha = 1.0f;
+    }
+    mImpl->mRenderer.SetProperty(VisualRenderer::Property::VISUAL_PRE_MULTIPLIED_ALPHA, preMultipliedAlpha);
+  }
+}
 
-  float preMultipliedAlpha = 0.0f;
-  if(IsPreMultipliedAlphaEnabled())
+void Visual::Base::RegisterDecoration()
+{
+  if(mImpl->mRenderer)
   {
-    preMultipliedAlpha = 1.0f;
+    if(IsTypeAvailableForCornerRadius(mImpl->mType))
+    {
+      if(mImpl->mAlwaysUsingCornerRadius || !(mImpl->mCornerRadius == Vector4::ZERO))
+      {
+        DownCast<DecoratedVisualRenderer>(mImpl->mRenderer).RegisterCornerRadiusUniform();
+        mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS, mImpl->mCornerRadius);
+        mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
+      }
+    }
+    if(IsTypeAvailableForBorderline(mImpl->mType))
+    {
+      if(mImpl->mAlwaysUsingBorderline || !EqualsZero(mImpl->mBorderlineWidth))
+      {
+        DownCast<DecoratedVisualRenderer>(mImpl->mRenderer).RegisterBorderlineUniform();
+        mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
+        mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR, mImpl->mBorderlineColor);
+        mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
+      }
+    }
   }
-  mImpl->mRenderer.RegisterProperty(PRE_MULTIPLIED_ALPHA_PROPERTY, preMultipliedAlpha);
 }
 
 void Visual::Base::SetMixColor(const Vector4& color)
@@ -636,7 +747,7 @@ void Visual::Base::SetMixColor(const Vector4& color)
 
   if(mImpl->mRenderer)
   {
-    mImpl->mRenderer.SetProperty(mImpl->mMixColorIndex, Vector3(color));
+    mImpl->mRenderer.SetProperty(VisualRenderer::Property::VISUAL_MIX_COLOR, Vector3(color));
     mImpl->mRenderer.SetProperty(DevelRenderer::Property::OPACITY, color.a);
   }
 }
@@ -649,7 +760,7 @@ void Visual::Base::SetMixColor(const Vector3& color)
 
   if(mImpl->mRenderer)
   {
-    mImpl->mRenderer.SetProperty(mImpl->mMixColorIndex, color);
+    mImpl->mRenderer.SetProperty(VisualRenderer::Property::VISUAL_MIX_COLOR, color);
   }
 }
 
@@ -679,7 +790,8 @@ void Visual::Base::ResourceReady(Toolkit::Visual::ResourceStatus resourceStatus)
 
 bool Visual::Base::IsResourceReady() const
 {
-  return (mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::READY);
+  return (mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::READY ||
+          mImpl->mResourceStatus == Toolkit::Visual::ResourceStatus::FAILED);
 }
 
 bool Visual::Base::IsSynchronousLoadingRequired() const
@@ -712,8 +824,139 @@ Renderer Visual::Base::GetRenderer()
   return mImpl->mRenderer;
 }
 
+Property::Index Visual::Base::GetIntKey(Property::Key key)
+{
+  if(key.type == Property::Key::INDEX)
+  {
+    return key.indexKey;
+  }
+
+  if(key.stringKey == ANCHOR_POINT)
+  {
+    return Toolkit::Visual::Transform::Property::ANCHOR_POINT;
+  }
+  else if(key.stringKey == EXTRA_SIZE)
+  {
+    return Toolkit::DevelVisual::Transform::Property::EXTRA_SIZE;
+  }
+  else if(key.stringKey == MIX_COLOR)
+  {
+    return Toolkit::Visual::Property::MIX_COLOR;
+  }
+  else if(key.stringKey == OPACITY)
+  {
+    return Toolkit::Visual::Property::OPACITY;
+  }
+  else if(key.stringKey == OFFSET)
+  {
+    return Toolkit::Visual::Transform::Property::OFFSET;
+  }
+  else if(key.stringKey == OFFSET_POLICY)
+  {
+    return Toolkit::Visual::Transform::Property::OFFSET_POLICY;
+  }
+  else if(key.stringKey == ORIGIN)
+  {
+    return Toolkit::Visual::Transform::Property::ORIGIN;
+  }
+  else if(key.stringKey == PREMULTIPLIED_ALPHA)
+  {
+    return Toolkit::Visual::Property::PREMULTIPLIED_ALPHA;
+  }
+  else if(key.stringKey == CUSTOM_SHADER)
+  {
+    return Toolkit::Visual::Property::SHADER;
+  }
+  else if(key.stringKey == SIZE)
+  {
+    return Toolkit::Visual::Transform::Property::SIZE;
+  }
+  else if(key.stringKey == SIZE_POLICY)
+  {
+    return Toolkit::Visual::Transform::Property::SIZE_POLICY;
+  }
+  else if(key.stringKey == TRANSFORM)
+  {
+    return Toolkit::Visual::Property::TRANSFORM;
+  }
+  else if(key.stringKey == VISUAL_FITTING_MODE)
+  {
+    return Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE;
+  }
+  else if(key.stringKey == CORNER_RADIUS)
+  {
+    return Toolkit::DevelVisual::Property::CORNER_RADIUS;
+  }
+  else if(key.stringKey == CORNER_RADIUS_POLICY)
+  {
+    return Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY;
+  }
+  else if(key.stringKey == BORDERLINE_WIDTH)
+  {
+    return Toolkit::DevelVisual::Property::BORDERLINE_WIDTH;
+  }
+  else if(key.stringKey == BORDERLINE_COLOR)
+  {
+    return Toolkit::DevelVisual::Property::BORDERLINE_COLOR;
+  }
+  else if(key.stringKey == BORDERLINE_OFFSET)
+  {
+    return Toolkit::DevelVisual::Property::BORDERLINE_OFFSET;
+  }
+
+  return Property::INVALID_INDEX;
+}
+
 Property::Index Visual::Base::GetPropertyIndex(Property::Key key)
 {
+  switch(GetIntKey(key))
+  {
+    case Dali::Toolkit::Visual::Transform::Property::OFFSET:
+    {
+      return VisualRenderer::Property::TRANSFORM_OFFSET;
+    }
+    case Dali::Toolkit::Visual::Transform::Property::SIZE:
+    {
+      return VisualRenderer::Property::TRANSFORM_SIZE;
+    }
+    case Dali::Toolkit::Visual::Transform::Property::ORIGIN:
+    {
+      return VisualRenderer::Property::TRANSFORM_ORIGIN;
+    }
+    case Dali::Toolkit::Visual::Transform::Property::ANCHOR_POINT:
+    {
+      return VisualRenderer::Property::TRANSFORM_ANCHOR_POINT;
+    }
+    case Dali::Toolkit::Visual::Property::MIX_COLOR:
+    {
+      return VisualRenderer::Property::VISUAL_MIX_COLOR;
+    }
+    case Dali::Toolkit::Visual::Property::OPACITY:
+    {
+      return DevelRenderer::Property::OPACITY;
+    }
+    case Dali::Toolkit::Visual::Property::PREMULTIPLIED_ALPHA:
+    {
+      return VisualRenderer::Property::VISUAL_PRE_MULTIPLIED_ALPHA;
+    }
+    case Dali::Toolkit::DevelVisual::Property::CORNER_RADIUS:
+    {
+      return DecoratedVisualRenderer::Property::CORNER_RADIUS;
+    }
+    case Dali::Toolkit::DevelVisual::Property::BORDERLINE_WIDTH:
+    {
+      return DecoratedVisualRenderer::Property::BORDERLINE_WIDTH;
+    }
+    case Dali::Toolkit::DevelVisual::Property::BORDERLINE_COLOR:
+    {
+      return DecoratedVisualRenderer::Property::BORDERLINE_COLOR;
+    }
+    case Dali::Toolkit::DevelVisual::Property::BORDERLINE_OFFSET:
+    {
+      return DecoratedVisualRenderer::Property::BORDERLINE_OFFSET;
+    }
+  }
+
   Property::Index index = mImpl->mRenderer.GetPropertyIndex(key);
 
   if(index == Property::INVALID_INDEX)
@@ -738,7 +981,9 @@ Property::Index Visual::Base::GetPropertyIndex(Property::Key key)
         // Leave keyIndex as INVALID_KEY - it can still be registered against the string key.
       }
       Property::Value value = shader.GetProperty(index);
-      index                 = mImpl->mRenderer.RegisterProperty(keyIndex, keyName, value);
+
+      // We already know that mRenderer didn't have property. So we can assume that it is unique.
+      index = mImpl->mRenderer.RegisterUniqueProperty(keyIndex, keyName, value);
     }
   }
   return index;
@@ -786,6 +1031,7 @@ void Visual::Base::AnimateProperty(
   Internal::TransitionData::Animator& animator)
 {
 #if defined(DEBUG_ENABLED)
+  if(gVisualBaseLogFilter->IsEnabledFor(Debug::General))
   {
     std::ostringstream oss;
     oss << "Visual::Base::AnimateProperty(Visual:" << mImpl->mName << " Property:" << animator.propertyKey << " Target: " << animator.targetValue << std::endl;
@@ -830,7 +1076,9 @@ void Visual::Base::AnimateRendererProperty(
   Dali::Animation&                    transition,
   Internal::TransitionData::Animator& animator)
 {
+  // Get actual renderer index (will convert transform keys into visualproperty indices)
   Property::Index index = GetPropertyIndex(animator.propertyKey);
+
   if(index != Property::INVALID_INDEX)
   {
     if(animator.targetValue.GetType() != Property::NONE)
@@ -849,7 +1097,6 @@ void Visual::Base::AnimateRendererProperty(
 
       mImpl->mTransform.UpdatePropertyMap(map);
     }
-
     SetupTransition(transition, animator, index, animator.initialValue, animator.targetValue);
   }
 }
@@ -858,50 +1105,47 @@ void Visual::Base::AnimateMixColorProperty(
   Dali::Animation&                    transition,
   Internal::TransitionData::Animator& animator)
 {
-  Property::Index index          = mImpl->mMixColorIndex;
-  bool            animateOpacity = false;
+  bool animateOpacity = false;
 
   Property::Value initialOpacity;
   Property::Value targetOpacity;
   Property::Value initialMixColor;
   Property::Value targetMixColor;
 
-  if(index != Property::INVALID_INDEX)
+  Vector4 initialColor;
+  if(animator.initialValue.Get(initialColor))
   {
-    Vector4 initialColor;
-    if(animator.initialValue.Get(initialColor))
+    if(animator.initialValue.GetType() == Property::VECTOR4)
     {
-      if(animator.initialValue.GetType() == Property::VECTOR4)
-      {
-        // if there is an initial color specifying alpha, test it
-        initialOpacity = initialColor.a;
-      }
-      initialMixColor = Vector3(initialColor);
+      // if there is an initial color specifying alpha, test it
+      initialOpacity = initialColor.a;
     }
+    initialMixColor = Vector3(initialColor);
+  }
 
-    // Set target value into data store
-    if(animator.targetValue.GetType() != Property::NONE)
+  // Set target value into data store
+  if(animator.targetValue.GetType() != Property::NONE)
+  {
+    Vector4 mixColor;
+    animator.targetValue.Get(mixColor);
+    if(animator.targetValue.GetType() == Property::VECTOR4)
     {
-      Vector4 mixColor;
-      animator.targetValue.Get(mixColor);
-      if(animator.targetValue.GetType() == Property::VECTOR4)
-      {
-        mImpl->mMixColor.a = mixColor.a;
-        targetOpacity      = mixColor.a;
-        animateOpacity     = true;
-      }
-
-      mImpl->mMixColor.r = mixColor.r;
-      mImpl->mMixColor.g = mixColor.g;
-      mImpl->mMixColor.b = mixColor.b;
-      targetMixColor     = Vector3(mixColor);
+      mImpl->mMixColor.a = mixColor.a;
+      targetOpacity      = mixColor.a;
+      animateOpacity     = true;
     }
 
-    SetupTransition(transition, animator, index, initialMixColor, targetMixColor);
-    if(animateOpacity)
-    {
-      SetupTransition(transition, animator, DevelRenderer::Property::OPACITY, initialOpacity, targetOpacity);
-    }
+    mImpl->mMixColor.r = mixColor.r;
+    mImpl->mMixColor.g = mixColor.g;
+    mImpl->mMixColor.b = mixColor.b;
+    targetMixColor     = Vector3(mixColor);
+  }
+
+  SetupTransition(transition, animator, VisualRenderer::Property::VISUAL_MIX_COLOR, initialMixColor, targetMixColor);
+
+  if(animateOpacity)
+  {
+    SetupTransition(transition, animator, DevelRenderer::Property::OPACITY, initialOpacity, targetOpacity);
   }
 }
 
@@ -913,99 +1157,114 @@ Dali::Property Visual::Base::GetPropertyObject(Dali::Property::Key key)
     return Dali::Property(handle, Property::INVALID_INDEX);
   }
 
-  // Mix color or opacity cases
-  if(key.type == Property::Key::INDEX)
-  {
-    if(key.indexKey == Toolkit::Visual::Property::MIX_COLOR || (mImpl->mType == Toolkit::Visual::COLOR && key.indexKey == ColorVisual::Property::MIX_COLOR) || (mImpl->mType == Toolkit::Visual::PRIMITIVE && key.indexKey == PrimitiveVisual::Property::MIX_COLOR))
-    {
-      return Dali::Property(mImpl->mRenderer, mImpl->mMixColorIndex);
-    }
-    else if(key.indexKey == Toolkit::Visual::Property::OPACITY)
-    {
-      return Dali::Property(mImpl->mRenderer, DevelRenderer::Property::OPACITY);
-    }
-    else if(key.indexKey == Toolkit::Visual::Transform::Property::OFFSET)
-    {
-      return Dali::Property(mImpl->mRenderer, OFFSET);
-    }
-    else if(key.indexKey == Toolkit::Visual::Transform::Property::SIZE)
-    {
-      return Dali::Property(mImpl->mRenderer, SIZE);
-    }
-  }
-  else
+  switch(GetIntKey(key))
   {
-    if(key.stringKey == MIX_COLOR)
+    // Default animatable properties from VisualRenderer
+    case Toolkit::Visual::Property::MIX_COLOR:
     {
-      return Dali::Property(mImpl->mRenderer, mImpl->mMixColorIndex);
+      return Dali::Property(mImpl->mRenderer, VisualRenderer::Property::VISUAL_MIX_COLOR);
     }
-    else if(key.stringKey == OPACITY)
+    case Toolkit::Visual::Property::OPACITY:
     {
       return Dali::Property(mImpl->mRenderer, DevelRenderer::Property::OPACITY);
     }
-    else if(key.stringKey == OFFSET)
+    case Toolkit::Visual::Transform::Property::OFFSET:
     {
-      return Dali::Property(mImpl->mRenderer, OFFSET);
+      return Dali::Property(mImpl->mRenderer, VisualRenderer::Property::TRANSFORM_OFFSET);
     }
-    else if(key.stringKey == SIZE)
+    case Toolkit::Visual::Transform::Property::SIZE:
     {
-      return Dali::Property(mImpl->mRenderer, SIZE);
+      return Dali::Property(mImpl->mRenderer, VisualRenderer::Property::TRANSFORM_SIZE);
     }
-  }
 
-  // Other cases
-  Property::Index index = GetPropertyIndex(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_OFFSET) || (key.type == Property::Key::STRING && key.stringKey == BORDERLINE_OFFSET)))
+    // Default animatable properties from DecoratedVisualRenderer
+    case Toolkit::DevelVisual::Property::CORNER_RADIUS:
     {
-      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);
+      if(IsTypeAvailableForCornerRadius(mImpl->mType))
+      {
+        const bool updateShader = !mImpl->mCustomShader && !IsRoundedCornerRequired();
 
-      // Borderline is animated now. we always have to use borderline feature.
-      mImpl->mAlwaysUsingBorderline = true;
+        // CornerRadius is animated now. we always have to use corner radius feature.
+        mImpl->mAlwaysUsingCornerRadius = true;
 
-      index = mImpl->mRenderer.GetPropertyIndex(key);
+        if(updateShader)
+        {
+          // Update each values to renderer
+          DownCast<DecoratedVisualRenderer>(mImpl->mRenderer).RegisterCornerRadiusUniform();
+          mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS, mImpl->mCornerRadius);
+          mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
 
-      // Change shader
-      UpdateShader();
+          // Change shader
+          UpdateShader();
+        }
+        if(!IsBorderlineRequired())
+        {
+          // If IsBorderlineRequired is true, BLEND_MODE is already BlendMode::ON_WITHOUT_CULL. So we don't overwrite it.
+          mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
+        }
+        return Dali::Property(mImpl->mRenderer, DecoratedVisualRenderer::Property::CORNER_RADIUS);
+      }
+      break;
     }
-    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)))
+    case Toolkit::DevelVisual::Property::BORDERLINE_WIDTH:
+    case Toolkit::DevelVisual::Property::BORDERLINE_COLOR:
+    case Toolkit::DevelVisual::Property::BORDERLINE_OFFSET:
     {
-      // 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);
-
-      // ConerRadius is animated now. we always have to use corner radius feature.
-      mImpl->mAlwaysUsingCornerRadius = true;
-
-      if(!IsBorderlineRequired())
+      if(IsTypeAvailableForBorderline(mImpl->mType))
       {
-        // If IsBorderlineRequired is true, BLEND_MODE is already BlendMode::ON_WITHOUT_CULL. So we don't overwrite it.
-        mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
-      }
+        const bool updateShader = !mImpl->mCustomShader && !IsBorderlineRequired();
+
+        // Borderline is animated now. we always have to use borderline feature.
+        mImpl->mAlwaysUsingBorderline = true;
 
-      index = mImpl->mCornerRadiusIndex;
+        if(updateShader)
+        {
+          // Update each values to renderer
+          DownCast<DecoratedVisualRenderer>(mImpl->mRenderer).RegisterBorderlineUniform();
+          mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_WIDTH, mImpl->mBorderlineWidth);
+          mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_COLOR, mImpl->mBorderlineColor);
+          mImpl->mRenderer.SetProperty(DecoratedVisualRenderer::Property::BORDERLINE_OFFSET, mImpl->mBorderlineOffset);
+
+          // Change shader
+          UpdateShader();
+        }
+        mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
 
-      // Change shader
-      UpdateShader();
+        return Dali::Property(mImpl->mRenderer, GetPropertyIndex(key));
+      }
+      break;
     }
-    else
+    default:
     {
-      // We can't find the property in the base class.
-      // Request to child class
-      return OnGetPropertyObject(key);
+      // Special case for MIX_COLOR
+      if(key.type == Property::Key::INDEX &&
+         ((mImpl->mType == Toolkit::Visual::COLOR && key.indexKey == ColorVisual::Property::MIX_COLOR) ||
+          (mImpl->mType == Toolkit::Visual::PRIMITIVE && key.indexKey == PrimitiveVisual::Property::MIX_COLOR)))
+      {
+        return Dali::Property(mImpl->mRenderer, VisualRenderer::Property::VISUAL_MIX_COLOR);
+      }
+
+      // Special case for BLUR_RADIUS
+      if(mImpl->mType == Toolkit::Visual::COLOR &&
+         ((key.type == Property::Key::INDEX && key.indexKey == DevelColorVisual::Property::BLUR_RADIUS) ||
+          (key.type == Property::Key::STRING && key.stringKey == BLUR_RADIUS_NAME)))
+      {
+        // Request to color-visual class
+        return OnGetPropertyObject(key);
+      }
     }
   }
 
-  return Dali::Property(mImpl->mRenderer, index);
+  // If it is not VisualRenderer property, check registered Renderer and Shader property.
+  Property::Index index = GetPropertyIndex(key);
+  if(index != Property::INVALID_INDEX)
+  {
+    return Dali::Property(mImpl->mRenderer, index);
+  }
+
+  // We can't find the property in the base class.
+  // Request to child class
+  return OnGetPropertyObject(key);
 }
 
 } // namespace Internal