partial rendering
[platform/core/uifw/dali-core.git] / dali / internal / event / common / object-impl.cpp
index 09e48c0..811d3fa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -136,55 +136,31 @@ std::string Object::GetPropertyName( Property::Index index ) const
   return std::string();
 }
 
-Property::Index Object::GetPropertyIndex( const std::string& name ) const
+Property::Index Object::GetPropertyIndex( Property::Key key ) const
 {
   Property::Index index = Property::INVALID_INDEX;
 
-  const TypeInfo* typeInfo( GetTypeInfo() );
-  if ( typeInfo )
-  {
-    index = typeInfo->GetPropertyIndex( name );
-  }
-  if( (index == Property::INVALID_INDEX)&&( mCustomProperties.Count() > 0 ) )
+  if( key.type == Property::Key::STRING )
   {
-    Property::Index count = PROPERTY_CUSTOM_START_INDEX;
-    const auto end = mCustomProperties.End();
-    for( auto iter = mCustomProperties.Begin(); iter != end; ++iter, ++count )
+    const TypeInfo* typeInfo( GetTypeInfo() );
+    if ( typeInfo )
     {
-      CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(*iter);
-      if ( custom->name == name )
-      {
-        if ( custom->childPropertyIndex != Property::INVALID_INDEX )
-        {
-          // If it is a child property, return the child property index
-          index = custom->childPropertyIndex;
-        }
-        else
-        {
-          index = count;
-        }
-        break;
-      }
+      index = typeInfo->GetPropertyIndex( key.stringKey );
     }
   }
 
-  return index;
-}
-
-Property::Index Object::GetPropertyIndex( Property::Index key ) const
-{
-  Property::Index index = Property::INVALID_INDEX;
-
-  if( mCustomProperties.Count() > 0 )
+  if( (index == Property::INVALID_INDEX)&&( mCustomProperties.Count() > 0 ) )
   {
     Property::Index count = PROPERTY_CUSTOM_START_INDEX;
     const auto end = mCustomProperties.End();
     for( auto iter = mCustomProperties.Begin(); iter != end; ++iter, ++count )
     {
       CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(*iter);
-      if( custom->key == key )
+
+      if( ( key.type == Property::Key::STRING && custom->name == key.stringKey) ||
+          ( key.type == Property::Key::INDEX && custom->key == key.indexKey ) )
       {
-        if( custom->childPropertyIndex != Property::INVALID_INDEX )
+        if ( custom->childPropertyIndex != Property::INVALID_INDEX )
         {
           // If it is a child property, return the child property index
           index = custom->childPropertyIndex;
@@ -201,20 +177,6 @@ Property::Index Object::GetPropertyIndex( Property::Index key ) const
   return index;
 }
 
-Property::Index Object::GetPropertyIndex( Property::Key key ) const
-{
-  Property::Index index = Property::INVALID_INDEX;
-  if( key.type == Property::Key::INDEX )
-  {
-    index = GetPropertyIndex( key.indexKey );
-  }
-  else
-  {
-    index = GetPropertyIndex( key.stringKey );
-  }
-  return index;
-}
-
 bool Object::IsPropertyWritable( Property::Index index ) const
 {
   DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
@@ -320,7 +282,7 @@ Property::Type Object::GetPropertyType( Property::Index index ) const
   return Property::NONE;
 }
 
-void Object::SetProperty( Property::Index index, const Property::Value& propertyValue )
+void Object::SetProperty(Property::Index index, Property::Value propertyValue)
 {
   DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
 
@@ -423,8 +385,11 @@ void Object::SetProperty( Property::Index index, const Property::Value& property
   if ( propertySet )
   {
     OnPropertySet( index, propertyValue );
-    Dali::Handle handle( this );
-    mPropertySetSignal.Emit( handle, index, propertyValue );
+    if(!mPropertySetSignal.Empty())
+    {
+      Dali::Handle handle(this);
+      mPropertySetSignal.Emit(handle, index, propertyValue);
+    }
   }
 }
 
@@ -453,7 +418,7 @@ Property::Value Object::GetProperty( Property::Index index ) const
   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.
-         // this is needed because property value may have been set as full property and get as a property component
+    // this is needed because property value may have been set as full property and get as a property component
     AnimatablePropertyMetadata* animatableProperty = GetSceneAnimatableProperty( index, nullptr );
     if( animatableProperty )
     {
@@ -507,7 +472,7 @@ Property::Value Object::GetCurrentProperty( Property::Index index ) const
   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.
-         // this is needed because property value may have been set as full property and get as a property component
+    // this is needed because property value may have been set as full property and get as a property component
     AnimatablePropertyMetadata* animatableProperty = GetSceneAnimatableProperty( index, nullptr );
     if( animatableProperty )
     {
@@ -571,22 +536,59 @@ void Object::GetPropertyIndices( Property::IndexContainer& indices ) const
   }
 }
 
-Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue )
+Property::Index Object::RegisterProperty(std::string name, Property::Value propertyValue)
 {
-  return RegisterProperty( name, Property::INVALID_KEY, propertyValue, Property::ANIMATABLE );
+  return RegisterProperty(std::move(name), Property::INVALID_KEY, std::move(propertyValue), Property::ANIMATABLE);
 }
 
-Property::Index Object::RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue )
+Property::Index Object::RegisterProperty(std::string name, Property::Index key, Property::Value propertyValue)
 {
-  return RegisterProperty( name, key, propertyValue, Property::ANIMATABLE );
+  return RegisterProperty(std::move(name), key, std::move(propertyValue), Property::ANIMATABLE);
 }
 
-Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode )
+void Object::SetProperties( const Property::Map& properties )
 {
-  return RegisterProperty( name, Property::INVALID_KEY, propertyValue, accessMode );
+  const auto count = properties.Count();
+  for( auto position = 0u; position < count; ++position )
+  {
+    // GetKeyAt and GetValue both return references which means no potential copying of maps/arrays.
+    // Iterating twice to get the value we want should still be fairly quick in a Property::Map.
+
+    const auto& key = properties.GetKeyAt( position );
+    const auto propertyIndex = ( key.type == Property::Key::INDEX ) ? key.indexKey : GetPropertyIndex( key );
+
+    if( propertyIndex != Property::INVALID_INDEX )
+    {
+      const auto& value = properties.GetValue( position );
+      SetProperty( propertyIndex, value );
+    }
+  }
 }
 
-Property::Index Object::RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue, Property::AccessMode accessMode )
+void Object::GetProperties( Property::Map& properties )
+{
+  properties.Clear();
+
+  Property::IndexContainer indexContainer;
+  GetPropertyIndices( indexContainer );
+
+  for( auto index : indexContainer )
+  {
+    properties[ index ] = GetProperty( index );
+  }
+}
+
+Property::Index Object::RegisterProperty(std::string          name,
+                                         Property::Value      propertyValue,
+                                         Property::AccessMode accessMode)
+{
+  return RegisterProperty(std::move(name), Property::INVALID_KEY, std::move(propertyValue), accessMode);
+}
+
+Property::Index Object::RegisterProperty(std::string          name,
+                                         Property::Index      key,
+                                         Property::Value      propertyValue,
+                                         Property::AccessMode accessMode)
 {
   // If property with the required key already exists, then just set it.
   Property::Index index = Property::INVALID_INDEX;
@@ -601,22 +603,27 @@ Property::Index Object::RegisterProperty( const std::string& name, Property::Ind
 
   if( index != Property::INVALID_INDEX ) // If there was a valid index found by either key, set it.
   {
-    SetProperty( index, propertyValue );
+    SetProperty(index, std::move(propertyValue));
   }
   else
   {
     // Otherwise register the property
     if( Property::ANIMATABLE == accessMode )
     {
-      index = RegisterSceneGraphProperty( name, key, PROPERTY_CUSTOM_START_INDEX + static_cast<Property::Index>( mCustomProperties.Count() ), propertyValue );
-      AddUniformMapping( index, name );
+      index = RegisterSceneGraphProperty(
+        name,
+        key,
+        PROPERTY_CUSTOM_START_INDEX + static_cast<Property::Index>(mCustomProperties.Count()),
+        std::move(propertyValue));
+      AddUniformMapping(index, std::move(name));
     }
     else
     {
       // Add entry to the property lookup
       index = PROPERTY_CUSTOM_START_INDEX + static_cast<Property::Index>( mCustomProperties.Count() );
 
-      CustomPropertyMetadata* customProperty = new CustomPropertyMetadata( name, propertyValue, accessMode );
+      CustomPropertyMetadata* customProperty =
+        new CustomPropertyMetadata(std::move(name), std::move(propertyValue), accessMode);
 
       // Resolve index for the child property
       Object* parent = GetParentObject();
@@ -625,7 +632,7 @@ Property::Index Object::RegisterProperty( const std::string& name, Property::Ind
         const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
         if( parentTypeInfo )
         {
-          Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( name );
+          Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( customProperty->name );
           if( childPropertyIndex != Property::INVALID_INDEX )
           {
             customProperty->childPropertyIndex = childPropertyIndex;
@@ -767,7 +774,7 @@ void Object::NotifyPropertyAnimation( Animation& animation, Property::Index inde
   }
 }
 
-void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const
+void Object::AddUniformMapping(Property::Index propertyIndex, std::string uniformName) const
 {
   // Get the address of the property if it's a scene property
   const PropertyInputImpl* propertyPtr = GetSceneObjectInputProperty( propertyIndex );
@@ -795,7 +802,8 @@ void Object::AddUniformMapping( Property::Index propertyIndex, const std::string
   {
     const SceneGraph::PropertyOwner& sceneObject = GetSceneObject();
 
-    OwnerPointer< SceneGraph::UniformPropertyMapping > map = new SceneGraph::UniformPropertyMapping( uniformName, propertyPtr );
+    OwnerPointer<SceneGraph::UniformPropertyMapping> map =
+      new SceneGraph::UniformPropertyMapping(std::move(uniformName), propertyPtr);
     // Message takes ownership of Uniform map (and will delete it after copy)
     AddUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), sceneObject, map );
   }
@@ -942,13 +950,13 @@ int32_t Object::GetPropertyComponentIndex( Property::Index index ) const
   return componentIndex;
 }
 
-DevelHandle::PropertySetSignalType& Object::PropertySetSignal()
+Handle::PropertySetSignalType& Object::PropertySetSignal()
 {
   return mPropertySetSignal;
 }
 
 Object::Object( const SceneGraph::PropertyOwner* sceneObject )
-: mEventThreadServices( *Stage::GetCurrent() ),
+: mEventThreadServices( EventThreadServices::Get() ),
   mUpdateObject( sceneObject ),
   mTypeInfo( nullptr ),
   mConstraints( nullptr ),
@@ -1058,7 +1066,7 @@ AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index inde
   return nullptr;
 }
 
-Property::Index Object::RegisterSceneGraphProperty( const std::string& name, Property::Index key, Property::Index index, const Property::Value& propertyValue ) const
+Property::Index Object::RegisterSceneGraphProperty( std::string name, Property::Index key, Property::Index index, Property::Value propertyValue ) const
 {
   // Create a new property
   Dali::Internal::OwnerPointer<PropertyBase> newProperty;
@@ -1139,11 +1147,11 @@ Property::Index Object::RegisterSceneGraphProperty( const std::string& name, Pro
   {
     DALI_ASSERT_ALWAYS( index <= PROPERTY_CUSTOM_MAX_INDEX && "Too many custom properties have been registered" );
 
-    mCustomProperties.PushBack( new CustomPropertyMetadata( name, key, propertyValue, property ) );
+    mCustomProperties.PushBack( new CustomPropertyMetadata( std::move(name), key, std::move(propertyValue), property ) );
   }
   else
   {
-    mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, propertyValue, property ) );
+    mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, std::move(propertyValue), property ) );
   }
 
   // queue a message to add the property