mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
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 <andrei.volykhin@gmail.com>
This commit is contained in:
parent
fc20d8b2e1
commit
3f496f8225
4 changed files with 13 additions and 10 deletions
|
@ -1185,15 +1185,27 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
|||
self.backend.set_global_composition(op, &mut self.state);
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#reset-the-rendering-context-to-its-default-state>
|
||||
pub(crate) fn recreate(&mut self, size: Option<Size2D<u64>>) {
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue