summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-05-29 03:56:46 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-05-29 03:56:46 (GMT)
commitb189057d5105b3aae2049d2182ecfceb0399f041 (patch)
tree2745c01760617dbc9a9d211f412a54ccd262250a /src
parent2eb60d000f3666fc42ba2b7305ca52556497c86a (diff)
parent07929fef22cb9cffc059f949e216ec585e0e7466 (diff)
downloadQt-b189057d5105b3aae2049d2182ecfceb0399f041.zip
Qt-b189057d5105b3aae2049d2182ecfceb0399f041.tar.gz
Qt-b189057d5105b3aae2049d2182ecfceb0399f041.tar.bz2
Merge branch 'kinetic-declarativeui-pixmapopt' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src')
-rw-r--r--src/declarative/canvas/qsimplecanvas.h16
-rw-r--r--src/declarative/canvas/qsimplecanvas_opengl.cpp6
-rw-r--r--src/declarative/canvas/qsimplecanvas_opengl1.cpp8
-rw-r--r--src/declarative/canvas/qsimplecanvasitem.cpp6
-rw-r--r--src/declarative/canvas/qsimplecanvasitem.h6
-rw-r--r--src/declarative/fx/qfxblendedimage.cpp8
-rw-r--r--src/declarative/fx/qfxblendedimage.h4
-rw-r--r--src/declarative/fx/qfxhighlightfilter.cpp2
-rw-r--r--src/declarative/fx/qfximage.cpp37
-rw-r--r--src/declarative/fx/qfximage_p.h2
-rw-r--r--src/declarative/fx/qfxpainteditem.cpp14
-rw-r--r--src/declarative/fx/qfxpainteditem_p.h2
-rw-r--r--src/declarative/fx/qfxparticles.cpp6
-rw-r--r--src/declarative/fx/qfxpixmap.cpp220
-rw-r--r--src/declarative/fx/qfxpixmap.h8
-rw-r--r--src/declarative/fx/qfxrect.cpp32
-rw-r--r--src/declarative/fx/qfxrect_p.h2
-rw-r--r--src/declarative/fx/qfxscalegrid.h1
-rw-r--r--src/declarative/fx/qfxtext.cpp54
-rw-r--r--src/declarative/fx/qfxtext_p.h8
-rw-r--r--src/declarative/fx/qfxtextedit_p.h4
-rw-r--r--src/declarative/fx/qfxwebview.cpp2
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 b928319..f817799 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 73eb3c4..4c6eb58 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 4e6204d..baf4b64 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 9807e21..c36ba98 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 55aecd7..8f63a90 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();
}
@@ -326,21 +324,21 @@ void QFxImage::paintContents(QPainter &p)
if (d->_smooth)
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;
@@ -354,10 +352,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();
@@ -377,40 +375,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));
}
@@ -945,7 +943,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<QRect> 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 e9f38b0..52f24a0 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 <QHash>
#include <QNetworkReply>
+#include <QPixmapCache>
#include <qfxperf.h>
#include <QtDeclarative/qmlengine.h>
#include <QFile>
-
QT_BEGIN_NAMESPACE
-class QFxPixmapCacheItem;
-typedef QHash<QString, QFxPixmapCacheItem *> QFxPixmapCache;
-static QFxPixmapCache qfxPixmapCache;
+class QSharedNetworkReply;
+typedef QHash<QString, QSharedNetworkReply *> 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<QFxPerf::PixmapLoad> 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<QFxPerf::PixmapLoad> 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<QFxPerf::PixmapLoad> 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 4271022..475c095 100644
--- a/src/declarative/fx/qfxrect.cpp
+++ b/src/declarative/fx/qfxrect.cpp
@@ -240,7 +240,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);
@@ -339,7 +339,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
@@ -385,7 +385,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();
@@ -463,8 +463,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()) {
@@ -483,8 +483,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()) {
@@ -607,39 +607,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 8faaa38..8cafcbb 100644
--- a/src/declarative/fx/qfxrect_p.h
+++ b/src/declarative/fx/qfxrect_p.h
@@ -100,7 +100,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 2a20de7..c59cb32 100644
--- a/src/declarative/fx/qfxscalegrid.h
+++ b/src/declarative/fx/qfxscalegrid.h
@@ -44,7 +44,6 @@
#include <QtCore/QString>
#include <QtCore/QObject>
-#include <QtGui/QImage>
#include <QtDeclarative/qfxglobal.h>
#include <QtDeclarative/qsimplecanvas.h>
#include <QtDeclarative/qfxpixmap.h>
diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp
index 94a1712..2486a84 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 4c35cae..bfccd34 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