mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-07 03:30:44 +00:00
Replace pixmap caching code with Qt's build in stuff
This commit is contained in:
parent
79e889d0a6
commit
18082cbef5
@ -26,8 +26,6 @@ QFont *defaultfont = nullptr;
|
|||||||
QFont *mediumfont = nullptr;
|
QFont *mediumfont = nullptr;
|
||||||
QFont *bigfont = nullptr;
|
QFont *bigfont = nullptr;
|
||||||
QHash<QString, QImage *> images;
|
QHash<QString, QImage *> images;
|
||||||
bool fbo_unsupported = false;
|
|
||||||
QGLFramebufferObject *fbo = nullptr;
|
|
||||||
|
|
||||||
static bool globalsInitialized = false;
|
static bool globalsInitialized = false;
|
||||||
|
|
||||||
@ -110,17 +108,6 @@ void DestroyGraphGlobals()
|
|||||||
delete i.value();
|
delete i.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the frame buffer object.
|
|
||||||
if (fbo) {
|
|
||||||
if (fbo->isBound()) {
|
|
||||||
fbo->release();
|
|
||||||
}
|
|
||||||
|
|
||||||
delete fbo;
|
|
||||||
fbo = nullptr;
|
|
||||||
fbo_unsupported = true; // just in case shutdown order gets messed up
|
|
||||||
}
|
|
||||||
|
|
||||||
globalsInitialized = false;
|
globalsInitialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,8 +255,7 @@ void gGraph::qglColor(QColor col)
|
|||||||
m_graphview->qglColor(col);
|
m_graphview->qglColor(col);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gGraph::renderText(QString text, int x, int y, float angle, QColor color, QFont *font,
|
void gGraph::renderText(QString text, int x, int y, float angle, QColor color, QFont *font, bool antialias)
|
||||||
bool antialias)
|
|
||||||
{
|
{
|
||||||
m_graphview->AddTextQue(text, x, y, angle, color, font, antialias);
|
m_graphview->AddTextQue(text, x, y, angle, color, font, antialias);
|
||||||
}
|
}
|
||||||
@ -1081,9 +1067,9 @@ void gGraph::ZoomX(double mult, int origin_px)
|
|||||||
//updateSelectionTime(max-min);
|
//updateSelectionTime(max-min);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gGraph::DrawTextQue()
|
void gGraph::DrawTextQue(QPainter &painter)
|
||||||
{
|
{
|
||||||
m_graphview->DrawTextQue();
|
m_graphview->DrawTextQue(painter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// margin recalcs..
|
// margin recalcs..
|
||||||
|
@ -11,11 +11,11 @@
|
|||||||
#define graphs_ggraph_h
|
#define graphs_ggraph_h
|
||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QGLFramebufferObject>
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
#include "Graphs/layer.h"
|
#include "Graphs/layer.h"
|
||||||
|
|
||||||
@ -26,14 +26,10 @@ extern QFont *defaultfont;
|
|||||||
extern QFont *mediumfont;
|
extern QFont *mediumfont;
|
||||||
extern QFont *bigfont;
|
extern QFont *bigfont;
|
||||||
extern QHash<QString, QImage *> images;
|
extern QHash<QString, QImage *> images;
|
||||||
extern bool fbo_unsupported;
|
|
||||||
extern QGLFramebufferObject *fbo;
|
|
||||||
|
|
||||||
bool InitGraphGlobals();
|
bool InitGraphGlobals();
|
||||||
void DestroyGraphGlobals();
|
void DestroyGraphGlobals();
|
||||||
|
|
||||||
const int max_fbo_width = 2048;
|
|
||||||
const int max_fbo_height = 2048;
|
|
||||||
const int mouse_movement_threshold = 6;
|
const int mouse_movement_threshold = 6;
|
||||||
|
|
||||||
/*! \class gGraph
|
/*! \class gGraph
|
||||||
@ -41,7 +37,7 @@ const int mouse_movement_threshold = 6;
|
|||||||
*/
|
*/
|
||||||
class gGraph : public QObject
|
class gGraph : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT;
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
friend class gGraphView;
|
friend class gGraphView;
|
||||||
|
|
||||||
@ -226,7 +222,7 @@ class gGraph : public QObject
|
|||||||
void setGroup(short group) { m_group = group; }
|
void setGroup(short group) { m_group = group; }
|
||||||
|
|
||||||
//! \brief Forces the main gGraphView object to draw all Text Components
|
//! \brief Forces the main gGraphView object to draw all Text Components
|
||||||
void DrawTextQue();
|
void DrawTextQue(QPainter &painter);
|
||||||
|
|
||||||
//! \brief Sends supplied day object to all Graph layers so they can precalculate stuff
|
//! \brief Sends supplied day object to all Graph layers so they can precalculate stuff
|
||||||
void setDay(Day *day);
|
void setDay(Day *day);
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPixmapCache>
|
#include <QPixmapCache>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QFontMetrics>
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||||
# include <QWindow>
|
# include <QWindow>
|
||||||
@ -38,11 +39,6 @@
|
|||||||
#include "SleepLib/profiles.h"
|
#include "SleepLib/profiles.h"
|
||||||
|
|
||||||
extern MainWindow *mainwin;
|
extern MainWindow *mainwin;
|
||||||
|
|
||||||
// for profiling purposes, a count of lines drawn in a single frame
|
|
||||||
int lines_drawn_this_frame = 0;
|
|
||||||
int quads_drawn_this_frame = 0;
|
|
||||||
|
|
||||||
extern QLabel *qstatus2;
|
extern QLabel *qstatus2;
|
||||||
|
|
||||||
gToolTip::gToolTip(gGraphView *graphview)
|
gToolTip::gToolTip(gGraphView *graphview)
|
||||||
@ -136,9 +132,6 @@ void gToolTip::paint(QPainter &painter) //actually paints it.
|
|||||||
rect.setHeight(h);
|
rect.setHeight(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
lines_drawn_this_frame += 4;
|
|
||||||
quads_drawn_this_frame += 1;
|
|
||||||
|
|
||||||
QBrush brush(QColor(255, 255, 128, 230));
|
QBrush brush(QColor(255, 255, 128, 230));
|
||||||
brush.setStyle(Qt::SolidPattern);
|
brush.setStyle(Qt::SolidPattern);
|
||||||
painter.setBrush(brush);
|
painter.setBrush(brush);
|
||||||
@ -248,11 +241,9 @@ gGraphView::gGraphView(QWidget *parent, gGraphView *shared)
|
|||||||
{
|
{
|
||||||
m_shared = shared;
|
m_shared = shared;
|
||||||
m_sizer_index = m_graph_index = 0;
|
m_sizer_index = m_graph_index = 0;
|
||||||
m_textque_items = 0;
|
|
||||||
m_button_down = m_graph_dragging = m_sizer_dragging = false;
|
m_button_down = m_graph_dragging = m_sizer_dragging = false;
|
||||||
m_lastypos = m_lastxpos = 0;
|
m_lastypos = m_lastxpos = 0;
|
||||||
m_horiz_travel = 0;
|
m_horiz_travel = 0;
|
||||||
pixmap_cache_size = 0;
|
|
||||||
m_minx = m_maxx = 0;
|
m_minx = m_maxx = 0;
|
||||||
m_day = nullptr;
|
m_day = nullptr;
|
||||||
m_selected_graph = nullptr;
|
m_selected_graph = nullptr;
|
||||||
@ -278,13 +269,6 @@ gGraphView::gGraphView(QWidget *parent, gGraphView *shared)
|
|||||||
//gt->start();
|
//gt->start();
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
//vlines=new gVertexBuffer(20000,GL_LINES);
|
|
||||||
|
|
||||||
//stippled->setSize(1.5);
|
|
||||||
//stippled->forceAntiAlias(false);
|
|
||||||
//lines->setSize(1.5);
|
|
||||||
//backlines->setSize(1.5);
|
|
||||||
|
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
m_showsplitter = true;
|
m_showsplitter = true;
|
||||||
timer = new QTimer(this);
|
timer = new QTimer(this);
|
||||||
@ -307,6 +291,7 @@ gGraphView::gGraphView(QWidget *parent, gGraphView *shared)
|
|||||||
m_blockUpdates = false;
|
m_blockUpdates = false;
|
||||||
use_pixmap_cache = true;
|
use_pixmap_cache = true;
|
||||||
|
|
||||||
|
// pixmapcache.setCacheLimit(10240*2);
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||||
m_dpr = this->windowHandle()->devicePixelRatio();
|
m_dpr = this->windowHandle()->devicePixelRatio();
|
||||||
#else
|
#else
|
||||||
@ -337,14 +322,6 @@ gGraphView::~gGraphView()
|
|||||||
m_graphs[i]=NULL;
|
m_graphs[i]=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<QString, myPixmapCache *>::iterator it;
|
|
||||||
|
|
||||||
for (it = pixmap_cache.begin(); it != pixmap_cache.end(); it++) {
|
|
||||||
delete(*it);
|
|
||||||
}
|
|
||||||
|
|
||||||
pixmap_cache.clear();
|
|
||||||
|
|
||||||
delete m_tooltip;
|
delete m_tooltip;
|
||||||
m_graphs.clear();
|
m_graphs.clear();
|
||||||
|
|
||||||
@ -359,15 +336,20 @@ gGraphView::~gGraphView()
|
|||||||
bool gGraphView::usePixmapCache()
|
bool gGraphView::usePixmapCache()
|
||||||
{
|
{
|
||||||
//use_pixmap_cache is an overide setting
|
//use_pixmap_cache is an overide setting
|
||||||
return use_pixmap_cache & PROFILE.appearance->usePixmapCaching();
|
return PROFILE.appearance->usePixmapCaching();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CACHE_DRAWTEXT
|
||||||
|
#ifndef CACHE_DRAWTEXT
|
||||||
// Render all qued text via QPainter method
|
// Render all qued text via QPainter method
|
||||||
void gGraphView::DrawTextQue(QPainter &painter)
|
void gGraphView::DrawTextQue(QPainter &painter)
|
||||||
{
|
{
|
||||||
int w, h;
|
int w, h;
|
||||||
|
|
||||||
for (int i = 0; i < m_textque_items; i++) {
|
// not sure if global antialiasing would be better..
|
||||||
|
//painter.setRenderHint(QPainter::TextAntialiasing, PROFILE.appearance->antiAliasing());
|
||||||
|
int m_textque_items = m_textque.size();
|
||||||
|
for (int i = 0; i < m_textque_items; ++i) {
|
||||||
TextQue &q = m_textque[i];
|
TextQue &q = m_textque[i];
|
||||||
painter.setPen(q.color);
|
painter.setPen(q.color);
|
||||||
painter.setRenderHint(QPainter::TextAntialiasing, q.antialias);
|
painter.setRenderHint(QPainter::TextAntialiasing, q.antialias);
|
||||||
@ -387,188 +369,88 @@ void gGraphView::DrawTextQue(QPainter &painter)
|
|||||||
painter.rotate(+q.angle);
|
painter.rotate(+q.angle);
|
||||||
painter.translate(-q.x, -q.y);
|
painter.translate(-q.x, -q.y);
|
||||||
}
|
}
|
||||||
|
strings_drawn_this_frame++;
|
||||||
q.text.clear();
|
q.text.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_textque_items = 0;
|
m_textque.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
// Render graphs with QPainter or pixmap caching, depending on preferences
|
// Render graphs with QPainter or pixmap caching, depending on preferences
|
||||||
void gGraphView::DrawTextQue()
|
void gGraphView::DrawTextQue(QPainter &painter)
|
||||||
{
|
{
|
||||||
const qint64 expire_after_ms = 4000; // expire string pixmaps after this many milliseconds
|
|
||||||
//const qint64 under_limit_cache_bonus=30000; // If under the limit, give a bonus to the millisecond timeout.
|
|
||||||
const qint32 max_pixmap_cache = 4 *
|
|
||||||
1048576; // Maximum size of pixmap cache (it can grow over this, but only temporarily)
|
|
||||||
|
|
||||||
quint64 ti = 0, exptime = 0;
|
|
||||||
int w, h;
|
|
||||||
QHash<QString, myPixmapCache *>::iterator it;
|
|
||||||
QPainter painter;
|
|
||||||
|
|
||||||
// Purge the Pixmap cache of any old text strings
|
|
||||||
if (usePixmapCache()) {
|
|
||||||
// Current time in milliseconds since epoch.
|
|
||||||
ti = QDateTime::currentDateTime().toMSecsSinceEpoch();
|
|
||||||
|
|
||||||
if (pixmap_cache_size >
|
|
||||||
max_pixmap_cache) { // comment this if block out to only cleanup when past the maximum cache size
|
|
||||||
// Expire any strings not used
|
|
||||||
QList<QString> expire;
|
|
||||||
|
|
||||||
exptime = expire_after_ms;
|
|
||||||
|
|
||||||
// Uncomment the next line to allow better use of pixmap cache memory
|
|
||||||
//if (pixmap_cache_size < max_pixmap_cache) exptime+=under_limit_cache_bonus;
|
|
||||||
|
|
||||||
for (it = pixmap_cache.begin(); it != pixmap_cache.end(); it++) {
|
|
||||||
if ((*it)->last_used < (ti - exptime)) {
|
|
||||||
expire.push_back(it.key());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: Force expiry if over an upper memory threshold.. doesn't appear to be necessary.
|
|
||||||
|
|
||||||
for (int i = 0; i < expire.count(); i++) {
|
|
||||||
const QString key = expire.at(i);
|
|
||||||
// unbind the texture
|
|
||||||
myPixmapCache *pc = pixmap_cache[key];
|
|
||||||
deleteTexture(pc->textureID);
|
|
||||||
QImage &pm = pc->image;
|
|
||||||
pixmap_cache_size -= pm.width() * pm.height() * (pm.depth() / 8);
|
|
||||||
// free the pixmap
|
|
||||||
//delete pc->pixmap;
|
|
||||||
|
|
||||||
// free the myPixmapCache object
|
|
||||||
delete pc;
|
|
||||||
|
|
||||||
// pull the dead record from the cache.
|
|
||||||
pixmap_cache.remove(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//glPushAttrib(GL_COLOR_BUFFER_BIT);
|
|
||||||
painter.begin(this);
|
|
||||||
|
|
||||||
int buf = 4;
|
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
|
||||||
float dpr = devicePixelRatio();
|
|
||||||
buf *= dpr;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// process the text drawing queue
|
// process the text drawing queue
|
||||||
for (int i = 0; i < m_textque_items; i++) {
|
int m_textque_items = m_textque.size();
|
||||||
|
|
||||||
|
int h,w;
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < m_textque_items; ++i) {
|
||||||
TextQue &q = m_textque[i];
|
TextQue &q = m_textque[i];
|
||||||
|
|
||||||
// can do antialiased text via texture cache fine on mac
|
// can do antialiased text via texture cache fine on mac
|
||||||
if (usePixmapCache()) {
|
if (usePixmapCache()) {
|
||||||
// Generate the pixmap cache "key"
|
// Generate the pixmap cache "key"
|
||||||
QString hstr = QString("%4:%5:%6%7").arg(q.text).arg(q.color.name()).arg(q.font->key()).arg(
|
QString hstr = QString("%1:%2:%3").
|
||||||
q.antialias);
|
arg(q.text).
|
||||||
|
arg(q.color.name()).
|
||||||
|
arg(q.font->pointSize());
|
||||||
|
|
||||||
QImage pm;
|
QPixmap pm;
|
||||||
|
const int buf = 8;
|
||||||
it = pixmap_cache.find(hstr);
|
if (!QPixmapCache::find(hstr, &pm)) {
|
||||||
myPixmapCache *pc = nullptr;
|
|
||||||
|
|
||||||
if (it != pixmap_cache.end()) {
|
|
||||||
pc = (*it);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// not found.. create the image and store it in a cache
|
|
||||||
|
|
||||||
//This is much slower than other text rendering methods, but caching more than makes up for the speed decrease.
|
|
||||||
pc = new myPixmapCache;
|
|
||||||
pc->last_used = ti; // set the last_used value.
|
|
||||||
|
|
||||||
QFontMetrics fm(*q.font);
|
QFontMetrics fm(*q.font);
|
||||||
QRect rect = fm.boundingRect(q.text);
|
QRect rect=fm.tightBoundingRect(q.text);
|
||||||
w = fm.width(q.text);
|
w = fm.width(q.text);
|
||||||
h = fm.height();
|
h = fm.height()+buf;
|
||||||
|
|
||||||
//#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
|
||||||
// w *= dpr;
|
|
||||||
// h *= dpr;
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
rect.setWidth(w);
|
|
||||||
rect.setHeight(h);
|
|
||||||
|
|
||||||
pm = QImage(w + buf, h + buf, QImage::Format_ARGB32_Premultiplied);
|
|
||||||
|
|
||||||
|
pm=QPixmap(w, h);
|
||||||
pm.fill(Qt::transparent);
|
pm.fill(Qt::transparent);
|
||||||
|
|
||||||
QPainter imgpainter(&pm);
|
QPainter imgpainter(&pm);
|
||||||
|
|
||||||
QBrush b(q.color);
|
imgpainter.setPen(q.color);
|
||||||
imgpainter.setBrush(b);
|
|
||||||
|
|
||||||
QFont font = *q.font;
|
imgpainter.setFont(*q.font);
|
||||||
//#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
|
||||||
// int fs = font.pointSize();
|
|
||||||
|
|
||||||
// if (fs > 0) {
|
|
||||||
// font.setPointSize(fs * dpr);
|
|
||||||
// } else {
|
|
||||||
// font.setPixelSize(font.pixelSize()*dpr);
|
|
||||||
// }
|
|
||||||
|
|
||||||
//#endif
|
|
||||||
imgpainter.setFont(font);
|
|
||||||
|
|
||||||
imgpainter.setRenderHint(QPainter::TextAntialiasing, q.antialias);
|
imgpainter.setRenderHint(QPainter::TextAntialiasing, q.antialias);
|
||||||
imgpainter.drawText(buf / 2, h, q.text);
|
imgpainter.drawText(0, h-buf, q.text);
|
||||||
imgpainter.end();
|
imgpainter.end();
|
||||||
|
|
||||||
pc->image = pm;
|
QPixmapCache::insert(hstr, pm);
|
||||||
pixmap_cache_size += pm.width() * pm.height() * (pm.depth() / 8);
|
strings_drawn_this_frame++;
|
||||||
pixmap_cache[hstr] = pc;
|
} else {
|
||||||
|
//cached
|
||||||
|
strings_cached_this_frame++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pc) {
|
h = pm.height();
|
||||||
pc->last_used = ti;
|
w = pm.width();
|
||||||
int h = pc->image.height();
|
if (q.angle != 0) {
|
||||||
int w = pc->image.width();
|
float xxx = q.x - h - (h / 2);
|
||||||
|
float yyy = q.y + w / 2; // + buf / 2;
|
||||||
|
|
||||||
//#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
xxx+=4;
|
||||||
// h /= dpr;
|
yyy+=4;
|
||||||
// w /= dpr;
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
if (q.angle != 0) {
|
painter.translate(xxx, yyy);
|
||||||
float xxx = q.x - h - (h / 2);
|
painter.rotate(-q.angle);
|
||||||
float yyy = q.y + w / 2 + buf / 2;
|
painter.drawPixmap(QRect(0, h / 2, w, h), pm);
|
||||||
|
painter.rotate(+q.angle);
|
||||||
painter.translate(xxx, yyy);
|
painter.translate(-xxx, -yyy);
|
||||||
painter.rotate(-q.angle);
|
} else {
|
||||||
painter.drawImage(QRect(0, h / 2, w, h), pc->image, pc->image.rect());
|
painter.drawPixmap(QRect(q.x - buf / 2, q.y - h + buf, w, h), pm);
|
||||||
painter.rotate(+q.angle);
|
|
||||||
painter.translate(-xxx, -yyy);
|
|
||||||
} else {
|
|
||||||
painter.drawImage(QRect(q.x - buf / 2, q.y - h + buf / 2, w, h), pc->image, pc->image.rect());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Just draw the fonts..
|
// Just draw the fonts..
|
||||||
QBrush b(q.color);
|
painter.setPen(QColor("red")); //q.color);
|
||||||
painter.setBrush(b);
|
|
||||||
painter.setFont(*q.font);
|
painter.setFont(*q.font);
|
||||||
|
|
||||||
if (q.angle == 0) {
|
if (q.angle == 0) {
|
||||||
// *********************************************************
|
|
||||||
// Holy crap this is slow
|
|
||||||
// The following line is responsible for 77% of drawing time
|
|
||||||
// *********************************************************
|
|
||||||
|
|
||||||
painter.drawText(q.x, q.y, q.text);
|
painter.drawText(q.x, q.y, q.text);
|
||||||
} else {
|
} else {
|
||||||
QBrush b(q.color);
|
|
||||||
painter.setBrush(b);
|
|
||||||
painter.setFont(*q.font);
|
painter.setFont(*q.font);
|
||||||
|
|
||||||
w = painter.fontMetrics().width(q.text);
|
w = painter.fontMetrics().width(q.text);
|
||||||
@ -580,42 +462,35 @@ void gGraphView::DrawTextQue()
|
|||||||
painter.rotate(+q.angle);
|
painter.rotate(+q.angle);
|
||||||
painter.translate(-q.x, -q.y);
|
painter.translate(-q.x, -q.y);
|
||||||
}
|
}
|
||||||
|
strings_drawn_this_frame++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
q.text.clear();
|
//q.text.clear();
|
||||||
//q.text.squeeze();
|
//q.text.squeeze();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!usePixmapCache()) {
|
m_textque.clear();
|
||||||
painter.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
//qDebug() << "rendered" << m_textque_items << "text items";
|
|
||||||
m_textque_items = 0;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void gGraphView::AddTextQue(QString &text, short x, short y, float angle, QColor color,
|
void gGraphView::AddTextQue(const QString &text, short x, short y, float angle, QColor color,
|
||||||
QFont *font, bool antialias)
|
QFont *font, bool antialias)
|
||||||
{
|
{
|
||||||
#ifdef ENABLED_THREADED_DRAWING
|
#ifdef ENABLED_THREADED_DRAWING
|
||||||
text_mutex.lock();
|
text_mutex.lock();
|
||||||
#endif
|
#endif
|
||||||
|
m_textque.append(TextQue(x,y,angle,text,color,font,antialias));
|
||||||
if (m_textque_items >= textque_max) {
|
|
||||||
DrawTextQue();
|
|
||||||
}
|
|
||||||
|
|
||||||
TextQue &q = m_textque[m_textque_items++];
|
|
||||||
#ifdef ENABLED_THREADED_DRAWING
|
#ifdef ENABLED_THREADED_DRAWING
|
||||||
text_mutex.unlock();
|
text_mutex.unlock();
|
||||||
#endif
|
#endif
|
||||||
q.text = text;
|
// q.text = text;
|
||||||
q.x = x;
|
// q.x = x;
|
||||||
q.y = y;
|
// q.y = y;
|
||||||
q.angle = angle;
|
// q.angle = angle;
|
||||||
q.color = color;
|
// q.color = color;
|
||||||
q.font = font;
|
// q.font = font;
|
||||||
q.antialias = antialias;
|
// q.antialias = antialias;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gGraphView::addGraph(gGraph *g, short group)
|
void gGraphView::addGraph(gGraph *g, short group)
|
||||||
@ -1205,8 +1080,6 @@ bool gGraphView::renderGraphs(QPainter &painter)
|
|||||||
g->paint(painter, g->m_rect.x(), g->m_rect.y(), g->m_rect.width(), g->m_rect.height());
|
g->paint(painter, g->m_rect.x(), g->m_rect.y(), g->m_rect.width(), g->m_rect.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
// can't draw snapshot text using this DrawTextQue function
|
|
||||||
// TODO: Find a better solution for detecting when in snapshot mode
|
|
||||||
if (m_graphs.size() > 1) {
|
if (m_graphs.size() > 1) {
|
||||||
DrawTextQue(painter);
|
DrawTextQue(painter);
|
||||||
|
|
||||||
@ -1319,6 +1192,11 @@ void gGraphView::paintGL()
|
|||||||
|
|
||||||
bool graphs_drawn = true;
|
bool graphs_drawn = true;
|
||||||
|
|
||||||
|
lines_drawn_this_frame = 0;
|
||||||
|
quads_drawn_this_frame = 0;
|
||||||
|
strings_drawn_this_frame = 0;
|
||||||
|
strings_cached_this_frame = 0;
|
||||||
|
|
||||||
graphs_drawn = renderGraphs(painter);
|
graphs_drawn = renderGraphs(painter);
|
||||||
|
|
||||||
if (!graphs_drawn) { // No graphs drawn?
|
if (!graphs_drawn) { // No graphs drawn?
|
||||||
@ -1361,12 +1239,11 @@ void gGraphView::paintGL()
|
|||||||
}
|
}
|
||||||
|
|
||||||
double fps = v / double(rs);
|
double fps = v / double(rs);
|
||||||
ss = "Debug Mode " + QString::number(fps, 'f', 1) +
|
ss = "Debug Mode " + QString::number(fps, 'f', 1) + "fps "
|
||||||
"fps " + QString::number(lines_drawn_this_frame, 'f', 0) +
|
+ QString::number(lines_drawn_this_frame, 'f', 0) + " lines "
|
||||||
" lines " + QString::number(quads_drawn_this_frame, 'f', 0) +
|
// + QString::number(quads_drawn_this_frame, 'f', 0) + " quads "
|
||||||
" quads " + QString::number(pixmap_cache.count(), 'f', 0) +
|
+ QString::number(strings_drawn_this_frame, 'f', 0) + " strings "
|
||||||
" strings " + QString::number(pixmap_cache_size / 1024.0, 'f', 1) +
|
+ QString::number(strings_cached_this_frame, 'f', 0) + " cached ";
|
||||||
"Kb";
|
|
||||||
|
|
||||||
int w, h;
|
int w, h;
|
||||||
// this uses tightBoundingRect, which is different on Mac than it is on Windows & Linux.
|
// this uses tightBoundingRect, which is different on Mac than it is on Windows & Linux.
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <QWaitCondition>
|
#include <QWaitCondition>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
|
#include <QPixmapCache>
|
||||||
|
|
||||||
#include <Graphs/gGraph.h>
|
#include <Graphs/gGraph.h>
|
||||||
#include <Graphs/glcommon.h>
|
#include <Graphs/glcommon.h>
|
||||||
@ -36,6 +37,22 @@ const int textque_max = 512;
|
|||||||
\brief Holds a single item of text for the drawing queue
|
\brief Holds a single item of text for the drawing queue
|
||||||
*/
|
*/
|
||||||
struct TextQue {
|
struct TextQue {
|
||||||
|
TextQue() {
|
||||||
|
}
|
||||||
|
TextQue(short x, short y, float angle, QString text, QColor color, QFont * font, bool antialias):
|
||||||
|
x(x), y(y), angle(angle), text(text), color(color), font(font), antialias(antialias)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
TextQue(const TextQue & copy) {
|
||||||
|
x=copy.x;
|
||||||
|
y=copy.y;
|
||||||
|
text=copy.text;
|
||||||
|
angle=copy.angle;
|
||||||
|
color=copy.color;
|
||||||
|
font=copy.font;
|
||||||
|
antialias=copy.antialias;
|
||||||
|
}
|
||||||
|
|
||||||
//! \variable contains the x axis screen position to draw the text
|
//! \variable contains the x axis screen position to draw the text
|
||||||
short x;
|
short x;
|
||||||
//! \variable contains the y axis screen position to draw the text
|
//! \variable contains the y axis screen position to draw the text
|
||||||
@ -133,16 +150,6 @@ class gToolTip : public QObject
|
|||||||
void timerDone();
|
void timerDone();
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! \struct myPixmapCache
|
|
||||||
\brief My version of Pixmap cache with texture binding support
|
|
||||||
|
|
||||||
*/
|
|
||||||
struct myPixmapCache {
|
|
||||||
quint64 last_used;
|
|
||||||
QImage image;
|
|
||||||
GLuint textureID;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*! \class gGraphView
|
/*! \class gGraphView
|
||||||
\brief Main OpenGL Graph Area, derived from QGLWidget
|
\brief Main OpenGL Graph Area, derived from QGLWidget
|
||||||
|
|
||||||
@ -237,11 +244,11 @@ class gGraphView : public QGLWidget
|
|||||||
void selectionTime();
|
void selectionTime();
|
||||||
|
|
||||||
//! \brief Add the Text information to the Text Drawing Queue (called by gGraphs renderText method)
|
//! \brief Add the Text information to the Text Drawing Queue (called by gGraphs renderText method)
|
||||||
void AddTextQue(QString &text, short x, short y, float angle = 0.0,
|
void AddTextQue(const QString &text, short x, short y, float angle = 0.0,
|
||||||
QColor color = Qt::black, QFont *font = defaultfont, bool antialias = true);
|
QColor color = Qt::black, QFont *font = defaultfont, bool antialias = true);
|
||||||
|
|
||||||
//! \brief Draw all Text in the text drawing queue
|
// //! \brief Draw all Text in the text drawing queue
|
||||||
void DrawTextQue();
|
// void DrawTextQue();
|
||||||
|
|
||||||
//! \brief Draw all text components using QPainter object painter
|
//! \brief Draw all text components using QPainter object painter
|
||||||
void DrawTextQue(QPainter &painter);
|
void DrawTextQue(QPainter &painter);
|
||||||
@ -319,6 +326,12 @@ class gGraphView : public QGLWidget
|
|||||||
//! \brief Graph drawing routines, returns true if there weren't any graphs to draw
|
//! \brief Graph drawing routines, returns true if there weren't any graphs to draw
|
||||||
bool renderGraphs(QPainter &painter);
|
bool renderGraphs(QPainter &painter);
|
||||||
|
|
||||||
|
// for profiling purposes, a count of lines drawn in a single frame
|
||||||
|
int lines_drawn_this_frame;
|
||||||
|
int quads_drawn_this_frame;
|
||||||
|
int strings_drawn_this_frame;
|
||||||
|
int strings_cached_this_frame;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! \brief Set up the OpenGL basics for the QGLWidget underneath
|
//! \brief Set up the OpenGL basics for the QGLWidget underneath
|
||||||
virtual void initializeGL();
|
virtual void initializeGL();
|
||||||
@ -401,9 +414,8 @@ class gGraphView : public QGLWidget
|
|||||||
int m_graph_index;
|
int m_graph_index;
|
||||||
|
|
||||||
//! \brief List of all queue text to draw.. not sure why I didn't use a vector here.. Might of been a leak issue
|
//! \brief List of all queue text to draw.. not sure why I didn't use a vector here.. Might of been a leak issue
|
||||||
TextQue m_textque[textque_max];
|
QVector<TextQue> m_textque;
|
||||||
|
|
||||||
int m_textque_items;
|
|
||||||
int m_lastxpos, m_lastypos;
|
int m_lastxpos, m_lastypos;
|
||||||
|
|
||||||
QString m_emptytext;
|
QString m_emptytext;
|
||||||
@ -425,11 +437,10 @@ class gGraphView : public QGLWidget
|
|||||||
|
|
||||||
QTime m_animationStarted;
|
QTime m_animationStarted;
|
||||||
|
|
||||||
// turn this into a struct later..
|
|
||||||
QHash<QString, myPixmapCache *> pixmap_cache;
|
|
||||||
qint32 pixmap_cache_size;
|
|
||||||
bool use_pixmap_cache;
|
bool use_pixmap_cache;
|
||||||
|
|
||||||
|
QPixmapCache pixmapcache;
|
||||||
|
|
||||||
QTime horizScrollTime, vertScrollTime;
|
QTime horizScrollTime, vertScrollTime;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -28,6 +28,7 @@ gLineChart::gLineChart(ChannelID code, QColor col, bool square_plot, bool disabl
|
|||||||
addPlot(code, col, square_plot);
|
addPlot(code, col, square_plot);
|
||||||
m_line_color = col;
|
m_line_color = col;
|
||||||
m_report_empty = false;
|
m_report_empty = false;
|
||||||
|
lines.reserve(50000);
|
||||||
}
|
}
|
||||||
gLineChart::~gLineChart()
|
gLineChart::~gLineChart()
|
||||||
{
|
{
|
||||||
@ -127,12 +128,7 @@ void gLineChart::SetDay(Day *d)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (m_code==CPAP_Leak) {
|
|
||||||
// subtract_offset=profile.cpap.[IntentionalLeak].toDouble();
|
|
||||||
//} else
|
|
||||||
subtract_offset = 0;
|
subtract_offset = 0;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
EventDataType gLineChart::Miny()
|
EventDataType gLineChart::Miny()
|
||||||
{
|
{
|
||||||
@ -247,8 +243,6 @@ void gLineChart::paint(QPainter &painter, gGraph &w, int left, int top, int widt
|
|||||||
|
|
||||||
painter.setClipRect(left, top, width, height+1);
|
painter.setClipRect(left, top, width, height+1);
|
||||||
painter.setClipping(true);
|
painter.setClipping(true);
|
||||||
QVector<QLine> lines;
|
|
||||||
lines.reserve(100000);
|
|
||||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
|
||||||
for (int gi = 0; gi < m_codes.size(); gi++) {
|
for (int gi = 0; gi < m_codes.size(); gi++) {
|
||||||
@ -666,8 +660,10 @@ void gLineChart::paint(QPainter &painter, gGraph &w, int left, int top, int widt
|
|||||||
if (done) { break; }
|
if (done) { break; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
painter.setPen(QPen(m_colors[gi],1.5));
|
painter.setPen(QPen(m_colors[gi],1));
|
||||||
painter.drawLines(lines);
|
painter.drawLines(lines);
|
||||||
|
w.graphView()->lines_drawn_this_frame+=lines.count();
|
||||||
|
lines.clear();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Draw Legends on the top line
|
// Draw Legends on the top line
|
||||||
|
@ -133,6 +133,8 @@ class gLineChart: public Layer
|
|||||||
QVector<QColor> m_colors;
|
QVector<QColor> m_colors;
|
||||||
QVector<bool> m_square;
|
QVector<bool> m_square;
|
||||||
QHash<ChannelID, bool> m_enabled;
|
QHash<ChannelID, bool> m_enabled;
|
||||||
|
|
||||||
|
QVector<QLine> lines;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GLINECHART_H
|
#endif // GLINECHART_H
|
||||||
|
@ -303,6 +303,7 @@ void gXAxis::paint(QPainter &painter, gGraph &w, int left, int top, int width, i
|
|||||||
} else {
|
} else {
|
||||||
painter.drawLines(ticks);
|
painter.drawLines(ticks);
|
||||||
}
|
}
|
||||||
|
w.graphView()->lines_drawn_this_frame += ticks.size();
|
||||||
|
|
||||||
w.invalidate_xAxisImage = false;
|
w.invalidate_xAxisImage = false;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#define GXAXIS_H
|
#define GXAXIS_H
|
||||||
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
#include <QPixmap>
|
||||||
#include "Graphs/layer.h"
|
#include "Graphs/layer.h"
|
||||||
|
|
||||||
/*! \class gXAxis
|
/*! \class gXAxis
|
||||||
|
@ -138,6 +138,7 @@ void gXGrid::paint(QPainter &painter, gGraph &w, int left, int top, int width, i
|
|||||||
painter.drawLines(majorlines);
|
painter.drawLines(majorlines);
|
||||||
painter.setPen(QPen(m_minor_color,1));
|
painter.setPen(QPen(m_minor_color,1));
|
||||||
painter.drawLines(minorlines);
|
painter.drawLines(minorlines);
|
||||||
|
w.graphView()->lines_drawn_this_frame += majorlines.size() + minorlines.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -395,6 +396,8 @@ void gYAxis::paint(QPainter &painter, gGraph &w, int left, int top, int width, i
|
|||||||
}
|
}
|
||||||
painter.setPen(m_line_color);
|
painter.setPen(m_line_color);
|
||||||
painter.drawLines(ticks);
|
painter.drawLines(ticks);
|
||||||
|
w.graphView()->lines_drawn_this_frame += ticks.size();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const QString gYAxis::Format(EventDataType v, int dp)
|
const QString gYAxis::Format(EventDataType v, int dp)
|
||||||
|
@ -266,9 +266,9 @@ void MainWindow::closeEvent(QCloseEvent * event)
|
|||||||
extern MainWindow *mainwin;
|
extern MainWindow *mainwin;
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
if (systraymenu) { delete systraymenu; }
|
// if (systraymenu) { delete systraymenu; }
|
||||||
|
|
||||||
if (systray) { delete systray; }
|
// if (systray) { delete systray; }
|
||||||
|
|
||||||
// Trash anything allocated by the Graph objects
|
// Trash anything allocated by the Graph objects
|
||||||
DestroyGraphGlobals();
|
DestroyGraphGlobals();
|
||||||
|
Loading…
Reference in New Issue
Block a user