summaryrefslogtreecommitdiffstats
path: root/src/imports/particles
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-07-05 04:20:14 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-07-05 08:31:07 (GMT)
commit09f07b98dfdaec2e48749768b967a48e588d3f7f (patch)
treeafb3d254883bef441614a2c9453be8ac9bf51e5f /src/imports/particles
parentb2aedd1d57a5a681b1185bf8908683ff563de4d6 (diff)
downloadQt-09f07b98dfdaec2e48749768b967a48e588d3f7f.zip
Qt-09f07b98dfdaec2e48749768b967a48e588d3f7f.tar.gz
Qt-09f07b98dfdaec2e48749768b967a48e588d3f7f.tar.bz2
Make declarative pixmap cache easier to use
The QDeclarativePixmapCache was both slow, and very trickey to use correctly. Many QML elements did not correctly cancel outstanding requests, which leads to pixmaps leaking indefinately. Other elements, such as Text, were subject to race conditions that meant they may never actually load all their images. QDeclarativePixmap is a single class than encapsulates the action of fetching a pixmap, as well as the pixmap itself and the responsibility of canceling outstanding requests. Rather than relying on Qt's pixmap cache that doesn't cache all the information QML needs, QDeclarativePixmap implements its own cache, that correctly degrades over time (unlike QPixmapCache that can stop expiring items in some conditions). Reviewed-by: Warwick Allison
Diffstat (limited to 'src/imports/particles')
-rw-r--r--src/imports/particles/qdeclarativeparticles.cpp33
1 files changed, 10 insertions, 23 deletions
diff --git a/src/imports/particles/qdeclarativeparticles.cpp b/src/imports/particles/qdeclarativeparticles.cpp
index 630c068..a7c445d 100644
--- a/src/imports/particles/qdeclarativeparticles.cpp
+++ b/src/imports/particles/qdeclarativeparticles.cpp
@@ -437,7 +437,7 @@ public:
, lifeSpanDev(1000), fadeInDur(200), fadeOutDur(300)
, angle(0), angleDev(0), velocity(0), velocityDev(0), emissionCarry(0.)
, addParticleTime(0), addParticleCount(0), lastAdvTime(0)
- , motion(0), pendingPixmapCache(false), clock(this)
+ , motion(0), clock(this)
{
}
@@ -456,7 +456,7 @@ public:
void updateOpacity(QDeclarativeParticle &p, int age);
QUrl url;
- QPixmap image;
+ QDeclarativePixmap image;
int count;
int emissionRate;
qreal emissionVariance;
@@ -475,7 +475,6 @@ public:
QDeclarativeParticleMotion *motion;
QDeclarativeParticlesPainter *paintItem;
- bool pendingPixmapCache;
QList<QPair<int, int> > bursts;//countLeft, emissionRate pairs
QList<QDeclarativeParticle> particles;
@@ -709,9 +708,6 @@ QDeclarativeParticles::QDeclarativeParticles(QDeclarativeItem *parent)
QDeclarativeParticles::~QDeclarativeParticles()
{
- Q_D(QDeclarativeParticles);
- if (d->pendingPixmapCache)
- QDeclarativePixmapCache::cancel(d->url, this);
}
/*!
@@ -732,10 +728,8 @@ QUrl QDeclarativeParticles::source() const
void QDeclarativeParticles::imageLoaded()
{
Q_D(QDeclarativeParticles);
- d->pendingPixmapCache = false;
- QString errorString;
- if (QDeclarativePixmapCache::get(d->url, &d->image, &errorString)==QDeclarativePixmapReply::Error)
- qmlInfo(this) << errorString;
+ if (d->image.isError())
+ qmlInfo(this) << d->image.error();
d->paintItem->updateSize();
d->paintItem->update();
}
@@ -747,27 +741,20 @@ void QDeclarativeParticles::setSource(const QUrl &name)
if ((d->url.isEmpty() == name.isEmpty()) && name == d->url)
return;
- if (d->pendingPixmapCache) {
- QDeclarativePixmapCache::cancel(d->url, this);
- d->pendingPixmapCache = false;
- }
if (name.isEmpty()) {
d->url = name;
- d->image = QPixmap();
+ d->image.clear(this);
d->paintItem->updateSize();
d->paintItem->update();
} else {
d->url = name;
Q_ASSERT(!name.isRelative());
- QString errorString;
- QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->url, &d->image, &errorString);
- if (status != QDeclarativePixmapReply::Ready && status != QDeclarativePixmapReply::Error) {
- QDeclarativePixmapReply *reply = QDeclarativePixmapCache::request(qmlEngine(this), d->url);
- connect(reply, SIGNAL(finished()), this, SLOT(imageLoaded()));
- d->pendingPixmapCache = true;
+ d->image.load(qmlEngine(this), d->url);
+ if (d->image.isLoading()) {
+ d->image.connectFinished(this, SLOT(imageLoaded()));
} else {
- if (status == QDeclarativePixmapReply::Error)
- qmlInfo(this) << errorString;
+ if (d->image.isError())
+ qmlInfo(this) << d->image.error();
//### unify with imageLoaded
d->paintItem->updateSize();
d->paintItem->update();