move getting the size for the subelement first before creating the cache id.

also remove all the SVG_CACHE_BUGFIX. it wasn't getting used and was making the code a lot uglier.

if someone wants to attempt to have the cache store transform-neutral renderings, they can have another crack it and do it so that ifdef's aren't necessary.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=799600
This commit is contained in:
Aaron J. Seigo 2008-04-21 23:00:58 +00:00
parent 8e9dd61541
commit 868a4107a3

106
svg.cpp
View File

@ -34,11 +34,6 @@
#include "theme.h"
/* If you set SVG_CACHE_BUGFIX to 1 you'll fix the cache bug that makes
SVG painting *VERY slow* but you'll break something somewhere.
*/
#define SVG_CACHE_BUGFIX 0
namespace Plasma
{
@ -124,42 +119,26 @@ class Svg::Private
ids.clear();
}
void findInCache(QPixmap& p, const QString& elementId, const QPainter *itemPainter, const QSizeF &size = QSizeF())
void findInCache(QPixmap& p, const QString& elementId, const QPainter *itemPainter, const QSizeF &s = QSizeF())
{
#if SVG_CACHE_BUGFIX
QSizeF localSize;
if (elementId.isEmpty() || multipleImages) {
localSize = size;
} else {
localSize = elementSize(elementId);
}
if (localSize.isEmpty())
return;
QTransform transform = itemPainter->worldTransform();
if (size.isValid()) {
transform.scale(size.width() / localSize.width(),
size.height() / localSize.height());
}
#endif
createRenderer();
#if SVG_CACHE_BUGFIX
QLineF v1 = transform.map(QLineF(0, 0, 1, 0));
QLineF v2 = transform.map(QLineF(0, 0, 0, 1));
QString id = QString::fromLatin1("%7_%6_%5_%4_%3_%2_%1").arg(size.width())
.arg(size.height())
.arg((int) v1.dx())
.arg((int) v1.dy())
.arg((int) v2.dx())
.arg((int) v2.dy())
.arg(path);
#else
QSize size;
if (elementId.isEmpty() || multipleImages) {
size = s.toSize();
} else {
size = elementSize(elementId);
}
if (!size.isValid()) {
p = QPixmap();
return;
}
QString id = QString::fromLatin1("%3_%2_%1_").arg(size.width())
.arg(size.height())
.arg(path);
#endif
if (!elementId.isEmpty()) {
id.append(elementId);
}
@ -175,45 +154,15 @@ class Svg::Private
} else {
//kDebug() << "didn't find cached version of " << id << ", so re-rendering";
}
#if !SVG_CACHE_BUGFIX
// we have to re-render this puppy
QSize s;
if (elementId.isEmpty() || multipleImages) {
s = size.toSize();
} else {
s = elementSize(elementId);
}
//kDebug() << "size for " << elementId << " is " << s;
// we have to re-render this puppy
if (!s.isValid()) {
p = QPixmap();
return;
}
#endif
p = QPixmap(size);
#if SVG_CACHE_BUGFIX
QRect deviceRect = transform.mapRect(QRectF(QPointF(), localSize)).toRect();
if (deviceRect.isEmpty())
return;
p = QPixmap(deviceRect.size());
#else
p = QPixmap(s);
#endif
p.fill(Qt::transparent);
QPainter renderPainter(&p);
#if SVG_CACHE_BUGFIX
QPointF tl = deviceRect.topLeft();
QTransform xform = QTransform().translate(-tl.x(), -tl.y());
xform = itemPainter->worldTransform() * xform;
renderPainter.setRenderHints(renderPainter.renderHints(), false);
renderPainter.setRenderHints(itemPainter->renderHints(), true);
renderPainter.setWorldTransform(xform, true);
#endif
if (elementId.isEmpty()) {
renderer->render(&renderPainter);
} else {
@ -229,7 +178,7 @@ class Svg::Private
p = p.fromImage(itmp);
}
if (!QPixmapCache::insert( id, p )) {
if (!QPixmapCache::insert(id, p)) {
//kDebug() << "pixmap cache is too small for inserting" << id << "of size" << s;
}
}
@ -361,18 +310,7 @@ void Svg::paint(QPainter* painter, const QPointF& point, const QString& elementI
return;
}
#if SVG_CACHE_BUGFIX
painter->save();
QTransform x = painter->worldTransform();
painter->setWorldTransform(QTransform(), false);
//kDebug() << "pix size is " << pix.size();
painter->drawPixmap(x.map(point), pix);
painter->restore();
#else
painter->drawPixmap(QRectF(point, pix.size()), pix, QRectF(QPointF(0,0), pix.size()));
#endif
}
void Svg::paint(QPainter* painter, int x, int y, const QString& elementID)
@ -384,17 +322,7 @@ void Svg::paint(QPainter* painter, const QRectF& rect, const QString& elementID)
{
QPixmap pix;
d->findInCache(pix, elementID, painter, rect.size());
#if SVG_CACHE_BUGFIX
if (pix.isNull())
return;
painter->save();
QTransform x = painter->worldTransform();
painter->setWorldTransform(QTransform());
painter->drawPixmap(x.map(rect.topLeft()) , pix);
painter->restore();
#else
painter->drawPixmap(rect, pix, QRectF(QPointF(0,0), pix.size()));
#endif
}
QSize Svg::size() const