Merge lp:~loic.molinari/oxide/oxide-ubuntu-scale-factor into lp:~oxide-developers/oxide/oxide.trunk

Proposed by Loïc Molinari
Status: Merged
Merged at revision: 1364
Proposed branch: lp:~loic.molinari/oxide/oxide-ubuntu-scale-factor
Merge into: lp:~oxide-developers/oxide/oxide.trunk
Diff against target: 122 lines (+41/-21)
3 files modified
qt/core/browser/oxide_qt_screen_client.cc (+15/-0)
qt/core/browser/oxide_qt_screen_client.h (+3/-0)
qt/core/browser/oxide_qt_screen_utils.cc (+23/-21)
To merge this branch: bzr merge lp:~loic.molinari/oxide/oxide-ubuntu-scale-factor
Reviewer Review Type Date Requested Status
Chris Coulson Approve
Gerry Boland (community) Needs Fixing
Michał Sawicz (community) Needs Information
Review via email: mp+286109@code.launchpad.net

Commit message

Added support for scale factor retrieved from the Ubuntu QPA plugin.

Description of the change

Added support for scale factor retrieved from the Ubuntu QPA plugin.

To post a comment you must log in.
Revision history for this message
Michał Sawicz (saviq) wrote :

Loic, this is against an oxide that's not even close to getting in to ubuntu... we're still at 1.12.5.

Any chance this could be reapplied against that?

review: Needs Information
Revision history for this message
Chris Coulson (chrisccoulson) wrote :

No, please don't do that. All changes land on trunk first

Revision history for this message
Michał Sawicz (saviq) wrote :

@Chris yeah, but we'd need this change for demo, and taking the whole of trunk oxide with us just for that feels suicidal...

Revision history for this message
Chris Coulson (chrisccoulson) wrote :

But that doesn't change anything - all changes are developed against and land on trunk first

Revision history for this message
Chris Coulson (chrisccoulson) wrote :

This looks ok, bar one style nit

review: Needs Fixing
Revision history for this message
Gerry Boland (gerboland) wrote :

+ SIGNAL(screenPropertyChanged(QPlatformWindow*, const QString&)),
+ SLOT(OnScreenPropertyChanged(QPlatformWindow*, const QString&)));

Should be QPlatformScreen

review: Needs Fixing
Revision history for this message
Chris Coulson (chrisccoulson) wrote :

One other thing - does the QPA plugin do the actual scaling in this case, or is this still done in the UI toolkit?

Revision history for this message
Gerry Boland (gerboland) wrote :

> One other thing - does the QPA plugin do the actual scaling in this case, or
> is this still done in the UI toolkit?

UITK does scaling, as should anything that renders content. QPA doesn't do any scaling.

Revision history for this message
Chris Coulson (chrisccoulson) wrote :

Thanks, I've merged this in now

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'qt/core/browser/oxide_qt_screen_client.cc'
2--- qt/core/browser/oxide_qt_screen_client.cc 2016-02-06 22:10:29 +0000
3+++ qt/core/browser/oxide_qt_screen_client.cc 2016-02-23 16:54:31 +0000
4@@ -41,6 +41,14 @@
5 UpdatePrimaryDisplay();
6 }
7
8+void ScreenClient::OnScreenPropertyChanged(
9+ QPlatformScreen *screen, const QString& propertyName) {
10+ if (propertyName == QStringLiteral("scale") &&
11+ screen == QGuiApplication::primaryScreen()->handle()) {
12+ UpdatePrimaryDisplay();
13+ }
14+}
15+
16 void ScreenClient::UpdatePrimaryDisplay() {
17 base::AutoLock lock(primary_display_lock_);
18
19@@ -96,6 +104,13 @@
20 SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)),
21 SLOT(OnScreenOrientationChanged(Qt::ScreenOrientation)));
22
23+ QString platform = QGuiApplication::platformName();
24+ if (platform.startsWith("ubuntu") || platform == "mirserver") {
25+ connect(QGuiApplication::platformNativeInterface(),
26+ SIGNAL(screenPropertyChanged(QPlatformScreen*, const QString&)),
27+ SLOT(OnScreenPropertyChanged(QPlatformScreen*, const QString&)));
28+ }
29+
30 UpdatePrimaryDisplay();
31 }
32
33
34=== modified file 'qt/core/browser/oxide_qt_screen_client.h'
35--- qt/core/browser/oxide_qt_screen_client.h 2016-02-02 21:56:01 +0000
36+++ qt/core/browser/oxide_qt_screen_client.h 2016-02-23 16:54:31 +0000
37@@ -20,6 +20,8 @@
38
39 #include <QObject>
40 #include <QtGlobal>
41+#include <QtGui/qpa/qplatformnativeinterface.h>
42+#include <QtGui/qpa/qplatformscreen.h>
43
44 #include "base/macros.h"
45 #include "base/synchronization/lock.h"
46@@ -40,6 +42,7 @@
47 private Q_SLOTS:
48 void OnScreenGeometryChanged(const QRect& geometry);
49 void OnScreenOrientationChanged(Qt::ScreenOrientation orientation);
50+ void OnScreenPropertyChanged(QPlatformScreen* screen, const QString& propertyName);
51
52 private:
53 void UpdatePrimaryDisplay();
54
55=== modified file 'qt/core/browser/oxide_qt_screen_utils.cc'
56--- qt/core/browser/oxide_qt_screen_utils.cc 2016-02-02 21:56:01 +0000
57+++ qt/core/browser/oxide_qt_screen_utils.cc 2016-02-23 16:54:31 +0000
58@@ -22,6 +22,7 @@
59 #include <QRect>
60 #include <QScreen>
61 #include <QString>
62+#include <QtGui/qpa/qplatformnativeinterface.h>
63
64 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScreenOrientationType.h"
65 #include "third_party/WebKit/public/platform/WebRect.h"
66@@ -51,27 +52,19 @@
67 }
68
69 float GetDeviceScaleFactorFromQScreen(QScreen* screen) {
70- // For some reason, the Ubuntu QPA plugin doesn't override
71- // QScreen::devicePixelRatio. However, applications using the Ubuntu
72- // SDK use something called "grid units". The relationship between
73- // grid units and device pixels is set by the "GRID_UNIT_PX" environment
74- // variable. On a screen with a DPR of 1.0f, GRID_UNIT_PX is set to 8, and
75- // 1 grid unit == 8 device pixels.
76- // If we are using the Ubuntu backend, we use GRID_UNIT_PX to derive the
77- // device pixel ratio, else we get it from QScreen::devicePixelRatio.
78- // XXX: There are 2 scenarios where this is completely broken:
79- // 1) Any apps not using the Ubuntu SDK but running with the Ubuntu
80- // QPA plugin. In this case, we derive a DPR from GRID_UNIT_PX if
81- // set, and the application probably uses QScreen::devicePixelRatio,
82- // which is always 1.0f
83- // 2) Any apps using the Ubuntu SDK but not running with the Ubuntu
84- // QPA plugin. In this case, we get the DPR from
85- // QScreen::devicePixelRatio, and the application uses GRID_UNIX_PX
86- // if set
87- // I think it would be better if the Ubuntu QPA plugin did override
88- // QScreen::devicePixelRatio (it could still get that from GRID_UNIT_PX),
89- // and the Ubuntu SDK used this to convert between grid units and device
90- // pixels, then we could just use QScreen::devicePixelRatio here
91+ // Because it only supports integer scale factors, the Ubuntu QPA plugin
92+ // doesn't use the default Qt devicePixelRatio but a custom scaling system
93+ // based on grid units. The relationship between grid units and device pixels
94+ // is set by the "GRID_UNIT_PX" environment variable. On a screen with a scale
95+ // factor of 1, GRID_UNIT_PX is set to 8, and 1 grid unit == 8 device pixels.
96+ // If the Ubuntu backend is used, we retrieve scale factors from the QPA
97+ // plugin. For old versions that don't expose these factors, we deduce the
98+ // scale factor by reading the "GRID_UNIT_PX" environment variable.
99+ //
100+ // XXX: This is broken for apps not using the Ubuntu SDK but running with the
101+ // Ubuntu QPA plugin. In this case, the scaling is applied even though
102+ // it's unlikely to be expected. A workaround is to have
103+ // "OXIDE_FORCE_DPR" set.
104
105 // Allow an override for testing
106 {
107@@ -85,6 +78,15 @@
108
109 QString platform = QGuiApplication::platformName();
110 if (platform.startsWith("ubuntu") || platform == "mirserver") {
111+
112+ QPlatformNativeInterface* interface =
113+ QGuiApplication::platformNativeInterface();
114+ void* data =
115+ interface->nativeResourceForScreen(QByteArray("scale"), screen);
116+ if (data) {
117+ return *reinterpret_cast<float*>(data);
118+ }
119+
120 QByteArray grid_unit_px(qgetenv("GRID_UNIT_PX"));
121 bool ok;
122 float scale = grid_unit_px.toFloat(&ok);

Subscribers

People subscribed via source and target branches