Commit a07c02a3 authored by Luigi Toscano's avatar Luigi Toscano

Port from KPixmapCache to KImageCache

parent 74210ecf
...@@ -15,6 +15,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS ...@@ -15,6 +15,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
Crash Crash
DBusAddons DBusAddons
DocTools DocTools
GuiAddons
I18n I18n
ItemModels ItemModels
KDELibs4Support KDELibs4Support
......
...@@ -45,6 +45,7 @@ target_link_libraries(lskat ...@@ -45,6 +45,7 @@ target_link_libraries(lskat
Qt5::Gui Qt5::Gui
Qt5::Svg Qt5::Svg
KF5::Crash KF5::Crash
KF5::GuiAddons
KF5::KDELibs4Support KF5::KDELibs4Support
KF5KDEGames KF5KDEGames
) )
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include <QDir> #include <QDir>
#include <QSvgRenderer> #include <QSvgRenderer>
#include <kpixmapcache.h>
#include <kconfig.h> #include <kconfig.h>
#include <kstandarddirs.h> #include <kstandarddirs.h>
...@@ -225,7 +224,7 @@ void KCardCachePrivate::submitRendering(const QString &key, const QImage &image) ...@@ -225,7 +224,7 @@ void KCardCachePrivate::submitRendering(const QString &key, const QImage &image)
qCDebug(LSKAT_LOG) << "Received render of" << key << "from rendering thread."; qCDebug(LSKAT_LOG) << "Received render of" << key << "from rendering thread.";
QPixmap pix = QPixmap::fromImage(image); QPixmap pix = QPixmap::fromImage(image);
QMutexLocker l(cacheMutex); QMutexLocker l(cacheMutex);
cache->insert(key, pix); cache->insertPixmap(key, pix);
} }
LoadThread::LoadThread(KCardCachePrivate *d_) LoadThread::LoadThread(KCardCachePrivate *d_)
...@@ -317,10 +316,10 @@ QPixmap KCardCache::backside() const ...@@ -317,10 +316,10 @@ QPixmap KCardCache::backside() const
{ {
QMutexLocker l(d->cacheMutex); QMutexLocker l(d->cacheMutex);
if (d->cache && (!d->cache->find(key, pix) || pix.isNull())) if (d->cache && (!d->cache->findPixmap(key, &pix) || pix.isNull()))
{ {
pix = d->renderSvg(element); pix = d->renderSvg(element);
d->cache->insert(key, pix); d->cache->insertPixmap(key, pix);
} }
} }
// Make sure we never return an invalid pixmap // Make sure we never return an invalid pixmap
...@@ -337,10 +336,10 @@ QPixmap KCardCache::frontside(const KCardInfo &info) const ...@@ -337,10 +336,10 @@ QPixmap KCardCache::frontside(const KCardInfo &info) const
{ {
QMutexLocker l(d->cacheMutex); QMutexLocker l(d->cacheMutex);
if (d->cache && (!d->cache->find(key, pix) || pix.isNull())) if (d->cache && (!d->cache->findPixmap(key, &pix) || pix.isNull()))
{ {
pix = d->renderSvg(info.svgName()); pix = d->renderSvg(info.svgName());
d->cache->insert(key, pix); d->cache->insertPixmap(key, pix);
} }
} }
// Make sure we never return an invalid pixmap // Make sure we never return an invalid pixmap
...@@ -364,17 +363,14 @@ void KCardCache::setDeckName(const QString &theme) ...@@ -364,17 +363,14 @@ void KCardCache::setDeckName(const QString &theme)
{ {
QMutexLocker l(d->cacheMutex); QMutexLocker l(d->cacheMutex);
delete d->cache; delete d->cache;
d->cache = new KPixmapCache(QString::fromLatin1("kdegames-cards_%1").arg(theme)); // The default size is arbitrary: it reflects the old KPixmapCache default
d->cache->setUseQPixmapCache(true); // and it seems to match the real maximum size for the decks
d->cache = new KImageCache(QString::fromLatin1("kdegames-cards_%1").arg(theme), 3*(1024<<10));
QDateTime dt = QFileInfo(CardDeckInfo::svgFilePath(theme)).lastModified(); QDateTime dt = QFileInfo(CardDeckInfo::svgFilePath(theme)).lastModified();
//PORT QT5 if (d->cache->lastModifiedTime() < dt)
#if 0
if (d->cache->timestamp() < dt.toTime_t())
{ {
d->cache->discard(); d->cache->clear();
d->cache->setTimestamp(dt.toTime_t());
} }
#endif
} }
{ {
QMutexLocker l(d->rendererMutex); QMutexLocker l(d->rendererMutex);
...@@ -399,7 +395,7 @@ void KCardCache::loadTheme(LoadInfos infos) ...@@ -399,7 +395,7 @@ void KCardCache::loadTheme(LoadInfos infos)
delete d->loadThread; delete d->loadThread;
// We have to compile the list of elements to load here, because we can not // We have to compile the list of elements to load here, because we can not
// check the contents of the KPixmapCache from outside the GUI thread. // check the contents of the KImageCache from outside the GUI thread.
QStringList elements; QStringList elements;
QPixmap pix; QPixmap pix;
if (infos &KCardCache::LoadFrontSide) if (infos &KCardCache::LoadFrontSide)
...@@ -418,7 +414,7 @@ void KCardCache::loadTheme(LoadInfos infos) ...@@ -418,7 +414,7 @@ void KCardCache::loadTheme(LoadInfos infos)
QString key = keyForPixmap(d->deckName, element, d->size); QString key = keyForPixmap(d->deckName, element, d->size);
{ {
QMutexLocker l(d->cacheMutex); QMutexLocker l(d->cacheMutex);
if (d->cache && !d->cache->find(key, pix)) if (d->cache && !d->cache->findPixmap(key, &pix))
elements << element; elements << element;
} }
} }
...@@ -441,7 +437,7 @@ QSizeF KCardCache::defaultCardSize(const KCardInfo &info) const ...@@ -441,7 +437,7 @@ QSizeF KCardCache::defaultCardSize(const KCardInfo &info) const
QString key = d->deckName + QLatin1Char('_') + info.svgName() + QLatin1String("_default"); QString key = d->deckName + QLatin1Char('_') + info.svgName() + QLatin1String("_default");
{ {
QMutexLocker(d->cacheMutex); QMutexLocker(d->cacheMutex);
if (d->cache && d->cache->find(key, pix)) if (d->cache && d->cache->findPixmap(key, &pix))
return pix.size(); return pix.size();
} }
...@@ -454,7 +450,7 @@ QSizeF KCardCache::defaultCardSize(const KCardInfo &info) const ...@@ -454,7 +450,7 @@ QSizeF KCardCache::defaultCardSize(const KCardInfo &info) const
{ {
QMutexLocker(d->cacheMutex); QMutexLocker(d->cacheMutex);
if (d->cache) if (d->cache)
d->cache->insert(key, pix); d->cache->insertPixmap(key, pix);
} }
return pix.size(); return pix.size();
...@@ -470,7 +466,7 @@ QSizeF KCardCache::defaultBackSize() const ...@@ -470,7 +466,7 @@ QSizeF KCardCache::defaultBackSize() const
QString key = d->deckName + QLatin1Char('_') + element + QLatin1String("_default"); QString key = d->deckName + QLatin1Char('_') + element + QLatin1String("_default");
{ {
QMutexLocker(d->cacheMutex); QMutexLocker(d->cacheMutex);
if (d->cache && d->cache->find(key, pix)) if (d->cache && d->cache->findPixmap(key, &pix))
return pix.size(); return pix.size();
} }
...@@ -483,7 +479,7 @@ QSizeF KCardCache::defaultBackSize() const ...@@ -483,7 +479,7 @@ QSizeF KCardCache::defaultBackSize() const
{ {
QMutexLocker(d->cacheMutex); QMutexLocker(d->cacheMutex);
if (d->cache) if (d->cache)
d->cache->insert(key, pix); d->cache->insertPixmap(key, pix);
} }
return pix.size(); return pix.size();
...@@ -493,5 +489,5 @@ void KCardCache::invalidateCache() ...@@ -493,5 +489,5 @@ void KCardCache::invalidateCache()
{ {
QMutexLocker l(d->cacheMutex); QMutexLocker l(d->cacheMutex);
if (d->cache) if (d->cache)
d->cache->discard(); d->cache->clear();
} }
...@@ -58,7 +58,7 @@ private: ...@@ -58,7 +58,7 @@ private:
* *
* Card games such as lskat or kpat should use this cache * Card games such as lskat or kpat should use this cache
* to load the various decks into QPixmaps instead of inventing * to load the various decks into QPixmaps instead of inventing
* their own. It uses KPixmapCache behind the scenes, set up to * their own. It uses KImageCache behind the scenes, set up to
* use disk and memory caching. Thus a SVG card deck that was loaded * use disk and memory caching. Thus a SVG card deck that was loaded
* by kpat for the size 100x200 does not need re-rendering when * by kpat for the size 100x200 does not need re-rendering when
* requested from lskat. * requested from lskat.
...@@ -97,7 +97,7 @@ public: ...@@ -97,7 +97,7 @@ public:
Q_DECLARE_FLAGS(LoadInfos, LoadInfo) Q_DECLARE_FLAGS(LoadInfos, LoadInfo)
/** /**
* Constructor creates and initializes a KPixmapCache for all KDE Games * Constructor creates and initializes a KImageCache
* card games * card games
*/ */
KCardCache(); KCardCache();
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#ifndef CARDCACHE_P_H #ifndef CARDCACHE_P_H
#define CARDCACHE_P_H #define CARDCACHE_P_H
#include <KImageCache>
#include <QImage> #include <QImage>
#include <QThread> #include <QThread>
#include <QString> #include <QString>
...@@ -27,7 +29,6 @@ ...@@ -27,7 +29,6 @@
#include <QSize> #include <QSize>
#include "cardcache.h" #include "cardcache.h"
class KPixmapCache;
class QMutex; class QMutex;
class QSvgRenderer; class QSvgRenderer;
class LoadThread; class LoadThread;
...@@ -36,7 +37,7 @@ class KCardCachePrivate : public QObject ...@@ -36,7 +37,7 @@ class KCardCachePrivate : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
KPixmapCache *cache; KImageCache *cache;
QMutex *cacheMutex; QMutex *cacheMutex;
QMutex *rendererMutex; QMutex *rendererMutex;
LoadThread *loadThread; LoadThread *loadThread;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment