Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_paint_device_cache.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef __KIS_PAINT_DEVICE_CACHE_H
8#define __KIS_PAINT_DEVICE_CACHE_H
9
10#include "kis_lock_free_cache.h"
11#include <QReadWriteLock>
12#include <QReadLocker>
13#include <QWriteLocker>
14
16{
17public:
19 : m_paintDevice(paintDevice),
20 m_exactBoundsCache(paintDevice),
21 m_nonDefaultPixelAreaCache(paintDevice),
22 m_regionCache(paintDevice),
24 {
25 }
26
35
36 void setupCache() {
37 invalidate();
38 }
39
47
51
53 QRect bounds;
55
56 if (!result) {
64 }
65
66 return bounds;
67 }
68
72
76
77 QImage createThumbnail(qint32 w, qint32 h, qreal oversample, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags) {
78 QImage thumbnail;
79
80 if (h == 0 || w == 0) {
81 return thumbnail;
82 }
83
84 {
85 QReadLocker readLocker(&m_thumbnailsLock);
87 if (m_thumbnails.contains(w) && m_thumbnails[w].contains(h) && m_thumbnails[w][h].contains(oversample)) {
88 thumbnail = m_thumbnails[w][h][oversample];
89 }
90 }
91 else {
92 readLocker.unlock();
93 QWriteLocker writeLocker(&m_thumbnailsLock);
94 m_thumbnails.clear();
95 m_thumbnailsValid = true;
96 }
97 }
98
99 if (thumbnail.isNull()) {
100 // the thumbnails in the cache are always generated from exact bounds
101 thumbnail = m_paintDevice->createThumbnail(w, h, m_paintDevice->exactBounds(), oversample, renderingIntent, conversionFlags);
102
103 QWriteLocker writeLocker(&m_thumbnailsLock);
104 m_thumbnails[w][h][oversample] = thumbnail;
105 m_thumbnailsValid = true;
106 }
107
108 return thumbnail;
109 }
110
111 int sequenceNumber() const {
112 return m_sequenceNumber;
113 }
114
115private:
117
119 ExactBoundsCache(KisPaintDevice *paintDevice) : m_paintDevice(paintDevice) {}
120
121 QRect calculateNewValue() const override {
122 return m_paintDevice->calculateExactBounds(false);
123 }
124 private:
126 };
127
129 NonDefaultPixelCache(KisPaintDevice *paintDevice) : m_paintDevice(paintDevice) {}
130
131 QRect calculateNewValue() const override {
133 }
134 private:
136 };
137
139 RegionCache(KisPaintDevice *paintDevice) : m_paintDevice(paintDevice) {}
140
141 KisRegion calculateNewValue() const override {
142 return m_paintDevice->dataManager()->region();
143 }
144 private:
146 };
147
151
152 QReadWriteLock m_thumbnailsLock;
153 bool m_thumbnailsValid {false};
154 QMap<int, QMap<int, QMap<qreal,QImage> > > m_thumbnails;
155
157};
158
159#endif /* __KIS_PAINT_DEVICE_CACHE_H */
const qreal oversample
KisRegion region() const
virtual bool wrapAroundMode() const =0
bool tryGetValue(T &result, Mode mode) const
QMap< int, QMap< int, QMap< qreal, QImage > > > m_thumbnails
NonDefaultPixelCache m_nonDefaultPixelAreaCache
QImage createThumbnail(qint32 w, qint32 h, qreal oversample, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags)
KisPaintDeviceCache(KisPaintDevice *paintDevice)
ExactBoundsCache m_exactBoundsCache
KisPaintDeviceCache(const KisPaintDeviceCache &rhs)
QImage createThumbnail(qint32 maxw, qint32 maxh, QRect rect, qreal oversample=1, KoColorConversionTransformation::Intent renderingIntent=KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::ConversionFlags conversionFlags=KoColorConversionTransformation::internalConversionFlags())
QRect exactBounds() const
QRect extent() const
KisDataManagerSP dataManager() const
KisDefaultBoundsBaseSP defaultBounds() const
QRect calculateExactBounds(bool nonDefaultOnly) const
#define bounds(x, a, b)
ExactBoundsCache(KisPaintDevice *paintDevice)
RegionCache(KisPaintDevice *paintDevice)
KisRegion calculateNewValue() const override