Krita Source Code Documentation
Loading...
Searching...
No Matches
KisAnimationFrameCache::Private Struct Reference

Classes

struct  Frame
 

Public Types

typedef QMap< KisOpenGLImageTexturesSP, KisAnimationFrameCache * > CachesMap
 

Public Member Functions

void addFrame (KisOpenGLUpdateInfoSP info, const KisTimeSpan &range)
 
int effectiveLevelOfDetail (const QRect &rc) const
 
KisOpenGLUpdateInfoSP fetchFrameDataImpl (KisImageSP image, const QRect &requestedRect, int lod)
 
KisOpenGLUpdateInfoSP getFrame (int time)
 
int getFrameIdAtTime (int time) const
 
bool hasFrame (int time) const
 
bool invalidate (const KisTimeSpan &range)
 
 Private (KisOpenGLImageTexturesSP _textures)
 
 ~Private ()
 

Public Attributes

int frameSizeLimit = 777
 
KisImageWSP image
 
QMap< int, int > newFrames
 
QScopedPointer< KisAbstractFrameCacheSwapperswapper
 
KisOpenGLImageTexturesSP textures
 

Static Public Attributes

static CachesMap caches
 

Detailed Description

Definition at line 33 of file kis_animation_frame_cache.cpp.

Member Typedef Documentation

◆ CachesMap

Constructor & Destructor Documentation

◆ Private()

KisAnimationFrameCache::Private::Private ( KisOpenGLImageTexturesSP _textures)
inline

◆ ~Private()

KisAnimationFrameCache::Private::~Private ( )
inline

Definition at line 41 of file kis_animation_frame_cache.cpp.

42 {
43 }

Member Function Documentation

◆ addFrame()

void KisAnimationFrameCache::Private::addFrame ( KisOpenGLUpdateInfoSP info,
const KisTimeSpan & range )
inline

Definition at line 103 of file kis_animation_frame_cache.cpp.

104 {
105 invalidate(range);
106
107 const int length = range.isInfinite() ? -1 : range.end() - range.start() + 1;
108 newFrames.insert(range.start(), length);
109 swapper->saveFrame(range.start(), info, image->bounds());
110 }
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
QRect bounds() const override
int start() const
bool isInfinite() const
int end() const
QScopedPointer< KisAbstractFrameCacheSwapper > swapper
bool invalidate(const KisTimeSpan &range)

References KisImage::bounds(), KisTimeSpan::end(), image, invalidate(), KisTimeSpan::isInfinite(), length(), newFrames, KisTimeSpan::start(), and swapper.

◆ effectiveLevelOfDetail()

int KisAnimationFrameCache::Private::effectiveLevelOfDetail ( const QRect & rc) const
inline

Definition at line 166 of file kis_animation_frame_cache.cpp.

166 {
167 if (!frameSizeLimit) return 0;
168
170
171 const qreal minLod = -std::log2(qreal(frameSizeLimit) / maxDimension);
172 const int lodLimit = qMax(0, qCeil(minLod));
173 return lodLimit;
174 }
auto maxDimension(Size size) -> decltype(size.width())

References frameSizeLimit, and KisAlgebra2D::maxDimension().

◆ fetchFrameDataImpl()

KisOpenGLUpdateInfoSP KisAnimationFrameCache::Private::fetchFrameDataImpl ( KisImageSP image,
const QRect & requestedRect,
int lod )

Definition at line 391 of file kis_animation_frame_cache.cpp.

392{
393 if (lod > 0) {
395 tempDevice->prepareClone(image->projection());
396 image->projection()->generateLodCloneDevice(tempDevice, image->projection()->extent(), lod);
397
398 const QRect fetchRect = KisLodTransform::alignedRect(requestedRect, lod);
399 return textures->updateInfoBuilder().buildUpdateInfo(fetchRect, tempDevice, image->bounds(), lod, true);
400 } else {
401 return textures->updateCache(requestedRect, image);
402 }
403}
KisPaintDeviceSP projection() const
static QRect alignedRect(const QRect &srcRect, int lod)
KisOpenGLUpdateInfoSP updateCache(const QRect &rect, KisImageSP srcImage)
KisOpenGLUpdateInfoBuilder & updateInfoBuilder()
QRect extent() const
void generateLodCloneDevice(KisPaintDeviceSP dst, const QRect &originalRect, int lod)
const KoColorSpace * colorSpace() const
void prepareClone(KisPaintDeviceSP src)
KisOpenGLUpdateInfoSP buildUpdateInfo(const QRect &rect, KisImageSP srcImage, bool convertColorSpace)

References KisLodTransformBase::alignedRect(), KisImage::bounds(), KisOpenGLUpdateInfoBuilder::buildUpdateInfo(), KisPaintDevice::colorSpace(), KisPaintDevice::extent(), KisPaintDevice::generateLodCloneDevice(), image, KisPaintDevice::prepareClone(), KisImage::projection(), textures, KisOpenGLImageTextures::updateCache(), and KisOpenGLImageTextures::updateInfoBuilder().

◆ getFrame()

KisOpenGLUpdateInfoSP KisAnimationFrameCache::Private::getFrame ( int time)
inline

Definition at line 97 of file kis_animation_frame_cache.cpp.

98 {
99 const int frameId = getFrameIdAtTime(time);
100 return frameId >= 0 ? swapper->loadFrame(frameId) : 0;
101 }

References getFrameIdAtTime(), and swapper.

◆ getFrameIdAtTime()

int KisAnimationFrameCache::Private::getFrameIdAtTime ( int time) const
inline

Definition at line 65 of file kis_animation_frame_cache.cpp.

66 {
67 if (newFrames.isEmpty()) return -1;
68
69 auto it = newFrames.upperBound(time);
70
71 if (it != newFrames.constBegin()) it--;
72
74 const int start = it.key();
75 const int length = it.value();
76
77 bool foundFrameValid = false;
78
79 if (length == -1) {
80 if (start <= time) {
81 foundFrameValid = true;
82 }
83 } else {
84 int end = start + length - 1;
85 if (start <= time && time <= end) {
86 foundFrameValid = true;
87 }
88 }
89
90 return foundFrameValid ? start : -1;
91 }
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, length(), and newFrames.

◆ hasFrame()

bool KisAnimationFrameCache::Private::hasFrame ( int time) const
inline

Definition at line 93 of file kis_animation_frame_cache.cpp.

93 {
94 return getFrameIdAtTime(time) >= 0;
95 }

References getFrameIdAtTime().

◆ invalidate()

bool KisAnimationFrameCache::Private::invalidate ( const KisTimeSpan & range)
inline

Invalidate any cached frames within the given time range.

Parameters
range
Returns
true if frames were invalidated, false if nothing was changed

Definition at line 117 of file kis_animation_frame_cache.cpp.

118 {
119 if (newFrames.isEmpty()) return false;
120
121 bool cacheChanged = false;
122
123 auto it = newFrames.lowerBound(range.start());
124 if (it.key() != range.start() && it != newFrames.begin()) it--;
125
126 while (it != newFrames.end()) {
127 const int start = it.key();
128 const int length = it.value();
129 const bool frameIsInfinite = (length == -1);
130 const int end = start + length - 1;
131
132 if (start >= range.start()) {
133 if (!range.isInfinite() && start > range.end()) {
134 break;
135 }
136
137 if (!range.isInfinite() && (frameIsInfinite || end > range.end())) {
138 // Reinsert with a later start
139 int newStart = range.end() + 1;
140 int newLength = frameIsInfinite ? -1 : (end - newStart + 1);
141
142 newFrames.insert(newStart, newLength);
143 swapper->moveFrame(start, newStart);
144 } else {
145 swapper->forgetFrame(start);
146 }
147
148 it = newFrames.erase(it);
149
150 cacheChanged = true;
151 continue;
152
153 } else if (frameIsInfinite || end >= range.start()) {
154 const int newEnd = range.start() - 1;
155 *it = newEnd - start + 1;
156
157 cacheChanged = true;
158 }
159
160 it++;
161 }
162
163 return cacheChanged;
164 }

References KisTimeSpan::end(), KisTimeSpan::isInfinite(), length(), newFrames, KisTimeSpan::start(), and swapper.

Member Data Documentation

◆ caches

KisAnimationFrameCache::Private::CachesMap KisAnimationFrameCache::Private::caches
static

Definition at line 179 of file kis_animation_frame_cache.cpp.

◆ frameSizeLimit

int KisAnimationFrameCache::Private::frameSizeLimit = 777

Definition at line 49 of file kis_animation_frame_cache.cpp.

◆ image

KisImageWSP KisAnimationFrameCache::Private::image

Definition at line 46 of file kis_animation_frame_cache.cpp.

◆ newFrames

QMap<int, int> KisAnimationFrameCache::Private::newFrames

Definition at line 63 of file kis_animation_frame_cache.cpp.

◆ swapper

QScopedPointer<KisAbstractFrameCacheSwapper> KisAnimationFrameCache::Private::swapper

Definition at line 48 of file kis_animation_frame_cache.cpp.

◆ textures

KisOpenGLImageTexturesSP KisAnimationFrameCache::Private::textures

Definition at line 45 of file kis_animation_frame_cache.cpp.


The documentation for this struct was generated from the following file: