Auto merge of #20923 - jdm:canvas-source, r=avadacatavra

Respect the source rectangle when drawing a canvas to another canvas.

This allows us to run the three.js examples without panicking, since they use self-drawing canvases to scroll the FPS graph.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] There are tests for these changes

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20923)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-06-07 17:37:03 -04:00 committed by GitHub
commit 40f7da0aac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 8 deletions

View file

@ -96,20 +96,20 @@ impl<'a> CanvasData<'a> {
// In this case source and target are the same canvas
let image_data = self.read_pixels(source_rect.to_i32(), image_size);
let writer = |draw_target: &DrawTarget| {
write_image(draw_target, image_data, source_rect.size, dest_rect,
smoothing_enabled, self.state.draw_options.composition,
self.state.draw_options.alpha);
};
if self.need_to_draw_shadow() {
let rect = Rect::new(Point2D::new(dest_rect.origin.x as f32, dest_rect.origin.y as f32),
Size2D::new(dest_rect.size.width as f32, dest_rect.size.height as f32));
self.draw_with_shadow(&rect, |new_draw_target: &DrawTarget| {
write_image(&new_draw_target, image_data, source_rect.size, dest_rect,
smoothing_enabled, self.state.draw_options.composition,
self.state.draw_options.alpha);
});
self.draw_with_shadow(&rect, writer);
} else {
// Writes on target canvas
write_image(&self.drawtarget, image_data, image_size, dest_rect,
smoothing_enabled, self.state.draw_options.composition,
self.state.draw_options.alpha);
writer(&self.drawtarget);
}
}