X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fcommon%2Fobject-impl.h;h=d66eb9e38c3282229eb27ff06700771677ef7469;hb=4bfc1d5f237df92a26659d0f55a0c451b59bc2e4;hp=10983a8144d6dc7ee4854b3804fa2d178c2d71e9;hpb=636f590a184a1596846591fb798917d8d8de8bba;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/common/object-impl.h b/dali/internal/event/common/object-impl.h index 10983a8..d66eb9e 100644 --- a/dali/internal/event/common/object-impl.h +++ b/dali/internal/event/common/object-impl.h @@ -1,8 +1,8 @@ -#ifndef __DALI_INTERNAL_OBJECT_H__ -#define __DALI_INTERNAL_OBJECT_H__ +#ifndef DALI_INTERNAL_OBJECT_H +#define DALI_INTERNAL_OBJECT_H /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 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. @@ -18,20 +18,26 @@ * */ +// EXTERNAL INCLUDES +#include // uint32_t + // INTERNAL INCLUDES -#include #include #include #include #include #include #include +#include #include +#include #include -#include -#include -#include +#include +#include +#include +#include #include +#include #include namespace Dali @@ -41,8 +47,8 @@ class PropertyNotification; namespace Internal { -class Constraint; -class Handle; +class ConstraintBase; +class EventThreadServices; class PropertyCondition; class PropertyInputImpl; class Stage; @@ -54,9 +60,9 @@ class PropertyBase; class PropertyOwner; } -typedef std::vector< Dali::ActiveConstraint > ActiveConstraintContainer; -typedef ActiveConstraintContainer::iterator ActiveConstraintIter; -typedef ActiveConstraintContainer::const_iterator ActiveConstraintConstIter; +using ConstraintContainer = std::vector< Dali::Constraint >; +using ConstraintIter = ConstraintContainer::iterator; +using ConstraintConstIter = ConstraintContainer::const_iterator; /** * A base class for objects which optionally provide properties. @@ -66,19 +72,15 @@ typedef ActiveConstraintContainer::const_iterator ActiveConstraintConstIter; * An object for a property-owning object in the scene-graph. * This provides an interface for observing the addition/removal of scene-objects. * - * The concrete derived class is responsible for: - * 1) Adding & removing an object from the scene-graph. The OnSceneObjectAdd() and OnSceneObjectRemove() - * methods should be called by the derived class, to trigger observer callbacks. - * 3) Implementing the GetSceneObject() methods, used to access the scene-object. - * 4) Providing access to properties stored by the scene-graph object. These should match the properties - * reported by the base Dali::Internal::Object methods. - * + * The derived class should either: + * a) Create their own scene-graph object and pass it to Object constructor. + * b) pass nullptr to Object constructor, in this case Object will create default scene object for property handling */ class Object : public Dali::BaseObject { public: - typedef Dali::Handle::Capability Capability; + using Capability = Dali::Handle::Capability; class Observer { @@ -111,125 +113,189 @@ public: }; /** - * Constructor. + * Creates a new object + * + * @return an smart pointer to the object */ - Object(); + static IntrusivePtr New(); /** * Add an observer to the object. * @param[in] observer The observer to add. */ - virtual void AddObserver( Observer& observer ); + void AddObserver( Observer& observer ); /** * Remove an observer from the object * @pre The observer has already been added. * @param[in] observer The observer to remove. */ - virtual void RemoveObserver( Observer& observer ); + void RemoveObserver( Observer& observer ); /** * @copydoc Dali::Handle::Supports() */ - virtual bool Supports( Capability capability ) const; + bool Supports( Capability capability ) const; /** * @copydoc Dali::Handle::GetPropertyCount() */ - virtual unsigned int GetPropertyCount() const; + uint32_t GetPropertyCount() const; /** * @copydoc Dali::Handle::GetPropertyName() */ - virtual std::string GetPropertyName( Property::Index index ) const; + std::string GetPropertyName( Property::Index index ) const; + + /** + * @copydoc Dali::Handle::GetPropertyIndex() + */ + Property::Index GetPropertyIndex( const std::string& name ) const; /** * @copydoc Dali::Handle::GetPropertyIndex() */ - virtual Property::Index GetPropertyIndex( const std::string& name ) const; + Property::Index GetPropertyIndex( Property::Index key ) const; + + /** + * @copydoc Dali::Handle::GetPropertyIndex() + */ + Property::Index GetPropertyIndex( Property::Key key ) const; /** * @copydoc Dali::Handle::IsPropertyWritable() */ - virtual bool IsPropertyWritable( Property::Index index ) const; + bool IsPropertyWritable( Property::Index index ) const; /** * @copydoc Dali::Handle::IsPropertyAnimatable() */ - virtual bool IsPropertyAnimatable( Property::Index index ) const; + bool IsPropertyAnimatable( Property::Index index ) const; /** * @copydoc Dali::Handle::IsPropertyAConstraintInput() */ - virtual bool IsPropertyAConstraintInput( Property::Index index ) const; + bool IsPropertyAConstraintInput( Property::Index index ) const; /** * @copydoc Dali::Handle::GetPropertyType() */ - virtual Property::Type GetPropertyType( Property::Index index ) const; + Property::Type GetPropertyType( Property::Index index ) const; /** * @copydoc Dali::Handle::SetProperty() */ - virtual void SetProperty( Property::Index index, const Property::Value& propertyValue ); + void SetProperty( Property::Index index, const Property::Value& propertyValue ); /** * @copydoc Dali::Handle::GetProperty() */ - virtual Property::Value GetProperty( Property::Index index ) const; + Property::Value GetProperty( Property::Index index ) const; + + /** + * @brief Retrieves the latest value of the property on the scene-graph. + * @param[in] index The index of the property required. + * @return The latest value of the property on the scene-graph. + */ + Property::Value GetCurrentProperty( Property::Index index ) const; /** * @copydoc Dali::Handle::GetPropertyIndices() */ - virtual void GetPropertyIndices( Property::IndexContainer& indices ) const; + void GetPropertyIndices( Property::IndexContainer& indices ) const; + + /** + * @copydoc Dali::Handle::RegisterProperty() + */ + Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue ); /** * @copydoc Dali::Handle::RegisterProperty() */ - virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue ); + Property::Index RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue ); + + /** + * @copydoc Dali::DevelHandle::SetProperties() + */ + void SetProperties( const Property::Map& properties ); /** * @copydoc Dali::Handle::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode) */ - virtual Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode ); + Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode ); + + /** + * @brief Implementing method for this override + */ + Property::Index RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue, Property::AccessMode accessMode ); + + /** + * @brief returns true if the custom property exists on this object. + * + * @note The property may be defined for a type within the type registry, but it isn't explicity + * defined in every consequent instantiation. It can be automatically added, e.g. parenting an actor + * automatically registers it's parent container's child properties. + * + * @param[in] handle The handle of the object to test + * @param[in] index The property index to look for. + * @return true if the property exists on the object, false otherwise. + */ + bool DoesCustomPropertyExist( Property::Index index ); /** * @copydoc Dali::Handle::AddPropertyNotification() */ - virtual Dali::PropertyNotification AddPropertyNotification( Property::Index index, - int componentIndex, - const Dali::PropertyCondition& condition ); + Dali::PropertyNotification AddPropertyNotification( Property::Index index, + int32_t componentIndex, + const Dali::PropertyCondition& condition ); /** * @copydoc Dali::Handle::RemovePropertyNotification() */ - virtual void RemovePropertyNotification( Dali::PropertyNotification propertyNotification ); + void RemovePropertyNotification( Dali::PropertyNotification propertyNotification ); /** * @copydoc Dali::Handle::RemovePropertyNotifications() */ - virtual void RemovePropertyNotifications(); + void RemovePropertyNotifications(); - // Constraints + /** + * Notifies that a property is being animated. + * @param[in] animation The animation animating the property. + * @param[in] index The index of the property. + * @param[in] value The value of the property after the animation. + * @param[in] animationType Whether the property value given is the target or a relative value. + */ + void NotifyPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType ); + + /******************************** Uniform Mappings ********************************/ /** - * Apply a constraint to a Object. - * @param[in] constraint The constraint to apply. + * Adds uniform mapping for given property + * @param propertyIndex index of the property + * @param uniformName name of the uniform (same as property name) + */ + void AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const; + + /** + * Removes uniform mapping for given property + * @param uniformName name of the uniform (same as property name) */ - Dali::ActiveConstraint ApplyConstraint( Constraint& constraint ); + void RemoveUniformMapping( const std::string& uniformName ) const; + + /******************************** Constraints ********************************/ /** - * Apply a constraint to a Object. + * Apply a constraint to an Object. * @param[in] constraint The constraint to apply. - * @param[in] weightObject An object with a "weight" float property. */ - Dali::ActiveConstraint ApplyConstraint( Constraint& constraint, Dali::Handle weightObject ); + void ApplyConstraint( ConstraintBase& constraint ); /** - * Remove one constraint from a Object. - * @param[in] activeConstraint The active constraint to remove. + * Remove one constraint from an Object. + * @param[in] constraint The constraint to remove. */ - void RemoveConstraint( Dali::ActiveConstraint activeConstraint ); + void RemoveConstraint( ConstraintBase& constraint ); /** * Remove all constraints from a Object. @@ -237,9 +303,9 @@ public: void RemoveConstraints(); /** - * Remove all constraints from a Object with a matching tag + * @copydoc Dali::Handle::RemoveConstraints( uint32_t ) */ - void RemoveConstraints( unsigned int tag ); + void RemoveConstraints( uint32_t tag ); /** * Called by TypeInfo to set the type-info that this object-impl is created by. @@ -250,18 +316,18 @@ public: /** * @return the index from which custom properties start */ - unsigned int CustomPropertyStartIndex() + uint32_t CustomPropertyStartIndex() { return PROPERTY_CUSTOM_START_INDEX; } - // To be overridden by deriving classes - /** * Retrieve the scene-graph object added by this object. - * @return A pointer to the object, or NULL if no object has been added to the scene-graph. + * @return reference to the scene-graph object, it will always exist */ - virtual const SceneGraph::PropertyOwner* GetSceneObject() const = 0; + const SceneGraph::PropertyOwner& GetSceneObject() const; + + /******************** Can be overridden by deriving classes ********************/ /** * Retrieve an animatable property owned by the scene-graph object. @@ -269,15 +335,15 @@ public: * @param[in] index The index of the property. * @return A dereferenceable pointer to a property, or NULL if a scene-object does not exist with this property. */ - virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const = 0; + virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const; /** - * Retrieve an constraint input-property owned by the scene-graph object. + * Retrieve a constraint input-property owned by the scene-graph object. * @pre -1 < index < GetPropertyCount(). * @param[in] index The index of the property. * @return A dereferenceable pointer to an input property, or NULL if a scene-object does not exist with this property. */ - virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const = 0; + virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const; /** * Query whether the property is a component of a scene-graph property. @@ -285,11 +351,23 @@ public: * @param[in] index The index of the property. * @return The index or Property::INVALID_COMPONENT_INDEX. */ - virtual int GetPropertyComponentIndex( Property::Index index ) const; + virtual int32_t GetPropertyComponentIndex( Property::Index index ) const; + + /** + * @copydoc Dali::Handle::PropertySetSignal() + */ + DevelHandle::PropertySetSignalType& PropertySetSignal(); protected: /** + * Constructor. Protected so use New to construct an instance of this class + * + * @param sceneObject the scene graph property owner + */ + Object( const SceneGraph::PropertyOwner* sceneObject ); + + /** * A reference counted object may only be deleted by calling Unreference() */ virtual ~Object(); @@ -305,8 +383,17 @@ protected: void OnSceneObjectRemove(); /** + * For overriding by derived classes to return the parent of this object. + */ + virtual Object* GetParentObject() const + { + // By default the Object does not have a parent + return nullptr; + }; + + /** * For use in derived classes. - * This is called after a non animatable custom property is set. + * This is called after a property is set. * @param [in] index The index of the property. * @param [in] propertyValue The value of the property. */ @@ -324,65 +411,47 @@ protected: * @param index * @return pointer to the property */ - CustomProperty* FindCustomProperty( Property::Index index ) const; - -private: // Default property extensions for derived classes - - /** - * Query how many default properties the derived class supports. - * @return The number of default properties. - */ - virtual unsigned int GetDefaultPropertyCount() const = 0; + CustomPropertyMetadata* FindCustomProperty( Property::Index index ) const; /** - * Retrieve all the indices that are associated with the default properties supported by the derived class. - * @return A container of default property indices. - * @note The deriving class must not modify the existing elements in the container. - */ - virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const = 0; - - /** - * Query how many default properties the derived class supports. - * @return The number of default properties. + * Helper to find animatable property + * @param index + * @return pointer to the property */ - virtual const char* GetDefaultPropertyName( Property::Index index ) const = 0; + AnimatablePropertyMetadata* FindAnimatableProperty( Property::Index index ) const; /** - * Query the index of a default property. + * Helper to register a scene-graph property * @param [in] name The name of the property. - * @return The index of the property, or Property::INVALID_INDEX if no default property exists with the given name. + * @param [in] key The key of the property + * @param [in] index The index of the property + * @param [in] value The value of the property. + * @return The index of the registered property or Property::INVALID_INDEX if registration failed. */ - virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const = 0; + Property::Index RegisterSceneGraphProperty( const std::string& name, Property::Index key, Property::Index index, const Property::Value& propertyValue ) const; /** - * Query whether a default property is writable. - * @param [in] index The index of the property. - * @return True if the property is animatable. + * Registers animatable scene property + * @param typeInfo to check the default value + * @param index of the property to register + * @param value initial value or nullptr */ - virtual bool IsDefaultPropertyWritable( Property::Index index ) const = 0; + void RegisterAnimatableProperty( const TypeInfo& typeInfo, Property::Index index, const Property::Value* value ) const; /** - * Query whether a default property is animatable. - * This determines whether the property can be the target of an animation or constraint. - * @param [in] index The index of the property. - * @return True if the property is animatable. + * Check whether the animatable property is registered already, if not then register on. + * @param [in] index The index of the property + * @param [in] value optional value for the property + * @return pointer to the property metadata */ - virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const = 0; + AnimatablePropertyMetadata* GetSceneAnimatableProperty( Property::Index index, const Property::Value* value ) const; /** - * @brief Query whether a default property can be used as an input to a constraint. - * - * @param [in] index The index of the property. - * @return True if the property can be used as an input to a constraint. + * Resolve the index and name of child properties if any. */ - virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const = 0; + void ResolveChildProperties(); - /** - * Query the type of a default property. - * @param [in] index The index of the property. - * @return The type of the property. - */ - virtual Property::Type GetDefaultPropertyType( Property::Index index ) const = 0; +private: // Default property extensions for derived classes /** * Set the value of a default property. @@ -390,43 +459,38 @@ private: // Default property extensions for derived classes * @param [in] index The index of the property. * @param [in] propertyValue The new value of the property. */ - virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) = 0; + virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ); /** * Retrieve a default property value. * @param [in] index The index of the property. * @return The property value. */ - virtual Property::Value GetDefaultProperty( Property::Index index ) const = 0; + virtual Property::Value GetDefaultProperty( Property::Index index ) const; /** - * @todo this is virtual so that for now actor can override it, - * it needs to be removed and only have GetSceneObject but that requires changing actor and constraint logic - * Retrieve the scene-graph object added by this object. - * @return A pointer to the object, or NULL if no object has been added to the scene-graph. + * Retrieve the latest scene-graph value of a default property. + * @param[in] index The index of the property. + * @return The latest scene-graph value of a default property. */ - virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const - { - return GetSceneObject(); - } + virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const; /** - * Notify derived class of installation of a new scene-object property. - * This method is called after the message is to sent to install the property - * @param [in] newProperty A newly allocated scene-object property. Ownership is obviously not passed. - * @param [in] name The name allocated to this custom property. - * @param [in] index The index allocated to this custom property. + * Notifies that a default property is being animated so the deriving class should update the cached value. + * @param[in] animation The animation animating the property. + * @param[in] index The index of the property. + * @param[in] value The value of the property after the animation. + * @param[in] animationType Whether the property value given is the target or a relative value. */ - virtual void NotifyScenePropertyInstalled( const SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index ) + virtual void OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type propertyChangeType ) { } private: - // Not implemented - Object(const Object& rhs); - - // Not implemented - Object& operator=(const Object& rhs); + // no default, copy or assignment + Object() = delete; + Object(const Object& rhs) = delete; + Object& operator=(const Object& rhs) = delete; /** * Enable property notifications in scene graph @@ -439,40 +503,71 @@ private: void DisablePropertyNotifications(); /** - * Helper for ApplyConstraint overloads. - * @param[in] constraint The constraint to apply. - * @param[in] weightObject An object with a "weight" float property, or an empty handle. - * @return The new active-constraint which is owned by Object. - */ - ActiveConstraintBase* DoApplyConstraint( Constraint& constraint, Dali::Handle weightObject ); - - /** - * Helper to remove active constraints + * Get the latest value of the property on the scene-graph. + * @param[in] entry An entry from the property lookup container. + * @return The latest value of the property. */ - void RemoveConstraint( ActiveConstraint& constraint, bool isInScenegraph ); + Property::Value GetCurrentPropertyValue( const PropertyMetadata& entry ) const; /** * Set the value of scene graph property. * @param [in] index The index of the property. - * @param [in] entry An entry from the CustomPropertyLookup. + * @param [in] entry An entry from the property lookup container. * @param [in] value The new value of the property. */ - virtual void SetSceneGraphProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value ); + virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value ); + +protected: + /** + * Get the event thread services object - used for sending messages to the scene graph + * Assert if called from the wrong thread. + * This is intentionally inline for performance reasons. + * + * @return The event thread services object + */ + inline EventThreadServices& GetEventThreadServices() + { + DALI_ASSERT_DEBUG( EventThreadServices::IsCoreRunning() ); + return mEventThreadServices; + } + + /** + * Get the event thread services object - used for sending messages to the scene graph + * Assert if called from the wrong thread + * This is intentionally inline for performance reasons. + * + * @return The event thread services object + */ + inline const EventThreadServices& GetEventThreadServices() const + { + DALI_ASSERT_DEBUG( EventThreadServices::IsCoreRunning() ); + return mEventThreadServices; + } private: - typedef OwnerContainer CustomPropertyLookup; - CustomPropertyLookup mCustomProperties; ///< Used for accessing custom Node properties - mutable TypeInfo const * mTypeInfo; ///< The type-info for this object, mutable so it can be lazy initialized from const method if it is required + EventThreadServices& mEventThreadServices; + +protected: + + // mutable because it's lazy initialised and GetSceneObject has to be const so it can be called from const methods + // const to prevent accidentally calling setters directly from event thread + // protected to allow fast access from derived classes that have their own scene object (no function call overhead) + mutable const SceneGraph::PropertyOwner* mUpdateObject; ///< Reference to object to hold the scene graph properties + +private: Dali::Vector mObservers; + mutable OwnerContainer mCustomProperties; ///< Used for accessing custom Node properties + mutable OwnerContainer mAnimatableProperties; ///< Used for accessing animatable Node properties + mutable const TypeInfo* mTypeInfo; ///< The type-info for this object, mutable so it can be lazy initialized from const method if it is required - ActiveConstraintContainer* mConstraints; ///< Container of owned active-constraints. + ConstraintContainer* mConstraints; ///< Container of owned -constraints. - typedef std::vector< Dali::PropertyNotification > PropertyNotificationContainer; - typedef PropertyNotificationContainer::iterator PropertyNotificationContainerIter; - typedef PropertyNotificationContainer::const_iterator PropertyNotificationContainerConstIter; + using PropertyNotificationContainer = std::vector< Dali::PropertyNotification >; PropertyNotificationContainer* mPropertyNotifications; ///< Container of owned property notifications. + DevelHandle::PropertySetSignalType mPropertySetSignal; + }; } // namespace Internal @@ -499,4 +594,4 @@ inline const Internal::Object& GetImplementation(const Dali::Handle& object) } // namespace Dali -#endif // __DALI_INTERNAL_OBJECT_H__ +#endif // DALI_INTERNAL_OBJECT_H