QQuickCanvas renames
[profile/ivi/qtdeclarative.git] / src / quick / util / qquickpixmapcache.cpp
index 801b007..1f4da46 100644 (file)
@@ -65,6 +65,8 @@
 #include <QtCore/qdebug.h>
 #include <private/qobject_p.h>
 #include <QSslError>
+#include <QQmlFile>
+#include <QMetaMethod>
 
 #define IMAGEREQUEST_MAX_REQUEST_COUNT       8
 #define IMAGEREQUEST_MAX_REDIRECT_RECURSION 16
@@ -86,7 +88,7 @@ static inline QString imageId(const QUrl &url)
     return url.toString(QUrl::RemoveScheme | QUrl::RemoveAuthority).mid(1);
 }
 
-QSGTexture *QQuickDefaultTextureFactory::createTexture(QQuickCanvas *) const
+QSGTexture *QQuickDefaultTextureFactory::createTexture(QQuickWindow *) const
 {
     QSGPlainTexture *t = new QSGPlainTexture();
     t->setImage(im);
@@ -227,7 +229,7 @@ public:
     }
 
     QQuickPixmapData(QQuickPixmap *pixmap, const QUrl &u, QQuickTextureFactory *texture, const QSize &s, const QSize &r)
-    : refCount(1), inCache(false), privatePixmap(false), pixmapStatus(QQuickPixmap::Ready),
+    : refCount(1), inCache(false), pixmapStatus(QQuickPixmap::Ready),
       url(u), implicitSize(s), requestSize(r), textureFactory(texture), reply(0), prevUnreferenced(0),
       prevUnreferencedPtr(0), nextUnreferenced(0)
     {
@@ -235,7 +237,7 @@ public:
     }
 
     QQuickPixmapData(QQuickPixmap *pixmap, QQuickTextureFactory *texture)
-    : refCount(1), inCache(false), privatePixmap(true), pixmapStatus(QQuickPixmap::Ready),
+    : refCount(1), inCache(false), pixmapStatus(QQuickPixmap::Ready),
       textureFactory(texture), reply(0), prevUnreferenced(0),
       prevUnreferencedPtr(0), nextUnreferenced(0)
     {
@@ -263,7 +265,6 @@ public:
     uint refCount;
 
     bool inCache:1;
-    bool privatePixmap:1;
     
     QQuickPixmap::Status pixmapStatus;
     QUrl url;
@@ -320,11 +321,7 @@ static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *e
 {
     QImageReader imgio(dev);
 
-    bool force_scale = false;
-    if (url.path().endsWith(QLatin1String(".svg"),Qt::CaseInsensitive)) {
-        imgio.setFormat("svg"); // QSvgPlugin::capabilities bug QTBUG-9053
-        force_scale = true;
-    }
+    const bool force_scale = imgio.format() == "svg" || imgio.format() == "svgz";
 
     if (requestSize.width() > 0 || requestSize.height() > 0) {
         QSize s = imgio.size();
@@ -377,6 +374,8 @@ QQuickPixmapReader::~QQuickPixmapReader()
     mutex.lock();
     // manually cancel all outstanding jobs.
     foreach (QQuickPixmapReply *reply, jobs) {
+        if (reply->data && reply->data->reply == reply)
+            reply->data->reply = 0;
         delete reply;
     }
     jobs.clear();
@@ -556,7 +555,7 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
         }
 
     } else {
-        QString lf = QQmlEnginePrivate::urlToLocalFileOrQrc(url);
+        QString lf = QQmlFile::urlToLocalFileOrQrc(url);
         if (!lf.isEmpty()) {
             // Image is local - load/decode immediately
             QImage image;
@@ -637,12 +636,10 @@ void QQuickPixmapReader::cancel(QQuickPixmapReply *reply)
 void QQuickPixmapReader::run()
 {
     if (replyDownloadProgress == -1) {
-        const QMetaObject *nr = &QNetworkReply::staticMetaObject;
-        const QMetaObject *pr = &QQuickPixmapReply::staticMetaObject;
+        replyDownloadProgress = QMetaMethod::fromSignal(&QNetworkReply::downloadProgress).methodIndex();
+        replyFinished = QMetaMethod::fromSignal(&QNetworkReply::finished).methodIndex();
+        downloadProgress = QMetaMethod::fromSignal(&QQuickPixmapReply::downloadProgress).methodIndex();
         const QMetaObject *ir = &QQuickPixmapReaderThreadObject::staticMetaObject;
-        replyDownloadProgress = nr->indexOfSignal("downloadProgress(qint64,qint64)");
-        replyFinished = nr->indexOfSignal("finished()");
-        downloadProgress = pr->indexOfSignal("downloadProgress(qint64,qint64)");
         threadNetworkRequestDone = ir->indexOfSlot("networkRequestDone()");
     }
 
@@ -836,13 +833,15 @@ QQuickPixmapReply::QQuickPixmapReply(QQuickPixmapData *d)
 : data(d), engineForReader(0), requestSize(d->requestSize), url(d->url), loading(false), redirectCount(0)
 {
     if (finishedIndex == -1) {
-        finishedIndex = QQuickPixmapReply::staticMetaObject.indexOfSignal("finished()");
-        downloadProgressIndex = QQuickPixmapReply::staticMetaObject.indexOfSignal("downloadProgress(qint64,qint64)");
+        finishedIndex = QMetaMethod::fromSignal(&QQuickPixmapReply::finished).methodIndex();
+        downloadProgressIndex = QMetaMethod::fromSignal(&QQuickPixmapReply::downloadProgress).methodIndex();
     }
 }
 
 QQuickPixmapReply::~QQuickPixmapReply()
 {
+    // note: this->data->reply must be set to zero if this->data->reply == this
+    // but it must be done within mutex locking, to be guaranteed to be safe.
 }
 
 bool QQuickPixmapReply::event(QEvent *event)
@@ -975,7 +974,7 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
             QQuickPixmap::tr("Failed to get image from provider: %1").arg(url.toString()));
     }
 
-    QString localFile = QQmlEnginePrivate::urlToLocalFileOrQrc(url);
+    QString localFile = QQmlFile::urlToLocalFileOrQrc(url);
     if (localFile.isEmpty()) 
         return 0;
 
@@ -1167,12 +1166,13 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &reques
     QHash<QQuickPixmapKey, QQuickPixmapData *>::Iterator iter = store->m_cache.find(key);
 
     if (iter == store->m_cache.end()) {
-        if (options & QQuickPixmap::Asynchronous) {
-            // pixmaps can only be loaded synchronously
-            if (url.scheme() == QLatin1String("image")) {
-                QQuickImageProvider *provider = static_cast<QQuickImageProvider *>(engine->imageProvider(imageProviderId(url)));
-                if (provider && provider->imageType() == QQuickImageProvider::Pixmap) {
+        if (url.scheme() == QLatin1String("image")) {
+            if (QQuickImageProvider *provider = static_cast<QQuickImageProvider *>(engine->imageProvider(imageProviderId(url)))) {
+                if (provider->imageType() == QQuickImageProvider::Pixmap) {
+                    // pixmaps can only be loaded synchronously
                     options &= ~QQuickPixmap::Asynchronous;
+                } else if (provider->flags() & QQuickImageProvider::ForceAsynchronousImageLoading) {
+                    options |= QQuickPixmap::Asynchronous;
                 }
             }
         }