Skip to content

Commit

Permalink
Fix serious performance issue in some cases.
Browse files Browse the repository at this point in the history
On some systems and on some versions of Qt5, QDrawPolyLine() is
extremely slow for large windows (4k).  This replaces DrawPolyLine()
with a bunch of DrawLines, which dramatically improves performance in
these cases.  However, it also means that wide lines with transparency
will have artifacts, and dashed lines will not work right when the point
density is very high.  So this is not a permanent fix.  The issue has
been reported to Qt.
  • Loading branch information
netterfield committed Aug 18, 2017
1 parent c38ce68 commit 7e26ed8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/libkstmath/curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <iostream>

// #define DEBUG_VECTOR_CURVE
// #define BENCHMARK
//#define BENCHMARK

// NOTE: on a modern (eg, sandybridge or later) cpu
// the cpu's branch prediction is so good, this does
Expand Down Expand Up @@ -695,6 +695,13 @@ double Curve::lineDim(const QRectF &R, double linewidth) {
return (int(lw+0.5));
}

void tmpPolyLine(const QPolygonF& poly, QPainter *p) {
int n = poly.count();
for (int i=0; i< n-1; i++) {
p->drawLine(poly[i], poly[i+1]);
}
}

void Curve::paintObjects(const CurveRenderContext& context) {
#ifdef BENCHMARK
QTime bench_time;
Expand All @@ -716,11 +723,13 @@ void Curve::paintObjects(const CurveRenderContext& context) {
p->fillRect(rect, barFillColor());
}
}
p->setPen(QPen(color(), _width, style));
p->setPen(QPen(color(), _width, style)); //, Qt::RoundCap, Qt::RoundJoin));

foreach(const QPolygonF& poly, _polygons) {
p->drawPolyline(poly);
tmpPolyLine(poly, p);
//p->drawPolyline(poly);
}
//qDebug() << "E:" << bench_time.elapsed() << "ms w: " << p->viewport().width() << "h: " << p->viewport().height() << " a: " << p->viewport().width() * p->viewport().height();
foreach(const QLineF& line, _lines) {
p->drawLine(line);
}
Expand Down

0 comments on commit 7e26ed8

Please sign in to comment.