(Object) RegisterProperty just sets the property if a property with the requested... 51/51651/2
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 11 Nov 2015 17:58:06 +0000 (17:58 +0000)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 12 Nov 2015 11:19:23 +0000 (11:19 +0000)
Change-Id: Ia993ddedfb9597cca4981bf792ef5c69dec753fe

automated-tests/src/dali/utc-Dali-Handle.cpp
dali/internal/event/common/object-impl.cpp
dali/internal/event/effects/shader-effect-impl.cpp
dali/public-api/object/handle.h

index efdac4a..0b2e68f 100644 (file)
@@ -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<Vector3>() );
+  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<float>(index) == 5.0f );
   END_TEST;
 }
+
 int UtcDaliHandleWeightNew(void)
 {
   TestApplication application;
@@ -758,3 +785,4 @@ int UtcDaliHandleWeightNew(void)
 
   END_TEST;
 }
+
index a9605e9..7ed9031 100644 (file)
@@ -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;
index d02799d..2b7fe66 100644 (file)
@@ -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<unsigned int>(index) >= CustomPropertyStartIndex() );
index b7caf59..41a749d 100644 (file)
@@ -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 );