summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-07-07 09:33:47 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-07-07 09:33:47 +0000
commit6d609e009f4836418bbe5b404be8ae03d29ef8cb (patch)
tree708bc7ba7bce2c7fc01cb719b594b296e51b17d0 /utils
parent6f06793f58f520ec7d44683f6447c0b540a265b3 (diff)
downloadrockbox-6d609e009f4836418bbe5b404be8ae03d29ef8cb.tar.gz
rockbox-6d609e009f4836418bbe5b404be8ae03d29ef8cb.tar.bz2
rockbox-6d609e009f4836418bbe5b404be8ae03d29ef8cb.zip
Theme Editor: Implemented caching for rendered text, added profiling info to debug build, added a 500msec delay when rendering after code changes to prevent editor from hanging on large themes
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27332 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils')
-rw-r--r--utils/themeeditor/graphics/rbfont.cpp19
-rw-r--r--utils/themeeditor/graphics/rbfontcache.cpp21
-rw-r--r--utils/themeeditor/graphics/rbfontcache.h2
-rw-r--r--utils/themeeditor/graphics/rbtext.cpp14
-rw-r--r--utils/themeeditor/graphics/rbtext.h4
-rw-r--r--utils/themeeditor/graphics/rbtextcache.cpp35
-rw-r--r--utils/themeeditor/graphics/rbtextcache.h39
-rw-r--r--utils/themeeditor/gui/editorwindow.cpp5
-rw-r--r--utils/themeeditor/gui/skindocument.cpp21
-rw-r--r--utils/themeeditor/gui/skindocument.h6
-rw-r--r--utils/themeeditor/themeeditor.pro10
11 files changed, 158 insertions, 18 deletions
diff --git a/utils/themeeditor/graphics/rbfont.cpp b/utils/themeeditor/graphics/rbfont.cpp
index cd68af99fe..3b7397283c 100644
--- a/utils/themeeditor/graphics/rbfont.cpp
+++ b/utils/themeeditor/graphics/rbfont.cpp
@@ -21,6 +21,7 @@
#include "rbfont.h"
#include "rbfontcache.h"
+#include "rbtextcache.h"
#include <QFont>
#include <QBrush>
@@ -166,6 +167,13 @@ RBFont::~RBFont()
RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
QGraphicsItem *parent)
{
+
+ /* Checking for a cache hit first */
+ QImage* image = RBTextCache::lookup(header.value("filename").toString()
+ + text);
+ if(image)
+ return new RBText(image, viewWidth, parent);
+
int firstChar = header.value("firstchar").toInt();
int height = header.value("height").toInt();
int maxWidth = header.value("maxwidth").toInt();
@@ -184,10 +192,10 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
for(int i = 0; i < widths.count(); i++)
totalWidth += widths[i];
- QImage image(totalWidth, height, QImage::Format_Indexed8);
+ image = new QImage(totalWidth, height, QImage::Format_Indexed8);
- image.setColor(0, qRgba(0,0,0,0));
- image.setColor(1, color.rgb());
+ image->setColor(0, qRgba(0,0,0,0));
+ image->setColor(1, color.rgb());
/* Drawing the text */
int startX = 0;
@@ -214,9 +222,9 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
for(int bit = 0; bit < 8; bit++)
{
if(mask & data)
- image.setPixel(x, y, 1);
+ image->setPixel(x, y, 1);
else
- image.setPixel(x, y, 0);
+ image->setPixel(x, y, 0);
y++;
mask <<= 1;
@@ -230,6 +238,7 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
startX += widths[i];
}
+ RBTextCache::insert(header.value("filename").toString() + text, image);
return new RBText(image, viewWidth, parent);
}
diff --git a/utils/themeeditor/graphics/rbfontcache.cpp b/utils/themeeditor/graphics/rbfontcache.cpp
index 3b6d56fd58..7ec77e11a1 100644
--- a/utils/themeeditor/graphics/rbfontcache.cpp
+++ b/utils/themeeditor/graphics/rbfontcache.cpp
@@ -22,3 +22,24 @@
#include "rbfontcache.h"
QHash<QString, RBFontCache::CacheInfo*> RBFontCache::cache;
+
+void RBFontCache::clearCache()
+{
+ QHash<QString, CacheInfo*>::iterator i;
+ for(i = cache.begin(); i != cache.end(); i++)
+ {
+ CacheInfo* c = *i;
+ if(c->imageData)
+ delete c->imageData;
+
+ if(c->offsetData)
+ delete c->offsetData;
+
+ if(c->widthData)
+ delete c->widthData;
+
+ delete c;
+ }
+
+ cache.clear();
+}
diff --git a/utils/themeeditor/graphics/rbfontcache.h b/utils/themeeditor/graphics/rbfontcache.h
index 50a6d2ec48..62d82b7188 100644
--- a/utils/themeeditor/graphics/rbfontcache.h
+++ b/utils/themeeditor/graphics/rbfontcache.h
@@ -23,6 +23,7 @@
#define RBFONTCACHE_H
#include <QHash>
+#include <QVariant>
class RBFontCache
{
@@ -39,6 +40,7 @@ public:
static CacheInfo* lookup(QString key){ return cache.value(key, 0); }
static void insert(QString key, CacheInfo* data){ cache.insert(key, data); }
+ static void clearCache();
private:
static QHash<QString, CacheInfo*> cache;
diff --git a/utils/themeeditor/graphics/rbtext.cpp b/utils/themeeditor/graphics/rbtext.cpp
index d7fe542ab1..4666f9ae99 100644
--- a/utils/themeeditor/graphics/rbtext.cpp
+++ b/utils/themeeditor/graphics/rbtext.cpp
@@ -23,24 +23,24 @@
#include <QPainter>
-RBText::RBText(const QImage &image, int maxWidth, QGraphicsItem *parent)
+RBText::RBText(QImage* image, int maxWidth, QGraphicsItem *parent)
:QGraphicsItem(parent), image(image), maxWidth(maxWidth)
{
}
QRectF RBText::boundingRect() const
{
- if(image.width() < maxWidth)
- return QRectF(0, 0, image.width(), image.height());
+ if(image->width() < maxWidth)
+ return QRectF(0, 0, image->width(), image->height());
else
- return QRectF(0, 0, maxWidth, image.height());
+ return QRectF(0, 0, maxWidth, image->height());
}
void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
- if(image.width() < maxWidth)
- painter->drawImage(0, 0, image, 0, 0, image.width(), image.height());
+ if(image->width() < maxWidth)
+ painter->drawImage(0, 0, *image, 0, 0, image->width(), image->height());
else
- painter->drawImage(0, 0, image, 0, 0, maxWidth, image.height());
+ painter->drawImage(0, 0, *image, 0, 0, maxWidth, image->height());
}
diff --git a/utils/themeeditor/graphics/rbtext.h b/utils/themeeditor/graphics/rbtext.h
index d03505491e..936a809f6c 100644
--- a/utils/themeeditor/graphics/rbtext.h
+++ b/utils/themeeditor/graphics/rbtext.h
@@ -28,14 +28,14 @@
class RBText : public QGraphicsItem
{
public:
- RBText(const QImage& image, int maxWidth, QGraphicsItem* parent);
+ RBText(QImage* image, int maxWidth, QGraphicsItem* parent);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
private:
- QImage image;
+ QImage* image;
int maxWidth;
};
diff --git a/utils/themeeditor/graphics/rbtextcache.cpp b/utils/themeeditor/graphics/rbtextcache.cpp
new file mode 100644
index 0000000000..0116b80311
--- /dev/null
+++ b/utils/themeeditor/graphics/rbtextcache.cpp
@@ -0,0 +1,35 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2010 Robert Bieber
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "rbtextcache.h"
+
+QHash<QString, QImage*> RBTextCache::cache;
+
+void RBTextCache::clearCache()
+{
+ QHash<QString, QImage*>::iterator i;
+ for(i = cache.begin(); i != cache.end(); i++)
+ {
+ delete (*i);
+ }
+
+ cache.clear();
+}
diff --git a/utils/themeeditor/graphics/rbtextcache.h b/utils/themeeditor/graphics/rbtextcache.h
new file mode 100644
index 0000000000..a0c0e42e8d
--- /dev/null
+++ b/utils/themeeditor/graphics/rbtextcache.h
@@ -0,0 +1,39 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2010 Robert Bieber
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef RBTEXTCACHE_H
+#define RBTEXTCACHE_H
+
+#include <QHash>
+#include <QImage>
+
+class RBTextCache
+{
+public:
+ static QImage* lookup(QString key){ return cache.value(key, 0); }
+ static void insert(QString key, QImage* im){ cache.insert(key, im); }
+ static void clearCache();
+
+private:
+ static QHash<QString, QImage*> cache;
+};
+
+#endif // RBTEXTCACHE_H
diff --git a/utils/themeeditor/gui/editorwindow.cpp b/utils/themeeditor/gui/editorwindow.cpp
index 4c073b9e0b..171e7b7019 100644
--- a/utils/themeeditor/gui/editorwindow.cpp
+++ b/utils/themeeditor/gui/editorwindow.cpp
@@ -22,6 +22,8 @@
#include "editorwindow.h"
#include "projectmodel.h"
#include "ui_editorwindow.h"
+#include "rbfontcache.h"
+#include "rbtextcache.h"
#include <QDesktopWidget>
#include <QFileSystemModel>
@@ -49,6 +51,9 @@ EditorWindow::~EditorWindow()
delete project;
delete deviceConfig;
delete deviceDock;
+
+ RBFontCache::clearCache();
+ RBTextCache::clearCache();
}
void EditorWindow::loadTabFromSkinFile(QString fileName)
diff --git a/utils/themeeditor/gui/skindocument.cpp b/utils/themeeditor/gui/skindocument.cpp
index 9a381a9589..f04c12d213 100644
--- a/utils/themeeditor/gui/skindocument.cpp
+++ b/utils/themeeditor/gui/skindocument.cpp
@@ -31,6 +31,8 @@
#include <QDebug>
+const int SkinDocument::updateInterval = 500;
+
SkinDocument::SkinDocument(QLabel* statusLabel, ProjectModel* project,
DeviceState* device, QWidget *parent)
:TabContent(parent), statusLabel(statusLabel),
@@ -70,6 +72,8 @@ SkinDocument::SkinDocument(QLabel* statusLabel, QString file,
/* Setting the title */
QStringList decomposed = fileName.split('/');
titleText = decomposed.last();
+
+ lastUpdate = QTime::currentTime();
}
SkinDocument::~SkinDocument()
@@ -161,6 +165,11 @@ void SkinDocument::setupUI()
findReplace->hide();
settingsChanged();
+
+ /* Setting up a timer to check for updates */
+ checkUpdate.setInterval(500);
+ QObject::connect(&checkUpdate, SIGNAL(timeout()),
+ this, SLOT(codeChanged()));
}
void SkinDocument::settingsChanged()
@@ -273,8 +282,16 @@ void SkinDocument::codeChanged()
else
emit titleChanged(titleText);
- model->render(project, device, &fileName);
-
+ if(lastUpdate.msecsTo(QTime::currentTime()) >= updateInterval)
+ {
+ model->render(project, device, &fileName);
+ checkUpdate.stop();
+ lastUpdate = QTime::currentTime();
+ }
+ else
+ {
+ checkUpdate.start();
+ }
cursorChanged();
}
diff --git a/utils/themeeditor/gui/skindocument.h b/utils/themeeditor/gui/skindocument.h
index 7563b3cb53..f7ac2bbc2c 100644
--- a/utils/themeeditor/gui/skindocument.h
+++ b/utils/themeeditor/gui/skindocument.h
@@ -26,6 +26,8 @@
#include <QLabel>
#include <QHBoxLayout>
#include <QGraphicsScene>
+#include <QTime>
+#include <QTimer>
#include "findreplacedialog.h"
@@ -113,6 +115,10 @@ private:
DeviceState* device;
FindReplaceDialog* findReplace;
+
+ QTime lastUpdate;
+ static const int updateInterval;
+ QTimer checkUpdate;
};
#endif // SKINDOCUMENT_H
diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro
index b0824cfe84..904adf239b 100644
--- a/utils/themeeditor/themeeditor.pro
+++ b/utils/themeeditor/themeeditor.pro
@@ -1,3 +1,7 @@
+# Enabling profiling
+QMAKE_CXXFLAGS_DEBUG += -pg
+QMAKE_LFLAGS_DEBUG += -pg
+
# build in a separate folder.
MYBUILDDIR = $$OUT_PWD/build/
OBJECTS_DIR = $$MYBUILDDIR/o
@@ -47,7 +51,8 @@ HEADERS += models/parsetreemodel.h \
graphics/rbprogressbar.h \
gui/findreplacedialog.h \
graphics/rbtext.h \
- graphics/rbfontcache.h
+ graphics/rbfontcache.h \
+ graphics/rbtextcache.h
SOURCES += main.cpp \
models/parsetreemodel.cpp \
models/parsetreenode.cpp \
@@ -69,7 +74,8 @@ SOURCES += main.cpp \
graphics/rbprogressbar.cpp \
gui/findreplacedialog.cpp \
graphics/rbtext.cpp \
- graphics/rbfontcache.cpp
+ graphics/rbfontcache.cpp \
+ graphics/rbtextcache.cpp
OTHER_FILES += README \
resources/windowicon.png \
resources/appicon.xcf \