From b43c5c30e39e75850e408c8d8f30f55c18e536a7 Mon Sep 17 00:00:00 2001 From: pylbrecht Date: Tue, 2 Jul 2019 19:14:15 +0200 Subject: [PATCH] WIP: Make GenericPathBuilder's methods take &mut self --- components/canvas/canvas_data.rs | 26 +++-- components/canvas/raqote_backend.rs | 144 ++++++++++++++-------------- 2 files changed, 88 insertions(+), 82 deletions(-) diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index c1f539a909f0..9152dff6dbd8 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -215,7 +215,12 @@ impl<'a> PathBuilderRef<'a> { // The prototypes are derived from azure's methods. pub trait GenericDrawTarget { fn clear_rect(&self, rect: &Rect); - fn copy_surface(&self, surface: SourceSurface, source: Rect, destination: Point2D); + fn copy_surface( + &mut self, + surface: SourceSurface, + source: Rect, + destination: Point2D, + ); fn create_gradient_stops( &self, gradient_stops: Vec, @@ -250,24 +255,24 @@ pub trait GenericDrawTarget { sigma: f32, operator: CompositionOp, ); - fn fill(&self, path: &Path, pattern: Pattern, draw_options: &DrawOptions); - fn fill_rect(&self, rect: &Rect, pattern: Pattern, draw_options: Option<&DrawOptions>); + fn fill(&mut self, path: &Path, pattern: Pattern, draw_options: &DrawOptions); + fn fill_rect(&mut self, rect: &Rect, pattern: Pattern, draw_options: Option<&DrawOptions>); fn get_format(&self) -> SurfaceFormat; fn get_size(&self) -> Size2D; fn get_transform(&self) -> Transform2D; - fn pop_clip(&self); - fn push_clip(&self, path: &Path); - fn set_transform(&self, matrix: &Transform2D); + fn pop_clip(&mut self); + fn push_clip(&mut self, path: &Path); + fn set_transform(&mut self, matrix: &Transform2D); fn snapshot(&self) -> SourceSurface; fn stroke( - &self, + &mut self, path: &Path, pattern: Pattern, stroke_options: &StrokeOptions, draw_options: &DrawOptions, ); fn stroke_line( - &self, + &mut self, start: Point2D, end: Point2D, pattern: Pattern, @@ -275,7 +280,7 @@ pub trait GenericDrawTarget { draw_options: &DrawOptions, ); fn stroke_rect( - &self, + &mut self, rect: &Rect, pattern: Pattern, stroke_options: &StrokeOptions, @@ -659,7 +664,8 @@ impl<'a> CanvasData<'a> { pub fn clip(&mut self) { self.ensure_path(); - self.drawtarget.push_clip(&self.path()); + let path = self.path(); + self.drawtarget.push_clip(&path); } pub fn is_point_in_path( diff --git a/components/canvas/raqote_backend.rs b/components/canvas/raqote_backend.rs index 831ce1b945f6..d49716dc6a26 100644 --- a/components/canvas/raqote_backend.rs +++ b/components/canvas/raqote_backend.rs @@ -143,129 +143,129 @@ impl Path { } impl GenericDrawTarget for raqote::DrawTarget { - fn clear_rect(&self, _rect: &Rect) { - unimplemented!() + fn clear_rect(&self, rect: &Rect) { + unimplemented!(); } - fn copy_surface( - &self, - _surface: SourceSurface, - _source: Rect, - _destination: Point2D, + &mut self, + surface: SourceSurface, + source: Rect, + destination: Point2D, ) { - unimplemented!() + unimplemented!(); } - fn create_gradient_stops( &self, - _gradient_stops: Vec, - _extend_mode: ExtendMode, + gradient_stops: Vec, + extend_mode: ExtendMode, ) -> GradientStops { - unimplemented!() + unimplemented!(); } fn create_path_builder(&self) -> Box { - unimplemented!() + unimplemented!(); } - fn create_similar_draw_target( &self, - _size: &Size2D, - _format: SurfaceFormat, + size: &Size2D, + format: SurfaceFormat, ) -> Box { - unimplemented!() + unimplemented!(); } fn create_source_surface_from_data( &self, - _data: &[u8], - _size: Size2D, - _stride: i32, + data: &[u8], + size: Size2D, + stride: i32, ) -> Option { - unimplemented!() + unimplemented!(); } fn draw_surface( &self, - _surface: SourceSurface, - _dest: Rect, - _source: Rect, - _filter: Filter, - _draw_options: &DrawOptions, + surface: SourceSurface, + dest: Rect, + source: Rect, + filter: Filter, + draw_options: &DrawOptions, ) { - unimplemented!() + unimplemented!(); } fn draw_surface_with_shadow( &self, - _surface: SourceSurface, - _dest: &Point2D, - _color: &Color, - _offset: &Vector2D, - _sigma: f32, - _operator: CompositionOp, + surface: SourceSurface, + dest: &Point2D, + color: &Color, + offset: &Vector2D, + sigma: f32, + operator: CompositionOp, ) { - unimplemented!() + unimplemented!(); } - fn fill(&self, _path: &Path, _pattern: Pattern, _draw_options: &DrawOptions) { - unimplemented!() + fn fill(&mut self, path: &Path, pattern: Pattern, draw_options: &DrawOptions) { + unimplemented!(); } - fn fill_rect(&self, _rect: &Rect, _pattern: Pattern, _draw_options: Option<&DrawOptions>) { - unimplemented!() + fn fill_rect( + &mut self, + rect: &Rect, + pattern: Pattern, + draw_options: Option<&DrawOptions>, + ) { + unimplemented!(); } fn get_format(&self) -> SurfaceFormat { - unimplemented!() + unimplemented!(); } fn get_size(&self) -> Size2D { - unimplemented!() + unimplemented!(); } fn get_transform(&self) -> Transform2D { - unimplemented!() + unimplemented!(); } - fn pop_clip(&self) { - unimplemented!() + fn pop_clip(&mut self) { + unimplemented!(); } - fn push_clip(&self, _path: &Path) { - unimplemented!() + fn push_clip(&mut self, path: &Path) { + unimplemented!(); } - fn set_transform(&self, _matrix: &Transform2D) { - unimplemented!() + fn set_transform(&mut self, matrix: &Transform2D) { + unimplemented!(); } fn snapshot(&self) -> SourceSurface { - unimplemented!() + unimplemented!(); } fn stroke( - &self, - _path: &Path, - _pattern: Pattern, - _stroke_options: &StrokeOptions, - _draw_options: &DrawOptions, + &mut self, + path: &Path, + pattern: Pattern, + stroke_options: &StrokeOptions, + draw_options: &DrawOptions, ) { - unimplemented!() + unimplemented!(); } fn stroke_line( - &self, - _start: Point2D, - _end: Point2D, - _pattern: Pattern, - _stroke_options: &StrokeOptions, - _draw_options: &DrawOptions, + &mut self, + start: Point2D, + end: Point2D, + pattern: Pattern, + stroke_options: &StrokeOptions, + draw_options: &DrawOptions, ) { - unimplemented!() + unimplemented!(); } fn stroke_rect( - &self, - _rect: &Rect, - _pattern: Pattern, - _stroke_options: &StrokeOptions<'_>, - _draw_options: &DrawOptions, + &mut self, + rect: &Rect, + pattern: Pattern, + stroke_options: &StrokeOptions, + draw_options: &DrawOptions, ) { - unimplemented!() + unimplemented!(); } - - fn snapshot_data(&self, _f: &dyn Fn(&[u8]) -> Vec) -> Vec { - unimplemented!() + fn snapshot_data(&self, f: &Fn(&[u8]) -> Vec) -> Vec { + unimplemented!(); } - fn snapshot_data_owned(&self) -> Vec { - unimplemented!() + unimplemented!(); } }