|
Krita Source Code Documentation
|
a provider-like interface class for sharing caches between multiple resources More...
#include <KoResourceCacheInterface.h>
Inheritance diagram for KoResourceCacheInterface:Public Types | |
| using | RelatedResourceCookie = std::uintptr_t |
Public Member Functions | |
| virtual QVariant | fetch (const QString &key) const =0 |
fetch a cached object from the cache using key | |
| virtual void | put (const QString &key, const QVariant &value)=0 |
| RelatedResourceCookie | relatedResourceCookie () const |
| void | setRelatedResourceCookie (RelatedResourceCookie cookie) |
| virtual | ~KoResourceCacheInterface () |
Private Attributes | |
| RelatedResourceCookie | m_cookie = RelatedResourceCookie() |
a provider-like interface class for sharing caches between multiple resources
Some resources, e.g. KisPaintOpPreset, may require some computational- intensive work to be done to start being useful. This work is not serialized into the file format, so after we load the preset and before we can start using it we need to spend some time on regenerating some caches. For KisPaintOpPreset such caches are: KisQImagePyramid and outline.
Instead of generating this cache before every stroke we can pregenerate it in advance and share among multiple presets.
And here comes KoResourceCacheInterface. It provides abstract interface for creating a cache and passing it into other presets.
Usage:
\code{.cpp}
// in the GUI thread
KisPaintOpPresetSP tempPreset =
preset->cloneWithResourcesSnapshot(resourcesInterface, canvasResourcesInterface);
// in the non-GUI background thread [1]
KoResourceCacheInterfaceSP cacheInterface =
new KoResourceCacheStorage();
tempPreset->regenerateResourceCache(cacheInterface);
// back in the GUI thread [2]
preset->setResourceCacheInterface(cacheInterface);
// now the GUI-scope preset has all the caches prepared,
// therefore, when we clone it to do real painting, it
// will have all the caches ready
\endcode
[1] - please take it into account that we cannot access the original preset from the non-GUI thread, because it may require resource database access, which is impossible in non-GUI thread. Therefore we must first create a copy of this resource with all the external resources linked to it, and only after that pass it to the non-gui thread
[2] - there is also a cache-validity complication. We have generated the cache using a snapshot of a specific state of resourcesInterface and canvasResourcesInterface. Therefore, if any of these change, we must reset the cache manually! See code in KisPresetShadowUpdater for example implementation.
Definition at line 70 of file KoResourceCacheInterface.h.
| using KoResourceCacheInterface::RelatedResourceCookie = std::uintptr_t |
A special cookie the resource may (or may not) initialize while initializing the cache. The resource may use this cookie later to verify that this resource actually belongs this very resource, not some other resource.
Definition at line 91 of file KoResourceCacheInterface.h.
|
virtual |
Definition at line 17 of file KoResourceCacheInterface.cpp.
|
pure virtual |
fetch a cached object from the cache using key
Implemented in KoResourceCachePrefixedStorageWrapper, and KoResourceCacheStorage.
|
pure virtual |
store a cached object value into the cache using key WARNING: storing an object twice with the same key is considered as invalid operation and will assert! This behavior is intentional to avoid cache key aliasing.
Implemented in KoResourceCachePrefixedStorageWrapper, and KoResourceCacheStorage.
| KoResourceCacheInterface::RelatedResourceCookie KoResourceCacheInterface::relatedResourceCookie | ( | ) | const |
Returns the related resource cookie
Definition at line 27 of file KoResourceCacheInterface.cpp.
References m_cookie.
| void KoResourceCacheInterface::setRelatedResourceCookie | ( | RelatedResourceCookie | cookie | ) |
Sets the related resource cookie
Definition at line 22 of file KoResourceCacheInterface.cpp.
References m_cookie.
|
private |
Definition at line 108 of file KoResourceCacheInterface.h.