From 46cc594c6753ef774fa3016c3039ebb07281a151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Fri, 15 Feb 2013 09:23:30 +0100 Subject: Fixed EGLFS reporting impossibly high physical dimensions. If FBIOGET_VSCREENINFO doesn't give us sensible values we need to default to something instead. Refactor the code that queries the resolution and depth to behave the same way. Change-Id: Id2b3fc41349a74610856273b10281f744612890b Reviewed-by: Gunnar Sletta --- src/plugins/platforms/eglfs/qeglfshooks_stub.cpp | 75 ++++++++++++++++++++---- 1 file changed, 62 insertions(+), 13 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp b/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp index d09423ec72..a8fa81a6ec 100644 --- a/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp +++ b/src/plugins/platforms/eglfs/qeglfshooks_stub.cpp @@ -46,6 +46,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE const char *QEglFSHooks::fbDeviceName() const @@ -86,16 +88,38 @@ 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) - qWarning("Could not query variable screen info."); - else - size = QSizeF(vinfo.width, vinfo.height); + if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1) { + qWarning("EGLFS: Could not query variable screen info."); + } else { + w = vinfo.width; + h = vinfo.height; + } close(fd); } else { - qWarning("Failed to open %s to detect screen size.", fbDeviceName()); + qWarning("EGLFS: Failed to open %s to detect physical screen size.", fbDeviceName()); } + + const int defaultPhysicalDpi = 100; + size.setWidth(w <= 0 ? vinfo.xres * Q_MM_PER_INCH / defaultPhysicalDpi : qreal(w)); + size.setHeight(h <= 0 ? vinfo.yres * Q_MM_PER_INCH / defaultPhysicalDpi : qreal(h)); + + if (w <= 0 || h <= 0) { + qWarning("EGLFS: Unable to query physical screen size, defaulting to %d dpi.\n" + "EGLFS: To override, set QT_QPA_EGLFS_PHYSICAL_WIDTH " + "and QT_QPA_EGLFS_PHYSICAL_HEIGHT (in millimeters).", + defaultPhysicalDpi); + } + + // override fb0 from environment var setting + if (width) + size.setWidth(width); + if (height) + size.setWidth(height); } return size; } @@ -118,15 +142,31 @@ 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) - qWarning("Could not query variable screen info."); - else - size = QSize(vinfo.xres, vinfo.yres); + if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1) { + qWarning("EGLFS: Could not query variable screen info."); + } else { + xres = vinfo.xres; + yres = vinfo.yres; + } close(fd); } else { - qWarning("Failed to open %s to detect screen depth.", fbDeviceName()); + qWarning("EGLFS: Failed to open %s to detect screen resolution.", fbDeviceName()); + } + + const int defaultWidth = 800; + const int defaultHeight = 600; + size.setWidth(xres <= 0 ? defaultWidth : xres); + size.setHeight(yres <= 0 ? defaultHeight : yres); + + if (xres <= 0 || yres <= 0) { + qWarning("EGLFS: Unable to query screen resolution, defaulting to %dx%d.\n" + "EGLFS: To override, set QT_QPA_EGLFS_WIDTH and QT_QPA_EGLFS_HEIGHT.", + defaultWidth, defaultHeight); } // override fb0 from environment var setting @@ -149,17 +189,26 @@ int QEglFSHooks::screenDepth() const if (fd != -1) { if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1) - qWarning("Could not query variable screen info."); + qWarning("EGLFS: Could not query variable screen info."); else depth = vinfo.bits_per_pixel; close(fd); } else { - qWarning("Failed to open %s to detect screen depth.", fbDeviceName()); + qWarning("EGLFS: Failed to open %s to detect screen depth.", fbDeviceName()); + } + + const int defaultDepth = 32; + + if (depth <= 0) { + depth = defaultDepth; + + qWarning("EGLFS: Unable to query screen depth, defaulting to %d.\n" + "EGLFS: To override, set QT_QPA_EGLFS_DEPTH.", defaultDepth); } } - return depth == 0 ? 32 : depth; + return depth; } QImage::Format QEglFSHooks::screenFormat() const -- cgit v1.2.3