2 * Copyright (c) 2024 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h>
22 #include <dali/devel-api/adaptor-framework/file-loader.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/integration-api/trace.h>
25 #include <dali/public-api/math/math-utils.h>
26 #include <dali/public-api/object/property-array.h>
29 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h>
30 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h>
31 #include <dali-toolkit/internal/visuals/image/image-visual-shader-factory.h>
48 constexpr auto LOOP_FOREVER = -1;
49 constexpr auto MICROSECONDS_PER_SECOND(1e+6);
51 #if defined(DEBUG_ENABLED)
52 Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VECTOR_ANIMATION");
55 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_IMAGE_PERFORMANCE_MARKER, false);
58 uint64_t GetNanoseconds()
60 // Get the time of a monotonic clock since its epoch.
61 auto epoch = std::chrono::steady_clock::now().time_since_epoch();
62 auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(epoch);
63 return static_cast<uint64_t>(duration.count());
67 int64_t CalculateFrameDurationMicroSeconds(const float frameRate, const float frameSpeedFactor)
69 return static_cast<int64_t>(MICROSECONDS_PER_SECOND / static_cast<double>(frameRate * frameSpeedFactor));
72 } // unnamed namespace
74 VectorAnimationTask::VectorAnimationTask(VisualFactoryCache& factoryCache)
75 : AsyncTask(MakeCallback(this, &VectorAnimationTask::TaskCompleted), AsyncTask::PriorityType::HIGH, AsyncTask::ThreadType::WORKER_THREAD),
77 mEncodedImageBuffer(),
78 mVectorRenderer(VectorAnimationRenderer::New()),
80 mVectorAnimationThread(factoryCache.GetVectorAnimationManager().GetVectorAnimationThread()),
82 mResourceReadySignal(),
83 mLoadCompletedCallback(MakeCallback(this, &VectorAnimationTask::OnLoadCompleted)),
86 mPlayState(PlayState::STOPPED),
87 mStopBehavior(DevelImageVisual::StopBehavior::CURRENT_FRAME),
88 mLoopingMode(DevelImageVisual::LoopingMode::RESTART),
89 mNextFrameStartTime(),
90 mFrameDurationMicroSeconds(MICROSECONDS_PER_SECOND / 60.0f),
92 mFrameSpeedFactor(1.0f),
100 mAnimationDataIndex(0),
101 mAppliedPlayStateId(0u),
102 mLoopCount(LOOP_FOREVER),
105 mUpdateFrameNumber(false),
106 mNeedAnimationFinishedTrigger(true),
107 mNeedForceRenderOnceTrigger(false),
108 mAnimationDataUpdated(false),
113 mKeepAnimation(false),
114 mLayerInfoCached(false),
115 mMarkerInfoCached(false),
116 mEnableFrameCache(false),
117 mNotifyAfterRasterization(false),
120 mVectorRenderer.UploadCompletedSignal().Connect(this, &VectorAnimationTask::OnUploadCompleted);
123 VectorAnimationTask::~VectorAnimationTask()
125 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::~VectorAnimationTask: destructor [%p]\n", this);
128 void VectorAnimationTask::Process()
130 mRasterized = Rasterize();
133 bool VectorAnimationTask::IsReady()
138 void VectorAnimationTask::Finalize()
141 Mutex::ScopedLock lock(mMutex);
143 // Release some objects in the main thread
144 if(mAnimationFinishedCallback)
146 mVectorAnimationThread.RemoveEventTriggerCallbacks(mAnimationFinishedCallback.get());
147 mAnimationFinishedCallback.reset();
149 if(mLoadCompletedCallback)
151 mVectorAnimationThread.RemoveEventTriggerCallbacks(mLoadCompletedCallback.get());
152 mLoadCompletedCallback.reset();
158 mVectorRenderer.Finalize();
161 void VectorAnimationTask::TaskCompleted(VectorAnimationTaskPtr task)
163 mVectorAnimationThread.OnTaskCompleted(task, task->IsRasterized(), task->IsAnimating());
166 bool VectorAnimationTask::IsRasterized()
171 bool VectorAnimationTask::IsAnimating()
173 return mKeepAnimation;
176 bool VectorAnimationTask::Load(bool synchronousLoading)
179 uint64_t mStartTimeNanoSceonds = 0;
180 uint64_t mEndTimeNanoSceonds = 0;
183 DALI_TRACE_BEGIN_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_LOTTIE_LOADING_TASK", [&](std::ostringstream& oss) {
184 mStartTimeNanoSceonds = GetNanoseconds();
185 oss << "[u:" << mImageUrl.GetEllipsedUrl() << "]";
188 if(mEncodedImageBuffer)
190 if(!mVectorRenderer.Load(mEncodedImageBuffer.GetRawBuffer()))
195 // We don't need to hold image buffer anymore.
196 mEncodedImageBuffer.Reset();
198 else if(mImageUrl.IsLocalResource())
200 if(!mVectorRenderer.Load(mImageUrl.GetUrl()))
207 Dali::Vector<uint8_t> remoteData;
208 if(!Dali::FileLoader::DownloadFileSynchronously(mImageUrl.GetUrl(), remoteData) || // Failed if we fail to download json file,
209 !mVectorRenderer.Load(remoteData)) // or download data is not valid vector animation file.
217 DALI_LOG_ERROR("VectorAnimationTask::Load: Load failed [%s]\n", mImageUrl.GetUrl().c_str());
218 mLoadRequest = false;
220 Mutex::ScopedLock lock(mMutex);
221 if(!synchronousLoading && mLoadCompletedCallback)
223 mVectorAnimationThread.AddEventTriggerCallback(mLoadCompletedCallback.get(), 0u);
227 DALI_TRACE_END_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_LOTTIE_LOADING_TASK", [&](std::ostringstream& oss) {
228 mEndTimeNanoSceonds = GetNanoseconds();
229 oss << std::fixed << std::setprecision(3);
231 oss << "d:" << static_cast<float>(mEndTimeNanoSceonds - mStartTimeNanoSceonds) / 1000000.0f << "ms ";
232 oss << "u:" << mImageUrl.GetEllipsedUrl() << "]";
237 mTotalFrame = mVectorRenderer.GetTotalFrameNumber();
239 mEndFrame = mTotalFrame - 1;
241 mFrameRate = mVectorRenderer.GetFrameRate();
243 mFrameDurationMicroSeconds = CalculateFrameDurationMicroSeconds(mFrameRate, mFrameSpeedFactor);
245 mLoadRequest = false;
247 Mutex::ScopedLock lock(mMutex);
248 if(!synchronousLoading && mLoadCompletedCallback)
250 mVectorAnimationThread.AddEventTriggerCallback(mLoadCompletedCallback.get(), 0u);
254 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::Load: file = %s [%d frames, %f fps] [%p]\n", mImageUrl.GetUrl().c_str(), mTotalFrame, mFrameRate, this);
256 DALI_TRACE_END_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_LOTTIE_LOADING_TASK", [&](std::ostringstream& oss) {
257 mEndTimeNanoSceonds = GetNanoseconds();
258 oss << std::fixed << std::setprecision(3);
260 oss << "d:" << static_cast<float>(mEndTimeNanoSceonds - mStartTimeNanoSceonds) / 1000000.0f << "ms ";
261 oss << "u:" << mImageUrl.GetEllipsedUrl() << "]";
267 void VectorAnimationTask::SetRenderer(Renderer renderer)
269 mVectorRenderer.SetRenderer(renderer);
271 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetRenderer [%p]\n", this);
274 void VectorAnimationTask::RequestLoad(const VisualUrl& url, EncodedImageBuffer encodedImageBuffer, bool synchronousLoading)
277 mEncodedImageBuffer = encodedImageBuffer;
279 if(!synchronousLoading)
283 mVectorAnimationThread.AddTask(this);
293 bool VectorAnimationTask::IsLoadRequested() const
298 void VectorAnimationTask::SetAnimationData(const AnimationData& data)
300 Mutex::ScopedLock lock(mMutex);
302 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetAnimationData [%p]\n", this);
304 uint32_t index = mAnimationDataIndex == 0 ? 1 : 0; // Use the other buffer
306 mAnimationData[index].push_back(data);
307 mAnimationDataUpdated = true;
309 if(data.resendFlag & VectorAnimationTask::RESEND_SIZE)
311 // The size should be changed in the main thread.
312 SetSize(data.width, data.height);
315 mVectorAnimationThread.AddTask(this);
318 void VectorAnimationTask::SetSize(uint32_t width, uint32_t height)
320 if(mWidth != width || mHeight != height)
322 mVectorRenderer.SetSize(width, height);
327 // If fixedCache is enabled, Call KeepRasterizedBuffer()
328 if(mEnableFrameCache)
330 if(mTotalFrame > 0 && !mLoadFailed)
332 mVectorRenderer.KeepRasterizedBuffer();
336 // If Load is not yet, update the size later.
341 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetSize: width = %d, height = %d [%p]\n", width, height, this);
345 void VectorAnimationTask::PlayAnimation()
347 if(mPlayState != PlayState::PLAYING)
349 mNeedAnimationFinishedTrigger = true;
350 mUpdateFrameNumber = false;
351 mPlayState = PlayState::PLAYING;
353 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::PlayAnimation: Play [%p]\n", this);
357 void VectorAnimationTask::StopAnimation()
359 if(mPlayState != PlayState::STOPPING)
361 mNeedAnimationFinishedTrigger = false;
362 mPlayState = PlayState::STOPPING;
364 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::StopAnimation: Stop [%p]\n", this);
368 void VectorAnimationTask::PauseAnimation()
370 if(mPlayState == PlayState::PLAYING)
372 mPlayState = PlayState::PAUSED;
374 // Ensure to render paused frame.
375 mNeedForceRenderOnceTrigger = true;
377 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::PauseAnimation: Pause [%p]\n", this);
381 void VectorAnimationTask::SetAnimationFinishedCallback(CallbackBase* callback)
383 Mutex::ScopedLock lock(mMutex);
384 mAnimationFinishedCallback = std::unique_ptr<CallbackBase>(callback);
387 void VectorAnimationTask::SetLoopCount(int32_t count)
389 if(mLoopCount != count)
394 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetLoopCount: [%d] [%p]\n", count, this);
398 void VectorAnimationTask::SetPlayRange(const Property::Array& playRange)
401 uint32_t startFrame = 0, endFrame = 0;
402 size_t count = playRange.Count();
406 int32_t start = 0, end = 0;
407 if(playRange.GetElementAt(0).Get(start) && playRange.GetElementAt(1).Get(end))
409 startFrame = static_cast<uint32_t>(start);
410 endFrame = static_cast<uint32_t>(end);
415 std::string startMarker, endMarker;
416 if(playRange.GetElementAt(0).Get(startMarker) && playRange.GetElementAt(1).Get(endMarker))
420 uint32_t frame; // We don't use this later
421 if(mVectorRenderer.GetMarkerInfo(startMarker, startFrame, frame) && mVectorRenderer.GetMarkerInfo(endMarker, frame, endFrame))
432 if(playRange.GetElementAt(0).Get(marker))
434 if(mVectorRenderer && mVectorRenderer.GetMarkerInfo(marker, startFrame, endFrame))
443 DALI_LOG_ERROR("VectorAnimationTask::SetPlayRange: Invalid range [%p]\n", this);
447 // Make sure the range specified is between 0 and the total frame number
448 startFrame = std::min(startFrame, mTotalFrame - 1);
449 endFrame = std::min(endFrame, mTotalFrame - 1);
451 // If the range is not in order swap values
452 if(startFrame > endFrame)
454 uint32_t temp = startFrame;
455 startFrame = endFrame;
459 if(startFrame != mStartFrame || endFrame != mEndFrame)
461 mStartFrame = startFrame;
462 mEndFrame = endFrame;
464 // If the current frame is out of the range, change the current frame also.
465 if(mStartFrame > mCurrentFrame)
467 mCurrentFrame = mStartFrame;
469 if(mPlayState != PlayState::PLAYING)
471 // Ensure to render current frame.
472 mNeedForceRenderOnceTrigger = true;
475 else if(mEndFrame < mCurrentFrame)
477 mCurrentFrame = mEndFrame;
479 if(mPlayState != PlayState::PLAYING)
481 // Ensure to render current frame.
482 mNeedForceRenderOnceTrigger = true;
486 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetPlayRange: [%d, %d] [%s] [%p]\n", mStartFrame, mEndFrame, mImageUrl.GetUrl().c_str(), this);
490 void VectorAnimationTask::GetPlayRange(uint32_t& startFrame, uint32_t& endFrame)
492 startFrame = mStartFrame;
493 endFrame = mEndFrame;
496 void VectorAnimationTask::SetCurrentFrameNumber(uint32_t frameNumber)
498 if(mCurrentFrame == frameNumber)
500 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetCurrentFrameNumber: Set same frame [%d] [%p]\n", frameNumber, this);
504 if(frameNumber >= mStartFrame && frameNumber <= mEndFrame)
506 mCurrentFrame = frameNumber;
507 mUpdateFrameNumber = false;
509 if(mPlayState != PlayState::PLAYING)
511 // Ensure to render current frame.
512 mNeedForceRenderOnceTrigger = true;
515 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetCurrentFrameNumber: frame number = %d [%p]\n", mCurrentFrame, this);
519 DALI_LOG_ERROR("Invalid frame number [%d (%d, %d)] [%p]\n", frameNumber, mStartFrame, mEndFrame, this);
523 uint32_t VectorAnimationTask::GetCurrentFrameNumber() const
525 return mCurrentFrame;
528 uint32_t VectorAnimationTask::GetTotalFrameNumber() const
533 void VectorAnimationTask::GetDefaultSize(uint32_t& width, uint32_t& height) const
535 mVectorRenderer.GetDefaultSize(width, height);
538 void VectorAnimationTask::SetStopBehavior(DevelImageVisual::StopBehavior::Type stopBehavior)
540 mStopBehavior = stopBehavior;
542 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetStopBehavior: stop behavor = %d [%p]\n", mStopBehavior, this);
545 void VectorAnimationTask::SetLoopingMode(DevelImageVisual::LoopingMode::Type loopingMode)
547 mLoopingMode = loopingMode;
549 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetLoopingMode: looping mode = %d [%p]\n", mLoopingMode, this);
552 void VectorAnimationTask::GetLayerInfo(Property::Map& map) const
554 // Fast-out if file is loading, or load failed.
555 if(mLoadFailed || IsLoadRequested())
560 if(DALI_UNLIKELY(!mLayerInfoCached))
562 // Update only 1 time.
563 mLayerInfoCached = true;
564 mVectorRenderer.GetLayerInfo(mCachedLayerInfo);
567 map = mCachedLayerInfo;
570 void VectorAnimationTask::GetMarkerInfo(Property::Map& map) const
572 // Fast-out if file is loading, or load failed.
573 if(mLoadFailed || IsLoadRequested())
578 if(DALI_UNLIKELY(!mMarkerInfoCached))
580 // Update only 1 time.
581 mMarkerInfoCached = true;
582 mVectorRenderer.GetMarkerInfo(mCachedMarkerInfo);
585 map = mCachedMarkerInfo;
588 VectorAnimationTask::ResourceReadySignalType& VectorAnimationTask::ResourceReadySignal()
590 return mResourceReadySignal;
593 bool VectorAnimationTask::Rasterize()
595 bool stopped = false;
596 uint32_t currentFrame;
597 mKeepAnimation = false;
600 Mutex::ScopedLock lock(mMutex);
603 // The task will be destroyed. We don't need rasterization.
619 uint64_t mStartTimeNanoSceonds = 0;
620 uint64_t mEndTimeNanoSceonds = 0;
622 DALI_TRACE_BEGIN_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_LOTTIE_RASTERIZE_TASK", [&](std::ostringstream& oss) {
623 mStartTimeNanoSceonds = GetNanoseconds();
624 oss << "[s:" << mWidth << "x" << mHeight << " ";
625 oss << "u:" << mImageUrl.GetEllipsedUrl() << "]";
628 ApplyAnimationData();
630 if(mPlayState == PlayState::PLAYING && mUpdateFrameNumber)
632 mCurrentFrame = mForward ? mCurrentFrame + mDroppedFrames + 1 : (mCurrentFrame > mDroppedFrames ? mCurrentFrame - mDroppedFrames - 1 : 0);
633 Dali::ClampInPlace(mCurrentFrame, mStartFrame, mEndFrame);
636 currentFrame = mCurrentFrame;
638 mUpdateFrameNumber = true;
640 if(mPlayState == PlayState::STOPPING)
642 mCurrentFrame = GetStoppedFrame(mStartFrame, mEndFrame, mCurrentFrame);
643 currentFrame = mCurrentFrame;
646 else if(mPlayState == PlayState::PLAYING)
648 bool animationFinished = false;
650 if(currentFrame >= mEndFrame) // last frame
652 if(mLoopingMode == DevelImageVisual::LoopingMode::AUTO_REVERSE)
658 if(mLoopCount < 0 || ++mCurrentLoop < mLoopCount) // repeat forever or before the last loop
660 mCurrentFrame = mStartFrame;
661 mUpdateFrameNumber = false;
665 animationFinished = true; // end of animation
669 else if(currentFrame == mStartFrame && !mForward) // first frame
671 if(mLoopCount < 0 || ++mCurrentLoop < mLoopCount) // repeat forever or before the last loop
677 animationFinished = true; // end of animation
681 if(animationFinished)
683 if(mStopBehavior == DevelImageVisual::StopBehavior::CURRENT_FRAME)
689 mPlayState = PlayState::STOPPING;
695 bool renderSuccess = false;
698 renderSuccess = mVectorRenderer.Render(currentFrame);
701 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::Rasterize: Rendering failed. Try again later.[%d] [%p]\n", currentFrame, this);
702 mUpdateFrameNumber = false;
706 if(stopped && renderSuccess)
708 mPlayState = PlayState::STOPPED;
712 mNeedForceRenderOnceTrigger = true;
716 // Notify the Renderer that rendering is stopped.
717 mVectorRenderer.RenderStopped();
720 // Animation is finished
722 Mutex::ScopedLock lock(mMutex);
723 if(mNeedAnimationFinishedTrigger && mAnimationFinishedCallback)
725 mVectorAnimationThread.AddEventTriggerCallback(mAnimationFinishedCallback.get(), mAppliedPlayStateId);
729 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::Rasterize: Animation is finished [current = %d] [%p]\n", currentFrame, this);
732 // Forcely trigger render once if need.
733 if(mNotifyAfterRasterization || mNeedForceRenderOnceTrigger)
735 mVectorAnimationThread.RequestForceRenderOnce();
736 mNeedForceRenderOnceTrigger = false;
739 if(mPlayState != PlayState::PAUSED && mPlayState != PlayState::STOPPED)
741 mKeepAnimation = true;
744 DALI_TRACE_END_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_LOTTIE_RASTERIZE_TASK", [&](std::ostringstream& oss) {
745 mEndTimeNanoSceonds = GetNanoseconds();
746 oss << std::fixed << std::setprecision(3);
748 oss << "d:" << static_cast<float>(mEndTimeNanoSceonds - mStartTimeNanoSceonds) / 1000000.0f << "ms ";
749 oss << "s:" << mWidth << "x" << mHeight << " ";
750 oss << "f:" << mCurrentFrame << " ";
751 oss << "l:" << mCurrentLoop << " ";
752 oss << "p:" << mPlayState << " ";
753 oss << "u:" << mImageUrl.GetEllipsedUrl() << "]";
759 uint32_t VectorAnimationTask::GetStoppedFrame(uint32_t startFrame, uint32_t endFrame, uint32_t currentFrame)
761 uint32_t frame = currentFrame;
763 switch(mStopBehavior)
765 case DevelImageVisual::StopBehavior::FIRST_FRAME:
770 case DevelImageVisual::StopBehavior::LAST_FRAME:
772 if(mLoopingMode == DevelImageVisual::LoopingMode::AUTO_REVERSE)
782 case DevelImageVisual::StopBehavior::CURRENT_FRAME:
784 frame = currentFrame;
792 /// Event & VectorAnimationThread called after Rasterize() finished.
793 VectorAnimationTask::TimePoint VectorAnimationTask::CalculateNextFrameTime(bool renderNow)
795 // std::chrono::time_point template has second parameter duration which defaults to the std::chrono::steady_clock supported
796 // duration. In some C++11 implementations it is a milliseconds duration, so it fails to compile unless mNextFrameStartTime
797 // is casted to use the default duration.
798 auto current = std::chrono::steady_clock::now();
802 mNextFrameStartTime = current;
807 const auto durationMicroSeconds = std::chrono::microseconds(mFrameDurationMicroSeconds);
809 mNextFrameStartTime = std::chrono::time_point_cast<TimePoint::duration>(mNextFrameStartTime + durationMicroSeconds);
810 if(mNextFrameStartTime < current)
812 uint32_t droppedFrames = 0;
814 while(current > std::chrono::time_point_cast<TimePoint::duration>(mNextFrameStartTime + durationMicroSeconds) && droppedFrames < mTotalFrame)
817 mNextFrameStartTime = std::chrono::time_point_cast<TimePoint::duration>(mNextFrameStartTime + durationMicroSeconds);
820 mNextFrameStartTime = current;
821 mDroppedFrames = droppedFrames;
825 return mNextFrameStartTime;
828 VectorAnimationTask::TimePoint VectorAnimationTask::GetNextFrameTime()
830 return mNextFrameStartTime;
833 void VectorAnimationTask::ApplyAnimationData()
838 Mutex::ScopedLock lock(mMutex);
840 if(!mAnimationDataUpdated || mAnimationData[mAnimationDataIndex].size() != 0)
842 // Data is not updated or the previous data is not applied yet.
846 mAnimationDataIndex = mAnimationDataIndex == 0 ? 1 : 0; // Swap index
847 mAnimationDataUpdated = false;
849 index = mAnimationDataIndex;
852 for(const auto& animationData : mAnimationData[index])
854 if(animationData.resendFlag & VectorAnimationTask::RESEND_LOOP_COUNT)
856 SetLoopCount(animationData.loopCount);
859 if(animationData.resendFlag & VectorAnimationTask::RESEND_PLAY_RANGE)
861 SetPlayRange(animationData.playRange);
864 if(animationData.resendFlag & VectorAnimationTask::RESEND_STOP_BEHAVIOR)
866 SetStopBehavior(animationData.stopBehavior);
869 if(animationData.resendFlag & VectorAnimationTask::RESEND_LOOPING_MODE)
871 SetLoopingMode(animationData.loopingMode);
874 if(animationData.resendFlag & VectorAnimationTask::RESEND_CURRENT_FRAME)
876 SetCurrentFrameNumber(animationData.currentFrame);
879 if(animationData.resendFlag & VectorAnimationTask::RESEND_NOTIFY_AFTER_RASTERIZATION)
881 mNotifyAfterRasterization = animationData.notifyAfterRasterization;
884 if(animationData.resendFlag & VectorAnimationTask::RESEND_FRAME_SPEED_FACTOR)
886 mFrameSpeedFactor = animationData.frameSpeedFactor;
888 // Recalculate frame duration with new frame speed factor.
889 mFrameDurationMicroSeconds = CalculateFrameDurationMicroSeconds(mFrameRate, mFrameSpeedFactor);
892 if(animationData.resendFlag & VectorAnimationTask::RESEND_NEED_RESOURCE_READY)
894 mVectorRenderer.InvalidateBuffer();
897 if(animationData.resendFlag & VectorAnimationTask::RESEND_DYNAMIC_PROPERTY)
899 for(auto&& iter : animationData.dynamicProperties)
901 mVectorRenderer.AddPropertyValueCallback(iter.keyPath, static_cast<VectorAnimationRenderer::VectorProperty>(iter.property), iter.callback, iter.id);
905 if(animationData.resendFlag & VectorAnimationTask::RESEND_PLAY_STATE)
907 mAppliedPlayStateId = animationData.playStateId;
908 if(animationData.playState == DevelImageVisual::PlayState::PLAYING)
912 else if(animationData.playState == DevelImageVisual::PlayState::PAUSED)
916 else if(animationData.playState == DevelImageVisual::PlayState::STOPPED)
924 mAnimationData[index].clear();
927 void VectorAnimationTask::OnUploadCompleted()
929 mResourceReadySignal.Emit(ResourceStatus::READY);
932 void VectorAnimationTask::OnLoadCompleted(uint32_t /* not used */)
936 if(mEnableFrameCache && mSizeUpdated)
938 mVectorRenderer.KeepRasterizedBuffer();
939 mSizeUpdated = false;
941 mResourceReadySignal.Emit(ResourceStatus::LOADED);
945 mResourceReadySignal.Emit(ResourceStatus::FAILED);
948 } // namespace Internal
950 } // namespace Toolkit