From bcbc8120b30a3d94d6a131ad936a8270657ffd96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 25 Aug 2016 13:02:47 +0200 Subject: multiwindow: Use showNormal() instead of show() to ensure normal geometry Change-Id: Ice607f536a620da5a70f2ba066f4983bb78c6288 Reviewed-by: Simon Hausmann --- tests/manual/qopenglwindow/multiwindow/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/manual/qopenglwindow') diff --git a/tests/manual/qopenglwindow/multiwindow/main.cpp b/tests/manual/qopenglwindow/multiwindow/main.cpp index caa15078d5..66ebb73c56 100644 --- a/tests/manual/qopenglwindow/multiwindow/main.cpp +++ b/tests/manual/qopenglwindow/multiwindow/main.cpp @@ -187,7 +187,7 @@ int main(int argc, char **argv) QPoint position = availableGeometry.topLeft(); position += QPoint(col * windowWidth, row * windowHeight); w->setFramePosition(position); - w->show(); + w->showNormal(); } int r = app.exec(); -- cgit v1.2.3 From 6ce96fdbf59138bebadbd8157d8285327a1a3796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 25 Aug 2016 13:09:27 +0200 Subject: 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 --- tests/manual/qopenglwindow/multiwindow/main.cpp | 53 ++++++++++--------------- 1 file changed, 20 insertions(+), 33 deletions(-) (limited to 'tests/manual/qopenglwindow') diff --git a/tests/manual/qopenglwindow/multiwindow/main.cpp b/tests/manual/qopenglwindow/multiwindow/main.cpp index 66ebb73c56..31688d717e 100644 --- a/tests/manual/qopenglwindow/multiwindow/main.cpp +++ b/tests/manual/qopenglwindow/multiwindow/main.cpp @@ -31,14 +31,7 @@ ** ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include +#include const char applicationDescription[] = "\n\ This application opens multiple windows and continuously schedules updates for\n\ @@ -67,40 +60,26 @@ class Window : public QOpenGLWindow { Q_OBJECT public: - Window(int n) : idx(n) { - r = g = b = fps = 0; - y = 0; + Window(int index) : windowNumber(index + 1), y(0), fps(0) { + + color = QColor::fromHsl((index * 30) % 360, 255, 127).toRgb(); + resize(200, 200); + setObjectName(QString("Window %1").arg(windowNumber)); + connect(this, SIGNAL(frameSwapped()), SLOT(frameSwapped())); fpsTimer.start(); } void paintGL() { 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); - 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); 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; if (y > height() - 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: - int idx; - GLfloat r, g, b; + int windowNumber; + QColor color; + int y; int framesSwapped; @@ -163,7 +150,7 @@ int main(int argc, char **argv) int numberOfWindows = qMax(parser.value(numWindowsOption).toInt(), 1); QList windows; for (int i = 0; i < numberOfWindows; ++i) { - Window *w = new Window(i + 1); + Window *w = new Window(i); windows << w; if (i == 0 && parser.isSet(vsyncOneOption)) { -- cgit v1.2.3 From 880beb121e76b60cdfbd59d6a04fd600532c72bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 31 Aug 2016 18:21:18 +0200 Subject: multiwindow: Call update() after swap Change-Id: Ic2c26339bce9fe92b2ccc730c72f53ce94397b78 Reviewed-by: Simon Hausmann --- tests/manual/qopenglwindow/multiwindow/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/manual/qopenglwindow') diff --git a/tests/manual/qopenglwindow/multiwindow/main.cpp b/tests/manual/qopenglwindow/multiwindow/main.cpp index 31688d717e..17442dbae5 100644 --- a/tests/manual/qopenglwindow/multiwindow/main.cpp +++ b/tests/manual/qopenglwindow/multiwindow/main.cpp @@ -83,8 +83,6 @@ public: y += 1; if (y > height() - 20) y = 20; - - update(); } public slots: @@ -95,6 +93,8 @@ public slots: framesSwapped = 0; fpsTimer.restart(); } + + update(); } protected: -- cgit v1.2.3 From efdecff085d6e9d8c738bd681757c8cc18a3a451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 31 Aug 2016 18:15:52 +0200 Subject: multiwindow: Replace per window fps timers with unified approach The FPS is now calculated and output on the command line in a single place. The animated fps counter has been replaced with a vertical line which should make it easier to observe tearing issues when vsync is disabled. Change-Id: Id356fc1958c048d85aba48edfed59124454038d4 Reviewed-by: Simon Hausmann --- tests/manual/qopenglwindow/multiwindow/main.cpp | 64 ++++++++++++++++++------- 1 file changed, 46 insertions(+), 18 deletions(-) (limited to 'tests/manual/qopenglwindow') diff --git a/tests/manual/qopenglwindow/multiwindow/main.cpp b/tests/manual/qopenglwindow/multiwindow/main.cpp index 17442dbae5..8b17226366 100644 --- a/tests/manual/qopenglwindow/multiwindow/main.cpp +++ b/tests/manual/qopenglwindow/multiwindow/main.cpp @@ -60,7 +60,7 @@ class Window : public QOpenGLWindow { Q_OBJECT public: - Window(int index) : windowNumber(index + 1), y(0), fps(0) { + Window(int index) : windowNumber(index + 1), x(0), framesSwapped(0) { color = QColor::fromHsl((index * 30) % 360, 255, 127).toRgb(); @@ -69,7 +69,6 @@ public: setObjectName(QString("Window %1").arg(windowNumber)); connect(this, SIGNAL(frameSwapped()), SLOT(frameSwapped())); - fpsTimer.start(); } void paintGL() { @@ -77,23 +76,14 @@ public: f->glClearColor(color.redF(), color.greenF(), color.blueF(), 1); f->glClear(GL_COLOR_BUFFER_BIT); - QPainter p(this); - p.setPen(Qt::white); - p.drawText(QPoint(20, y), QString(QLatin1String("Window %1 (%2 FPS)")).arg(windowNumber).arg(fps)); - y += 1; - if (y > height() - 20) - y = 20; + QPainter painter(this); + painter.drawLine(x, 0, x, height()); + x = ++x % width(); } public slots: void frameSwapped() { ++framesSwapped; - if (fpsTimer.elapsed() > 1000) { - fps = qRound(framesSwapped * (1000.0 / fpsTimer.elapsed())); - framesSwapped = 0; - fpsTimer.restart(); - } - update(); } @@ -107,14 +97,46 @@ protected: private: int windowNumber; QColor color; - - int y; + int x; int framesSwapped; - QElapsedTimer fpsTimer; - int fps; + friend void printFps(); }; +static const qreal kFpsInterval = 500; + +void printFps() +{ + static QElapsedTimer timer; + if (!timer.isValid()) { + timer.start(); + return; + } + + const qreal frameFactor = (kFpsInterval / timer.elapsed()) * (1000.0 / kFpsInterval); + + QDebug output = qDebug().nospace(); + + qreal averageFps = 0; + const QWindowList windows = QGuiApplication::topLevelWindows(); + for (int i = 0; i < windows.size(); ++i) { + Window *w = qobject_cast(windows.at(i)); + Q_ASSERT(w); + + int fps = qRound(w->framesSwapped * frameFactor); + output << (i + 1) << "=" << fps << ", "; + + averageFps += fps; + w->framesSwapped = 0; + } + averageFps = qRound(averageFps / windows.size()); + qreal msPerFrame = 1000.0 / averageFps; + + output << "avg=" << averageFps << ", ms=" << msPerFrame; + + timer.restart(); +} + int main(int argc, char **argv) { QGuiApplication app(argc, argv); @@ -177,6 +199,12 @@ int main(int argc, char **argv) w->showNormal(); } + QTimer fpsTimer; + fpsTimer.setInterval(kFpsInterval); + fpsTimer.setTimerType(Qt::PreciseTimer); + QObject::connect(&fpsTimer, &QTimer::timeout, &printFps); + fpsTimer.start(); + int r = app.exec(); qDeleteAll(windows); return r; -- cgit v1.2.3 From fecee98836842af1693696c547405af3f740e0d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 25 Aug 2016 15:04:54 +0200 Subject: multiwindow: Base vsync debug output on actual surface format Allows us to detect cases where the requested vsync combination was not possible to fulfill. Change-Id: Ie8f3665129f7a1ab7fcefb94b2298d54520b753a Reviewed-by: Simon Hausmann --- tests/manual/qopenglwindow/multiwindow/main.cpp | 30 +++++++++++++++---------- 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'tests/manual/qopenglwindow') diff --git a/tests/manual/qopenglwindow/multiwindow/main.cpp b/tests/manual/qopenglwindow/multiwindow/main.cpp index 8b17226366..89a94f3b3e 100644 --- a/tests/manual/qopenglwindow/multiwindow/main.cpp +++ b/tests/manual/qopenglwindow/multiwindow/main.cpp @@ -88,6 +88,18 @@ public slots: } protected: + void exposeEvent(QExposeEvent *event) { + if (!isExposed()) + return; + + QSurfaceFormat format = context()->format(); + qDebug() << this << format.swapBehavior() << "with Vsync =" << (format.swapInterval() ? "ON" : "OFF"); + if (format.swapInterval() != requestedFormat().swapInterval()) + qWarning() << "WARNING: Did not get requested swap interval of" << requestedFormat().swapInterval() << "for" << this; + + QOpenGLWindow::exposeEvent(event); + } + void mousePressEvent(QMouseEvent *event) { qDebug() << this << event; color.setHsl((color.hue() + 90) % 360, color.saturation(), color.lightness()); @@ -158,14 +170,9 @@ int main(int argc, char **argv) parser.process(app); - QSurfaceFormat fmt; - if (parser.isSet(noVsyncOption)) { - qDebug("swap interval 0 (no throttling)"); - fmt.setSwapInterval(0); - } else { - qDebug("swap interval 1 (sync to vblank)"); - } - QSurfaceFormat::setDefaultFormat(fmt); + QSurfaceFormat defaultSurfaceFormat; + defaultSurfaceFormat.setSwapInterval(parser.isSet(noVsyncOption) ? 0 : 1); + QSurfaceFormat::setDefaultFormat(defaultSurfaceFormat); QRect availableGeometry = app.primaryScreen()->availableGeometry(); @@ -176,12 +183,11 @@ int main(int argc, char **argv) windows << w; if (i == 0 && parser.isSet(vsyncOneOption)) { - qDebug("swap interval 1 for first window only"); - QSurfaceFormat vsyncedSurfaceFormat = fmt; + QSurfaceFormat vsyncedSurfaceFormat = defaultSurfaceFormat; vsyncedSurfaceFormat.setSwapInterval(1); w->setFormat(vsyncedSurfaceFormat); - fmt.setSwapInterval(0); - QSurfaceFormat::setDefaultFormat(fmt); + defaultSurfaceFormat.setSwapInterval(0); + QSurfaceFormat::setDefaultFormat(defaultSurfaceFormat); } static int windowWidth = w->width() + 20; -- cgit v1.2.3