2 * Copyright (c) 2018 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-image-rasterize-thread.h>
22 #include <dali/devel-api/adaptor-framework/thread-settings.h>
23 #include <dali/integration-api/adaptors/adaptor.h>
24 #include <dali/integration-api/debug.h>
40 #if defined(DEBUG_ENABLED)
41 Debug::Filter* gVectorAnimationLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_VECTOR_ANIMATION" );
44 } // unnamed namespace
46 VectorRasterizeThread::VectorRasterizeThread( const std::string& url, Renderer renderer, uint32_t width, uint32_t height )
49 mResourceReadyTrigger( NULL ),
57 mDestroyThread( false ),
58 mResourceReady( false ),
59 mLogFactory( Dali::Adaptor::Get().GetLogFactory() )
61 mVectorRenderer = VectorAnimationRenderer::New( mUrl, renderer, width, height );
64 VectorRasterizeThread::~VectorRasterizeThread()
68 ConditionalWait::ScopedLock lock( mConditionalWait );
69 mDestroyThread = true;
70 mConditionalWait.Notify( lock );
72 // This should be called in the main thread to stop waiting for the dequeuable buffer.
73 mVectorRenderer.StopRender();
76 DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::~VectorRasterizeThread: Join\n" );
80 delete mResourceReadyTrigger;
83 void VectorRasterizeThread::Run()
85 SetThreadName( "VectorImageThread" );
86 mLogFactory.InstallLogFunction();
88 //TODO: check the return value
91 while( IsThreadReady() )
97 void VectorRasterizeThread::StartAnimation()
99 ConditionalWait::ScopedLock lock( mConditionalWait );
104 mConditionalWait.Notify( lock );
106 DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StartAnimation: Start\n" );
110 void VectorRasterizeThread::StopAnimation()
112 ConditionalWait::ScopedLock lock( mConditionalWait );
118 DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StopAnimation: Stop\n" );
122 void VectorRasterizeThread::PauseAnimation()
124 ConditionalWait::ScopedLock lock( mConditionalWait );
125 if( mPlaying && !mPaused )
129 DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::PauseAnimation: Pause\n" );
133 void VectorRasterizeThread::ResumeAnimation()
135 ConditionalWait::ScopedLock lock( mConditionalWait );
136 if( mPlaying && mPaused )
139 mConditionalWait.Notify( lock );
141 DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::ResumeAnimation: Resume\n" );
145 void VectorRasterizeThread::RenderFrame()
147 ConditionalWait::ScopedLock lock( mConditionalWait );
149 mConditionalWait.Notify( lock );
151 DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::RenderFrame: Render\n" );
154 void VectorRasterizeThread::SetResourceReadyCallback( EventThreadCallback* callback )
156 mResourceReadyTrigger = callback;
159 bool VectorRasterizeThread::IsThreadReady()
161 ConditionalWait::ScopedLock lock( mConditionalWait );
163 if( ( !mPlaying || mPaused ) && !mNeedRender && !mDestroyThread )
165 DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::IsThreadReady: Wait\n" );
172 mConditionalWait.Wait( lock );
175 // Keep the thread alive if this thread is NOT to be destroyed
176 return !mDestroyThread;
179 bool VectorRasterizeThread::StartRender()
181 //TODO: check the return value
182 mVectorRenderer.StartRender();
184 mTotalFrame = mVectorRenderer.GetTotalFrameNumber();
186 DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::StartRender: Renderer is started [%d]\n", mTotalFrame );
191 void VectorRasterizeThread::Rasterize()
193 DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: [%d]\n", mCurrentFrame );
196 mVectorRenderer.Render( mCurrentFrame );
198 if( mPlaying && !mPaused )
202 if( mCurrentFrame >= mTotalFrame )
210 if( !mResourceReady )
212 DALI_LOG_INFO( gVectorAnimationLogFilter, Debug::Verbose, "VectorRasterizeThread::Rasterize: Resource ready trigger\n" );
214 mResourceReadyTrigger->Trigger();
215 mResourceReady = true;
219 } // namespace Internal
221 } // namespace Toolkit