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 "rbfont.h"
|
||||||
#include "rbfontcache.h"
|
#include "rbfontcache.h"
|
||||||
|
#include "rbtextcache.h"
|
||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
|
@ -166,6 +167,13 @@ RBFont::~RBFont()
|
||||||
RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
|
RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
|
||||||
QGraphicsItem *parent)
|
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 firstChar = header.value("firstchar").toInt();
|
||||||
int height = header.value("height").toInt();
|
int height = header.value("height").toInt();
|
||||||
int maxWidth = header.value("maxwidth").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++)
|
for(int i = 0; i < widths.count(); i++)
|
||||||
totalWidth += widths[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(0, qRgba(0,0,0,0));
|
||||||
image.setColor(1, color.rgb());
|
image->setColor(1, color.rgb());
|
||||||
|
|
||||||
/* Drawing the text */
|
/* Drawing the text */
|
||||||
int startX = 0;
|
int startX = 0;
|
||||||
|
@ -214,9 +222,9 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
|
||||||
for(int bit = 0; bit < 8; bit++)
|
for(int bit = 0; bit < 8; bit++)
|
||||||
{
|
{
|
||||||
if(mask & data)
|
if(mask & data)
|
||||||
image.setPixel(x, y, 1);
|
image->setPixel(x, y, 1);
|
||||||
else
|
else
|
||||||
image.setPixel(x, y, 0);
|
image->setPixel(x, y, 0);
|
||||||
|
|
||||||
y++;
|
y++;
|
||||||
mask <<= 1;
|
mask <<= 1;
|
||||||
|
@ -230,6 +238,7 @@ RBText* RBFont::renderText(QString text, QColor color, int viewWidth,
|
||||||
startX += widths[i];
|
startX += widths[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RBTextCache::insert(header.value("filename").toString() + text, image);
|
||||||
return new RBText(image, viewWidth, parent);
|
return new RBText(image, viewWidth, parent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,3 +22,24 @@
|
||||||
#include "rbfontcache.h"
|
#include "rbfontcache.h"
|
||||||
|
|
||||||
QHash<QString, RBFontCache::CacheInfo*> RBFontCache::cache;
|
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
|
#define RBFONTCACHE_H
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
class RBFontCache
|
class RBFontCache
|
||||||
{
|
{
|
||||||
|
@ -39,6 +40,7 @@ public:
|
||||||
|
|
||||||
static CacheInfo* lookup(QString key){ return cache.value(key, 0); }
|
static CacheInfo* lookup(QString key){ return cache.value(key, 0); }
|
||||||
static void insert(QString key, CacheInfo* data){ cache.insert(key, data); }
|
static void insert(QString key, CacheInfo* data){ cache.insert(key, data); }
|
||||||
|
static void clearCache();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QHash<QString, CacheInfo*> cache;
|
static QHash<QString, CacheInfo*> cache;
|
||||||
|
|
|
@ -23,24 +23,24 @@
|
||||||
|
|
||||||
#include <QPainter>
|
#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)
|
:QGraphicsItem(parent), image(image), maxWidth(maxWidth)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF RBText::boundingRect() const
|
QRectF RBText::boundingRect() const
|
||||||
{
|
{
|
||||||
if(image.width() < maxWidth)
|
if(image->width() < maxWidth)
|
||||||
return QRectF(0, 0, image.width(), image.height());
|
return QRectF(0, 0, image->width(), image->height());
|
||||||
else
|
else
|
||||||
return QRectF(0, 0, maxWidth, image.height());
|
return QRectF(0, 0, maxWidth, image->height());
|
||||||
}
|
}
|
||||||
|
|
||||||
void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void RBText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget)
|
QWidget *widget)
|
||||||
{
|
{
|
||||||
if(image.width() < maxWidth)
|
if(image->width() < maxWidth)
|
||||||
painter->drawImage(0, 0, image, 0, 0, image.width(), image.height());
|
painter->drawImage(0, 0, *image, 0, 0, image->width(), image->height());
|
||||||
else
|
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
|
class RBText : public QGraphicsItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RBText(const QImage& image, int maxWidth, QGraphicsItem* parent);
|
RBText(QImage* image, int maxWidth, QGraphicsItem* parent);
|
||||||
|
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget);
|
QWidget *widget);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QImage image;
|
QImage* image;
|
||||||
int maxWidth;
|
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 "editorwindow.h"
|
||||||
#include "projectmodel.h"
|
#include "projectmodel.h"
|
||||||
#include "ui_editorwindow.h"
|
#include "ui_editorwindow.h"
|
||||||
|
#include "rbfontcache.h"
|
||||||
|
#include "rbtextcache.h"
|
||||||
|
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QFileSystemModel>
|
#include <QFileSystemModel>
|
||||||
|
@ -49,6 +51,9 @@ EditorWindow::~EditorWindow()
|
||||||
delete project;
|
delete project;
|
||||||
delete deviceConfig;
|
delete deviceConfig;
|
||||||
delete deviceDock;
|
delete deviceDock;
|
||||||
|
|
||||||
|
RBFontCache::clearCache();
|
||||||
|
RBTextCache::clearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorWindow::loadTabFromSkinFile(QString fileName)
|
void EditorWindow::loadTabFromSkinFile(QString fileName)
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
const int SkinDocument::updateInterval = 500;
|
||||||
|
|
||||||
SkinDocument::SkinDocument(QLabel* statusLabel, ProjectModel* project,
|
SkinDocument::SkinDocument(QLabel* statusLabel, ProjectModel* project,
|
||||||
DeviceState* device, QWidget *parent)
|
DeviceState* device, QWidget *parent)
|
||||||
:TabContent(parent), statusLabel(statusLabel),
|
:TabContent(parent), statusLabel(statusLabel),
|
||||||
|
@ -70,6 +72,8 @@ SkinDocument::SkinDocument(QLabel* statusLabel, QString file,
|
||||||
/* Setting the title */
|
/* Setting the title */
|
||||||
QStringList decomposed = fileName.split('/');
|
QStringList decomposed = fileName.split('/');
|
||||||
titleText = decomposed.last();
|
titleText = decomposed.last();
|
||||||
|
|
||||||
|
lastUpdate = QTime::currentTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
SkinDocument::~SkinDocument()
|
SkinDocument::~SkinDocument()
|
||||||
|
@ -161,6 +165,11 @@ void SkinDocument::setupUI()
|
||||||
findReplace->hide();
|
findReplace->hide();
|
||||||
|
|
||||||
settingsChanged();
|
settingsChanged();
|
||||||
|
|
||||||
|
/* Setting up a timer to check for updates */
|
||||||
|
checkUpdate.setInterval(500);
|
||||||
|
QObject::connect(&checkUpdate, SIGNAL(timeout()),
|
||||||
|
this, SLOT(codeChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkinDocument::settingsChanged()
|
void SkinDocument::settingsChanged()
|
||||||
|
@ -273,8 +282,16 @@ void SkinDocument::codeChanged()
|
||||||
else
|
else
|
||||||
emit titleChanged(titleText);
|
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();
|
cursorChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
|
#include <QTime>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "findreplacedialog.h"
|
#include "findreplacedialog.h"
|
||||||
|
|
||||||
|
@ -113,6 +115,10 @@ private:
|
||||||
DeviceState* device;
|
DeviceState* device;
|
||||||
|
|
||||||
FindReplaceDialog* findReplace;
|
FindReplaceDialog* findReplace;
|
||||||
|
|
||||||
|
QTime lastUpdate;
|
||||||
|
static const int updateInterval;
|
||||||
|
QTimer checkUpdate;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SKINDOCUMENT_H
|
#endif // SKINDOCUMENT_H
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
# Enabling profiling
|
||||||
|
QMAKE_CXXFLAGS_DEBUG += -pg
|
||||||
|
QMAKE_LFLAGS_DEBUG += -pg
|
||||||
|
|
||||||
# build in a separate folder.
|
# build in a separate folder.
|
||||||
MYBUILDDIR = $$OUT_PWD/build/
|
MYBUILDDIR = $$OUT_PWD/build/
|
||||||
OBJECTS_DIR = $$MYBUILDDIR/o
|
OBJECTS_DIR = $$MYBUILDDIR/o
|
||||||
|
@ -47,7 +51,8 @@ HEADERS += models/parsetreemodel.h \
|
||||||
graphics/rbprogressbar.h \
|
graphics/rbprogressbar.h \
|
||||||
gui/findreplacedialog.h \
|
gui/findreplacedialog.h \
|
||||||
graphics/rbtext.h \
|
graphics/rbtext.h \
|
||||||
graphics/rbfontcache.h
|
graphics/rbfontcache.h \
|
||||||
|
graphics/rbtextcache.h
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
models/parsetreemodel.cpp \
|
models/parsetreemodel.cpp \
|
||||||
models/parsetreenode.cpp \
|
models/parsetreenode.cpp \
|
||||||
|
@ -69,7 +74,8 @@ SOURCES += main.cpp \
|
||||||
graphics/rbprogressbar.cpp \
|
graphics/rbprogressbar.cpp \
|
||||||
gui/findreplacedialog.cpp \
|
gui/findreplacedialog.cpp \
|
||||||
graphics/rbtext.cpp \
|
graphics/rbtext.cpp \
|
||||||
graphics/rbfontcache.cpp
|
graphics/rbfontcache.cpp \
|
||||||
|
graphics/rbtextcache.cpp
|
||||||
OTHER_FILES += README \
|
OTHER_FILES += README \
|
||||||
resources/windowicon.png \
|
resources/windowicon.png \
|
||||||
resources/appicon.xcf \
|
resources/appicon.xcf \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue