[4.0] Changed Update to reset only target properties each frame
[platform/core/uifw/dali-core.git] / dali / internal / update / common / animatable-property.h
index 3415f83..f82ed88 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_SCENE_GRAPH_ANIMATABLE_PROPERTY_H__
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -258,7 +258,10 @@ public:
     if( mBaseValue != value )
     {
       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;
 
       OnBake();
     }
@@ -416,6 +419,7 @@ public:
   void Bake(BufferIndex bufferIndex, int value)
   {
     mValue[bufferIndex] = value;
+    mValue[1-bufferIndex] = value;
     mBaseValue = mValue[bufferIndex];
 
     OnBake();
@@ -474,185 +478,6 @@ private:
 };
 
 /**
- * An unsigned integer animatable property of a scene-graph object.
- */
-template <>
-class AnimatableProperty<unsigned int> : public AnimatablePropertyBase
-{
-public:
-
-  /**
-   * Create an animatable property.
-   * @param [in] initialValue The initial value of the property.
-   */
-  AnimatableProperty( unsigned int initialValue )
-  : mValue( initialValue ),
-    mBaseValue( initialValue )
-  {
-  }
-
-  /**
-   * Virtual destructor.
-   */
-  virtual ~AnimatableProperty()
-  {
-  }
-
-  /**
-   * @copydoc Dali::Internal::SceneGraph::PropertyBase::GetType()
-   */
-  virtual Dali::Property::Type GetType() const
-  {
-    return Dali::PropertyTypes::Get<unsigned int>();
-  }
-
-  /**
-   * @copydoc Dali::Internal::SceneGraph::PropertyBase::ResetToBaseValue()
-   */
-  virtual void ResetToBaseValue(BufferIndex updateBufferIndex)
-  {
-    if (CLEAN_FLAG != mDirtyFlags)
-    {
-      mValue[updateBufferIndex] = mBaseValue;
-
-      mDirtyFlags = ( mDirtyFlags >> 1 );
-    }
-  }
-
-  /**
-   * @copydoc Dali::Internal::PropertyInputImpl::GetUnsignedInteger()
-   */
-  virtual const unsigned int& GetUnsignedInteger( BufferIndex bufferIndex ) const
-  {
-    return mValue[ bufferIndex ];
-  }
-
-  /**
-   * Set the property value. This will only persist for the current frame; the property
-   * will be reset with the base value, at the beginning of the next frame.
-   * @param[in] bufferIndex The buffer to write.
-   * @param[in] value The new property value.
-   */
-  void Set(BufferIndex bufferIndex, unsigned int value)
-  {
-    mValue[bufferIndex] = value;
-
-    OnSet();
-  }
-
-  /**
-   * Change the property value by a relative amount.
-   * @param[in] bufferIndex The buffer to write.
-   * @param[in] delta The property will change by this amount.
-   */
-  void SetRelative(BufferIndex bufferIndex, unsigned int delta)
-  {
-    mValue[bufferIndex] = mValue[bufferIndex] + delta;
-
-    OnSet();
-  }
-
-  /**
-   * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
-   */
-  unsigned int& Get(size_t bufferIndex)
-  {
-    return mValue[bufferIndex];
-  }
-
-  /**
-   * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
-   */
-  const unsigned int& Get(size_t bufferIndex) const
-  {
-    return mValue[bufferIndex];
-  }
-
-  /**
-   * Retrieve the property value.
-   * @param[in] bufferIndex The buffer to read.
-   * @return The property value.
-   */
-  unsigned int& operator[](size_t bufferIndex)
-  {
-    return mValue[bufferIndex];
-  }
-
-  /**
-   * Retrieve the property value.
-   * @param[in] bufferIndex The buffer to read.
-   * @return The property value.
-   */
-  const unsigned int& operator[](size_t bufferIndex) const
-  {
-    return mValue[bufferIndex];
-  }
-
-  /**
-   * Set both the property value & base value.
-   * @param[in] bufferIndex The buffer to write for the property value.
-   * @param[in] value The new property value.
-   */
-  void Bake(BufferIndex bufferIndex, unsigned int value)
-  {
-    mValue[bufferIndex] = value;
-    mBaseValue = mValue[bufferIndex];
-
-    OnBake();
-  }
-
-  /**
-   * Change the property value & base value by a relative amount.
-   * @param[in] bufferIndex The buffer to write for the local property value.
-   * @param[in] delta The property will change by this amount.
-   */
-  void BakeRelative(BufferIndex bufferIndex, unsigned int delta)
-  {
-    mValue[bufferIndex] = mValue[bufferIndex] + delta;
-    mBaseValue = mValue[bufferIndex];
-
-    OnBake();
-  }
-
-  /**
-   * Sets both double-buffered values & the base value.
-   * This should only be used when the owning object has not been connected to the scene-graph.
-   * @param[in] value The new property value.
-   */
-  void SetInitial(const unsigned int& value)
-  {
-    mValue[0]  = value;
-    mValue[1]  = mValue[0];
-    mBaseValue = mValue[0];
-  }
-
-  /**
-   * Change both double-buffered values & the base value by a relative amount.
-   * This should only be used when the owning object has not been connected to the scene-graph.
-   * @param[in] delta The property will change by this amount.
-   */
-  void SetInitialRelative(const unsigned int& delta)
-  {
-    mValue[0] = mValue[0] + delta;
-    mValue[1] = mValue[0];
-    mBaseValue = mValue[0];
-  }
-
-private:
-
-  // Undefined
-  AnimatableProperty(const AnimatableProperty& property);
-
-  // Undefined
-  AnimatableProperty& operator=(const AnimatableProperty& rhs);
-
-private:
-  DoubleBuffered<unsigned int> mValue; ///< The double-buffered property value
-  unsigned int mBaseValue;             ///< Reset to this base value at the beginning of each frame
-};
-
-
-/**
  * An float animatable property of a scene-graph object.
  */
 template <>
@@ -774,7 +599,10 @@ 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];
 
     OnBake();
@@ -1003,7 +831,10 @@ public:
    */
   void Bake(BufferIndex bufferIndex, const Vector2& 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 = value;
 
     OnBake();
@@ -1017,6 +848,7 @@ public:
   void BakeX(BufferIndex bufferIndex, float value)
   {
     mValue[bufferIndex].x = value;
+    mValue[1-bufferIndex].x = value;
     mBaseValue.x = value;
 
     OnBake();
@@ -1030,6 +862,7 @@ public:
   void BakeY(BufferIndex bufferIndex, float value)
   {
     mValue[bufferIndex].y = value;
+    mValue[1-bufferIndex].y = value;
     mBaseValue.y = value;
 
     OnBake();
@@ -1296,6 +1129,7 @@ public:
   void Bake(BufferIndex bufferIndex, const Vector3& value)
   {
     mValue[bufferIndex] = value;
+    mValue[1-bufferIndex] = value;
     mBaseValue = value;
 
     OnBake();
@@ -1309,6 +1143,7 @@ public:
   void BakeX(BufferIndex bufferIndex, float value)
   {
     mValue[bufferIndex].x = value;
+    mValue[1-bufferIndex].x = value;
     mBaseValue.x = value;
 
     OnBake();
@@ -1322,6 +1157,7 @@ public:
   void BakeY(BufferIndex bufferIndex, float value)
   {
     mValue[bufferIndex].y = value;
+    mValue[1-bufferIndex].y = value;
     mBaseValue.y = value;
 
     OnBake();
@@ -1335,6 +1171,7 @@ public:
   void BakeZ(BufferIndex bufferIndex, float value)
   {
     mValue[bufferIndex].z = value;
+    mValue[1-bufferIndex].z = value;
     mBaseValue.z = value;
 
     OnBake();
@@ -1643,6 +1480,7 @@ public:
   void Bake(BufferIndex bufferIndex, const Vector4& value)
   {
     mValue[bufferIndex] = value;
+    mValue[1-bufferIndex] = value;
     mBaseValue = mValue[bufferIndex];
 
     OnBake();
@@ -1656,6 +1494,7 @@ public:
   void BakeX(BufferIndex bufferIndex, float value)
   {
     mValue[bufferIndex].x = value;
+    mValue[1-bufferIndex].x = value;
     mBaseValue.x = mValue[bufferIndex].x;
 
     OnBake();
@@ -1669,6 +1508,7 @@ public:
   void BakeY(BufferIndex bufferIndex, float value)
   {
     mValue[bufferIndex].y = value;
+    mValue[1-bufferIndex].y = value;
     mBaseValue.y = mValue[bufferIndex].y;
 
     OnBake();
@@ -1682,6 +1522,7 @@ public:
   void BakeZ(BufferIndex bufferIndex, float value)
   {
     mValue[bufferIndex].z = value;
+    mValue[1-bufferIndex].z = value;
     mBaseValue.z = mValue[bufferIndex].z;
 
     OnBake();
@@ -1695,6 +1536,7 @@ public:
   void BakeW(BufferIndex bufferIndex, float value)
   {
     mValue[bufferIndex].w = value;
+    mValue[1-bufferIndex].w = value;
     mBaseValue.w = mValue[bufferIndex].w;
 
     OnBake();
@@ -1922,7 +1764,10 @@ public:
    */
   void Bake(BufferIndex bufferIndex, const Quaternion& 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 = value;
 
     OnBake();
@@ -2080,7 +1925,10 @@ public:
    */
   void Bake(BufferIndex bufferIndex, const Matrix& 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();
@@ -2238,7 +2086,10 @@ public:
    */
   void Bake(BufferIndex bufferIndex, const Matrix3& 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();