Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_onion_skin_cache.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QReadWriteLock>
10#include <QReadLocker>
11#include <QWriteLocker>
12
13
14#include "kis_paint_device.h"
16#include "kis_default_bounds.h"
17#include "kis_time_span.h"
18#include "kis_image.h"
19#include "KoColorSpace.h"
20
22
23
25{
27
28 int cacheTime = 0;
30 int framesHash = 0;
31 QReadWriteLock lock;
32
34 const KisRasterKeyframeChannel *keyframes = source->keyframeChannel();
35
36 const int time = source->defaultBounds()->currentTime();
37 const KisTimeSpan span = source->keyframeChannel()->identicalFrames(cacheTime);
38 const int seqNo = compositor->configSeqNo();
39 const int hash = keyframes->channelHash();
40
41 return span.contains(time) && cacheConfigSeqNo == seqNo && framesHash == hash;
42 }
43
45 const KisRasterKeyframeChannel *keyframes = source->keyframeChannel();
46
47 const int time = source->defaultBounds()->currentTime();
48 const int seqNo = compositor->configSeqNo();
49 const int hash = keyframes->channelHash();
50
51 cacheTime = time;
52 cacheConfigSeqNo = seqNo;
53 framesHash = hash;
54 }
55};
56
61
65
67{
69
70 KisPaintDeviceSP cachedProjection;
71
72 QReadLocker readLocker(&m_d->lock);
73 cachedProjection = m_d->cachedProjection;
74
75
76 if (!cachedProjection || !m_d->checkCacheValid(source, compositor)) {
77
78 readLocker.unlock();
79 QWriteLocker writeLocker(&m_d->lock);
80 cachedProjection = m_d->cachedProjection;
81 if (!cachedProjection ||
82 !m_d->checkCacheValid(source, compositor) ||
83 *cachedProjection->colorSpace() != *source->colorSpace()) {
84
85 if (!cachedProjection) {
86 cachedProjection = new KisPaintDevice(source->colorSpace());
87 } else {
88 cachedProjection->setDefaultBounds(new KisDefaultBounds());
89 cachedProjection->clear();
90
91 if (*cachedProjection->colorSpace() != *source->colorSpace()) {
92 cachedProjection->convertTo(source->colorSpace());
93 }
94 }
95
96 const QRect extent = compositor->calculateExtent(source);
97 compositor->composite(source, cachedProjection, extent);
98
99 cachedProjection->setDefaultBounds(source->defaultBounds());
100
106 const int lod = source->defaultBounds()->currentLevelOfDetail();
107 if (lod > 0) {
108 QScopedPointer<KisPaintDevice::LodDataStruct> data(cachedProjection->createLodDataStruct(lod));
109 cachedProjection->updateLodDataStruct(data.data(), extent);
110 cachedProjection->uploadLodDataStruct(data.data());
111 }
112
113 m_d->updateCacheMetrics(source, compositor);
114 m_d->cachedProjection = cachedProjection;
115 }
116 }
117
118 return cachedProjection;
119}
120
122{
123 QWriteLocker writeLocker(&m_d->lock);
124 m_d->cachedProjection = 0;
125}
126
128{
129 return m_d->cachedProjection;
130}
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
int channelHash() const
Calculates a pseudo-unique hash based on the relevant internal state of the channel.
KisPaintDeviceSP lodCapableDevice() const
KisPaintDeviceSP projection(KisPaintDeviceSP source)
const QScopedPointer< Private > m_d
QRect calculateExtent(const KisPaintDeviceSP device, int time)
void composite(const KisPaintDeviceSP sourceDevice, KisPaintDeviceSP targetDevice, const QRect &rect)
static KisOnionSkinCompositor * instance()
void uploadLodDataStruct(LodDataStruct *dst)
virtual void clear()
void setDefaultBounds(KisDefaultBoundsBaseSP bounds)
LodDataStruct * createLodDataStruct(int lod)
void updateLodDataStruct(LodDataStruct *dst, const QRect &srcRect)
const KoColorSpace * colorSpace() const
void convertTo(const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent=KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::ConversionFlags conversionFlags=KoColorConversionTransformation::internalConversionFlags(), KUndo2Command *parentCommand=nullptr, KoUpdater *progressUpdater=nullptr)
The KisRasterKeyframeChannel is a concrete KisKeyframeChannel subclass that stores and manages KisRas...
bool contains(int time) const
void updateCacheMetrics(KisPaintDeviceSP source, KisOnionSkinCompositor *compositor)
bool checkCacheValid(KisPaintDeviceSP source, KisOnionSkinCompositor *compositor)