LibWeb: Don't paint canvas objects with non-visible fill styles

This commit is contained in:
Tim Ledbetter 2025-10-25 23:34:02 +01:00 committed by Jelle Raaijmakers
parent 01947ded23
commit 9dceb06992
Notes: github-actions[bot] 2025-10-26 15:46:43 +00:00
3 changed files with 48 additions and 9 deletions

View file

@ -373,6 +373,9 @@ void CanvasRenderingContext2D::stroke_internal(Gfx::Path const& path)
return;
auto& state = drawing_state();
auto paint_style = state.stroke_style.to_gfx_paint_style();
if (!paint_style->is_visible())
return;
auto line_cap = to_gfx_cap(state.line_cap);
auto line_join = to_gfx_join(state.line_join);
@ -384,7 +387,7 @@ void CanvasRenderingContext2D::stroke_internal(Gfx::Path const& path)
dash_array.append(static_cast<float>(dash));
}
paint_shadow_for_stroke_internal(path, line_cap, line_join, dash_array);
painter->stroke_path(path, state.stroke_style.to_gfx_paint_style(), state.filter, state.line_width, state.global_alpha, state.current_compositing_and_blending_operator, line_cap, line_join, state.miter_limit, dash_array, state.line_dash_offset);
painter->stroke_path(path, paint_style, state.filter, state.line_width, state.global_alpha, state.current_compositing_and_blending_operator, line_cap, line_join, state.miter_limit, dash_array, state.line_dash_offset);
did_draw(path.bounding_box());
}
@ -415,10 +418,14 @@ void CanvasRenderingContext2D::fill_internal(Gfx::Path const& path, Gfx::Winding
if (!painter)
return;
auto& state = this->drawing_state();
auto paint_style = state.fill_style.to_gfx_paint_style();
if (!paint_style->is_visible())
return;
paint_shadow_for_fill_internal(path, winding_rule);
auto& state = this->drawing_state();
painter->fill_path(path, state.fill_style.to_gfx_paint_style(), state.filter, state.global_alpha, state.current_compositing_and_blending_operator, winding_rule);
painter->fill_path(path, paint_style, state.filter, state.global_alpha, state.current_compositing_and_blending_operator, winding_rule);
did_draw(path.bounding_box());
}
@ -1072,9 +1079,6 @@ void CanvasRenderingContext2D::paint_shadow_for_fill_internal(Gfx::Path const& p
if (state.current_compositing_and_blending_operator == Gfx::CompositingAndBlendingOperator::Copy)
return;
if (!state.fill_style.to_gfx_paint_style()->is_visible())
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)
@ -1109,9 +1113,6 @@ void CanvasRenderingContext2D::paint_shadow_for_stroke_internal(Gfx::Path const&
if (state.shadow_blur == 0.0f && state.shadow_offset_x == 0.0f && state.shadow_offset_y == 0.0f)
return;
if (!state.stroke_style.to_gfx_paint_style()->is_visible())
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

@ -0,0 +1,6 @@
Harness status: OK
Found 1 tests
1 Pass
Pass Canvas test: 2d.gradient.empty

View file

@ -0,0 +1,32 @@
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<meta charset="UTF-8">
<title>Canvas test: 2d.gradient.empty</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.gradient.empty</h1>
<p class="desc"></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("");
_addTest(function(canvas, ctx) {
ctx.fillStyle = '#0f0';
ctx.fillRect(0, 0, 100, 50);
var g = ctx.createLinearGradient(0, 0, 0, 50);
ctx.fillStyle = g;
ctx.fillRect(0, 0, 100, 50);
_assertPixelApprox(canvas, 50,25, 0,255,0,255, 2);
});
</script>