mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Reset Painter when resetting canvas to its initial state
This commit is contained in:
parent
017e8a5b8d
commit
1c00279488
Notes:
github-actions[bot]
2025-10-23 16:53:42 +00:00
Author: https://github.com/tcl3
Commit: 1c00279488
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6536
Reviewed-by: https://github.com/gmta ✅
7 changed files with 119 additions and 1 deletions
|
|
@ -634,8 +634,10 @@ void CanvasRenderingContext2D::reset_to_default_state()
|
||||||
// 4. Reset everything that drawing state consists of to their initial values.
|
// 4. Reset everything that drawing state consists of to their initial values.
|
||||||
reset_drawing_state();
|
reset_drawing_state();
|
||||||
|
|
||||||
if (surface)
|
if (surface) {
|
||||||
|
painter()->reset();
|
||||||
did_draw(surface->rect().to_type<float>());
|
did_draw(surface->rect().to_type<float>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-measuretext
|
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-measuretext
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Canvas test: 2d.reset.state.clip</title>
|
||||||
|
<h1>2d.reset.state.clip</h1>
|
||||||
|
<p class="desc">check that the clip is reset</p>
|
||||||
|
<canvas id="canvas" width="200" height="200">
|
||||||
|
<p class="fallback">FAIL (fallback content)</p>
|
||||||
|
</canvas>
|
||||||
|
<script>
|
||||||
|
const canvas = document.getElementById("canvas");
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
|
ctx.fillRect(0, 0, 200, 200);
|
||||||
|
</script>
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<link rel="match" href="../../../../../../expected/wpt-import/html/canvas/element/reset/2d.reset.state.clip-expected.html">
|
||||||
|
<title>Canvas test: 2d.reset.state.clip</title>
|
||||||
|
<h1>2d.reset.state.clip</h1>
|
||||||
|
<p class="desc">check that the clip is reset</p>
|
||||||
|
<canvas id="canvas" width="200" height="200">
|
||||||
|
<p class="fallback">FAIL (fallback content)</p>
|
||||||
|
</canvas>
|
||||||
|
<script>
|
||||||
|
const canvas = document.getElementById("canvas");
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.rect(0, 0, 100, 100);
|
||||||
|
ctx.clip();
|
||||||
|
|
||||||
|
ctx.fillRect(0, 0, 200, 200);
|
||||||
|
|
||||||
|
ctx.reset();
|
||||||
|
|
||||||
|
ctx.fillRect(0, 0, 200, 200);
|
||||||
|
</script>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
Harness status: OK
|
||||||
|
|
||||||
|
Found 1 tests
|
||||||
|
|
||||||
|
1 Pass
|
||||||
|
Pass Resetting the canvas state resets the current clip region
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
Harness status: OK
|
||||||
|
|
||||||
|
Found 1 tests
|
||||||
|
|
||||||
|
1 Pass
|
||||||
|
Pass Resetting the canvas state resets the current transformation matrix
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Canvas test: 2d.canvas.host.initial.reset.clip</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.canvas.host.initial.reset.clip</h1>
|
||||||
|
<p class="desc">Resetting the canvas state resets the current clip region</p>
|
||||||
|
|
||||||
|
|
||||||
|
<p class="output">Actual output:</p>
|
||||||
|
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
|
||||||
|
|
||||||
|
<ul id="d"></ul>
|
||||||
|
<script>
|
||||||
|
var t = async_test("Resetting the canvas state resets the current clip region");
|
||||||
|
_addTest(function(canvas, ctx) {
|
||||||
|
|
||||||
|
canvas.width = 100;
|
||||||
|
ctx.rect(0, 0, 1, 1);
|
||||||
|
ctx.clip();
|
||||||
|
canvas.width = 100;
|
||||||
|
ctx.fillStyle = '#0f0';
|
||||||
|
ctx.fillRect(0, 0, 100, 50);
|
||||||
|
_assertPixel(canvas, 20,20, 0,255,0,255);
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
@ -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.canvas.host.initial.reset.transform</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.canvas.host.initial.reset.transform</h1>
|
||||||
|
<p class="desc">Resetting the canvas state resets the current transformation matrix</p>
|
||||||
|
|
||||||
|
|
||||||
|
<p class="output">Actual output:</p>
|
||||||
|
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
|
||||||
|
|
||||||
|
<ul id="d"></ul>
|
||||||
|
<script>
|
||||||
|
var t = async_test("Resetting the canvas state resets the current transformation matrix");
|
||||||
|
_addTest(function(canvas, ctx) {
|
||||||
|
|
||||||
|
canvas.width = 100;
|
||||||
|
ctx.scale(0.1, 0.1);
|
||||||
|
canvas.width = 100;
|
||||||
|
ctx.fillStyle = '#0f0';
|
||||||
|
ctx.fillRect(0, 0, 100, 50);
|
||||||
|
_assertPixel(canvas, 20,20, 0,255,0,255);
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue