Pass a Rect instead of an Option<Rect> to PutImageData

This commit is contained in:
David Zbarsky 2015-08-08 04:50:55 -04:00
parent 78792cced2
commit 48c24f8492
3 changed files with 5 additions and 14 deletions

View file

@ -594,7 +594,7 @@ impl<'a> CanvasPaintTask<'a> {
fn put_image_data(&mut self, mut imagedata: Vec<u8>,
image_data_rect: Rect<f64>,
dirty_rect: Option<Rect<f64>>) {
dirty_rect: Rect<f64>) {
if image_data_rect.size.width <= 0.0 || image_data_rect.size.height <= 0.0 {
return
@ -604,18 +604,9 @@ impl<'a> CanvasPaintTask<'a> {
// rgba -> bgra
byte_swap(&mut imagedata);
let image_rect = Rect::new(Point2D::zero(),
Size2D::new(image_data_rect.size.width, image_data_rect.size.height));
// Dirty rectangle defines the area of the source image to be copied
// on the destination canvas
let source_rect = match dirty_rect {
Some(dirty_rect) =>
self.calculate_dirty_rect(dirty_rect, image_data_rect),
// If no dirty area is provided we consider the whole source image
// as the area to be copied to the canvas
None => image_rect,
};
let source_rect = self.calculate_dirty_rect(dirty_rect, image_data_rect);
// 5) If either dirtyWidth or dirtyHeight is negative or zero,
// stop without affecting any bitmaps

View file

@ -91,7 +91,7 @@ pub enum Canvas2dMsg {
GetImageData(Rect<f64>, Size2D<f64>, IpcSender<Vec<u8>>),
LineTo(Point2D<f32>),
MoveTo(Point2D<f32>),
PutImageData(Vec<u8>, Rect<f64>, Option<Rect<f64>>),
PutImageData(Vec<u8>, Rect<f64>, Rect<f64>),
QuadraticCurveTo(Point2D<f32>, Point2D<f32>),
Rect(Rect<f32>),
RestoreContext,

View file

@ -929,8 +929,8 @@ impl<'a> CanvasRenderingContext2DMethods for &'a CanvasRenderingContext2D {
let image_data_rect = Rect::new(Point2D::new(*dx, *dy),
Size2D::new(imagedata.Width() as f64,
imagedata.Height() as f64));
let dirty_rect = Some(Rect::new(Point2D::new(*dirtyX, *dirtyY),
Size2D::new(*dirtyWidth, *dirtyHeight)));
let dirty_rect = Rect::new(Point2D::new(*dirtyX, *dirtyY),
Size2D::new(*dirtyWidth, *dirtyHeight));
let msg = CanvasMsg::Canvas2d(Canvas2dMsg::PutImageData(data, image_data_rect, dirty_rect));
self.ipc_renderer.send(msg).unwrap();
self.mark_as_dirty();