[dali_2.3.31] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / common / property-input-impl.h
index ff4604d..ab2ee09 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_PROPERTY_INPUT_IMPL_H__
-#define __DALI_INTERNAL_PROPERTY_INPUT_IMPL_H__
+#ifndef DALI_INTERNAL_PROPERTY_INPUT_IMPL_H
+#define DALI_INTERNAL_PROPERTY_INPUT_IMPL_H
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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 <iostream>
 
 // INTERNAL INCLUDES
-#include <dali/public-api/object/property-input.h>
+#include <dali/internal/common/buffer-index.h>
+#include <dali/public-api/math/matrix.h>
+#include <dali/public-api/math/matrix3.h>
+#include <dali/public-api/math/quaternion.h>
 #include <dali/public-api/math/vector2.h>
 #include <dali/public-api/math/vector3.h>
 #include <dali/public-api/math/vector4.h>
-#include <dali/public-api/math/quaternion.h>
-#include <dali/public-api/math/matrix3.h>
-#include <dali/public-api/math/matrix.h>
-#include <dali/internal/common/buffer-index.h>
+#include <dali/public-api/object/property-input.h>
 
-namespace Dali
+#if defined(ANDROID) || defined(WIN32) || defined(__APPLE__)
+namespace std
 {
+uint64_t _Hash_bytes(const void* bytes, uint64_t size, uint64_t seed);
 
+}
+#endif
+
+namespace Dali
+{
 namespace Internal
 {
-
 /**
  * An abstract interface for receiving property values, and for querying whether
  * a property value has changed i.e. whether a constraint needs to be reapplied.
@@ -44,13 +50,10 @@ namespace Internal
 class PropertyInputImpl
 {
 public:
-
   /**
    * Virtual destructor.
    */
-  virtual ~PropertyInputImpl()
-  {
-  }
+  virtual ~PropertyInputImpl() = default;
 
   /**
    * Query the type of property input.
@@ -76,10 +79,9 @@ public:
    * @param[in] bufferIndex The buffer to read from.
    * @return The boolean value.
    */
-  virtual const bool& GetBoolean( BufferIndex bufferIndex ) const
+  virtual const bool& GetBoolean(BufferIndex bufferIndex) const
   {
-    DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
-    // the return will never be executed due to assert above so just keep the compiler happy
+    // the return will never be executed, it's just to keep the compiler happy
     return reinterpret_cast<const bool&>(*this);
   }
 
@@ -89,10 +91,9 @@ public:
    * @param[in] bufferIndex The buffer to read from.
    * @return The integer value.
    */
-  virtual const int& GetInteger( BufferIndex bufferIndex ) const
+  virtual const int& GetInteger(BufferIndex bufferIndex) const
   {
-    DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
-    // the return will never be executed due to assert above so just keep the compiler happy
+    // the return will never be executed, it's just to keep the compiler happy
     return reinterpret_cast<const int&>(*this);
   }
 
@@ -102,10 +103,9 @@ public:
    * @param[in] bufferIndex The buffer to read from.
    * @return The float value.
    */
-  virtual const float& GetFloat( BufferIndex bufferIndex ) const
+  virtual const float& GetFloat(BufferIndex bufferIndex) const
   {
-    DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
-    // the return will never be executed due to assert above so just keep the compiler happy
+    // the return will never be executed, it's just to keep the compiler happy
     return reinterpret_cast<const float&>(*this);
   }
 
@@ -115,10 +115,9 @@ public:
    * @param[in] bufferIndex The buffer to read from.
    * @return The Vector2 value.
    */
-  virtual const Vector2& GetVector2( BufferIndex bufferIndex ) const
+  virtual const Vector2& GetVector2(BufferIndex bufferIndex) const
   {
-    DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
-    // the return will never be executed due to assert above so just keep the compiler happy
+    // the return will never be executed, it's just to keep the compiler happy
     return reinterpret_cast<const Vector2&>(*this);
   }
 
@@ -128,10 +127,9 @@ public:
    * @param[in] bufferIndex The buffer to read from.
    * @return The Vector3 value.
    */
-  virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
+  virtual const Vector3& GetVector3(BufferIndex bufferIndex) const
   {
-    DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
-    // the return will never be executed due to assert above so just keep the compiler happy
+    // the return will never be executed, it's just to keep the compiler happy
     return reinterpret_cast<const Vector3&>(*this);
   }
 
@@ -141,10 +139,9 @@ public:
    * @param[in] bufferIndex The buffer to read from.
    * @return The Vector4 value.
    */
-  virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
+  virtual const Vector4& GetVector4(BufferIndex bufferIndex) const
   {
-    DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
-    // the return will never be executed due to assert above so just keep the compiler happy
+    // the return will never be executed, it's just to keep the compiler happy
     return reinterpret_cast<const Vector4&>(*this);
   }
 
@@ -154,10 +151,9 @@ public:
    * @param[in] bufferIndex The buffer to read from.
    * @return The Quaternion value.
    */
-  virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
+  virtual const Quaternion& GetQuaternion(BufferIndex bufferIndex) const
   {
-    DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
-    // the return will never be executed due to assert above so just keep the compiler happy
+    // the return will never be executed, it's just to keep the compiler happy
     return reinterpret_cast<const Quaternion&>(*this);
   }
 
@@ -167,10 +163,9 @@ public:
    * @param[in] bufferIndex The buffer to read from.
    * @return The Matrix value.
    */
-  virtual const Matrix3& GetMatrix3( BufferIndex bufferIndex ) const
+  virtual const Matrix3& GetMatrix3(BufferIndex bufferIndex) const
   {
-    DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
-    // the return will never be executed due to assert above so just keep the compiler happy
+    // the return will never be executed, it's just to keep the compiler happy
     return reinterpret_cast<const Matrix3&>(*this);
   }
 
@@ -180,13 +175,24 @@ public:
    * @param[in] bufferIndex The buffer to read from.
    * @return The Matrix value.
    */
-  virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
+  virtual const Matrix& GetMatrix(BufferIndex bufferIndex) const
   {
-    DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
-    // the return will never be executed due to assert above so just keep the compiler happy
+    // the return will never be executed, it's just to keep the compiler happy
     return reinterpret_cast<const Matrix&>(*this);
   }
 
+  /**
+   * Retrieve the address of the property value. Only for use
+   * when writing uniforms.
+   */
+  virtual const void* GetValueAddress(BufferIndex bufferIndex) const = 0;
+
+  /**
+   * Retrieve the size of the property value for use in copying.
+   * Only for use when writing uniforms.
+   */
+  virtual size_t GetValueSize() const = 0;
+
   // Accessors for Constraint functions
 
   /**
@@ -197,9 +203,9 @@ public:
    * @param[in] updateBufferIndex The current update buffer index.
    * @return The boolean value.
    */
-  virtual const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
+  virtual const bool& GetConstraintInputBoolean(BufferIndex updateBufferIndex) const
   {
-    return GetBoolean( updateBufferIndex );
+    return GetBoolean(updateBufferIndex);
   }
 
   /**
@@ -210,9 +216,9 @@ public:
    * @param[in] updateBufferIndex The current update buffer index.
    * @return The integer value.
    */
-  virtual const int& GetConstraintInputInteger( BufferIndex updateBufferIndex ) const
+  virtual const int& GetConstraintInputInteger(BufferIndex updateBufferIndex) const
   {
-    return GetInteger( updateBufferIndex );
+    return GetInteger(updateBufferIndex);
   }
 
   /**
@@ -223,9 +229,9 @@ public:
    * @param[in] updateBufferIndex The current update buffer index.
    * @return The float value.
    */
-  virtual const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
+  virtual const float& GetConstraintInputFloat(BufferIndex updateBufferIndex) const
   {
-    return GetFloat( updateBufferIndex );
+    return GetFloat(updateBufferIndex);
   }
 
   /**
@@ -236,9 +242,9 @@ public:
    * @param[in] updateBufferIndex The buffer to read from.
    * @return The Vector2 value.
    */
-  virtual const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
+  virtual const Vector2& GetConstraintInputVector2(BufferIndex updateBufferIndex) const
   {
-    return GetVector2( updateBufferIndex );
+    return GetVector2(updateBufferIndex);
   }
 
   /**
@@ -249,9 +255,9 @@ public:
    * @param[in] updateBufferIndex The buffer to read from.
    * @return The Vector3 value.
    */
-  virtual const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
+  virtual const Vector3& GetConstraintInputVector3(BufferIndex updateBufferIndex) const
   {
-    return GetVector3( updateBufferIndex );
+    return GetVector3(updateBufferIndex);
   }
 
   /**
@@ -262,9 +268,9 @@ public:
    * @param[in] updateBufferIndex The buffer to read from.
    * @return The Vector4 value.
    */
-  virtual const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
+  virtual const Vector4& GetConstraintInputVector4(BufferIndex updateBufferIndex) const
   {
-    return GetVector4( updateBufferIndex );
+    return GetVector4(updateBufferIndex);
   }
 
   /**
@@ -275,9 +281,9 @@ public:
    * @param[in] updateBufferIndex The buffer to read from.
    * @return The Quaternion value.
    */
-  virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
+  virtual const Quaternion& GetConstraintInputQuaternion(BufferIndex updateBufferIndex) const
   {
-    return GetQuaternion( updateBufferIndex );
+    return GetQuaternion(updateBufferIndex);
   }
 
   /**
@@ -288,9 +294,9 @@ public:
    * @param[in] updateBufferIndex The buffer to read from.
    * @return The Matrix value.
    */
-  virtual const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
+  virtual const Matrix3& GetConstraintInputMatrix3(BufferIndex updateBufferIndex) const
   {
-    return GetMatrix3( updateBufferIndex );
+    return GetMatrix3(updateBufferIndex);
   }
 
   /**
@@ -301,9 +307,9 @@ public:
    * @param[in] updateBufferIndex The buffer to read from.
    * @return The Matrix value.
    */
-  virtual const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
+  virtual const Matrix& GetConstraintInputMatrix(BufferIndex updateBufferIndex) const
   {
-    return GetMatrix( updateBufferIndex );
+    return GetMatrix(updateBufferIndex);
   }
 
   /**
@@ -316,67 +322,123 @@ public:
     return false;
   }
 
+  std::uint64_t Hash(BufferIndex bufferIndex, uint64_t seed) const
+  {
+    switch(GetType())
+    {
+      case Property::BOOLEAN:
+      {
+        return std::_Hash_bytes(&GetBoolean(bufferIndex), sizeof(bool), seed);
+      }
+
+      case Property::INTEGER:
+      {
+        return std::_Hash_bytes(&GetInteger(bufferIndex), sizeof(int), seed);
+      }
+
+      case Property::FLOAT:
+      {
+        return std::_Hash_bytes(&GetFloat(bufferIndex), sizeof(float), seed);
+      }
+
+      case Property::VECTOR2:
+      {
+        return std::_Hash_bytes(&GetVector2(bufferIndex), sizeof(Vector2), seed);
+      }
+
+      case Property::VECTOR3:
+      {
+        return std::_Hash_bytes(&GetVector3(bufferIndex), sizeof(Vector3), seed);
+      }
+
+      case Property::VECTOR4:
+      {
+        return std::_Hash_bytes(&GetVector4(bufferIndex), sizeof(Vector4), seed);
+      }
+
+      case Property::ROTATION:
+      {
+        return std::_Hash_bytes(&GetQuaternion(bufferIndex), sizeof(Quaternion), seed);
+      }
+
+      case Property::MATRIX:
+      {
+        return std::_Hash_bytes(&GetMatrix(bufferIndex), sizeof(Matrix), seed);
+      }
+
+      case Property::MATRIX3:
+      {
+        return std::_Hash_bytes(&GetMatrix3(bufferIndex), sizeof(Matrix3), seed);
+      }
+
+      default:
+        break; // print nothing
+    }
+
+    return seed;
+  }
+
   /**
    * Print the property value using a stream.
    * @param[in] debugStream The output stream.
    * @param[in] bufferIndex The buffer to read from.
    * @todo Place this far-too-large-to-be-inlined function in a cpp and remove <iostream> header dependency from this file.
    */
-  void DebugPrint( std::ostream& debugStream, BufferIndex bufferIndex ) const
+  void DebugPrint(std::ostream& debugStream, BufferIndex bufferIndex) const
   {
-    switch ( GetType() )
+    switch(GetType())
     {
       case Property::BOOLEAN:
       {
-        debugStream << GetBoolean( bufferIndex );
+        debugStream << GetBoolean(bufferIndex);
         break;
       }
 
       case Property::INTEGER:
       {
-        debugStream << GetInteger( bufferIndex );
+        debugStream << GetInteger(bufferIndex);
         break;
       }
 
       case Property::FLOAT:
       {
-        debugStream << GetFloat( bufferIndex );
+        debugStream << GetFloat(bufferIndex);
         break;
       }
 
       case Property::VECTOR2:
       {
-        debugStream << GetVector2( bufferIndex );
+        debugStream << GetVector2(bufferIndex);
         break;
       }
 
       case Property::VECTOR3:
       {
-        debugStream << GetVector3( bufferIndex );
+        debugStream << GetVector3(bufferIndex);
         break;
       }
 
       case Property::VECTOR4:
       {
-        debugStream << GetVector4( bufferIndex );
+        debugStream << GetVector4(bufferIndex);
         break;
       }
 
       case Property::ROTATION:
       {
-        debugStream << GetQuaternion( bufferIndex );
+        debugStream << GetQuaternion(bufferIndex);
         break;
       }
 
       case Property::MATRIX:
       {
-        debugStream << GetMatrix( bufferIndex );
+        debugStream << GetMatrix(bufferIndex);
         break;
       }
 
       case Property::MATRIX3:
       {
-        debugStream << GetMatrix3( bufferIndex );
+        debugStream << GetMatrix3(bufferIndex);
         break;
       }
 
@@ -390,4 +452,4 @@ public:
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_PROPERTY_INPUT_IMPL_H__
+#endif // DALI_INTERNAL_PROPERTY_INPUT_IMPL_H