-#ifndef __DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H__
+#ifndef DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H
+#define DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
// INTERNAL INCLUDES
-#include <dali/public-api/common/dali-common.h>
-#include <dali/public-api/signals/callback.h>
#include <dali/internal/event/animation/property-constraint-ptr.h>
+#include <dali/internal/render/common/performance-monitor.h>
+#include <dali/internal/update/animation/scene-graph-constraint-base.h>
#include <dali/internal/update/common/animatable-property.h>
#include <dali/internal/update/common/property-owner.h>
-#include <dali/internal/update/animation/scene-graph-constraint-base.h>
-#include <dali/internal/render/common/performance-monitor.h>
+#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/signals/callback.h>
namespace Dali
{
-
namespace Internal
{
-
namespace SceneGraph
{
-
/**
* Used to constrain a property of a scene-object.
* The constraint function takes another scene-object property as an input.
*/
-template < class PropertyType, typename PropertyAccessorType >
+template<class PropertyType, typename PropertyAccessorType>
class Constraint : public ConstraintBase
{
public:
-
- typedef typename PropertyConstraintPtr< PropertyType >::Type ConstraintFunctionPtr;
+ using ConstraintFunctionPtr = typename PropertyConstraintPtr<PropertyType>::Type;
/**
* Create a new scene-graph constraint.
* @param[in] targetProperty The target property.
* @param[in] ownerSet A set of property owners; func is connected to the properties provided by these objects.
* @param[in] func The function to calculate the final constrained value.
+ * @param[in] removeAction Remove action to perform when constraint is removed
* @return A smart-pointer to a newly allocated constraint.
*/
- static ConstraintBase* New( const PropertyBase& targetProperty,
- PropertyOwnerContainer& ownerContainer,
- ConstraintFunctionPtr func )
+ static ConstraintBase* New(const PropertyBase& targetProperty,
+ PropertyOwnerContainer& ownerContainer,
+ ConstraintFunctionPtr func,
+ RemoveAction removeAction)
{
// Scene-graph thread can edit these objects
- PropertyBase& property = const_cast< PropertyBase& >( targetProperty );
+ PropertyBase& property = const_cast<PropertyBase&>(targetProperty);
- return new Constraint< PropertyType, PropertyAccessorType >( property,
- ownerContainer,
- func );
+ return new Constraint<PropertyType, PropertyAccessorType>(property,
+ ownerContainer,
+ func,
+ removeAction);
}
/**
* Virtual destructor.
*/
- virtual ~Constraint()
- {
- }
-
- /**
- * Query whether the constraint needs to be applied. If a constraint depends on a set of properties,
- * then it should be applied when any of those properties have changed.
- */
- bool ApplyNeeded()
- {
- if ( mFirstApply )
- {
- mFirstApply = false;
- return true;
- }
-
- if ( ! mTargetProperty.IsClean() ||
- mFunc->InputsChanged() )
- {
- return true;
- }
-
- // We don't need to reapply constraint if none of the properties changed
- return false;
- }
+ ~Constraint() override = default;
/**
* @copydoc Dali::Internal::SceneGraph::ConstraintBase::Apply()
*/
- virtual void Apply( BufferIndex updateBufferIndex )
+ void Apply(BufferIndex updateBufferIndex) override
{
- if ( mDisconnected )
- {
- return; // Early-out when property owners have been disconnected
- }
-
- if ( mFunc->InputsInitialized() &&
- ApplyNeeded() )
+ if(!mDisconnected)
{
- PropertyType current = mTargetProperty.Get( updateBufferIndex );
- mFunc->Apply( updateBufferIndex, current );
-
- // Optionally bake the final value
- if ( Dali::Constraint::Bake == mRemoveAction )
+ if(mFunc->InputsInitialized())
{
- mTargetProperty.Bake( updateBufferIndex, current );
+ PropertyType current = mTargetProperty.Get(updateBufferIndex);
+ PropertyType old = mTargetProperty.Get(!updateBufferIndex);
+
+ mFunc->Apply(updateBufferIndex, current);
+
+ // Compare with value of the previous frame
+ if constexpr(std::is_same_v<PropertyType, float>)
+ {
+ if(!Equals(old, current))
+ {
+ if(!mObservedOwners.Empty())
+ {
+ // The first observer is the target of the constraint
+ mObservedOwners[0]->SetUpdated(true);
+ }
+ }
+ }
+ else
+ {
+ if(old != current)
+ {
+ if(!mObservedOwners.Empty())
+ {
+ // The first observer is the target of the constraint
+ mObservedOwners[0]->SetUpdated(true);
+ }
+ }
+ }
+
+ // Optionally bake the final value
+ if(Dali::Constraint::BAKE == mRemoveAction)
+ {
+ mTargetProperty.Bake(updateBufferIndex, current);
+ }
+ else
+ {
+ mTargetProperty.Set(updateBufferIndex, current);
+ }
+
+ INCREASE_COUNTER(PerformanceMonitor::CONSTRAINTS_APPLIED);
}
else
{
- mTargetProperty.Set( updateBufferIndex, current );
+ INCREASE_COUNTER(PerformanceMonitor::CONSTRAINTS_SKIPPED);
}
-
- INCREASE_COUNTER(PerformanceMonitor::CONSTRAINTS_APPLIED);
- }
- else
- {
- INCREASE_COUNTER(PerformanceMonitor::CONSTRAINTS_SKIPPED);
}
}
private:
-
/**
* @copydoc Dali::Internal::SceneGraph::Constraint::New()
*/
- Constraint( PropertyBase& targetProperty,
- PropertyOwnerContainer& ownerContainer,
- ConstraintFunctionPtr func )
- : ConstraintBase( ownerContainer ),
- mTargetProperty( &targetProperty ),
- mFunc( func )
+ Constraint(PropertyBase& targetProperty,
+ PropertyOwnerContainer& ownerContainer,
+ ConstraintFunctionPtr func,
+ RemoveAction removeAction)
+ : ConstraintBase(ownerContainer, removeAction),
+ mTargetProperty(&targetProperty),
+ mFunc(func)
{
}
// Undefined
- Constraint( const Constraint& constraint );
-
- // Undefined
- Constraint& operator=( const Constraint& rhs );
+ Constraint() = delete;
+ Constraint(const Constraint& constraint) = delete;
+ Constraint& operator=(const Constraint& rhs) = delete;
/**
* @copydoc Dali::Internal::SceneGraph::ConstraintBase::OnDisconnect()
*/
- virtual void OnDisconnect()
+ void OnDisconnect() override
{
// Discard target object/property pointers
mTargetProperty.Reset();
- mFunc = NULL;
+ mFunc = nullptr;
}
protected:
-
PropertyAccessorType mTargetProperty; ///< Raw-pointer to the target property. Not owned.
ConstraintFunctionPtr mFunc;
} // namespace Dali
-#endif // __DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H__
+#endif // DALI_INTERNAL_SCENE_GRAPH_CONSTRAINT_H