From 3f496f8225204a60334181adc2b422a96f4ccf59 Mon Sep 17 00:00:00 2001 From: Andrei Volykhin Date: Tue, 24 Jun 2025 14:09:25 +0300 Subject: [PATCH] canvas: Reset the current path on canvas context resetting (#37671) Follow the HTML canvas specification and empty the list of subpaths in context's current default path (step 2) on canvas context reseting (reset() or set bitmap dimestion). https://html.spec.whatwg.org/multipage/#reset-the-rendering-context-to-its-default-state Testing: Improvements in the tests - html/canvas/element/canvas-host/2d.canvas.host.initial.reset.path.html - html/canvas/offscreen/canvas-host/2d.canvas.host.initial.reset.path* Signed-off-by: Andrei Volykhin --- components/canvas/canvas_data.rs | 14 +++++++++++++- .../2d.canvas.host.initial.reset.path.html.ini | 3 --- .../2d.canvas.host.initial.reset.path.html.ini | 3 --- ...2d.canvas.host.initial.reset.path.worker.js.ini | 3 --- 4 files changed, 13 insertions(+), 10 deletions(-) delete mode 100644 tests/wpt/meta/html/canvas/element/canvas-host/2d.canvas.host.initial.reset.path.html.ini delete mode 100644 tests/wpt/meta/html/canvas/offscreen/canvas-host/2d.canvas.host.initial.reset.path.html.ini delete mode 100644 tests/wpt/meta/html/canvas/offscreen/canvas-host/2d.canvas.host.initial.reset.path.worker.js.ini diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index 7d90742f3a8..dbde4bd408c 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -1185,15 +1185,27 @@ impl<'a, B: Backend> CanvasData<'a, B> { self.backend.set_global_composition(op, &mut self.state); } + /// pub(crate) fn recreate(&mut self, size: Option>) { let size = size .unwrap_or_else(|| self.drawtarget.get_size().to_u64()) .max(MIN_WR_IMAGE_SIZE); + + // Step 1. Clear canvas's bitmap to transparent black. self.drawtarget = self .backend .create_drawtarget(Size2D::new(size.width, size.height)); - self.state = self.backend.new_paint_state(); + + // Step 2. Empty the list of subpaths in context's current default path. + self.path_state = None; + + // Step 3. Clear the context's drawing state stack. self.saved_states.clear(); + + // Step 4. Reset everything that drawing state consists of to their + // initial values. + self.state = self.backend.new_paint_state(); + self.update_image_rendering(); } diff --git a/tests/wpt/meta/html/canvas/element/canvas-host/2d.canvas.host.initial.reset.path.html.ini b/tests/wpt/meta/html/canvas/element/canvas-host/2d.canvas.host.initial.reset.path.html.ini deleted file mode 100644 index e12e364d828..00000000000 --- a/tests/wpt/meta/html/canvas/element/canvas-host/2d.canvas.host.initial.reset.path.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[2d.canvas.host.initial.reset.path.html] - [Resetting the canvas state resets the current path] - expected: FAIL diff --git a/tests/wpt/meta/html/canvas/offscreen/canvas-host/2d.canvas.host.initial.reset.path.html.ini b/tests/wpt/meta/html/canvas/offscreen/canvas-host/2d.canvas.host.initial.reset.path.html.ini deleted file mode 100644 index e12e364d828..00000000000 --- a/tests/wpt/meta/html/canvas/offscreen/canvas-host/2d.canvas.host.initial.reset.path.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[2d.canvas.host.initial.reset.path.html] - [Resetting the canvas state resets the current path] - expected: FAIL diff --git a/tests/wpt/meta/html/canvas/offscreen/canvas-host/2d.canvas.host.initial.reset.path.worker.js.ini b/tests/wpt/meta/html/canvas/offscreen/canvas-host/2d.canvas.host.initial.reset.path.worker.js.ini deleted file mode 100644 index d37d5bc29d9..00000000000 --- a/tests/wpt/meta/html/canvas/offscreen/canvas-host/2d.canvas.host.initial.reset.path.worker.js.ini +++ /dev/null @@ -1,3 +0,0 @@ -[2d.canvas.host.initial.reset.path.worker.html] - [Resetting the canvas state resets the current path] - expected: FAIL