X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fanimated-vector-image%2Fvector-animation-task.h;h=0ca2295f8a497cfe18a7498124ee2043559c12f9;hp=702a7183d120eb005f5df0ad14ab414937f72b92;hb=34a9372d83f9a8a63ef0abcc93c652448e308562;hpb=d0b0cfa4a44953be9af9128885eb6ef5d83a214e diff --git a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h index 702a718..0ca2295 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h +++ b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_VECTOR_ANIMATION_TASK_H /* - * Copyright (c) 2021 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. @@ -42,23 +42,33 @@ typedef IntrusivePtr VectorAnimationTaskPtr; /** * The task of the vector animation. */ -class VectorAnimationTask : public RefObject +class VectorAnimationTask : public RefObject, public ConnectionTracker { public: - using UploadCompletedSignalType = Dali::VectorAnimationRenderer::UploadCompletedSignalType; + enum class ResourceStatus + { + LOADED, /// Resource is loaded + READY, /// Resource is ready + FAILED /// Resource is fail to load + }; + + using ResourceReadySignalType = Signal; + + using TimePoint = std::chrono::time_point; /** * Flags for re-sending data to the vector animation thread */ enum ResendFlags { - RESEND_PLAY_RANGE = 1 << 0, - RESEND_LOOP_COUNT = 1 << 1, - RESEND_STOP_BEHAVIOR = 1 << 2, - RESEND_LOOPING_MODE = 1 << 3, - RESEND_CURRENT_FRAME = 1 << 4, - RESEND_SIZE = 1 << 5, - RESEND_PLAY_STATE = 1 << 6 + RESEND_PLAY_RANGE = 1 << 0, + RESEND_LOOP_COUNT = 1 << 1, + RESEND_STOP_BEHAVIOR = 1 << 2, + RESEND_LOOPING_MODE = 1 << 3, + RESEND_CURRENT_FRAME = 1 << 4, + RESEND_SIZE = 1 << 5, + RESEND_PLAY_STATE = 1 << 6, + RESEND_NEED_RESOURCE_READY = 1 << 7 }; /** @@ -108,9 +118,8 @@ public: * @brief Constructor. * * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object - * @param[in] url The url of the vector animation file */ - VectorAnimationTask(VisualFactoryCache& factoryCache, const std::string& url); + VectorAnimationTask(VisualFactoryCache& factoryCache); /** * @brief Destructor. @@ -130,6 +139,19 @@ public: void SetRenderer(Renderer renderer); /** + * @brief Requests to load the animation file. + * + * @param[in] url The url of the vector animation file + */ + void RequestLoad(const std::string& url); + + /** + * @brief Queries whether loading is requested. + * @return True if loading is requested. + */ + bool IsLoadRequested() const; + + /** * @brief Sets data to specify animation playback. * @param[in] data The animation data */ @@ -173,34 +195,37 @@ public: void GetLayerInfo(Property::Map& map) const; /** - * @brief Connect to this signal to be notified when the texture upload is completed. + * @brief Connect to this signal to be notified when the resource is ready. * @return The signal to connect to. */ - UploadCompletedSignalType& UploadCompletedSignal(); + ResourceReadySignalType& ResourceReadySignal(); /** * @brief Rasterizes the current frame. - * @return true if the animation is running, false otherwise. + * @param[out] keepAnimation true if the animation is running, false otherwise. + * @return true if the rasterization succeeded, false otherwise. */ - bool Rasterize(); + bool Rasterize(bool& keepAnimation); /** * @brief Calculates the time for the next frame rasterization. * @return The time for the next frame rasterization. */ - std::chrono::time_point CalculateNextFrameTime(bool renderNow); + TimePoint CalculateNextFrameTime(bool renderNow); /** * @brief Gets the time for the next frame rasterization. * @return The time for the next frame rasterization. */ - std::chrono::time_point GetNextFrameTime(); + TimePoint GetNextFrameTime(); private: /** - * @brief Initializes the vector renderer. + * @brief Loads the animation file. + * + * @return True if loading succeeded, false otherwise. */ - void Initialize(); + bool Load(); /** * @brief Play the vector animation. @@ -267,6 +292,16 @@ private: */ void ApplyAnimationData(); + /** + * @brief Called when the texture upload is completed. + */ + void OnUploadCompleted(); + + /** + * @brief Event callback from rasterize thread. This is called when the file loading is completed. + */ + void OnLoadCompleted(); + // Undefined VectorAnimationTask(const VectorAnimationTask& task) = delete; @@ -282,32 +317,37 @@ private: PAUSED ///< The animation is paused }; - std::string mUrl; - VectorAnimationRenderer mVectorRenderer; - AnimationData mAnimationData[2]; - VectorAnimationThread& mVectorAnimationThread; - ConditionalWait mConditionalWait; - std::unique_ptr mAnimationFinishedTrigger; - PlayState mPlayState; - DevelImageVisual::StopBehavior::Type mStopBehavior; - DevelImageVisual::LoopingMode::Type mLoopingMode; - std::chrono::time_point mNextFrameStartTime; - int64_t mFrameDurationNanoSeconds; - float mFrameRate; - uint32_t mCurrentFrame; - uint32_t mTotalFrame; - uint32_t mStartFrame; - uint32_t mEndFrame; - uint32_t mWidth; - uint32_t mHeight; - uint32_t mAnimationDataIndex; - int32_t mLoopCount; - int32_t mCurrentLoop; - bool mForward; - bool mUpdateFrameNumber; - bool mNeedAnimationFinishedTrigger; - bool mAnimationDataUpdated; - bool mDestroyTask; + std::string mUrl; + VectorAnimationRenderer mVectorRenderer; + AnimationData mAnimationData[2]; + VectorAnimationThread& mVectorAnimationThread; + ConditionalWait mConditionalWait; + ResourceReadySignalType mResourceReadySignal; + std::unique_ptr mAnimationFinishedTrigger; + std::unique_ptr mLoadCompletedTrigger; + PlayState mPlayState; + DevelImageVisual::StopBehavior::Type mStopBehavior; + DevelImageVisual::LoopingMode::Type mLoopingMode; + TimePoint mNextFrameStartTime; + int64_t mFrameDurationMicroSeconds; + float mFrameRate; + uint32_t mCurrentFrame; + uint32_t mTotalFrame; + uint32_t mStartFrame; + uint32_t mEndFrame; + uint32_t mDroppedFrames; + uint32_t mWidth; + uint32_t mHeight; + uint32_t mAnimationDataIndex; + int32_t mLoopCount; + int32_t mCurrentLoop; + bool mForward; + bool mUpdateFrameNumber; + bool mNeedAnimationFinishedTrigger; + bool mAnimationDataUpdated; + bool mDestroyTask; + bool mLoadRequest; + bool mLoadFailed; }; } // namespace Internal