mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
canvas: Pass pattern by ref (#37662)
We pass all other options as ref too. Testing: Just refactor, but the code is covered by WPT tests. Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
25fe003af2
commit
e0f3679d55
3 changed files with 34 additions and 40 deletions
|
@ -81,7 +81,7 @@ pub(crate) trait GenericDrawTarget<B: Backend> {
|
||||||
sigma: f32,
|
sigma: f32,
|
||||||
operator: B::CompositionOp,
|
operator: B::CompositionOp,
|
||||||
);
|
);
|
||||||
fn fill(&mut self, path: &B::Path, pattern: B::Pattern<'_>, draw_options: &B::DrawOptions);
|
fn fill(&mut self, path: &B::Path, pattern: &B::Pattern<'_>, draw_options: &B::DrawOptions);
|
||||||
fn fill_text(
|
fn fill_text(
|
||||||
&mut self,
|
&mut self,
|
||||||
text_runs: Vec<TextRun>,
|
text_runs: Vec<TextRun>,
|
||||||
|
@ -92,7 +92,7 @@ pub(crate) trait GenericDrawTarget<B: Backend> {
|
||||||
fn fill_rect(
|
fn fill_rect(
|
||||||
&mut self,
|
&mut self,
|
||||||
rect: &Rect<f32>,
|
rect: &Rect<f32>,
|
||||||
pattern: B::Pattern<'_>,
|
pattern: &B::Pattern<'_>,
|
||||||
draw_options: &B::DrawOptions,
|
draw_options: &B::DrawOptions,
|
||||||
);
|
);
|
||||||
fn get_size(&self) -> Size2D<i32>;
|
fn get_size(&self) -> Size2D<i32>;
|
||||||
|
@ -103,7 +103,7 @@ pub(crate) trait GenericDrawTarget<B: Backend> {
|
||||||
fn stroke(
|
fn stroke(
|
||||||
&mut self,
|
&mut self,
|
||||||
path: &B::Path,
|
path: &B::Path,
|
||||||
pattern: B::Pattern<'_>,
|
pattern: &B::Pattern<'_>,
|
||||||
stroke_options: &B::StrokeOptions,
|
stroke_options: &B::StrokeOptions,
|
||||||
draw_options: &B::DrawOptions,
|
draw_options: &B::DrawOptions,
|
||||||
);
|
);
|
||||||
|
@ -111,14 +111,14 @@ pub(crate) trait GenericDrawTarget<B: Backend> {
|
||||||
&mut self,
|
&mut self,
|
||||||
start: Point2D<f32>,
|
start: Point2D<f32>,
|
||||||
end: Point2D<f32>,
|
end: Point2D<f32>,
|
||||||
pattern: B::Pattern<'_>,
|
pattern: &B::Pattern<'_>,
|
||||||
stroke_options: &B::StrokeOptions,
|
stroke_options: &B::StrokeOptions,
|
||||||
draw_options: &B::DrawOptions,
|
draw_options: &B::DrawOptions,
|
||||||
);
|
);
|
||||||
fn stroke_rect(
|
fn stroke_rect(
|
||||||
&mut self,
|
&mut self,
|
||||||
rect: &Rect<f32>,
|
rect: &Rect<f32>,
|
||||||
pattern: B::Pattern<'_>,
|
pattern: &B::Pattern<'_>,
|
||||||
stroke_options: &B::StrokeOptions,
|
stroke_options: &B::StrokeOptions,
|
||||||
draw_options: &B::DrawOptions,
|
draw_options: &B::DrawOptions,
|
||||||
);
|
);
|
||||||
|
|
|
@ -765,16 +765,13 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
||||||
self.draw_with_shadow(&draw_rect, |new_draw_target: &mut B::DrawTarget| {
|
self.draw_with_shadow(&draw_rect, |new_draw_target: &mut B::DrawTarget| {
|
||||||
new_draw_target.fill_rect(
|
new_draw_target.fill_rect(
|
||||||
&draw_rect,
|
&draw_rect,
|
||||||
self.state.fill_style.clone(),
|
&self.state.fill_style,
|
||||||
&self.state.draw_options,
|
&self.state.draw_options,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
self.drawtarget.fill_rect(
|
self.drawtarget
|
||||||
&draw_rect,
|
.fill_rect(&draw_rect, &self.state.fill_style, &self.state.draw_options);
|
||||||
self.state.fill_style.clone(),
|
|
||||||
&self.state.draw_options,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -791,7 +788,7 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
||||||
self.draw_with_shadow(rect, |new_draw_target: &mut B::DrawTarget| {
|
self.draw_with_shadow(rect, |new_draw_target: &mut B::DrawTarget| {
|
||||||
new_draw_target.stroke_rect(
|
new_draw_target.stroke_rect(
|
||||||
rect,
|
rect,
|
||||||
self.state.stroke_style.clone(),
|
&self.state.stroke_style,
|
||||||
&self.state.stroke_opts,
|
&self.state.stroke_opts,
|
||||||
&self.state.draw_options,
|
&self.state.draw_options,
|
||||||
);
|
);
|
||||||
|
@ -802,14 +799,14 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
||||||
self.drawtarget.stroke_line(
|
self.drawtarget.stroke_line(
|
||||||
rect.origin,
|
rect.origin,
|
||||||
rect.bottom_right(),
|
rect.bottom_right(),
|
||||||
self.state.stroke_style.clone(),
|
&self.state.stroke_style,
|
||||||
&stroke_opts,
|
&stroke_opts,
|
||||||
&self.state.draw_options,
|
&self.state.draw_options,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
self.drawtarget.stroke_rect(
|
self.drawtarget.stroke_rect(
|
||||||
rect,
|
rect,
|
||||||
self.state.stroke_style.clone(),
|
&self.state.stroke_style,
|
||||||
&self.state.stroke_opts,
|
&self.state.stroke_opts,
|
||||||
&self.state.draw_options,
|
&self.state.draw_options,
|
||||||
);
|
);
|
||||||
|
@ -892,7 +889,7 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
||||||
|
|
||||||
self.drawtarget.fill(
|
self.drawtarget.fill(
|
||||||
&path,
|
&path,
|
||||||
self.state.fill_style.clone(),
|
&self.state.fill_style,
|
||||||
&self.state.draw_options.clone(),
|
&self.state.draw_options.clone(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -904,11 +901,8 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
||||||
|
|
||||||
let path = to_path::<B>(path, self.drawtarget.create_path_builder());
|
let path = to_path::<B>(path, self.drawtarget.create_path_builder());
|
||||||
|
|
||||||
self.drawtarget.fill(
|
self.drawtarget
|
||||||
&path,
|
.fill(&path, &self.state.fill_style, &self.state.draw_options);
|
||||||
self.state.fill_style.clone(),
|
|
||||||
&self.state.draw_options,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn stroke(&mut self) {
|
pub(crate) fn stroke(&mut self) {
|
||||||
|
@ -922,7 +916,7 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
||||||
|
|
||||||
self.drawtarget.stroke(
|
self.drawtarget.stroke(
|
||||||
&path,
|
&path,
|
||||||
self.state.stroke_style.clone(),
|
&self.state.stroke_style,
|
||||||
&self.state.stroke_opts,
|
&self.state.stroke_opts,
|
||||||
&self.state.draw_options,
|
&self.state.draw_options,
|
||||||
);
|
);
|
||||||
|
@ -937,7 +931,7 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
||||||
|
|
||||||
self.drawtarget.stroke(
|
self.drawtarget.stroke(
|
||||||
&path,
|
&path,
|
||||||
self.state.stroke_style.clone(),
|
&self.state.stroke_style,
|
||||||
&self.state.stroke_opts,
|
&self.state.stroke_opts,
|
||||||
&self.state.draw_options,
|
&self.state.draw_options,
|
||||||
);
|
);
|
||||||
|
|
|
@ -375,7 +375,7 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
||||||
let mut options = raqote::DrawOptions::new();
|
let mut options = raqote::DrawOptions::new();
|
||||||
options.blend_mode = raqote::BlendMode::Clear;
|
options.blend_mode = raqote::BlendMode::Clear;
|
||||||
let pattern = Pattern::Color(0, 0, 0, 0);
|
let pattern = Pattern::Color(0, 0, 0, 0);
|
||||||
<Self as GenericDrawTarget<RaqoteBackend>>::fill(self, &pb.finish(), pattern, &options);
|
<Self as GenericDrawTarget<RaqoteBackend>>::fill(self, &pb.finish(), &pattern, &options);
|
||||||
}
|
}
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn copy_surface(
|
fn copy_surface(
|
||||||
|
@ -448,7 +448,12 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
||||||
dest.size.height as f32,
|
dest.size.height as f32,
|
||||||
);
|
);
|
||||||
|
|
||||||
<Self as GenericDrawTarget<RaqoteBackend>>::fill(self, &pb.finish(), pattern, draw_options);
|
<Self as GenericDrawTarget<RaqoteBackend>>::fill(
|
||||||
|
self,
|
||||||
|
&pb.finish(),
|
||||||
|
&pattern,
|
||||||
|
draw_options,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
fn draw_surface_with_shadow(
|
fn draw_surface_with_shadow(
|
||||||
&self,
|
&self,
|
||||||
|
@ -464,13 +469,13 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
||||||
fn fill(
|
fn fill(
|
||||||
&mut self,
|
&mut self,
|
||||||
path: &<RaqoteBackend as Backend>::Path,
|
path: &<RaqoteBackend as Backend>::Path,
|
||||||
pattern: <RaqoteBackend as Backend>::Pattern<'_>,
|
pattern: &<RaqoteBackend as Backend>::Pattern<'_>,
|
||||||
draw_options: &<RaqoteBackend as Backend>::DrawOptions,
|
draw_options: &<RaqoteBackend as Backend>::DrawOptions,
|
||||||
) {
|
) {
|
||||||
match draw_options.blend_mode {
|
match draw_options.blend_mode {
|
||||||
raqote::BlendMode::Src => {
|
raqote::BlendMode::Src => {
|
||||||
self.clear(raqote::SolidSource::from_unpremultiplied_argb(0, 0, 0, 0));
|
self.clear(raqote::SolidSource::from_unpremultiplied_argb(0, 0, 0, 0));
|
||||||
self.fill(path, &source(&pattern), draw_options);
|
self.fill(path, &source(pattern), draw_options);
|
||||||
},
|
},
|
||||||
raqote::BlendMode::Clear |
|
raqote::BlendMode::Clear |
|
||||||
raqote::BlendMode::SrcAtop |
|
raqote::BlendMode::SrcAtop |
|
||||||
|
@ -479,7 +484,7 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
||||||
raqote::BlendMode::Xor |
|
raqote::BlendMode::Xor |
|
||||||
raqote::BlendMode::DstOver |
|
raqote::BlendMode::DstOver |
|
||||||
raqote::BlendMode::SrcOver => {
|
raqote::BlendMode::SrcOver => {
|
||||||
self.fill(path, &source(&pattern), draw_options);
|
self.fill(path, &source(pattern), draw_options);
|
||||||
},
|
},
|
||||||
raqote::BlendMode::SrcIn |
|
raqote::BlendMode::SrcIn |
|
||||||
raqote::BlendMode::SrcOut |
|
raqote::BlendMode::SrcOut |
|
||||||
|
@ -488,7 +493,7 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
||||||
let mut options = *draw_options;
|
let mut options = *draw_options;
|
||||||
self.push_layer_with_blend(1., options.blend_mode);
|
self.push_layer_with_blend(1., options.blend_mode);
|
||||||
options.blend_mode = raqote::BlendMode::SrcOver;
|
options.blend_mode = raqote::BlendMode::SrcOver;
|
||||||
self.fill(path, &source(&pattern), &options);
|
self.fill(path, &source(pattern), &options);
|
||||||
self.pop_layer();
|
self.pop_layer();
|
||||||
},
|
},
|
||||||
_ => warn!("unrecognized blend mode: {:?}", draw_options.blend_mode),
|
_ => warn!("unrecognized blend mode: {:?}", draw_options.blend_mode),
|
||||||
|
@ -558,7 +563,7 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
||||||
fn fill_rect(
|
fn fill_rect(
|
||||||
&mut self,
|
&mut self,
|
||||||
rect: &Rect<f32>,
|
rect: &Rect<f32>,
|
||||||
pattern: <RaqoteBackend as Backend>::Pattern<'_>,
|
pattern: &<RaqoteBackend as Backend>::Pattern<'_>,
|
||||||
draw_options: &<RaqoteBackend as Backend>::DrawOptions,
|
draw_options: &<RaqoteBackend as Backend>::DrawOptions,
|
||||||
) {
|
) {
|
||||||
let mut pb = raqote::PathBuilder::new();
|
let mut pb = raqote::PathBuilder::new();
|
||||||
|
@ -592,17 +597,17 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
||||||
fn stroke(
|
fn stroke(
|
||||||
&mut self,
|
&mut self,
|
||||||
path: &<RaqoteBackend as Backend>::Path,
|
path: &<RaqoteBackend as Backend>::Path,
|
||||||
pattern: Pattern<'_>,
|
pattern: &Pattern<'_>,
|
||||||
stroke_options: &<RaqoteBackend as Backend>::StrokeOptions,
|
stroke_options: &<RaqoteBackend as Backend>::StrokeOptions,
|
||||||
draw_options: &<RaqoteBackend as Backend>::DrawOptions,
|
draw_options: &<RaqoteBackend as Backend>::DrawOptions,
|
||||||
) {
|
) {
|
||||||
self.stroke(path, &source(&pattern), stroke_options, draw_options);
|
self.stroke(path, &source(pattern), stroke_options, draw_options);
|
||||||
}
|
}
|
||||||
fn stroke_line(
|
fn stroke_line(
|
||||||
&mut self,
|
&mut self,
|
||||||
start: Point2D<f32>,
|
start: Point2D<f32>,
|
||||||
end: Point2D<f32>,
|
end: Point2D<f32>,
|
||||||
pattern: <RaqoteBackend as Backend>::Pattern<'_>,
|
pattern: &<RaqoteBackend as Backend>::Pattern<'_>,
|
||||||
stroke_options: &<RaqoteBackend as Backend>::StrokeOptions,
|
stroke_options: &<RaqoteBackend as Backend>::StrokeOptions,
|
||||||
draw_options: &<RaqoteBackend as Backend>::DrawOptions,
|
draw_options: &<RaqoteBackend as Backend>::DrawOptions,
|
||||||
) {
|
) {
|
||||||
|
@ -618,7 +623,7 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
||||||
|
|
||||||
self.stroke(
|
self.stroke(
|
||||||
&pb.finish(),
|
&pb.finish(),
|
||||||
&source(&pattern),
|
&source(pattern),
|
||||||
&stroke_options,
|
&stroke_options,
|
||||||
draw_options,
|
draw_options,
|
||||||
);
|
);
|
||||||
|
@ -626,7 +631,7 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
||||||
fn stroke_rect(
|
fn stroke_rect(
|
||||||
&mut self,
|
&mut self,
|
||||||
rect: &Rect<f32>,
|
rect: &Rect<f32>,
|
||||||
pattern: <RaqoteBackend as Backend>::Pattern<'_>,
|
pattern: &<RaqoteBackend as Backend>::Pattern<'_>,
|
||||||
stroke_options: &<RaqoteBackend as Backend>::StrokeOptions,
|
stroke_options: &<RaqoteBackend as Backend>::StrokeOptions,
|
||||||
draw_options: &<RaqoteBackend as Backend>::DrawOptions,
|
draw_options: &<RaqoteBackend as Backend>::DrawOptions,
|
||||||
) {
|
) {
|
||||||
|
@ -638,12 +643,7 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
||||||
rect.size.height,
|
rect.size.height,
|
||||||
);
|
);
|
||||||
|
|
||||||
self.stroke(
|
self.stroke(&pb.finish(), &source(pattern), stroke_options, draw_options);
|
||||||
&pb.finish(),
|
|
||||||
&source(&pattern),
|
|
||||||
stroke_options,
|
|
||||||
draw_options,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn bytes(&self) -> Cow<[u8]> {
|
fn bytes(&self) -> Cow<[u8]> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue