summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2010-08-17 13:38:33 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-08-19 08:47:11 (GMT)
commitf894befedf669fb864a500b0aa395157ff0fb929 (patch)
treec5bc53dcd98dbce2471e23e7014c2a30247e8941 /src/declarative/qml
parentf6cfafde26b4735965be8df0d11e9d7c297c75b9 (diff)
downloadQt-f894befedf669fb864a500b0aa395157ff0fb929.zip
Qt-f894befedf669fb864a500b0aa395157ff0fb929.tar.gz
Qt-f894befedf669fb864a500b0aa395157ff0fb929.tar.bz2
QDeclarativeImageProvider: Do not keep the global declarative mutex locked when processing.
The point is to be able to process images in a thread. If the mutex is locked, this is useless. Use case is a slow QDeclarativeImageProvider that generates thumbmails from large files. Even with the asynchronous attribute set to true, the gui thread would be blocked by the mutex. By using QSharedPointer, I also fix the leak of the providers (which were not deleted) Reviewed-by: Martin Jones
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp15
-rw-r--r--src/declarative/qml/qdeclarativeengine_p.h2
-rw-r--r--src/declarative/qml/qdeclarativeimageprovider.cpp4
3 files changed, 13 insertions, 8 deletions
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 513fc65..bc7468f 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -674,7 +674,7 @@ void QDeclarativeEngine::addImageProvider(const QString &providerId, QDeclarativ
{
Q_D(QDeclarativeEngine);
QMutexLocker locker(&d->mutex);
- d->imageProviders.insert(providerId, provider);
+ d->imageProviders.insert(providerId, QSharedPointer<QDeclarativeImageProvider>(provider));
}
/*!
@@ -684,7 +684,7 @@ QDeclarativeImageProvider *QDeclarativeEngine::imageProvider(const QString &prov
{
Q_D(const QDeclarativeEngine);
QMutexLocker locker(&d->mutex);
- return d->imageProviders.value(providerId);
+ return d->imageProviders.value(providerId).data();
}
/*!
@@ -698,13 +698,14 @@ void QDeclarativeEngine::removeImageProvider(const QString &providerId)
{
Q_D(QDeclarativeEngine);
QMutexLocker locker(&d->mutex);
- delete d->imageProviders.take(providerId);
+ d->imageProviders.take(providerId);
}
QDeclarativeImageProvider::ImageType QDeclarativeEnginePrivate::getImageProviderType(const QUrl &url)
{
QMutexLocker locker(&mutex);
- QDeclarativeImageProvider *provider = imageProviders.value(url.host());
+ QSharedPointer<QDeclarativeImageProvider> provider = imageProviders.value(url.host());
+ locker.unlock();
if (provider)
return provider->imageType();
return static_cast<QDeclarativeImageProvider::ImageType>(-1);
@@ -714,7 +715,8 @@ QImage QDeclarativeEnginePrivate::getImageFromProvider(const QUrl &url, QSize *s
{
QMutexLocker locker(&mutex);
QImage image;
- QDeclarativeImageProvider *provider = imageProviders.value(url.host());
+ QSharedPointer<QDeclarativeImageProvider> provider = imageProviders.value(url.host());
+ locker.unlock();
if (provider)
image = provider->requestImage(url.path().mid(1), size, req_size);
return image;
@@ -724,7 +726,8 @@ QPixmap QDeclarativeEnginePrivate::getPixmapFromProvider(const QUrl &url, QSize
{
QMutexLocker locker(&mutex);
QPixmap pixmap;
- QDeclarativeImageProvider *provider = imageProviders.value(url.host());
+ QSharedPointer<QDeclarativeImageProvider> provider = imageProviders.value(url.host());
+ locker.unlock();
if (provider)
pixmap = provider->requestPixmap(url.path().mid(1), size, req_size);
return pixmap;
diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h
index 3b5dd5a..db2db35 100644
--- a/src/declarative/qml/qdeclarativeengine_p.h
+++ b/src/declarative/qml/qdeclarativeengine_p.h
@@ -232,7 +232,7 @@ public:
mutable QNetworkAccessManager *networkAccessManager;
mutable QDeclarativeNetworkAccessManagerFactory *networkAccessManagerFactory;
- QHash<QString,QDeclarativeImageProvider*> imageProviders;
+ QHash<QString,QSharedPointer<QDeclarativeImageProvider> > imageProviders;
QDeclarativeImageProvider::ImageType getImageProviderType(const QUrl &url);
QImage getImageFromProvider(const QUrl &url, QSize *size, const QSize& req_size);
QPixmap getPixmapFromProvider(const QUrl &url, QSize *size, const QSize& req_size);
diff --git a/src/declarative/qml/qdeclarativeimageprovider.cpp b/src/declarative/qml/qdeclarativeimageprovider.cpp
index ea68327..ef31be7 100644
--- a/src/declarative/qml/qdeclarativeimageprovider.cpp
+++ b/src/declarative/qml/qdeclarativeimageprovider.cpp
@@ -161,7 +161,9 @@ QDeclarativeImageProvider::QDeclarativeImageProvider(ImageType type)
}
/*!
- \internal
+ Destroys the QDeclarativeImageProvider
+
+ \note The destructor of your derived class need to be thread safe.
*/
QDeclarativeImageProvider::~QDeclarativeImageProvider()
{