Lazy register animatable property if not registered yet 45/37645/4
authorRichard Huang <r.huang@samsung.com>
Wed, 1 Apr 2015 14:54:35 +0000 (15:54 +0100)
committerRichard Huang <r.huang@samsung.com>
Wed, 1 Apr 2015 15:57:29 +0000 (16:57 +0100)
Change-Id: I25bbda12ebf4f811653387b187718387a399bb14

dali/internal/event/actors/actor-impl.cpp
dali/internal/event/common/object-impl.cpp
dali/internal/event/common/object-impl.h
dali/internal/event/common/property-metadata.h
dali/public-api/object/type-registry-helper.h

index 6a1efd9..0f59fed 100644 (file)
@@ -40,6 +40,7 @@
 #include <dali/internal/event/render-tasks/render-task-list-impl.h>
 #include <dali/internal/event/common/property-helper.h>
 #include <dali/internal/event/common/stage-impl.h>
+#include <dali/internal/event/common/type-info-impl.h>
 #include <dali/internal/event/actor-attachments/actor-attachment-impl.h>
 #include <dali/internal/event/animation/constraint-impl.h>
 #include <dali/internal/event/common/projection.h>
@@ -3396,7 +3397,19 @@ const PropertyBase* Actor::GetSceneObjectAnimatableProperty( Property::Index ind
   if ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX && index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )
   {
     AnimatablePropertyMetadata* animatable = FindAnimatableProperty( index );
+    if( !animatable )
+    {
+      const TypeInfo* typeInfo( GetTypeInfo() );
+      if ( typeInfo )
+      {
+        if( Property::INVALID_INDEX != RegisterSceneGraphProperty( typeInfo->GetPropertyName( index ), index, Property::Value( typeInfo->GetPropertyType( index ) ) ) )
+        {
+          animatable = FindAnimatableProperty( index );
+        }
+      }
+    }
     DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
+
     property = animatable->GetSceneGraphProperty();
   }
   else if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
@@ -3507,7 +3520,19 @@ const PropertyInputImpl* Actor::GetSceneObjectInputProperty( Property::Index ind
   if ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX && index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )
   {
     AnimatablePropertyMetadata* animatable = FindAnimatableProperty( index );
+    if( !animatable )
+    {
+      const TypeInfo* typeInfo( GetTypeInfo() );
+      if ( typeInfo )
+      {
+        if( Property::INVALID_INDEX != RegisterSceneGraphProperty( typeInfo->GetPropertyName( index ), index, Property::Value( typeInfo->GetPropertyType( index ) ) ) )
+        {
+          animatable = FindAnimatableProperty( index );
+        }
+      }
+    }
     DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
+
     property = animatable->GetSceneGraphProperty();
   }
   else if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
index b404f60..e5568c1 100644 (file)
@@ -401,13 +401,13 @@ void Object::SetProperty( Property::Index index, const Property::Value& property
     if(!animatableProperty)
     {
       const TypeInfo* typeInfo( GetTypeInfo() );
-      if (typeInfo && Property::INVALID_INDEX == RegisterSceneGraphProperty(typeInfo->GetPropertyName(index), index, propertyValue))
+      if (!typeInfo)
       {
-        DALI_LOG_ERROR("Cannot register property\n");
+        DALI_LOG_ERROR("Cannot find property index\n");
       }
-      else
+      else if ( Property::INVALID_INDEX == RegisterSceneGraphProperty( typeInfo->GetPropertyName( index ), index, propertyValue ) )
       {
-        DALI_LOG_ERROR("Cannot find property index\n");
+        DALI_LOG_ERROR("Cannot register property\n");
       }
     }
     else
@@ -630,7 +630,7 @@ Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Prop
     }
     else
     {
-      mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( propertyValue.GetType(), property ) );
+      mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, propertyValue.GetType(), property ) );
     }
 
     // queue a message to add the property
@@ -682,6 +682,23 @@ Dali::PropertyNotification Object::AddPropertyNotification(Property::Index index
     {
       DALI_ASSERT_ALWAYS( false && "Property notification added to event side only property." );
     }
+    else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
+    {
+      // check whether the animatable property is registered already, if not then register one.
+      AnimatablePropertyMetadata* animatable = FindAnimatableProperty( index );
+      if( !animatable )
+      {
+        const TypeInfo* typeInfo( GetTypeInfo() );
+        if ( typeInfo )
+        {
+          if( Property::INVALID_INDEX != RegisterSceneGraphProperty( typeInfo->GetPropertyName( index ), index, Property::Value( typeInfo->GetPropertyType( index ) ) ) )
+          {
+            animatable = FindAnimatableProperty( index );
+          }
+        }
+      }
+      DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
+    }
     else if ( mCustomProperties.Count() > 0 )
     {
       CustomPropertyMetadata* custom = FindCustomProperty( index );
@@ -1154,16 +1171,15 @@ CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) cons
 
 AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index index ) const
 {
-  AnimatablePropertyMetadata* property( NULL );
-  int arrayIndex = index - ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX;
-  if( arrayIndex >= 0 )
+  for ( int arrayIndex = 0; arrayIndex < (int)mAnimatableProperties.Count(); arrayIndex++ )
   {
-    if( arrayIndex < (int)mAnimatableProperties.Count() )
+    AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>( mAnimatableProperties[ arrayIndex ] );
+    if( property->index == index )
     {
-      property = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[ arrayIndex ]);
+      return property;
     }
   }
-  return property;
+  return NULL;
 }
 
 } // namespace Internal
index bb09d8c..3133135 100644 (file)
@@ -334,6 +334,15 @@ protected:
    */
   AnimatablePropertyMetadata* FindAnimatableProperty( Property::Index index ) const;
 
+  /**
+   * Helper to register a scene-graph property
+   * @param [in] name The name of the property.
+   * @param [in] index The index of the property
+   * @param [in] value The value of the property.
+   * @return The index of the registered property or Property::INVALID_INDEX if registration failed.
+   */
+  Property::Index RegisterSceneGraphProperty(const std::string& name, Property::Index index, const Property::Value& propertyValue) const;
+
 private: // Default property extensions for derived classes
 
   /**
@@ -474,15 +483,6 @@ private:
    */
   virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
 
-  /**
-   * Helper to register a scene-graph property
-   * @param [in] name The name of the property.
-   * @param [in] index The index of the property
-   * @param [in] value The value of the property.
-   * @return The index of the registered property or Property::INVALID_INDEX if registration failed.
-   */
-  Property::Index RegisterSceneGraphProperty(const std::string& name, Property::Index index, const Property::Value& propertyValue) const;
-
 protected:
   /**
    * Get the event thread services object - used for sending messages to the scene graph
index be416e0..a2f8fb8 100644 (file)
@@ -141,10 +141,14 @@ public:
 
   /**
    * Constructor for metadata of animatable property
+   * @param [in] newIndex The index of the animatable property.
+   * @param [in] newType The type ID of the animatable property.
    * @param [in] newProperty A pointer to the scene-graph owned property.
    */
-  AnimatablePropertyMetadata( Property::Type newType,
+  AnimatablePropertyMetadata( Property::Index newIndex,
+                        Property::Type newType,
                         const SceneGraph::PropertyBase* newProperty )
+  : index(newIndex)
   {
     type = newType;
     mProperty = newProperty;
@@ -153,9 +157,12 @@ public:
 
   /**
    * Constructor for metadata of animatable property
+   * @param [in] newIndex The index of the animatable property.
    * @param [in] newValue The value of the scene-graph owned property.
    */
-  AnimatablePropertyMetadata( Property::Value newValue )
+  AnimatablePropertyMetadata( Property::Index newIndex,
+                        Property::Value newValue )
+  : index(newIndex)
   {
     type = newValue.GetType();
     value = newValue;
@@ -169,6 +176,8 @@ public:
     return true ;
   }
 
+  Property::Index index;       ///< The index of the property
+
 private:
 
   // Not implemented
index 2eb873f..c1a5d3f 100644 (file)
@@ -44,7 +44,7 @@ namespace Internal
   DALI_COMPILE_TIME_ASSERT( ( Toolkit::objectType::Property::enumIndex - Toolkit::objectType::PROPERTY_START_INDEX ) == count );
 
 #define DALI_ANIMATABLE_PROPERTY_REGISTRATION_INTERNAL( count, typeRegistrationObject, objectType, text, valueType, enumIndex) \
-  AnimatablePropertyRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, Toolkit::objectType::AnimatableProperty::enumIndex, Property::valueType );
+  AnimatablePropertyRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, Toolkit::objectType::Property::enumIndex, Property::valueType );
 
 #define DALI_SIGNAL_REGISTRATION_INTERNAL( count, typeRegistrationObject, objectType, text, textVariable ) \
   const char* const textVariable = text; \