#include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h>
// EXTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/file-loader.h>
#include <dali/integration-api/debug.h>
+#include <dali/integration-api/trace.h>
#include <dali/public-api/math/math-utils.h>
#include <dali/public-api/object/property-array.h>
#include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h>
#include <dali-toolkit/internal/visuals/image-visual-shader-factory.h>
+#ifdef TRACE_ENABLED
+#include <sstream>
+#endif
+
namespace Dali
{
namespace Toolkit
Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VECTOR_ANIMATION");
#endif
+DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_IMAGE_PERFORMANCE_MARKER, false);
+
} // unnamed namespace
VectorAnimationTask::VectorAnimationTask(VisualFactoryCache& factoryCache)
: AsyncTask(MakeCallback(this, &VectorAnimationTask::TaskCompleted), AsyncTask::PriorityType::HIGH, AsyncTask::ThreadType::WORKER_THREAD),
- mUrl(),
+ mImageUrl(),
+ mEncodedImageBuffer(),
mVectorRenderer(VectorAnimationRenderer::New()),
mAnimationData(),
mVectorAnimationThread(factoryCache.GetVectorAnimationManager().GetVectorAnimationThread()),
mConditionalWait(),
mResourceReadySignal(),
- mAnimationFinishedTrigger(),
- mLoadCompletedTrigger(new EventThreadCallback(MakeCallback(this, &VectorAnimationTask::OnLoadCompleted))),
+ mLoadCompletedCallback(MakeCallback(this, &VectorAnimationTask::OnLoadCompleted)),
+ mCachedLayerInfo(),
+ mCachedMarkerInfo(),
mPlayState(PlayState::STOPPED),
mStopBehavior(DevelImageVisual::StopBehavior::CURRENT_FRAME),
mLoopingMode(DevelImageVisual::LoopingMode::RESTART),
mLoadRequest(false),
mLoadFailed(false),
mRasterized(false),
- mKeepAnimation(false)
+ mKeepAnimation(false),
+ mLayerInfoCached(false),
+ mMarkerInfoCached(false)
{
mVectorRenderer.UploadCompletedSignal().Connect(this, &VectorAnimationTask::OnUploadCompleted);
}
ConditionalWait::ScopedLock lock(mConditionalWait);
// Release some objects in the main thread
- if(mAnimationFinishedTrigger)
+ if(mAnimationFinishedCallback)
{
- mAnimationFinishedTrigger.reset();
+ mVectorAnimationThread.RemoveEventTriggerCallback(mAnimationFinishedCallback.get());
+ mAnimationFinishedCallback.reset();
}
- if(mLoadCompletedTrigger)
+ if(mLoadCompletedCallback)
{
- mLoadCompletedTrigger.reset();
+ mVectorAnimationThread.RemoveEventTriggerCallback(mLoadCompletedCallback.get());
+ mLoadCompletedCallback.reset();
}
mVectorRenderer.Finalize();
bool VectorAnimationTask::Load(bool synchronousLoading)
{
- if(!mVectorRenderer.Load(mUrl))
+#ifdef TRACE_ENABLED
+ if(gTraceFilter && gTraceFilter->IsTraceEnabled())
+ {
+ std::ostringstream oss;
+ oss << "[url:" << mImageUrl.GetUrl() << "]";
+ // DALI_TRACE_BEGIN(gTraceFilter, "DALI_LOTTIE_LOADING_TASK"); ///< TODO : Open it if we can control trace log level
+ DALI_LOG_RELEASE_INFO("BEGIN: DALI_LOTTIE_LOADING_TASK %s", oss.str().c_str());
+ }
+#endif
+
+ if(mEncodedImageBuffer)
+ {
+ if(!mVectorRenderer.Load(mEncodedImageBuffer.GetRawBuffer()))
+ {
+ mLoadFailed = true;
+ }
+
+ // We don't need to hold image buffer anymore.
+ mEncodedImageBuffer.Reset();
+ }
+ else if(mImageUrl.IsLocalResource())
+ {
+ if(!mVectorRenderer.Load(mImageUrl.GetUrl()))
+ {
+ mLoadFailed = true;
+ }
+ }
+ else
+ {
+ Dali::Vector<uint8_t> remoteData;
+ if(!Dali::FileLoader::DownloadFileSynchronously(mImageUrl.GetUrl(), remoteData) || // Failed if we fail to download json file,
+ !mVectorRenderer.Load(remoteData)) // or download data is not valid vector animation file.
+ {
+ mLoadFailed = true;
+ }
+ }
+
+ if(mLoadFailed)
{
- DALI_LOG_ERROR("VectorAnimationTask::Load: Load failed [%s]\n", mUrl.c_str());
+ DALI_LOG_ERROR("VectorAnimationTask::Load: Load failed [%s]\n", mImageUrl.GetUrl().c_str());
mLoadRequest = false;
- mLoadFailed = true;
- if(!synchronousLoading)
+ if(!synchronousLoading && mLoadCompletedCallback)
{
- mLoadCompletedTrigger->Trigger();
+ mVectorAnimationThread.AddEventTriggerCallback(mLoadCompletedCallback.get());
}
+#ifdef TRACE_ENABLED
+ if(gTraceFilter && gTraceFilter->IsTraceEnabled())
+ {
+ std::ostringstream oss;
+ oss << "[url:" << mImageUrl.GetUrl() << "]";
+ // DALI_TRACE_END(gTraceFilter, "DALI_LOTTIE_LOADING_TASK"); ///< TODO : Open it if we can control trace log level
+ DALI_LOG_RELEASE_INFO("END: DALI_LOTTIE_LOADING_TASK %s", oss.str().c_str());
+ }
+#endif
return false;
}
mFrameDurationMicroSeconds = MICROSECONDS_PER_SECOND / mFrameRate;
mLoadRequest = false;
- if(!synchronousLoading)
+ if(!synchronousLoading && mLoadCompletedCallback)
{
- mLoadCompletedTrigger->Trigger();
+ mVectorAnimationThread.AddEventTriggerCallback(mLoadCompletedCallback.get());
}
- DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::Load: file = %s [%d frames, %f fps] [%p]\n", mUrl.c_str(), mTotalFrame, mFrameRate, this);
+ DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::Load: file = %s [%d frames, %f fps] [%p]\n", mImageUrl.GetUrl().c_str(), mTotalFrame, mFrameRate, this);
+
+#ifdef TRACE_ENABLED
+ if(gTraceFilter && gTraceFilter->IsTraceEnabled())
+ {
+ std::ostringstream oss;
+ oss << "[url:" << mImageUrl.GetUrl() << "]";
+ // DALI_TRACE_END(gTraceFilter, "DALI_LOTTIE_LOADING_TASK"); ///< TODO : Open it if we can control trace log level
+ DALI_LOG_RELEASE_INFO("END: DALI_LOTTIE_LOADING_TASK %s", oss.str().c_str());
+ }
+#endif
return true;
}
DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetRenderer [%p]\n", this);
}
-void VectorAnimationTask::RequestLoad(const std::string& url, bool synchronousLoading)
+void VectorAnimationTask::RequestLoad(const VisualUrl& url, EncodedImageBuffer encodedImageBuffer, bool synchronousLoading)
{
- mUrl = url;
+ mImageUrl = url;
+ mEncodedImageBuffer = encodedImageBuffer;
if(!synchronousLoading)
{
uint32_t index = mAnimationDataIndex == 0 ? 1 : 0; // Use the other buffer
- mAnimationData[index] = data;
+ mAnimationData[index].push_back(data);
mAnimationDataUpdated = true;
if(data.resendFlag & VectorAnimationTask::RESEND_SIZE)
}
}
-void VectorAnimationTask::SetAnimationFinishedCallback(EventThreadCallback* callback)
+void VectorAnimationTask::SetAnimationFinishedCallback(CallbackBase* callback)
{
ConditionalWait::ScopedLock lock(mConditionalWait);
- if(callback)
- {
- mAnimationFinishedTrigger = std::unique_ptr<EventThreadCallback>(callback);
- }
+ mAnimationFinishedCallback = std::unique_ptr<CallbackBase>(callback);
}
void VectorAnimationTask::SetLoopCount(int32_t count)
mCurrentFrame = mEndFrame;
}
- DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetPlayRange: [%d, %d] [%s] [%p]\n", mStartFrame, mEndFrame, mUrl.c_str(), this);
+ DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorAnimationTask::SetPlayRange: [%d, %d] [%s] [%p]\n", mStartFrame, mEndFrame, mImageUrl.GetUrl().c_str(), this);
}
}
void VectorAnimationTask::GetLayerInfo(Property::Map& map) const
{
- mVectorRenderer.GetLayerInfo(map);
+ // Fast-out if file is loading, or load failed.
+ if(mLoadFailed || IsLoadRequested())
+ {
+ return;
+ }
+
+ if(DALI_UNLIKELY(!mLayerInfoCached))
+ {
+ // Update only 1 time.
+ mLayerInfoCached = true;
+ mVectorRenderer.GetLayerInfo(mCachedLayerInfo);
+ }
+
+ map = mCachedLayerInfo;
+}
+
+void VectorAnimationTask::GetMarkerInfo(Property::Map& map) const
+{
+ // Fast-out if file is loading, or load failed.
+ if(mLoadFailed || IsLoadRequested())
+ {
+ return;
+ }
+
+ if(DALI_UNLIKELY(!mMarkerInfoCached))
+ {
+ // Update only 1 time.
+ mMarkerInfoCached = true;
+ mVectorRenderer.GetMarkerInfo(mCachedMarkerInfo);
+ }
+
+ map = mCachedMarkerInfo;
}
VectorAnimationTask::ResourceReadySignalType& VectorAnimationTask::ResourceReadySignal()
return false;
}
+#ifdef TRACE_ENABLED
+ if(gTraceFilter && gTraceFilter->IsTraceEnabled())
+ {
+ std::ostringstream oss;
+ oss << "[size:" << mWidth << "x" << mHeight << " ";
+ oss << "url:" << mImageUrl.GetUrl() << "]";
+ DALI_TRACE_BEGIN_WITH_MESSAGE(gTraceFilter, "DALI_LOTTIE_RASTERIZE_TASK", oss.str().c_str());
+ }
+#endif
+
ApplyAnimationData();
if(mPlayState == PlayState::PLAYING && mUpdateFrameNumber)
// Animation is finished
{
ConditionalWait::ScopedLock lock(mConditionalWait);
- if(mNeedAnimationFinishedTrigger && mAnimationFinishedTrigger)
+ if(mNeedAnimationFinishedTrigger && mAnimationFinishedCallback)
{
- mAnimationFinishedTrigger->Trigger();
+ mVectorAnimationThread.AddEventTriggerCallback(mAnimationFinishedCallback.get());
}
}
mKeepAnimation = true;
}
+#ifdef TRACE_ENABLED
+ if(gTraceFilter && gTraceFilter->IsTraceEnabled())
+ {
+ std::ostringstream oss;
+ oss << "[size:" << mWidth << "x" << mHeight << " ";
+ oss << "frame:" << mCurrentFrame << " ";
+ oss << "loop:" << mCurrentLoop << " ";
+ oss << "state:" << mPlayState << " ";
+ oss << "url:" << mImageUrl.GetUrl() << "]";
+ DALI_TRACE_END_WITH_MESSAGE(gTraceFilter, "DALI_LOTTIE_RASTERIZE_TASK", oss.str().c_str());
+ }
+#endif
+
return true;
}
{
ConditionalWait::ScopedLock lock(mConditionalWait);
- if(!mAnimationDataUpdated || mAnimationData[mAnimationDataIndex].resendFlag != 0)
+ if(!mAnimationDataUpdated || mAnimationData[mAnimationDataIndex].size() != 0)
{
// Data is not updated or the previous data is not applied yet.
return;
index = mAnimationDataIndex;
}
- if(mAnimationData[index].resendFlag & VectorAnimationTask::RESEND_LOOP_COUNT)
+ for(const auto& animationData : mAnimationData[index])
{
- SetLoopCount(mAnimationData[index].loopCount);
- }
-
- if(mAnimationData[index].resendFlag & VectorAnimationTask::RESEND_PLAY_RANGE)
- {
- SetPlayRange(mAnimationData[index].playRange);
- }
-
- if(mAnimationData[index].resendFlag & VectorAnimationTask::RESEND_STOP_BEHAVIOR)
- {
- SetStopBehavior(mAnimationData[index].stopBehavior);
- }
+ if(animationData.resendFlag & VectorAnimationTask::RESEND_LOOP_COUNT)
+ {
+ SetLoopCount(animationData.loopCount);
+ }
- if(mAnimationData[index].resendFlag & VectorAnimationTask::RESEND_LOOPING_MODE)
- {
- SetLoopingMode(mAnimationData[index].loopingMode);
- }
+ if(animationData.resendFlag & VectorAnimationTask::RESEND_PLAY_RANGE)
+ {
+ SetPlayRange(animationData.playRange);
+ }
- if(mAnimationData[index].resendFlag & VectorAnimationTask::RESEND_CURRENT_FRAME)
- {
- SetCurrentFrameNumber(mAnimationData[index].currentFrame);
- }
+ if(animationData.resendFlag & VectorAnimationTask::RESEND_STOP_BEHAVIOR)
+ {
+ SetStopBehavior(animationData.stopBehavior);
+ }
- if(mAnimationData[index].resendFlag & VectorAnimationTask::RESEND_NEED_RESOURCE_READY)
- {
- mVectorRenderer.InvalidateBuffer();
- }
+ if(animationData.resendFlag & VectorAnimationTask::RESEND_LOOPING_MODE)
+ {
+ SetLoopingMode(animationData.loopingMode);
+ }
- if(mAnimationData[index].resendFlag & VectorAnimationTask::RESEND_DYNAMIC_PROPERTY)
- {
- for(auto&& iter : mAnimationData[index].dynamicProperties)
+ if(animationData.resendFlag & VectorAnimationTask::RESEND_CURRENT_FRAME)
{
- mVectorRenderer.AddPropertyValueCallback(iter.keyPath, static_cast<VectorAnimationRenderer::VectorProperty>(iter.property), iter.callback, iter.id);
+ SetCurrentFrameNumber(animationData.currentFrame);
}
- }
- if(mAnimationData[index].resendFlag & VectorAnimationTask::RESEND_PLAY_STATE)
- {
- if(mAnimationData[index].playState == DevelImageVisual::PlayState::PLAYING)
+ if(animationData.resendFlag & VectorAnimationTask::RESEND_NEED_RESOURCE_READY)
{
- PlayAnimation();
+ mVectorRenderer.InvalidateBuffer();
}
- else if(mAnimationData[index].playState == DevelImageVisual::PlayState::PAUSED)
+
+ if(animationData.resendFlag & VectorAnimationTask::RESEND_DYNAMIC_PROPERTY)
{
- PauseAnimation();
+ for(auto&& iter : animationData.dynamicProperties)
+ {
+ mVectorRenderer.AddPropertyValueCallback(iter.keyPath, static_cast<VectorAnimationRenderer::VectorProperty>(iter.property), iter.callback, iter.id);
+ }
}
- else if(mAnimationData[index].playState == DevelImageVisual::PlayState::STOPPED)
+
+ if(animationData.resendFlag & VectorAnimationTask::RESEND_PLAY_STATE)
{
- StopAnimation();
+ if(animationData.playState == DevelImageVisual::PlayState::PLAYING)
+ {
+ PlayAnimation();
+ }
+ else if(animationData.playState == DevelImageVisual::PlayState::PAUSED)
+ {
+ PauseAnimation();
+ }
+ else if(animationData.playState == DevelImageVisual::PlayState::STOPPED)
+ {
+ StopAnimation();
+ }
}
}
- // reset data
- mAnimationData[index].dynamicProperties.clear();
- mAnimationData[index].resendFlag = 0;
+ // reset data list
+ mAnimationData[index].clear();
}
void VectorAnimationTask::OnUploadCompleted()