diff options
Diffstat (limited to 'src/declarative/util/qdeclarativepixmapcache.cpp')
-rw-r--r-- | src/declarative/util/qdeclarativepixmapcache.cpp | 82 |
1 files changed, 47 insertions, 35 deletions
diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp index 458d003888..dcce7db813 100644 --- a/src/declarative/util/qdeclarativepixmapcache.cpp +++ b/src/declarative/util/qdeclarativepixmapcache.cpp @@ -48,7 +48,8 @@ #include <private/qdeclarativeengine_p.h> #include <qsgtexture.h> -#include <qsgtexture_p.h> +#include <private/qsgtexture_p.h> +#include <private/qsgcontext_p.h> #include <QCoreApplication> #include <QImageReader> @@ -75,12 +76,10 @@ QT_BEGIN_NAMESPACE // The cache limit describes the maximum "junk" in the cache. // These are the same defaults as QPixmapCache -#if defined(Q_OS_SYMBIAN) -static int cache_limit = 1024 * 1024; // 1048 KB cache limit for symbian -#elif defined(Q_WS_QWS) || defined(Q_WS_WINCE) +#if defined(Q_WS_QWS) || defined(Q_WS_WINCE) static int cache_limit = 2048 * 1024; // 2048 KB cache limit for embedded #else -static int cache_limit = 10240 * 1024; // 10 MB cache limit for desktop +static int cache_limit = 128 * 1024; // 10 MB cache limit for desktop #endif class QDeclarativePixmapReader; @@ -104,16 +103,17 @@ public: class Event : public QEvent { public: Event(ReadError, const QString &, const QSize &, const QImage &image); - Event(ReadError, const QString &, const QSize &, const QSGTextureRef &t); + Event(ReadError, const QString &, const QSize &, QSGTexture *t, QSGContext *context); ReadError error; QString errorString; QSize implicitSize; QImage image; - QSGTextureRef texture; + QSGTexture *texture; + QSGContext *context; }; void postReply(ReadError, const QString &, const QSize &, const QImage &); - void postReply(ReadError, const QString &, const QSize &, const QSGTextureRef &t); + void postReply(ReadError, const QString &, const QSize &, QSGTexture *t, QSGContext *context); Q_SIGNALS: @@ -192,39 +192,46 @@ class QDeclarativePixmapData public: QDeclarativePixmapData(const QUrl &u, const QSize &s, const QString &e) : refCount(1), inCache(false), pixmapStatus(QDeclarativePixmap::Error), - url(u), errorString(e), requestSize(s), reply(0), prevUnreferenced(0), + url(u), errorString(e), requestSize(s), texture(0), context(0), reply(0), prevUnreferenced(0), prevUnreferencedPtr(0), nextUnreferenced(0) { } QDeclarativePixmapData(const QUrl &u, const QSize &r) : refCount(1), inCache(false), pixmapStatus(QDeclarativePixmap::Loading), - url(u), requestSize(r), reply(0), prevUnreferenced(0), prevUnreferencedPtr(0), + url(u), requestSize(r), texture(0), context(0), reply(0), prevUnreferenced(0), prevUnreferencedPtr(0), nextUnreferenced(0) { } QDeclarativePixmapData(const QUrl &u, const QPixmap &p, const QSize &s, const QSize &r) : refCount(1), inCache(false), privatePixmap(false), pixmapStatus(QDeclarativePixmap::Ready), - url(u), pixmap(p), implicitSize(s), requestSize(r), reply(0), prevUnreferenced(0), + url(u), pixmap(p), implicitSize(s), requestSize(r), texture(0), context(0), reply(0), prevUnreferenced(0), prevUnreferencedPtr(0), nextUnreferenced(0) { } - QDeclarativePixmapData(const QUrl &u, const QSGTextureRef &t, const QSize &s, const QSize &r) + QDeclarativePixmapData(const QUrl &u, QSGTexture *t, QSGContext *c, const QSize &s, const QSize &r) : refCount(1), inCache(false), privatePixmap(false), pixmapStatus(QDeclarativePixmap::Ready), - url(u), implicitSize(s), requestSize(r), texture(t), reply(0), prevUnreferenced(0), + url(u), implicitSize(s), requestSize(r), texture(t), context(c), reply(0), prevUnreferenced(0), prevUnreferencedPtr(0), nextUnreferenced(0) { } QDeclarativePixmapData(const QPixmap &p) : refCount(1), inCache(false), privatePixmap(true), pixmapStatus(QDeclarativePixmap::Ready), - pixmap(p), implicitSize(p.size()), requestSize(p.size()), reply(0), prevUnreferenced(0), + pixmap(p), implicitSize(p.size()), requestSize(p.size()), texture(0), context(0), reply(0), prevUnreferenced(0), prevUnreferencedPtr(0), nextUnreferenced(0) { } + ~QDeclarativePixmapData() + { + if (texture && context) { + context->schdelueTextureForCleanup(texture); + } + } + int cost() const; void addref(); void release(); @@ -243,7 +250,8 @@ public: QSize implicitSize; QSize requestSize; - QSGTextureRef texture; + QSGTexture *texture; + QSGContext *context; QDeclarativePixmapReply *reply; @@ -273,10 +281,11 @@ void QDeclarativePixmapReply::postReply(ReadError error, const QString &errorStr } void QDeclarativePixmapReply::postReply(ReadError error, const QString &errorString, - const QSize &implicitSize, const QSGTextureRef &texture) + const QSize &implicitSize, QSGTexture *texture, + QSGContext *context) { loading = false; - QCoreApplication::postEvent(this, new Event(error, errorString, implicitSize, texture)); + QCoreApplication::postEvent(this, new Event(error, errorString, implicitSize, texture, context)); } QDeclarativePixmapReply::Event::Event(ReadError e, const QString &s, const QSize &iSize, const QImage &i) @@ -284,8 +293,8 @@ QDeclarativePixmapReply::Event::Event(ReadError e, const QString &s, const QSize { } -QDeclarativePixmapReply::Event::Event(ReadError e, const QString &s, const QSize &iSize, const QSGTextureRef &t) - : QEvent(QEvent::User), error(e), errorString(s), implicitSize(iSize), texture(t) +QDeclarativePixmapReply::Event::Event(ReadError e, const QString &s, const QSize &iSize, QSGTexture *t, QSGContext *c) + : QEvent(QEvent::User), error(e), errorString(s), implicitSize(iSize), texture(t), context(c) { } @@ -385,6 +394,7 @@ void QDeclarativePixmapReader::networkRequestDone(QNetworkReply *reply) QImage image; QSGTexture *texture = 0; + QSGContext *ctx = QDeclarativeEnginePrivate::get(engine)->sgContext; QDeclarativePixmapReply::ReadError error = QDeclarativePixmapReply::NoError; QString errorString; QSize readSize; @@ -395,7 +405,6 @@ void QDeclarativePixmapReader::networkRequestDone(QNetworkReply *reply) QByteArray all = reply->readAll(); QBuffer buff(&all); buff.open(QIODevice::ReadOnly); - QSGContext *ctx = QDeclarativeEnginePrivate::get(engine)->sgContext; if (ctx && ctx->canDecodeImageToTexture()) texture = ctx->decodeImageToTexture(&buff, &readSize, job->requestSize); if (!texture) { @@ -410,7 +419,7 @@ void QDeclarativePixmapReader::networkRequestDone(QNetworkReply *reply) mutex.lock(); if (!cancelled.contains(job)) { if (texture) - job->postReply(error, errorString, readSize, QSGTextureRef(texture)); + job->postReply(error, errorString, readSize, texture, ctx); else job->postReply(error, errorString, readSize, image); } else { @@ -468,7 +477,8 @@ void QDeclarativePixmapReader::processJobs() replies.remove(reply); reply->close(); } - delete job; + // deleteLater, since not owned by this thread + job->deleteLater(); } cancelled.clear(); } @@ -509,7 +519,7 @@ void QDeclarativePixmapReader::processJob(QDeclarativePixmapReply *runningJob, c mutex.lock(); if (!cancelled.contains(runningJob)) { if (sgContext) - runningJob->postReply(errorCode, errorStr, readSize, sgContext->createTexture(image)); + runningJob->postReply(errorCode, errorStr, readSize, sgContext->createTexture(image), sgContext); else runningJob->postReply(errorCode, errorStr, readSize, image); } @@ -523,7 +533,8 @@ void QDeclarativePixmapReader::processJob(QDeclarativePixmapReply *runningJob, c errorStr = QDeclarativePixmap::tr("Failed to get texture from provider: %1").arg(url.toString()); } mutex.lock(); - if (!cancelled.contains(runningJob)) runningJob->postReply(errorCode, errorStr, readSize, QSGTextureRef(t)); + if (!cancelled.contains(runningJob)) + runningJob->postReply(errorCode, errorStr, readSize, t, sgContext); mutex.unlock(); } @@ -555,7 +566,7 @@ void QDeclarativePixmapReader::processJob(QDeclarativePixmapReply *runningJob, c mutex.lock(); if (!cancelled.contains(runningJob)) { if (texture) - runningJob->postReply(errorCode, errorStr, readSize, QSGTextureRef(texture)); + runningJob->postReply(errorCode, errorStr, readSize, texture, sgContext); else runningJob->postReply(errorCode, errorStr, readSize, image); } else { @@ -784,9 +795,10 @@ bool QDeclarativePixmapReply::event(QEvent *event) data->pixmapStatus = (de->error == NoError) ? QDeclarativePixmap::Ready : QDeclarativePixmap::Error; if (data->pixmapStatus == QDeclarativePixmap::Ready) { - if (!de->texture.isNull()) + if (de->texture) { data->texture = de->texture; - else + data->context = de->context; + } else data->pixmap = QPixmap::fromImage(de->image); data->implicitSize = de->implicitSize; } else { @@ -870,7 +882,7 @@ static QDeclarativePixmapData* createPixmapDataSync(QDeclarativeEngine *engine, QSGTexture *texture = ep->getTextureFromProvider(url, &readSize, requestSize); if (texture) { *ok = true; - return new QDeclarativePixmapData(url, QSGTextureRef(texture), readSize, requestSize); + return new QDeclarativePixmapData(url, texture, sgContext, readSize, requestSize); } } @@ -881,7 +893,7 @@ static QDeclarativePixmapData* createPixmapDataSync(QDeclarativeEngine *engine, *ok = true; if (sgContext) { QSGTexture *t = sgContext->createTexture(image); - return new QDeclarativePixmapData(url, QSGTextureRef(t), readSize, requestSize); + return new QDeclarativePixmapData(url, t, sgContext,readSize, requestSize); } return new QDeclarativePixmapData(url, QPixmap::fromImage(image), readSize, requestSize); } @@ -893,7 +905,7 @@ static QDeclarativePixmapData* createPixmapDataSync(QDeclarativeEngine *engine, *ok = true; if (sgContext) { QSGTexture *t = sgContext->createTexture(pixmap.toImage()); - return new QDeclarativePixmapData(url, QSGTextureRef(t), readSize, requestSize); + return new QDeclarativePixmapData(url, t, sgContext,readSize, requestSize); } return new QDeclarativePixmapData(url, pixmap, readSize, requestSize); } @@ -933,7 +945,7 @@ static QDeclarativePixmapData* createPixmapDataSync(QDeclarativeEngine *engine, } if (texture) - return new QDeclarativePixmapData(url, QSGTextureRef(texture), readSize, requestSize); + return new QDeclarativePixmapData(url, texture, ctx, readSize, requestSize); else return new QDeclarativePixmapData(url, QPixmap::fromImage(image), readSize, requestSize); @@ -1036,7 +1048,7 @@ const QSize &QDeclarativePixmap::requestSize() const return nullPixmap()->size; } -QSGTextureRef QDeclarativePixmap::texture() const +QSGTexture *QDeclarativePixmap::texture() const { return d ? d->texture : 0; } @@ -1060,7 +1072,7 @@ void QDeclarativePixmap::setPixmap(const QPixmap &p) int QDeclarativePixmap::width() const { if (d) - return !d->texture.isNull() ? d->texture->textureSize().width() : d->pixmap.width(); + return d->texture ? d->texture->textureSize().width() : d->pixmap.width(); else return 0; } @@ -1068,7 +1080,7 @@ int QDeclarativePixmap::width() const int QDeclarativePixmap::height() const { if (d) - return !d->texture.isNull() ? d->texture->textureSize().height() : d->pixmap.height(); + return d->texture? d->texture->textureSize().height() : d->pixmap.height(); else return 0; } @@ -1076,7 +1088,7 @@ int QDeclarativePixmap::height() const QRect QDeclarativePixmap::rect() const { if (d) - return !d->texture.isNull() ? QRect(QPoint(), d->texture->textureSize()) : d->pixmap.rect(); + return d->texture ? QRect(QPoint(), d->texture->textureSize()) : d->pixmap.rect(); else return QRect(); } |