A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

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

+158 -18
+14 -5
utils/themeeditor/graphics/rbfont.cpp
··· 21 21 22 22 #include "rbfont.h" 23 23 #include "rbfontcache.h" 24 + #include "rbtextcache.h" 24 25 25 26 #include <QFont> 26 27 #include <QBrush> ··· 166 167 RBText* RBFont::renderText(QString text, QColor color, int viewWidth, 167 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 177 int firstChar = header.value("firstchar").toInt(); 170 178 int height = header.value("height").toInt(); 171 179 int maxWidth = header.value("maxwidth").toInt(); ··· 184 192 for(int i = 0; i < widths.count(); i++) 185 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)); 190 - image.setColor(1, color.rgb()); 197 + image->setColor(0, qRgba(0,0,0,0)); 198 + image->setColor(1, color.rgb()); 191 199 192 200 /* Drawing the text */ 193 201 int startX = 0; ··· 214 222 for(int bit = 0; bit < 8; bit++) 215 223 { 216 224 if(mask & data) 217 - image.setPixel(x, y, 1); 225 + image->setPixel(x, y, 1); 218 226 else 219 - image.setPixel(x, y, 0); 227 + image->setPixel(x, y, 0); 220 228 221 229 y++; 222 230 mask <<= 1; ··· 230 238 startX += widths[i]; 231 239 } 232 240 241 + RBTextCache::insert(header.value("filename").toString() + text, image); 233 242 return new RBText(image, viewWidth, parent); 234 243 235 244 }
+21
utils/themeeditor/graphics/rbfontcache.cpp
··· 22 22 #include "rbfontcache.h" 23 23 24 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 + }
+2
utils/themeeditor/graphics/rbfontcache.h
··· 23 23 #define RBFONTCACHE_H 24 24 25 25 #include <QHash> 26 + #include <QVariant> 26 27 27 28 class RBFontCache 28 29 { ··· 39 40 40 41 static CacheInfo* lookup(QString key){ return cache.value(key, 0); } 41 42 static void insert(QString key, CacheInfo* data){ cache.insert(key, data); } 43 + static void clearCache(); 42 44 43 45 private: 44 46 static QHash<QString, CacheInfo*> cache;
+7 -7
utils/themeeditor/graphics/rbtext.cpp
··· 23 23 24 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 27 :QGraphicsItem(parent), image(image), maxWidth(maxWidth) 28 28 { 29 29 } 30 30 31 31 QRectF RBText::boundingRect() const 32 32 { 33 - if(image.width() < maxWidth) 34 - return QRectF(0, 0, image.width(), image.height()); 33 + if(image->width() < maxWidth) 34 + return QRectF(0, 0, image->width(), image->height()); 35 35 else 36 - return QRectF(0, 0, maxWidth, image.height()); 36 + return QRectF(0, 0, maxWidth, image->height()); 37 37 } 38 38 39 39 void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 40 40 QWidget *widget) 41 41 { 42 - if(image.width() < maxWidth) 43 - painter->drawImage(0, 0, image, 0, 0, image.width(), image.height()); 42 + if(image->width() < maxWidth) 43 + painter->drawImage(0, 0, *image, 0, 0, image->width(), image->height()); 44 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 }
+2 -2
utils/themeeditor/graphics/rbtext.h
··· 28 28 class RBText : public QGraphicsItem 29 29 { 30 30 public: 31 - RBText(const QImage& image, int maxWidth, QGraphicsItem* parent); 31 + RBText(QImage* image, int maxWidth, QGraphicsItem* parent); 32 32 33 33 QRectF boundingRect() const; 34 34 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 35 35 QWidget *widget); 36 36 37 37 private: 38 - QImage image; 38 + QImage* image; 39 39 int maxWidth; 40 40 41 41 };
+35
utils/themeeditor/graphics/rbtextcache.cpp
··· 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 + }
+39
utils/themeeditor/graphics/rbtextcache.h
··· 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
+5
utils/themeeditor/gui/editorwindow.cpp
··· 22 22 #include "editorwindow.h" 23 23 #include "projectmodel.h" 24 24 #include "ui_editorwindow.h" 25 + #include "rbfontcache.h" 26 + #include "rbtextcache.h" 25 27 26 28 #include <QDesktopWidget> 27 29 #include <QFileSystemModel> ··· 49 51 delete project; 50 52 delete deviceConfig; 51 53 delete deviceDock; 54 + 55 + RBFontCache::clearCache(); 56 + RBTextCache::clearCache(); 52 57 } 53 58 54 59 void EditorWindow::loadTabFromSkinFile(QString fileName)
+19 -2
utils/themeeditor/gui/skindocument.cpp
··· 31 31 32 32 #include <QDebug> 33 33 34 + const int SkinDocument::updateInterval = 500; 35 + 34 36 SkinDocument::SkinDocument(QLabel* statusLabel, ProjectModel* project, 35 37 DeviceState* device, QWidget *parent) 36 38 :TabContent(parent), statusLabel(statusLabel), ··· 70 72 /* Setting the title */ 71 73 QStringList decomposed = fileName.split('/'); 72 74 titleText = decomposed.last(); 75 + 76 + lastUpdate = QTime::currentTime(); 73 77 } 74 78 75 79 SkinDocument::~SkinDocument() ··· 161 165 findReplace->hide(); 162 166 163 167 settingsChanged(); 168 + 169 + /* Setting up a timer to check for updates */ 170 + checkUpdate.setInterval(500); 171 + QObject::connect(&checkUpdate, SIGNAL(timeout()), 172 + this, SLOT(codeChanged())); 164 173 } 165 174 166 175 void SkinDocument::settingsChanged() ··· 273 282 else 274 283 emit titleChanged(titleText); 275 284 276 - model->render(project, device, &fileName); 277 - 285 + if(lastUpdate.msecsTo(QTime::currentTime()) >= updateInterval) 286 + { 287 + model->render(project, device, &fileName); 288 + checkUpdate.stop(); 289 + lastUpdate = QTime::currentTime(); 290 + } 291 + else 292 + { 293 + checkUpdate.start(); 294 + } 278 295 cursorChanged(); 279 296 280 297 }
+6
utils/themeeditor/gui/skindocument.h
··· 26 26 #include <QLabel> 27 27 #include <QHBoxLayout> 28 28 #include <QGraphicsScene> 29 + #include <QTime> 30 + #include <QTimer> 29 31 30 32 #include "findreplacedialog.h" 31 33 ··· 113 115 DeviceState* device; 114 116 115 117 FindReplaceDialog* findReplace; 118 + 119 + QTime lastUpdate; 120 + static const int updateInterval; 121 + QTimer checkUpdate; 116 122 }; 117 123 118 124 #endif // SKINDOCUMENT_H
+8 -2
utils/themeeditor/themeeditor.pro
··· 1 + # Enabling profiling 2 + QMAKE_CXXFLAGS_DEBUG += -pg 3 + QMAKE_LFLAGS_DEBUG += -pg 4 + 1 5 # build in a separate folder. 2 6 MYBUILDDIR = $$OUT_PWD/build/ 3 7 OBJECTS_DIR = $$MYBUILDDIR/o ··· 47 51 graphics/rbprogressbar.h \ 48 52 gui/findreplacedialog.h \ 49 53 graphics/rbtext.h \ 50 - graphics/rbfontcache.h 54 + graphics/rbfontcache.h \ 55 + graphics/rbtextcache.h 51 56 SOURCES += main.cpp \ 52 57 models/parsetreemodel.cpp \ 53 58 models/parsetreenode.cpp \ ··· 69 74 graphics/rbprogressbar.cpp \ 70 75 gui/findreplacedialog.cpp \ 71 76 graphics/rbtext.cpp \ 72 - graphics/rbfontcache.cpp 77 + graphics/rbfontcache.cpp \ 78 + graphics/rbtextcache.cpp 73 79 OTHER_FILES += README \ 74 80 resources/windowicon.png \ 75 81 resources/appicon.xcf \