X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Fanimation%2Fscene-graph-animation.h;h=4119c151984a4d4d2228d1e7db125e2ed71c7198;hb=refs%2Fchanges%2F98%2F285298%2F5;hp=c99c1822738207e981740bdbaa74372a532856a6;hpb=2637b48f1dba3520a4a26f1b63fc25ddc5524abf;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/animation/scene-graph-animation.h b/dali/internal/update/animation/scene-graph-animation.h index c99c182..4119c15 100644 --- a/dali/internal/update/animation/scene-graph-animation.h +++ b/dali/internal/update/animation/scene-graph-animation.h @@ -1,8 +1,8 @@ -#ifndef __DALI_INTERNAL_SCENE_GRAPH_ANIMATION_H__ -#define __DALI_INTERNAL_SCENE_GRAPH_ANIMATION_H__ +#ifndef DALI_INTERNAL_SCENE_GRAPH_ANIMATION_H +#define DALI_INTERNAL_SCENE_GRAPH_ANIMATION_H /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -20,27 +20,18 @@ // INTERNAL INCLUDES #include -#include + #include #include -#include +#include +#include namespace Dali { - namespace Internal { - namespace SceneGraph { - -class Animation; - -typedef OwnerContainer< Animation* > AnimationContainer; - -typedef AnimationContainer::Iterator AnimationIter; -typedef AnimationContainer::ConstIterator AnimationConstIter; - /** * Animations are used to change the properties of scene graph objects, as part of a scene * managers "update" phase. An animation is a container of Animator objects; the actual setting @@ -49,8 +40,7 @@ typedef AnimationContainer::ConstIterator AnimationConstIter; class Animation { public: - - typedef Dali::Animation::EndAction EndAction; + using EndAction = Dali::Animation::EndAction; enum State { @@ -64,15 +54,13 @@ public: * Construct a new Animation. * @param[in] durationSeconds The duration of the animation in seconds. * @param[in] speedFactor Multiplier to the animation velocity. - * @param[in] isLooping Whether the animation will loop. + * @param[in] playRange Minimum and maximum progress between which the animation will play. + * @param[in] loopCount The number of times the animation will loop. ( See SetLoopCount() ) * @param[in] endAction The action to perform when the animation ends. - * @param[in] destroyAction The action to perform when the animation is destroyed. + * @param[in] disconnectAction The action to perform when the property owner of an animator is disconnected. * @return A new Animation */ - static Animation* New( float durationSeconds, float speedFactor, bool isLooping, EndAction endAction, EndAction destroyAction ) - { - return new Animation( durationSeconds, speedFactor, isLooping, endAction, destroyAction ); - } + static Animation* New(float durationSeconds, float speedFactor, const Vector2& playRange, int32_t loopCount, EndAction endAction, EndAction disconnectAction); /** * Virtual destructor @@ -80,6 +68,12 @@ public: virtual ~Animation(); /** + * Overriden delete operator + * Deletes the animation from its global memory pool + */ + void operator delete(void* ptr); + + /** * Set the duration of an animation. * @pre durationSeconds must be greater than zero. * @param[in] durationSeconds The duration in seconds. @@ -87,6 +81,12 @@ public: void SetDuration(float durationSeconds); /** + * Set the progress marker to trigger notification + * @param[in] progress percent of progress to trigger notification, 0.0f < progress <= 1.0f + */ + void SetProgressNotification(float progress); + + /** * Retrieve the duration of the animation. * @return The duration in seconds. */ @@ -95,13 +95,13 @@ public: return mDurationSeconds; } - /* + /** * Retrieve the current progress of the animation. * @return The current progress as a normalized value between [0,1]. */ float GetCurrentProgress() const { - if( mDurationSeconds > 0.0f ) + if(mDurationSeconds > 0.0f) { return mElapsedSeconds / mDurationSeconds; } @@ -109,25 +109,30 @@ public: return 0.0f; } - /* + /** * Sets the progress of the animation. * @param[in] The new progress as a normalized value between [0,1] */ - void SetCurrentProgress( float progress ) + void SetCurrentProgress(float progress) { mElapsedSeconds = mDurationSeconds * progress; } - void SetSpeedFactor( float factor ) + /** + * Specifies a speed factor for the animation. + * @param[in] factor A value which will multiply the velocity + */ + void SetSpeedFactor(float factor) { mSpeedFactor = factor; } /** - * Set whether the animation will loop. - * @param[in] looping True if the animation will loop. + * Set the animation loop count. + * 0 is loop forever, N loop play N times + * @param[in] loopCount The loop count */ - void SetLooping(bool looping); + void SetLoopCount(int32_t loopCount); /** * Query whether the animation will loop. @@ -135,7 +140,16 @@ public: */ bool IsLooping() const { - return mLooping; + return mLoopCount != 1; + } + + /** + * Get the loop count + * @return the loop count + */ + int32_t GetLoopCount() const + { + return mLoopCount; } /** @@ -154,32 +168,46 @@ public: } /** - * Set the destroy action of the animation. + * Set the disconnect action of the animation when connected objects are disconnected. * This action is performed during the next update when - * the animation is destroyed. - * @param[in] action The destroy action. + * the connected object is disconnected. + * @param[in] action The disconnect action. */ - void SetDestroyAction(EndAction action); + void SetDisconnectAction(EndAction action); /** * Retrieve the action performed when the animation is destroyed. * @return The destroy action. */ - EndAction GetDestroyAction() + EndAction GetDisconnectAction() { - return mDestroyAction; + return mDisconnectAction; } /** + * Set the playing range. The animation will only play between the minimum and maximum progress + * speficied. + * + * @param[in] range Two values between [0,1] to specify minimum and maximum progress. + */ + void SetPlayRange(const Vector2& range); + + /** * Play the animation. */ void Play(); - /* + /** * Play the animation from a given point * @param[in] progress A value between [0,1] form where the animation should start playing */ - void PlayFrom( float progress ); + void PlayFrom(float progress); + + /** + * @brief Play the animation after a given delay time. + * @param[in] delaySeconds The delay time + */ + void PlayAfter(float delaySeconds); /** * Pause the animation. @@ -195,7 +223,7 @@ public: /** * Called shortly before the animation is destroyed. - * @param[in] bufferIndex The buffer to update when mDestroyAction == Bake. + * @param[in] bufferIndex The buffer to update when mEndAction == Bake. */ void OnDestroy(BufferIndex bufferIndex); @@ -213,55 +241,73 @@ public: * Retrive a count of the number of times the animation has been played to completion. * This can be used to emit "Finised" signals from the public-api */ - int GetPlayCount() const + int32_t GetPlayedCount() const { - return mPlayCount; + return mPlayedCount; } /** - * Add a newly created animator. - * Animators are automatically removed, when orphaned from an animatable scene object. - * @param[in] animator The animator to add. - * @param[in] propertyOwner The scene-object that owns the animatable property. - * @post The animator is owned by this animation. + * Get the current loop count from zero to GetLoopCount(). */ - void AddAnimator( AnimatorBase* animator, PropertyOwner* propertyOwner ); + int32_t GetCurrentLoop() const + { + return mCurrentLoop; + } /** - * Retrieve the animators from an animation. - * @return The container of animators. + * Query whether the animation is currently active (i.e. at least one of the animators has been updated in either frame) + * @return True if the animation is currently active */ - AnimatorContainer& GetAnimators() + bool IsActive() const { - return mAnimators; + // As we have double buffering, if animator is updated in either frame, it needs to be rendered. + return mIsActive[0] || mIsActive[1]; } /** + * @brief Sets the looping mode. + * + * Animation plays forwards and then restarts from the beginning or runs backwards again. + * @param[in] loopingMode True when the looping mode is AUTO_REVERSE + */ + void SetLoopingMode(bool loopingMode); + + /** + * Add a newly created animator. + * Animators are automatically removed, when orphaned from an animatable scene object. + * @param[in] animator The animator to add. + * @param[in] propertyOwner The scene-object that owns the animatable property. + * @post The animator is owned by this animation. + */ + void AddAnimator(OwnerPointer& animator); + + /** * This causes the animators to change the properties of objects in the scene graph. * @pre The animation is playing or paused. * @param[in] bufferIndex The buffer to update. * @param[in] elapsedSeconds The time elapsed since the previous frame. - * @return True if the animation has finished. + * @param[out] looped True if the animation looped + * @param[out] finished True if the animation has finished. + * @param[out] progressReached True if progress marker reached */ - bool Update(BufferIndex bufferIndex, float elapsedSeconds); + void Update(BufferIndex bufferIndex, float elapsedSeconds, bool& looped, bool& finished, bool& progressReached); + static uint32_t GetMemoryPoolCapacity(); protected: - /** * Protected constructor. See New() */ - Animation( float durationSeconds, float speedFactor, bool isLooping, EndAction endAction, EndAction destroyAction ); - + Animation(float durationSeconds, float speedFactor, const Vector2& playRange, int32_t loopCount, EndAction endAction, EndAction disconnectAction); private: - /** * Helper for Update, also used to bake when the animation is stopped or destroyed. * @param[in] bufferIndex The buffer to update. * @param[in] bake True if the final result should be baked. + * @param[in] animationFinished True if the animation has finished. */ - void UpdateAnimators(BufferIndex bufferIndex, bool bake); + void UpdateAnimators(BufferIndex bufferIndex, bool bake, bool animationFinished); /** * Helper function to bake the result of the animation when it is stopped or @@ -269,7 +315,13 @@ private: * @param[in] bufferIndex The buffer to update. * @param[in] action The end action specified. */ - void Bake(BufferIndex bufferIndex, EndAction action ); + void Bake(BufferIndex bufferIndex, EndAction action); + + /** + * Helper function to set active state of animators. + * @param[in] active Every animator is set to this state + */ + void SetAnimatorsActive(bool active); // Undefined Animation(const Animation&); @@ -278,138 +330,196 @@ private: Animation& operator=(const Animation& rhs); protected: + OwnerContainer mAnimators; + + Vector2 mPlayRange; float mDurationSeconds; + float mDelaySeconds; + float mElapsedSeconds; float mSpeedFactor; - bool mLooping; + float mProgressMarker; // Progress marker to trigger a notification + + int32_t mPlayedCount; // Incremented at end of animation or completion of all loops + // Never incremented when looping forever. Event thread tracks to signal end. + int32_t mLoopCount; // N loop setting + int32_t mCurrentLoop; // Current loop number + EndAction mEndAction; - EndAction mDestroyAction; + EndAction mDisconnectAction; State mState; - float mElapsedSeconds; - int mPlayCount; - AnimatorContainer mAnimators; + bool mProgressReachedSignalRequired; // Flag to indicate the progress marker was hit + bool mAutoReverseEnabled; // Flag to identify that the looping mode is auto reverse. + bool mIsActive[2]; // Flag to indicate whether the animation is active in the current frame (which is double buffered) }; }; //namespace SceneGraph // value types used by messages -template <> struct ParameterType< Dali::Animation::EndAction > : public BasicType< Dali::Animation::EndAction > {}; +template<> +struct ParameterType : public BasicType +{ +}; namespace SceneGraph { - // Messages for Animation -inline void SetDurationMessage( EventToUpdate& eventToUpdate, const Animation& animation, float durationSeconds ) +inline void SetDurationMessage(EventThreadServices& eventThreadServices, const Animation& animation, float durationSeconds) +{ + using LocalType = MessageValue1; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new(slot) LocalType(&animation, &Animation::SetDuration, durationSeconds); +} + +inline void SetProgressNotificationMessage(EventThreadServices& eventThreadServices, const Animation& animation, float progress) +{ + using LocalType = MessageValue1; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new(slot) LocalType(&animation, &Animation::SetProgressNotification, progress); +} + +inline void SetLoopingMessage(EventThreadServices& eventThreadServices, const Animation& animation, int32_t loopCount) +{ + using LocalType = MessageValue1; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new(slot) LocalType(&animation, &Animation::SetLoopCount, loopCount); +} + +inline void SetEndActionMessage(EventThreadServices& eventThreadServices, const Animation& animation, Dali::Animation::EndAction action) +{ + using LocalType = MessageValue1; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new(slot) LocalType(&animation, &Animation::SetEndAction, action); +} + +inline void SetDisconnectActionMessage(EventThreadServices& eventThreadServices, const Animation& animation, Dali::Animation::EndAction action) { - typedef MessageValue1< Animation, float > LocalType; + using LocalType = MessageValue1; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &animation, &Animation::SetDuration, durationSeconds ); + new(slot) LocalType(&animation, &Animation::SetDisconnectAction, action); } -inline void SetLoopingMessage( EventToUpdate& eventToUpdate, const Animation& animation, bool looping ) +inline void SetCurrentProgressMessage(EventThreadServices& eventThreadServices, const Animation& animation, float progress) { - typedef MessageValue1< Animation, bool > LocalType; + using LocalType = MessageValue1; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &animation, &Animation::SetLooping, looping ); + new(slot) LocalType(&animation, &Animation::SetCurrentProgress, progress); } -inline void SetEndActionMessage( EventToUpdate& eventToUpdate, const Animation& animation, Dali::Animation::EndAction action ) +inline void SetSpeedFactorMessage(EventThreadServices& eventThreadServices, const Animation& animation, float factor) { - typedef MessageValue1< Animation, Dali::Animation::EndAction > LocalType; + using LocalType = MessageValue1; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &animation, &Animation::SetEndAction, action ); + new(slot) LocalType(&animation, &Animation::SetSpeedFactor, factor); } -inline void SetDestroyActionMessage( EventToUpdate& eventToUpdate, const Animation& animation, Dali::Animation::EndAction action ) +inline void SetPlayRangeMessage(EventThreadServices& eventThreadServices, const Animation& animation, const Vector2& range) { - typedef MessageValue1< Animation, Dali::Animation::EndAction > LocalType; + using LocalType = MessageValue1; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &animation, &Animation::SetDestroyAction, action ); + new(slot) LocalType(&animation, &Animation::SetPlayRange, range); } -inline void SetCurrentProgressMessage( EventToUpdate& eventToUpdate, const Animation& animation, float progress ) +inline void PlayAnimationMessage(EventThreadServices& eventThreadServices, const Animation& animation) { - typedef MessageValue1< Animation, float > LocalType; + using LocalType = Message; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &animation, &Animation::SetCurrentProgress, progress ); + new(slot) LocalType(&animation, &Animation::Play); } -inline void SetSpeedFactorMessage( EventToUpdate& eventToUpdate, const Animation& animation, float factor ) +inline void PlayAnimationFromMessage(EventThreadServices& eventThreadServices, const Animation& animation, float progress) { - typedef MessageValue1< Animation, float > LocalType; + using LocalType = MessageValue1; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &animation, &Animation::SetSpeedFactor, factor ); + new(slot) LocalType(&animation, &Animation::PlayFrom, progress); } -inline void PlayAnimationMessage( EventToUpdate& eventToUpdate, const Animation& animation ) +inline void PauseAnimationMessage(EventThreadServices& eventThreadServices, const Animation& animation) { - typedef Message< Animation > LocalType; + using LocalType = Message; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &animation, &Animation::Play ); + new(slot) LocalType(&animation, &Animation::Pause); } -inline void PlayAnimationFromMessage( EventToUpdate& eventToUpdate, const Animation& animation, float progress ) +inline void AddAnimatorMessage(EventThreadServices& eventThreadServices, const Animation& animation, AnimatorBase& animator) { - typedef MessageValue1< Animation,float > LocalType; + using LocalType = MessageValue1 >; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &animation, &Animation::PlayFrom, progress ); + OwnerPointer parameter(&animator); + new(slot) LocalType(&animation, &Animation::AddAnimator, parameter); } -inline void PauseAnimationMessage( EventToUpdate& eventToUpdate, const Animation& animation ) +inline void PlayAfterMessage(EventThreadServices& eventThreadServices, const Animation& animation, float delaySeconds) { - typedef Message< Animation > LocalType; + using LocalType = MessageValue1; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &animation, &Animation::Pause ); + new(slot) LocalType(&animation, &Animation::PlayAfter, delaySeconds); } -inline void AddAnimatorMessage( EventToUpdate& eventToUpdate, const Animation& animation, AnimatorBase& animator, const PropertyOwner& owner ) +inline void SetLoopingModeMessage(EventThreadServices& eventThreadServices, const Animation& animation, bool loopingMode) { - typedef MessageValue2< Animation, OwnerPointer, PropertyOwner* > LocalType; + using LocalType = MessageValue1; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType)); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &animation, &Animation::AddAnimator, &animator, const_cast( &owner ) ); + new(slot) LocalType(&animation, &Animation::SetLoopingMode, loopingMode); } } // namespace SceneGraph @@ -418,4 +528,4 @@ inline void AddAnimatorMessage( EventToUpdate& eventToUpdate, const Animation& a } // namespace Dali -#endif // __DALI_INTERNAL_SCENE_GRAPH_ANIMATION_H__ +#endif // DALI_INTERNAL_SCENE_GRAPH_ANIMATION_H