From f139c6fbfc335c384bfd7ac744830c7c2f992fb5 Mon Sep 17 00:00:00 2001 From: Richard Huang Date: Wed, 1 Apr 2015 15:54:35 +0100 Subject: [PATCH] Lazy register animatable property if not registered yet Change-Id: I25bbda12ebf4f811653387b187718387a399bb14 --- dali/internal/event/actors/actor-impl.cpp | 25 +++++++++++++++++ dali/internal/event/common/object-impl.cpp | 38 ++++++++++++++++++-------- dali/internal/event/common/object-impl.h | 18 ++++++------ dali/internal/event/common/property-metadata.h | 13 +++++++-- dali/public-api/object/type-registry-helper.h | 2 +- 5 files changed, 73 insertions(+), 23 deletions(-) diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index 6a1efd9..0f59fed 100644 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -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 ) diff --git a/dali/internal/event/common/object-impl.cpp b/dali/internal/event/common/object-impl.cpp index b404f60..e5568c1 100644 --- a/dali/internal/event/common/object-impl.cpp +++ b/dali/internal/event/common/object-impl.cpp @@ -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( mAnimatableProperties[ arrayIndex ] ); + if( property->index == index ) { - property = static_cast(mAnimatableProperties[ arrayIndex ]); + return property; } } - return property; + return NULL; } } // namespace Internal diff --git a/dali/internal/event/common/object-impl.h b/dali/internal/event/common/object-impl.h index bb09d8c..3133135 100644 --- a/dali/internal/event/common/object-impl.h +++ b/dali/internal/event/common/object-impl.h @@ -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 diff --git a/dali/internal/event/common/property-metadata.h b/dali/internal/event/common/property-metadata.h index be416e0..a2f8fb8 100644 --- a/dali/internal/event/common/property-metadata.h +++ b/dali/internal/event/common/property-metadata.h @@ -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 diff --git a/dali/public-api/object/type-registry-helper.h b/dali/public-api/object/type-registry-helper.h index 2eb873f..c1a5d3f 100644 --- a/dali/public-api/object/type-registry-helper.h +++ b/dali/public-api/object/type-registry-helper.h @@ -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; \ -- 2.7.4