Commit a1e58ff5 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Rebase patch on Qt 5.13

parent 823b66ac
From 3ef20bcb114c316efb74a0a704e918731847620c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= <morten.sorvig@qt.io>
Date: Mon, 25 Apr 2016 11:31:34 +0200
Subject: [PATCH 32/36] Update Dpi and scale factor computation
Remove pixelScale() in favor of logicalBaseDpi(). Compute scale factor
based on logical DPI and logical base DPI, or optionally based on the
physical DPI.
Add policies for running the scale factor and adjusting the logical
DPI reported to the application. The policies are set via environment
variables:
QT_SCALE_FACTOR_ROUNDING_POLICY=Round|Ceil|Floor|RoundPreferFloor|PassThrough
QT_DPI_ADJUSTMENT_POLICY=AdjustDpi|DontAdjustDpi|AdjustUpOnly
QT_USE_PHYSICAL_DPI=0|1
Done-with: Friedemann Kleint <Friedemann.Kleint@qt.io>
Task-number: QTBUG-53022
Change-Id: I4846f223186df665eb0a9c827eaef0a96d1f458f
---
src/gui/kernel/qhighdpiscaling.cpp | 234 ++++++++++++++++--
src/gui/kernel/qhighdpiscaling_p.h | 29 +++
src/gui/kernel/qplatformscreen.cpp | 14 ++
src/gui/kernel/qplatformscreen.h | 1 +
.../android/qandroidplatformscreen.cpp | 8 +-
.../android/qandroidplatformscreen.h | 2 +-
src/plugins/platforms/cocoa/qcocoascreen.h | 1 +
.../platforms/windows/qwindowsscreen.cpp | 9 -
.../platforms/windows/qwindowsscreen.h | 2 +-
src/plugins/platforms/xcb/qxcbscreen.cpp | 11 -
src/plugins/platforms/xcb/qxcbscreen.h | 3 +-
tests/manual/highdpi/highdpi.pro | 1 +
12 files changed, 264 insertions(+), 51 deletions(-)
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp
index 541d4f12af..ae531569ce 100644
--- a/src/gui/kernel/qhighdpiscaling.cpp
+++ b/src/gui/kernel/qhighdpiscaling.cpp
diff --git a/qtbase/src/gui/kernel/qhighdpiscaling.cpp b/qtbase/src/gui/kernel/qhighdpiscaling.cpp
index 22e46e085..cdf6c8669 100644
--- a/qtbase/src/gui/kernel/qhighdpiscaling.cpp
+++ b/qtbase/src/gui/kernel/qhighdpiscaling.cpp
@@ -44,6 +44,9 @@
#include "private/qscreen_p.h"
......@@ -66,7 +31,7 @@ index 541d4f12af..ae531569ce 100644
static inline qreal initialGlobalScaleFactor()
{
@@ -247,6 +262,191 @@ static inline bool usePixelDensity()
@@ -248,6 +263,191 @@ static inline bool usePixelDensity()
qgetenv(legacyDevicePixelEnvVar).compare("auto", Qt::CaseInsensitive) == 0);
}
......@@ -258,7 +223,7 @@ index 541d4f12af..ae531569ce 100644
void QHighDpiScaling::initHighDpiScaling()
{
// Determine if there is a global scale factor set.
@@ -257,8 +457,6 @@ void QHighDpiScaling::initHighDpiScaling()
@@ -258,8 +458,6 @@ void QHighDpiScaling::initHighDpiScaling()
m_pixelDensityScalingActive = false; //set in updateHighDpiScaling below
......@@ -267,16 +232,7 @@ index 541d4f12af..ae531569ce 100644
m_active = m_globalScalingActive || m_usePixelDensity;
}
@@ -310,7 +508,7 @@ void QHighDpiScaling::updateHighDpiScaling()
++i;
}
}
- m_active = m_globalScalingActive || m_screenFactorSet || m_pixelDensityScalingActive;
+ m_active = m_globalScalingActive || m_usePixelDensity;
}
/*
@@ -371,22 +569,8 @@ qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen)
@@ -380,22 +578,8 @@ qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen)
{
qreal factor = qreal(1.0);
if (screen) {
......@@ -301,31 +257,10 @@ index 541d4f12af..ae531569ce 100644
if (m_screenFactorSet) {
QVariant screenFactor = screen->screen()->property(scaleFactorProperty);
if (screenFactor.isValid())
@@ -399,13 +583,15 @@ qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen)
QDpi QHighDpiScaling::logicalDpi(const QScreen *screen)
{
// (Note: m_active test is performed at call site.)
- if (!screen)
+ if (!screen || !screen->handle())
return QDpi(96, 96);
- qreal platformScreenfactor = screenSubfactor(screen->handle());
- QDpi platformScreenDpi = screen->handle()->logicalDpi();
- return QDpi(platformScreenDpi.first / platformScreenfactor,
- platformScreenDpi.second / platformScreenfactor);
+ if (!m_usePixelDensity)
+ return screen->handle()->logicalDpi();
+
+ const qreal scaleFactor = rawScaleFactor(screen->handle());
+ const qreal roundedScaleFactor = roundScaleFactor(scaleFactor);
+ return effectiveLogicalDpi(screen->handle(), scaleFactor, roundedScaleFactor);
}
qreal QHighDpiScaling::factor(const QScreen *screen)
diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h
index ecd9ed6515..55bddfeb88 100644
--- a/src/gui/kernel/qhighdpiscaling_p.h
+++ b/src/gui/kernel/qhighdpiscaling_p.h
diff --git a/qtbase/src/gui/kernel/qhighdpiscaling_p.h b/qtbase/src/gui/kernel/qhighdpiscaling_p.h
index 83fc9452c..c664693a0 100644
--- a/qtbase/src/gui/kernel/qhighdpiscaling_p.h
+++ b/qtbase/src/gui/kernel/qhighdpiscaling_p.h
@@ -71,7 +71,33 @@ typedef QPair<qreal, qreal> QDpi;
#ifndef QT_NO_HIGHDPISCALING
......@@ -361,7 +296,7 @@ index ecd9ed6515..55bddfeb88 100644
static void updateHighDpiScaling();
static void setGlobalFactor(qreal factor);
@@ -88,6 +114,9 @@ public:
static QDpi logicalDpi(const QScreen *screen);
static QDpi logicalDpi();
private:
+ static qreal rawScaleFactor(const QPlatformScreen *screen);
......@@ -370,11 +305,11 @@ index ecd9ed6515..55bddfeb88 100644
static qreal screenSubfactor(const QPlatformScreen *screen);
static qreal m_factor;
diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp
index b7b312e89e..07a2231228 100644
--- a/src/gui/kernel/qplatformscreen.cpp
+++ b/src/gui/kernel/qplatformscreen.cpp
@@ -194,6 +194,20 @@ QDpi QPlatformScreen::logicalDpi() const
diff --git a/qtbase/src/gui/kernel/qplatformscreen.cpp b/qtbase/src/gui/kernel/qplatformscreen.cpp
index 21ae75ba8..ff76528a0 100644
--- a/qtbase/src/gui/kernel/qplatformscreen.cpp
+++ b/qtbase/src/gui/kernel/qplatformscreen.cpp
@@ -197,6 +197,20 @@ QDpi QPlatformScreen::logicalDpi() const
25.4 * s.height() / ps.height());
}
......@@ -395,10 +330,10 @@ index b7b312e89e..07a2231228 100644
/*!
Reimplement this function in subclass to return the device pixel ratio
for the screen. This is the ratio between physical pixels and the
diff --git a/src/gui/kernel/qplatformscreen.h b/src/gui/kernel/qplatformscreen.h
index e9d64c8a29..63b5d5a4a7 100644
--- a/src/gui/kernel/qplatformscreen.h
+++ b/src/gui/kernel/qplatformscreen.h
diff --git a/qtbase/src/gui/kernel/qplatformscreen.h b/qtbase/src/gui/kernel/qplatformscreen.h
index e9d64c8a2..63b5d5a4a 100644
--- a/qtbase/src/gui/kernel/qplatformscreen.h
+++ b/qtbase/src/gui/kernel/qplatformscreen.h
@@ -113,6 +113,7 @@ public:
virtual QSizeF physicalSize() const;
......@@ -407,10 +342,10 @@ index e9d64c8a29..63b5d5a4a7 100644
virtual qreal devicePixelRatio() const;
virtual qreal pixelDensity() const;
diff --git a/src/plugins/platforms/android/qandroidplatformscreen.cpp b/src/plugins/platforms/android/qandroidplatformscreen.cpp
index 7dc8bb8080..80757c2135 100644
--- a/src/plugins/platforms/android/qandroidplatformscreen.cpp
+++ b/src/plugins/platforms/android/qandroidplatformscreen.cpp
diff --git a/qtbase/src/plugins/platforms/android/qandroidplatformscreen.cpp b/qtbase/src/plugins/platforms/android/qandroidplatformscreen.cpp
index 7dc8bb808..80757c213 100644
--- a/qtbase/src/plugins/platforms/android/qandroidplatformscreen.cpp
+++ b/qtbase/src/plugins/platforms/android/qandroidplatformscreen.cpp
@@ -401,15 +401,17 @@ void QAndroidPlatformScreen::doRedraw()
m_dirtyRect = QRect();
}
......@@ -432,10 +367,10 @@ index 7dc8bb8080..80757c2135 100644
}
Qt::ScreenOrientation QAndroidPlatformScreen::orientation() const
diff --git a/src/plugins/platforms/android/qandroidplatformscreen.h b/src/plugins/platforms/android/qandroidplatformscreen.h
index f15aeae3fd..5dc158e351 100644
--- a/src/plugins/platforms/android/qandroidplatformscreen.h
+++ b/src/plugins/platforms/android/qandroidplatformscreen.h
diff --git a/qtbase/src/plugins/platforms/android/qandroidplatformscreen.h b/qtbase/src/plugins/platforms/android/qandroidplatformscreen.h
index f15aeae3f..5dc158e35 100644
--- a/qtbase/src/plugins/platforms/android/qandroidplatformscreen.h
+++ b/qtbase/src/plugins/platforms/android/qandroidplatformscreen.h
@@ -103,7 +103,7 @@ protected:
private:
......@@ -445,10 +380,10 @@ index f15aeae3fd..5dc158e351 100644
Qt::ScreenOrientation orientation() const override;
Qt::ScreenOrientation nativeOrientation() const override;
void surfaceChanged(JNIEnv *env, jobject surface, int w, int h) override;
diff --git a/src/plugins/platforms/cocoa/qcocoascreen.h b/src/plugins/platforms/cocoa/qcocoascreen.h
index 9ded98df32..a73b97c771 100644
--- a/src/plugins/platforms/cocoa/qcocoascreen.h
+++ b/src/plugins/platforms/cocoa/qcocoascreen.h
diff --git a/qtbase/src/plugins/platforms/cocoa/qcocoascreen.h b/qtbase/src/plugins/platforms/cocoa/qcocoascreen.h
index 9ded98df3..a73b97c77 100644
--- a/qtbase/src/plugins/platforms/cocoa/qcocoascreen.h
+++ b/qtbase/src/plugins/platforms/cocoa/qcocoascreen.h
@@ -64,6 +64,7 @@ public:
qreal devicePixelRatio() const override;
QSizeF physicalSize() const override { return m_physicalSize; }
......@@ -457,10 +392,10 @@ index 9ded98df32..a73b97c771 100644
qreal refreshRate() const override { return m_refreshRate; }
QString name() const override { return m_name; }
QPlatformCursor *cursor() const override { return m_cursor; }
diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp
index 8a5f0e6577..ebde684038 100644
--- a/src/plugins/platforms/windows/qwindowsscreen.cpp
+++ b/src/plugins/platforms/windows/qwindowsscreen.cpp
diff --git a/qtbase/src/plugins/platforms/windows/qwindowsscreen.cpp b/qtbase/src/plugins/platforms/windows/qwindowsscreen.cpp
index 0520f8893..9b7b4630f 100644
--- a/qtbase/src/plugins/platforms/windows/qwindowsscreen.cpp
+++ b/qtbase/src/plugins/platforms/windows/qwindowsscreen.cpp
@@ -254,15 +254,6 @@ QWindow *QWindowsScreen::windowAt(const QPoint &screenPoint, unsigned flags)
return result;
}
......@@ -477,10 +412,10 @@ index 8a5f0e6577..ebde684038 100644
/*!
\brief Determine siblings in a virtual desktop system.
diff --git a/src/plugins/platforms/windows/qwindowsscreen.h b/src/plugins/platforms/windows/qwindowsscreen.h
index 33c9effa2a..a7b1c64e29 100644
--- a/src/plugins/platforms/windows/qwindowsscreen.h
+++ b/src/plugins/platforms/windows/qwindowsscreen.h
diff --git a/qtbase/src/plugins/platforms/windows/qwindowsscreen.h b/qtbase/src/plugins/platforms/windows/qwindowsscreen.h
index 824bcb1ad..cd765f181 100644
--- a/qtbase/src/plugins/platforms/windows/qwindowsscreen.h
+++ b/qtbase/src/plugins/platforms/windows/qwindowsscreen.h
@@ -87,7 +87,7 @@ public:
QImage::Format format() const override { return m_data.format; }
QSizeF physicalSize() const override { return m_data.physicalSizeMM; }
......@@ -490,10 +425,10 @@ index 33c9effa2a..a7b1c64e29 100644
qreal devicePixelRatio() const override { return 1.0; }
qreal refreshRate() const override { return m_data.refreshRateHz; }
QString name() const override { return m_data.name; }
diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp
index 57dbdc9bec..9af0794d29 100644
--- a/src/plugins/platforms/xcb/qxcbscreen.cpp
+++ b/src/plugins/platforms/xcb/qxcbscreen.cpp
diff --git a/qtbase/src/plugins/platforms/xcb/qxcbscreen.cpp b/qtbase/src/plugins/platforms/xcb/qxcbscreen.cpp
index 57dbdc9be..9af0794d2 100644
--- a/qtbase/src/plugins/platforms/xcb/qxcbscreen.cpp
+++ b/qtbase/src/plugins/platforms/xcb/qxcbscreen.cpp
@@ -671,11 +671,6 @@ QDpi QXcbScreen::logicalDpi() const
return m_virtualDesktop->dpi();
}
......@@ -519,10 +454,10 @@ index 57dbdc9bec..9af0794d29 100644
m_geometry = geometry;
m_availableGeometry = geometry & m_virtualDesktop->workArea();
QWindowSystemInterface::handleScreenGeometryChange(QPlatformScreen::screen(), m_geometry, m_availableGeometry);
diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h
index be6c45e415..3f619d71c2 100644
--- a/src/plugins/platforms/xcb/qxcbscreen.h
+++ b/src/plugins/platforms/xcb/qxcbscreen.h
diff --git a/qtbase/src/plugins/platforms/xcb/qxcbscreen.h b/qtbase/src/plugins/platforms/xcb/qxcbscreen.h
index be6c45e41..3f619d71c 100644
--- a/qtbase/src/plugins/platforms/xcb/qxcbscreen.h
+++ b/qtbase/src/plugins/platforms/xcb/qxcbscreen.h
@@ -161,7 +161,7 @@ public:
QImage::Format format() const override;
QSizeF physicalSize() const override { return m_sizeMillimeters; }
......@@ -540,15 +475,12 @@ index be6c45e415..3f619d71c2 100644
QEdidParser m_edid;
};
diff --git a/tests/manual/highdpi/highdpi.pro b/tests/manual/highdpi/highdpi.pro
index 9db083cd82..2de8ed3bb5 100644
--- a/tests/manual/highdpi/highdpi.pro
+++ b/tests/manual/highdpi/highdpi.pro
diff --git a/qtbase/tests/manual/highdpi/highdpi.pro b/qtbase/tests/manual/highdpi/highdpi.pro
index 9db083cd8..2de8ed3bb 100644
--- a/qtbase/tests/manual/highdpi/highdpi.pro
+++ b/qtbase/tests/manual/highdpi/highdpi.pro
@@ -15,3 +15,4 @@ HEADERS += \
RESOURCES += \
highdpi.qrc
+DEFINES += HAVE_SCREEN_BASE_DPI
--
2.18.0.windows.1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment