Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_dab_cache.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2012 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "kis_dab_cache.h"
8
9#include <KoColor.h>
10#include "kis_paint_device.h"
11#include "kis_brush.h"
13#include "kis_color_source.h"
14#include "KisSharpnessOption.h"
15#include "kis_texture_option.h"
16
17#include <kundo2command.h>
18
36
37
38
40 : m_d(new Private(brush))
41{
42}
43
45{
46 delete m_d;
47}
48
53
58
63
64
66 KisColorSource *colorSource,
67 const QPointF &cursorPoint,
68 KisDabShape const& shape,
69 const KisPaintInformation& info,
70 qreal softnessFactor,
71 QRect *dstDabRect,
72 qreal lightnessStrength)
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}
84
86 const KoColor& color,
87 const QPointF &cursorPoint,
88 KisDabShape const& shape,
89 const KisPaintInformation& info,
90 qreal softnessFactor,
91 QRect *dstDabRect,
92 qreal lightnessStrength)
93{
94 return fetchDabCommon(cs, 0, color,
95 cursorPoint,
96 shape,
97 info,
98 softnessFactor,
99 dstDabRect,
100 lightnessStrength);
101}
102
104 const QPointF &cursorPoint,
105 KisDabShape const& shape,
106 const KisPaintInformation& info,
107 qreal softnessFactor,
108 QRect *dstDabRect)
109{
110 return fetchDabCommon(cs, 0, KoColor(),
111 cursorPoint,
112 shape,
113 info,
114 softnessFactor,
115 dstDabRect,
116 1.0,
117 true);
118}
119
120inline
122 const KisPaintInformation& info,
123 QRect *dstDabRect)
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}
136
142{
144 // we do not own these resources, so just
145 // release them before destruction
146 colorSource.take();
147 sharpnessOption.take();
148 textureOption.take();
149 }
150};
151
152inline
154 KisColorSource *colorSource,
155 const KoColor& color,
156 const QPointF &cursorPoint,
157 KisDabShape shape,
158 const KisPaintInformation& info,
159 qreal softnessFactor,
160 QRect *dstDabRect,
161 qreal lightnessStrength,
162 bool forceNormalizedRGBAImageStamp)
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)
bool needSeparateOriginal(KisTextureOption *textureOption, KisSharpnessOption *sharpnessOption) const
bool needSeparateOriginal() const
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)
Private *const m_d
void setTexturePostprocessing(KisTextureOption *option)
KisFixedPaintDeviceSP fetchFromCache(KisDabCacheUtils::DabRenderingResources *resources, const KisPaintInformation &info, QRect *dstDabRect)
KisFixedPaintDeviceSP fetchDab(const KoColorSpace *cs, KisColorSource *colorSource, const QPointF &cursorPoint, KisDabShape const &, const KisPaintInformation &info, qreal softnessFactor, QRect *dstDabRect, qreal lightnessStrength=1.0)
KisDabCache(KisBrushSP brush)
void setSharpnessPostprocessing(KisSharpnessOption *option)
KisFixedPaintDeviceSP fetchNormalizedImageDab(const KoColorSpace *cs, const QPointF &cursorPoint, KisDabShape const &shape, const KisPaintInformation &info, qreal softnessFactor, QRect *dstDabRect)
const KoColorSpace * colorSpace() const
void postProcessDab(KisFixedPaintDeviceSP dab, const QPoint &dabTopLeft, const KisPaintInformation &info, DabRenderingResources *resources)
QRect correctDabRectWhenFetchedFromCache(const QRect &dabRect, const QSize &realDabSize)
QScopedPointer< KisColorSource > colorSource
QScopedPointer< KisSharpnessOption > sharpnessOption
QScopedPointer< KisTextureOption > textureOption
Private(KisBrushSP brush)
KisFixedPaintDeviceSP dab
KisSharpnessOption * sharpnessOption
KisPaintDeviceSP colorSourceDevice
KisTextureOption * textureOption
KisFixedPaintDeviceSP dabOriginal