summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2013-01-14 16:26:03 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-22 09:24:40 +0100
commit4f14b42f7dc289cd73a5e7aa934d6052c708bac3 (patch)
tree998a1b751318c16dcba0a2cafec03982a73ad152 /src/plugins/platforms/eglfs/qeglfshooks_stub.cpp
parent25c90050974714b5582df5ef9609be4efe4e771a (diff)
Add support for forced VSYNC using the EGLFS platform plugin.
Before a buffer swap the new QEglFSHooks::waitForVSync method is called which looks at QT_QPA_EGLFS_FORCEVSYNC and - if that is set and non-null - calls ioctl with the FBIO_WAITFORVSYNC request on the framebuffer device. This is required on some embedded platforms where the driver does not support VSYNC yet the Kernel provides a generic implementation. I tested this using QML_RENDER_TIMING=1 which proofs that the frame rate for an example of mine drops from >125fps to a straight ~60fps with a few frames that take ~33ms (i.e. 30fps) as expected for VSYNC. To prevent excessive open/close calls on the frame buffer device per frame, the file descriptor is now cached. To keep the QEglFSHooks interface as clean as possible this is done via a global static in qeglfshooks_stub.cpp and initialized and freed in platformInit and platformDestroy. Change-Id: I4d31b227c65ff22aa089db0fbc62c89a59cbb6c7 Reviewed-by: Sean Harmer <sean.harmer@kdab.com> Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Diffstat (limited to 'src/plugins/platforms/eglfs/qeglfshooks_stub.cpp')
-rw-r--r--src/plugins/platforms/eglfs/qeglfshooks_stub.cpp50
1 files changed, 28 insertions, 22 deletions
diff --git a/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp b/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp
index a8fa81a6ec..6c036cd680 100644
--- a/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp
+++ b/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp
@@ -47,9 +47,14 @@
#include <sys/ioctl.h>
#include <private/qmath_p.h>
+#include <private/qcore_unix_p.h>
QT_BEGIN_NAMESPACE
+// file descriptor for the frame buffer
+// this is a global static to keep the QEglFSHooks interface as clean as possible
+static int framebuffer = -1;
+
const char *QEglFSHooks::fbDeviceName() const
{
return "/dev/fb0";
@@ -58,10 +63,17 @@ const char *QEglFSHooks::fbDeviceName() const
void QEglFSHooks::platformInit()
{
Q_UNUSED(hooks);
+
+ framebuffer = qt_safe_open(fbDeviceName(), O_RDONLY);
+
+ if (framebuffer == -1)
+ qWarning("EGLFS: Failed to open %s", fbDeviceName());
}
void QEglFSHooks::platformDestroy()
{
+ if (framebuffer != -1)
+ close(framebuffer);
}
EGLNativeDisplayType QEglFSHooks::platformDisplay() const
@@ -86,22 +98,16 @@ QSizeF QEglFSHooks::physicalScreenSize() const
}
struct fb_var_screeninfo vinfo;
- int fd = open(fbDeviceName(), O_RDONLY);
-
int w = -1;
int h = -1;
- if (fd != -1) {
- if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
+ if (framebuffer != -1) {
+ if (ioctl(framebuffer, FBIOGET_VSCREENINFO, &vinfo) == -1) {
qWarning("EGLFS: Could not query variable screen info.");
} else {
w = vinfo.width;
h = vinfo.height;
}
-
- close(fd);
- } else {
- qWarning("EGLFS: Failed to open %s to detect physical screen size.", fbDeviceName());
}
const int defaultPhysicalDpi = 100;
@@ -140,22 +146,17 @@ QSize QEglFSHooks::screenSize() const
}
struct fb_var_screeninfo vinfo;
- int fd = open(fbDeviceName(), O_RDONLY);
int xres = -1;
int yres = -1;
- if (fd != -1) {
- if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
+ if (framebuffer != -1) {
+ if (ioctl(framebuffer, FBIOGET_VSCREENINFO, &vinfo) == -1) {
qWarning("EGLFS: Could not query variable screen info.");
} else {
xres = vinfo.xres;
yres = vinfo.yres;
}
-
- close(fd);
- } else {
- qWarning("EGLFS: Failed to open %s to detect screen resolution.", fbDeviceName());
}
const int defaultWidth = 800;
@@ -185,17 +186,12 @@ int QEglFSHooks::screenDepth() const
if (depth == 0) {
struct fb_var_screeninfo vinfo;
- int fd = open(fbDeviceName(), O_RDONLY);
- if (fd != -1) {
- if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1)
+ if (framebuffer != -1) {
+ if (ioctl(framebuffer, FBIOGET_VSCREENINFO, &vinfo) == -1)
qWarning("EGLFS: Could not query variable screen info.");
else
depth = vinfo.bits_per_pixel;
-
- close(fd);
- } else {
- qWarning("EGLFS: Failed to open %s to detect screen depth.", fbDeviceName());
}
const int defaultDepth = 32;
@@ -250,6 +246,16 @@ QEglFSCursor *QEglFSHooks::createCursor(QEglFSScreen *screen) const
return 0;
}
+void QEglFSHooks::waitForVSync() const
+{
+ static const bool forceSync = qgetenv("QT_QPA_EGLFS_FORCEVSYNC").toInt();
+ if (forceSync && framebuffer != -1) {
+ int arg = 0;
+ if (ioctl(framebuffer, FBIO_WAITFORVSYNC, &arg) == -1)
+ qWarning("Could not wait for vsync.");
+ }
+}
+
#ifndef EGLFS_PLATFORM_HOOKS
QEglFSHooks stubHooks;
#endif