Skip to content

libbreezecommon: Use closed-form rectangle blur instead of box blur

Tatsuyuki Ishi requested to merge ishitatsuyuki/breeze:blur into master

f1e4f103 ("[libbreezecommon] Use box blur instead of FFT blur") introduced the current 3-pass separable box blur method for shadows, replacing the extremely slow FFT method. It gave a sizable performance improvement, but the box blur method was designed for blurring arbitrary images, and in case of fixed shapes like rectangles, we can do a lot better by using a more specific solution.

This change replaces the shadow blurring method with a closed-form solution of blurred rectangles [1]. It calculates the alpha value for each pixel in constant time, at a high accuracy (~0.1% error), and without any intermediate memory access. This change also fuses computation for multiple shadows so that they don't need to render to an intermediate framebuffer.

The tradeoff is that rounded corners are ignored with this method due to mathematical complexity. Overall, it should still be a good approximation since the corner radius is much smaller than the blur radius.

With the speed improvement, blurs should block the main thread less and in turn make KWin (and MDI applications) more responsive.

[1] http://madebyevan.com/shaders/fast-rounded-rectangle-shadows/

Merge request reports