From cc3ed89e34f2866abc1649c823e8b32838ffeeee Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 28 Jul 2024 20:10:56 +0200 Subject: [PATCH] gpu: Draw proper shadows again The fix in commit 5e7f227d broke shadows while trying to make them faster. So use a better way to make them faster. With the normalized blur radius, we can now conclude that all the values too far from p.y will cause the gauss() call to return close to 0, so we can skip any y value that is too far from p.y. And that allows us to put an upper limit on the loop iterations. Tests included Fixes #6888 --- gsk/gpu/shaders/gskgpuboxshadow.glsl | 8 +++++--- ...set-shadow-corner-blur-huge-nocairo-nogl.node | 10 ++++++++++ ...tset-shadow-corner-blur-huge-nocairo-nogl.png | Bin 0 -> 112 bytes .../gsk/compare/outset-shadow-corner-blur.node | 7 +++++++ .../gsk/compare/outset-shadow-corner-blur.png | Bin 0 -> 4192 bytes testsuite/gsk/meson.build | 2 ++ 6 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 testsuite/gsk/compare/outset-shadow-corner-blur-huge-nocairo-nogl.node create mode 100644 testsuite/gsk/compare/outset-shadow-corner-blur-huge-nocairo-nogl.png create mode 100644 testsuite/gsk/compare/outset-shadow-corner-blur.node create mode 100644 testsuite/gsk/compare/outset-shadow-corner-blur.png diff --git a/gsk/gpu/shaders/gskgpuboxshadow.glsl b/gsk/gpu/shaders/gskgpuboxshadow.glsl index b5b7b99290..f74cc78734 100644 --- a/gsk/gpu/shaders/gskgpuboxshadow.glsl +++ b/gsk/gpu/shaders/gskgpuboxshadow.glsl @@ -114,13 +114,15 @@ blur_corner (vec2 p, p /= _sigma; r /= _sigma; float result = 0.0; - float step = max (1.0, r.y / 8.0); - for (float y = 0.5 * step; y <= r.y; y += step) + float start = max (p.y - 3.0, 0.0); + float end = min (p.y + 3.0, r.y); + float step = (end - start) / 7.0; + for (float y = start; y <= end; y += step) { float x = r.x - ellipse_x (r, r.y - y); result -= gauss (p.y - y, 1.0) * erf_range (vec2 (- p.x, x - p.x), 1.0); } - return result; + return step * result; } float diff --git a/testsuite/gsk/compare/outset-shadow-corner-blur-huge-nocairo-nogl.node b/testsuite/gsk/compare/outset-shadow-corner-blur-huge-nocairo-nogl.node new file mode 100644 index 0000000000..054c3d3ce2 --- /dev/null +++ b/testsuite/gsk/compare/outset-shadow-corner-blur-huge-nocairo-nogl.node @@ -0,0 +1,10 @@ +clip { + clip: 1400 1400 20 20; + child: color-matrix { + matrix: matrix3d(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255); + child: outset-shadow { + blur: 1000; + outline: 0 0 1000 1000 / 1000 0 1000 0; + } + } +} diff --git a/testsuite/gsk/compare/outset-shadow-corner-blur-huge-nocairo-nogl.png b/testsuite/gsk/compare/outset-shadow-corner-blur-huge-nocairo-nogl.png new file mode 100644 index 0000000000000000000000000000000000000000..02d28f5626ee0000a6cedb62ea58b80d947feec0 GIT binary patch literal 112 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAj3?#R^_xk}U#^NA%Cx&(BWL^R}EXkhE0gSv1 zjB_%rjevaS0G|+7AiccG_7;%h_H=O!;gC&U0Fnz}V0<5^`X0z)@O1TaS?83{1OR`Q B7Zd;h literal 0 HcmV?d00001 diff --git a/testsuite/gsk/compare/outset-shadow-corner-blur.node b/testsuite/gsk/compare/outset-shadow-corner-blur.node new file mode 100644 index 0000000000..ac1bd33bd7 --- /dev/null +++ b/testsuite/gsk/compare/outset-shadow-corner-blur.node @@ -0,0 +1,7 @@ +clip { + clip: 0 0 15 15; + child: outset-shadow { + blur: 10; + outline: 0 0 100 100 / 100 0 100 0; + } +} diff --git a/testsuite/gsk/compare/outset-shadow-corner-blur.png b/testsuite/gsk/compare/outset-shadow-corner-blur.png new file mode 100644 index 0000000000000000000000000000000000000000..781abc4fd4a28137e8e126be8b4da52937edcdbe GIT binary patch literal 4192 zcmeHKYitx%6rNHkrC2B}sTBmq0b>DY=drup&d{Zl-O?_&rIZa&AF+34?rsNmXO^95 zciW;;6a?c71!D+^D56k{Mq47jp<>i1pduwa6s1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