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 74 of file KoColorConversionCache.cpp.

◆ ~KoColorConversionCache()

KoColorConversionCache::~KoColorConversionCache ( )

Definition at line 78 of file KoColorConversionCache.cpp.

79{
80 Q_FOREACH (CachedTransformation* transfo, d->cache) {
81 delete transfo;
82 }
83 delete d;
84}
QMultiHash< KoColorConversionCacheKey, CachedTransformation * > cache

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

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 86 of file KoColorConversionCache.cpp.

90{
91 KoColorConversionCacheKey key(src, dst, _renderingIntent, _conversionFlags);
92
93 FastPathCacheItem *cacheItem =
94 d->fastStorage.localData();
95
96 if (cacheItem) {
97 if (cacheItem->first == key) {
98 return cacheItem->second;
99 }
100 }
101
102 cacheItem = 0;
103
104 QMutexLocker lock(&d->cacheMutex);
105 QList< CachedTransformation* > cachedTransfos = d->cache.values(key);
106 if (cachedTransfos.size() != 0) {
107 Q_FOREACH (CachedTransformation* ct, cachedTransfos) {
108 ct->transfo->setSrcColorSpace(src);
109 ct->transfo->setDstColorSpace(dst);
110
112 break;
113 }
114 }
115 if (!cacheItem) {
116 KoColorConversionTransformation* transfo = src->createColorConverter(dst, _renderingIntent, _conversionFlags);
117 CachedTransformation* ct = new CachedTransformation(transfo);
118 d->cache.insert(key, ct);
120 }
121
122 d->fastStorage.setLocalData(cacheItem);
123 return cacheItem->second;
124}
QPair< KoColorConversionCacheKey, KoCachedColorConversionTransformation > FastPathCacheItem
QThreadStorage< FastPathCacheItem * > fastStorage

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 126 of file KoColorConversionCache.cpp.

127{
128 d->fastStorage.setLocalData(0);
129
130 QMutexLocker lock(&d->cacheMutex);
131 QMultiHash< KoColorConversionCacheKey, CachedTransformation*>::iterator endIt = d->cache.end();
132 for (QMultiHash< KoColorConversionCacheKey, CachedTransformation*>::iterator it = d->cache.begin(); it != endIt;) {
133 if (it.key().src == cs || it.key().dst == cs) {
134 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
135 delete it.value();
136 it = d->cache.erase(it);
137 } else {
138 ++it;
139 }
140 }
141}

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

Member Data Documentation

◆ d

Private* const KoColorConversionCache::d
private

Definition at line 50 of file KoColorConversionCache.h.


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