From 07929fef22cb9cffc059f949e216ec585e0e7466 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 26 May 2009 09:01:50 +1000 Subject: Switch from QImage to QPixmap, to allow OpenVG optimization. Switch QFxPixmap to use QPixmapCache, not own partial QImage cache. OpenGL prefers QImage for optimization, but that optimization is only partially preserved (QFxPixmap deals ONLY with QPixmap now). Opaque QFxPixmap no longer available. --- src/declarative/canvas/qsimplecanvas.h | 16 -- src/declarative/canvas/qsimplecanvas_opengl.cpp | 6 +- src/declarative/canvas/qsimplecanvas_opengl1.cpp | 8 +- src/declarative/canvas/qsimplecanvasitem.cpp | 6 +- src/declarative/canvas/qsimplecanvasitem.h | 6 +- src/declarative/fx/qfxblendedimage.cpp | 8 +- src/declarative/fx/qfxblendedimage.h | 4 +- src/declarative/fx/qfxhighlightfilter.cpp | 2 +- src/declarative/fx/qfximage.cpp | 37 ++-- src/declarative/fx/qfximage_p.h | 2 +- src/declarative/fx/qfxpainteditem.cpp | 14 +- src/declarative/fx/qfxpainteditem_p.h | 2 +- src/declarative/fx/qfxparticles.cpp | 6 +- src/declarative/fx/qfxpixmap.cpp | 220 +++++++++-------------- src/declarative/fx/qfxpixmap.h | 8 +- src/declarative/fx/qfxrect.cpp | 32 ++-- src/declarative/fx/qfxrect_p.h | 2 +- src/declarative/fx/qfxscalegrid.h | 1 - src/declarative/fx/qfxtext.cpp | 54 +++--- src/declarative/fx/qfxtext_p.h | 8 +- src/declarative/fx/qfxtextedit_p.h | 4 +- src/declarative/fx/qfxwebview.cpp | 2 +- 22 files changed, 180 insertions(+), 268 deletions(-) diff --git a/src/declarative/canvas/qsimplecanvas.h b/src/declarative/canvas/qsimplecanvas.h index 880fae0..1cbd3c7 100644 --- a/src/declarative/canvas/qsimplecanvas.h +++ b/src/declarative/canvas/qsimplecanvas.h @@ -88,27 +88,11 @@ namespace QSimpleCanvasConfig #elif defined(QFX_RENDER_QPAINTER) typedef QTransform Matrix; - typedef QImage Image; inline Matrix transformToMatrix(const QTransform &t) { return t; } inline QTransform matrixToTransform(const Matrix &t) { return t; } - inline bool needConvert(ImageType type, const Image &img) { - QImage::Format f = img.format(); - return !((type == Opaque && f == QImage::Format_RGB16) || - (type == Translucent && f == QImage::Format_ARGB32_Premultiplied)); - } - inline Image convert(ImageType type, const Image &img) { - if (type == Opaque) - return img.convertToFormat(QImage::Format_RGB16); - else - return img.convertToFormat(QImage::Format_ARGB32_Premultiplied); - } - inline Image create(const QSize &s) - { return QImage(s, QImage::Format_ARGB32_Premultiplied); } - inline const Image &toImage(const QImage &i) - { return i; } #endif } diff --git a/src/declarative/canvas/qsimplecanvas_opengl.cpp b/src/declarative/canvas/qsimplecanvas_opengl.cpp index 98f92d7..72f8324 100644 --- a/src/declarative/canvas/qsimplecanvas_opengl.cpp +++ b/src/declarative/canvas/qsimplecanvas_opengl.cpp @@ -416,13 +416,13 @@ QGLShaderProgram *QSimpleCanvasItem::GLPainter::useColorShader(const QColor &col return item->basicShaders()->constantColor(); } -void QSimpleCanvasItem::GLPainter::drawImage(const QPointF &point, +void QSimpleCanvasItem::GLPainter::drawPixmap(const QPointF &point, const GLTexture &texture) { - drawImage(QRectF(point, QSizeF(texture.width(), texture.height())), texture); + drawPixmap(QRectF(point, QSizeF(texture.width(), texture.height())), texture); } -void QSimpleCanvasItem::GLPainter::drawImage(const QRectF &rect, +void QSimpleCanvasItem::GLPainter::drawPixmap(const QRectF &rect, const GLTexture &img) { QGLShaderProgram *shader = useTextureShader(); diff --git a/src/declarative/canvas/qsimplecanvas_opengl1.cpp b/src/declarative/canvas/qsimplecanvas_opengl1.cpp index 3fd8490..6e50ef8 100644 --- a/src/declarative/canvas/qsimplecanvas_opengl1.cpp +++ b/src/declarative/canvas/qsimplecanvas_opengl1.cpp @@ -386,16 +386,16 @@ void QSimpleCanvasPrivate::release(QGLFramebufferObject *) { } -void QSimpleCanvasItem::GLPainter::drawImage(const QPointF &point, +void QSimpleCanvasItem::GLPainter::drawPixmap(const QPointF &point, const GLTexture &texture) { - drawImage(QRectF(point, QSizeF(texture.width(), texture.height())), texture); + drawPixmap(QRectF(point, QSizeF(texture.width(), texture.height())), texture); } -void QSimpleCanvasItem::GLPainter::drawImage(const QRectF &rect, +void QSimpleCanvasItem::GLPainter::drawPixmap(const QRectF &rect, const GLTexture &img) { - qFatal("Cannot call QSimpleCanvasItem::GLPainter::drawImage() when using OpenGL ES 1.1"); + qFatal("Cannot call QSimpleCanvasItem::GLPainter::drawPixmap() when using OpenGL ES 1.1"); } QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvasitem.cpp b/src/declarative/canvas/qsimplecanvasitem.cpp index 3666b82..f2222a9 100644 --- a/src/declarative/canvas/qsimplecanvasitem.cpp +++ b/src/declarative/canvas/qsimplecanvasitem.cpp @@ -1852,12 +1852,12 @@ QSimpleCanvasItem *QSimpleCanvasItem::findNextFocus(QSimpleCanvasItem *item) return 0; } -QImage QSimpleCanvasItem::string(const QString &str, const QColor &c, const QFont &f) +QPixmap QSimpleCanvasItem::string(const QString &str, const QColor &c, const QFont &f) { QFontMetrics fm(f); QSize size(fm.width(str), fm.height()*(str.count(QLatin1Char('\n'))+1)); //fm.boundingRect(str).size(); - QImage img(size, QImage::Format_ARGB32_Premultiplied); - img.fill(0); + QPixmap img(size); + img.fill(Qt::transparent); QPainter p(&img); p.setPen(c); p.setFont(f); diff --git a/src/declarative/canvas/qsimplecanvasitem.h b/src/declarative/canvas/qsimplecanvasitem.h index cf23fc6..77ac52e 100644 --- a/src/declarative/canvas/qsimplecanvasitem.h +++ b/src/declarative/canvas/qsimplecanvasitem.h @@ -175,8 +175,8 @@ public: QGLShaderProgram *useTextureShader(); QGLShaderProgram *useColorShader(const QColor &); - void drawImage(const QPointF &, const GLTexture &); - void drawImage(const QRectF &, const GLTexture &); + void drawPixmap(const QPointF &, const GLTexture &); + void drawPixmap(const QRectF &, const GLTexture &); private: GLPainter(const GLPainter &); GLPainter &operator=(const GLPainter &); @@ -228,7 +228,7 @@ public: GLBasicShaders *basicShaders() const; - static QImage string(const QString &, const QColor & = Qt::black, const QFont & = QFont()); + static QPixmap string(const QString &, const QColor & = Qt::black, const QFont & = QFont()); protected: virtual void geometryChanged(const QRectF &newGeometry, diff --git a/src/declarative/fx/qfxblendedimage.cpp b/src/declarative/fx/qfxblendedimage.cpp index 79b8e41..56b25ea 100644 --- a/src/declarative/fx/qfxblendedimage.cpp +++ b/src/declarative/fx/qfxblendedimage.cpp @@ -192,9 +192,9 @@ void QFxBlendedImage::paintContents(QPainter &p) } if (_blend < 0.75) - p.drawImage(0, 0, primPix); + p.drawPixmap(0, 0, primPix); else - p.drawImage(0, 0, secPix); + p.drawPixmap(0, 0, secPix); if (_smooth) { p.restore(); @@ -212,8 +212,8 @@ void QFxBlendedImage::paintGLContents(GLPainter &p) if (dirty) { prim.clear(); sec.clear(); - prim.setImage(primPix); - sec.setImage(secPix); + prim.setImage(primPix.toImage()); + sec.setImage(secPix.toImage()); dirty = false; } diff --git a/src/declarative/fx/qfxblendedimage.h b/src/declarative/fx/qfxblendedimage.h index 2fdf15b..352e559 100644 --- a/src/declarative/fx/qfxblendedimage.h +++ b/src/declarative/fx/qfxblendedimage.h @@ -99,8 +99,8 @@ private: GLTexture prim; GLTexture sec; #endif - QFxPixmap primPix; - QFxPixmap secPix; + QPixmap primPix; + QPixmap secPix; }; QML_DECLARE_TYPE(QFxBlendedImage); diff --git a/src/declarative/fx/qfxhighlightfilter.cpp b/src/declarative/fx/qfxhighlightfilter.cpp index a22ad98..32264b1 100644 --- a/src/declarative/fx/qfxhighlightfilter.cpp +++ b/src/declarative/fx/qfxhighlightfilter.cpp @@ -135,7 +135,7 @@ QString QFxHighlightFilter::source() const void QFxHighlightFilter::imageLoaded() { - QImage img = QFxPixmap(d->url); + QPixmap img = QFxPixmap(d->url); #if defined(QFX_RENDER_OPENGL2) if (!img.isNull()) d->tex.setImage(img); diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp index 064580e..9cbd607 100644 --- a/src/declarative/fx/qfximage.cpp +++ b/src/declarative/fx/qfximage.cpp @@ -141,16 +141,15 @@ QFxImage::~QFxImage() QPixmap QFxImage::pixmap() const { Q_D(const QFxImage); - return d->_pix.pixmap(); + return d->_pix; } void QFxImage::setPixmap(const QPixmap &pix) { Q_D(QFxImage); d->url = QUrl(); - d->_pix.setPixmap(pix); + d->_pix = pix; d->_opaque=false; - d->_pix.setOpaque(false); setImplicitWidth(d->_pix.width()); setImplicitHeight(d->_pix.height()); @@ -255,7 +254,6 @@ void QFxImage::setOpaque(bool o) if (o == d->_opaque) return; d->_opaque = o; - d->_pix.setOpaque(o); update(); } @@ -327,21 +325,21 @@ void QFxImage::paintContents(QPainter &p) p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->_smooth); } - QSimpleCanvasConfig::Image pix = d->_pix; + QPixmap pix = d->_pix; if (d->_tiled) { p.save(); p.setClipRect(0, 0, width(), height(), Qt::IntersectClip); QRect me = QRect(0, 0, width(), height()); - int pw = d->_pix.width(); - int ph = d->_pix.height(); + int pw = pix.width(); + int ph = pix.height(); int yy = 0; while(yy < height()) { int xx = 0; while(xx < width()) { - p.drawImage(xx, yy, d->_pix); + p.drawPixmap(xx, yy, pix); xx += pw; } yy += ph; @@ -355,10 +353,10 @@ void QFxImage::paintContents(QPainter &p) height() / qreal(pix.height())); QTransform old = p.transform(); p.setWorldTransform(scale * old); - p.drawImage(0, 0, pix); + p.drawPixmap(0, 0, pix); p.setWorldTransform(old); } else { - p.drawImage(0, 0, pix); + p.drawPixmap(0, 0, pix); } } else { int sgl = d->_scaleGrid->left(); @@ -378,40 +376,40 @@ void QFxImage::paintContents(QPainter &p) // Upper left if (sgt && sgl) - p.drawImage(QRect(0, 0, sgl, sgt), pix, QRect(0, 0, sgl, sgt)); + p.drawPixmap(QRect(0, 0, sgl, sgt), pix, QRect(0, 0, sgl, sgt)); // Upper middle if (pix.width() - xSide && sgt) - p.drawImage(QRect(sgl, 0, w - xSide, sgt), pix, + p.drawPixmap(QRect(sgl, 0, w - xSide, sgt), pix, QRect(sgl, 0, pix.width() - xSide, sgt)); // Upper right if (sgt && pix.width() - sgr) - p.drawImage(QPoint(w-sgr, 0), pix, + p.drawPixmap(QPoint(w-sgr, 0), pix, QRect(pix.width()-sgr, 0, sgr, sgt)); // Middle left if (sgl && pix.height() - ySide) - p.drawImage(QRect(0, sgt, sgl, h - ySide), pix, + p.drawPixmap(QRect(0, sgt, sgl, h - ySide), pix, QRect(0, sgt, sgl, pix.height() - ySide)); // Middle if (pix.width() - xSide && pix.height() - ySide) - p.drawImage(QRect(sgl, sgt, w - xSide, h - ySide), + p.drawPixmap(QRect(sgl, sgt, w - xSide, h - ySide), pix, QRect(sgl, sgt, pix.width() - xSide, pix.height() - ySide)); // Middle right if (sgr && pix.height() - ySide) - p.drawImage(QRect(w-sgr, sgt, sgr, h - ySide), pix, + p.drawPixmap(QRect(w-sgr, sgt, sgr, h - ySide), pix, QRect(pix.width()-sgr, sgt, sgr, pix.height() - ySide)); // Lower left if (sgl && sgr) - p.drawImage(QPoint(0, h - sgb), pix, + p.drawPixmap(QPoint(0, h - sgb), pix, QRect(0, pix.height() - sgb, sgl, sgb)); // Lower Middle if (pix.width() - xSide && sgb) - p.drawImage(QRect(sgl, h - sgb, w - xSide, sgb), pix, + p.drawPixmap(QRect(sgl, h - sgb, w - xSide, sgb), pix, QRect(sgl, pix.height() - sgb, pix.width() - xSide, sgb)); // Lower Right if (sgr && sgb) - p.drawImage(QPoint(w-sgr, h - sgb), pix, + p.drawPixmap(QPoint(w-sgr, h - sgb), pix, QRect(pix.width()-sgr, pix.height() - sgb, sgr, sgb)); } @@ -947,7 +945,6 @@ void QFxImage::requestFinished() d->status = Error; } d->_pix = QFxPixmap(d->url); - d->_pix.setOpaque(d->_opaque); setOptions(QFxImage::SimpleItem, true); } setImplicitWidth(d->_pix.width()); diff --git a/src/declarative/fx/qfximage_p.h b/src/declarative/fx/qfximage_p.h index 8227ce4..b3cccf9 100644 --- a/src/declarative/fx/qfximage_p.h +++ b/src/declarative/fx/qfximage_p.h @@ -95,7 +95,7 @@ public: } QFxScaleGrid *_scaleGrid; - QFxPixmap _pix; + QPixmap _pix; bool _tiled : 1; bool _smooth : 1; bool _opaque : 1; diff --git a/src/declarative/fx/qfxpainteditem.cpp b/src/declarative/fx/qfxpainteditem.cpp index 4d2e327..7fd74a6 100644 --- a/src/declarative/fx/qfxpainteditem.cpp +++ b/src/declarative/fx/qfxpainteditem.cpp @@ -271,7 +271,7 @@ void QFxPaintedItem::paintGLContents(GLPainter &p) QRect area = d->imagecache[i]->area; if (topaint.contains(area)) { QRectF target(area.x(), area.y(), area.width(), area.height()); - p.drawImage(target.toRect(), d->imagecache[i]->image); + p.drawPixmap(target.toRect(), d->imagecache[i]->image); topaint -= area; d->imagecache[i]->age=0; } else { @@ -303,12 +303,8 @@ void QFxPaintedItem::paintGLContents(GLPainter &p) const QVector rects = bigger.rects(); for (int i = 0; i < rects.count(); ++i) { const QRect &r = rects.at(i); -#if defined(QFX_RENDER_QPAINTER) - QImage img(r.size(),QImage::Format_ARGB32_Premultiplied); -#else - QImage img(r.size(),QImage::Format_ARGB32); -#endif - img.fill(0); + QPixmap img(r.size()); + img.fill(Qt::transparent); { QPainter qp(&img); qp.translate(-r.x(),-r.y()); @@ -317,13 +313,13 @@ void QFxPaintedItem::paintGLContents(GLPainter &p) QFxPaintedItemPrivate::ImageCacheItem *newitem = new QFxPaintedItemPrivate::ImageCacheItem; newitem->area = r; #if defined(QFX_RENDER_QPAINTER) - newitem->image = QSimpleCanvasConfig::Image(QSimpleCanvasConfig::toImage(img)); + newitem->image = img; #else newitem->image.setImage(img); #endif d->imagecache.append(newitem); QRectF target(r.x(), r.y(), r.width(), r.height()); - p.drawImage(target.toRect(), newitem->image); + p.drawPixmap(target.toRect(), newitem->image); } } #if defined(QFX_RENDER_OPENGL2) diff --git a/src/declarative/fx/qfxpainteditem_p.h b/src/declarative/fx/qfxpainteditem_p.h index 5d5da6b..d8d1a2a 100644 --- a/src/declarative/fx/qfxpainteditem_p.h +++ b/src/declarative/fx/qfxpainteditem_p.h @@ -78,7 +78,7 @@ public: int age; QRect area; #if defined(QFX_RENDER_QPAINTER) - QSimpleCanvasConfig::Image image; + QPixmap image; #else GLTexture image; #endif diff --git a/src/declarative/fx/qfxparticles.cpp b/src/declarative/fx/qfxparticles.cpp index 67c1208..83c7694 100644 --- a/src/declarative/fx/qfxparticles.cpp +++ b/src/declarative/fx/qfxparticles.cpp @@ -397,7 +397,7 @@ public: QString source; QUrl url; - QSimpleCanvasConfig::Image image; + QPixmap image; int count; int lifeSpan; int lifeSpanDev; @@ -671,7 +671,7 @@ void QFxParticles::setSource(const QString &name) if (name.isEmpty()) { d->source = name; d->url = QUrl(); - d->image = QSimpleCanvasConfig::Image(); + d->image = QPixmap(); #if defined(QFX_RENDER_OPENGL) d->texDirty = true; d->tex.clear(); @@ -1124,7 +1124,7 @@ void QFxParticlesPainter::paintContents(QPainter &p) for (int i = 0; i < d->particles.count(); ++i) { const QFxParticle &particle = d->particles.at(i); p.setOpacity(particle.opacity); - p.drawImage(particle.x - myX, particle.y - myY, d->image); + p.drawPixmap(particle.x - myX, particle.y - myY, d->image); } update();//Should I need this? (GV does) } diff --git a/src/declarative/fx/qfxpixmap.cpp b/src/declarative/fx/qfxpixmap.cpp index 0e5a10f..0ea94f5 100644 --- a/src/declarative/fx/qfxpixmap.cpp +++ b/src/declarative/fx/qfxpixmap.cpp @@ -42,44 +42,49 @@ #include "qfxpixmap.h" #include #include +#include #include #include #include - QT_BEGIN_NAMESPACE -class QFxPixmapCacheItem; -typedef QHash QFxPixmapCache; -static QFxPixmapCache qfxPixmapCache; +class QSharedNetworkReply; +typedef QHash QFxSharedNetworkReplyHash; +static QFxSharedNetworkReplyHash qfxActiveNetworkReplies; -class QFxPixmapCacheItem +class QSharedNetworkReply { public: - QFxPixmapCacheItem() : reply(0), refCount(1) {} - QString key; + QSharedNetworkReply(QNetworkReply *r) : reply(r), refCount(1) {} + ~QSharedNetworkReply() + { + reply->deleteLater(); + } QNetworkReply *reply; -#if defined(QFX_RENDER_OPENGL) - QImage image; -#else - QImage image; - QImage opaqueImage; -#endif int refCount; - void addRef() { ++refCount; } - void release() { Q_ASSERT(refCount > 0); --refCount; if (refCount == 0) { qfxPixmapCache.remove(key); delete this; } } + void addRef() + { + ++refCount; + } + void release() + { + Q_ASSERT(refCount > 0); + --refCount; + if (refCount == 0) { + QString key = reply->url().toString(); + qfxActiveNetworkReplies.remove(key); + delete this; + } + } }; -static QFxPixmapCacheItem qfxPixmapCacheDummyItem; - class QFxPixmapPrivate { public: - QFxPixmapPrivate() - : opaque(false), pixmap(&qfxPixmapCacheDummyItem) { pixmap->addRef(); } + QFxPixmapPrivate() {} - bool opaque; - QFxPixmapCacheItem *pixmap; + QPixmap pixmap; }; /*! @@ -102,131 +107,71 @@ QFxPixmap::QFxPixmap(const QUrl &url) #ifdef Q_ENABLE_PERFORMANCE_LOG QFxPerfTimer perf; #endif - QString key = url.toString(); - QFxPixmapCache::Iterator iter = qfxPixmapCache.find(key); - if (iter == qfxPixmapCache.end()) { - qWarning() << "QFxPixmap: URL not loaded" << url; - } else { - QNetworkReply *reply = (*iter)->reply; - if (reply) { - if (reply->error()) { - qWarning() << "Error loading" << url << reply->errorString(); +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + if (url.scheme()==QLatin1String("file")) { + d->pixmap.load(url.toLocalFile()); + } else +#endif + { + QString key = url.toString(); + if (!QPixmapCache::find(key,&d->pixmap)) { + QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) { + // API usage error + qWarning() << "QFxPixmap: URL not loaded" << url; } else { - (*iter)->image.load(reply, 0); + if ((*iter)->reply->error()) { + qWarning() << "Network error loading" << url << (*iter)->reply->errorString(); + } else { + QImage img; + if (img.load((*iter)->reply, 0)) { + d->pixmap = QPixmap::fromImage(img); + QPixmapCache::insert(key, d->pixmap); + } else { + qWarning() << "Format error loading" << url; + } + } + (*iter)->release(); } - reply->deleteLater(); - (*iter)->reply = 0; } - (*iter)->addRef(); } - - d->pixmap = *iter; } QFxPixmap::QFxPixmap(const QFxPixmap &o) : d(new QFxPixmapPrivate) { - d->opaque = o.d->opaque; - o.d->pixmap->addRef(); - d->pixmap->release(); d->pixmap = o.d->pixmap; } QFxPixmap::~QFxPixmap() { - d->pixmap->release(); delete d; } QFxPixmap &QFxPixmap::operator=(const QFxPixmap &o) { - d->opaque = o.d->opaque; - o.d->pixmap->addRef(); - d->pixmap->release(); d->pixmap = o.d->pixmap; return *this; } bool QFxPixmap::isNull() const { - return d->pixmap->image.isNull(); -} - -bool QFxPixmap::opaque() const -{ - return d->opaque; -} - -void QFxPixmap::setOpaque(bool o) -{ - d->opaque = o; + return d->pixmap.isNull(); } int QFxPixmap::width() const { - return d->pixmap->image.width(); + return d->pixmap.width(); } int QFxPixmap::height() const { - return d->pixmap->image.height(); -} - -QPixmap QFxPixmap::pixmap() const -{ - return QPixmap::fromImage(d->pixmap->image); + return d->pixmap.height(); } -void QFxPixmap::setPixmap(const QPixmap &pix) +QFxPixmap::operator const QPixmap &() const { - QFxPixmapCache::Iterator iter = qfxPixmapCache.find(QString::number(pix.cacheKey())); - if (iter == qfxPixmapCache.end()) { - QFxPixmapCacheItem *item = new QFxPixmapCacheItem; - item->key = QString::number(pix.cacheKey()); - if (d->pixmap) - d->pixmap->release(); - d->pixmap = item; - d->pixmap->image = pix.toImage(); - qfxPixmapCache.insert(QString::number(pix.cacheKey()), item); - } else { - (*iter)->addRef(); - d->pixmap = *iter; - } - -#if 0 - int size = 0; - for (QFxPixmapCache::Iterator iter = qfxPixmapCache.begin(); iter != qfxPixmapCache.end(); ++iter) { - size += (*iter)->image.width() * (*iter)->image.height(); - } - qWarning() << qfxPixmapCache.count() << size; -#endif -} - -QFxPixmap::operator const QSimpleCanvasConfig::Image &() const -{ -#if defined(QFX_RENDER_OPENGL) - return d->pixmap->image; -#else - if (d->opaque) { - if (!d->pixmap->image.isNull() && d->pixmap->opaqueImage.isNull()) { -#ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer perf; -#endif - d->pixmap->opaqueImage = d->pixmap->image.convertToFormat(QPixmap::defaultDepth() == 16 ? - QImage::Format_RGB16 : - QImage::Format_RGB32); - } - return d->pixmap->opaqueImage; - } else { - if (!d->pixmap->image.isNull() && d->pixmap->image.format() != QImage::Format_ARGB32_Premultiplied) { -#ifdef Q_ENABLE_PERFORMANCE_LOG - QFxPerfTimer perf; -#endif - d->pixmap->image = d->pixmap->image.convertToFormat(QImage::Format_ARGB32_Premultiplied); - } - return d->pixmap->image; - } -#endif + return d->pixmap; } /*! @@ -239,37 +184,33 @@ QFxPixmap::operator const QSimpleCanvasConfig::Image &() const */ QNetworkReply *QFxPixmap::get(QmlEngine *engine, const QUrl& url, QObject* obj, const char* slot) { - QString key = url.toString(); - QFxPixmapCache::Iterator iter = qfxPixmapCache.find(key); - if (iter == qfxPixmapCache.end()) { - QFxPixmapCacheItem *item = new QFxPixmapCacheItem; - item->addRef(); // XXX - will never get deleted. Need to revisit caching - item->key = key; #ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - if (url.scheme()==QLatin1String("file")) { - item->image.load(url.toLocalFile(), 0); - } else -#endif - { - QNetworkRequest req(url); - req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); - item->reply = engine->networkAccessManager()->get(req); - } - iter = qfxPixmapCache.insert(item->key, item); - } else { - (*iter)->addRef(); + if (url.scheme()==QLatin1String("file")) { + QObject dummy; + QObject::connect(&dummy, SIGNAL(destroyed()), obj, slot); + return 0; } - if ((*iter)->reply) { - // still loading - QObject::connect((*iter)->reply, SIGNAL(finished()), obj, slot); - return (*iter)->reply; - } else { - // already loaded +#endif + + QString key = url.toString(); + if (QPixmapCache::find(key,0)) { QObject dummy; QObject::connect(&dummy, SIGNAL(destroyed()), obj, slot); + return 0; + } + + QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) { + QNetworkRequest req(url); + req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); + QSharedNetworkReply *item = new QSharedNetworkReply(engine->networkAccessManager()->get(req)); + iter = qfxActiveNetworkReplies.insert(key, item); + } else { + (*iter)->addRef(); } - return 0; + QObject::connect((*iter)->reply, SIGNAL(finished()), obj, slot); + return (*iter)->reply; } /*! @@ -282,12 +223,11 @@ QNetworkReply *QFxPixmap::get(QmlEngine *engine, const QUrl& url, QObject* obj, void QFxPixmap::cancelGet(const QUrl& url, QObject* obj) { QString key = url.toString(); - QFxPixmapCache::Iterator iter = qfxPixmapCache.find(key); - if (iter == qfxPixmapCache.end()) + QFxSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) return; - if ((*iter)->reply) - QObject::disconnect((*iter)->reply, 0, obj, 0); - // XXX - loading not cancelled. Need to revisit caching + QObject::disconnect((*iter)->reply, 0, obj, 0); + (*iter)->release(); } QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxpixmap.h b/src/declarative/fx/qfxpixmap.h index fd56ee4..ae693c1 100644 --- a/src/declarative/fx/qfxpixmap.h +++ b/src/declarative/fx/qfxpixmap.h @@ -71,16 +71,10 @@ public: bool isNull() const; - bool opaque() const; - void setOpaque(bool); - int width() const; int height() const; - QPixmap pixmap() const; - void setPixmap(const QPixmap &pix); - - operator const QSimpleCanvasConfig::Image &() const; + operator const QPixmap &() const; private: QFxPixmapPrivate *d; diff --git a/src/declarative/fx/qfxrect.cpp b/src/declarative/fx/qfxrect.cpp index f81f9b3..c5ee60b 100644 --- a/src/declarative/fx/qfxrect.cpp +++ b/src/declarative/fx/qfxrect.cpp @@ -187,7 +187,7 @@ void QFxRect::doUpdate() { #if defined(QFX_RENDER_QPAINTER) Q_D(QFxRect); - d->_rectImage = QSimpleCanvasConfig::Image(); + d->_rectImage = QPixmap(); #endif #if defined(QFX_RENDER_OPENGL) Q_D(QFxRect); @@ -241,7 +241,7 @@ void QFxRect::setRadius(qreal radius) d->_radius = radius; #if defined(QFX_RENDER_QPAINTER) - d->_rectImage = QSimpleCanvasConfig::Image(); + d->_rectImage = QPixmap(); #elif defined(QFX_RENDER_OPENGL) d->_rectTexture.clear(); #endif @@ -287,7 +287,7 @@ void QFxRect::setColor(const QColor &c) d->_color = c; #if defined(QFX_RENDER_QPAINTER) - d->_rectImage = QSimpleCanvasConfig::Image(); + d->_rectImage = QPixmap(); #endif #if defined(QFX_RENDER_OPENGL) d->_rectTexture.clear(); @@ -401,8 +401,8 @@ void QFxRect::generateRoundedRect() Q_D(QFxRect); if (d->_rectImage.isNull()) { const int pw = d->_pen && d->_pen->isValid() ? d->_pen->width() : 0; - d->_rectImage = QImage(d->_radius*2 + 3 + pw*2, d->_radius*2 + 3 + pw*2, QImage::Format_ARGB32_Premultiplied); - d->_rectImage.fill(0); + d->_rectImage = QPixmap(d->_radius*2 + 3 + pw*2, d->_radius*2 + 3 + pw*2); + d->_rectImage.fill(Qt::transparent); QPainter p(&(d->_rectImage)); p.setRenderHint(QPainter::Antialiasing); if (d->_pen && d->_pen->isValid()) { @@ -421,8 +421,8 @@ void QFxRect::generateBorderedRect() Q_D(QFxRect); if (d->_rectImage.isNull()) { const int pw = d->_pen && d->_pen->isValid() ? d->_pen->width() : 0; - d->_rectImage = QImage(d->pen()->width()*2 + 3 + pw*2, d->pen()->width()*2 + 3 + pw*2, QImage::Format_ARGB32_Premultiplied); - d->_rectImage.fill(0); + d->_rectImage = QPixmap(d->pen()->width()*2 + 3 + pw*2, d->pen()->width()*2 + 3 + pw*2); + d->_rectImage.fill(Qt::transparent); QPainter p(&(d->_rectImage)); p.setRenderHint(QPainter::Antialiasing); if (d->_pen && d->_pen->isValid()) { @@ -560,39 +560,39 @@ void QFxRect::drawRect(QPainter &p) } // Upper left - p.drawImage(QRect(-pw/2, -pw/2, xOffset, yOffset), d->_rectImage, QRect(0, 0, xOffset, yOffset)); + p.drawPixmap(QRect(-pw/2, -pw/2, xOffset, yOffset), d->_rectImage, QRect(0, 0, xOffset, yOffset)); // Upper middle if (xMiddles) - p.drawImage(QRect(xOffset-pw/2, -pw/2, width() - xSide + pw, yOffset), d->_rectImage, + p.drawPixmap(QRect(xOffset-pw/2, -pw/2, width() - xSide + pw, yOffset), d->_rectImage, QRect(d->_rectImage.width()/2, 0, 1, yOffset)); // Upper right - p.drawImage(QPoint(width()-xOffset+pw/2, -pw/2), d->_rectImage, + p.drawPixmap(QPoint(width()-xOffset+pw/2, -pw/2), d->_rectImage, QRect(d->_rectImage.width()-xOffset, 0, xOffset, yOffset)); // Middle left if (yMiddles) - p.drawImage(QRect(-pw/2, yOffset-pw/2, xOffset, height() - ySide + pw), d->_rectImage, + p.drawPixmap(QRect(-pw/2, yOffset-pw/2, xOffset, height() - ySide + pw), d->_rectImage, QRect(0, d->_rectImage.height()/2, xOffset, 1)); // Middle if (xMiddles && yMiddles) // XXX paint errors in animation example //p.fillRect(xOffset-pw/2, yOffset-pw/2, width() - xSide + pw, height() - ySide + pw, d->getColor()); - p.drawImage(QRect(xOffset-pw/2, yOffset-pw/2, width() - xSide + pw, height() - ySide + pw), d->_rectImage, + p.drawPixmap(QRect(xOffset-pw/2, yOffset-pw/2, width() - xSide + pw, height() - ySide + pw), d->_rectImage, QRect(d->_rectImage.width()/2, d->_rectImage.height()/2, 1, 1)); // Middle right if (yMiddles) - p.drawImage(QRect(width()-xOffset+pw/2, yOffset-pw/2, xOffset, height() - ySide + pw), d->_rectImage, + p.drawPixmap(QRect(width()-xOffset+pw/2, yOffset-pw/2, xOffset, height() - ySide + pw), d->_rectImage, QRect(d->_rectImage.width()-xOffset, d->_rectImage.height()/2, xOffset, 1)); // Lower left - p.drawImage(QPoint(-pw/2, height() - yOffset + pw/2), d->_rectImage, QRect(0, d->_rectImage.height() - yOffset, xOffset, yOffset)); + p.drawPixmap(QPoint(-pw/2, height() - yOffset + pw/2), d->_rectImage, QRect(0, d->_rectImage.height() - yOffset, xOffset, yOffset)); // Lower Middle if (xMiddles) - p.drawImage(QRect(xOffset-pw/2, height() - yOffset +pw/2, width() - xSide + pw, yOffset), d->_rectImage, + p.drawPixmap(QRect(xOffset-pw/2, height() - yOffset +pw/2, width() - xSide + pw, yOffset), d->_rectImage, QRect(d->_rectImage.width()/2, d->_rectImage.height() - yOffset, 1, yOffset)); // Lower Right - p.drawImage(QPoint(width()-xOffset+pw/2, height() - yOffset+pw/2), d->_rectImage, + p.drawPixmap(QPoint(width()-xOffset+pw/2, height() - yOffset+pw/2), d->_rectImage, QRect(d->_rectImage.width()-xOffset, d->_rectImage.height() - yOffset, xOffset, yOffset)); } } diff --git a/src/declarative/fx/qfxrect_p.h b/src/declarative/fx/qfxrect_p.h index 2fd555f..60eaf1d 100644 --- a/src/declarative/fx/qfxrect_p.h +++ b/src/declarative/fx/qfxrect_p.h @@ -98,7 +98,7 @@ public: QFxPen *_pen; qreal _radius; #if defined(QFX_RENDER_QPAINTER) - QSimpleCanvasConfig::Image _rectImage; + QPixmap _rectImage; #endif }; diff --git a/src/declarative/fx/qfxscalegrid.h b/src/declarative/fx/qfxscalegrid.h index d0f735f..e2bcf88 100644 --- a/src/declarative/fx/qfxscalegrid.h +++ b/src/declarative/fx/qfxscalegrid.h @@ -44,7 +44,6 @@ #include #include -#include #include #include #include diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp index 315b451..b7ae50c 100644 --- a/src/declarative/fx/qfxtext.cpp +++ b/src/declarative/fx/qfxtext.cpp @@ -525,42 +525,44 @@ QString QFxText::propertyInfo() const void QFxTextPrivate::drawOutline() { - QImage img = QImage(imgCache.size(), QImage::Format_ARGB32_Premultiplied); + QPixmap img = QPixmap(imgCache.size()); + img.fill(Qt::transparent); + QPainter ppm(&img); - img.fill(qRgba(0, 0, 0, 0)); QPoint pos(imgCache.rect().topLeft()); pos += QPoint(-1, 0); - ppm.drawImage(pos, imgStyleCache); + ppm.drawPixmap(pos, imgStyleCache); pos += QPoint(2, 0); - ppm.drawImage(pos, imgStyleCache); + ppm.drawPixmap(pos, imgStyleCache); pos += QPoint(-1, -1); - ppm.drawImage(pos, imgStyleCache); + ppm.drawPixmap(pos, imgStyleCache); pos += QPoint(0, 2); - ppm.drawImage(pos, imgStyleCache); + ppm.drawPixmap(pos, imgStyleCache); pos += QPoint(0, -1); - QPainter &p = ppm; - p.drawImage(pos, imgCache); + ppm.drawPixmap(pos, imgCache); + ppm.end(); - imgCache = QSimpleCanvasConfig::toImage(img); + imgCache = img; } void QFxTextPrivate::drawOutline(int yOffset) { - QImage img = QImage(imgCache.size(), QImage::Format_ARGB32_Premultiplied); + QPixmap img = QPixmap(imgCache.size()); + img.fill(Qt::transparent); + QPainter ppm(&img); - img.fill(qRgba(0, 0, 0, 0)); QPoint pos(imgCache.rect().topLeft()); pos += QPoint(0, yOffset); - ppm.drawImage(pos, imgStyleCache); + ppm.drawPixmap(pos, imgStyleCache); pos += QPoint(0, -yOffset); - QPainter &p = ppm; - p.drawImage(pos, imgCache); + ppm.drawPixmap(pos, imgCache); + ppm.end(); - imgCache = QSimpleCanvasConfig::toImage(img); + imgCache = img; } QSize QFxTextPrivate::setupTextLayout(QTextLayout *layout) @@ -600,7 +602,7 @@ QSize QFxTextPrivate::setupTextLayout(QTextLayout *layout) return QSize((int)widthUsed, height); } -QImage QFxTextPrivate::wrappedTextImage(bool drawStyle) +QPixmap QFxTextPrivate::wrappedTextImage(bool drawStyle) { //do layout QFont f; if (_font) f = _font->font(); @@ -620,8 +622,8 @@ QImage QFxTextPrivate::wrappedTextImage(bool drawStyle) } //paint text - QImage img(size, QImage::Format_ARGB32_Premultiplied); - img.fill(0); + QPixmap img(size); + img.fill(Qt::transparent); QPainter p(&img); if (drawStyle) { p.setPen(styleColor); @@ -633,13 +635,13 @@ QImage QFxTextPrivate::wrappedTextImage(bool drawStyle) return img; } -QImage QFxTextPrivate::richTextImage(bool drawStyle) +QPixmap QFxTextPrivate::richTextImage(bool drawStyle) { QSize size = doc->size().toSize(); //paint text - QImage img(size, QImage::Format_ARGB32_Premultiplied); - img.fill(0); + QPixmap img(size); + img.fill(Qt::transparent); QPainter p(&img); if (drawStyle) { @@ -667,14 +669,14 @@ void QFxTextPrivate::checkImgCache() bool empty = text.isEmpty(); if (empty) { - imgCache = QSimpleCanvasConfig::Image(); - imgStyleCache = QImage(); + imgCache = QPixmap(); + imgStyleCache = QPixmap(); } else if (richText) { - imgCache = QSimpleCanvasConfig::toImage(richTextImage(false)); + imgCache = richTextImage(false); if (style != QFxText::Normal) imgStyleCache = richTextImage(true); //### should use styleColor } else { - imgCache = QSimpleCanvasConfig::toImage(wrappedTextImage(false)); + imgCache = wrappedTextImage(false); if (style != QFxText::Normal) imgStyleCache = wrappedTextImage(true); //### should use styleColor } @@ -745,7 +747,7 @@ void QFxText::paintContents(QPainter &p) p.save(); p.setClipRect(boundingRect()); } - p.drawImage(x, y, d->imgCache); + p.drawPixmap(x, y, d->imgCache); if (needClip) p.restore(); } diff --git a/src/declarative/fx/qfxtext_p.h b/src/declarative/fx/qfxtext_p.h index 8bb3142..dfaef63 100644 --- a/src/declarative/fx/qfxtext_p.h +++ b/src/declarative/fx/qfxtext_p.h @@ -94,8 +94,8 @@ public: void drawOutline(); void drawOutline(int yOffset); - QImage wrappedTextImage(bool drawStyle); - QImage richTextImage(bool drawStyle); + QPixmap wrappedTextImage(bool drawStyle); + QPixmap richTextImage(bool drawStyle); QSize setupTextLayout(QTextLayout *layout); QString text; @@ -118,8 +118,8 @@ public: #if defined(QFX_RENDER_OPENGL) GLTexture tex; #endif - QSimpleCanvasConfig::Image imgCache; - QImage imgStyleCache; + QPixmap imgCache; + QPixmap imgStyleCache; QFxText::HAlignment hAlign; QFxText::VAlignment vAlign; Qt::TextElideMode elideMode; diff --git a/src/declarative/fx/qfxtextedit_p.h b/src/declarative/fx/qfxtextedit_p.h index 78b0018..9f26b10 100644 --- a/src/declarative/fx/qfxtextedit_p.h +++ b/src/declarative/fx/qfxtextedit_p.h @@ -89,8 +89,8 @@ public: #if defined(QFX_RENDER_OPENGL) GLTexture texture; #endif - QSimpleCanvasConfig::Image imgCache; - QImage imgStyleCache; + QPixmap imgCache; + QPixmap imgStyleCache; QFxTextEdit::HAlignment hAlign; QFxTextEdit::VAlignment vAlign; bool dirty; diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp index 7998711..0e86249 100644 --- a/src/declarative/fx/qfxwebview.cpp +++ b/src/declarative/fx/qfxwebview.cpp @@ -161,7 +161,7 @@ public: int age; QRect area; #if defined(QFX_RENDER_QPAINTER) - QSimpleCanvasConfig::Image image; + QPixmap image; #else GLTexture image; #endif -- cgit v0.12