diff --git a/components/canvas/azure_backend.rs b/components/canvas/azure_backend.rs index 57e53e6ab7e..905e4ee8f46 100644 --- a/components/canvas/azure_backend.rs +++ b/components/canvas/azure_backend.rs @@ -18,6 +18,8 @@ use canvas_traits::canvas::*; use cssparser::RGBA; use euclid::default::{Point2D, Rect, Size2D, Transform2D, Vector2D}; +use std::marker::PhantomData; + pub struct AzureBackend; impl Backend for AzureBackend { @@ -31,7 +33,7 @@ impl Backend for AzureBackend { fn size_from_pattern(&self, rect: &Rect, pattern: &Pattern) -> Option> { match pattern { - Pattern::Azure(azure_hl::Pattern::Surface(ref surface)) => { + Pattern::Azure(azure_hl::Pattern::Surface(ref surface), _) => { let surface_size = surface.size(); let size = match (surface.repeat_x, surface.repeat_y) { (true, true) => rect.size, @@ -43,7 +45,7 @@ impl Backend for AzureBackend { }; Some(size) }, - Pattern::Azure(_) => None, + Pattern::Azure(..) => None, } } @@ -58,7 +60,7 @@ impl Backend for AzureBackend { drawtarget: &dyn GenericDrawTarget, ) { if let Some(pattern) = style.to_azure_pattern(drawtarget) { - state.fill_style = Pattern::Azure(pattern) + state.fill_style = Pattern::Azure(pattern, PhantomData::default()) } } @@ -69,7 +71,7 @@ impl Backend for AzureBackend { drawtarget: &dyn GenericDrawTarget, ) { if let Some(pattern) = style.to_azure_pattern(drawtarget) { - state.stroke_style = Pattern::Azure(pattern) + state.stroke_style = Pattern::Azure(pattern, PhantomData::default()) } } @@ -108,12 +110,14 @@ impl<'a> CanvasPaintState<'a> { azure_hl::CompositionOp::Over, antialias.into_azure(), )), - fill_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new( - azure_hl::Color::black(), - ))), - stroke_style: Pattern::Azure(azure_hl::Pattern::Color(ColorPattern::new( - azure_hl::Color::black(), - ))), + fill_style: Pattern::Azure( + azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black())), + PhantomData::default(), + ), + stroke_style: Pattern::Azure( + azure_hl::Pattern::Color(ColorPattern::new(azure_hl::Color::black())), + PhantomData::default(), + ), stroke_opts: StrokeOptions::Azure(azure_hl::StrokeOptions::new( 1.0, JoinStyle::MiterOrBevel, @@ -132,14 +136,15 @@ impl<'a> CanvasPaintState<'a> { impl GenericPathBuilder for azure_hl::PathBuilder { fn arc( - &self, + &mut self, origin: Point2D, radius: f32, start_angle: f32, end_angle: f32, anticlockwise: bool, ) { - self.arc( + azure_hl::PathBuilder::arc( + self, origin as Point2D, radius as AzFloat, start_angle as AzFloat, @@ -148,22 +153,23 @@ impl GenericPathBuilder for azure_hl::PathBuilder { ); } fn bezier_curve_to( - &self, + &mut self, control_point1: &Point2D, control_point2: &Point2D, control_point3: &Point2D, ) { - self.bezier_curve_to( + azure_hl::PathBuilder::bezier_curve_to( + self, control_point1 as &Point2D, control_point2 as &Point2D, control_point3 as &Point2D, ); } - fn close(&self) { - self.close(); + fn close(&mut self) { + azure_hl::PathBuilder::close(self); } fn ellipse( - &self, + &mut self, origin: Point2D, radius_x: f32, radius_y: f32, @@ -172,7 +178,8 @@ impl GenericPathBuilder for azure_hl::PathBuilder { end_angle: f32, anticlockwise: bool, ) { - self.ellipse( + azure_hl::PathBuilder::ellipse( + self, origin as Point2D, radius_x as AzFloat, radius_y as AzFloat, @@ -182,34 +189,40 @@ impl GenericPathBuilder for azure_hl::PathBuilder { anticlockwise, ); } - fn get_current_point(&self) -> Point2D { - let AzPoint { x, y } = self.get_current_point(); + fn get_current_point(&mut self) -> Point2D { + let AzPoint { x, y } = azure_hl::PathBuilder::get_current_point(self); Point2D::new(x as f32, y as f32) } - fn line_to(&self, point: Point2D) { - self.line_to(point as Point2D); + fn line_to(&mut self, point: Point2D) { + azure_hl::PathBuilder::line_to(self, point as Point2D); } - fn move_to(&self, point: Point2D) { - self.move_to(point as Point2D); + fn move_to(&mut self, point: Point2D) { + azure_hl::PathBuilder::move_to(self, point as Point2D); } - fn quadratic_curve_to(&self, control_point: &Point2D, end_point: &Point2D) { - self.quadratic_curve_to( + fn quadratic_curve_to(&mut self, control_point: &Point2D, end_point: &Point2D) { + azure_hl::PathBuilder::quadratic_curve_to( + self, control_point as &Point2D, end_point as &Point2D, ); } - fn finish(&self) -> Path { - Path::Azure(self.finish()) + fn finish(&mut self) -> Path { + Path::Azure(azure_hl::PathBuilder::finish(self)) } } impl GenericDrawTarget for azure_hl::DrawTarget { - fn clear_rect(&self, rect: &Rect) { - self.clear_rect(rect as &Rect); + fn clear_rect(&mut self, rect: &Rect) { + azure_hl::DrawTarget::clear_rect(self, rect as &Rect); } - fn copy_surface(&self, surface: SourceSurface, source: Rect, destination: Point2D) { - self.copy_surface(surface.into_azure(), source, destination); + fn copy_surface( + &mut self, + surface: SourceSurface, + source: Rect, + destination: Point2D, + ) { + azure_hl::DrawTarget::copy_surface(self, surface.into_azure(), source, destination); } fn create_gradient_stops( @@ -282,15 +295,22 @@ impl GenericDrawTarget for azure_hl::DrawTarget { operator.into_azure(), ); } - fn fill(&self, path: &Path, pattern: Pattern, draw_options: &DrawOptions) { - self.fill( + fn fill(&mut self, path: &Path, pattern: Pattern, draw_options: &DrawOptions) { + azure_hl::DrawTarget::fill( + self, path.as_azure(), pattern.as_azure().to_pattern_ref(), draw_options.as_azure(), ); } - fn fill_rect(&self, rect: &Rect, pattern: Pattern, draw_options: Option<&DrawOptions>) { - self.fill_rect( + fn fill_rect( + &mut self, + rect: &Rect, + pattern: Pattern, + draw_options: Option<&DrawOptions>, + ) { + azure_hl::DrawTarget::fill_rect( + self, rect as &Rect, pattern.as_azure().to_pattern_ref(), draw_options.map(|x| x.as_azure()), @@ -306,26 +326,27 @@ impl GenericDrawTarget for azure_hl::DrawTarget { fn get_transform(&self) -> Transform2D { self.get_transform() as Transform2D } - fn pop_clip(&self) { - self.pop_clip(); + fn pop_clip(&mut self) { + azure_hl::DrawTarget::pop_clip(self); } - fn push_clip(&self, path: &Path) { - self.push_clip(path.as_azure()); + fn push_clip(&mut self, path: &Path) { + azure_hl::DrawTarget::push_clip(self, path.as_azure()); } - fn set_transform(&self, matrix: &Transform2D) { - self.set_transform(matrix as &Transform2D); + fn set_transform(&mut self, matrix: &Transform2D) { + azure_hl::DrawTarget::set_transform(self, matrix as &Transform2D); } fn snapshot(&self) -> SourceSurface { SourceSurface::Azure(self.snapshot()) } fn stroke( - &self, + &mut self, path: &Path, pattern: Pattern, stroke_options: &StrokeOptions, draw_options: &DrawOptions, ) { - self.stroke( + azure_hl::DrawTarget::stroke( + self, path.as_azure(), pattern.as_azure().to_pattern_ref(), stroke_options.as_azure(), @@ -333,7 +354,7 @@ impl GenericDrawTarget for azure_hl::DrawTarget { ); } fn stroke_line( - &self, + &mut self, start: Point2D, end: Point2D, pattern: Pattern, @@ -354,7 +375,8 @@ impl GenericDrawTarget for azure_hl::DrawTarget { stroke_options.mDashPattern, ); - self.stroke_line( + azure_hl::DrawTarget::stroke_line( + self, start, end, pattern.as_azure().to_pattern_ref(), @@ -363,13 +385,14 @@ impl GenericDrawTarget for azure_hl::DrawTarget { ); } fn stroke_rect( - &self, + &mut self, rect: &Rect, pattern: Pattern, stroke_options: &StrokeOptions, draw_options: &DrawOptions, ) { - self.stroke_rect( + azure_hl::DrawTarget::stroke_rect( + self, rect as &Rect, pattern.as_azure().to_pattern_ref(), stroke_options.as_azure(), @@ -469,10 +492,10 @@ impl Path { } } -impl Pattern { +impl Pattern<'_> { fn as_azure(&self) -> &azure_hl::Pattern { match self { - Pattern::Azure(p) => p, + Pattern::Azure(p, _) => p, } } } @@ -723,10 +746,10 @@ impl ToAzureStyle for RGBA { } } -impl Pattern { +impl Pattern<'_> { pub fn is_zero_size_gradient(&self) -> bool { match *self { - Pattern::Azure(azure_hl::Pattern::LinearGradient(ref gradient)) => { + Pattern::Azure(azure_hl::Pattern::LinearGradient(ref gradient), _) => { gradient.is_zero_size() }, _ => false, diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index 9eb9eb55889..3f66525b7c0 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -354,7 +354,7 @@ pub enum Path { #[derive(Clone)] pub enum Pattern<'a> { #[cfg(feature = "canvas2d-azure")] - Azure(azure::azure_hl::Pattern), + Azure(azure::azure_hl::Pattern, PhantomData<&'a ()>), #[cfg(feature = "canvas2d-raqote")] Raqote(raqote::Source<'a>), }