aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/qsgdefaultcontext.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2022-01-17 11:57:37 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2022-01-20 19:33:01 +0100
commit8d9347085822afe3778909bf879a1274b97b231a (patch)
treef2781bf85e0ca3c8bd374bd156ba5be2b5ba0735 /src/quick/scenegraph/qsgdefaultcontext.cpp
parent338e892a18b73c912881e6e7f93ade0dbaa1eb8b (diff)
Better handle requesting no-vsync and make this usable with threaded
Just like we have e.g. QSG_NO_DEPTH_BUFFER, it is highly useful to have a QSG_NO_VSYNC which is folded into swapInterval=0 which is then mapped to QRhiSwapChain::NoVSync, i.e. both OpenGL and other APIs will be happy. Thus one can, if so desired, try disabling vsync-based blocking without modifying the application. Now, since we know if there is at least one window that has swapInterval == 0 set, the threaded render loop can recognize and handle this: the same way it falls back to the system timer based animation advancing when there are more than 1 visible windows, having a no-vsync window can trigger the same. This way the animations advancing too fast issue disappears (at the expense of potentially more stuttering) whenever explicitly requesting the disabling of vsync-based throttling. In addition, expand the scenegraph docs around this topic. Note however that this does nothing for animators (the render thread animators). Those do not have a fallback option at all. If the render thread spins too fast, they will advance too fast. [ChangeLog][QtQuick] In addition to setting the swapInterval to 0 in the QQuickWindow's QSurfaceFormat, one can now also set the QSG_NO_VSYNC=1 environment variable to achieve the same (applies globally to all Quick windows in the application). The threaded render loop can now recognize that one or more windows have vsync-based throttling disabled explicitly, and if so, it will fall back automatically to using system timers to advance animations in order to prevent animations from running too fast when the presentation rate is not throttled by vsync. Fixes: QTBUG-99950 Fixes: QTBUG-99951 Change-Id: Iddda81b467b48dbb8d87748868daa8d922ad1bd0 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/quick/scenegraph/qsgdefaultcontext.cpp')
-rw-r--r--src/quick/scenegraph/qsgdefaultcontext.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/quick/scenegraph/qsgdefaultcontext.cpp b/src/quick/scenegraph/qsgdefaultcontext.cpp
index a25b34d22d..7ea7e55bdf 100644
--- a/src/quick/scenegraph/qsgdefaultcontext.cpp
+++ b/src/quick/scenegraph/qsgdefaultcontext.cpp
@@ -208,6 +208,7 @@ QSurfaceFormat QSGDefaultContext::defaultSurfaceFormat() const
static bool useDepth = qEnvironmentVariableIsEmpty("QSG_NO_DEPTH_BUFFER");
static bool useStencil = qEnvironmentVariableIsEmpty("QSG_NO_STENCIL_BUFFER");
static bool enableDebug = qEnvironmentVariableIsSet("QSG_OPENGL_DEBUG");
+ static bool disableVSync = qEnvironmentVariableIsSet("QSG_NO_VSYNC");
if (useDepth && format.depthBufferSize() == -1)
format.setDepthBufferSize(24);
else if (!useDepth)
@@ -221,6 +222,8 @@ QSurfaceFormat QSGDefaultContext::defaultSurfaceFormat() const
if (QQuickWindow::hasDefaultAlphaBuffer())
format.setAlphaBufferSize(8);
format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
+ if (disableVSync) // swapInterval defaults to 1, it has no -1 special value
+ format.setSwapInterval(0);
return format;
}