2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/common/object-impl.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/devel-api/object/handle-devel.h>
27 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
28 #include <dali/internal/update/common/animatable-property.h>
29 #include <dali/internal/update/common/property-owner.h>
30 #include <dali/internal/update/common/property-owner-messages.h>
31 #include <dali/internal/update/common/uniform-map.h>
32 #include <dali/internal/event/animation/constraint-impl.h>
33 #include <dali/internal/event/common/property-helper.h>
34 #include <dali/internal/event/common/property-notification-impl.h>
35 #include <dali/internal/event/common/stage-impl.h>
36 #include <dali/internal/event/common/type-registry-impl.h>
38 using Dali::Internal::SceneGraph::AnimatableProperty;
39 using Dali::Internal::SceneGraph::PropertyBase;
47 namespace // unnamed namespace
49 const int32_t SUPPORTED_CAPABILITIES = Dali::Handle::DYNAMIC_PROPERTIES; // Object provides this capability
51 #if defined(DEBUG_ENABLED)
52 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_OBJECT" );
55 constexpr Property::Index MAX_PER_CLASS_PROPERTY_INDEX = ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX;
57 } // unnamed namespace
59 IntrusivePtr<Object> Object::New()
61 return new Object( nullptr ); // no scene object by default
64 void Object::AddObserver(Observer& observer)
66 // make sure an observer doesn't observe the same object twice
67 // otherwise it will get multiple calls to OnSceneObjectAdd(), OnSceneObjectRemove() and ObjectDestroyed()
68 DALI_ASSERT_DEBUG( mObservers.End() == std::find( mObservers.Begin(), mObservers.End(), &observer));
70 mObservers.PushBack( &observer );
73 void Object::RemoveObserver(Observer& observer)
75 // Find the observer...
76 const auto endIter = mObservers.End();
77 for( auto iter = mObservers.Begin(); iter != endIter; ++iter)
79 if( (*iter) == &observer)
81 mObservers.Erase( iter );
85 DALI_ASSERT_DEBUG(endIter != mObservers.End());
88 bool Object::Supports( Capability capability ) const
90 return (capability & SUPPORTED_CAPABILITIES);
93 uint32_t Object::GetPropertyCount() const
96 const TypeInfo* typeInfo( GetTypeInfo() );
99 count = typeInfo->GetPropertyCount();
101 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Registered Properties: %d\n", count );
104 uint32_t custom = static_cast<uint32_t>( mCustomProperties.Count() );
106 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Custom Properties: %d\n", custom );
108 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Total Properties: %d\n", count );
113 std::string Object::GetPropertyName( Property::Index index ) const
115 DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index out of bounds" );
117 // is this a per class or per instance property
118 if ( index < MAX_PER_CLASS_PROPERTY_INDEX )
120 const TypeInfo* typeInfo( GetTypeInfo() );
123 return typeInfo->GetPropertyName( index );
126 else // child property or custom property
128 CustomPropertyMetadata* custom = FindCustomProperty( index );
135 DALI_LOG_ERROR( "Property index %d not found\n", index );
136 return std::string();
139 Property::Index Object::GetPropertyIndex( Property::Key key ) const
141 Property::Index index = Property::INVALID_INDEX;
143 if( key.type == Property::Key::STRING )
145 const TypeInfo* typeInfo( GetTypeInfo() );
148 index = typeInfo->GetPropertyIndex( key.stringKey );
152 if( (index == Property::INVALID_INDEX)&&( mCustomProperties.Count() > 0 ) )
154 Property::Index count = PROPERTY_CUSTOM_START_INDEX;
155 const auto end = mCustomProperties.End();
156 for( auto iter = mCustomProperties.Begin(); iter != end; ++iter, ++count )
158 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(*iter);
160 if( ( key.type == Property::Key::STRING && custom->name == key.stringKey) ||
161 ( key.type == Property::Key::INDEX && custom->key == key.indexKey ) )
163 if ( custom->childPropertyIndex != Property::INVALID_INDEX )
165 // If it is a child property, return the child property index
166 index = custom->childPropertyIndex;
180 bool Object::IsPropertyWritable( Property::Index index ) const
182 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
184 bool writable = false;
186 // is this a per class or per instance property
187 if ( index < MAX_PER_CLASS_PROPERTY_INDEX )
189 const TypeInfo* typeInfo( GetTypeInfo() );
192 writable = typeInfo->IsPropertyWritable( index );
197 CustomPropertyMetadata* custom = FindCustomProperty( index );
200 writable = custom->IsWritable();
207 bool Object::IsPropertyAnimatable( Property::Index index ) const
209 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
211 bool animatable = false;
213 // is this a per class or per instance property
214 if ( index < MAX_PER_CLASS_PROPERTY_INDEX )
216 const TypeInfo* typeInfo( GetTypeInfo() );
219 animatable = typeInfo->IsPropertyAnimatable( index );
224 CustomPropertyMetadata* custom = FindCustomProperty( index );
227 animatable = custom->IsAnimatable();
234 bool Object::IsPropertyAConstraintInput( Property::Index index ) const
236 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
238 bool isConstraintInput = false;
240 // is this a per class or per instance property
241 if ( index < MAX_PER_CLASS_PROPERTY_INDEX )
243 const TypeInfo* typeInfo( GetTypeInfo() );
246 isConstraintInput = typeInfo->IsPropertyAConstraintInput( index );
251 CustomPropertyMetadata* custom = FindCustomProperty( index );
254 // ... custom properties can be used as input to a constraint.
255 isConstraintInput = true;
259 return isConstraintInput;
262 Property::Type Object::GetPropertyType( Property::Index index ) const
264 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
266 // is this a per class or per instance property
267 if ( index < MAX_PER_CLASS_PROPERTY_INDEX )
269 const TypeInfo* typeInfo( GetTypeInfo() );
272 return typeInfo->GetPropertyType( index );
276 CustomPropertyMetadata* custom = FindCustomProperty( index );
279 return custom->GetType();
282 return Property::NONE;
285 void Object::SetProperty( Property::Index index, const Property::Value& propertyValue )
287 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
289 bool propertySet( true );
291 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
293 SetDefaultProperty( index, propertyValue );
295 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
297 const TypeInfo* typeInfo( GetTypeInfo() );
300 typeInfo->SetProperty( this, index, propertyValue );
304 // cannot register this property as there is no setter for it.
305 // event side properties must have a setter for now so need to be registered
306 DALI_LOG_ERROR( "Property index %d not found\n", index );
310 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
312 // check whether the animatable property is registered already, if not then register one.
313 AnimatablePropertyMetadata* animatableProperty = GetSceneAnimatableProperty( index, &propertyValue );
314 if( !animatableProperty )
316 DALI_LOG_ERROR( "Property index %d not found\n", index );
321 // update the cached property value
322 animatableProperty->SetPropertyValue( propertyValue );
324 // set the scene graph property value
325 SetSceneGraphProperty( index, *animatableProperty, propertyValue );
330 CustomPropertyMetadata* custom = FindCustomProperty( index );
332 if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
336 // If the child property is not registered yet, register it.
337 custom = new CustomPropertyMetadata( "", propertyValue, Property::READ_WRITE );
338 mCustomProperties.PushBack( custom );
341 custom->childPropertyIndex = index;
343 // Resolve name for the child property
344 Object* parent = GetParentObject();
347 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
350 custom->name = parentTypeInfo->GetChildPropertyName( index );
357 if( custom->IsAnimatable() )
359 // update the cached property value
360 custom->SetPropertyValue( propertyValue );
362 // set the scene graph property value
363 SetSceneGraphProperty( index, *custom, propertyValue );
365 else if( custom->IsWritable() )
367 // update the cached property value
368 custom->SetPropertyValue( propertyValue );
372 // trying to set value on read only property is no-op
378 DALI_LOG_ERROR( "Property index %d not found\n", index );
383 // Let derived classes know that a property has been set
384 // TODO: We should not call this for read-only properties, SetDefaultProperty() && TypeInfo::SetProperty() should return a bool, which would be true if the property is set
387 OnPropertySet( index, propertyValue );
388 Dali::Handle handle( this );
389 mPropertySetSignal.Emit( handle, index, propertyValue );
393 Property::Value Object::GetProperty( Property::Index index ) const
395 DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index is out of bounds" );
397 Property::Value value;
399 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
401 value = GetDefaultProperty( index );
403 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
405 const TypeInfo* typeInfo( GetTypeInfo() );
408 value = typeInfo->GetProperty( this, index );
412 DALI_LOG_ERROR( "Property index %d not found\n", index );
415 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
417 // check whether the animatable property is registered already, if not then register one.
418 // this is needed because property value may have been set as full property and get as a property component
419 AnimatablePropertyMetadata* animatableProperty = GetSceneAnimatableProperty( index, nullptr );
420 if( animatableProperty )
422 // get the cached animatable property value
423 value = animatableProperty->GetPropertyValue();
427 DALI_LOG_ERROR( "Property index %d not found\n", index );
430 else if(mCustomProperties.Count() > 0)
432 CustomPropertyMetadata* custom = FindCustomProperty( index );
435 // get the cached custom property value
436 value = custom->GetPropertyValue();
440 DALI_LOG_ERROR( "Property index %d not found\n", index );
447 Property::Value Object::GetCurrentProperty( Property::Index index ) const
449 DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index is out of bounds" );
451 Property::Value value;
453 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
455 value = GetDefaultPropertyCurrentValue( index );
457 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
459 const TypeInfo* typeInfo( GetTypeInfo() );
462 value = typeInfo->GetProperty( this, index );
466 DALI_LOG_ERROR( "Property index %d not found\n", index );
469 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
471 // check whether the animatable property is registered already, if not then register one.
472 // this is needed because property value may have been set as full property and get as a property component
473 AnimatablePropertyMetadata* animatableProperty = GetSceneAnimatableProperty( index, nullptr );
474 if( animatableProperty )
476 // get the animatable property value
477 value = GetCurrentPropertyValue( *animatableProperty );
481 DALI_LOG_ERROR( "Property index %d not found\n", index );
484 else if(mCustomProperties.Count() > 0)
486 CustomPropertyMetadata* custom = FindCustomProperty( index );
489 // get the custom property value
490 value = GetCurrentPropertyValue( *custom );
494 DALI_LOG_ERROR( "Property index %d not found\n", index );
501 void Object::GetPropertyIndices( Property::IndexContainer& indices ) const
506 const TypeInfo* typeInfo( GetTypeInfo() );
509 typeInfo->GetPropertyIndices( indices );
513 if ( mCustomProperties.Count() > 0 )
515 indices.Reserve( indices.Size() + mCustomProperties.Count() );
517 auto iter = mCustomProperties.Begin();
518 const auto endIter = mCustomProperties.End();
520 for ( ; iter != endIter; ++iter, ++i )
522 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>( *iter );
523 if ( custom->childPropertyIndex != Property::INVALID_INDEX )
525 // If it is a child property, add the child property index
526 indices.PushBack( custom->childPropertyIndex );
530 indices.PushBack( PROPERTY_CUSTOM_START_INDEX + i );
536 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue )
538 return RegisterProperty( name, Property::INVALID_KEY, propertyValue, Property::ANIMATABLE );
541 Property::Index Object::RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue )
543 return RegisterProperty( name, key, propertyValue, Property::ANIMATABLE );
546 void Object::SetProperties( const Property::Map& properties )
548 const auto count = properties.Count();
549 for( auto position = 0u; position < count; ++position )
551 // GetKeyAt and GetValue both return references which means no potential copying of maps/arrays.
552 // Iterating twice to get the value we want should still be fairly quick in a Property::Map.
554 const auto& key = properties.GetKeyAt( position );
555 const auto propertyIndex = ( key.type == Property::Key::INDEX ) ? key.indexKey : GetPropertyIndex( key );
557 if( propertyIndex != Property::INVALID_INDEX )
559 const auto& value = properties.GetValue( position );
560 SetProperty( propertyIndex, value );
565 void Object::GetProperties( Property::Map& properties )
569 Property::IndexContainer indexContainer;
570 GetPropertyIndices( indexContainer );
572 for( auto index : indexContainer )
574 properties[ index ] = GetProperty( index );
578 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode )
580 return RegisterProperty( name, Property::INVALID_KEY, propertyValue, accessMode );
583 Property::Index Object::RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue, Property::AccessMode accessMode )
585 // If property with the required key already exists, then just set it.
586 Property::Index index = Property::INVALID_INDEX;
587 if( key != Property::INVALID_KEY ) // Try integer key first if it's valid
589 index = GetPropertyIndex( key );
591 if( index == Property::INVALID_INDEX ) // If it wasn't valid, or doesn't exist, try name
593 index = GetPropertyIndex( name );
596 if( index != Property::INVALID_INDEX ) // If there was a valid index found by either key, set it.
598 SetProperty( index, propertyValue );
602 // Otherwise register the property
603 if( Property::ANIMATABLE == accessMode )
605 index = RegisterSceneGraphProperty( name, key, PROPERTY_CUSTOM_START_INDEX + static_cast<Property::Index>( mCustomProperties.Count() ), propertyValue );
606 AddUniformMapping( index, name );
610 // Add entry to the property lookup
611 index = PROPERTY_CUSTOM_START_INDEX + static_cast<Property::Index>( mCustomProperties.Count() );
613 CustomPropertyMetadata* customProperty = new CustomPropertyMetadata( name, propertyValue, accessMode );
615 // Resolve index for the child property
616 Object* parent = GetParentObject();
619 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
622 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( name );
623 if( childPropertyIndex != Property::INVALID_INDEX )
625 customProperty->childPropertyIndex = childPropertyIndex;
626 index = childPropertyIndex;
631 mCustomProperties.PushBack( customProperty );
638 bool Object::DoesCustomPropertyExist( Property::Index index )
640 auto metadata = FindCustomProperty( index );
641 return metadata != nullptr;
644 Dali::PropertyNotification Object::AddPropertyNotification( Property::Index index,
645 int32_t componentIndex,
646 const Dali::PropertyCondition& condition)
648 if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
650 if ( index <= PROPERTY_REGISTRATION_MAX_INDEX )
652 DALI_ABORT( "Property notification added to event side only property." );
654 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
656 // check whether the animatable property is registered already, if not then register one.
657 AnimatablePropertyMetadata* animatable = GetSceneAnimatableProperty( index, nullptr );
658 DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
660 else if ( mCustomProperties.Count() > 0 )
662 CustomPropertyMetadata* custom = FindCustomProperty( index );
663 DALI_ASSERT_ALWAYS( custom && "Invalid property index" );
664 DALI_ASSERT_ALWAYS( custom->IsAnimatable() && "Property notification added to event side only property." );
668 Dali::Handle self(this);
669 Property target( self, index );
671 PropertyNotificationPtr internal = PropertyNotification::New( target, componentIndex, condition );
672 Dali::PropertyNotification propertyNotification(internal.Get());
674 if( !mPropertyNotifications )
676 mPropertyNotifications = new PropertyNotificationContainer;
678 mPropertyNotifications->push_back(propertyNotification);
680 return propertyNotification;
683 void Object::RemovePropertyNotification(Dali::PropertyNotification propertyNotification)
685 if( mPropertyNotifications )
687 auto iter = mPropertyNotifications->begin();
688 while(iter != mPropertyNotifications->end() )
690 if(*iter == propertyNotification)
692 mPropertyNotifications->erase(iter);
693 // As we can't ensure all references are removed, we can just disable
695 GetImplementation(propertyNotification).Disable();
703 void Object::RemovePropertyNotifications()
705 if( mPropertyNotifications )
707 auto iter = mPropertyNotifications->begin();
708 while(iter != mPropertyNotifications->end() )
710 // As we can't ensure all references are removed, we can just disable
712 GetImplementation(*iter).Disable();
716 mPropertyNotifications->clear();
720 void Object::NotifyPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType )
722 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
724 OnNotifyDefaultPropertyAnimation( animation, index, value, animationType );
728 PropertyMetadata* propertyMetadata = nullptr;
729 if( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
731 propertyMetadata = FindAnimatableProperty( index );
735 CustomPropertyMetadata* custom = FindCustomProperty( index );
736 if( custom && custom->IsAnimatable() )
738 propertyMetadata = custom;
742 if( propertyMetadata )
744 switch( animationType )
747 case Animation::BETWEEN:
749 // Update the cached property value
750 propertyMetadata->SetPropertyValue( value );
755 // Adjust the cached property value
756 propertyMetadata->AdjustPropertyValueBy( value );
764 void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const
766 // Get the address of the property if it's a scene property
767 const PropertyInputImpl* propertyPtr = GetSceneObjectInputProperty( propertyIndex );
769 // Check instead for newly registered properties
770 if( propertyPtr == nullptr )
772 PropertyMetadata* animatable = FindAnimatableProperty( propertyIndex );
775 propertyPtr = animatable->GetSceneGraphProperty();
779 if( propertyPtr == nullptr )
781 PropertyMetadata* custom = FindCustomProperty( propertyIndex );
784 propertyPtr = custom->GetSceneGraphProperty();
790 const SceneGraph::PropertyOwner& sceneObject = GetSceneObject();
792 OwnerPointer< SceneGraph::UniformPropertyMapping > map = new SceneGraph::UniformPropertyMapping( uniformName, propertyPtr );
793 // Message takes ownership of Uniform map (and will delete it after copy)
794 AddUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), sceneObject, map );
798 void Object::RemoveUniformMapping( const std::string& uniformName ) const
800 const SceneGraph::PropertyOwner& sceneObject = GetSceneObject();
801 RemoveUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), sceneObject, uniformName);
804 void Object::ApplyConstraint( ConstraintBase& constraint )
808 mConstraints = new ConstraintContainer;
810 mConstraints->push_back( Dali::Constraint( &constraint ) );
813 void Object::RemoveConstraint( ConstraintBase& constraint )
815 // nullptr if the Constraint sources are destroyed before Constraint::Apply()
818 ConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), Dali::Constraint( &constraint ) ) );
819 if( it != mConstraints->end() )
821 mConstraints->erase( it );
826 void Object::RemoveConstraints()
828 // guard against constraint sending messages during core destruction
829 if( mConstraints && Stage::IsInstalled() )
831 for ( auto&& item : *mConstraints )
833 GetImplementation( item ).RemoveInternal();
837 mConstraints = nullptr;
841 void Object::RemoveConstraints( uint32_t tag )
843 // guard against constraint sending messages during core destruction
844 if( mConstraints && Stage::IsInstalled() )
846 auto iter( mConstraints->begin() );
847 while(iter != mConstraints->end() )
849 ConstraintBase& constraint = GetImplementation( *iter );
850 if( constraint.GetTag() == tag )
852 GetImplementation( *iter ).RemoveInternal();
853 iter = mConstraints->erase( iter );
861 if ( mConstraints->empty() )
864 mConstraints = nullptr;
869 void Object::SetTypeInfo( const TypeInfo* typeInfo )
871 mTypeInfo = typeInfo;
874 const SceneGraph::PropertyOwner& Object::GetSceneObject() const
878 auto sceneObject = SceneGraph::PropertyOwner::New();
879 OwnerPointer< SceneGraph::PropertyOwner > transferOwnership( sceneObject );
880 mUpdateObject = sceneObject;
881 AddObjectMessage( const_cast<EventThreadServices&>( GetEventThreadServices() ).GetUpdateManager(), transferOwnership );
883 DALI_ASSERT_DEBUG( mUpdateObject && "there must always be a scene object" );
884 return *mUpdateObject;
887 const PropertyBase* Object::GetSceneObjectAnimatableProperty( Property::Index index ) const
889 const SceneGraph::PropertyBase* property = nullptr;
890 if ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX && index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )
892 AnimatablePropertyMetadata* animatable = GetSceneAnimatableProperty( index, nullptr );
893 DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
895 property = animatable->GetSceneGraphProperty();
897 else if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && // Child properties are also stored as custom properties
898 ( index <= PROPERTY_CUSTOM_MAX_INDEX ) )
900 CustomPropertyMetadata* custom = FindCustomProperty( index );
901 DALI_ASSERT_ALWAYS( custom && "Property index is invalid" );
903 property = custom->GetSceneGraphProperty();
908 const PropertyInputImpl* Object::GetSceneObjectInputProperty( Property::Index index ) const
910 // reuse animatable version as they are inputs as well
911 return GetSceneObjectAnimatableProperty( index );
914 int32_t Object::GetPropertyComponentIndex( Property::Index index ) const
916 int32_t componentIndex = Property::INVALID_COMPONENT_INDEX;
918 if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
920 // check whether the animatable property is registered already, if not then register one.
921 AnimatablePropertyMetadata* animatableProperty = GetSceneAnimatableProperty( index, nullptr );
922 if( animatableProperty )
924 componentIndex = animatableProperty->componentIndex;
927 if( Property::INVALID_COMPONENT_INDEX == componentIndex )
929 const TypeInfo* typeInfo( GetTypeInfo() );
932 componentIndex = typeInfo->GetComponentIndex(index);
936 return componentIndex;
939 Handle::PropertySetSignalType& Object::PropertySetSignal()
941 return mPropertySetSignal;
944 Object::Object( const SceneGraph::PropertyOwner* sceneObject )
945 : mEventThreadServices( EventThreadServices::Get() ),
946 mUpdateObject( sceneObject ),
947 mTypeInfo( nullptr ),
948 mConstraints( nullptr ),
949 mPropertyNotifications( nullptr )
955 // Notification for observers
956 for( auto&& item : mObservers )
958 item->ObjectDestroyed( *this );
961 delete mPropertyNotifications;
963 // Guard to allow handle destruction after Core has been destroyed
964 if( Stage::IsInstalled() )
966 if( nullptr != mUpdateObject )
968 RemoveObjectMessage( GetEventThreadServices().GetUpdateManager(), mUpdateObject );
973 void Object::OnSceneObjectAdd()
975 // Notification for observers
976 for( auto&& item : mObservers )
978 item->SceneObjectAdded(*this);
981 // enable property notifications in scene graph
982 EnablePropertyNotifications();
985 void Object::OnSceneObjectRemove()
987 // Notification for observers
988 for( auto&& item : mObservers )
990 item->SceneObjectRemoved(*this);
993 // disable property notifications in scene graph
994 DisablePropertyNotifications();
997 const TypeInfo* Object::GetTypeInfo() const
1001 // This uses a dynamic_cast so can be quite expensive so we only really want to do it once
1002 // especially as the type-info does not change during the life-time of an application
1004 TypeRegistry::TypeInfoPointer typeInfoHandle = TypeRegistry::Get()->GetTypeInfo( this );
1005 if ( typeInfoHandle )
1007 mTypeInfo = typeInfoHandle.Get(); // just a raw pointer to use, ownership is kept
1014 CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) const
1016 CustomPropertyMetadata* property = nullptr;
1017 if ( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) )
1019 for ( std::size_t arrayIndex = 0; arrayIndex < mCustomProperties.Count(); arrayIndex++ )
1021 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>( mCustomProperties[ arrayIndex ] );
1022 if( custom->childPropertyIndex == index )
1030 int32_t arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
1031 if( arrayIndex >= 0 )
1033 if( arrayIndex < static_cast<int32_t>( mCustomProperties.Count() ) ) // we can only access the first 2 billion custom properties
1035 property = static_cast<CustomPropertyMetadata*>(mCustomProperties[ arrayIndex ]);
1042 AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index index ) const
1044 for( auto&& entry : mAnimatableProperties )
1046 AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>( entry );
1047 if( property->index == index )
1055 Property::Index Object::RegisterSceneGraphProperty( const std::string& name, Property::Index key, Property::Index index, const Property::Value& propertyValue ) const
1057 // Create a new property
1058 Dali::Internal::OwnerPointer<PropertyBase> newProperty;
1060 switch ( propertyValue.GetType() )
1062 case Property::BOOLEAN:
1064 newProperty = new AnimatableProperty<bool>( propertyValue.Get<bool>() );
1068 case Property::INTEGER:
1070 newProperty = new AnimatableProperty<int32_t>( propertyValue.Get<int32_t>() );
1074 case Property::FLOAT:
1076 newProperty = new AnimatableProperty<float>( propertyValue.Get<float>() );
1080 case Property::VECTOR2:
1082 newProperty = new AnimatableProperty<Vector2>( propertyValue.Get<Vector2>() );
1086 case Property::VECTOR3:
1088 newProperty = new AnimatableProperty<Vector3>( propertyValue.Get<Vector3>() );
1092 case Property::VECTOR4:
1094 newProperty = new AnimatableProperty<Vector4>( propertyValue.Get<Vector4>() );
1098 case Property::MATRIX:
1100 newProperty = new AnimatableProperty<Matrix>( propertyValue.Get<Matrix>() );
1104 case Property::MATRIX3:
1106 newProperty = new AnimatableProperty<Matrix3>( propertyValue.Get<Matrix3>() );
1110 case Property::ROTATION:
1112 newProperty = new AnimatableProperty<Quaternion>( propertyValue.Get<Quaternion>() );
1116 case Property::RECTANGLE:
1117 case Property::STRING:
1118 case Property::ARRAY:
1120 case Property::EXTENTS:
1121 case Property::NONE:
1123 DALI_ASSERT_ALWAYS( !"Property type is not animatable" );
1128 // get the scene property owner
1129 const SceneGraph::PropertyOwner& scenePropertyOwner = GetSceneObject();
1130 // keep a local pointer to the property as the OwnerPointer will pass its copy to the message
1131 const PropertyBase* property = newProperty.Get();
1132 if(index >= PROPERTY_CUSTOM_START_INDEX)
1134 DALI_ASSERT_ALWAYS( index <= PROPERTY_CUSTOM_MAX_INDEX && "Too many custom properties have been registered" );
1136 mCustomProperties.PushBack( new CustomPropertyMetadata( name, key, propertyValue, property ) );
1140 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, propertyValue, property ) );
1143 // queue a message to add the property
1144 InstallCustomPropertyMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), scenePropertyOwner, newProperty ); // Message takes ownership
1149 void Object::RegisterAnimatableProperty( const TypeInfo& typeInfo,
1150 Property::Index index,
1151 const Property::Value* value ) const
1153 // If the property is not a component of a base property, register the whole property itself.
1154 const std::string& propertyName = typeInfo.GetPropertyName( index );
1155 Property::Value initialValue;
1158 initialValue = *value;
1162 initialValue = typeInfo.GetPropertyDefaultValue( index ); // recurses type hierarchy
1163 if( Property::NONE == initialValue.GetType() )
1165 initialValue = Property::Value( typeInfo.GetPropertyType( index ) ); // recurses type hierarchy
1168 RegisterSceneGraphProperty( propertyName, Property::INVALID_KEY, index, initialValue );
1169 AddUniformMapping( index, propertyName );
1172 AnimatablePropertyMetadata* Object::GetSceneAnimatableProperty( Property::Index index, const Property::Value* value ) const
1174 // property range already checked by calling methods
1175 // check whether the animatable property is registered already, if not then register one.
1176 AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index );
1177 if( !animatableProperty )
1179 const TypeInfo* typeInfo( GetTypeInfo() );
1182 Property::Index basePropertyIndex = typeInfo->GetBasePropertyIndex( index );
1183 if( basePropertyIndex == Property::INVALID_INDEX )
1185 // If the property is not a component of a base property, register the whole property itself.
1186 RegisterAnimatableProperty( *typeInfo, index, value );
1190 // Since the property is a component of a base property, check whether the base property is registered.
1191 animatableProperty = FindAnimatableProperty( basePropertyIndex );
1192 if( !animatableProperty )
1194 // If the base property is not registered yet, register the base property first.
1195 RegisterAnimatableProperty( *typeInfo, basePropertyIndex, value );
1196 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1199 // Create the metadata for the property component.
1200 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, typeInfo->GetComponentIndex(index), animatableProperty->value, animatableProperty->GetSceneGraphProperty() ) );
1203 // The metadata has just been added and therefore should be in the end of the vector.
1204 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
1208 return animatableProperty;
1211 void Object::ResolveChildProperties()
1213 // Resolve index for the child property
1214 Object* parent = GetParentObject();
1217 const TypeInfo* parentTypeInfo( parent->GetTypeInfo() );
1218 if( parentTypeInfo )
1220 // Go through each custom property
1221 for( auto&& entry : mCustomProperties )
1223 CustomPropertyMetadata* customProperty = static_cast<CustomPropertyMetadata*>( entry );
1225 if( customProperty->name.empty() )
1227 if( customProperty->childPropertyIndex != Property::INVALID_INDEX )
1229 // Resolve name for any child property with no name
1230 customProperty->name = parentTypeInfo->GetChildPropertyName( customProperty->childPropertyIndex );
1235 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex( customProperty->name );
1236 if( childPropertyIndex != Property::INVALID_INDEX )
1238 // Resolve index for any property with a name that matches the parent's child property name
1239 customProperty->childPropertyIndex = childPropertyIndex;
1247 void Object::SetDefaultProperty( Property::Index index, const Property::Value& property )
1252 Property::Value Object::GetDefaultProperty(Property::Index index) const
1254 return Property::Value();
1257 Property::Value Object::GetDefaultPropertyCurrentValue( Property::Index index ) const
1259 return GetDefaultProperty( index );
1262 void Object::EnablePropertyNotifications()
1264 if( mPropertyNotifications )
1266 for( auto&& element : *mPropertyNotifications )
1268 GetImplementation( element ).Enable();
1273 void Object::DisablePropertyNotifications()
1275 if( mPropertyNotifications )
1277 for( auto&& element : *mPropertyNotifications )
1279 GetImplementation( element ).Disable();
1284 Property::Value Object::GetCurrentPropertyValue( const PropertyMetadata& entry ) const
1286 Property::Value value;
1288 if( !entry.IsAnimatable() )
1290 value = entry.GetPropertyValue();
1294 BufferIndex bufferIndex( GetEventThreadServices().GetEventBufferIndex() );
1296 switch ( entry.GetType() )
1298 case Property::BOOLEAN:
1300 const AnimatableProperty<bool>* property = static_cast< const AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
1301 DALI_ASSERT_DEBUG( property );
1303 value = (*property)[ bufferIndex ];
1307 case Property::INTEGER:
1309 const AnimatableProperty<int32_t>* property = static_cast< const AnimatableProperty<int32_t>* >( entry.GetSceneGraphProperty() );
1310 DALI_ASSERT_DEBUG( property );
1312 value = (*property)[ bufferIndex ];
1316 case Property::FLOAT:
1318 const AnimatableProperty<float>* property = static_cast< const AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
1319 DALI_ASSERT_DEBUG( property );
1321 value = (*property)[ bufferIndex ];
1325 case Property::VECTOR2:
1327 const AnimatableProperty<Vector2>* property = static_cast< const AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
1328 DALI_ASSERT_DEBUG( property );
1330 if(entry.componentIndex == 0)
1332 value = (*property)[ bufferIndex ].x;
1334 else if(entry.componentIndex == 1)
1336 value = (*property)[ bufferIndex ].y;
1340 value = (*property)[ bufferIndex ];
1345 case Property::VECTOR3:
1347 const AnimatableProperty<Vector3>* property = static_cast< const AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
1348 DALI_ASSERT_DEBUG( property );
1350 if(entry.componentIndex == 0)
1352 value = (*property)[ bufferIndex ].x;
1354 else if(entry.componentIndex == 1)
1356 value = (*property)[ bufferIndex ].y;
1358 else if(entry.componentIndex == 2)
1360 value = (*property)[ bufferIndex ].z;
1364 value = (*property)[ bufferIndex ];
1369 case Property::VECTOR4:
1371 const AnimatableProperty<Vector4>* property = static_cast< const AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
1372 DALI_ASSERT_DEBUG( property );
1374 if(entry.componentIndex == 0)
1376 value = (*property)[ bufferIndex ].x;
1378 else if(entry.componentIndex == 1)
1380 value = (*property)[ bufferIndex ].y;
1382 else if(entry.componentIndex == 2)
1384 value = (*property)[ bufferIndex ].z;
1386 else if(entry.componentIndex == 3)
1388 value = (*property)[ bufferIndex ].w;
1392 value = (*property)[ bufferIndex ];
1397 case Property::MATRIX:
1399 const AnimatableProperty<Matrix>* property = static_cast< const AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
1400 DALI_ASSERT_DEBUG( property );
1402 value = (*property)[ bufferIndex ];
1406 case Property::MATRIX3:
1408 const AnimatableProperty<Matrix3>* property = static_cast< const AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
1409 DALI_ASSERT_DEBUG( property );
1411 value = (*property)[ bufferIndex ];
1415 case Property::ROTATION:
1417 const AnimatableProperty<Quaternion>* property = static_cast< const AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
1418 DALI_ASSERT_DEBUG( property );
1420 value = (*property)[ bufferIndex ];
1426 // unreachable code due to higher level logic
1434 void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value )
1436 switch ( entry.GetType() )
1438 case Property::BOOLEAN:
1440 const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
1441 DALI_ASSERT_DEBUG( property );
1443 // property is being used in a separate thread; queue a message to set the property
1444 BakeMessage<bool>( GetEventThreadServices(), *property, value.Get<bool>() );
1448 case Property::INTEGER:
1450 const AnimatableProperty<int32_t>* property = dynamic_cast< const AnimatableProperty<int32_t>* >( entry.GetSceneGraphProperty() );
1451 DALI_ASSERT_DEBUG( property );
1453 // property is being used in a separate thread; queue a message to set the property
1454 BakeMessage<int32_t>( GetEventThreadServices(), *property, value.Get<int32_t>() );
1458 case Property::FLOAT:
1460 const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
1461 DALI_ASSERT_DEBUG( property );
1463 // property is being used in a separate thread; queue a message to set the property
1464 BakeMessage<float>( GetEventThreadServices(), *property, value.Get<float>() );
1468 case Property::VECTOR2:
1470 const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
1471 DALI_ASSERT_DEBUG( property );
1473 // property is being used in a separate thread; queue a message to set the property
1474 if(entry.componentIndex == 0)
1476 SetXComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1478 else if(entry.componentIndex == 1)
1480 SetYComponentMessage<Vector2>( GetEventThreadServices(), *property, value.Get<float>() );
1484 BakeMessage<Vector2>( GetEventThreadServices(), *property, value.Get<Vector2>() );
1489 case Property::VECTOR3:
1491 const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
1492 DALI_ASSERT_DEBUG( property );
1494 // property is being used in a separate thread; queue a message to set the property
1495 if(entry.componentIndex == 0)
1497 SetXComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1499 else if(entry.componentIndex == 1)
1501 SetYComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1503 else if(entry.componentIndex == 2)
1505 SetZComponentMessage<Vector3>( GetEventThreadServices(), *property, value.Get<float>() );
1509 BakeMessage<Vector3>( GetEventThreadServices(), *property, value.Get<Vector3>() );
1515 case Property::VECTOR4:
1517 const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
1518 DALI_ASSERT_DEBUG( property );
1520 // property is being used in a separate thread; queue a message to set the property
1521 if(entry.componentIndex == 0)
1523 SetXComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1525 else if(entry.componentIndex == 1)
1527 SetYComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1529 else if(entry.componentIndex == 2)
1531 SetZComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1533 else if(entry.componentIndex == 3)
1535 SetWComponentMessage<Vector4>( GetEventThreadServices(), *property, value.Get<float>() );
1539 BakeMessage<Vector4>( GetEventThreadServices(), *property, value.Get<Vector4>() );
1544 case Property::ROTATION:
1546 const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
1547 DALI_ASSERT_DEBUG( property );
1549 // property is being used in a separate thread; queue a message to set the property
1550 BakeMessage<Quaternion>( GetEventThreadServices(), *property, value.Get<Quaternion>() );
1554 case Property::MATRIX:
1556 const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
1557 DALI_ASSERT_DEBUG( property );
1559 // property is being used in a separate thread; queue a message to set the property
1560 BakeMessage<Matrix>( GetEventThreadServices(), *property, value.Get<Matrix>() );
1564 case Property::MATRIX3:
1566 const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
1567 DALI_ASSERT_DEBUG( property );
1569 // property is being used in a separate thread; queue a message to set the property
1570 BakeMessage<Matrix3>( GetEventThreadServices(), *property, value.Get<Matrix3>() );
1576 // non-animatable scene graph property, do nothing
1581 } // namespace Internal