summaryrefslogtreecommitdiffstats
path: root/src/graphicsitems/qximagebase.cpp
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@nokia.com>2010-12-09 09:42:04 +0100
committerGunnar Sletta <gunnar.sletta@nokia.com>2010-12-09 09:42:04 +0100
commit618719564b0e15ae383c2ffbf87f331375ad6778 (patch)
tree9623ad243b22dacaaf806d7f0532e245c21024a8 /src/graphicsitems/qximagebase.cpp
parent763d2fdd4299b707ea2e4de5cff324871632485b (diff)
initial code for lazy image
Diffstat (limited to 'src/graphicsitems/qximagebase.cpp')
-rw-r--r--src/graphicsitems/qximagebase.cpp61
1 files changed, 42 insertions, 19 deletions
diff --git a/src/graphicsitems/qximagebase.cpp b/src/graphicsitems/qximagebase.cpp
index 185c291..e77151a 100644
--- a/src/graphicsitems/qximagebase.cpp
+++ b/src/graphicsitems/qximagebase.cpp
@@ -103,8 +103,7 @@ void QxImageBase::setSource(const QUrl &url)
d->url = url;
emit sourceChanged(d->url);
- if (isComponentComplete())
- load();
+ markDirty(QxImageBasePrivate::DirtySource);
}
void QxImageBase::setSourceSize(const QSize& size)
@@ -116,8 +115,8 @@ void QxImageBase::setSourceSize(const QSize& size)
d->sourcesize = size;
d->explicitSourceSize = true;
emit sourceSizeChanged();
- if (isComponentComplete())
- load();
+
+ markDirty(QxImageBasePrivate::DirtySourceSize);
}
QSize QxImageBase::sourceSize() const
@@ -195,17 +194,25 @@ void QxImageBase::requestFinished()
QSGTextureManager *tm = QSGContext::current->textureManager();
if (d->async) {
- d->texture = tm->requestUpload(d->pix.pixmap().toImage(),
+
+ QImage image = d->pix.pixmap().toImage();
+
+ printf("%p: source size -> %dx%d imageSize: %dx%d '%s'\n",
+ this,
+ sourceSize().width(), sourceSize().height(),
+ image.width(), image.height(),
+ qPrintable(source().toLocalFile())
+ );
+
+ d->texture = tm->requestUpload(image,
this,
SLOT(textureStatusChanged(int)));
- if (d->texture->status() == QSGTexture::Ready) {
- pixmapChange();
- }
} else {
d->texture = tm->upload(d->pix.pixmap().toImage());
- pixmapChange();
}
+
+ markDirty(QxImageBasePrivate::DirtyTextureReady);
}
void QxImageBase::textureStatusChanged(int status)
@@ -216,12 +223,9 @@ void QxImageBase::textureStatusChanged(int status)
d->status = Ready;
emit statusChanged(d->status);
- if (!d->texture.isNull()) {
- pixmapChange();
- }
+ if (!d->texture.isNull())
+ markDirty(QxImageBasePrivate::DirtyTextureReady);
}
-
-
}
void QxImageBase::requestProgress(qint64 received, qint64 total)
@@ -233,14 +237,33 @@ void QxImageBase::requestProgress(qint64 received, qint64 total)
}
}
-void QxImageBase::componentComplete()
+void QxImageBase::pixmapChange()
+{
+}
+
+void QxImageBase::markDirty(int flag)
{
Q_D(QxImageBase);
- QxItem::componentComplete();
- if (d->url.isValid())
- load();
+ d->dirty |= flag;
+ if (!d->connected) {
+ connect(QSGContext::current, SIGNAL(aboutToRenderNextFrame()), this, SLOT(prepare()));
+ }
}
-void QxImageBase::pixmapChange()
+void QxImageBase::prepare()
{
+ Q_D(QxImageBase);
+
+ printf("QxImageBase(%p)::prepare(%s): dirty=%x pixmap=(%dx%d)\n", this, qPrintable(d->url.toLocalFile()), d->dirty, d->pix.width(), d->pix.height());
+
+ if (d->dirty & (QxImageBasePrivate::DirtySource | QxImageBasePrivate::DirtySourceSize))
+ load();
+
+ if (d->dirty & QxImageBasePrivate::DirtyTextureReady && !d->texture.isNull()) {
+ // Updating the stuff...
+ pixmapChange();
+ }
+
+ disconnect(QSGContext::current, SIGNAL(aboutToRenderNextFrame()), this, SLOT(prepare()));
+ d->connected = false;
}