X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Fanimation%2Fscene-graph-animation.h;h=3e27055f4ada3db8e6a9daeda3264536cc954150;hb=77de4c4ae763aeb42c5bf02be9191ab0694b48a1;hp=96350377a60a50c11a096b2c8cbb238f98f69846;hpb=46589d84c800e9ce26845d77a57df023e3df6922;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 9635037..3e27055 100644 --- a/dali/internal/update/animation/scene-graph-animation.h +++ b/dali/internal/update/animation/scene-graph-animation.h @@ -2,7 +2,7 @@ #define __DALI_INTERNAL_SCENE_GRAPH_ANIMATION_H__ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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,10 +20,11 @@ // INTERNAL INCLUDES #include -#include + #include #include -#include +#include +#include namespace Dali { @@ -65,15 +66,12 @@ public: * @param[in] durationSeconds The duration of the animation in seconds. * @param[in] speedFactor Multiplier to the animation velocity. * @param[in] playRange Minimum and maximum progress between which the animation will play. - * @param[in] isLooping Whether the animation will loop. + * @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, const Vector2& playRange, bool isLooping, EndAction endAction, EndAction destroyAction ) - { - return new Animation( durationSeconds, speedFactor, playRange, isLooping, endAction, destroyAction ); - } + static Animation* New( float durationSeconds, float speedFactor, const Vector2& playRange, int loopCount, EndAction endAction, EndAction disconnectAction ); /** * Virtual destructor @@ -81,6 +79,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. @@ -88,6 +92,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. */ @@ -125,10 +135,11 @@ public: } /** - * 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(int loopCount); /** * Query whether the animation will loop. @@ -136,7 +147,16 @@ public: */ bool IsLooping() const { - return mLooping; + return mLoopCount != 1; + } + + /* + * Get the loop count + * @return the loop count + */ + int GetLoopCount() const + { + return mLoopCount; } /** @@ -155,20 +175,20 @@ 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; } /** @@ -184,13 +204,19 @@ public: */ 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 ); /** + * @brief Play the animation after a given delay time. + * @param[in] delaySeconds The delay time + */ + void PlayAfter( float delaySeconds ); + + /** * Pause the animation. */ void Pause(); @@ -204,7 +230,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); @@ -222,9 +248,17 @@ 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 + int GetPlayedCount() const { - return mPlayCount; + return mPlayedCount; + } + + /** + * Get the current loop count from zero to GetLoopCount(). + */ + int GetCurrentLoop() const + { + return mCurrentLoop; } /** @@ -234,7 +268,7 @@ public: * @param[in] propertyOwner The scene-object that owns the animatable property. * @post The animator is owned by this animation. */ - void AddAnimator( AnimatorBase* animator, PropertyOwner* propertyOwner ); + void AddAnimator( OwnerPointer& animator ); /** * Retrieve the animators from an animation. @@ -250,9 +284,11 @@ public: * @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 ); protected: @@ -260,7 +296,7 @@ protected: /** * Protected constructor. See New() */ - Animation( float durationSeconds, float speedFactor, const Vector2& playRange, bool isLooping, EndAction endAction, EndAction destroyAction ); + Animation( float durationSeconds, float speedFactor, const Vector2& playRange, int loopCount, EndAction endAction, EndAction disconnectAction ); private: @@ -269,8 +305,9 @@ 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 @@ -280,6 +317,12 @@ private: */ 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&); @@ -288,18 +331,27 @@ private: protected: + AnimatorContainer mAnimators; + + Vector2 mPlayRange; + float mDurationSeconds; + float mDelaySeconds; + float mElapsedSeconds; float mSpeedFactor; - bool mLooping; + float mProgressMarker; // Progress marker to trigger a notification + + int mPlayedCount; // Incremented at end of animation or completion of all loops + // Never incremented when looping forever. Event thread tracks to signal end. + int mLoopCount; // N loop setting + int mCurrentLoop; // Current loop number + EndAction mEndAction; - EndAction mDestroyAction; + EndAction mDisconnectAction; State mState; - float mElapsedSeconds; - int mPlayCount; - Vector2 mPlayRange; - AnimatorContainer mAnimators; + bool mProgressReachedSignalRequired; // Flag to indicate the progress marker was hit }; }; //namespace SceneGraph @@ -312,125 +364,149 @@ 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 ) { typedef MessageValue1< Animation, float > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + unsigned int* 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 SetLoopingMessage( EventToUpdate& eventToUpdate, const Animation& animation, bool looping ) +inline void SetProgressNotificationMessage( EventThreadServices& eventThreadServices, const Animation& animation, float progress ) +{ + typedef MessageValue1< Animation, float > LocalType; + + // Reserve some memory inside the message queue + unsigned int* 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, int loopCount ) { - typedef MessageValue1< Animation, bool > LocalType; + typedef MessageValue1< Animation, int > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + unsigned int* 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::SetLoopCount, loopCount ); } -inline void SetEndActionMessage( EventToUpdate& eventToUpdate, const Animation& animation, Dali::Animation::EndAction action ) +inline void SetEndActionMessage( EventThreadServices& eventThreadServices, const Animation& animation, Dali::Animation::EndAction action ) { typedef MessageValue1< Animation, Dali::Animation::EndAction > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + unsigned int* 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 SetDestroyActionMessage( EventToUpdate& eventToUpdate, const Animation& animation, Dali::Animation::EndAction action ) +inline void SetDisconnectActionMessage( EventThreadServices& eventThreadServices, const Animation& animation, Dali::Animation::EndAction action ) { typedef MessageValue1< Animation, Dali::Animation::EndAction > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + unsigned int* 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::SetDisconnectAction, action ); } -inline void SetCurrentProgressMessage( EventToUpdate& eventToUpdate, const Animation& animation, float progress ) +inline void SetCurrentProgressMessage( EventThreadServices& eventThreadServices, const Animation& animation, float progress ) { typedef MessageValue1< Animation, float > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + unsigned int* 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 ); } -inline void SetSpeedFactorMessage( EventToUpdate& eventToUpdate, const Animation& animation, float factor ) +inline void SetSpeedFactorMessage( EventThreadServices& eventThreadServices, const Animation& animation, float factor ) { typedef MessageValue1< Animation, float > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + unsigned int* 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 ); } -inline void SetPlayRangeMessage( EventToUpdate& eventToUpdate, const Animation& animation, const Vector2& range ) +inline void SetPlayRangeMessage( EventThreadServices& eventThreadServices, const Animation& animation, const Vector2& range ) { typedef MessageValue1< Animation, Vector2 > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + unsigned int* 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::SetPlayRange, range ); } -inline void PlayAnimationMessage( EventToUpdate& eventToUpdate, const Animation& animation ) +inline void PlayAnimationMessage( EventThreadServices& eventThreadServices, const Animation& animation ) { typedef Message< Animation > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + unsigned int* 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 ); } -inline void PlayAnimationFromMessage( EventToUpdate& eventToUpdate, const Animation& animation, float progress ) +inline void PlayAnimationFromMessage( EventThreadServices& eventThreadServices, const Animation& animation, float progress ) { typedef MessageValue1< Animation,float > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + unsigned int* 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 ); } -inline void PauseAnimationMessage( EventToUpdate& eventToUpdate, const Animation& animation ) +inline void PauseAnimationMessage( EventThreadServices& eventThreadServices, const Animation& animation ) { typedef Message< Animation > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + unsigned int* 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 ); } -inline void AddAnimatorMessage( EventToUpdate& eventToUpdate, const Animation& animation, AnimatorBase& animator, const PropertyOwner& owner ) +inline void AddAnimatorMessage( EventThreadServices& eventThreadServices, const Animation& animation, AnimatorBase& animator ) +{ + typedef MessageValue1< Animation, OwnerPointer > LocalType; + + // Reserve some memory inside the message queue + unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + OwnerPointer parameter( &animator ); + new (slot) LocalType( &animation, &Animation::AddAnimator, parameter ); +} + +inline void PlayAfterMessage( EventThreadServices& eventThreadServices, const Animation& animation, float delaySeconds ) { - typedef MessageValue2< Animation, OwnerPointer, PropertyOwner* > LocalType; + typedef MessageValue1< Animation, float > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) ); + unsigned int* 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::PlayAfter, delaySeconds ); } } // namespace SceneGraph