diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2019-04-08 03:49:36 +0300 |
---|---|---|
committer | Rebecca Worledge <rebecca.worledge@theqtcompany.com> | 2019-04-08 16:17:28 +0000 |
commit | 0915ad743c60ec2bb7b0b21b53d6ee059794272b (patch) | |
tree | 281ad9c7cb465c4fc9572cef00de39653f5fb00b | |
parent | 12757c2b4ea2ccd35907a4b146766d3a5219e83d (diff) |
BatchRenderer: simplify the pre-rendering code
there is no point in running the noop loop to check if we need to wait
before running the pre-rendering loop
-> simply run the pre-rendering loop and then wait unconditionally
Change-Id: I112e9f2f37a14b809e704b04bcc2fd6fdcdd39ec
Reviewed-by: Rebecca Worledge <rebecca.worledge@theqtcompany.com>
-rw-r--r-- | src/imports/rasterrenderer/batchrenderer.cpp | 44 |
1 files changed, 7 insertions, 37 deletions
diff --git a/src/imports/rasterrenderer/batchrenderer.cpp b/src/imports/rasterrenderer/batchrenderer.cpp index 74722f9..5c4da48 100644 --- a/src/imports/rasterrenderer/batchrenderer.cpp +++ b/src/imports/rasterrenderer/batchrenderer.cpp @@ -159,14 +159,6 @@ void BatchRenderer::setCacheSize(int size) void BatchRenderer::prerender(Entry *animEntry) { - LottieAnimation *animator = animEntry->animator; - - if (animEntry->frameCache.count() == m_cacheSize) { - qCDebug(lcLottieQtBodymovinRenderThread) << "Animator:" << static_cast<void*>(animEntry->animator) - << "Cache full, cannot render more"; - return; - } - while (animEntry->frameCache.count() < m_cacheSize) { // It may be that the animator has deregistered itself while // te mutex was locked. In that case we cannot render here anymore @@ -188,7 +180,7 @@ void BatchRenderer::prerender(Entry *animEntry) << static_cast<void*>(animEntry->animator) << "Frame drawn to cache. FN:" << animEntry->currentFrame; - emit frameReady(animator, animEntry->currentFrame); + emit frameReady(animEntry->animator, animEntry->currentFrame); animEntry->currentFrame += animEntry->animDir; @@ -200,30 +192,6 @@ void BatchRenderer::prerender(Entry *animEntry) } } -void BatchRenderer::prerender() -{ - QMutexLocker mlocker(&m_mutex); - bool wait = true; - - foreach (Entry *e, m_animData) { - if (e->frameCache.size() < m_cacheSize) { - wait = false; - break; - } - } - - if (wait) - m_waitCondition.wait(&m_mutex); - - QHash<LottieAnimation*, Entry*>::iterator it = m_animData.begin(); - while (it != m_animData.end()) { - Entry *e = *it; - if (e && e->frameCache.size() < m_cacheSize) - prerender(e); - ++it; - } -} - void BatchRenderer::frameRendered(LottieAnimation *animator, int frameNumber) { Entry *entry = m_animData.value(animator, nullptr); @@ -243,11 +211,13 @@ void BatchRenderer::run() { qCDebug(lcLottieQtBodymovinRenderThread) << "rendering thread" << QThread::currentThread(); - while (-1) { - if (QThread::currentThread()->isInterruptionRequested()) - return; + while (!isInterruptionRequested()) { + QMutexLocker mlocker(&m_mutex); - prerender(); + for (Entry *e : qAsConst(m_animData)) + prerender(e); + + m_waitCondition.wait(&m_mutex); } } |