Skip to content
Permalink
Browse files

Use push_layer_with_blend() only when necessary

push_layer_with_blend() comes at a performance cost, so we only use it
on blend modes that require it.
  • Loading branch information
pylbrecht committed Dec 3, 2019
1 parent a02daef commit 04e9523e5f9cdc19b7116dae4f3ad6110f1e65a6
Showing with 36 additions and 5 deletions.
  1. +36 −5 components/canvas/raqote_backend.rs
@@ -329,11 +329,42 @@ impl GenericDrawTarget for raqote::DrawTarget {
warn!("no support for drawing shadows");
}
fn fill(&mut self, path: &Path, pattern: Pattern, draw_options: &DrawOptions) {
let mut options = draw_options.as_raqote().clone();
self.push_layer_with_blend(1., options.blend_mode);
options.blend_mode = raqote::BlendMode::SrcOver;
self.fill(path.as_raqote(), pattern.as_raqote(), &options);
self.pop_layer();
match draw_options.as_raqote().blend_mode {
raqote::BlendMode::Src => {
self.clear(raqote::SolidSource::from_unpremultiplied_argb(0, 0, 0, 0));
self.fill(
path.as_raqote(),
pattern.as_raqote(),
draw_options.as_raqote(),
);
},
raqote::BlendMode::SrcAtop |
raqote::BlendMode::DstOut |
raqote::BlendMode::Add |
raqote::BlendMode::Xor |
raqote::BlendMode::DstOver |
raqote::BlendMode::SrcOver => {
self.fill(
path.as_raqote(),
pattern.as_raqote(),
draw_options.as_raqote(),
);
},
raqote::BlendMode::SrcIn |
raqote::BlendMode::SrcOut |
raqote::BlendMode::DstIn |
raqote::BlendMode::DstAtop => {
let mut options = draw_options.as_raqote().clone();
self.push_layer_with_blend(1., options.blend_mode);
options.blend_mode = raqote::BlendMode::SrcOver;
self.fill(path.as_raqote(), pattern.as_raqote(), &options);
self.pop_layer();
},
_ => warn!(
"unrecognized blend mode: {:?}",
draw_options.as_raqote().blend_mode
),
}
}
fn fill_rect(
&mut self,

0 comments on commit 04e9523

Please sign in to comment.
You can’t perform that action at this time.