gl-renderer: simplify main() in frag

By moving the application of view_alpha after pre-multiplication we can
simplify main() considerably.

The cost is that for straight-alpha input or color_pipeline() we might
be doing three multiplications more than before. However,

 a) the cost of running color_pipeline() probably dominates anyway, and
 b) to get straight-alpha input you have to use a future Wayland
   extension that probably won't be advertised without color management.

So we keep the optimization for the simple case (no color management)
while potentially incurring a small cost on the heavy case (with color
management).

Thanks to Pierre-Yves Mordred for the inspiration in
https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/889#note_1411774

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
Pekka Paalanen 2022-06-03 14:15:01 +03:00 committed by Pekka Paalanen
parent 932c374779
commit 57d32722a2

View File

@ -271,24 +271,14 @@ main()
/* Electrical (non-linear) RGBA values, may be premult or not */
color = sample_input_texture();
if (c_need_color_pipeline) {
if (c_need_color_pipeline)
color = color_pipeline(color); /* Produces straight alpha */
color.a *= view_alpha;
/* pre-multiply for blending */
/* Ensure pre-multiplied for blending */
if (!c_input_is_premult || c_need_color_pipeline)
color.rgb *= color.a;
} else {
/* Fast path for disabled color management */
if (c_input_is_premult) {
color *= view_alpha;
} else {
color.a *= view_alpha;
/* pre-multiply for blending */
color.rgb *= color.a;
}
}
if (c_green_tint)
color = vec4(0.0, 0.3, 0.0, 0.2) + color * 0.8;