Commit 57b7509f authored by Tusooa Zhu's avatar Tusooa Zhu 🔼 Committed by Blackbeard (alberto flores)

Revert the implicit sharing of KoImageData

KoImageData was explicitly shared, and the implicit sharing
breaks TestImageCollection
parent 817d14df
......@@ -41,22 +41,28 @@
#define MAX_MEMORY_IMAGESIZE 90000
KoImageData::KoImageData()
: d(0)
{
}
KoImageData::KoImageData(const KoImageData &imageData)
: KoShapeUserData(),
d(imageData.d)
d(imageData.d)
{
if (d)
d->refCount.ref();
}
KoImageData::KoImageData(KoImageDataPrivate *priv)
: d(priv)
{
d->refCount.ref();
}
KoImageData::~KoImageData()
{
if (d && !d->refCount.deref())
delete d;
}
QPixmap KoImageData::pixmap(const QSize &size)
......@@ -98,10 +104,10 @@ QPixmap KoImageData::pixmap(const QSize &size)
}
if (d->dataStoreState == KoImageDataPrivate::StateImageLoaded) {
if (d->cleanCacheTimer->isActive())
d->cleanCacheTimer->stop();
if (d->cleanCacheTimer.isActive())
d->cleanCacheTimer.stop();
// schedule an auto-unload of the big QImage in a second.
d->cleanCacheTimer->start();
d->cleanCacheTimer.start();
}
}
return d->pixmap;
......@@ -132,7 +138,6 @@ QSizeF KoImageData::imageSize()
return d->imageSize;
}
// XXX: why const here?
QImage KoImageData::image() const
{
if (d->dataStoreState == KoImageDataPrivate::StateNotLoaded) {
......@@ -178,7 +183,8 @@ void KoImageData::setImage(const QImage &image, KoImageCollection *collection)
delete other;
} else {
if (d == 0) {
d = new KoImageDataPrivate();
d = new KoImageDataPrivate(this);
d->refCount.ref();
}
delete d->temporaryFile;
d->temporaryFile = 0;
......@@ -229,7 +235,8 @@ void KoImageData::setImage(const QString &url, KoStore *store, KoImageCollection
delete other;
} else {
if (d == 0) {
d = new KoImageDataPrivate();
d = new KoImageDataPrivate(this);
d->refCount.ref();
} else {
d->clear();
}
......@@ -283,7 +290,8 @@ void KoImageData::setImage(const QByteArray &imageData, KoImageCollection *colle
}
else {
if (d == 0) {
d = new KoImageDataPrivate();
d = new KoImageDataPrivate(this);
d->refCount.ref();
}
d->suffix = "png"; // good default for non-lossy storage.
......@@ -327,11 +335,6 @@ bool KoImageData::isValid() const
&& d->errorCode == Success;
}
KoImageDataPrivate *KoImageData::priv()
{
return d.data();
}
bool KoImageData::operator==(const KoImageData &other) const
{
return other.d == d;
......@@ -339,6 +342,10 @@ bool KoImageData::operator==(const KoImageData &other) const
KoImageData &KoImageData::operator=(const KoImageData &other)
{
if (other.d)
other.d->refCount.ref();
if (d && !d->refCount.deref())
delete d;
d = other.d;
return *this;
}
......
......@@ -25,7 +25,6 @@
#include <QSize>
#include <QMetaType>
#include <QSharedDataPointer>
#include <KoShapeUserData.h>
......@@ -113,7 +112,7 @@ public:
bool isValid() const;
/// \internal
KoImageDataPrivate *priv();
KoImageDataPrivate *priv() { return d; }
private:
friend class KoImageCollection;
......@@ -133,7 +132,8 @@ private:
private:
QSharedDataPointer<KoImageDataPrivate> d;
KoImageDataPrivate *d;
Q_PRIVATE_SLOT(d, void cleanupImageCache())
};
Q_DECLARE_METATYPE(KoImageData*)
......
......@@ -31,16 +31,17 @@
#include <FlakeDebug.h>
#include <QBuffer>
KoImageDataPrivate::KoImageDataPrivate()
KoImageDataPrivate::KoImageDataPrivate(KoImageData *q)
: collection(0),
errorCode(KoImageData::Success),
key(0),
refCount(0),
dataStoreState(StateEmpty),
temporaryFile(0)
{
cleanCacheTimer->setSingleShot(true);
cleanCacheTimer->setInterval(1000);
QObject::connect(cleanCacheTimer.data(), &QTimer::timeout, [&]() { cleanupImageCache(); });
cleanCacheTimer.setSingleShot(true);
cleanCacheTimer.setInterval(1000);
QObject::connect(&cleanCacheTimer, SIGNAL(timeout()), q, SLOT(cleanupImageCache()));
}
KoImageDataPrivate::~KoImageDataPrivate()
......
......@@ -29,19 +29,16 @@
#include <QPixmap>
#include <QTimer>
#include <QDir>
#include <QSharedData>
#include <KisNewOnCopy.h>
#include "KoImageData.h"
class KoImageCollection;
class QTemporaryFile;
class KoImageDataPrivate : public QSharedData
class KoImageDataPrivate
{
public:
KoImageDataPrivate();
explicit KoImageDataPrivate(KoImageData *q);
virtual ~KoImageDataPrivate();
/**
......@@ -73,17 +70,18 @@ public:
};
KoImageCollection *collection;
mutable KoImageData::ErrorCode errorCode;
KoImageData::ErrorCode errorCode;
QSizeF imageSize;
qint64 key;
QString suffix; // the suffix of the picture e.g. png TODO use a QByteArray ?
KisNewOnCopy<QTimer> cleanCacheTimer;
QTimer cleanCacheTimer;
QAtomicInt refCount;
// Image data store.
mutable DataStoreState dataStoreState;
DataStoreState dataStoreState;
QUrl imageLocation;
// XXX this should not be needed
mutable QImage image;
QImage image;
/// screen optimized cached version.
QPixmap pixmap;
......
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