From 55b5b98bce787f6550f0eea4b0b08d8dfb37dbfb Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Wed, 11 Nov 2015 17:58:06 +0000 Subject: [PATCH] (Object) RegisterProperty just sets the property if a property with the requested name already exists Change-Id: Ia993ddedfb9597cca4981bf792ef5c69dec753fe --- automated-tests/src/dali/utc-Dali-Handle.cpp | 30 ++++++++++++++++++- dali/internal/event/common/object-impl.cpp | 35 ++++++++++++---------- dali/internal/event/effects/shader-effect-impl.cpp | 10 ++----- dali/public-api/object/handle.h | 2 ++ 4 files changed, 53 insertions(+), 24 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Handle.cpp b/automated-tests/src/dali/utc-Dali-Handle.cpp index efdac4a..0b2e68f 100644 --- a/automated-tests/src/dali/utc-Dali-Handle.cpp +++ b/automated-tests/src/dali/utc-Dali-Handle.cpp @@ -597,8 +597,34 @@ int UtcDaliHandleRegisterProperty(void) tet_infoline("Positive Test Dali::Handle::RegisterProperty()"); TestApplication application; + Stage stage = Stage::GetCurrent(); + Actor actor = Actor::New(); - DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get() ); + stage.Add( actor ); + + const unsigned int defaultPropertyCount = actor.GetPropertyCount(); + + application.SendNotification(); + application.Render(); + + Property::Index index1 = actor.RegisterProperty( "MyProperty", Vector3::ONE ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 1, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index1 ), Vector3::ONE, TEST_LOCATION ); + + // No new property should be registered when we call the below function + Property::Index index2 = actor.RegisterProperty( "MyProperty", Vector3::ZAXIS ); + + application.SendNotification(); + application.Render(); + + + DALI_TEST_EQUALS( index1, index2, TEST_LOCATION ); // We should have the same index as per the first registration + DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 1, TEST_LOCATION ); // Property count should be the same + DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index2 ), Vector3::ZAXIS, TEST_LOCATION ); // Value should be what we sent on second RegisterProperty call END_TEST; } @@ -749,6 +775,7 @@ int UtcDaliHandleCustomProperty(void) DALI_TEST_CHECK( handle.GetProperty(index) == 5.0f ); END_TEST; } + int UtcDaliHandleWeightNew(void) { TestApplication application; @@ -758,3 +785,4 @@ int UtcDaliHandleWeightNew(void) END_TEST; } + diff --git a/dali/internal/event/common/object-impl.cpp b/dali/internal/event/common/object-impl.cpp index a9605e9..7ed9031 100644 --- a/dali/internal/event/common/object-impl.cpp +++ b/dali/internal/event/common/object-impl.cpp @@ -622,29 +622,34 @@ Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Prop } } -Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue) +Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue ) { - Property::Index index = RegisterSceneGraphProperty(name, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), propertyValue); - - /// @todo: don't keep a table of mappings per handle. - AddUniformMapping(index, name); - - return index; + return RegisterProperty( name, propertyValue, Property::ANIMATABLE ); } -Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode) +Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode ) { - Property::Index index; // No need to initialise as it's overridden anyway - - if(Property::ANIMATABLE == accessMode) + // If property with the required name already exists, then just set it. + Property::Index index = GetPropertyIndex( name ); + if( index != Property::INVALID_INDEX ) { - index = RegisterProperty(name, propertyValue); + SetProperty( index, propertyValue ); } else { - // Add entry to the property lookup - index = PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(); - mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue, accessMode ) ); + // Otherwise register the property + + if(Property::ANIMATABLE == accessMode) + { + index = RegisterSceneGraphProperty( name, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), propertyValue ); + AddUniformMapping( index, name ); + } + else + { + // Add entry to the property lookup + index = PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(); + mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue, accessMode ) ); + } } return index; diff --git a/dali/internal/event/effects/shader-effect-impl.cpp b/dali/internal/event/effects/shader-effect-impl.cpp index d02799d..2b7fe66 100644 --- a/dali/internal/event/effects/shader-effect-impl.cpp +++ b/dali/internal/event/effects/shader-effect-impl.cpp @@ -237,14 +237,8 @@ void ShaderEffect::SetEffectImage( Dali::Image image ) void ShaderEffect::SetUniform( const std::string& name, Property::Value value, UniformCoordinateType uniformCoordinateType ) { - // Register the property if it does not exist - Property::Index index = GetPropertyIndex( name ); - if ( Property::INVALID_INDEX == index ) - { - index = RegisterProperty( name, value ); - } - - SetProperty( index, value ); + // Register/Set the property + Property::Index index = RegisterProperty( name, value ); // RegisterProperty guarantees a positive value as index DALI_ASSERT_DEBUG( static_cast(index) >= CustomPropertyStartIndex() ); diff --git a/dali/public-api/object/handle.h b/dali/public-api/object/handle.h index b7caf59..41a749d 100644 --- a/dali/public-api/object/handle.h +++ b/dali/public-api/object/handle.h @@ -226,6 +226,7 @@ public: * @param [in] name The name of the property. * @param [in] propertyValue The new value of the property. * @return The index of the property or Property::INVALID_INDEX if registration failed + * @note If a property with the desired name already exists, then the value given is just set. */ Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue ); @@ -249,6 +250,7 @@ public: * @param [in] propertyValue The new value of the property. * @param [in] accessMode The property access mode (writable, animatable etc). * @return The index of the property + * @note If a property with the desired name already exists, then the value given is just set. */ Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode ); -- 2.7.4