forked from len0rd/rockbox
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
This commit is contained in:
parent
6f06793f58
commit
6d609e009f
11 changed files with 158 additions and 18 deletions
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
|
35
utils/themeeditor/graphics/rbtextcache.cpp
Normal file
35
utils/themeeditor/graphics/rbtextcache.cpp
Normal file
|
@ -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();
|
||||
}
|
39
utils/themeeditor/graphics/rbtextcache.h
Normal file
39
utils/themeeditor/graphics/rbtextcache.h
Normal file
|
@ -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
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
||||
if(lastUpdate.msecsTo(QTime::currentTime()) >= updateInterval)
|
||||
{
|
||||
model->render(project, device, &fileName);
|
||||
|
||||
checkUpdate.stop();
|
||||
lastUpdate = QTime::currentTime();
|
||||
}
|
||||
else
|
||||
{
|
||||
checkUpdate.start();
|
||||
}
|
||||
cursorChanged();
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue