attempt to share renderers. this should make quite a difference, one would hope. needs more testing.
svn path=/trunk/KDE/kdebase/workspace/plasma/lib/; revision=669390
This commit is contained in:
parent
c7b7b5b8ca
commit
498ce9d548
51
svg.cpp
51
svg.cpp
@ -22,14 +22,40 @@
|
|||||||
#include <QMatrix>
|
#include <QMatrix>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
|
#include <QSharedData>
|
||||||
|
|
||||||
#include <KDebug>
|
#include <KDebug>
|
||||||
|
#include <KSharedPtr>
|
||||||
#include <KSvgRenderer>
|
#include <KSvgRenderer>
|
||||||
|
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class SharedSvgRenderer : public KSvgRenderer, public QSharedData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef KSharedPtr<SharedSvgRenderer> Ptr;
|
||||||
|
|
||||||
|
SharedSvgRenderer(QObject *parent = 0)
|
||||||
|
: KSvgRenderer(parent)
|
||||||
|
{}
|
||||||
|
|
||||||
|
SharedSvgRenderer(const QString &filename, QObject *parent = 0)
|
||||||
|
: KSvgRenderer(filename, parent)
|
||||||
|
{}
|
||||||
|
|
||||||
|
SharedSvgRenderer(const QByteArray &contents, QObject *parent = 0)
|
||||||
|
: KSvgRenderer(contents, parent)
|
||||||
|
{}
|
||||||
|
|
||||||
|
~SharedSvgRenderer()
|
||||||
|
{
|
||||||
|
kDebug() << "leaving this world for a better one." << endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class Svg::Private
|
class Svg::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -47,7 +73,12 @@ class Svg::Private
|
|||||||
|
|
||||||
~Private()
|
~Private()
|
||||||
{
|
{
|
||||||
delete renderer;
|
if (renderer.count() == 2) {
|
||||||
|
// this and the cache reference it; and boy is this not thread safe ;)
|
||||||
|
renderers.erase(renderers.find(themePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeFromCache()
|
void removeFromCache()
|
||||||
@ -112,7 +143,15 @@ class Svg::Private
|
|||||||
|
|
||||||
//TODO: connect the renderer's repaintNeeded to the Plasma::Svg signal
|
//TODO: connect the renderer's repaintNeeded to the Plasma::Svg signal
|
||||||
// take into consideration for cache, e.g. don't cache if svg is animated
|
// take into consideration for cache, e.g. don't cache if svg is animated
|
||||||
renderer = new KSvgRenderer(path);
|
QHash<QString, SharedSvgRenderer::Ptr>::const_iterator it = renderers.find(path);
|
||||||
|
|
||||||
|
if (it != renderers.end()) {
|
||||||
|
kDebug() << "gots us an existing one!" << endl;
|
||||||
|
renderer = it.value();
|
||||||
|
} else {
|
||||||
|
renderer = new SharedSvgRenderer(path);
|
||||||
|
renderers[path] = renderer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize elementSize( const QString& elementId )
|
QSize elementSize( const QString& elementId )
|
||||||
@ -127,8 +166,8 @@ class Svg::Private
|
|||||||
return elementSize.toSize();
|
return elementSize.toSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: share renderers between Svg objects with identical themePath
|
static QHash<QString, SharedSvgRenderer::Ptr> renderers;
|
||||||
KSvgRenderer* renderer;
|
SharedSvgRenderer::Ptr renderer;
|
||||||
QString themePath;
|
QString themePath;
|
||||||
QString path;
|
QString path;
|
||||||
QString id;
|
QString id;
|
||||||
@ -136,6 +175,8 @@ class Svg::Private
|
|||||||
bool themed;
|
bool themed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QHash<QString, SharedSvgRenderer::Ptr> Svg::Private:: renderers;
|
||||||
|
|
||||||
Svg::Svg( const QString& imagePath, QObject* parent )
|
Svg::Svg( const QString& imagePath, QObject* parent )
|
||||||
: QObject( parent ),
|
: QObject( parent ),
|
||||||
d( new Private( imagePath ) )
|
d( new Private( imagePath ) )
|
||||||
@ -199,7 +240,7 @@ void Svg::themeChanged()
|
|||||||
{
|
{
|
||||||
d->removeFromCache();
|
d->removeFromCache();
|
||||||
d->path.clear();
|
d->path.clear();
|
||||||
delete d->renderer;
|
//delete d->renderer; we're a KSharedPtr
|
||||||
d->renderer = 0;
|
d->renderer = 0;
|
||||||
emit repaintNeeded();
|
emit repaintNeeded();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user