2 * Copyright (c) 2021 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/devel-api/object/handle-devel.h>
26 #include <dali/integration-api/debug.h>
27 #include <dali/internal/common/const-string.h>
28 #include <dali/internal/event/animation/constraint-impl.h>
29 #include <dali/internal/event/common/property-helper.h>
30 #include <dali/internal/event/common/property-notification-impl.h>
31 #include <dali/internal/event/common/stage-impl.h>
32 #include <dali/internal/event/common/type-registry-impl.h>
33 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
34 #include <dali/internal/update/common/animatable-property.h>
35 #include <dali/internal/update/common/property-owner-messages.h>
36 #include <dali/internal/update/common/property-owner.h>
37 #include <dali/internal/update/common/uniform-map.h>
39 using Dali::Internal::SceneGraph::AnimatableProperty;
40 using Dali::Internal::SceneGraph::PropertyBase;
46 namespace // unnamed namespace
48 const int32_t SUPPORTED_CAPABILITIES = Dali::Handle::DYNAMIC_PROPERTIES; // Object provides this capability
50 #if defined(DEBUG_ENABLED)
51 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_OBJECT");
54 constexpr Property::Index MAX_PER_CLASS_PROPERTY_INDEX = ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX;
56 } // unnamed namespace
58 IntrusivePtr<Object> Object::New()
60 return new Object(nullptr); // no scene object by default
63 void Object::AddObserver(Observer& observer)
65 // make sure an observer doesn't observe the same object twice
66 // otherwise it will get multiple calls to OnSceneObjectAdd(), OnSceneObjectRemove() and ObjectDestroyed()
67 DALI_ASSERT_DEBUG(mObservers.End() == std::find(mObservers.Begin(), mObservers.End(), &observer));
69 mObservers.PushBack(&observer);
72 void Object::RemoveObserver(Observer& observer)
74 // Find the observer...
75 const auto endIter = mObservers.End();
76 for(auto iter = mObservers.Begin(); iter != endIter; ++iter)
78 if((*iter) == &observer)
80 mObservers.Erase(iter);
84 DALI_ASSERT_DEBUG(endIter != mObservers.End());
87 bool Object::Supports(Capability capability) const
89 return (capability & SUPPORTED_CAPABILITIES);
92 uint32_t Object::GetPropertyCount() const
95 const TypeInfo* typeInfo(GetTypeInfo());
98 count = typeInfo->GetPropertyCount();
100 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Registered Properties: %d\n", count);
103 uint32_t custom = static_cast<uint32_t>(mCustomProperties.Count());
105 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Custom Properties: %d\n", custom);
107 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Total Properties: %d\n", count);
112 std::string_view Object::GetPropertyName(Property::Index index) const
114 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index out of bounds");
116 // is this a per class or per instance property
117 if(index < MAX_PER_CLASS_PROPERTY_INDEX)
119 const TypeInfo* typeInfo(GetTypeInfo());
122 return typeInfo->GetPropertyName(index);
125 else // child property or custom property
127 CustomPropertyMetadata* custom = FindCustomProperty(index);
130 return custom->name.GetStringView();
134 DALI_LOG_ERROR("Property index %d not found\n", index);
138 Property::Index Object::GetPropertyIndex(KeyRef key) const
140 Property::Index index = Property::INVALID_INDEX;
142 if(key.mType == Property::Key::STRING)
144 const TypeInfo* typeInfo(GetTypeInfo());
147 index = typeInfo->GetPropertyIndex(key.mString);
151 if((index == Property::INVALID_INDEX) && (mCustomProperties.Count() > 0))
153 Property::Index count = PROPERTY_CUSTOM_START_INDEX;
154 const auto end = mCustomProperties.End();
155 for(auto iter = mCustomProperties.Begin(); iter != end; ++iter, ++count)
157 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(*iter);
159 if((key.mType == Property::Key::STRING && custom->name == key.mString) ||
160 (key.mType == Property::Key::INDEX && custom->key == key.mIndex))
162 if(custom->childPropertyIndex != Property::INVALID_INDEX)
164 // If it is a child property, return the child property index
165 index = custom->childPropertyIndex;
179 bool Object::IsPropertyWritable(Property::Index index) const
181 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
183 bool writable = false;
185 // is this a per class or per instance property
186 if(index < MAX_PER_CLASS_PROPERTY_INDEX)
188 const TypeInfo* typeInfo(GetTypeInfo());
191 writable = typeInfo->IsPropertyWritable(index);
196 CustomPropertyMetadata* custom = FindCustomProperty(index);
199 writable = custom->IsWritable();
206 bool Object::IsPropertyAnimatable(Property::Index index) const
208 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
210 bool animatable = false;
212 // is this a per class or per instance property
213 if(index < MAX_PER_CLASS_PROPERTY_INDEX)
215 const TypeInfo* typeInfo(GetTypeInfo());
218 animatable = typeInfo->IsPropertyAnimatable(index);
223 CustomPropertyMetadata* custom = FindCustomProperty(index);
226 animatable = custom->IsAnimatable();
233 bool Object::IsPropertyAConstraintInput(Property::Index index) const
235 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
237 bool isConstraintInput = false;
239 // is this a per class or per instance property
240 if(index < MAX_PER_CLASS_PROPERTY_INDEX)
242 const TypeInfo* typeInfo(GetTypeInfo());
245 isConstraintInput = typeInfo->IsPropertyAConstraintInput(index);
250 CustomPropertyMetadata* custom = FindCustomProperty(index);
253 // ... custom properties can be used as input to a constraint.
254 isConstraintInput = true;
258 return isConstraintInput;
261 Property::Type Object::GetPropertyType(Property::Index index) const
263 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
265 // is this a per class or per instance property
266 if(index < MAX_PER_CLASS_PROPERTY_INDEX)
268 const TypeInfo* typeInfo(GetTypeInfo());
271 return typeInfo->GetPropertyType(index);
275 CustomPropertyMetadata* custom = FindCustomProperty(index);
278 return custom->GetType();
281 return Property::NONE;
284 void Object::SetProperty(Property::Index index, Property::Value propertyValue)
286 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
288 bool propertySet(true);
290 if(index < DEFAULT_PROPERTY_MAX_COUNT)
292 SetDefaultProperty(index, propertyValue);
294 else if((index >= PROPERTY_REGISTRATION_START_INDEX) && (index <= PROPERTY_REGISTRATION_MAX_INDEX))
296 const TypeInfo* typeInfo(GetTypeInfo());
299 typeInfo->SetProperty(this, index, propertyValue);
303 // cannot register this property as there is no setter for it.
304 // event side properties must have a setter for now so need to be registered
305 DALI_LOG_ERROR("Property index %d not found\n", index);
309 else if((index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX) && (index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX))
311 // check whether the animatable property is registered already, if not then register one.
312 AnimatablePropertyMetadata* animatableProperty = GetSceneAnimatableProperty(index, &propertyValue);
313 if(!animatableProperty)
315 DALI_LOG_ERROR("Property index %d not found\n", index);
320 // update the cached property value
321 animatableProperty->SetPropertyValue(propertyValue);
323 // set the scene graph property value
324 SetSceneGraphProperty(index, *animatableProperty, propertyValue);
329 CustomPropertyMetadata* custom = FindCustomProperty(index);
331 if((index >= CHILD_PROPERTY_REGISTRATION_START_INDEX) && (index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX))
335 // If the child property is not registered yet, register it.
336 custom = new CustomPropertyMetadata({}, propertyValue, Property::READ_WRITE);
337 mCustomProperties.PushBack(custom);
340 custom->childPropertyIndex = index;
342 // Resolve name for the child property
343 Object* parent = GetParentObject();
346 const TypeInfo* parentTypeInfo(parent->GetTypeInfo());
349 custom->name = ConstString(parentTypeInfo->GetChildPropertyName(index));
356 if(custom->IsAnimatable())
358 // update the cached property value
359 custom->SetPropertyValue(propertyValue);
361 // set the scene graph property value
362 SetSceneGraphProperty(index, *custom, propertyValue);
364 else if(custom->IsWritable())
366 // update the cached property value
367 custom->SetPropertyValue(propertyValue);
371 // trying to set value on read only property is no-op
377 DALI_LOG_ERROR("Property index %d not found\n", index);
382 // Let derived classes know that a property has been set
383 // 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
386 OnPropertySet(index, propertyValue);
387 if(!mPropertySetSignal.Empty())
389 Dali::Handle handle(this);
390 mPropertySetSignal.Emit(handle, index, propertyValue);
395 Property::Value Object::GetProperty(Property::Index index) const
397 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
399 Property::Value value;
401 if(index < DEFAULT_PROPERTY_MAX_COUNT)
403 value = GetDefaultProperty(index);
405 else if((index >= PROPERTY_REGISTRATION_START_INDEX) && (index <= PROPERTY_REGISTRATION_MAX_INDEX))
407 const TypeInfo* typeInfo(GetTypeInfo());
410 value = typeInfo->GetProperty(this, index);
414 DALI_LOG_ERROR("Property index %d not found\n", index);
417 else if((index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX) && (index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX))
419 // check whether the animatable property is registered already, if not then register one.
420 // this is needed because property value may have been set as full property and get as a property component
421 AnimatablePropertyMetadata* animatableProperty = GetSceneAnimatableProperty(index, nullptr);
422 if(animatableProperty)
424 // get the cached animatable property value
425 value = animatableProperty->GetPropertyValue();
429 DALI_LOG_ERROR("Property index %d not found\n", index);
432 else if(mCustomProperties.Count() > 0)
434 CustomPropertyMetadata* custom = FindCustomProperty(index);
437 // get the cached custom property value
438 value = custom->GetPropertyValue();
442 DALI_LOG_ERROR("Property index %d not found\n", index);
449 Property::Value Object::GetCurrentProperty(Property::Index index) const
451 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
453 Property::Value value;
455 if(index < DEFAULT_PROPERTY_MAX_COUNT)
457 value = GetDefaultPropertyCurrentValue(index);
459 else if((index >= PROPERTY_REGISTRATION_START_INDEX) && (index <= PROPERTY_REGISTRATION_MAX_INDEX))
461 const TypeInfo* typeInfo(GetTypeInfo());
464 value = typeInfo->GetProperty(this, index);
468 DALI_LOG_ERROR("Property index %d not found\n", index);
471 else if((index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX) && (index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX))
473 // check whether the animatable property is registered already, if not then register one.
474 // this is needed because property value may have been set as full property and get as a property component
475 AnimatablePropertyMetadata* animatableProperty = GetSceneAnimatableProperty(index, nullptr);
476 if(animatableProperty)
478 // get the animatable property value
479 value = GetCurrentPropertyValue(*animatableProperty);
483 DALI_LOG_ERROR("Property index %d not found\n", index);
486 else if(mCustomProperties.Count() > 0)
488 CustomPropertyMetadata* custom = FindCustomProperty(index);
491 // get the custom property value
492 value = GetCurrentPropertyValue(*custom);
496 DALI_LOG_ERROR("Property index %d not found\n", index);
503 void Object::GetPropertyIndices(Property::IndexContainer& indices) const
508 const TypeInfo* typeInfo(GetTypeInfo());
511 typeInfo->GetPropertyIndices(indices);
515 if(mCustomProperties.Count() > 0)
517 indices.Reserve(indices.Size() + mCustomProperties.Count());
519 auto iter = mCustomProperties.Begin();
520 const auto endIter = mCustomProperties.End();
522 for(; iter != endIter; ++iter, ++i)
524 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(*iter);
525 if(custom->childPropertyIndex != Property::INVALID_INDEX)
527 // If it is a child property, add the child property index
528 indices.PushBack(custom->childPropertyIndex);
532 indices.PushBack(PROPERTY_CUSTOM_START_INDEX + i);
538 Property::Index Object::RegisterProperty(std::string_view name, Property::Value propertyValue)
540 return RegisterProperty(name, Property::INVALID_KEY, std::move(propertyValue), Property::ANIMATABLE);
543 Property::Index Object::RegisterProperty(std::string_view name, Property::Index key, Property::Value propertyValue)
545 return RegisterProperty(name, key, std::move(propertyValue), Property::ANIMATABLE);
548 void Object::SetProperties(const Property::Map& properties)
550 const auto count = properties.Count();
551 for(auto position = 0u; position < count; ++position)
553 // GetKeyAt and GetValue both return references which means no potential copying of maps/arrays.
554 // Iterating twice to get the value we want should still be fairly quick in a Property::Map.
556 const auto& key = properties.GetKeyAt(position);
557 const auto propertyIndex = (key.type == Property::Key::INDEX) ? key.indexKey : GetPropertyIndex(key);
559 if(propertyIndex != Property::INVALID_INDEX)
561 const auto& value = properties.GetValue(position);
562 SetProperty(propertyIndex, value);
567 void Object::GetProperties(Property::Map& properties)
571 Property::IndexContainer indexContainer;
572 GetPropertyIndices(indexContainer);
574 for(auto index : indexContainer)
576 properties[index] = GetProperty(index);
580 Property::Index Object::RegisterProperty(std::string_view name,
581 Property::Value propertyValue,
582 Property::AccessMode accessMode)
584 return RegisterProperty(name, Property::INVALID_KEY, std::move(propertyValue), accessMode);
587 Property::Index Object::RegisterProperty(std::string_view name,
589 Property::Value propertyValue,
590 Property::AccessMode accessMode)
592 auto constString = ConstString(name);
593 // If property with the required key already exists, then just set it.
594 Property::Index index = Property::INVALID_INDEX;
595 if(key != Property::INVALID_KEY) // Try integer key first if it's valid
597 index = GetPropertyIndex(key);
599 if(index == Property::INVALID_INDEX) // If it wasn't valid, or doesn't exist, try name
601 index = GetPropertyIndex(constString);
604 if(index != Property::INVALID_INDEX) // If there was a valid index found by either key, set it.
606 SetProperty(index, std::move(propertyValue));
610 // Otherwise register the property
611 if(Property::ANIMATABLE == accessMode)
613 index = RegisterSceneGraphProperty(
616 PROPERTY_CUSTOM_START_INDEX + static_cast<Property::Index>(mCustomProperties.Count()),
617 std::move(propertyValue));
618 AddUniformMapping(index, constString);
622 // Add entry to the property lookup
623 index = PROPERTY_CUSTOM_START_INDEX + static_cast<Property::Index>(mCustomProperties.Count());
625 CustomPropertyMetadata* customProperty =
626 new CustomPropertyMetadata(constString, std::move(propertyValue), accessMode);
628 // Resolve index for the child property
629 Object* parent = GetParentObject();
632 const TypeInfo* parentTypeInfo(parent->GetTypeInfo());
635 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex(customProperty->name);
636 if(childPropertyIndex != Property::INVALID_INDEX)
638 customProperty->childPropertyIndex = childPropertyIndex;
639 index = childPropertyIndex;
644 mCustomProperties.PushBack(customProperty);
651 bool Object::DoesCustomPropertyExist(Property::Index index)
653 auto metadata = FindCustomProperty(index);
654 return metadata != nullptr;
657 Dali::PropertyNotification Object::AddPropertyNotification(Property::Index index,
658 int32_t componentIndex,
659 const Dali::PropertyCondition& condition)
661 if(index >= DEFAULT_PROPERTY_MAX_COUNT)
663 if(index <= PROPERTY_REGISTRATION_MAX_INDEX)
665 DALI_ABORT("Property notification added to event side only property.");
667 else if((index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX) && (index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX))
669 // check whether the animatable property is registered already, if not then register one.
670 AnimatablePropertyMetadata* animatable = GetSceneAnimatableProperty(index, nullptr);
671 DALI_ASSERT_ALWAYS(animatable && "Property index is invalid");
673 else if(mCustomProperties.Count() > 0)
675 CustomPropertyMetadata* custom = FindCustomProperty(index);
676 DALI_ASSERT_ALWAYS(custom && "Invalid property index");
677 DALI_ASSERT_ALWAYS(custom->IsAnimatable() && "Property notification added to event side only property.");
681 Dali::Handle self(this);
682 Property target(self, index);
684 PropertyNotificationPtr internal = PropertyNotification::New(target, componentIndex, condition);
685 Dali::PropertyNotification propertyNotification(internal.Get());
687 if(!mPropertyNotifications)
689 mPropertyNotifications = new PropertyNotificationContainer;
691 mPropertyNotifications->push_back(propertyNotification);
693 return propertyNotification;
696 void Object::RemovePropertyNotification(Dali::PropertyNotification propertyNotification)
698 if(mPropertyNotifications)
700 auto iter = mPropertyNotifications->begin();
701 while(iter != mPropertyNotifications->end())
703 if(*iter == propertyNotification)
705 mPropertyNotifications->erase(iter);
706 // As we can't ensure all references are removed, we can just disable
708 GetImplementation(propertyNotification).Disable();
716 void Object::RemovePropertyNotifications()
718 if(mPropertyNotifications)
720 auto iter = mPropertyNotifications->begin();
721 while(iter != mPropertyNotifications->end())
723 // As we can't ensure all references are removed, we can just disable
725 GetImplementation(*iter).Disable();
729 mPropertyNotifications->clear();
733 void Object::NotifyPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType)
735 if(index < DEFAULT_PROPERTY_MAX_COUNT)
737 OnNotifyDefaultPropertyAnimation(animation, index, value, animationType);
741 PropertyMetadata* propertyMetadata = nullptr;
742 if((index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX) && (index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX))
744 propertyMetadata = FindAnimatableProperty(index);
748 CustomPropertyMetadata* custom = FindCustomProperty(index);
749 if(custom && custom->IsAnimatable())
751 propertyMetadata = custom;
757 switch(animationType)
760 case Animation::BETWEEN:
762 // Update the cached property value
763 propertyMetadata->SetPropertyValue(value);
768 // Adjust the cached property value
769 propertyMetadata->AdjustPropertyValueBy(value);
777 void Object::AddUniformMapping(Property::Index propertyIndex, ConstString uniformName) const
779 // Get the address of the property if it's a scene property
780 const PropertyInputImpl* propertyPtr = GetSceneObjectInputProperty(propertyIndex);
782 // Check instead for newly registered properties
783 if(propertyPtr == nullptr)
785 PropertyMetadata* animatable = FindAnimatableProperty(propertyIndex);
788 propertyPtr = animatable->GetSceneGraphProperty();
792 if(propertyPtr == nullptr)
794 PropertyMetadata* custom = FindCustomProperty(propertyIndex);
797 propertyPtr = custom->GetSceneGraphProperty();
803 const SceneGraph::PropertyOwner& sceneObject = GetSceneObject();
805 SceneGraph::UniformPropertyMapping map(uniformName, propertyPtr);
806 // Message takes ownership of Uniform map (and will delete it after copy)
807 AddUniformMapMessage(const_cast<EventThreadServices&>(GetEventThreadServices()), sceneObject, map);
811 void Object::RemoveUniformMapping(const std::string& uniformName) const
813 const SceneGraph::PropertyOwner& sceneObject = GetSceneObject();
814 RemoveUniformMapMessage(const_cast<EventThreadServices&>(GetEventThreadServices()), sceneObject, ConstString(uniformName));
817 void Object::ApplyConstraint(ConstraintBase& constraint)
821 mConstraints = new ConstraintContainer;
823 mConstraints->push_back(Dali::Constraint(&constraint));
826 void Object::RemoveConstraint(ConstraintBase& constraint)
828 // nullptr if the Constraint sources are destroyed before Constraint::Apply()
831 ConstraintIter it(std::find(mConstraints->begin(), mConstraints->end(), Dali::Constraint(&constraint)));
832 if(it != mConstraints->end())
834 mConstraints->erase(it);
839 void Object::RemoveConstraints()
841 // guard against constraint sending messages during core destruction
842 if(mConstraints && Stage::IsInstalled())
844 for(auto&& item : *mConstraints)
846 GetImplementation(item).RemoveInternal();
850 mConstraints = nullptr;
854 void Object::RemoveConstraints(uint32_t tag)
856 // guard against constraint sending messages during core destruction
857 if(mConstraints && Stage::IsInstalled())
859 auto iter(mConstraints->begin());
860 while(iter != mConstraints->end())
862 ConstraintBase& constraint = GetImplementation(*iter);
863 if(constraint.GetTag() == tag)
865 GetImplementation(*iter).RemoveInternal();
866 iter = mConstraints->erase(iter);
874 if(mConstraints->empty())
877 mConstraints = nullptr;
882 void Object::SetTypeInfo(const TypeInfo* typeInfo)
884 mTypeInfo = typeInfo;
887 const SceneGraph::PropertyOwner& Object::GetSceneObject() const
891 auto sceneObject = SceneGraph::PropertyOwner::New();
892 OwnerPointer<SceneGraph::PropertyOwner> transferOwnership(sceneObject);
893 mUpdateObject = sceneObject;
894 AddObjectMessage(const_cast<EventThreadServices&>(GetEventThreadServices()).GetUpdateManager(), transferOwnership);
896 DALI_ASSERT_DEBUG(mUpdateObject && "there must always be a scene object");
897 return *mUpdateObject;
900 const PropertyBase* Object::GetSceneObjectAnimatableProperty(Property::Index index) const
902 const SceneGraph::PropertyBase* property = nullptr;
903 if(index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX && index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX)
905 AnimatablePropertyMetadata* animatable = GetSceneAnimatableProperty(index, nullptr);
906 DALI_ASSERT_ALWAYS(animatable && "Property index is invalid");
908 property = animatable->GetSceneGraphProperty();
910 else if((index >= CHILD_PROPERTY_REGISTRATION_START_INDEX) && // Child properties are also stored as custom properties
911 (index <= PROPERTY_CUSTOM_MAX_INDEX))
913 CustomPropertyMetadata* custom = FindCustomProperty(index);
914 DALI_ASSERT_ALWAYS(custom && "Property index is invalid");
916 property = custom->GetSceneGraphProperty();
921 const PropertyInputImpl* Object::GetSceneObjectInputProperty(Property::Index index) const
923 // reuse animatable version as they are inputs as well
924 return GetSceneObjectAnimatableProperty(index);
927 int32_t Object::GetPropertyComponentIndex(Property::Index index) const
929 int32_t componentIndex = Property::INVALID_COMPONENT_INDEX;
931 if((index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX) && (index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX))
933 // check whether the animatable property is registered already, if not then register one.
934 AnimatablePropertyMetadata* animatableProperty = GetSceneAnimatableProperty(index, nullptr);
935 if(animatableProperty)
937 componentIndex = animatableProperty->componentIndex;
940 if(Property::INVALID_COMPONENT_INDEX == componentIndex)
942 const TypeInfo* typeInfo(GetTypeInfo());
945 componentIndex = typeInfo->GetComponentIndex(index);
949 return componentIndex;
952 Handle::PropertySetSignalType& Object::PropertySetSignal()
954 return mPropertySetSignal;
957 Object::Object(const SceneGraph::PropertyOwner* sceneObject)
958 : mEventThreadServices(EventThreadServices::Get()),
959 mUpdateObject(sceneObject),
961 mConstraints(nullptr),
962 mPropertyNotifications(nullptr)
968 // Notification for observers
969 for(auto&& item : mObservers)
971 item->ObjectDestroyed(*this);
974 // Disable property notifications in scene graph
975 DisablePropertyNotifications();
978 delete mPropertyNotifications;
980 // Guard to allow handle destruction after Core has been destroyed
981 if(Stage::IsInstalled())
983 if(nullptr != mUpdateObject)
985 RemoveObjectMessage(GetEventThreadServices().GetUpdateManager(), mUpdateObject);
990 void Object::OnSceneObjectAdd()
992 // Notification for observers
993 for(auto&& item : mObservers)
995 item->SceneObjectAdded(*this);
998 // enable property notifications in scene graph
999 EnablePropertyNotifications();
1002 void Object::OnSceneObjectRemove()
1004 // Notification for observers
1005 for(auto&& item : mObservers)
1007 item->SceneObjectRemoved(*this);
1010 // disable property notifications in scene graph
1011 DisablePropertyNotifications();
1014 const TypeInfo* Object::GetTypeInfo() const
1018 // This uses a dynamic_cast so can be quite expensive so we only really want to do it once
1019 // especially as the type-info does not change during the life-time of an application
1021 TypeRegistry::TypeInfoPointer typeInfoHandle = TypeRegistry::Get()->GetTypeInfo(this);
1024 mTypeInfo = typeInfoHandle.Get(); // just a raw pointer to use, ownership is kept
1031 CustomPropertyMetadata* Object::FindCustomProperty(Property::Index index) const
1033 CustomPropertyMetadata* property = nullptr;
1034 if((index >= CHILD_PROPERTY_REGISTRATION_START_INDEX) && (index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX))
1036 for(std::size_t arrayIndex = 0; arrayIndex < mCustomProperties.Count(); arrayIndex++)
1038 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(mCustomProperties[arrayIndex]);
1039 if(custom->childPropertyIndex == index)
1047 int32_t arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
1050 if(arrayIndex < static_cast<int32_t>(mCustomProperties.Count())) // we can only access the first 2 billion custom properties
1052 property = static_cast<CustomPropertyMetadata*>(mCustomProperties[arrayIndex]);
1059 AnimatablePropertyMetadata* Object::FindAnimatableProperty(Property::Index index) const
1061 for(auto&& entry : mAnimatableProperties)
1063 AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>(entry);
1064 if(property->index == index)
1072 Property::Index Object::RegisterSceneGraphProperty(ConstString name, Property::Index key, Property::Index index, Property::Value propertyValue) const
1074 // Create a new property
1075 Dali::Internal::OwnerPointer<PropertyBase> newProperty;
1077 switch(propertyValue.GetType())
1079 case Property::BOOLEAN:
1081 newProperty = new AnimatableProperty<bool>(propertyValue.Get<bool>());
1085 case Property::INTEGER:
1087 newProperty = new AnimatableProperty<int32_t>(propertyValue.Get<int32_t>());
1091 case Property::FLOAT:
1093 newProperty = new AnimatableProperty<float>(propertyValue.Get<float>());
1097 case Property::VECTOR2:
1099 newProperty = new AnimatableProperty<Vector2>(propertyValue.Get<Vector2>());
1103 case Property::VECTOR3:
1105 newProperty = new AnimatableProperty<Vector3>(propertyValue.Get<Vector3>());
1109 case Property::VECTOR4:
1111 newProperty = new AnimatableProperty<Vector4>(propertyValue.Get<Vector4>());
1115 case Property::MATRIX:
1117 newProperty = new AnimatableProperty<Matrix>(propertyValue.Get<Matrix>());
1121 case Property::MATRIX3:
1123 newProperty = new AnimatableProperty<Matrix3>(propertyValue.Get<Matrix3>());
1127 case Property::ROTATION:
1129 newProperty = new AnimatableProperty<Quaternion>(propertyValue.Get<Quaternion>());
1133 case Property::RECTANGLE:
1134 case Property::STRING:
1135 case Property::ARRAY:
1137 case Property::EXTENTS:
1138 case Property::NONE:
1140 DALI_ASSERT_ALWAYS(!"Property type is not animatable");
1145 // get the scene property owner
1146 const SceneGraph::PropertyOwner& scenePropertyOwner = GetSceneObject();
1147 // keep a local pointer to the property as the OwnerPointer will pass its copy to the message
1148 const PropertyBase* property = newProperty.Get();
1149 if(index >= PROPERTY_CUSTOM_START_INDEX)
1151 DALI_ASSERT_ALWAYS(index <= PROPERTY_CUSTOM_MAX_INDEX && "Too many custom properties have been registered");
1153 mCustomProperties.PushBack(new CustomPropertyMetadata(name, key, std::move(propertyValue), property));
1157 mAnimatableProperties.PushBack(new AnimatablePropertyMetadata(index, std::move(propertyValue), property));
1160 // queue a message to add the property
1161 InstallCustomPropertyMessage(const_cast<EventThreadServices&>(GetEventThreadServices()), scenePropertyOwner, newProperty); // Message takes ownership
1166 void Object::RegisterAnimatableProperty(const TypeInfo& typeInfo,
1167 Property::Index index,
1168 const Property::Value* value) const
1170 // If the property is not a component of a base property, register the whole property itself.
1171 auto propertyName = ConstString(typeInfo.GetPropertyName(index));
1172 Property::Value initialValue;
1175 initialValue = *value;
1179 initialValue = typeInfo.GetPropertyDefaultValue(index); // recurses type hierarchy
1180 if(Property::NONE == initialValue.GetType())
1182 initialValue = Property::Value(typeInfo.GetPropertyType(index)); // recurses type hierarchy
1185 RegisterSceneGraphProperty(propertyName, Property::INVALID_KEY, index, initialValue);
1186 AddUniformMapping(index, propertyName);
1189 AnimatablePropertyMetadata* Object::GetSceneAnimatableProperty(Property::Index index, const Property::Value* value) const
1191 // property range already checked by calling methods
1192 // check whether the animatable property is registered already, if not then register one.
1193 AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty(index);
1194 if(!animatableProperty)
1196 const TypeInfo* typeInfo(GetTypeInfo());
1199 Property::Index basePropertyIndex = typeInfo->GetBasePropertyIndex(index);
1200 if(basePropertyIndex == Property::INVALID_INDEX)
1202 // If the property is not a component of a base property, register the whole property itself.
1203 RegisterAnimatableProperty(*typeInfo, index, value);
1207 // Since the property is a component of a base property, check whether the base property is registered.
1208 animatableProperty = FindAnimatableProperty(basePropertyIndex);
1209 if(!animatableProperty)
1211 // If the base property is not registered yet, register the base property first.
1212 RegisterAnimatableProperty(*typeInfo, basePropertyIndex, value);
1213 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size() - 1]);
1216 // Create the metadata for the property component.
1217 mAnimatableProperties.PushBack(new AnimatablePropertyMetadata(index, typeInfo->GetComponentIndex(index), animatableProperty->value, animatableProperty->GetSceneGraphProperty()));
1220 // The metadata has just been added and therefore should be in the end of the vector.
1221 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size() - 1]);
1225 return animatableProperty;
1228 void Object::ResolveChildProperties()
1230 // Resolve index for the child property
1231 Object* parent = GetParentObject();
1234 const TypeInfo* parentTypeInfo(parent->GetTypeInfo());
1237 // Go through each custom property
1238 for(auto&& entry : mCustomProperties)
1240 CustomPropertyMetadata* customProperty = static_cast<CustomPropertyMetadata*>(entry);
1242 if(customProperty->name.IsEmpty())
1244 if(customProperty->childPropertyIndex != Property::INVALID_INDEX)
1246 // Resolve name for any child property with no name
1247 customProperty->name = ConstString(parentTypeInfo->GetChildPropertyName(customProperty->childPropertyIndex));
1252 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex(customProperty->name);
1253 if(childPropertyIndex != Property::INVALID_INDEX)
1255 // Resolve index for any property with a name that matches the parent's child property name
1256 customProperty->childPropertyIndex = childPropertyIndex;
1264 void Object::SetDefaultProperty(Property::Index index, const Property::Value& property)
1269 Property::Value Object::GetDefaultProperty(Property::Index index) const
1271 return Property::Value();
1274 Property::Value Object::GetDefaultPropertyCurrentValue(Property::Index index) const
1276 return GetDefaultProperty(index);
1279 void Object::EnablePropertyNotifications()
1281 if(mPropertyNotifications)
1283 for(auto&& element : *mPropertyNotifications)
1285 GetImplementation(element).Enable();
1290 void Object::DisablePropertyNotifications()
1292 if(mPropertyNotifications)
1294 for(auto&& element : *mPropertyNotifications)
1296 GetImplementation(element).Disable();
1301 Property::Value Object::GetCurrentPropertyValue(const PropertyMetadata& entry) const
1303 Property::Value value;
1305 if(!entry.IsAnimatable())
1307 value = entry.GetPropertyValue();
1311 BufferIndex bufferIndex(GetEventThreadServices().GetEventBufferIndex());
1313 switch(entry.GetType())
1315 case Property::BOOLEAN:
1317 const AnimatableProperty<bool>* property = static_cast<const AnimatableProperty<bool>*>(entry.GetSceneGraphProperty());
1318 DALI_ASSERT_DEBUG(property);
1320 value = (*property)[bufferIndex];
1324 case Property::INTEGER:
1326 const AnimatableProperty<int32_t>* property = static_cast<const AnimatableProperty<int32_t>*>(entry.GetSceneGraphProperty());
1327 DALI_ASSERT_DEBUG(property);
1329 value = (*property)[bufferIndex];
1333 case Property::FLOAT:
1335 const AnimatableProperty<float>* property = static_cast<const AnimatableProperty<float>*>(entry.GetSceneGraphProperty());
1336 DALI_ASSERT_DEBUG(property);
1338 value = (*property)[bufferIndex];
1342 case Property::VECTOR2:
1344 const AnimatableProperty<Vector2>* property = static_cast<const AnimatableProperty<Vector2>*>(entry.GetSceneGraphProperty());
1345 DALI_ASSERT_DEBUG(property);
1347 if(entry.componentIndex == 0)
1349 value = (*property)[bufferIndex].x;
1351 else if(entry.componentIndex == 1)
1353 value = (*property)[bufferIndex].y;
1357 value = (*property)[bufferIndex];
1362 case Property::VECTOR3:
1364 const AnimatableProperty<Vector3>* property = static_cast<const AnimatableProperty<Vector3>*>(entry.GetSceneGraphProperty());
1365 DALI_ASSERT_DEBUG(property);
1367 if(entry.componentIndex == 0)
1369 value = (*property)[bufferIndex].x;
1371 else if(entry.componentIndex == 1)
1373 value = (*property)[bufferIndex].y;
1375 else if(entry.componentIndex == 2)
1377 value = (*property)[bufferIndex].z;
1381 value = (*property)[bufferIndex];
1386 case Property::VECTOR4:
1388 const AnimatableProperty<Vector4>* property = static_cast<const AnimatableProperty<Vector4>*>(entry.GetSceneGraphProperty());
1389 DALI_ASSERT_DEBUG(property);
1391 if(entry.componentIndex == 0)
1393 value = (*property)[bufferIndex].x;
1395 else if(entry.componentIndex == 1)
1397 value = (*property)[bufferIndex].y;
1399 else if(entry.componentIndex == 2)
1401 value = (*property)[bufferIndex].z;
1403 else if(entry.componentIndex == 3)
1405 value = (*property)[bufferIndex].w;
1409 value = (*property)[bufferIndex];
1414 case Property::MATRIX:
1416 const AnimatableProperty<Matrix>* property = static_cast<const AnimatableProperty<Matrix>*>(entry.GetSceneGraphProperty());
1417 DALI_ASSERT_DEBUG(property);
1419 value = (*property)[bufferIndex];
1423 case Property::MATRIX3:
1425 const AnimatableProperty<Matrix3>* property = static_cast<const AnimatableProperty<Matrix3>*>(entry.GetSceneGraphProperty());
1426 DALI_ASSERT_DEBUG(property);
1428 value = (*property)[bufferIndex];
1432 case Property::ROTATION:
1434 const AnimatableProperty<Quaternion>* property = static_cast<const AnimatableProperty<Quaternion>*>(entry.GetSceneGraphProperty());
1435 DALI_ASSERT_DEBUG(property);
1437 value = (*property)[bufferIndex];
1443 // unreachable code due to higher level logic
1451 void Object::SetSceneGraphProperty(Property::Index index, const PropertyMetadata& entry, const Property::Value& value)
1453 switch(entry.GetType())
1455 case Property::BOOLEAN:
1457 const AnimatableProperty<bool>* property = dynamic_cast<const AnimatableProperty<bool>*>(entry.GetSceneGraphProperty());
1458 DALI_ASSERT_DEBUG(property);
1460 // property is being used in a separate thread; queue a message to set the property
1461 BakeMessage<bool>(GetEventThreadServices(), *property, value.Get<bool>());
1465 case Property::INTEGER:
1467 const AnimatableProperty<int32_t>* property = dynamic_cast<const AnimatableProperty<int32_t>*>(entry.GetSceneGraphProperty());
1468 DALI_ASSERT_DEBUG(property);
1470 // property is being used in a separate thread; queue a message to set the property
1471 BakeMessage<int32_t>(GetEventThreadServices(), *property, value.Get<int32_t>());
1475 case Property::FLOAT:
1477 const AnimatableProperty<float>* property = dynamic_cast<const AnimatableProperty<float>*>(entry.GetSceneGraphProperty());
1478 DALI_ASSERT_DEBUG(property);
1480 // property is being used in a separate thread; queue a message to set the property
1481 BakeMessage<float>(GetEventThreadServices(), *property, value.Get<float>());
1485 case Property::VECTOR2:
1487 const AnimatableProperty<Vector2>* property = dynamic_cast<const AnimatableProperty<Vector2>*>(entry.GetSceneGraphProperty());
1488 DALI_ASSERT_DEBUG(property);
1490 // property is being used in a separate thread; queue a message to set the property
1491 if(entry.componentIndex == 0)
1493 SetXComponentMessage<Vector2>(GetEventThreadServices(), *property, value.Get<float>());
1495 else if(entry.componentIndex == 1)
1497 SetYComponentMessage<Vector2>(GetEventThreadServices(), *property, value.Get<float>());
1501 BakeMessage<Vector2>(GetEventThreadServices(), *property, value.Get<Vector2>());
1506 case Property::VECTOR3:
1508 const AnimatableProperty<Vector3>* property = dynamic_cast<const AnimatableProperty<Vector3>*>(entry.GetSceneGraphProperty());
1509 DALI_ASSERT_DEBUG(property);
1511 // property is being used in a separate thread; queue a message to set the property
1512 if(entry.componentIndex == 0)
1514 SetXComponentMessage<Vector3>(GetEventThreadServices(), *property, value.Get<float>());
1516 else if(entry.componentIndex == 1)
1518 SetYComponentMessage<Vector3>(GetEventThreadServices(), *property, value.Get<float>());
1520 else if(entry.componentIndex == 2)
1522 SetZComponentMessage<Vector3>(GetEventThreadServices(), *property, value.Get<float>());
1526 BakeMessage<Vector3>(GetEventThreadServices(), *property, value.Get<Vector3>());
1532 case Property::VECTOR4:
1534 const AnimatableProperty<Vector4>* property = dynamic_cast<const AnimatableProperty<Vector4>*>(entry.GetSceneGraphProperty());
1535 DALI_ASSERT_DEBUG(property);
1537 // property is being used in a separate thread; queue a message to set the property
1538 if(entry.componentIndex == 0)
1540 SetXComponentMessage<Vector4>(GetEventThreadServices(), *property, value.Get<float>());
1542 else if(entry.componentIndex == 1)
1544 SetYComponentMessage<Vector4>(GetEventThreadServices(), *property, value.Get<float>());
1546 else if(entry.componentIndex == 2)
1548 SetZComponentMessage<Vector4>(GetEventThreadServices(), *property, value.Get<float>());
1550 else if(entry.componentIndex == 3)
1552 SetWComponentMessage<Vector4>(GetEventThreadServices(), *property, value.Get<float>());
1556 BakeMessage<Vector4>(GetEventThreadServices(), *property, value.Get<Vector4>());
1561 case Property::ROTATION:
1563 const AnimatableProperty<Quaternion>* property = dynamic_cast<const AnimatableProperty<Quaternion>*>(entry.GetSceneGraphProperty());
1564 DALI_ASSERT_DEBUG(property);
1566 // property is being used in a separate thread; queue a message to set the property
1567 BakeMessage<Quaternion>(GetEventThreadServices(), *property, value.Get<Quaternion>());
1571 case Property::MATRIX:
1573 const AnimatableProperty<Matrix>* property = dynamic_cast<const AnimatableProperty<Matrix>*>(entry.GetSceneGraphProperty());
1574 DALI_ASSERT_DEBUG(property);
1576 // property is being used in a separate thread; queue a message to set the property
1577 BakeMessage<Matrix>(GetEventThreadServices(), *property, value.Get<Matrix>());
1581 case Property::MATRIX3:
1583 const AnimatableProperty<Matrix3>* property = dynamic_cast<const AnimatableProperty<Matrix3>*>(entry.GetSceneGraphProperty());
1584 DALI_ASSERT_DEBUG(property);
1586 // property is being used in a separate thread; queue a message to set the property
1587 BakeMessage<Matrix3>(GetEventThreadServices(), *property, value.Get<Matrix3>());
1593 // non-animatable scene graph property, do nothing
1598 } // namespace Internal