Krita Source Code Documentation
Loading...
Searching...
No Matches
KisDabCache Class Reference

The KisDabCache class provides caching for dabs into the brush paintop. More...

#include <kis_dab_cache.h>

+ Inheritance diagram for KisDabCache:

Classes

struct  Private
 

Public Member Functions

KisFixedPaintDeviceSP fetchDab (const KoColorSpace *cs, const KoColor &color, const QPointF &cursorPoint, KisDabShape const &, const KisPaintInformation &info, qreal softnessFactor, QRect *dstDabRect, qreal lightnessStrength=1.0)
 
KisFixedPaintDeviceSP fetchDab (const KoColorSpace *cs, KisColorSource *colorSource, const QPointF &cursorPoint, KisDabShape const &, const KisPaintInformation &info, qreal softnessFactor, QRect *dstDabRect, qreal lightnessStrength=1.0)
 
KisFixedPaintDeviceSP fetchNormalizedImageDab (const KoColorSpace *cs, const QPointF &cursorPoint, KisDabShape const &shape, const KisPaintInformation &info, qreal softnessFactor, QRect *dstDabRect)
 
 KisDabCache (KisBrushSP brush)
 
bool needSeparateOriginal () const
 
void setSharpnessPostprocessing (KisSharpnessOption *option)
 
void setTexturePostprocessing (KisTextureOption *option)
 
 ~KisDabCache ()
 
- Public Member Functions inherited from KisDabCacheBase
void disableSubpixelPrecision ()
 
 KisDabCacheBase ()
 
bool needSeparateOriginal (KisTextureOption *textureOption, KisSharpnessOption *sharpnessOption) const
 
void setMirrorPostprocessing (KisMirrorOption *option)
 
void setPrecisionOption (KisPrecisionOption *option)
 
 ~KisDabCacheBase ()
 

Private Member Functions

KisFixedPaintDeviceSP fetchDabCommon (const KoColorSpace *cs, KisColorSource *colorSource, const KoColor &color, const QPointF &cursorPoint, KisDabShape, const KisPaintInformation &info, qreal softnessFactor, QRect *dstDabRect, qreal lightnessStrength=1.0, bool forceNormalizedRGBAImageStamp=false)
 
KisFixedPaintDeviceSP fetchFromCache (KisDabCacheUtils::DabRenderingResources *resources, const KisPaintInformation &info, QRect *dstDabRect)
 

Private Attributes

Private *const m_d
 

Additional Inherited Members

- Protected Member Functions inherited from KisDabCacheBase
void fetchDabGenerationInfo (bool hasDabInCache, KisDabCacheUtils::DabRenderingResources *resources, const KisDabCacheUtils::DabRequestInfo &request, KisDabCacheUtils::DabGenerationInfo *di, bool *shouldUseCache)
 

Detailed Description

The KisDabCache class provides caching for dabs into the brush paintop.

This class adds caching of the dabs to the paintop system of Krita. Such cache makes the execution of the benchmarks up to 2 times faster. Subjectively, the real painting becomes much faster, especially with huge brushes. Artists report up to 20% speed gain while painting.

Of course, such caching makes the painting a bit less precise: we need to tolerate subpixel differences to allow the cache to work. Sometimes small difference in the size of a dab can also be acceptable. That is why I introduced levels of precision. They are graded from 1 to 5: from the fastest and less precise to the slowest, but with the best quality. You can see the slider in the paintop settings dialog. The ToolTip text explains which features of the brush are sacrificed on each precision level.

The texturing and mirroring problems are solved.

Definition at line 41 of file kis_dab_cache.h.

Constructor & Destructor Documentation

◆ KisDabCache()

KisDabCache::KisDabCache ( KisBrushSP brush)

Definition at line 39 of file kis_dab_cache.cpp.

40 : m_d(new Private(brush))
41{
42}
Private *const m_d

◆ ~KisDabCache()

KisDabCache::~KisDabCache ( )

Definition at line 44 of file kis_dab_cache.cpp.

45{
46 delete m_d;
47}

References m_d.

Member Function Documentation

◆ fetchDab() [1/2]

KisFixedPaintDeviceSP KisDabCache::fetchDab ( const KoColorSpace * cs,
const KoColor & color,
const QPointF & cursorPoint,
KisDabShape const & shape,
const KisPaintInformation & info,
qreal softnessFactor,
QRect * dstDabRect,
qreal lightnessStrength = 1.0 )

Definition at line 85 of file kis_dab_cache.cpp.

93{
94 return fetchDabCommon(cs, 0, color,
95 cursorPoint,
96 shape,
97 info,
98 softnessFactor,
99 dstDabRect,
100 lightnessStrength);
101}
KisFixedPaintDeviceSP fetchDabCommon(const KoColorSpace *cs, KisColorSource *colorSource, const KoColor &color, const QPointF &cursorPoint, KisDabShape, const KisPaintInformation &info, qreal softnessFactor, QRect *dstDabRect, qreal lightnessStrength=1.0, bool forceNormalizedRGBAImageStamp=false)

References fetchDabCommon().

◆ fetchDab() [2/2]

KisFixedPaintDeviceSP KisDabCache::fetchDab ( const KoColorSpace * cs,
KisColorSource * colorSource,
const QPointF & cursorPoint,
KisDabShape const & shape,
const KisPaintInformation & info,
qreal softnessFactor,
QRect * dstDabRect,
qreal lightnessStrength = 1.0 )

Definition at line 65 of file kis_dab_cache.cpp.

73{
74 //Q_UNUSED(lightnessStrength);
75
76 return fetchDabCommon(cs, colorSource, KoColor(),
77 cursorPoint,
78 shape,
79 info,
80 softnessFactor,
81 dstDabRect,
82 lightnessStrength);
83}

References fetchDabCommon().

◆ fetchDabCommon()

KisFixedPaintDeviceSP KisDabCache::fetchDabCommon ( const KoColorSpace * cs,
KisColorSource * colorSource,
const KoColor & color,
const QPointF & cursorPoint,
KisDabShape shape,
const KisPaintInformation & info,
qreal softnessFactor,
QRect * dstDabRect,
qreal lightnessStrength = 1.0,
bool forceNormalizedRGBAImageStamp = false )
inlineprivate

Definition at line 153 of file kis_dab_cache.cpp.

163{
164 Q_ASSERT(dstDabRect);
165 //Q_UNUSED(lightnessStrength);
166
167 bool hasDabInCache = true;
168
169 if (!m_d->dab || *m_d->dab->colorSpace() != *cs) {
170 m_d->dab = new KisFixedPaintDevice(cs);
171 hasDabInCache = false;
172 }
173
174 using namespace KisDabCacheUtils;
175
176 // 0. Notify brush that we ar going to paint a new dab
177
178 m_d->brush->prepareForSeqNo(info, m_d->seqNo);
179 m_d->seqNo++;
180
181 // 1. Calculate new dab parameters and whether we can reuse the cache
182
184 resources.brush = m_d->brush;
186
187 // NOTE: we use a special subclass of resources that will NOT
188 // delete options on destruction!
189 resources.colorSource.reset(colorSource);
190 resources.sharpnessOption.reset(m_d->sharpnessOption);
191 resources.textureOption.reset(m_d->textureOption);
192
193
195 bool shouldUseCache = false;
196
197 fetchDabGenerationInfo(hasDabInCache,
198 &resources,
200 color,
201 cursorPoint,
202 shape,
203 info,
204 softnessFactor,
205 lightnessStrength),
206 &di,
207 &shouldUseCache);
208
209 *dstDabRect = di.dstDabRect;
210
211
212 // 2. Try return a saved dab from the cache
213
214 if (shouldUseCache) {
215 return fetchFromCache(&resources, info, dstDabRect);
216 }
217
218 // 3. Generate new dab
219
220 generateDab(di, &resources, &m_d->dab, forceNormalizedRGBAImageStamp);
221
222 // 4. Do postprocessing
223 if (di.needsPostprocessing) {
224 if (!m_d->dabOriginal || *cs != *m_d->dabOriginal->colorSpace()) {
226 }
227
228 *m_d->dabOriginal = *m_d->dab;
229
230 postProcessDab(m_d->dab, di.dstDabRect.topLeft(), info, &resources);
231 }
232
233 return m_d->dab;
234}
void fetchDabGenerationInfo(bool hasDabInCache, KisDabCacheUtils::DabRenderingResources *resources, const KisDabCacheUtils::DabRequestInfo &request, KisDabCacheUtils::DabGenerationInfo *di, bool *shouldUseCache)
KisFixedPaintDeviceSP fetchFromCache(KisDabCacheUtils::DabRenderingResources *resources, const KisPaintInformation &info, QRect *dstDabRect)
const KoColorSpace * colorSpace() const
void postProcessDab(KisFixedPaintDeviceSP dab, const QPoint &dabTopLeft, const KisPaintInformation &info, DabRenderingResources *resources)
void generateDab(const DabGenerationInfo &di, DabRenderingResources *resources, KisFixedPaintDeviceSP *dab, bool forceNormalizedRGBAImageStamp)
QScopedPointer< KisColorSource > colorSource
QScopedPointer< KisSharpnessOption > sharpnessOption
QScopedPointer< KisTextureOption > textureOption
KisFixedPaintDeviceSP dab
KisSharpnessOption * sharpnessOption
KisPaintDeviceSP colorSourceDevice
KisTextureOption * textureOption
KisFixedPaintDeviceSP dabOriginal

References KisDabCache::Private::brush, KisDabCacheUtils::DabRenderingResources::brush, KisDabCacheUtils::DabRenderingResources::colorSource, KisDabCache::Private::colorSourceDevice, KisDabCacheUtils::DabRenderingResources::colorSourceDevice, KisFixedPaintDevice::colorSpace(), KisDabCache::Private::dab, KisDabCache::Private::dabOriginal, KisDabCacheUtils::DabGenerationInfo::dstDabRect, KisDabCacheBase::fetchDabGenerationInfo(), fetchFromCache(), m_d, KisDabCacheUtils::DabGenerationInfo::needsPostprocessing, KisDabCache::Private::seqNo, KisDabCache::Private::sharpnessOption, KisDabCacheUtils::DabRenderingResources::sharpnessOption, KisDabCache::Private::textureOption, and KisDabCacheUtils::DabRenderingResources::textureOption.

◆ fetchFromCache()

KisFixedPaintDeviceSP KisDabCache::fetchFromCache ( KisDabCacheUtils::DabRenderingResources * resources,
const KisPaintInformation & info,
QRect * dstDabRect )
inlineprivate

Definition at line 121 of file kis_dab_cache.cpp.

124{
125 if (needSeparateOriginal()) {
126 *m_d->dab = *m_d->dabOriginal;
127 *dstDabRect = KisDabCacheUtils::correctDabRectWhenFetchedFromCache(*dstDabRect, m_d->dab->bounds().size());
128 KisDabCacheUtils::postProcessDab(m_d->dab, dstDabRect->topLeft(), info, resources);
129 }
130 else {
131 *dstDabRect = KisDabCacheUtils::correctDabRectWhenFetchedFromCache(*dstDabRect, m_d->dab->bounds().size());
132 }
133
134 return m_d->dab;
135}
bool needSeparateOriginal() const
QRect correctDabRectWhenFetchedFromCache(const QRect &dabRect, const QSize &realDabSize)

References KisFixedPaintDevice::bounds(), KisDabCacheUtils::correctDabRectWhenFetchedFromCache(), KisDabCache::Private::dab, KisDabCache::Private::dabOriginal, m_d, needSeparateOriginal(), and KisDabCacheUtils::postProcessDab().

◆ fetchNormalizedImageDab()

KisFixedPaintDeviceSP KisDabCache::fetchNormalizedImageDab ( const KoColorSpace * cs,
const QPointF & cursorPoint,
KisDabShape const & shape,
const KisPaintInformation & info,
qreal softnessFactor,
QRect * dstDabRect )

Definition at line 103 of file kis_dab_cache.cpp.

109{
110 return fetchDabCommon(cs, 0, KoColor(),
111 cursorPoint,
112 shape,
113 info,
114 softnessFactor,
115 dstDabRect,
116 1.0,
117 true);
118}

References fetchDabCommon().

◆ needSeparateOriginal()

bool KisDabCache::needSeparateOriginal ( ) const

Definition at line 59 of file kis_dab_cache.cpp.

60{
62}
bool needSeparateOriginal(KisTextureOption *textureOption, KisSharpnessOption *sharpnessOption) const

References m_d, KisDabCacheBase::needSeparateOriginal(), KisDabCache::Private::sharpnessOption, and KisDabCache::Private::textureOption.

◆ setSharpnessPostprocessing()

void KisDabCache::setSharpnessPostprocessing ( KisSharpnessOption * option)

Definition at line 49 of file kis_dab_cache.cpp.

50{
51 m_d->sharpnessOption = option;
52}

References m_d, and KisDabCache::Private::sharpnessOption.

◆ setTexturePostprocessing()

void KisDabCache::setTexturePostprocessing ( KisTextureOption * option)

Definition at line 54 of file kis_dab_cache.cpp.

55{
56 m_d->textureOption = option;
57}

References m_d, and KisDabCache::Private::textureOption.

Member Data Documentation

◆ m_d

Private* const KisDabCache::m_d
private

Definition at line 97 of file kis_dab_cache.h.


The documentation for this class was generated from the following files: