eglfs: Fix the logical dpi calculation for some devices

KMS and backends using the default logicalDpi() implementation
(EGLDevice for instance) did not correctly check if the physical width
and height are greater than zero. The result is a NaN dpi on systems
where the drivers report a zero size. This in turn breaks font
rendering and various other things.

isValid() is changed to !isEmpty(). This way we check for width and
height > 0 instead of >= 0.

Change-Id: I8cdcf93a116379ae33c65599ad792a3b712518a3
Reviewed-by: Louai Al-Khanji <louai.al-khanji@theqtcompany.com>
bb10
Laszlo Agocs 2015-12-02 16:00:45 +01:00
parent bf0af8b5a2
commit 14e138652d
3 changed files with 23 additions and 8 deletions

View File

@ -160,10 +160,10 @@ QSizeF QEglFSKmsScreen::physicalSize() const
QDpi QEglFSKmsScreen::logicalDpi() const
{
QSizeF ps = physicalSize();
QSize s = geometry().size();
const QSizeF ps = physicalSize();
const QSize s = geometry().size();
if (ps.isValid() && s.isValid())
if (!ps.isEmpty() && !s.isEmpty())
return QDpi(25.4 * s.width() / ps.width(),
25.4 * s.height() / ps.height());
else

View File

@ -33,6 +33,7 @@
#include "qeglfskmsegldeviceintegration.h"
#include <QLoggingCategory>
#include <private/qmath_p.h>
QT_BEGIN_NAMESPACE
@ -115,7 +116,18 @@ EGLDisplay QEglFSKmsEglDeviceIntegration::createDisplay(EGLNativeDisplayType nat
QSizeF QEglFSKmsEglDeviceIntegration::physicalScreenSize() const
{
return QSizeF(m_drm_connector->mmWidth, m_drm_connector->mmHeight);
const int defaultPhysicalDpi = 100;
static const int width = qEnvironmentVariableIntValue("QT_QPA_EGLFS_PHYSICAL_WIDTH");
static const int height = qEnvironmentVariableIntValue("QT_QPA_EGLFS_PHYSICAL_HEIGHT");
QSizeF size(width, height);
if (size.isEmpty()) {
size = QSizeF(m_drm_connector->mmWidth, m_drm_connector->mmHeight);
if (size.isEmpty()) {
const float pixelsPerMm = Q_MM_PER_INCH / defaultPhysicalDpi;
size = QSizeF(screenSize().width() * pixelsPerMm, screenSize().height() * pixelsPerMm);
}
}
return size;
}
QSize QEglFSKmsEglDeviceIntegration::screenSize() const

View File

@ -212,11 +212,14 @@ QSize QEGLDeviceIntegration::screenSize() const
QDpi QEGLDeviceIntegration::logicalDpi() const
{
QSizeF ps = physicalScreenSize();
QSize s = screenSize();
const QSizeF ps = physicalScreenSize();
const QSize s = screenSize();
return QDpi(25.4 * s.width() / ps.width(),
25.4 * s.height() / ps.height());
if (!ps.isEmpty() && !s.isEmpty())
return QDpi(25.4 * s.width() / ps.width(),
25.4 * s.height() / ps.height());
else
return QDpi(100, 100);
}
qreal QEGLDeviceIntegration::pixelDensity() const