Skip to content

Commit 1c00279

Browse files
tcl3gmta
authored andcommitted
LibWeb: Reset Painter when resetting canvas to its initial state
1 parent 017e8a5 commit 1c00279

File tree

7 files changed

+119
-1
lines changed

7 files changed

+119
-1
lines changed

Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,10 @@ void CanvasRenderingContext2D::reset_to_default_state()
634634
// 4. Reset everything that drawing state consists of to their initial values.
635635
reset_drawing_state();
636636

637-
if (surface)
637+
if (surface) {
638+
painter()->reset();
638639
did_draw(surface->rect().to_type<float>());
640+
}
639641
}
640642

641643
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-measuretext
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
4+
<title>Canvas test: 2d.reset.state.clip</title>
5+
<h1>2d.reset.state.clip</h1>
6+
<p class="desc">check that the clip is reset</p>
7+
<canvas id="canvas" width="200" height="200">
8+
<p class="fallback">FAIL (fallback content)</p>
9+
</canvas>
10+
<script>
11+
const canvas = document.getElementById("canvas");
12+
const ctx = canvas.getContext('2d');
13+
14+
ctx.fillRect(0, 0, 200, 200);
15+
</script>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
4+
<link rel="match" href="../../../../../../expected/wpt-import/html/canvas/element/reset/2d.reset.state.clip-expected.html">
5+
<title>Canvas test: 2d.reset.state.clip</title>
6+
<h1>2d.reset.state.clip</h1>
7+
<p class="desc">check that the clip is reset</p>
8+
<canvas id="canvas" width="200" height="200">
9+
<p class="fallback">FAIL (fallback content)</p>
10+
</canvas>
11+
<script>
12+
const canvas = document.getElementById("canvas");
13+
const ctx = canvas.getContext('2d');
14+
15+
ctx.beginPath();
16+
ctx.rect(0, 0, 100, 100);
17+
ctx.clip();
18+
19+
ctx.fillRect(0, 0, 200, 200);
20+
21+
ctx.reset();
22+
23+
ctx.fillRect(0, 0, 200, 200);
24+
</script>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Harness status: OK
2+
3+
Found 1 tests
4+
5+
1 Pass
6+
Pass Resetting the canvas state resets the current clip region
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Harness status: OK
2+
3+
Found 1 tests
4+
5+
1 Pass
6+
Pass Resetting the canvas state resets the current transformation matrix
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
4+
<title>Canvas test: 2d.canvas.host.initial.reset.clip</title>
5+
<script src="../../../../resources/testharness.js"></script>
6+
<script src="../../../../resources/testharnessreport.js"></script>
7+
<script src="../../../../html/canvas/resources/canvas-tests.js"></script>
8+
<link rel="stylesheet" href="../../../../html/canvas/resources/canvas-tests.css">
9+
<body class="show_output">
10+
11+
<h1>2d.canvas.host.initial.reset.clip</h1>
12+
<p class="desc">Resetting the canvas state resets the current clip region</p>
13+
14+
15+
<p class="output">Actual output:</p>
16+
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
17+
18+
<ul id="d"></ul>
19+
<script>
20+
var t = async_test("Resetting the canvas state resets the current clip region");
21+
_addTest(function(canvas, ctx) {
22+
23+
canvas.width = 100;
24+
ctx.rect(0, 0, 1, 1);
25+
ctx.clip();
26+
canvas.width = 100;
27+
ctx.fillStyle = '#0f0';
28+
ctx.fillRect(0, 0, 100, 50);
29+
_assertPixel(canvas, 20,20, 0,255,0,255);
30+
31+
});
32+
</script>
33+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
4+
<title>Canvas test: 2d.canvas.host.initial.reset.transform</title>
5+
<script src="../../../../resources/testharness.js"></script>
6+
<script src="../../../../resources/testharnessreport.js"></script>
7+
<script src="../../../../html/canvas/resources/canvas-tests.js"></script>
8+
<link rel="stylesheet" href="../../../../html/canvas/resources/canvas-tests.css">
9+
<body class="show_output">
10+
11+
<h1>2d.canvas.host.initial.reset.transform</h1>
12+
<p class="desc">Resetting the canvas state resets the current transformation matrix</p>
13+
14+
15+
<p class="output">Actual output:</p>
16+
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
17+
18+
<ul id="d"></ul>
19+
<script>
20+
var t = async_test("Resetting the canvas state resets the current transformation matrix");
21+
_addTest(function(canvas, ctx) {
22+
23+
canvas.width = 100;
24+
ctx.scale(0.1, 0.1);
25+
canvas.width = 100;
26+
ctx.fillStyle = '#0f0';
27+
ctx.fillRect(0, 0, 100, 50);
28+
_assertPixel(canvas, 20,20, 0,255,0,255);
29+
30+
});
31+
</script>
32+

0 commit comments

Comments
 (0)