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

#include <KoColorConversionCache.h>

Classes

struct  CachedTransformation
 
struct  Private
 

Public Member Functions

KoCachedColorConversionTransformation cachedConverter (const KoColorSpace *src, const KoColorSpace *dst, KoColorConversionTransformation::Intent _renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags)
 
void colorSpaceIsDestroyed (const KoColorSpace *src)
 
 KoColorConversionCache ()
 
 ~KoColorConversionCache ()
 

Private Attributes

Private *const d
 

Detailed Description

This class holds a cache of KoColorConversionTransformations.

This class is not part of public API, and can be changed without notice.

Definition at line 20 of file KoColorConversionCache.h.

Constructor & Destructor Documentation

◆ KoColorConversionCache()

KoColorConversionCache::KoColorConversionCache ( )

Definition at line 60 of file KoColorConversionCache.cpp.

◆ ~KoColorConversionCache()

KoColorConversionCache::~KoColorConversionCache ( )

Definition at line 64 of file KoColorConversionCache.cpp.

65{
66 if (d->fastStorage.hasLocalData()) {
67 d->fastStorage.localData().clear();
68 }
69
70 Q_FOREACH (CachedTransformation* transfo, d->cache) {
71 delete transfo;
72 }
73 delete d;
74}
QMultiHash< KoColorConversionCacheKey, CachedTransformation * > cache
QThreadStorage< PerThreadRotatingCache > fastStorage

References KoColorConversionCache::Private::cache, d, and KoColorConversionCache::Private::fastStorage.

Member Function Documentation

◆ cachedConverter()

KoCachedColorConversionTransformation KoColorConversionCache::cachedConverter ( const KoColorSpace * src,
const KoColorSpace * dst,
KoColorConversionTransformation::Intent _renderingIntent,
KoColorConversionTransformation::ConversionFlags conversionFlags )

This function returns a cached color transformation if available or create one.

Parameters
srcsource color space
dstdestination color space
_renderingIntentrendering intent
conversionFlagsconversion flags

Definition at line 76 of file KoColorConversionCache.cpp.

80{
81 KoColorConversionCacheKey key(src, dst, _renderingIntent, _conversionFlags);
82
83 std::optional<KoCachedColorConversionTransformation> cachedTransformation;
84
85 if (!d->fastStorage.hasLocalData()) {
87 } else {
88 cachedTransformation = d->fastStorage.localData().find(key);
89 }
90
91 if (cachedTransformation) {
92 return *cachedTransformation;
93 }
94
95 QMutexLocker lock(&d->cacheMutex);
96
97 auto it = d->cache.constFind(key);
98 if (it != d->cache.constEnd()) {
99 CachedTransformation* ct = it.value();
100 ct->transfo->setSrcColorSpace(src);
101 ct->transfo->setDstColorSpace(dst);
102 cachedTransformation = KoCachedColorConversionTransformation(ct);
103 } else {
104 KoColorConversionTransformation* transfo = src->createColorConverter(dst, _renderingIntent, _conversionFlags);
105 CachedTransformation* ct = new CachedTransformation(transfo);
106 d->cache.insert(key, ct);
107 cachedTransformation = KoCachedColorConversionTransformation(ct);
108 }
109 d->fastStorage.localData().push(key, *cachedTransformation);
110
111 return *cachedTransformation;
112}
KisRotatingCache< KoColorConversionCacheKey, KoCachedColorConversionTransformation, 4 > PerThreadRotatingCache

References KoColorConversionCache::Private::cache, KoColorConversionCache::Private::cacheMutex, d, KoColorConversionCache::Private::fastStorage, KoColorConversionTransformation::setDstColorSpace(), KoColorConversionTransformation::setSrcColorSpace(), and KoColorConversionCache::CachedTransformation::transfo.

◆ colorSpaceIsDestroyed()

void KoColorConversionCache::colorSpaceIsDestroyed ( const KoColorSpace * src)

This function is called by the destructor of the color space to warn the cache that any pointers to this color space is going to be invalid and that the cache needs to stop using those pointers.

Parameters
srcsource color space

Definition at line 114 of file KoColorConversionCache.cpp.

115{
116 if (d->fastStorage.hasLocalData()) {
117 d->fastStorage.localData().clear();
118 }
119
120 QMutexLocker lock(&d->cacheMutex);
121 QMultiHash< KoColorConversionCacheKey, CachedTransformation*>::iterator endIt = d->cache.end();
122 for (QMultiHash< KoColorConversionCacheKey, CachedTransformation*>::iterator it = d->cache.begin(); it != endIt;) {
123 if (it.key().src == cs || it.key().dst == cs) {
124 Q_ASSERT(it.value()->isNotInUse()); // That's terribly evil, if that assert fails, that means that someone is using a color transformation with a color space which is currently being deleted
125 delete it.value();
126 it = d->cache.erase(it);
127 } else {
128 ++it;
129 }
130 }
131}

References KoColorConversionCache::Private::cache, KoColorConversionCache::Private::cacheMutex, d, and KoColorConversionCache::Private::fastStorage.

Member Data Documentation

◆ d

Private* const KoColorConversionCache::d
private

Definition at line 57 of file KoColorConversionCache.h.


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