Use modern construct 'using' instead of typedef.
[platform/core/uifw/dali-core.git] / dali / internal / update / common / animatable-property.h
index a05d545..8972bc9 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_ANIMATABLE_PROPERTY_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_ANIMATABLE_PROPERTY_H__
+#ifndef DALI_INTERNAL_SCENE_GRAPH_ANIMATABLE_PROPERTY_H
+#define DALI_INTERNAL_SCENE_GRAPH_ANIMATABLE_PROPERTY_H
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
@@ -52,9 +52,9 @@ namespace SceneGraph
  * However if the property was only "Set" (and not "Baked"), then typically the base value and previous value will not match.
  * In this case the reset operation is equivalent to a "Bake", and the value is considered "dirty" for an additional frame.
  */
-static const unsigned int CLEAN_FLAG = 0x00; ///< Indicates that the value did not change in this, or the previous frame
-static const unsigned int BAKED_FLAG = 0x01; ///< Indicates that the value was Baked during the previous frame
-static const unsigned int SET_FLAG   = 0x02; ///< Indicates that the value was Set during the previous frame
+static const uint32_t CLEAN_FLAG = 0x00; ///< Indicates that the value did not change in this, or the previous frame
+static const uint32_t BAKED_FLAG = 0x01; ///< Indicates that the value was Baked during the previous frame
+static const uint32_t SET_FLAG   = 0x02; ///< Indicates that the value was Set during the previous frame
 
 template <class T>
 class AnimatableProperty;
@@ -118,7 +118,7 @@ public: // From PropertyBase
 
 protected: // so that ResetToBaseValue can set it directly
 
-  unsigned int mDirtyFlags; ///< Flag whether value changed during previous 2 frames
+  uint32_t mDirtyFlags; ///< Flag whether value changed during previous 2 frames
 
 };
 
@@ -205,7 +205,7 @@ public:
     // false + false does not change value, true + false does not either
     if( delta && !mValue[bufferIndex] )
     {
-      mValue[bufferIndex] += delta;
+      mValue[bufferIndex] = delta;
 
       OnSet();
     }
@@ -214,7 +214,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  bool& Get(size_t bufferIndex)
+  bool& Get( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -222,7 +222,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  const bool& Get(size_t bufferIndex) const
+  const bool& Get( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -232,7 +232,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  bool& operator[](size_t bufferIndex)
+  bool& operator[]( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -242,7 +242,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  const bool& operator[](size_t bufferIndex) const
+  const bool& operator[]( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -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();
     }
@@ -271,7 +274,7 @@ public:
    */
   void BakeRelative(BufferIndex bufferIndex, bool delta)
   {
-    mValue[bufferIndex] += delta;
+    mValue[bufferIndex] = mValue[bufferIndex] || delta;
     mBaseValue = mValue[bufferIndex];
 
     OnBake();
@@ -375,7 +378,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  int& Get(size_t bufferIndex)
+  int& Get( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -383,7 +386,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  const int& Get(size_t bufferIndex) const
+  const int& Get( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -393,7 +396,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  int& operator[](size_t bufferIndex)
+  int& operator[]( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -403,7 +406,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  const int& operator[](size_t bufferIndex) const
+  const int& operator[]( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -416,6 +419,7 @@ public:
   void Bake(BufferIndex bufferIndex, int value)
   {
     mValue[bufferIndex] = value;
+    mValue[1-bufferIndex] = value;
     mBaseValue = mValue[bufferIndex];
 
     OnBake();
@@ -555,7 +559,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  float& Get(size_t bufferIndex)
+  float& Get( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -563,7 +567,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  const float& Get(size_t bufferIndex) const
+  const float& Get( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -573,7 +577,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  float& operator[](size_t bufferIndex)
+  float& operator[]( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -583,7 +587,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  const float& operator[](size_t bufferIndex) const
+  const float& operator[]( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -595,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();
@@ -784,7 +791,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  Vector2& Get(size_t bufferIndex)
+  Vector2& Get( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -792,7 +799,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  const Vector2& Get(size_t bufferIndex) const
+  const Vector2& Get( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -802,7 +809,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  Vector2& operator[](size_t bufferIndex)
+  Vector2& operator[]( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -812,7 +819,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  const Vector2& operator[](size_t bufferIndex) const
+  const Vector2& operator[]( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -824,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();
@@ -838,6 +848,7 @@ public:
   void BakeX(BufferIndex bufferIndex, float value)
   {
     mValue[bufferIndex].x = value;
+    mValue[1-bufferIndex].x = value;
     mBaseValue.x = value;
 
     OnBake();
@@ -851,6 +862,7 @@ public:
   void BakeY(BufferIndex bufferIndex, float value)
   {
     mValue[bufferIndex].y = value;
+    mValue[1-bufferIndex].y = value;
     mBaseValue.y = value;
 
     OnBake();
@@ -1076,7 +1088,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  Vector3& Get(size_t bufferIndex)
+  Vector3& Get( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -1084,7 +1096,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  const Vector3& Get(size_t bufferIndex) const
+  const Vector3& Get( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -1094,7 +1106,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  Vector3& operator[](size_t bufferIndex)
+  Vector3& operator[]( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -1104,7 +1116,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  const Vector3& operator[](size_t bufferIndex) const
+  const Vector3& operator[]( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -1117,6 +1129,7 @@ public:
   void Bake(BufferIndex bufferIndex, const Vector3& value)
   {
     mValue[bufferIndex] = value;
+    mValue[1-bufferIndex] = value;
     mBaseValue = value;
 
     OnBake();
@@ -1130,6 +1143,7 @@ public:
   void BakeX(BufferIndex bufferIndex, float value)
   {
     mValue[bufferIndex].x = value;
+    mValue[1-bufferIndex].x = value;
     mBaseValue.x = value;
 
     OnBake();
@@ -1143,6 +1157,7 @@ public:
   void BakeY(BufferIndex bufferIndex, float value)
   {
     mValue[bufferIndex].y = value;
+    mValue[1-bufferIndex].y = value;
     mBaseValue.y = value;
 
     OnBake();
@@ -1156,6 +1171,7 @@ public:
   void BakeZ(BufferIndex bufferIndex, float value)
   {
     mValue[bufferIndex].z = value;
+    mValue[1-bufferIndex].z = value;
     mBaseValue.z = value;
 
     OnBake();
@@ -1423,7 +1439,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  Vector4& Get(size_t bufferIndex)
+  Vector4& Get( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -1431,7 +1447,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  const Vector4& Get(size_t bufferIndex) const
+  const Vector4& Get( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -1441,7 +1457,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  Vector4& operator[](size_t bufferIndex)
+  Vector4& operator[]( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -1451,7 +1467,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  const Vector4& operator[](size_t bufferIndex) const
+  const Vector4& operator[]( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -1464,6 +1480,7 @@ public:
   void Bake(BufferIndex bufferIndex, const Vector4& value)
   {
     mValue[bufferIndex] = value;
+    mValue[1-bufferIndex] = value;
     mBaseValue = mValue[bufferIndex];
 
     OnBake();
@@ -1477,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();
@@ -1490,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();
@@ -1503,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();
@@ -1516,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();
@@ -1703,7 +1724,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  Quaternion& Get(size_t bufferIndex)
+  Quaternion& Get( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -1711,7 +1732,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  const Quaternion& Get(size_t bufferIndex) const
+  const Quaternion& Get( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -1721,7 +1742,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  Quaternion& operator[](size_t bufferIndex)
+  Quaternion& operator[]( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -1731,7 +1752,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  const Quaternion& operator[](size_t bufferIndex) const
+  const Quaternion& operator[]( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -1743,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();
@@ -1861,7 +1885,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  Matrix& Get(size_t bufferIndex)
+  Matrix& Get( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -1869,7 +1893,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  const Matrix& Get(size_t bufferIndex) const
+  const Matrix& Get( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -1879,7 +1903,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  Matrix& operator[](size_t bufferIndex)
+  Matrix& operator[]( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -1889,7 +1913,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  const Matrix& operator[](size_t bufferIndex) const
+  const Matrix& operator[]( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -1901,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();
@@ -2019,7 +2046,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  Matrix3& Get(size_t bufferIndex)
+  Matrix3& Get( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -2027,7 +2054,7 @@ public:
   /**
    * @copydoc Dali::SceneGraph::AnimatableProperty::Get()
    */
-  const Matrix3& Get(size_t bufferIndex) const
+  const Matrix3& Get( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -2037,7 +2064,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  Matrix3& operator[](size_t bufferIndex)
+  Matrix3& operator[]( BufferIndex bufferIndex )
   {
     return mValue[bufferIndex];
   }
@@ -2047,7 +2074,7 @@ public:
    * @param[in] bufferIndex The buffer to read.
    * @return The property value.
    */
-  const Matrix3& operator[](size_t bufferIndex) const
+  const Matrix3& operator[]( BufferIndex bufferIndex ) const
   {
     return mValue[bufferIndex];
   }
@@ -2059,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();
@@ -2104,10 +2134,10 @@ void BakeMessage( EventThreadServices& eventThreadServices,
                   const SceneGraph::AnimatableProperty<T>& property,
                   typename ParameterType< T >::PassingType newValue )
 {
-  typedef MessageDoubleBuffered1< SceneGraph::AnimatableProperty<T>, T > LocalType;
+  using LocalType = MessageDoubleBuffered1<SceneGraph::AnimatableProperty<T>, T>;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+  uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &property,
@@ -2120,10 +2150,10 @@ void BakeRelativeMessage( EventThreadServices& eventThreadServices,
                           const SceneGraph::AnimatableProperty<T>& property,
                           const T& delta )
 {
-  typedef MessageDoubleBuffered1< SceneGraph::AnimatableProperty<T>, const T& > LocalType;
+  using LocalType = MessageDoubleBuffered1<SceneGraph::AnimatableProperty<T>, const T&>;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+  uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &property,
@@ -2136,10 +2166,10 @@ void SetXComponentMessage( EventThreadServices& eventThreadServices,
                            const SceneGraph::AnimatableProperty<T>& property,
                            typename ParameterType< float >::PassingType newValue )
 {
-  typedef MessageDoubleBuffered1< SceneGraph::AnimatableProperty<T>, float > LocalType;
+  using LocalType = MessageDoubleBuffered1<SceneGraph::AnimatableProperty<T>, float>;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+  uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &property,
@@ -2152,10 +2182,10 @@ void SetYComponentMessage( EventThreadServices& eventThreadServices,
                            const SceneGraph::AnimatableProperty<T>& property,
                            typename ParameterType< float >::PassingType newValue )
 {
-  typedef MessageDoubleBuffered1< SceneGraph::AnimatableProperty<T>, float > LocalType;
+  using LocalType = MessageDoubleBuffered1<SceneGraph::AnimatableProperty<T>, float>;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+  uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &property,
@@ -2168,10 +2198,10 @@ void SetZComponentMessage( EventThreadServices& eventThreadServices,
                            const SceneGraph::AnimatableProperty<T>& property,
                            typename ParameterType< float >::PassingType newValue )
 {
-  typedef MessageDoubleBuffered1< SceneGraph::AnimatableProperty<T>, float > LocalType;
+  using LocalType = MessageDoubleBuffered1<SceneGraph::AnimatableProperty<T>, float>;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+  uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &property,
@@ -2184,10 +2214,10 @@ void SetWComponentMessage( EventThreadServices& eventThreadServices,
                            const SceneGraph::AnimatableProperty<T>& property,
                            typename ParameterType< float >::PassingType newValue )
 {
-  typedef MessageDoubleBuffered1< SceneGraph::AnimatableProperty<T>, float > LocalType;
+  using LocalType = MessageDoubleBuffered1<SceneGraph::AnimatableProperty<T>, float>;
 
   // Reserve some memory inside the message queue
-  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+  uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
   new (slot) LocalType( &property,
@@ -2199,4 +2229,4 @@ void SetWComponentMessage( EventThreadServices& eventThreadServices,
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_SCENE_GRAPH_ANIMATABLE_PROPERTY_H__
+#endif // DALI_INTERNAL_SCENE_GRAPH_ANIMATABLE_PROPERTY_H