mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +01:00
canvas2d: Implement .reset()
(#31258)
* Implement Canvas2D reset * Update WPT tests * Apply suggestions from code review --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
29c206a702
commit
b2ae3928ab
106 changed files with 28 additions and 289 deletions
|
@ -1054,7 +1054,8 @@ impl<'a> CanvasData<'a> {
|
|||
self.backend.set_global_composition(op, &mut self.state);
|
||||
}
|
||||
|
||||
pub fn recreate(&mut self, size: Size2D<u64>) {
|
||||
pub fn recreate(&mut self, size: Option<Size2D<u64>>) {
|
||||
let size = size.unwrap_or_else(|| self.drawtarget.get_size().to_u64());
|
||||
self.drawtarget = self
|
||||
.backend
|
||||
.create_drawtarget(Size2D::new(size.width, size.height));
|
||||
|
|
|
@ -216,7 +216,14 @@ impl CanvasState {
|
|||
pub fn set_bitmap_dimensions(&self, size: Size2D<u64>) {
|
||||
self.reset_to_initial_state();
|
||||
self.ipc_renderer
|
||||
.send(CanvasMsg::Recreate(size, self.get_canvas_id()))
|
||||
.send(CanvasMsg::Recreate(Some(size), self.get_canvas_id()))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn reset(&self) {
|
||||
self.reset_to_initial_state();
|
||||
self.ipc_renderer
|
||||
.send(CanvasMsg::Recreate(None, self.get_canvas_id()))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ impl CanvasRenderingContext2D {
|
|||
self.canvas_state
|
||||
.get_ipc_renderer()
|
||||
.send(CanvasMsg::Recreate(
|
||||
size.to_u64(),
|
||||
Some(size.to_u64()),
|
||||
self.canvas_state.get_canvas_id(),
|
||||
))
|
||||
.unwrap();
|
||||
|
@ -181,6 +181,11 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
|||
self.canvas_state.restore()
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#dom-context-2d-reset>
|
||||
fn Reset(&self) {
|
||||
self.canvas_state.reset()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-scale
|
||||
fn Scale(&self, x: f64, y: f64) {
|
||||
self.canvas_state.scale(x, y)
|
||||
|
|
|
@ -213,6 +213,11 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
|
|||
self.canvas_state.restore()
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#dom-context-2d-reset>
|
||||
fn Reset(&self) {
|
||||
self.canvas_state.reset()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalalpha
|
||||
fn GlobalAlpha(&self) -> f64 {
|
||||
self.canvas_state.global_alpha()
|
||||
|
|
|
@ -95,6 +95,11 @@ impl PaintRenderingContext2DMethods for PaintRenderingContext2D {
|
|||
self.context.Restore()
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#dom-context-2d-reset>
|
||||
fn Reset(&self) {
|
||||
self.context.Reset()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-scale
|
||||
fn Scale(&self, x: f64, y: f64) {
|
||||
self.context.Scale(x, y)
|
||||
|
|
|
@ -44,6 +44,7 @@ interface mixin CanvasState {
|
|||
// state
|
||||
undefined save(); // push state on state stack
|
||||
undefined restore(); // pop state stack and restore state
|
||||
undefined reset();
|
||||
};
|
||||
|
||||
interface mixin CanvasTransform {
|
||||
|
|
|
@ -28,7 +28,7 @@ pub enum CanvasMsg {
|
|||
Canvas2d(Canvas2dMsg, CanvasId),
|
||||
FromLayout(FromLayoutMsg, CanvasId),
|
||||
FromScript(FromScriptMsg, CanvasId),
|
||||
Recreate(Size2D<u64>, CanvasId),
|
||||
Recreate(Option<Size2D<u64>>, CanvasId),
|
||||
Close(CanvasId),
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue