Mir

Merge lp:~vanvugt/mir/fix-1339471 into lp:mir

Proposed by Daniel van Vugt
Status: Rejected
Rejected by: Daniel van Vugt
Proposed branch: lp:~vanvugt/mir/fix-1339471
Merge into: lp:mir
Diff against target: 187 lines (+29/-41)
6 files modified
examples/demo-shell/demo_renderer.cpp (+11/-11)
examples/eglcounter.cpp (+2/-3)
examples/eglflash.c (+11/-21)
examples/egltriangle.c (+2/-3)
src/server/compositor/gl_renderer.cpp (+2/-2)
tests/unit-tests/compositor/test_gl_renderer.cpp (+1/-1)
To merge this branch: bzr merge lp:~vanvugt/mir/fix-1339471
Reviewer Review Type Date Requested Status
Alberto Aguirre (community) Disapprove
Alexandros Frantzis (community) Disapprove
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+226064@code.launchpad.net

Commit message

Revert r1687 as it is producing visibly incorrect colours when compared
to r1686. (LP: #1339471)

This reverts enhancement LP: #1318852, which needs to be approached
differently. Aside from anything else it's infeasible to modify all existing
alpha-blending apps and toolkits to pre-multiply alpha values like r1687
necessitated. So simply modifying the colours used in
mir_demo_client_multiwin wouldn't scale and fix all other toolkits' apps in
the world.

The default blending function must be (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
but we're free to add options that change that for particular special
surfaces if necessary. So LP: #1318852 can be re-implemented in some other
way.

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
Alexandros Frantzis (afrantzis) wrote :

Qt/Qml apps render with premultiplied alpha by default. Cairo does premultiplied alpha by default too.

I think it's reasonable to demand (and document clearly) that surfaces with alpha passed to Mir are premultiplied.

Perhaps we could let the clients select per surface, if we find that important clients can't do premultiplied alpha. Even so, premultiplied alpha would a reasonable default.

review: Disapprove
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

" So simply modifying the colours used in
mir_demo_client_multiwin wouldn't scale and fix all other toolkits' apps in
the world."

What are these toolkits? Most of the libraries I know do pre-multiplied alpha (for good reason) by default.

review: Disapprove
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Alright, clearly my graphics knowledge is a decade or so behind the those newer tookits.

Unmerged revisions

1754. By Daniel van Vugt

Revert r1687 as it is producing visibly incorrect colours when compared
to r1686. (LP: #1339471)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/demo-shell/demo_renderer.cpp'
2--- examples/demo-shell/demo_renderer.cpp 2014-06-18 12:50:31 +0000
3+++ examples/demo-shell/demo_renderer.cpp 2014-07-09 06:44:55 +0000
4@@ -94,6 +94,15 @@
5 {
6 Color col = color;
7
8+ // Cut out the corner in a circular shape.
9+ if (x < cx && y < cy)
10+ {
11+ int dx = cx - x;
12+ int dy = cy - y;
13+ if (dx * dx + dy * dy >= radius_sqr)
14+ col.a = 0;
15+ }
16+
17 // Set gradient
18 if (y < cy)
19 {
20@@ -105,15 +114,6 @@
21 col.b += (highlight - col.b) * brighten;
22 }
23
24- // Cut out the corner in a circular shape.
25- if (x < cx && y < cy)
26- {
27- int dx = cx - x;
28- int dy = cy - y;
29- if (dx * dx + dy * dy >= radius_sqr)
30- col = {0, 0, 0, 0};
31- }
32-
33 image[y * width + x] = col;
34 }
35 }
36@@ -164,7 +164,7 @@
37 if (opaque)
38 glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
39 else
40- glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
41+ glClearColor(0.2f, 0.2f, 0.2f, 0.0f);
42
43 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
44 glClear(GL_COLOR_BUFFER_BIT);
45@@ -273,7 +273,7 @@
46
47 // Shadows always need blending...
48 glEnable(GL_BLEND);
49- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
50+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
51 }
52
53 void DemoRenderer::tessellate_frame(std::vector<graphics::GLPrimitive>& primitives,
54
55=== modified file 'examples/eglcounter.cpp'
56--- examples/eglcounter.cpp 2014-06-05 21:28:43 +0000
57+++ examples/eglcounter.cpp 2014-07-09 06:44:55 +0000
58@@ -201,7 +201,7 @@
59 };
60
61 /* Colours from http://design.ubuntu.com/brand/colour-palette */
62-#define MID_AUBERGINE(x) x*0.368627451f, x*0.152941176f, x*0.31372549f
63+#define MID_AUBERGINE 0.368627451f, 0.152941176f, 0.31372549f
64 #define ORANGE 0.866666667f, 0.282352941f, 0.141414141f
65
66 int main(int argc, char *argv[])
67@@ -254,8 +254,7 @@
68 return 2;
69 }
70
71- float const opacity = mir_eglapp_background_opacity;
72- glClearColor(MID_AUBERGINE(opacity), opacity);
73+ glClearColor(MID_AUBERGINE, mir_eglapp_background_opacity);
74 glViewport(0, 0, width, height);
75
76 glUseProgram(prog);
77
78=== modified file 'examples/eglflash.c'
79--- examples/eglflash.c 2014-06-05 21:28:43 +0000
80+++ examples/eglflash.c 2014-07-09 06:44:55 +0000
81@@ -23,11 +23,6 @@
82 #include <unistd.h>
83 #include <GLES2/gl2.h>
84
85-typedef struct Color
86-{
87- GLfloat r, g, b, a;
88-} Color;
89-
90 int main(int argc, char *argv[])
91 {
92 unsigned int width = 0, height = 0;
93@@ -35,25 +30,20 @@
94 if (!mir_eglapp_init(argc, argv, &width, &height))
95 return 1;
96
97- float const opacity = mir_eglapp_background_opacity;
98- Color red = {opacity, 0.0f, 0.0f, opacity};
99- Color green = {0.0f, opacity, 0.0f, opacity};
100- Color blue = {0.0f, 0.0f, opacity, opacity};
101-
102 /* This is probably the simplest GL you can do */
103 while (mir_eglapp_running())
104 {
105- glClearColor(red.r, red.g, red.b, red.a);
106- glClear(GL_COLOR_BUFFER_BIT);
107- mir_eglapp_swap_buffers();
108- sleep(1);
109-
110- glClearColor(green.r, green.g, green.b, green.a);
111- glClear(GL_COLOR_BUFFER_BIT);
112- mir_eglapp_swap_buffers();
113- sleep(1);
114-
115- glClearColor(blue.r, blue.g, blue.b, blue.a);
116+ glClearColor(1.0f, 0.0f, 0.0f, mir_eglapp_background_opacity);
117+ glClear(GL_COLOR_BUFFER_BIT);
118+ mir_eglapp_swap_buffers();
119+ sleep(1);
120+
121+ glClearColor(0.0f, 1.0f, 0.0f, mir_eglapp_background_opacity);
122+ glClear(GL_COLOR_BUFFER_BIT);
123+ mir_eglapp_swap_buffers();
124+ sleep(1);
125+
126+ glClearColor(0.0f, 0.0f, 1.0f, mir_eglapp_background_opacity);
127 glClear(GL_COLOR_BUFFER_BIT);
128 mir_eglapp_swap_buffers();
129 sleep(1);
130
131=== modified file 'examples/egltriangle.c'
132--- examples/egltriangle.c 2014-06-09 17:16:32 +0000
133+++ examples/egltriangle.c 2014-07-09 06:44:55 +0000
134@@ -44,7 +44,7 @@
135 }
136
137 /* Colours from http://design.ubuntu.com/brand/colour-palette */
138-#define MID_AUBERGINE(x) x*0.368627451f, x*0.152941176f, x*0.31372549f
139+#define MID_AUBERGINE 0.368627451f, 0.152941176f, 0.31372549f
140 #define ORANGE 0.866666667f, 0.282352941f, 0.141414141f
141
142 int main(int argc, char *argv[])
143@@ -105,8 +105,7 @@
144 return 2;
145 }
146
147- float const opacity = mir_eglapp_background_opacity;
148- glClearColor(MID_AUBERGINE(opacity), opacity);
149+ glClearColor(MID_AUBERGINE, mir_eglapp_background_opacity);
150 glViewport(0, 0, width, height);
151
152 glUseProgram(prog);
153
154=== modified file 'src/server/compositor/gl_renderer.cpp'
155--- src/server/compositor/gl_renderer.cpp 2014-06-18 12:50:31 +0000
156+++ src/server/compositor/gl_renderer.cpp 2014-07-09 06:44:55 +0000
157@@ -64,7 +64,7 @@
158 "varying vec2 v_texcoord;\n"
159 "void main() {\n"
160 " vec4 frag = texture2D(tex, v_texcoord);\n"
161- " gl_FragColor = alpha*frag;\n"
162+ " gl_FragColor = vec4(frag.xyz, frag.a * alpha);\n"
163 "}\n"
164 };
165 }
166@@ -125,7 +125,7 @@
167 if (renderable.shaped() || renderable.alpha() < 1.0f)
168 {
169 glEnable(GL_BLEND);
170- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
171+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
172 }
173 else
174 {
175
176=== modified file 'tests/unit-tests/compositor/test_gl_renderer.cpp'
177--- tests/unit-tests/compositor/test_gl_renderer.cpp 2014-06-18 12:50:31 +0000
178+++ tests/unit-tests/compositor/test_gl_renderer.cpp 2014-07-09 06:44:55 +0000
179@@ -183,7 +183,7 @@
180 EXPECT_CALL(*renderable, shaped())
181 .WillOnce(Return(true));
182 EXPECT_CALL(mock_gl, glEnable(GL_BLEND));
183- EXPECT_CALL(mock_gl, glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
184+ EXPECT_CALL(mock_gl, glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
185 EXPECT_CALL(mock_gl, glActiveTexture(GL_TEXTURE0));
186
187 EXPECT_CALL(mock_gl, glUniform2f(centre_uniform_location, _, _));

Subscribers

People subscribed via source and target branches