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

Subscribers

People subscribed via source and target branches