Merge lp:~loic.molinari/ubuntu-ui-toolkit/ubuntu-ui-toolkit-shape-content-orientation-workaround-removal into lp:ubuntu-ui-toolkit/staging

Proposed by Loïc Molinari
Status: Merged
Approved by: Cris Dywan
Approved revision: 1586
Merged at revision: 1588
Proposed branch: lp:~loic.molinari/ubuntu-ui-toolkit/ubuntu-ui-toolkit-shape-content-orientation-workaround-removal
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 189 lines (+15/-53)
4 files modified
src/Ubuntu/Components/plugin/shaders/shape.frag (+6/-7)
src/Ubuntu/Components/plugin/shaders/shapeoverlay.frag (+4/-5)
src/Ubuntu/Components/plugin/ucubuntushape.cpp (+4/-39)
src/Ubuntu/Components/plugin/ucubuntushape.h (+1/-2)
To merge this branch: bzr merge lp:~loic.molinari/ubuntu-ui-toolkit/ubuntu-ui-toolkit-shape-content-orientation-workaround-removal
Reviewer Review Type Date Requested Status
Cris Dywan Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+266529@code.launchpad.net

Commit message

[UbuntuShape] Removed content orientation work around.

The shape was using a workaround to make it render correctly when the content orientation was not the native one. This was perfect for the OrientationHelper shipped with the toolkit but now that the Shell implements the rotation, this is not needed anymore and causes some rendering issues. Note that the shape will still needs to support correct rendering when rotated using the rotation property of the Item, but that is a different issue.

Description of the change

[UbuntuShape] Removed content orientation work around.

The shape was using a workaround to make it render correctly when the content orientation was not the native one. This was perfect for the OrientationHelper shipped with the toolkit but now that the Shell implements the rotation, this is not needed anymore and causes some rendering issues. Note that the shape will still needs to support correct rendering when rotated using the rotation property of the Item, but that is a different issue.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

This makes sense.

However I have a small concern. With this change the UbuntuShape becomes "incompatible" with platforms that use Window.contentOrientation such as Ubuntu Phone used to, and others such as Wayland, Android, Sailfish, etc. might - if we care about apps on other platforms that is. Now as already pointed out, Item.rotation isn't currently supported but could be - and technically even the Window.contentOrientation applied by OrientationHelper was changing Item.rotation all along, only that's now what the code was based on. So, I'm wondering, can we have transparent Item.rotation support? And can/ should we avoid being too specific to what Unity8 does, as hard-coding shell-specifics in the toolkit seems less than future proof?

review: Needs Information
Revision history for this message
Loïc Molinari (loic.molinari) wrote :

That is true and I plan to propose a solution that works for both Item.rotation and Window.contentOrientation. There is a dedicated bug for that (bug #1480199).

Revision history for this message
Cris Dywan (kalikiana) wrote :

Okay, thanks. So this is good to go.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Ubuntu/Components/plugin/shaders/shape.frag'
2--- src/Ubuntu/Components/plugin/shaders/shape.frag 2015-07-23 16:01:51 +0000
3+++ src/Ubuntu/Components/plugin/shaders/shape.frag 2015-07-31 10:02:25 +0000
4@@ -24,8 +24,8 @@
5
6 uniform sampler2D shapeTexture;
7 uniform sampler2D sourceTexture;
8-uniform lowp vec2 dfdtFactors;
9 uniform lowp vec2 opacityFactors;
10+uniform lowp float dfdtFactor;
11 uniform lowp float sourceOpacity;
12 uniform lowp float distanceAA;
13 uniform bool textured;
14@@ -56,10 +56,9 @@
15 }
16
17 // Get screen-space derivative of texture coordinate t representing the normalized distance
18- // between 2 pixels. dFd*() unfortunately have to be called outside of branches in order to work
19+ // between 2 pixels. dFd*() functions have to be called outside of branches in order to work
20 // correctly with VMware's "Gallium 0.4 on SVGA3D".
21- lowp vec2 derivatives = vec2(dFdx(shapeCoord.t), dFdy(shapeCoord.t));
22- lowp float dfdt = dfdtFactors.x != 0.0 ? derivatives.x : derivatives.y;
23+ lowp float dfdt = dFdy(shapeCoord.t);
24
25 if (aspect == FLAT) {
26 // Mask the current color with an anti-aliased and resolution independent shape mask built
27@@ -71,7 +70,7 @@
28 } else if (aspect == INSET) {
29 // The vertex layout of the shape is made so that the derivative is negative from top to
30 // middle and positive from middle to bottom.
31- lowp float shapeSide = dfdt * dfdtFactors.y <= 0.0 ? 0.0 : 1.0;
32+ lowp float shapeSide = dfdt * dfdtFactor <= 0.0 ? 0.0 : 1.0;
33 // Blend the shape inner shadow over the current color. The shadow color is black, its
34 // translucency is stored in the texture.
35 lowp float shadow = shapeData[int(shapeSide)];
36@@ -93,11 +92,11 @@
37 } else if (aspect == DROP_SHADOW) {
38 // The vertex layout of the shape is made so that the derivative is negative from top to
39 // middle and positive from middle to bottom.
40- lowp float shapeSide = dfdt * dfdtFactors.y <= 0.0 ? 0.0 : 1.0;
41+ lowp int shapeSide = dfdt * dfdtFactor <= 0.0 ? 0 : 1;
42 // Get the anti-aliased and resolution independent shape mask using distance fields.
43 lowp float distanceMin = abs(dfdt) * -distanceAA + 0.5;
44 lowp float distanceMax = abs(dfdt) * distanceAA + 0.5;
45- lowp float mask = smoothstep(distanceMin, distanceMax, shapeData[int(shapeSide)]);
46+ lowp float mask = smoothstep(distanceMin, distanceMax, shapeData[shapeSide]);
47 // Get the shadow color outside of the shape mask.
48 lowp float shadow = (shapeData.b * -mask) + shapeData.b; // -ab + a = a(1 - b)
49 // Mask the current color then blend the shadow over the resulting color. We simply use
50
51=== modified file 'src/Ubuntu/Components/plugin/shaders/shapeoverlay.frag'
52--- src/Ubuntu/Components/plugin/shaders/shapeoverlay.frag 2015-04-16 11:59:56 +0000
53+++ src/Ubuntu/Components/plugin/shaders/shapeoverlay.frag 2015-07-31 10:02:25 +0000
54@@ -24,8 +24,8 @@
55
56 uniform sampler2D shapeTexture;
57 uniform sampler2D sourceTexture;
58-uniform lowp vec2 dfdtFactors;
59 uniform lowp vec2 opacityFactors;
60+uniform lowp float dfdtFactor;
61 uniform lowp float sourceOpacity;
62 uniform lowp float distanceAA;
63 uniform bool textured;
64@@ -64,10 +64,9 @@
65 color = vec4(1.0 - overlay.a) * color + overlay;
66
67 // Get screen-space derivative of texture coordinate t representing the normalized distance
68- // between 2 pixels. dFd*() unfortunately have to be called outside of branches in order to work
69+ // between 2 pixels. dFd*() functions have to be called outside of branches in order to work
70 // correctly with VMware's "Gallium 0.4 on SVGA3D".
71- lowp vec2 derivatives = vec2(dFdx(shapeCoord.t), dFdy(shapeCoord.t));
72- lowp float dfdt = dfdtFactors.x != 0.0 ? derivatives.x : derivatives.y;
73+ lowp float dfdt = dFdy(shapeCoord.t);
74
75 if (aspect == FLAT) {
76 // Mask the current color with an anti-aliased and resolution independent shape mask built
77@@ -79,7 +78,7 @@
78 } else if (aspect == INSET) {
79 // The vertex layout of the shape is made so that the derivative is negative from top to
80 // middle and positive from middle to bottom.
81- lowp float shapeSide = dfdt * dfdtFactors.y <= 0.0 ? 0.0 : 1.0;
82+ lowp float shapeSide = dfdt * dfdtFactor <= 0.0 ? 0.0 : 1.0;
83 // Blend the shape inner shadow over the current color. The shadow color is black, its
84 // translucency is stored in the texture.
85 lowp float shadow = shapeData[int(shapeSide)];
86
87=== modified file 'src/Ubuntu/Components/plugin/ucubuntushape.cpp'
88--- src/Ubuntu/Components/plugin/ucubuntushape.cpp 2015-07-24 18:11:57 +0000
89+++ src/Ubuntu/Components/plugin/ucubuntushape.cpp 2015-07-31 10:02:25 +0000
90@@ -74,8 +74,8 @@
91
92 m_functions = QOpenGLContext::currentContext()->functions();
93 m_matrixId = program()->uniformLocation("matrix");
94- m_dfdtFactorsId = program()->uniformLocation("dfdtFactors");
95 m_opacityFactorsId = program()->uniformLocation("opacityFactors");
96+ m_dfdtFactorId = program()->uniformLocation("dfdtFactor");
97 m_sourceOpacityId = program()->uniformLocation("sourceOpacity");
98 m_distanceAAId = program()->uniformLocation("distanceAA");
99 m_texturedId = program()->uniformLocation("textured");
100@@ -138,13 +138,9 @@
101 const float distanceAA = (shapeTextureDistanceAA * distanceAApx) / (2.0 * 255.0f);
102 program()->setUniformValue(m_distanceAAId, data->distanceAAFactor * distanceAA);
103
104- // Send screen-space derivative factors. Note that when rendering is redirected to a
105- // ShaderEffectSource (FBO), dFdy() sign is flipped.
106- const float orientation = static_cast<float>(data->dfdtFactors & 0x4);
107- const float flip = static_cast<float>(data->dfdtFactors & 0x3) - 1.0f;
108- const bool flipped = orientation != 1.0f && state.projectionMatrix()(1, 3) < 0.0f;
109- const QVector2D dfdtFactors(orientation, flipped ? -flip : flip);
110- program()->setUniformValue(m_dfdtFactorsId, dfdtFactors);
111+ // When rendering is redirected to a ShaderEffectSource (FBO), dFdy() sign is flipped.
112+ const float dfdtFactor = (state.projectionMatrix()(1, 3) < 0.0f) ? -1.0f : 1.0f;
113+ program()->setUniformValue(m_dfdtFactorId, dfdtFactor);
114
115 // Update QtQuick engine uniforms.
116 if (state.isMatrixDirty()) {
117@@ -252,7 +248,6 @@
118
119 static struct { QOpenGLContext* openglContext; quint32 textureId[shapeTextureCount]; }
120 shapeTextures[maxShapeTextures];
121-static bool isPrimaryOrientationLandscape = false;
122
123 static int getShapeTexturesIndex(const QOpenGLContext* openglContext);
124
125@@ -310,17 +305,6 @@
126 , m_sourceOpacity(255)
127 , m_flags(Stretched)
128 {
129- static bool once = true;
130- if (once) {
131- // Stored statically as the primary orientation is fixed and we don't support multiple
132- // screens for now.
133- if (QGuiApplication::primaryScreen()->primaryOrientation() &
134- (Qt::LandscapeOrientation | Qt::InvertedLandscapeOrientation)) {
135- isPrimaryOrientationLandscape = true;
136- }
137- once = false;
138- }
139-
140 setFlag(ItemHasContents);
141 QObject::connect(&UCUnits::instance(), SIGNAL(gridUnitChanged()), this,
142 SLOT(_q_gridUnitChanged()));
143@@ -1307,25 +1291,6 @@
144 materialData->distanceAAFactor =
145 qMin((radius / (end - start)) - (start / (end - start)), 1.0f) * 255.0f;
146
147- // Screen-space derivatives factors for fragment shaders depend on the primary orientation and
148- // content orientation. A flag indicating a 90° rotation around the primary orientation is
149- // stored on the 3rd bit of dfdtFactors, the flip factor is stored on the first 2 bits as 0 for
150- // -1 and as 2 for 1 (efficiently converted using: float(x & 0x3) - 1.0f).
151- const Qt::ScreenOrientation contentOrientation = window()->contentOrientation();
152- if (isPrimaryOrientationLandscape) {
153- const quint8 portraitMask = Qt::PortraitOrientation | Qt::InvertedPortraitOrientation;
154- const quint8 flipMask = Qt::InvertedLandscapeOrientation | Qt::InvertedPortraitOrientation;
155- quint8 factors = contentOrientation & portraitMask ? 0x4 : 0x0;
156- factors |= contentOrientation & flipMask ? 0x0 : 0x2;
157- materialData->dfdtFactors = factors;
158- } else {
159- const quint8 landscapeMask = Qt::LandscapeOrientation | Qt::InvertedLandscapeOrientation;
160- const quint8 flipMask = Qt::InvertedPortraitOrientation | Qt::LandscapeOrientation;
161- quint8 factors = contentOrientation & landscapeMask ? 0x4 : 0x0;
162- factors |= contentOrientation & flipMask ? 0x0 : 0x2;
163- materialData->dfdtFactors = factors;
164- }
165-
166 // When the radius is equal to radiusSizeOffset (which means radius size is 0), no aspect is
167 // flagged so that a dedicated (statically flow controlled) shaved off shader can be used for
168 // optimal performance.
169
170=== modified file 'src/Ubuntu/Components/plugin/ucubuntushape.h'
171--- src/Ubuntu/Components/plugin/ucubuntushape.h 2015-07-23 17:17:47 +0000
172+++ src/Ubuntu/Components/plugin/ucubuntushape.h 2015-07-31 10:02:25 +0000
173@@ -41,8 +41,8 @@
174 private:
175 QOpenGLFunctions* m_functions;
176 int m_matrixId;
177- int m_dfdtFactorsId;
178 int m_opacityFactorsId;
179+ int m_dfdtFactorId;
180 int m_sourceOpacityId;
181 int m_distanceAAId;
182 int m_texturedId;
183@@ -70,7 +70,6 @@
184 quint32 shapeTextureId;
185 quint8 distanceAAFactor;
186 quint8 sourceOpacity;
187- quint8 dfdtFactors;
188 quint8 flags;
189 };
190

Subscribers

People subscribed via source and target branches