Call OnBake(), OnSet only if the value is really changed 49/313149/1
authorEunki, Hong <eunkiki.hong@samsung.com>
Wed, 19 Jun 2024 09:57:05 +0000 (18:57 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Wed, 19 Jun 2024 10:05:11 +0000 (19:05 +0900)
Let we check the current value and inputed value, so if they are same, ignore.

It will be useful when we don't want to mark dirty for animatable property doesn't changed.

For performance issue, let we just check only for bool / int / float.

TODO : Chould we check them also at Vector2,3,4?

Change-Id: I70b36eab97585a09c2c021da4f37a1d983a771af
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali/internal/update/common/animatable-property.h

index f9bd877..4697d88 100644 (file)
@@ -379,9 +379,13 @@ public:
    */
   void Set(BufferIndex bufferIndex, int value)
   {
-    mValue[bufferIndex] = value;
+    // check if the value actually changed to avoid dirtying nodes unnecessarily
+    if(mValue[bufferIndex] != value)
+    {
+      mValue[bufferIndex] = value;
 
-    OnSet();
+      OnSet();
+    }
   }
 
   /**
@@ -391,9 +395,13 @@ public:
    */
   void SetRelative(BufferIndex bufferIndex, int delta)
   {
-    mValue[bufferIndex] = mValue[bufferIndex] + delta;
+    // check if the value actually changed to avoid dirtying nodes unnecessarily
+    if(delta)
+    {
+      mValue[bufferIndex] = mValue[bufferIndex] + delta;
 
-    OnSet();
+      OnSet();
+    }
   }
 
   /**
@@ -439,11 +447,15 @@ public:
    */
   void Bake(BufferIndex bufferIndex, int value)
   {
-    mValue[bufferIndex]     = value;
-    mValue[1 - bufferIndex] = value;
-    mBaseValue              = mValue[bufferIndex];
+    // bake has to check the base value as current buffer value can be correct by constraint or something else
+    if(mBaseValue != value)
+    {
+      mValue[bufferIndex]     = value;
+      mValue[1 - bufferIndex] = value;
+      mBaseValue              = mValue[bufferIndex];
 
-    OnBake();
+      OnBake();
+    }
   }
 
   /**
@@ -570,9 +582,13 @@ public:
    */
   void Set(BufferIndex bufferIndex, float value)
   {
-    mValue[bufferIndex] = value;
+    // check if the value actually changed to avoid dirtying nodes unnecessarily
+    if(!Dali::Equals(mValue[bufferIndex], value))
+    {
+      mValue[bufferIndex] = value;
 
-    OnSet();
+      OnSet();
+    }
   }
 
   /**
@@ -582,9 +598,13 @@ public:
    */
   void SetRelative(BufferIndex bufferIndex, float delta)
   {
-    mValue[bufferIndex] = mValue[bufferIndex] + delta;
+    // check if the value actually changed to avoid dirtying nodes unnecessarily
+    if(!Dali::EqualsZero(delta))
+    {
+      mValue[bufferIndex] = mValue[bufferIndex] + delta;
 
-    OnSet();
+      OnSet();
+    }
   }
 
   /**
@@ -630,13 +650,17 @@ public:
    */
   void Bake(BufferIndex bufferIndex, float value)
   {
-    // It's ok to bake both buffers as render is performed in same thread as update. Reading from event side
-    // has never been atomically safe.
-    mValue[bufferIndex]     = value;
-    mValue[1 - bufferIndex] = value;
-    mBaseValue              = mValue[bufferIndex];
+    // bake has to check the base value as current buffer value can be correct by constraint or something else
+    if(!Dali::Equals(mBaseValue, value))
+    {
+      // It's ok to bake both buffers as render is performed in same thread as update. Reading from event side
+      // has never been atomically safe.
+      mValue[bufferIndex]     = value;
+      mValue[1 - bufferIndex] = value;
+      mBaseValue              = mValue[bufferIndex];
 
-    OnBake();
+      OnBake();
+    }
   }
 
   /**