2 * Copyright (c) 2021 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-rasterize-thread.h>
22 #include <dali/devel-api/adaptor-framework/thread-settings.h>
23 #include <dali/integration-api/adaptor-framework/adaptor.h>
24 #include <dali/integration-api/debug.h>
36 #if defined(DEBUG_ENABLED)
37 Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VECTOR_ANIMATION");
40 } // unnamed namespace
42 VectorRasterizeThread::VectorRasterizeThread()
46 mDestroyThread(false),
47 mIsThreadStarted(false),
48 mLogFactory(Dali::Adaptor::Get().GetLogFactory())
52 VectorRasterizeThread::~VectorRasterizeThread()
56 ConditionalWait::ScopedLock lock(mConditionalWait);
57 mDestroyThread = true;
58 mConditionalWait.Notify(lock);
61 DALI_LOG_INFO(gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::~VectorRasterizeThread: Join [%p]\n", this);
66 void VectorRasterizeThread::SetCompletedCallback(CallbackBase* callback)
68 ConditionalWait::ScopedLock lock(mConditionalWait);
70 mCompletedCallback = std::unique_ptr<CallbackBase>(callback);
73 void VectorRasterizeThread::AddTask(VectorAnimationTaskPtr task)
75 // Lock while adding task to the queue
76 ConditionalWait::ScopedLock lock(mConditionalWait);
81 mIsThreadStarted = true;
84 if(mRasterizeTasks.end() == std::find(mRasterizeTasks.begin(), mRasterizeTasks.end(), task))
86 mRasterizeTasks.push_back(task);
88 // wake up the animation thread
89 mConditionalWait.Notify(lock);
93 void VectorRasterizeThread::Run()
95 SetThreadName("VectorRasterizeThread");
96 mLogFactory.InstallLogFunction();
98 while(!mDestroyThread)
104 void VectorRasterizeThread::Rasterize()
106 VectorAnimationTaskPtr nextTask;
108 // Lock while popping task out from the queue
109 ConditionalWait::ScopedLock lock(mConditionalWait);
112 if(mRasterizeTasks.empty())
114 mConditionalWait.Wait(lock);
117 // pop out the next task from the queue
118 if(!mRasterizeTasks.empty())
120 std::vector<VectorAnimationTaskPtr>::iterator next = mRasterizeTasks.begin();
122 mRasterizeTasks.erase(next);
128 bool keepAnimation = nextTask->Rasterize();
130 if(mCompletedCallback)
132 CallbackBase::Execute(*mCompletedCallback, nextTask, keepAnimation);
137 } // namespace Internal
139 } // namespace Toolkit