diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-07-07 09:33:47 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-07-07 09:33:47 +0000 |
commit | 6d609e009f4836418bbe5b404be8ae03d29ef8cb (patch) | |
tree | 708bc7ba7bce2c7fc01cb719b594b296e51b17d0 /utils/themeeditor/graphics | |
parent | 6f06793f58f520ec7d44683f6447c0b540a265b3 (diff) | |
download | rockbox-6d609e009f4836418bbe5b404be8ae03d29ef8cb.tar.gz 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/themeeditor/graphics')
-rw-r--r-- | utils/themeeditor/graphics/rbfont.cpp | 19 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbfontcache.cpp | 21 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbfontcache.h | 2 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbtext.cpp | 14 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbtext.h | 4 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbtextcache.cpp | 35 | ||||
-rw-r--r-- | utils/themeeditor/graphics/rbtextcache.h | 39 |
7 files changed, 120 insertions, 14 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 @@ | |||
21 | 21 | ||
22 | #include "rbfont.h" | 22 | #include "rbfont.h" |
23 | #include "rbfontcache.h" | 23 | #include "rbfontcache.h" |
24 | #include "rbtextcache.h" | ||
24 | 25 | ||
25 | #include <QFont> | 26 | #include <QFont> |
26 | #include <QBrush> | 27 | #include <QBrush> |
@@ -166,6 +167,13 @@ RBFont::~RBFont() | |||
166 | RBText* RBFont::renderText(QString text, QColor color, int viewWidth, | 167 | RBText* RBFont::renderText(QString text, QColor color, int viewWidth, |
167 | QGraphicsItem *parent) | 168 | QGraphicsItem *parent) |
168 | { | 169 | { |
170 | |||
171 | /* Checking for a cache hit first */ | ||
172 | QImage* image = RBTextCache::lookup(header.value("filename").toString() | ||
173 | + text); | ||
174 | if(image) | ||
175 | return new RBText(image, viewWidth, parent); | ||
176 | |||
169 | int firstChar = header.value("firstchar").toInt(); | 177 | int firstChar = header.value("firstchar").toInt(); |
170 | int height = header.value("height").toInt(); | 178 | int height = header.value("height").toInt(); |
171 | int maxWidth = header.value("maxwidth").toInt(); | 179 | int maxWidth = header.value("maxwidth").toInt(); |
@@ -184,10 +192,10 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth, | |||
184 | for(int i = 0; i < widths.count(); i++) | 192 | for(int i = 0; i < widths.count(); i++) |
185 | totalWidth += widths[i]; | 193 | totalWidth += widths[i]; |
186 | 194 | ||
187 | QImage image(totalWidth, height, QImage::Format_Indexed8); | 195 | image = new QImage(totalWidth, height, QImage::Format_Indexed8); |
188 | 196 | ||
189 | image.setColor(0, qRgba(0,0,0,0)); | 197 | image->setColor(0, qRgba(0,0,0,0)); |
190 | image.setColor(1, color.rgb()); | 198 | image->setColor(1, color.rgb()); |
191 | 199 | ||
192 | /* Drawing the text */ | 200 | /* Drawing the text */ |
193 | int startX = 0; | 201 | int startX = 0; |
@@ -214,9 +222,9 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth, | |||
214 | for(int bit = 0; bit < 8; bit++) | 222 | for(int bit = 0; bit < 8; bit++) |
215 | { | 223 | { |
216 | if(mask & data) | 224 | if(mask & data) |
217 | image.setPixel(x, y, 1); | 225 | image->setPixel(x, y, 1); |
218 | else | 226 | else |
219 | image.setPixel(x, y, 0); | 227 | image->setPixel(x, y, 0); |
220 | 228 | ||
221 | y++; | 229 | y++; |
222 | mask <<= 1; | 230 | mask <<= 1; |
@@ -230,6 +238,7 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth, | |||
230 | startX += widths[i]; | 238 | startX += widths[i]; |
231 | } | 239 | } |
232 | 240 | ||
241 | RBTextCache::insert(header.value("filename").toString() + text, image); | ||
233 | return new RBText(image, viewWidth, parent); | 242 | return new RBText(image, viewWidth, parent); |
234 | 243 | ||
235 | } | 244 | } |
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 @@ | |||
22 | #include "rbfontcache.h" | 22 | #include "rbfontcache.h" |
23 | 23 | ||
24 | QHash<QString, RBFontCache::CacheInfo*> RBFontCache::cache; | 24 | QHash<QString, RBFontCache::CacheInfo*> RBFontCache::cache; |
25 | |||
26 | void RBFontCache::clearCache() | ||
27 | { | ||
28 | QHash<QString, CacheInfo*>::iterator i; | ||
29 | for(i = cache.begin(); i != cache.end(); i++) | ||
30 | { | ||
31 | CacheInfo* c = *i; | ||
32 | if(c->imageData) | ||
33 | delete c->imageData; | ||
34 | |||
35 | if(c->offsetData) | ||
36 | delete c->offsetData; | ||
37 | |||
38 | if(c->widthData) | ||
39 | delete c->widthData; | ||
40 | |||
41 | delete c; | ||
42 | } | ||
43 | |||
44 | cache.clear(); | ||
45 | } | ||
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 @@ | |||
23 | #define RBFONTCACHE_H | 23 | #define RBFONTCACHE_H |
24 | 24 | ||
25 | #include <QHash> | 25 | #include <QHash> |
26 | #include <QVariant> | ||
26 | 27 | ||
27 | class RBFontCache | 28 | class RBFontCache |
28 | { | 29 | { |
@@ -39,6 +40,7 @@ public: | |||
39 | 40 | ||
40 | static CacheInfo* lookup(QString key){ return cache.value(key, 0); } | 41 | static CacheInfo* lookup(QString key){ return cache.value(key, 0); } |
41 | static void insert(QString key, CacheInfo* data){ cache.insert(key, data); } | 42 | static void insert(QString key, CacheInfo* data){ cache.insert(key, data); } |
43 | static void clearCache(); | ||
42 | 44 | ||
43 | private: | 45 | private: |
44 | static QHash<QString, CacheInfo*> cache; | 46 | 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 @@ | |||
23 | 23 | ||
24 | #include <QPainter> | 24 | #include <QPainter> |
25 | 25 | ||
26 | RBText::RBText(const QImage &image, int maxWidth, QGraphicsItem *parent) | 26 | RBText::RBText(QImage* image, int maxWidth, QGraphicsItem *parent) |
27 | :QGraphicsItem(parent), image(image), maxWidth(maxWidth) | 27 | :QGraphicsItem(parent), image(image), maxWidth(maxWidth) |
28 | { | 28 | { |
29 | } | 29 | } |
30 | 30 | ||
31 | QRectF RBText::boundingRect() const | 31 | QRectF RBText::boundingRect() const |
32 | { | 32 | { |
33 | if(image.width() < maxWidth) | 33 | if(image->width() < maxWidth) |
34 | return QRectF(0, 0, image.width(), image.height()); | 34 | return QRectF(0, 0, image->width(), image->height()); |
35 | else | 35 | else |
36 | return QRectF(0, 0, maxWidth, image.height()); | 36 | return QRectF(0, 0, maxWidth, image->height()); |
37 | } | 37 | } |
38 | 38 | ||
39 | void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, | 39 | void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
40 | QWidget *widget) | 40 | QWidget *widget) |
41 | { | 41 | { |
42 | if(image.width() < maxWidth) | 42 | if(image->width() < maxWidth) |
43 | painter->drawImage(0, 0, image, 0, 0, image.width(), image.height()); | 43 | painter->drawImage(0, 0, *image, 0, 0, image->width(), image->height()); |
44 | else | 44 | else |
45 | painter->drawImage(0, 0, image, 0, 0, maxWidth, image.height()); | 45 | painter->drawImage(0, 0, *image, 0, 0, maxWidth, image->height()); |
46 | } | 46 | } |
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 @@ | |||
28 | class RBText : public QGraphicsItem | 28 | class RBText : public QGraphicsItem |
29 | { | 29 | { |
30 | public: | 30 | public: |
31 | RBText(const QImage& image, int maxWidth, QGraphicsItem* parent); | 31 | RBText(QImage* image, int maxWidth, QGraphicsItem* parent); |
32 | 32 | ||
33 | QRectF boundingRect() const; | 33 | QRectF boundingRect() const; |
34 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, | 34 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
35 | QWidget *widget); | 35 | QWidget *widget); |
36 | 36 | ||
37 | private: | 37 | private: |
38 | QImage image; | 38 | QImage* image; |
39 | int maxWidth; | 39 | int maxWidth; |
40 | 40 | ||
41 | }; | 41 | }; |
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Robert Bieber | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "rbtextcache.h" | ||
23 | |||
24 | QHash<QString, QImage*> RBTextCache::cache; | ||
25 | |||
26 | void RBTextCache::clearCache() | ||
27 | { | ||
28 | QHash<QString, QImage*>::iterator i; | ||
29 | for(i = cache.begin(); i != cache.end(); i++) | ||
30 | { | ||
31 | delete (*i); | ||
32 | } | ||
33 | |||
34 | cache.clear(); | ||
35 | } | ||
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Robert Bieber | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef RBTEXTCACHE_H | ||
23 | #define RBTEXTCACHE_H | ||
24 | |||
25 | #include <QHash> | ||
26 | #include <QImage> | ||
27 | |||
28 | class RBTextCache | ||
29 | { | ||
30 | public: | ||
31 | static QImage* lookup(QString key){ return cache.value(key, 0); } | ||
32 | static void insert(QString key, QImage* im){ cache.insert(key, im); } | ||
33 | static void clearCache(); | ||
34 | |||
35 | private: | ||
36 | static QHash<QString, QImage*> cache; | ||
37 | }; | ||
38 | |||
39 | #endif // RBTEXTCACHE_H | ||