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,
|
||||
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(
|
||||
&mut self,
|
||||
text_runs: Vec<TextRun>,
|
||||
|
@ -92,7 +92,7 @@ pub(crate) trait GenericDrawTarget<B: Backend> {
|
|||
fn fill_rect(
|
||||
&mut self,
|
||||
rect: &Rect<f32>,
|
||||
pattern: B::Pattern<'_>,
|
||||
pattern: &B::Pattern<'_>,
|
||||
draw_options: &B::DrawOptions,
|
||||
);
|
||||
fn get_size(&self) -> Size2D<i32>;
|
||||
|
@ -103,7 +103,7 @@ pub(crate) trait GenericDrawTarget<B: Backend> {
|
|||
fn stroke(
|
||||
&mut self,
|
||||
path: &B::Path,
|
||||
pattern: B::Pattern<'_>,
|
||||
pattern: &B::Pattern<'_>,
|
||||
stroke_options: &B::StrokeOptions,
|
||||
draw_options: &B::DrawOptions,
|
||||
);
|
||||
|
@ -111,14 +111,14 @@ pub(crate) trait GenericDrawTarget<B: Backend> {
|
|||
&mut self,
|
||||
start: Point2D<f32>,
|
||||
end: Point2D<f32>,
|
||||
pattern: B::Pattern<'_>,
|
||||
pattern: &B::Pattern<'_>,
|
||||
stroke_options: &B::StrokeOptions,
|
||||
draw_options: &B::DrawOptions,
|
||||
);
|
||||
fn stroke_rect(
|
||||
&mut self,
|
||||
rect: &Rect<f32>,
|
||||
pattern: B::Pattern<'_>,
|
||||
pattern: &B::Pattern<'_>,
|
||||
stroke_options: &B::StrokeOptions,
|
||||
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| {
|
||||
new_draw_target.fill_rect(
|
||||
&draw_rect,
|
||||
self.state.fill_style.clone(),
|
||||
&self.state.fill_style,
|
||||
&self.state.draw_options,
|
||||
);
|
||||
});
|
||||
} else {
|
||||
self.drawtarget.fill_rect(
|
||||
&draw_rect,
|
||||
self.state.fill_style.clone(),
|
||||
&self.state.draw_options,
|
||||
);
|
||||
self.drawtarget
|
||||
.fill_rect(&draw_rect, &self.state.fill_style, &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| {
|
||||
new_draw_target.stroke_rect(
|
||||
rect,
|
||||
self.state.stroke_style.clone(),
|
||||
&self.state.stroke_style,
|
||||
&self.state.stroke_opts,
|
||||
&self.state.draw_options,
|
||||
);
|
||||
|
@ -802,14 +799,14 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
|||
self.drawtarget.stroke_line(
|
||||
rect.origin,
|
||||
rect.bottom_right(),
|
||||
self.state.stroke_style.clone(),
|
||||
&self.state.stroke_style,
|
||||
&stroke_opts,
|
||||
&self.state.draw_options,
|
||||
);
|
||||
} else {
|
||||
self.drawtarget.stroke_rect(
|
||||
rect,
|
||||
self.state.stroke_style.clone(),
|
||||
&self.state.stroke_style,
|
||||
&self.state.stroke_opts,
|
||||
&self.state.draw_options,
|
||||
);
|
||||
|
@ -892,7 +889,7 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
|||
|
||||
self.drawtarget.fill(
|
||||
&path,
|
||||
self.state.fill_style.clone(),
|
||||
&self.state.fill_style,
|
||||
&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());
|
||||
|
||||
self.drawtarget.fill(
|
||||
&path,
|
||||
self.state.fill_style.clone(),
|
||||
&self.state.draw_options,
|
||||
);
|
||||
self.drawtarget
|
||||
.fill(&path, &self.state.fill_style, &self.state.draw_options);
|
||||
}
|
||||
|
||||
pub(crate) fn stroke(&mut self) {
|
||||
|
@ -922,7 +916,7 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
|||
|
||||
self.drawtarget.stroke(
|
||||
&path,
|
||||
self.state.stroke_style.clone(),
|
||||
&self.state.stroke_style,
|
||||
&self.state.stroke_opts,
|
||||
&self.state.draw_options,
|
||||
);
|
||||
|
@ -937,7 +931,7 @@ impl<'a, B: Backend> CanvasData<'a, B> {
|
|||
|
||||
self.drawtarget.stroke(
|
||||
&path,
|
||||
self.state.stroke_style.clone(),
|
||||
&self.state.stroke_style,
|
||||
&self.state.stroke_opts,
|
||||
&self.state.draw_options,
|
||||
);
|
||||
|
|
|
@ -375,7 +375,7 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
|||
let mut options = raqote::DrawOptions::new();
|
||||
options.blend_mode = raqote::BlendMode::Clear;
|
||||
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)]
|
||||
fn copy_surface(
|
||||
|
@ -448,7 +448,12 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
|||
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(
|
||||
&self,
|
||||
|
@ -464,13 +469,13 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
|||
fn fill(
|
||||
&mut self,
|
||||
path: &<RaqoteBackend as Backend>::Path,
|
||||
pattern: <RaqoteBackend as Backend>::Pattern<'_>,
|
||||
pattern: &<RaqoteBackend as Backend>::Pattern<'_>,
|
||||
draw_options: &<RaqoteBackend as Backend>::DrawOptions,
|
||||
) {
|
||||
match draw_options.blend_mode {
|
||||
raqote::BlendMode::Src => {
|
||||
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::SrcAtop |
|
||||
|
@ -479,7 +484,7 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
|||
raqote::BlendMode::Xor |
|
||||
raqote::BlendMode::DstOver |
|
||||
raqote::BlendMode::SrcOver => {
|
||||
self.fill(path, &source(&pattern), draw_options);
|
||||
self.fill(path, &source(pattern), draw_options);
|
||||
},
|
||||
raqote::BlendMode::SrcIn |
|
||||
raqote::BlendMode::SrcOut |
|
||||
|
@ -488,7 +493,7 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
|||
let mut options = *draw_options;
|
||||
self.push_layer_with_blend(1., options.blend_mode);
|
||||
options.blend_mode = raqote::BlendMode::SrcOver;
|
||||
self.fill(path, &source(&pattern), &options);
|
||||
self.fill(path, &source(pattern), &options);
|
||||
self.pop_layer();
|
||||
},
|
||||
_ => warn!("unrecognized blend mode: {:?}", draw_options.blend_mode),
|
||||
|
@ -558,7 +563,7 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
|||
fn fill_rect(
|
||||
&mut self,
|
||||
rect: &Rect<f32>,
|
||||
pattern: <RaqoteBackend as Backend>::Pattern<'_>,
|
||||
pattern: &<RaqoteBackend as Backend>::Pattern<'_>,
|
||||
draw_options: &<RaqoteBackend as Backend>::DrawOptions,
|
||||
) {
|
||||
let mut pb = raqote::PathBuilder::new();
|
||||
|
@ -592,17 +597,17 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
|||
fn stroke(
|
||||
&mut self,
|
||||
path: &<RaqoteBackend as Backend>::Path,
|
||||
pattern: Pattern<'_>,
|
||||
pattern: &Pattern<'_>,
|
||||
stroke_options: &<RaqoteBackend as Backend>::StrokeOptions,
|
||||
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(
|
||||
&mut self,
|
||||
start: Point2D<f32>,
|
||||
end: Point2D<f32>,
|
||||
pattern: <RaqoteBackend as Backend>::Pattern<'_>,
|
||||
pattern: &<RaqoteBackend as Backend>::Pattern<'_>,
|
||||
stroke_options: &<RaqoteBackend as Backend>::StrokeOptions,
|
||||
draw_options: &<RaqoteBackend as Backend>::DrawOptions,
|
||||
) {
|
||||
|
@ -618,7 +623,7 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
|||
|
||||
self.stroke(
|
||||
&pb.finish(),
|
||||
&source(&pattern),
|
||||
&source(pattern),
|
||||
&stroke_options,
|
||||
draw_options,
|
||||
);
|
||||
|
@ -626,7 +631,7 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
|||
fn stroke_rect(
|
||||
&mut self,
|
||||
rect: &Rect<f32>,
|
||||
pattern: <RaqoteBackend as Backend>::Pattern<'_>,
|
||||
pattern: &<RaqoteBackend as Backend>::Pattern<'_>,
|
||||
stroke_options: &<RaqoteBackend as Backend>::StrokeOptions,
|
||||
draw_options: &<RaqoteBackend as Backend>::DrawOptions,
|
||||
) {
|
||||
|
@ -638,12 +643,7 @@ impl GenericDrawTarget<RaqoteBackend> for raqote::DrawTarget {
|
|||
rect.size.height,
|
||||
);
|
||||
|
||||
self.stroke(
|
||||
&pb.finish(),
|
||||
&source(&pattern),
|
||||
stroke_options,
|
||||
draw_options,
|
||||
);
|
||||
self.stroke(&pb.finish(), &source(pattern), stroke_options, draw_options);
|
||||
}
|
||||
#[allow(unsafe_code)]
|
||||
fn bytes(&self) -> Cow<[u8]> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue