Krita Source Code Documentation
Loading...
Searching...
No Matches
KisAsyncAnimationCacheRenderDialog.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2017 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
11#include <kis_time_span.h>
12#include <kis_image.h>
14
15namespace {
16
17QList<int> calcDirtyFramesList(KisAnimationFrameCacheSP cache, const KisTimeSpan &playbackRange)
18{
19 QList<int> result;
20
21 KisImageSP image = cache->image();
22 if (!image) return result;
23
25 if (!animation->hasAnimation()) return result;
26
27 if (playbackRange.isValid()) {
28 KIS_ASSERT_RECOVER_RETURN_VALUE(!playbackRange.isInfinite(), result);
29
30 // TODO: optimize check for fully-cached case
31 for (int frame = playbackRange.start(); frame <= playbackRange.end(); frame++) {
32 const KisTimeSpan stillFrameRange =
34
35 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(stillFrameRange.isValid(), result);
36
37 if (cache->frameStatus(stillFrameRange.start()) == KisAnimationFrameCache::Uncached) {
38 result.append(stillFrameRange.start());
39 } else {
40 cache->tryGlueSameFrames(stillFrameRange);
41 }
42
43 if (stillFrameRange.isInfinite()) {
44 break;
45 } else {
46 frame = stillFrameRange.end();
47 }
48 }
49 }
50
51 return result;
52}
53
54}
55
57{
58 int result = -1;
59
60 KisImageSP image = cache->image();
61 if (!image) return result;
62
64 if (!animation->hasAnimation()) return result;
65
66 if (playbackRange.isValid()) {
67 KIS_ASSERT_RECOVER_RETURN_VALUE(!playbackRange.isInfinite(), result);
68
69 // TODO: optimize check for fully-cached case
70 for (int frame = playbackRange.start(); frame <= playbackRange.end(); frame++) {
71 if (skipRange.contains(frame)) {
72 if (skipRange.isInfinite()) {
73 break;
74 } else {
75 frame = skipRange.end();
76 continue;
77 }
78 }
79
80 if (cache->frameStatus(frame) != KisAnimationFrameCache::Cached) {
81 result = frame;
82 break;
83 }
84 }
85 }
86
87 return result;
88}
89
90
102
104 : KisAsyncAnimationRenderDialogBase(i18n("Regenerating cache..."), cache->image(), busyWait),
105 m_d(new Private(cache, range))
106{
107}
108
113
115{
116 return calcDirtyFramesList(m_d->cache, m_d->range);
117}
118
124
126{
127 Q_UNUSED(image);
128 Q_UNUSED(frame);
129
130 KisAsyncAnimationCacheRenderer *cacheRenderer =
131 dynamic_cast<KisAsyncAnimationCacheRenderer*>(renderer);
132
133 KIS_SAFE_ASSERT_RECOVER_RETURN(cacheRenderer);
134
135 cacheRenderer->setFrameCache(m_d->cache);
136}
137
bool tryGlueSameFrames(const KisTimeSpan &range)
CacheStatus frameStatus(int time) const
KisAsyncAnimationRendererBase * createRenderer(KisImageSP image) override
create a renderer object linked to image
KisAsyncAnimationCacheRenderDialog(KisAnimationFrameCacheSP cache, const KisTimeSpan &range, int busyWait=200)
QList< int > calcDirtyFrames() const override
returns a list of frames that should be regenerated by the dialog
static int calcFirstDirtyFrame(KisAnimationFrameCacheSP cache, const KisTimeSpan &playbackRange, const KisTimeSpan &skipRange)
void initializeRendererForFrame(KisAsyncAnimationRendererBase *renderer, KisImageSP image, int frame) override
void setFrameCache(KisAnimationFrameCacheSP cache)
KisAsyncAnimationRenderDialogBase is a special class for rendering multiple frames of the image and p...
KisImageAnimationInterface * animationInterface() const
bool contains(int time) const
int start() const
bool isInfinite() const
static KisTimeSpan calculateIdenticalFramesRecursive(const KisNode *node, int time)
int end() const
bool isValid() const
#define KIS_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:85
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
Private(KisAnimationFrameCacheSP _cache, const KisTimeSpan &_range)