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 delete mPropertyNotifications;
976 // Guard to allow handle destruction after Core has been destroyed
977 if(Stage::IsInstalled())
979 if(nullptr != mUpdateObject)
981 RemoveObjectMessage(GetEventThreadServices().GetUpdateManager(), mUpdateObject);
986 void Object::OnSceneObjectAdd()
988 // Notification for observers
989 for(auto&& item : mObservers)
991 item->SceneObjectAdded(*this);
994 // enable property notifications in scene graph
995 EnablePropertyNotifications();
998 void Object::OnSceneObjectRemove()
1000 // Notification for observers
1001 for(auto&& item : mObservers)
1003 item->SceneObjectRemoved(*this);
1006 // disable property notifications in scene graph
1007 DisablePropertyNotifications();
1010 const TypeInfo* Object::GetTypeInfo() const
1014 // This uses a dynamic_cast so can be quite expensive so we only really want to do it once
1015 // especially as the type-info does not change during the life-time of an application
1017 TypeRegistry::TypeInfoPointer typeInfoHandle = TypeRegistry::Get()->GetTypeInfo(this);
1020 mTypeInfo = typeInfoHandle.Get(); // just a raw pointer to use, ownership is kept
1027 CustomPropertyMetadata* Object::FindCustomProperty(Property::Index index) const
1029 CustomPropertyMetadata* property = nullptr;
1030 if((index >= CHILD_PROPERTY_REGISTRATION_START_INDEX) && (index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX))
1032 for(std::size_t arrayIndex = 0; arrayIndex < mCustomProperties.Count(); arrayIndex++)
1034 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(mCustomProperties[arrayIndex]);
1035 if(custom->childPropertyIndex == index)
1043 int32_t arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
1046 if(arrayIndex < static_cast<int32_t>(mCustomProperties.Count())) // we can only access the first 2 billion custom properties
1048 property = static_cast<CustomPropertyMetadata*>(mCustomProperties[arrayIndex]);
1055 AnimatablePropertyMetadata* Object::FindAnimatableProperty(Property::Index index) const
1057 for(auto&& entry : mAnimatableProperties)
1059 AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>(entry);
1060 if(property->index == index)
1068 Property::Index Object::RegisterSceneGraphProperty(ConstString name, Property::Index key, Property::Index index, Property::Value propertyValue) const
1070 // Create a new property
1071 Dali::Internal::OwnerPointer<PropertyBase> newProperty;
1073 switch(propertyValue.GetType())
1075 case Property::BOOLEAN:
1077 newProperty = new AnimatableProperty<bool>(propertyValue.Get<bool>());
1081 case Property::INTEGER:
1083 newProperty = new AnimatableProperty<int32_t>(propertyValue.Get<int32_t>());
1087 case Property::FLOAT:
1089 newProperty = new AnimatableProperty<float>(propertyValue.Get<float>());
1093 case Property::VECTOR2:
1095 newProperty = new AnimatableProperty<Vector2>(propertyValue.Get<Vector2>());
1099 case Property::VECTOR3:
1101 newProperty = new AnimatableProperty<Vector3>(propertyValue.Get<Vector3>());
1105 case Property::VECTOR4:
1107 newProperty = new AnimatableProperty<Vector4>(propertyValue.Get<Vector4>());
1111 case Property::MATRIX:
1113 newProperty = new AnimatableProperty<Matrix>(propertyValue.Get<Matrix>());
1117 case Property::MATRIX3:
1119 newProperty = new AnimatableProperty<Matrix3>(propertyValue.Get<Matrix3>());
1123 case Property::ROTATION:
1125 newProperty = new AnimatableProperty<Quaternion>(propertyValue.Get<Quaternion>());
1129 case Property::RECTANGLE:
1130 case Property::STRING:
1131 case Property::ARRAY:
1133 case Property::EXTENTS:
1134 case Property::NONE:
1136 DALI_ASSERT_ALWAYS(!"Property type is not animatable");
1141 // get the scene property owner
1142 const SceneGraph::PropertyOwner& scenePropertyOwner = GetSceneObject();
1143 // keep a local pointer to the property as the OwnerPointer will pass its copy to the message
1144 const PropertyBase* property = newProperty.Get();
1145 if(index >= PROPERTY_CUSTOM_START_INDEX)
1147 DALI_ASSERT_ALWAYS(index <= PROPERTY_CUSTOM_MAX_INDEX && "Too many custom properties have been registered");
1149 mCustomProperties.PushBack(new CustomPropertyMetadata(name, key, std::move(propertyValue), property));
1153 mAnimatableProperties.PushBack(new AnimatablePropertyMetadata(index, std::move(propertyValue), property));
1156 // queue a message to add the property
1157 InstallCustomPropertyMessage(const_cast<EventThreadServices&>(GetEventThreadServices()), scenePropertyOwner, newProperty); // Message takes ownership
1162 void Object::RegisterAnimatableProperty(const TypeInfo& typeInfo,
1163 Property::Index index,
1164 const Property::Value* value) const
1166 // If the property is not a component of a base property, register the whole property itself.
1167 auto propertyName = ConstString(typeInfo.GetPropertyName(index));
1168 Property::Value initialValue;
1171 initialValue = *value;
1175 initialValue = typeInfo.GetPropertyDefaultValue(index); // recurses type hierarchy
1176 if(Property::NONE == initialValue.GetType())
1178 initialValue = Property::Value(typeInfo.GetPropertyType(index)); // recurses type hierarchy
1181 RegisterSceneGraphProperty(propertyName, Property::INVALID_KEY, index, initialValue);
1182 AddUniformMapping(index, propertyName);
1185 AnimatablePropertyMetadata* Object::GetSceneAnimatableProperty(Property::Index index, const Property::Value* value) const
1187 // property range already checked by calling methods
1188 // check whether the animatable property is registered already, if not then register one.
1189 AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty(index);
1190 if(!animatableProperty)
1192 const TypeInfo* typeInfo(GetTypeInfo());
1195 Property::Index basePropertyIndex = typeInfo->GetBasePropertyIndex(index);
1196 if(basePropertyIndex == Property::INVALID_INDEX)
1198 // If the property is not a component of a base property, register the whole property itself.
1199 RegisterAnimatableProperty(*typeInfo, index, value);
1203 // Since the property is a component of a base property, check whether the base property is registered.
1204 animatableProperty = FindAnimatableProperty(basePropertyIndex);
1205 if(!animatableProperty)
1207 // If the base property is not registered yet, register the base property first.
1208 RegisterAnimatableProperty(*typeInfo, basePropertyIndex, value);
1209 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size() - 1]);
1212 // Create the metadata for the property component.
1213 mAnimatableProperties.PushBack(new AnimatablePropertyMetadata(index, typeInfo->GetComponentIndex(index), animatableProperty->value, animatableProperty->GetSceneGraphProperty()));
1216 // The metadata has just been added and therefore should be in the end of the vector.
1217 animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size() - 1]);
1221 return animatableProperty;
1224 void Object::ResolveChildProperties()
1226 // Resolve index for the child property
1227 Object* parent = GetParentObject();
1230 const TypeInfo* parentTypeInfo(parent->GetTypeInfo());
1233 // Go through each custom property
1234 for(auto&& entry : mCustomProperties)
1236 CustomPropertyMetadata* customProperty = static_cast<CustomPropertyMetadata*>(entry);
1238 if(customProperty->name.IsEmpty())
1240 if(customProperty->childPropertyIndex != Property::INVALID_INDEX)
1242 // Resolve name for any child property with no name
1243 customProperty->name = ConstString(parentTypeInfo->GetChildPropertyName(customProperty->childPropertyIndex));
1248 Property::Index childPropertyIndex = parentTypeInfo->GetChildPropertyIndex(customProperty->name);
1249 if(childPropertyIndex != Property::INVALID_INDEX)
1251 // Resolve index for any property with a name that matches the parent's child property name
1252 customProperty->childPropertyIndex = childPropertyIndex;
1260 void Object::SetDefaultProperty(Property::Index index, const Property::Value& property)
1265 Property::Value Object::GetDefaultProperty(Property::Index index) const
1267 return Property::Value();
1270 Property::Value Object::GetDefaultPropertyCurrentValue(Property::Index index) const
1272 return GetDefaultProperty(index);
1275 void Object::EnablePropertyNotifications()
1277 if(mPropertyNotifications)
1279 for(auto&& element : *mPropertyNotifications)
1281 GetImplementation(element).Enable();
1286 void Object::DisablePropertyNotifications()
1288 if(mPropertyNotifications)
1290 for(auto&& element : *mPropertyNotifications)
1292 GetImplementation(element).Disable();
1297 Property::Value Object::GetCurrentPropertyValue(const PropertyMetadata& entry) const
1299 Property::Value value;
1301 if(!entry.IsAnimatable())
1303 value = entry.GetPropertyValue();
1307 BufferIndex bufferIndex(GetEventThreadServices().GetEventBufferIndex());
1309 switch(entry.GetType())
1311 case Property::BOOLEAN:
1313 const AnimatableProperty<bool>* property = static_cast<const AnimatableProperty<bool>*>(entry.GetSceneGraphProperty());
1314 DALI_ASSERT_DEBUG(property);
1316 value = (*property)[bufferIndex];
1320 case Property::INTEGER:
1322 const AnimatableProperty<int32_t>* property = static_cast<const AnimatableProperty<int32_t>*>(entry.GetSceneGraphProperty());
1323 DALI_ASSERT_DEBUG(property);
1325 value = (*property)[bufferIndex];
1329 case Property::FLOAT:
1331 const AnimatableProperty<float>* property = static_cast<const AnimatableProperty<float>*>(entry.GetSceneGraphProperty());
1332 DALI_ASSERT_DEBUG(property);
1334 value = (*property)[bufferIndex];
1338 case Property::VECTOR2:
1340 const AnimatableProperty<Vector2>* property = static_cast<const AnimatableProperty<Vector2>*>(entry.GetSceneGraphProperty());
1341 DALI_ASSERT_DEBUG(property);
1343 if(entry.componentIndex == 0)
1345 value = (*property)[bufferIndex].x;
1347 else if(entry.componentIndex == 1)
1349 value = (*property)[bufferIndex].y;
1353 value = (*property)[bufferIndex];
1358 case Property::VECTOR3:
1360 const AnimatableProperty<Vector3>* property = static_cast<const AnimatableProperty<Vector3>*>(entry.GetSceneGraphProperty());
1361 DALI_ASSERT_DEBUG(property);
1363 if(entry.componentIndex == 0)
1365 value = (*property)[bufferIndex].x;
1367 else if(entry.componentIndex == 1)
1369 value = (*property)[bufferIndex].y;
1371 else if(entry.componentIndex == 2)
1373 value = (*property)[bufferIndex].z;
1377 value = (*property)[bufferIndex];
1382 case Property::VECTOR4:
1384 const AnimatableProperty<Vector4>* property = static_cast<const AnimatableProperty<Vector4>*>(entry.GetSceneGraphProperty());
1385 DALI_ASSERT_DEBUG(property);
1387 if(entry.componentIndex == 0)
1389 value = (*property)[bufferIndex].x;
1391 else if(entry.componentIndex == 1)
1393 value = (*property)[bufferIndex].y;
1395 else if(entry.componentIndex == 2)
1397 value = (*property)[bufferIndex].z;
1399 else if(entry.componentIndex == 3)
1401 value = (*property)[bufferIndex].w;
1405 value = (*property)[bufferIndex];
1410 case Property::MATRIX:
1412 const AnimatableProperty<Matrix>* property = static_cast<const AnimatableProperty<Matrix>*>(entry.GetSceneGraphProperty());
1413 DALI_ASSERT_DEBUG(property);
1415 value = (*property)[bufferIndex];
1419 case Property::MATRIX3:
1421 const AnimatableProperty<Matrix3>* property = static_cast<const AnimatableProperty<Matrix3>*>(entry.GetSceneGraphProperty());
1422 DALI_ASSERT_DEBUG(property);
1424 value = (*property)[bufferIndex];
1428 case Property::ROTATION:
1430 const AnimatableProperty<Quaternion>* property = static_cast<const AnimatableProperty<Quaternion>*>(entry.GetSceneGraphProperty());
1431 DALI_ASSERT_DEBUG(property);
1433 value = (*property)[bufferIndex];
1439 // unreachable code due to higher level logic
1447 void Object::SetSceneGraphProperty(Property::Index index, const PropertyMetadata& entry, const Property::Value& value)
1449 switch(entry.GetType())
1451 case Property::BOOLEAN:
1453 const AnimatableProperty<bool>* property = dynamic_cast<const AnimatableProperty<bool>*>(entry.GetSceneGraphProperty());
1454 DALI_ASSERT_DEBUG(property);
1456 // property is being used in a separate thread; queue a message to set the property
1457 BakeMessage<bool>(GetEventThreadServices(), *property, value.Get<bool>());
1461 case Property::INTEGER:
1463 const AnimatableProperty<int32_t>* property = dynamic_cast<const AnimatableProperty<int32_t>*>(entry.GetSceneGraphProperty());
1464 DALI_ASSERT_DEBUG(property);
1466 // property is being used in a separate thread; queue a message to set the property
1467 BakeMessage<int32_t>(GetEventThreadServices(), *property, value.Get<int32_t>());
1471 case Property::FLOAT:
1473 const AnimatableProperty<float>* property = dynamic_cast<const AnimatableProperty<float>*>(entry.GetSceneGraphProperty());
1474 DALI_ASSERT_DEBUG(property);
1476 // property is being used in a separate thread; queue a message to set the property
1477 BakeMessage<float>(GetEventThreadServices(), *property, value.Get<float>());
1481 case Property::VECTOR2:
1483 const AnimatableProperty<Vector2>* property = dynamic_cast<const AnimatableProperty<Vector2>*>(entry.GetSceneGraphProperty());
1484 DALI_ASSERT_DEBUG(property);
1486 // property is being used in a separate thread; queue a message to set the property
1487 if(entry.componentIndex == 0)
1489 SetXComponentMessage<Vector2>(GetEventThreadServices(), *property, value.Get<float>());
1491 else if(entry.componentIndex == 1)
1493 SetYComponentMessage<Vector2>(GetEventThreadServices(), *property, value.Get<float>());
1497 BakeMessage<Vector2>(GetEventThreadServices(), *property, value.Get<Vector2>());
1502 case Property::VECTOR3:
1504 const AnimatableProperty<Vector3>* property = dynamic_cast<const AnimatableProperty<Vector3>*>(entry.GetSceneGraphProperty());
1505 DALI_ASSERT_DEBUG(property);
1507 // property is being used in a separate thread; queue a message to set the property
1508 if(entry.componentIndex == 0)
1510 SetXComponentMessage<Vector3>(GetEventThreadServices(), *property, value.Get<float>());
1512 else if(entry.componentIndex == 1)
1514 SetYComponentMessage<Vector3>(GetEventThreadServices(), *property, value.Get<float>());
1516 else if(entry.componentIndex == 2)
1518 SetZComponentMessage<Vector3>(GetEventThreadServices(), *property, value.Get<float>());
1522 BakeMessage<Vector3>(GetEventThreadServices(), *property, value.Get<Vector3>());
1528 case Property::VECTOR4:
1530 const AnimatableProperty<Vector4>* property = dynamic_cast<const AnimatableProperty<Vector4>*>(entry.GetSceneGraphProperty());
1531 DALI_ASSERT_DEBUG(property);
1533 // property is being used in a separate thread; queue a message to set the property
1534 if(entry.componentIndex == 0)
1536 SetXComponentMessage<Vector4>(GetEventThreadServices(), *property, value.Get<float>());
1538 else if(entry.componentIndex == 1)
1540 SetYComponentMessage<Vector4>(GetEventThreadServices(), *property, value.Get<float>());
1542 else if(entry.componentIndex == 2)
1544 SetZComponentMessage<Vector4>(GetEventThreadServices(), *property, value.Get<float>());
1546 else if(entry.componentIndex == 3)
1548 SetWComponentMessage<Vector4>(GetEventThreadServices(), *property, value.Get<float>());
1552 BakeMessage<Vector4>(GetEventThreadServices(), *property, value.Get<Vector4>());
1557 case Property::ROTATION:
1559 const AnimatableProperty<Quaternion>* property = dynamic_cast<const AnimatableProperty<Quaternion>*>(entry.GetSceneGraphProperty());
1560 DALI_ASSERT_DEBUG(property);
1562 // property is being used in a separate thread; queue a message to set the property
1563 BakeMessage<Quaternion>(GetEventThreadServices(), *property, value.Get<Quaternion>());
1567 case Property::MATRIX:
1569 const AnimatableProperty<Matrix>* property = dynamic_cast<const AnimatableProperty<Matrix>*>(entry.GetSceneGraphProperty());
1570 DALI_ASSERT_DEBUG(property);
1572 // property is being used in a separate thread; queue a message to set the property
1573 BakeMessage<Matrix>(GetEventThreadServices(), *property, value.Get<Matrix>());
1577 case Property::MATRIX3:
1579 const AnimatableProperty<Matrix3>* property = dynamic_cast<const AnimatableProperty<Matrix3>*>(entry.GetSceneGraphProperty());
1580 DALI_ASSERT_DEBUG(property);
1582 // property is being used in a separate thread; queue a message to set the property
1583 BakeMessage<Matrix3>(GetEventThreadServices(), *property, value.Get<Matrix3>());
1589 // non-animatable scene graph property, do nothing
1594 } // namespace Internal