multiwindow: React to mouse press to allow debugging UI responsiveness

The animated FPS counter should be enough to observe smooth animations,
so we use the color of the window to visualize frame latency.

Change-Id: I1171a1c4bdc261ca8655771290c6735357821781
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Tor Arne Vestbø 2016-08-25 13:09:27 +02:00 committed by Tor Arne Vestbø
parent bcbc8120b3
commit 6ce96fdbf5

View File

@ -31,14 +31,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include <QGuiApplication> #include <QtGui>
#include <QOpenGLWindow>
#include <QOpenGLContext>
#include <QOpenGLFunctions>
#include <QPainter>
#include <QElapsedTimer>
#include <QCommandLineParser>
#include <QScreen>
const char applicationDescription[] = "\n\ const char applicationDescription[] = "\n\
This application opens multiple windows and continuously schedules updates for\n\ This application opens multiple windows and continuously schedules updates for\n\
@ -67,40 +60,26 @@ class Window : public QOpenGLWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
Window(int n) : idx(n) { Window(int index) : windowNumber(index + 1), y(0), fps(0) {
r = g = b = fps = 0;
y = 0; color = QColor::fromHsl((index * 30) % 360, 255, 127).toRgb();
resize(200, 200); resize(200, 200);
setObjectName(QString("Window %1").arg(windowNumber));
connect(this, SIGNAL(frameSwapped()), SLOT(frameSwapped())); connect(this, SIGNAL(frameSwapped()), SLOT(frameSwapped()));
fpsTimer.start(); fpsTimer.start();
} }
void paintGL() { void paintGL() {
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
f->glClearColor(r, g, b, 1); f->glClearColor(color.redF(), color.greenF(), color.blueF(), 1);
f->glClear(GL_COLOR_BUFFER_BIT); f->glClear(GL_COLOR_BUFFER_BIT);
switch (idx % 3) {
case 0:
r += 0.005f;
break;
case 1:
g += 0.005f;
break;
case 2:
b += 0.005f;
break;
}
if (r > 1)
r = 0;
if (g > 1)
g = 0;
if (b > 1)
b = 0;
QPainter p(this); QPainter p(this);
p.setPen(Qt::white); p.setPen(Qt::white);
p.drawText(QPoint(20, y), QString(QLatin1String("Window %1 (%2 FPS)")).arg(idx).arg(fps)); p.drawText(QPoint(20, y), QString(QLatin1String("Window %1 (%2 FPS)")).arg(windowNumber).arg(fps));
y += 1; y += 1;
if (y > height() - 20) if (y > height() - 20)
y = 20; y = 20;
@ -118,9 +97,17 @@ public slots:
} }
} }
protected:
void mousePressEvent(QMouseEvent *event) {
qDebug() << this << event;
color.setHsl((color.hue() + 90) % 360, color.saturation(), color.lightness());
color = color.toRgb();
}
private: private:
int idx; int windowNumber;
GLfloat r, g, b; QColor color;
int y; int y;
int framesSwapped; int framesSwapped;
@ -163,7 +150,7 @@ int main(int argc, char **argv)
int numberOfWindows = qMax(parser.value(numWindowsOption).toInt(), 1); int numberOfWindows = qMax(parser.value(numWindowsOption).toInt(), 1);
QList<QWindow *> windows; QList<QWindow *> windows;
for (int i = 0; i < numberOfWindows; ++i) { for (int i = 0; i < numberOfWindows; ++i) {
Window *w = new Window(i + 1); Window *w = new Window(i);
windows << w; windows << w;
if (i == 0 && parser.isSet(vsyncOneOption)) { if (i == 0 && parser.isSet(vsyncOneOption)) {