LibWeb: Don't draw shadows if shadow offset and blur are not set

This commit is contained in:
Tim Ledbetter 2025-10-21 10:22:49 +01:00 committed by Jelle Raaijmakers
parent eb44cca5bd
commit 13f551612c
Notes: github-actions[bot] 2025-10-21 16:56:48 +00:00
4 changed files with 48 additions and 6 deletions

View file

@ -1064,6 +1064,8 @@ void CanvasRenderingContext2D::paint_shadow_for_fill_internal(Gfx::Path const& p
return;
auto& state = this->drawing_state();
if (state.shadow_blur == 0.0f && state.shadow_offset_x == 0.0f && state.shadow_offset_y == 0.0f)
return;
if (state.current_compositing_and_blending_operator == Gfx::CompositingAndBlendingOperator::Copy)
return;
@ -1098,6 +1100,9 @@ void CanvasRenderingContext2D::paint_shadow_for_stroke_internal(Gfx::Path const&
if (state.current_compositing_and_blending_operator == Gfx::CompositingAndBlendingOperator::Copy)
return;
if (state.shadow_blur == 0.0f && state.shadow_offset_x == 0.0f && state.shadow_offset_y == 0.0f)
return;
auto alpha = state.global_alpha * (state.shadow_color.alpha() / 255.0f);
auto fill_style_color = state.fill_style.as_color();
if (fill_style_color.has_value() && fill_style_color->alpha() > 0)

View file

@ -2,19 +2,19 @@ Harness status: OK
Found 15 tests
8 Pass
7 Fail
12 Pass
3 Fail
Pass globalCompositeOperation clear
Pass globalCompositeOperation copy
Fail globalCompositeOperation destination
Pass globalCompositeOperation source-over
Pass globalCompositeOperation destination-over
Fail globalCompositeOperation source-in
Fail globalCompositeOperation destination-in
Fail globalCompositeOperation source-out
Pass globalCompositeOperation source-in
Pass globalCompositeOperation destination-in
Pass globalCompositeOperation source-out
Pass globalCompositeOperation destination-out
Pass globalCompositeOperation source-atop
Fail globalCompositeOperation destination-atop
Pass globalCompositeOperation destination-atop
Pass globalCompositeOperation xor
Fail globalCompositeOperation lighter
Fail globalCompositeOperation plus-darker

View file

@ -0,0 +1,6 @@
Harness status: OK
Found 1 tests
1 Pass
Pass Shadows are not drawn when only shadowColor is set

View file

@ -0,0 +1,31 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<title>Canvas test: 2d.shadow.enable.off.2</title>
<script src="../../../../resources/testharness.js"></script>
<script src="../../../../resources/testharnessreport.js"></script>
<script src="../../../../html/canvas/resources/canvas-tests.js"></script>
<link rel="stylesheet" href="../../../../html/canvas/resources/canvas-tests.css">
<body class="show_output">
<h1>2d.shadow.enable.off.2</h1>
<p class="desc">Shadows are not drawn when only shadowColor is set</p>
<p class="output">Actual output:</p>
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
<p class="output expectedtext">Expected output:<p><img src="../../../../images/green-100x50.png" class="output expected" id="expected" alt="">
<ul id="d"></ul>
<script>
var t = async_test("Shadows are not drawn when only shadowColor is set");
_addTest(function(canvas, ctx) {
ctx.globalCompositeOperation = 'destination-atop';
ctx.shadowColor = '#f00';
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
_assertPixel(canvas, 50,25, 0,255,0,255);
});
</script>