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>
dev
Pekka Paalanen 2 years ago committed by Pekka Paalanen
parent 932c374779
commit 57d32722a2
  1. 16
      libweston/renderer-gl/fragment.glsl

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

Loading…
Cancel
Save