Multithread fixes

This commit is contained in:
Mark Watkins 2011-08-31 22:24:45 +10:00
parent 04de897780
commit 7e14cb978e
9 changed files with 45 additions and 87 deletions

View File

@ -16,9 +16,9 @@ gFlagsGroup::gFlagsGroup()
static QColor col2=QColor(0xff,0xff,0xff,0xff); static QColor col2=QColor(0xff,0xff,0xff,0xff);
static QColor col=Qt::black; static QColor col=Qt::black;
addGLBuf(quad1=new GLBuffer(col1,2048,GL_QUADS)); addGLBuf(quad1=new GLBuffer(col1,512,GL_QUADS));
addGLBuf(quad2=new GLBuffer(col2,2048,GL_QUADS)); addGLBuf(quad2=new GLBuffer(col2,512,GL_QUADS));
addGLBuf(lines=new GLBuffer(col,2048,GL_LINES)); addGLBuf(lines=new GLBuffer(col,20,GL_LINE_LOOP));
quad1->setAntiAlias(true); quad1->setAntiAlias(true);
quad2->setAntiAlias(true); quad2->setAntiAlias(true);
lines->setAntiAlias(false); lines->setAntiAlias(false);
@ -70,35 +70,13 @@ void gFlagsGroup::paint(gGraph &w, int left, int top, int width, int height)
quad2->add(left+width-1,linetop+barh,left+width-1,linetop); quad2->add(left+width-1,linetop+barh,left+width-1,linetop);
} }
// barcol=&col1;
//int qo=0;
//if (evil_intel_graphics_card) qo=1;
// Draw the bars with filled quads
/*glBegin(GL_QUADS);
w.qglColor(*barcol);
glVertex2f(left, linetop);
glVertex2f(left, linetop+barh);
glVertex2f(left+width-1, linetop+barh);
glVertex2f(left+width-1, linetop);
glEnd(); */
// Paint the actual flags // Paint the actual flags
lvisible[i]->paint(w,left,linetop,width,barh); lvisible[i]->paint(w,left,linetop,width,barh);
linetop+=barh; linetop+=barh;
} }
// Draw the outer rectangle outline lines->add(left-1, top, left-1, top+height);
glBegin(GL_LINE_LOOP); lines->add(left+width, top+height, left+width, top);
glLineWidth(1);
w.qglColor(Qt::black);
glVertex2f(left-1, top);
glVertex2f(left-1, top+height);
glVertex2f(left+width, top+height);
glVertex2f(left+width, top);
glEnd ();
} }
gFlagsLine::gFlagsLine(ChannelID code,QColor flag_color,QString label,bool always_visible,FlagType flt) gFlagsLine::gFlagsLine(ChannelID code,QColor flag_color,QString label,bool always_visible,FlagType flt)
@ -172,37 +150,4 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
if (verts_exceeded) { if (verts_exceeded) {
qWarning() << "maxverts exceeded in gFlagsLine::plot()"; qWarning() << "maxverts exceeded in gFlagsLine::plot()";
} }
// glScissor(left,top,width,height);
//glEnable(GL_SCISSOR_TEST);
//quads->draw();
//lines->draw();
/*glEnableClientState(GL_VERTEX_ARRAY);
bool antialias=pref["UseAntiAliasing"].toBool();
if (antialias) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glLineWidth (1.5);
} else glLineWidth (1);
w.qglColor(m_flag_color);
if (quadcnt>0) {
glVertexPointer(2, GL_SHORT, 0, quadarray);
glDrawArrays(GL_QUADS, 0, quadcnt>>1);
}
if (vertcnt>0) {
glVertexPointer(2, GL_SHORT, 0, vertarray);
glDrawArrays(GL_LINES, 0, vertcnt>>1);
}
if (antialias) {
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
}
glDisableClientState(GL_VERTEX_ARRAY);
*/
//glDisable(GL_SCISSOR_TEST);
} }

View File

@ -39,10 +39,13 @@ void DoneGraphs()
void GetTextExtent(QString text, int & width, int & height, QFont *font) void GetTextExtent(QString text, int & width, int & height, QFont *font)
{ {
static QMutex mut;
mut.lock();
QFontMetrics fm(*font); QFontMetrics fm(*font);
//QRect r=fm.tightBoundingRect(text); //QRect r=fm.tightBoundingRect(text);
width=fm.width(text); //fm.width(text); width=fm.width(text); //fm.width(text);
height=fm.xHeight()+2; //fm.ascent(); height=fm.xHeight()+2; //fm.ascent();
mut.unlock();
} }
GLBuffer::GLBuffer(QColor color,int max,int type) GLBuffer::GLBuffer(QColor color,int max,int type)
@ -291,19 +294,24 @@ const double zoom_hard_limit=500.0;
gThread::gThread(gGraph *g) gThread::gThread(gGraph *g)
{ {
graph=g; graph=g;
mutex.lock();
} }
void gThread::run() void gThread::run()
{ {
int originX=m_lastbounds.x(); while (this->isRunning()) {
int originY=m_lastbounds.y(); mutex.lock();
int width=m_lastbounds.width(); int originX=m_lastbounds.x();
int height=m_lastbounds.height(); int originY=m_lastbounds.y();
graph->paint(originX,originY,width,height); int width=m_lastbounds.width();
graph->threadDone(); int height=m_lastbounds.height();
graph->paint(originX,originY,width,height);
graph->threadDone();
}
} }
void gThread::paint(int originX, int originY, int width, int height) void gThread::paint(int originX, int originY, int width, int height)
{ {
m_lastbounds=QRect(originX,originY,width,height); m_lastbounds=QRect(originX,originY,width,height);
mutex.unlock(); // this is the signal to start
} }
gGraph::gGraph(gGraphView *graphview,QString title,int height,short group) : gGraph::gGraph(gGraphView *graphview,QString title,int height,short group) :
@ -326,12 +334,17 @@ gGraph::gGraph(gGraphView *graphview,QString title,int height,short group) :
m_marginright=10; m_marginright=10;
m_selecting_area=m_blockzoom=false; m_selecting_area=m_blockzoom=false;
m_lastx23=0; m_lastx23=0;
m_thread=new gThread(this); m_thread=new gThread(this);
if (m_graphview->useThreads()) m_thread->start();
quad=new GLBuffer(QColor(128,128,255,128),8,GL_QUADS); quad=new GLBuffer(QColor(128,128,255,128),8,GL_QUADS);
quad->forceAntiAlias(true); quad->forceAntiAlias(true);
} }
gGraph::~gGraph() gGraph::~gGraph()
{ {
if (m_graphview->useThreads()) {
m_thread->exit();
}
delete m_thread; delete m_thread;
delete quad; delete quad;
} }
@ -433,7 +446,8 @@ void gGraph::paint(int originX, int originY, int width, int height)
glEnd(); glEnd();
glDisable(GL_BLEND); glDisable(GL_BLEND);
*/ */
glColor4f(0,0,0,1);
//glColor4f(0,0,0,1);
renderText(title(),20,originY+height/2,90,Qt::black,mediumfont); renderText(title(),20,originY+height/2,90,Qt::black,mediumfont);
left=0,right=0,top=0,bottom=0; left=0,right=0,top=0,bottom=0;
@ -494,7 +508,7 @@ void gGraph::paint(int originX, int originY, int width, int height)
/*m_graphview->gl_mutex.lock(); /*m_graphview->gl_mutex.lock();
drawGLBuf(); drawGLBuf();
m_graphview->gl_mutex.unlock();*/ m_graphview->gl_mutex.unlock(); */
} }
@ -1201,7 +1215,7 @@ void gGraphView::paintGL()
threaded=true; threaded=true;
} else threaded=false; } else threaded=false;
//threaded=true; threaded=true;
for (int i=0;i<m_graphs.size();i++) { for (int i=0;i<m_graphs.size();i++) {
if (m_graphs[i]->isEmpty() || !m_graphs[i]->visible()) continue; if (m_graphs[i]->isEmpty() || !m_graphs[i]->visible()) continue;
numgraphs++; numgraphs++;
@ -1218,8 +1232,8 @@ void gGraphView::paintGL()
if (threaded) { if (threaded) {
masterlock->acquire(1); masterlock->acquire(1);
m_graphs[i]->thread()->paint(px,py,width()-titleWidth,h); m_graphs[i]->thread()->paint(px,py,width()-titleWidth,h);
m_graphs[i]->thread()->start(QThread::HighestPriority); //m_graphs[i]->thread()->start(QThread::HighestPriority);
m_graphs[i]->thread()->wait(); //m_graphs[i]->thread()->wait();
} else { } else {
m_graphs[i]->paint(px,py,width()-titleWidth,h); m_graphs[i]->paint(px,py,width()-titleWidth,h);
} }

View File

@ -163,9 +163,11 @@ public:
gThread(gGraph *g); gThread(gGraph *g);
void run(); void run();
void paint(int originX, int originY, int width, int height); void paint(int originX, int originY, int width, int height);
QMutex mutex;
protected: protected:
gGraph * graph; gGraph * graph;
QRect m_lastbounds; QRect m_lastbounds;
}; };
class gGraph class gGraph
@ -310,6 +312,7 @@ public:
void setDay(Day * day); void setDay(Day * day);
void threadDone(); void threadDone();
QSemaphore * masterlock; QSemaphore * masterlock;
bool useThreads() { return m_idealthreads>1; }
protected: protected:
int m_idealthreads; int m_idealthreads;
Day * m_day; Day * m_day;

View File

@ -16,8 +16,11 @@ gLineChart::gLineChart(ChannelID code,QColor col,bool square_plot, bool disable_
{ {
m_line_color=col; m_line_color=col;
m_report_empty=false; m_report_empty=false;
addGLBuf(lines=new GLBuffer(col,40000,GL_LINES)); addGLBuf(lines=new GLBuffer(col,100000,GL_LINES));
addGLBuf(outlines=new GLBuffer(QColor(0,0,0,255),20,GL_LINE_LOOP));
lines->setAntiAlias(true); lines->setAntiAlias(true);
outlines->setAntiAlias(false);
} }
gLineChart::~gLineChart() gLineChart::~gLineChart()
@ -114,16 +117,8 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
int minz,maxz; int minz,maxz;
// Draw bounding box // Draw bounding box
{ outlines->add(left, top, left, top+height);
w.qglColor(Qt::black); outlines->add(left+width,top+height, left+width, top);
glLineWidth (1);
glBegin (GL_LINE_LOOP);
glVertex2i (left, top);
glVertex2i (left, top+height);
glVertex2i (left+width,top+height);
glVertex2i (left+width, top);
glEnd ();
}
width--; width--;
height-=2; height-=2;

View File

@ -33,6 +33,7 @@ protected:
bool m_disable_accel; bool m_disable_accel;
QColor m_line_color; QColor m_line_color;
GLBuffer * lines; GLBuffer * lines;
GLBuffer * outlines;
}; };
#endif // GLINECHART_H #endif // GLINECHART_H

View File

@ -135,7 +135,7 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
qWarning() << "exceeded maxverts in gLineOverlay::Plot()"; qWarning() << "exceeded maxverts in gLineOverlay::Plot()";
} }
bool antialias=pref["UseAntiAliasing"].toBool(); /* bool antialias=pref["UseAntiAliasing"].toBool();
if (antialias) { if (antialias) {
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //_MINUS_SRC_ALPHA);
@ -151,7 +151,7 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
if (antialias) { if (antialias) {
glDisable(GL_LINE_SMOOTH); glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND); glDisable(GL_BLEND);
} } */
//glDisable(GL_SCISSOR_TEST); //glDisable(GL_SCISSOR_TEST);
} }

View File

@ -15,7 +15,7 @@ gTimeYAxis::gTimeYAxis(QColor col)
gTimeYAxis::~gTimeYAxis() gTimeYAxis::~gTimeYAxis()
{ {
} }
const QString & gTimeYAxis::Format(double v) const QString gTimeYAxis::Format(double v)
{ {
static QString t; static QString t;
int i=v; int i=v;

View File

@ -16,7 +16,7 @@ class gTimeYAxis:public gYAxis
public: public:
gTimeYAxis(QColor col=QColor("black")); gTimeYAxis(QColor col=QColor("black"));
virtual ~gTimeYAxis(); virtual ~gTimeYAxis();
virtual const QString & Format(double v); virtual const QString Format(double v);
}; };

View File

@ -50,7 +50,7 @@ class gYAxis:public Layer
void SetShowMajorTicks(bool b) { m_show_major_ticks=b; } void SetShowMajorTicks(bool b) { m_show_major_ticks=b; }
bool ShowMinorTicks() { return m_show_minor_ticks; } bool ShowMinorTicks() { return m_show_minor_ticks; }
bool ShowMajorTicks() { return m_show_major_ticks; } bool ShowMajorTicks() { return m_show_major_ticks; }
virtual const QString & Format(double v) { static QString t; t.sprintf("%.1f",v); return t; } virtual const QString Format(double v) { return QString().sprintf("%.1f",v); }
static const int Margin=50; // Left margin space static const int Margin=50; // Left margin space
void SetScale(float f) { m_yaxis_scale=f; } // Scale yaxis ticker values (only what's displayed) void SetScale(float f) { m_yaxis_scale=f; } // Scale yaxis ticker values (only what's displayed)