path: root/src/gui/kernel/qscreen_p.h
diff options
authorMorten Johan Sørvig <>2015-06-22 12:32:11 +0200
committerPaul Olav Tvete <>2015-07-30 12:44:41 +0000
commita705b4ec1f6f7133390054f8b6b8077ef0550311 (patch)
treed9df0f8650bd62690c8489e4491bc5c2407c9d07 /src/gui/kernel/qscreen_p.h
parentdcd2debe625841ee8cba6d13a56cde7613c40358 (diff)
Introduce cross platform high-dpi scaling
Add a coordinate scaling layer to QtGui, which supports 'devicePixelRatio' type high-dpi on all platforms, in production and also for development and testing purposes. High-DPI scaling is opt-in, by setting environment variables: QT_SCALE_FACTOR - sets a global scale factor QT_AUTO_SCREEN_SCALE_FACTOR - sets per-screen scale factors, where the scale factors are provided by the platform plugin. This QtGui scaling can be used instead of or in addition to scaling done by the window system. This distinction is not visible to applications [when they use Qt API], which will see a change in the value returned by the devicePixelRatio() accessors as usual. Introduce a new (private to Qt) coordinate system: native pixels. The coordinate system stack now looks like: device-independent pixels (app, upper parts of Qt) native pixels (lower parts of Qt Gui, platform plugins) device pixels (backing stores and OpenGL) Add private QHighDpi namespace with scaling functions that convert between device-independent pixels and native pixels: T toNativePixels(T, QWindow *); T fromNativePixels(T, QWindow *); Add scaling calls the QWindow (and friends) cross-platform implementation, around the calls to QPlatformWindow functions. QPlatformWindow now uses native coordinates - platform code remains largely unchanged since native coordinates are window system coordinates. QWindow now uses (possibly) scaled coordinates. This means that platform plugins no longer can rely on QWindow::geometry() and related functions. QPlatformWindow::windowGeometry() and other convenience functions have been added for use when the platform plugin needs to convert scaled geometry to native geometry. Add Qt::AA_NoHighDpiScaling, which can be use to disable any scaling in QtGui, effectively ignoring the environment variables. (Note that this does not disable any scaling done by the window system.) Contributions from Friedemann and Paul. Task-number: QTBUG-46615 Change-Id: I673bbd69c130e73b13cce83be11bfb28f580bf60 Reviewed-by: Lars Knoll <>
Diffstat (limited to 'src/gui/kernel/qscreen_p.h')
1 files changed, 10 insertions, 15 deletions
diff --git a/src/gui/kernel/qscreen_p.h b/src/gui/kernel/qscreen_p.h
index d341b71932..4492eddd45 100644
--- a/src/gui/kernel/qscreen_p.h
+++ b/src/gui/kernel/qscreen_p.h
@@ -47,6 +47,7 @@
#include <QtGui/qscreen.h>
#include <qpa/qplatformscreen.h>
+#include "qhighdpiscaling_p.h"
#include <QtCore/private/qobject_p.h>
@@ -54,25 +55,19 @@ QT_BEGIN_NAMESPACE
class QScreenPrivate : public QObjectPrivate
- QScreenPrivate(QPlatformScreen *screen)
- : platformScreen(screen)
+ QScreenPrivate()
+ : platformScreen(0)
, orientationUpdateMask(0)
- orientation = platformScreen->orientation();
- geometry = platformScreen->geometry();
- availableGeometry = platformScreen->availableGeometry();
- logicalDpi = platformScreen->logicalDpi();
- refreshRate = platformScreen->refreshRate();
- // safeguard ourselves against buggy platform behavior...
- if (refreshRate < 1.0)
- refreshRate = 60.0;
- updatePrimaryOrientation();
+ }
- filteredOrientation = orientation;
- if (filteredOrientation == Qt::PrimaryOrientation)
- filteredOrientation = primaryOrientation;
+ void setPlatformScreen(QPlatformScreen *screen);
+ void updateHighDpi()
+ {
+ geometry = platformScreen->deviceIndependentGeometry();
+ availableGeometry = QHighDpi::fromNative(platformScreen->availableGeometry(), QHighDpiScaling::factor(platformScreen), geometry.topLeft());
void updatePrimaryOrientation();