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>
This commit is contained in:
parent
25c9005097
commit
4f14b42f7d
@ -79,6 +79,7 @@ void QEglFSContext::swapBuffers(QPlatformSurface *surface)
|
|||||||
cursor->paintOnScreen();
|
cursor->paintOnScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hooks->waitForVSync();
|
||||||
QEGLPlatformContext::swapBuffers(surface);
|
QEGLPlatformContext::swapBuffers(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ public:
|
|||||||
virtual bool hasCapability(QPlatformIntegration::Capability cap) const;
|
virtual bool hasCapability(QPlatformIntegration::Capability cap) const;
|
||||||
virtual QEglFSCursor *createCursor(QEglFSScreen *screen) const;
|
virtual QEglFSCursor *createCursor(QEglFSScreen *screen) const;
|
||||||
virtual bool filterConfig(EGLDisplay display, EGLConfig config) const;
|
virtual bool filterConfig(EGLDisplay display, EGLConfig config) const;
|
||||||
|
virtual void waitForVSync() const;
|
||||||
|
|
||||||
virtual const char *fbDeviceName() const;
|
virtual const char *fbDeviceName() const;
|
||||||
};
|
};
|
||||||
|
@ -47,9 +47,14 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#include <private/qmath_p.h>
|
#include <private/qmath_p.h>
|
||||||
|
#include <private/qcore_unix_p.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
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
|
const char *QEglFSHooks::fbDeviceName() const
|
||||||
{
|
{
|
||||||
return "/dev/fb0";
|
return "/dev/fb0";
|
||||||
@ -58,10 +63,17 @@ const char *QEglFSHooks::fbDeviceName() const
|
|||||||
void QEglFSHooks::platformInit()
|
void QEglFSHooks::platformInit()
|
||||||
{
|
{
|
||||||
Q_UNUSED(hooks);
|
Q_UNUSED(hooks);
|
||||||
|
|
||||||
|
framebuffer = qt_safe_open(fbDeviceName(), O_RDONLY);
|
||||||
|
|
||||||
|
if (framebuffer == -1)
|
||||||
|
qWarning("EGLFS: Failed to open %s", fbDeviceName());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QEglFSHooks::platformDestroy()
|
void QEglFSHooks::platformDestroy()
|
||||||
{
|
{
|
||||||
|
if (framebuffer != -1)
|
||||||
|
close(framebuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLNativeDisplayType QEglFSHooks::platformDisplay() const
|
EGLNativeDisplayType QEglFSHooks::platformDisplay() const
|
||||||
@ -86,22 +98,16 @@ QSizeF QEglFSHooks::physicalScreenSize() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct fb_var_screeninfo vinfo;
|
struct fb_var_screeninfo vinfo;
|
||||||
int fd = open(fbDeviceName(), O_RDONLY);
|
|
||||||
|
|
||||||
int w = -1;
|
int w = -1;
|
||||||
int h = -1;
|
int h = -1;
|
||||||
|
|
||||||
if (fd != -1) {
|
if (framebuffer != -1) {
|
||||||
if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
|
if (ioctl(framebuffer, FBIOGET_VSCREENINFO, &vinfo) == -1) {
|
||||||
qWarning("EGLFS: Could not query variable screen info.");
|
qWarning("EGLFS: Could not query variable screen info.");
|
||||||
} else {
|
} else {
|
||||||
w = vinfo.width;
|
w = vinfo.width;
|
||||||
h = vinfo.height;
|
h = vinfo.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
|
||||||
} else {
|
|
||||||
qWarning("EGLFS: Failed to open %s to detect physical screen size.", fbDeviceName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const int defaultPhysicalDpi = 100;
|
const int defaultPhysicalDpi = 100;
|
||||||
@ -140,22 +146,17 @@ QSize QEglFSHooks::screenSize() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct fb_var_screeninfo vinfo;
|
struct fb_var_screeninfo vinfo;
|
||||||
int fd = open(fbDeviceName(), O_RDONLY);
|
|
||||||
|
|
||||||
int xres = -1;
|
int xres = -1;
|
||||||
int yres = -1;
|
int yres = -1;
|
||||||
|
|
||||||
if (fd != -1) {
|
if (framebuffer != -1) {
|
||||||
if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
|
if (ioctl(framebuffer, FBIOGET_VSCREENINFO, &vinfo) == -1) {
|
||||||
qWarning("EGLFS: Could not query variable screen info.");
|
qWarning("EGLFS: Could not query variable screen info.");
|
||||||
} else {
|
} else {
|
||||||
xres = vinfo.xres;
|
xres = vinfo.xres;
|
||||||
yres = vinfo.yres;
|
yres = vinfo.yres;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
|
||||||
} else {
|
|
||||||
qWarning("EGLFS: Failed to open %s to detect screen resolution.", fbDeviceName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const int defaultWidth = 800;
|
const int defaultWidth = 800;
|
||||||
@ -185,17 +186,12 @@ int QEglFSHooks::screenDepth() const
|
|||||||
|
|
||||||
if (depth == 0) {
|
if (depth == 0) {
|
||||||
struct fb_var_screeninfo vinfo;
|
struct fb_var_screeninfo vinfo;
|
||||||
int fd = open(fbDeviceName(), O_RDONLY);
|
|
||||||
|
|
||||||
if (fd != -1) {
|
if (framebuffer != -1) {
|
||||||
if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1)
|
if (ioctl(framebuffer, FBIOGET_VSCREENINFO, &vinfo) == -1)
|
||||||
qWarning("EGLFS: Could not query variable screen info.");
|
qWarning("EGLFS: Could not query variable screen info.");
|
||||||
else
|
else
|
||||||
depth = vinfo.bits_per_pixel;
|
depth = vinfo.bits_per_pixel;
|
||||||
|
|
||||||
close(fd);
|
|
||||||
} else {
|
|
||||||
qWarning("EGLFS: Failed to open %s to detect screen depth.", fbDeviceName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const int defaultDepth = 32;
|
const int defaultDepth = 32;
|
||||||
@ -250,6 +246,16 @@ QEglFSCursor *QEglFSHooks::createCursor(QEglFSScreen *screen) const
|
|||||||
return 0;
|
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
|
#ifndef EGLFS_PLATFORM_HOOKS
|
||||||
QEglFSHooks stubHooks;
|
QEglFSHooks stubHooks;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user