(Animatable property) default value setting and uniform mapping 64/57164/5
authorx1ma <x1.ma@samsung.com>
Fri, 15 Jan 2016 13:58:22 +0000 (13:58 +0000)
committerXiangyin Ma <x1.ma@samsung.com>
Tue, 19 Jan 2016 16:43:46 +0000 (08:43 -0800)
Change-Id: I2a6413863e597c588b14ddce24f701c5a2aa64c3

automated-tests/src/dali/utc-Dali-TypeRegistry.cpp
dali/devel-api/object/type-registry-helper.h
dali/internal/event/common/object-impl.cpp
dali/internal/event/common/object-impl.h
dali/internal/event/common/type-info-impl.cpp
dali/internal/event/common/type-info-impl.h
dali/internal/event/common/type-registry-impl.cpp
dali/internal/event/common/type-registry-impl.h
dali/public-api/object/type-registry.cpp
dali/public-api/object/type-registry.h

index a920c8b..a107637 100644 (file)
@@ -1047,6 +1047,7 @@ int UtcDaliTypeRegistryAnimatablePropertyRegistrationP(void)
   DALI_TEST_CHECK( handle );
   Actor customActor = Actor::DownCast( handle );
   DALI_TEST_CHECK( customActor );
+  Stage::GetCurrent().Add(customActor);
 
   unsigned int customPropertyCount( customActor.GetPropertyCount() );
 
@@ -1054,7 +1055,7 @@ int UtcDaliTypeRegistryAnimatablePropertyRegistrationP(void)
   std::string animatablePropertyName( "animatableProp1" );
   int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
   Property::Type animatablePropertyType( Property::FLOAT );
-  AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
+  AnimatablePropertyRegistration animatableProperty( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
 
   // Check property count after registration
   DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
@@ -1067,7 +1068,7 @@ int UtcDaliTypeRegistryAnimatablePropertyRegistrationP(void)
   application.Render();
 
   // Check the animatable property value
-  DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.0f, TEST_LOCATION );
+  DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.f, TEST_LOCATION );
 
   // Check the animatable property name
   DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
@@ -1091,6 +1092,21 @@ int UtcDaliTypeRegistryAnimatablePropertyRegistrationP(void)
   unsigned int customActorIndices = indices.Size();
   DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
 
+  // check that the property is animatable
+  Animation animation = Animation::New(0.2f);
+  animation.AnimateTo( Property( customActor, animatablePropertyIndex ), 15.f, AlphaFunction::LINEAR );
+  animation.Play();
+  // Render and notify, animation play for 0.05 seconds
+  application.SendNotification();
+  application.Render(50);
+  DALI_TEST_EQUALS( 0.25f, animation.GetCurrentProgress(), TEST_LOCATION );
+  DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 22.5f, TEST_LOCATION );
+  // Render and notify, animation play for another 0.1 seconds
+  application.SendNotification();
+  application.Render(100);
+  DALI_TEST_EQUALS( 0.75f, animation.GetCurrentProgress(), TEST_LOCATION );
+  DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 17.5f, TEST_LOCATION );
+
   END_TEST;
 }
 
@@ -1124,6 +1140,107 @@ int UtcDaliTypeRegistryAnimatablePropertyRegistrationN(void)
   END_TEST;
 }
 
+int UtcDaliTypeRegistryAnimatablePropertyRegistrationWithDefaultP(void)
+{
+  TestApplication application;
+  TypeRegistry typeRegistry = TypeRegistry::Get();
+
+  // Check property count before property registration
+  TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
+  DALI_TEST_CHECK( typeInfo );
+  BaseHandle handle = typeInfo.CreateInstance();
+  DALI_TEST_CHECK( handle );
+  Actor customActor = Actor::DownCast( handle );
+  DALI_TEST_CHECK( customActor );
+  Stage::GetCurrent().Add(customActor);
+
+  unsigned int customPropertyCount( customActor.GetPropertyCount() );
+
+  // Register animatable property
+  std::string animatablePropertyName( "animatableProp1" );
+  int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
+  AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, 10.f );
+
+  // Check property count after registration
+  DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  // Check the animatable property value
+  DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 10.f, TEST_LOCATION );
+
+  // Check the animatable property name
+  DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
+
+  // Check the animatable property index
+  DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
+
+  // Check the animatable property type
+  DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), Property::FLOAT, TEST_LOCATION );
+
+  // Check property count of type-info is 1
+  Property::IndexContainer indices;
+  typeInfo.GetPropertyIndices( indices );
+  DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
+
+  // Ensure indices returned from actor and customActor differ by one
+  Actor actor = Actor::New();
+  actor.GetPropertyIndices( indices );
+  unsigned int actorIndices = indices.Size();
+  customActor.GetPropertyIndices( indices );
+  unsigned int customActorIndices = indices.Size();
+  DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
+
+  // check that the property is animatable
+  Animation animation = Animation::New(0.2f);
+  animation.AnimateTo( Property( customActor, animatablePropertyIndex ), 20.f, AlphaFunction::LINEAR );
+  animation.Play();
+  // Render and notify, animation play for 0.05 seconds
+  application.SendNotification();
+  application.Render(50);
+  DALI_TEST_EQUALS( 0.25f, animation.GetCurrentProgress(), TEST_LOCATION );
+  DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 12.5f, TEST_LOCATION );
+  // Render and notify, animation play for another 0.1 seconds
+  application.SendNotification();
+  application.Render(100);
+  DALI_TEST_EQUALS( 0.75f, animation.GetCurrentProgress(), TEST_LOCATION );
+  DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 17.5f, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliTypeRegistryAnimatablePropertyRegistrationWithDefaultN(void)
+{
+  TestApplication application;
+  TypeRegistry typeRegistry = TypeRegistry::Get();
+
+  // Attempt to register an animatable property type out-of-bounds index (less than)
+  try
+  {
+    AnimatablePropertyRegistration property1( customType1, "animPropName",   ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, false );
+    tet_result( TET_FAIL );
+  }
+  catch ( DaliException& e )
+  {
+    DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
+  }
+
+  // Attempt to register an animatable property type out-of-bounds index (greater than)
+  try
+  {
+    AnimatablePropertyRegistration property1( customType1, "animPropName",   ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, true );
+    tet_result( TET_FAIL );
+  }
+  catch ( DaliException& e )
+  {
+    DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
+  }
+
+  END_TEST;
+}
+
 int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationP(void)
 {
   TestApplication application;
index 7d6b90b..017eed3 100644 (file)
@@ -46,6 +46,9 @@ namespace Internal
 #define DALI_ANIMATABLE_PROPERTY_REGISTRATION_INTERNAL( count, typeRegistrationObject, objectNamespace, objectType, text, valueType, enumIndex) \
   AnimatablePropertyRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, objectNamespace::objectType::Property::enumIndex, Property::valueType );
 
+#define DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT_INTERNAL( count, typeRegistrationObject, objectNamespace, objectType, text, value, enumIndex) \
+  AnimatablePropertyRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, objectNamespace::objectType::Property::enumIndex, value );
+
 #define DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION_INTERNAL( count, typeRegistrationObject, objectNamespace, objectType, text, enumIndex, baseEnumIndex, componentIndex) \
   AnimatablePropertyComponentRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, objectNamespace::objectType::Property::enumIndex, objectNamespace::objectType::Property::baseEnumIndex, componentIndex );
 
@@ -71,6 +74,9 @@ namespace Internal
 #define DALI_ANIMATABLE_PROPERTY_REGISTRATION( objectNamespace, objectType, text, valueType, enumIndex ) \
   DALI_ANIMATABLE_PROPERTY_REGISTRATION_INTERNAL( __COUNTER__, typeRegistration, objectNamespace, objectType, text, valueType, enumIndex )
 
+#define DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( objectNamespace, objectType, text, value, enumIndex ) \
+  DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT_INTERNAL( __COUNTER__, typeRegistration, objectNamespace, objectType, text, value, enumIndex )
+
 #define DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( objectNamespace, objectType, text, enumIndex, baseEnumIndex, componentIndex ) \
   DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION_INTERNAL( __COUNTER__, typeRegistration, objectNamespace, objectType, text, enumIndex, baseEnumIndex, componentIndex )
 
index 7ed9031..d000227 100644 (file)
@@ -759,7 +759,7 @@ void Object::DisablePropertyNotifications()
   }
 }
 
-void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName )
+void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const
 {
   // Get the address of the property if it's a scene property
   const PropertyInputImpl* propertyPtr = GetSceneObjectInputProperty( propertyIndex );
@@ -793,7 +793,7 @@ void Object::AddUniformMapping( Property::Index propertyIndex, const std::string
     {
       SceneGraph::UniformPropertyMapping* map = new SceneGraph::UniformPropertyMapping( uniformName, propertyPtr );
       // Message takes ownership of Uniform map (and will delete it after copy)
-      AddUniformMapMessage( GetEventThreadServices(), *sceneObject, map);
+      AddUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *sceneObject, map);
     }
     else
     {
@@ -1258,7 +1258,9 @@ AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index i
       if(basePropertyIndex == Property::INVALID_INDEX)
       {
         // If the property is not a component of a base property, register the whole property itself.
-        RegisterSceneGraphProperty(typeInfo->GetPropertyName(index), index, Property::Value(typeInfo->GetPropertyType(index)));
+        const  std::string& propertyName = typeInfo->GetPropertyName(index);
+        RegisterSceneGraphProperty(propertyName, index, typeInfo->GetPropertyDefaultValue(index));
+        AddUniformMapping( index, propertyName );
       }
       else
       {
@@ -1267,9 +1269,11 @@ AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index i
         if(!animatableProperty)
         {
           // If the base property is not registered yet, register the base property first.
-          if(Property::INVALID_INDEX != RegisterSceneGraphProperty(typeInfo->GetPropertyName(basePropertyIndex), basePropertyIndex, Property::Value(typeInfo->GetPropertyType(basePropertyIndex))))
+          const  std::string& basePropertyName = typeInfo->GetPropertyName(basePropertyIndex);
+          if(Property::INVALID_INDEX != RegisterSceneGraphProperty(basePropertyName, basePropertyIndex, Property::Value(typeInfo->GetPropertyType(basePropertyIndex))))
           {
             animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
+            AddUniformMapping( basePropertyIndex, basePropertyName );
           }
         }
 
index bcbce81..472112b 100644 (file)
@@ -217,7 +217,7 @@ public:
   /**
    * @copydoc Dali::Handle::AddUniformMapping()
    */
-  void AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName );
+  void AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const;
 
   /**
    * @copydoc Dali::Handle::RemoveUniformMapping( )
index b73d925..bae3a8a 100644 (file)
@@ -415,6 +415,22 @@ void TypeInfo::AddAnimatableProperty( const std::string& name, Property::Index i
   }
 }
 
+void TypeInfo::AddAnimatableProperty( const std::string& name, Property::Index index, const Property::Value& defaultValue )
+{
+  RegisteredPropertyContainer::iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
+                                                        PairFinder< Property::Index, RegisteredPropertyPair>(index) );
+
+  if ( iter == mRegisteredProperties.end() )
+  {
+    mRegisteredProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( defaultValue.GetType(), NULL, NULL, name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) );
+    mPropertyDefaultValues.push_back( PropertyDefaultValuePair( index, defaultValue ) );
+  }
+  else
+  {
+    DALI_ASSERT_ALWAYS( ! "Property index already added to Type" );
+  }
+}
+
 void TypeInfo::AddAnimatablePropertyComponent( const std::string& name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex )
 {
   Property::Type type = GetPropertyType( baseIndex );
@@ -586,6 +602,20 @@ Property::Type TypeInfo::GetPropertyType( Property::Index index ) const
   return type;
 }
 
+Property::Value TypeInfo::GetPropertyDefaultValue( Property::Index index ) const
+{
+  PropertyDefaultValueContainer::const_iterator iter = find_if( mPropertyDefaultValues.begin(), mPropertyDefaultValues.end(),
+                                                    PairFinder< Property::Index, PropertyDefaultValuePair >( index ) );
+  if( iter !=  mPropertyDefaultValues.end() )
+  {
+    return iter->second;
+  }
+  else
+  {
+    return Property::Value( GetPropertyType( index ) );
+  }
+}
+
 void TypeInfo::SetProperty( BaseObject *object, Property::Index index, const Property::Value& value ) const
 {
   RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
index 9055e35..840af88 100644 (file)
@@ -147,6 +147,14 @@ public:
   void AddAnimatableProperty( const std::string& name, Property::Index index, Property::Type type );
 
   /**
+   * Adds an animatable property with the given default value.
+   * @param[in] name The name of the property.
+   * @param[in] index The index of the property
+   * @param[in] type The Property::Type.
+   */
+  void AddAnimatableProperty( const std::string& name, Property::Index index, const Property::Value& defaultValue );
+
+  /**
    * Adds a component of an animatable property to the type.
    * The animatable property must have been type-registered and must be a Vector2, Vector3 or Vector4 type.
    * @param[in] name The name of the component.
@@ -212,6 +220,13 @@ public:
   Property::Type GetPropertyType( Property::Index index ) const;
 
   /**
+   * Retrieve the default value of the property at the given index.
+   * @param[in] index The property index.
+   * @return The default property value at that index.
+   */
+  Property::Value GetPropertyDefaultValue( Property::Index index ) const;
+
+  /**
    * Sets the value of a property at the index specified for the given object.
    * @param[in] object The object whose property is to be set.
    * @param[in] index The property index.
@@ -278,10 +293,12 @@ private:
   typedef std::pair<std::string, Dali::TypeInfo::SignalConnectorFunction > ConnectionPair;
   typedef std::pair<std::string, Dali::TypeInfo::ActionFunction > ActionPair;
   typedef std::pair<Property::Index, RegisteredProperty> RegisteredPropertyPair;
+  typedef std::pair<Property::Index, Property::Value> PropertyDefaultValuePair;
 
   typedef std::vector< ActionPair > ActionContainer;
   typedef std::vector< ConnectionPair > ConnectorContainer;
   typedef std::vector< RegisteredPropertyPair > RegisteredPropertyContainer;
+  typedef std::vector< PropertyDefaultValuePair > PropertyDefaultValueContainer;
 
   std::string mTypeName;
   std::string mBaseTypeName;
@@ -289,6 +306,7 @@ private:
   ActionContainer mActions;
   ConnectorContainer mSignalConnectors;
   RegisteredPropertyContainer mRegisteredProperties;
+  PropertyDefaultValueContainer mPropertyDefaultValues;
 };
 
 } // namespace Internal
index 540c099..c487ac3 100644 (file)
@@ -232,6 +232,22 @@ bool TypeRegistry::RegisterAnimatableProperty( TypeRegistration& registered, con
   return false;
 }
 
+bool TypeRegistry::RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, const Property::Value& value )
+{
+  RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
+
+  if( iter != mRegistryLut.end() )
+  {
+    DALI_ASSERT_DEBUG(iter->second);
+
+    GetImplementation(iter->second).AddAnimatableProperty( name, index, value );
+
+    return true;
+  }
+
+  return false;
+}
+
 bool TypeRegistry::RegisterAnimatablePropertyComponent( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex )
 {
   RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
index 5423349..5028e14 100644 (file)
@@ -127,6 +127,16 @@ public:
   bool RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type );
 
   /**
+   * Register a scene graph only property with a default value
+   * @param [in] registered TypeRegistration object used to register the type
+   * @param [in] name Property name
+   * @param [in] index Property index
+   * @param [in] value Property default value
+   * @return true if registered
+   */
+  bool RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, const Property::Value& defaultValue );
+
+  /**
    * Register a component of a scene graph only property that supports components (i.e. Vector2, Vector3 and Vector4)
    * @param [in] registered TypeRegistration object used to register the type
    * @param [in] name Component name
index ac1f2fb..9196869 100644 (file)
@@ -142,6 +142,13 @@ AnimatablePropertyRegistration::AnimatablePropertyRegistration( TypeRegistration
   Internal::TypeRegistry::Get()->RegisterAnimatableProperty( registered, name, index, type );
 }
 
+AnimatablePropertyRegistration::AnimatablePropertyRegistration( TypeRegistration& registered, const std::string& name, Property::Index index, const Property::Value& value )
+{
+  DALI_ASSERT_ALWAYS( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) );
+
+  Internal::TypeRegistry::Get()->RegisterAnimatableProperty( registered, name, index, value );
+}
+
 AnimatablePropertyComponentRegistration::AnimatablePropertyComponentRegistration( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex)
 {
   DALI_ASSERT_ALWAYS( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) );
index e4a0338..abb6554 100644 (file)
@@ -310,6 +310,22 @@ public:
    * @pre "registered" must be registered with the TypeRegistry.
    */
   AnimatablePropertyRegistration( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type );
+
+  /**
+   * @brief This constructor registers the animatable property with the registered default value.
+   *
+   * This constructor is for scene-graph only properties where the
+   * value of the property can be retrieved and set via specified
+   * functions.
+   *
+   * @param [in] registered The TypeRegistration object
+   * @param [in] name The name of the property
+   * @param [in] index The property index. Must be a value between ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX and ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX inclusive.
+   * @param [in] value The property default value.
+   *
+   * @pre "registered" must be registered with the TypeRegistry.
+   */
+  AnimatablePropertyRegistration( TypeRegistration& registered, const std::string& name, Property::Index index, const Property::Value& value );
 };
 
 /**