Merge lp:~loic.molinari/ubuntu-ui-toolkit/ubuntu-ui-toolkit-dfdt-factors-fix into lp:ubuntu-ui-toolkit/staging

Proposed by Loïc Molinari on 2015-05-20
Status: Merged
Approved by: Christian Dywan on 2015-06-02
Approved revision: 1189
Merged at revision: 1525
Proposed branch: lp:~loic.molinari/ubuntu-ui-toolkit/ubuntu-ui-toolkit-dfdt-factors-fix
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 118 lines (+37/-31)
2 files modified
modules/Ubuntu/Components/plugin/ucubuntushape.cpp (+36/-31)
modules/Ubuntu/Components/plugin/ucubuntushape.h (+1/-0)
To merge this branch: bzr merge lp:~loic.molinari/ubuntu-ui-toolkit/ubuntu-ui-toolkit-dfdt-factors-fix
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve on 2015-06-02
Christian Dywan 2015-05-20 Approve on 2015-06-02
Review via email: mp+259692@code.launchpad.net

Commit Message

[UbuntuShape] Computed dfdt factors based on window content orientation.

Previous logic was based on screen orientation which is not in sync with OrientationHelper.qml.

Description of the Change

[UbuntuShape] Computed dfdt factors based on window content orientation.

Previous logic was based on screen orientation which is not in sync with OrientationHelper.qml.

To post a comment you must log in.
1189. By Loïc Molinari on 2015-05-21

Explicitely initialized .bss variable for portability reasons (not required by C standard but set to 0 on Linux for sure).

Christian Dywan (kalikiana) wrote :

FYI I tried this in conjunction with my branch for orientation test cases and buttons are still jagged badly around the border, for your convenience a throw-away test branch (./run_tests.sh ubuntuuitoolkit.tests.components.test_popover.PopoverRotateTestCase.test_rotate to see it in action).

Christian Dywan (kalikiana) wrote :

As discussed, this fix specifically addresses aliasing seen when rotating a device with an app locked to original orientation (such as toolkit gallery when modified to not rotate) and it works perfectly.

The symptom is exactly the same as what I referred to above, but that's visible in tests only, and can be addressed in a follow-up in any case.

My final concern here is actually that this is very hard to verify as long as very different specific conditions lead to aliasing issues. And multi monitor support will make it even more complex. I filed bug 1461077.

review: Approve
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/plugin/ucubuntushape.cpp'
2--- modules/Ubuntu/Components/plugin/ucubuntushape.cpp 2015-04-30 19:51:26 +0000
3+++ modules/Ubuntu/Components/plugin/ucubuntushape.cpp 2015-05-21 11:25:23 +0000
4@@ -49,36 +49,8 @@
5
6 // --- Scene graph shader ---
7
8-// Factors used to know which screen-space derivatives must be used in the fragment shaders based on
9-// the primary orientation and current orientation.
10-static float dfdtFactors[2];
11-
12-static void orientationChanged(Qt::ScreenOrientation orientation)
13-{
14- const quint8 landscapeMask = Qt::LandscapeOrientation | Qt::InvertedLandscapeOrientation;
15- const quint8 portraitMask = Qt::PortraitOrientation | Qt::InvertedPortraitOrientation;
16- if (QGuiApplication::primaryScreen()->primaryOrientation() & landscapeMask) {
17- const quint8 flippedMask =
18- Qt::InvertedLandscapeOrientation | Qt::InvertedPortraitOrientation;
19- dfdtFactors[0] = orientation & landscapeMask ? 0.0f : 1.0f;
20- dfdtFactors[1] = orientation & flippedMask ? -1.0f : 1.0f;
21- } else {
22- const quint8 flippedMask = Qt::InvertedPortraitOrientation | Qt::LandscapeOrientation;
23- dfdtFactors[0] = orientation & portraitMask ? 0.0f : 1.0f;
24- dfdtFactors[1] = orientation & flippedMask ? -1.0f : 1.0f;
25- }
26-}
27-
28 ShapeShader::ShapeShader()
29 {
30- static bool once = true;
31- if (once) {
32- const QScreen* primaryScreen = QGuiApplication::primaryScreen();
33- orientationChanged(primaryScreen->orientation());
34- QObject::connect(primaryScreen, &QScreen::orientationChanged, orientationChanged);
35- once = false;
36- }
37-
38 setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/uc/shaders/shape.vert"));
39 setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/uc/shaders/shape.frag"));
40 }
41@@ -168,9 +140,11 @@
42
43 // Send screen-space derivative factors. Note that when rendering is redirected to a
44 // ShaderEffectSource (FBO), dFdy() sign is flipped.
45- const bool flipped = dfdtFactors[0] != 1.0f && state.projectionMatrix()(1, 3) < 0.0f;
46- const QVector2D dfdtFactorsVector(dfdtFactors[0], flipped ? -dfdtFactors[1] : dfdtFactors[1]);
47- program()->setUniformValue(m_dfdtFactorsId, dfdtFactorsVector);
48+ const float orientation = static_cast<float>(data->dfdtFactors & 0x4);
49+ const float flip = static_cast<float>(data->dfdtFactors & 0x3) - 1.0f;
50+ const bool flipped = orientation != 1.0f && state.projectionMatrix()(1, 3) < 0.0f;
51+ const QVector2D dfdtFactors(orientation, flipped ? -flip : flip);
52+ program()->setUniformValue(m_dfdtFactorsId, dfdtFactors);
53
54 // Update QtQuick engine uniforms.
55 if (state.isMatrixDirty()) {
56@@ -272,6 +246,7 @@
57 // --- QtQuick item ---
58
59 static QHash<QOpenGLContext*, quint32> shapeTextureHash;
60+static bool isPrimaryOrientationLandscape = false;
61
62 const float implicitWidthGU = 8.0f;
63 const float implicitHeightGU = 8.0f;
64@@ -331,6 +306,17 @@
65 , m_sourceOpacity(255)
66 , m_flags(Stretched)
67 {
68+ static bool once = true;
69+ if (once) {
70+ // Stored statically as the primary orientation is fixed and we don't support multiple
71+ // screens for now.
72+ if (QGuiApplication::primaryScreen()->primaryOrientation() &
73+ (Qt::LandscapeOrientation | Qt::InvertedLandscapeOrientation)) {
74+ isPrimaryOrientationLandscape = true;
75+ }
76+ once = false;
77+ }
78+
79 setFlag(ItemHasContents);
80 QObject::connect(&UCUnits::instance(), SIGNAL(gridUnitChanged()), this,
81 SLOT(_q_gridUnitChanged()));
82@@ -1236,6 +1222,25 @@
83 materialData->distanceAAFactor = qMin(
84 (radius / (end - start)) - (start / (end - start)), 1.0f) * 255.0f;
85
86+ // Screen-space derivatives factors for fragment shaders depend on the primary orientation and
87+ // content orientation. A flag indicating a 90° rotation around the primary orientation is
88+ // stored on the 3rd bit of dfdtFactors, the flip factor is stored on the first 2 bits as 0 for
89+ // -1 and as 2 for 1 (efficiently converted using: float(x & 0x3) - 1.0f).
90+ const Qt::ScreenOrientation contentOrientation = window()->contentOrientation();
91+ if (isPrimaryOrientationLandscape) {
92+ const quint8 portraitMask = Qt::PortraitOrientation | Qt::InvertedPortraitOrientation;
93+ const quint8 flipMask = Qt::InvertedLandscapeOrientation | Qt::InvertedPortraitOrientation;
94+ quint8 factors = contentOrientation & portraitMask ? 0x4 : 0x0;
95+ factors |= contentOrientation & flipMask ? 0x0 : 0x2;
96+ materialData->dfdtFactors = factors;
97+ } else {
98+ const quint8 landscapeMask = Qt::LandscapeOrientation | Qt::InvertedLandscapeOrientation;
99+ const quint8 flipMask = Qt::InvertedPortraitOrientation | Qt::LandscapeOrientation;
100+ quint8 factors = contentOrientation & landscapeMask ? 0x4 : 0x0;
101+ factors |= contentOrientation & flipMask ? 0x0 : 0x2;
102+ materialData->dfdtFactors = factors;
103+ }
104+
105 // When the radius is equal to radiusSizeOffset (which means radius size is 0), no aspect is
106 // flagged so that a dedicated (statically flow controlled) shaved off shader can be used for
107 // optimal performance.
108
109=== modified file 'modules/Ubuntu/Components/plugin/ucubuntushape.h'
110--- modules/Ubuntu/Components/plugin/ucubuntushape.h 2015-04-22 19:33:39 +0000
111+++ modules/Ubuntu/Components/plugin/ucubuntushape.h 2015-05-21 11:25:23 +0000
112@@ -68,6 +68,7 @@
113 quint32 shapeTexture;
114 quint8 distanceAAFactor;
115 quint8 sourceOpacity;
116+ quint8 dfdtFactors;
117 quint8 flags;
118 };
119

Subscribers

People subscribed via source and target branches