From 86ce20dca3e73d97ce141df52129e0c4a9caf985 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 25 Mar 2015 09:48:32 +0100 Subject: [PATCH 1/3] Fix indentation in canvas_paint_task. --- components/canvas/canvas_paint_task.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/components/canvas/canvas_paint_task.rs b/components/canvas/canvas_paint_task.rs index 4822fd48750..262b85aa65b 100644 --- a/components/canvas/canvas_paint_task.rs +++ b/components/canvas/canvas_paint_task.rs @@ -65,9 +65,9 @@ impl<'a> CanvasPaintTask<'a> { let mut src = (src_read_rect.origin.y * stride + src_read_rect.origin.x * 4) as usize; //copy the data to the destination vector for _ in range(0, src_read_rect.size.height) { - let row = &src_data[src .. src + (4 * src_read_rect.size.width) as usize]; - image_data.push_all(row); - src += stride as usize; + let row = &src_data[src .. src + (4 * src_read_rect.size.width) as usize]; + image_data.push_all(row); + src += stride as usize; } image_data @@ -78,30 +78,30 @@ impl<'a> CanvasPaintTask<'a> { /// dest_rect: The area of the canvas where the imagedata will be copied /// smoothing_enabled: if smoothing is applied to the copied pixels fn write_pixels(&self, imagedata: &Vec, - image_size: Size2D, - source_rect: Rect, - dest_rect: Rect, - smoothing_enabled: bool) { + image_size: Size2D, + source_rect: Rect, + dest_rect: Rect, + smoothing_enabled: bool) { // From spec https://html.spec.whatwg.org/multipage/scripting.html#dom-context-2d-drawimage // When scaling up, if the imageSmoothingEnabled attribute is set to true, the user agent should attempt // to apply a smoothing algorithm to the image data when it is scaled. // Otherwise, the image must be rendered using nearest-neighbor interpolation. let filter = if smoothing_enabled { - Filter::Linear + Filter::Linear } else { - Filter::Point + Filter::Point }; let source_surface = self.drawtarget.create_source_surface_from_data(imagedata.as_slice(), - image_size, image_size.width * 4, SurfaceFormat::B8G8R8A8); + image_size, image_size.width * 4, SurfaceFormat::B8G8R8A8); let draw_surface_options = DrawSurfaceOptions::new(filter, true); let draw_options = DrawOptions::new(1.0f64 as AzFloat, 0); self.drawtarget.draw_surface(source_surface, - dest_rect.to_azfloat(), - source_rect.to_azfloat(), - draw_surface_options, draw_options); + dest_rect.to_azfloat(), + source_rect.to_azfloat(), + draw_surface_options, draw_options); } /// dirty_rect: original dirty_rect provided by the putImageData call From cb46a5788dc8fb0257006e21ffeaea6bf86a1826 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 25 Mar 2015 09:48:59 +0100 Subject: [PATCH 2/3] Stop using the deprecated range function in canvas_paint_task. --- components/canvas/canvas_paint_task.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/canvas/canvas_paint_task.rs b/components/canvas/canvas_paint_task.rs index 262b85aa65b..bdc67169a9d 100644 --- a/components/canvas/canvas_paint_task.rs +++ b/components/canvas/canvas_paint_task.rs @@ -64,7 +64,7 @@ impl<'a> CanvasPaintTask<'a> { //start offset of the copyable rectangle let mut src = (src_read_rect.origin.y * stride + src_read_rect.origin.x * 4) as usize; //copy the data to the destination vector - for _ in range(0, src_read_rect.size.height) { + for _ in 0..src_read_rect.size.height { let row = &src_data[src .. src + (4 * src_read_rect.size.width) as usize]; image_data.push_all(row); src += stride as usize; From 6113dd42b1674e1e08288e5b8efaf29606d0aa30 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 25 Mar 2015 09:49:15 +0100 Subject: [PATCH 3/3] Pass a slice to write_pixels. --- components/canvas/canvas_paint_task.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/canvas/canvas_paint_task.rs b/components/canvas/canvas_paint_task.rs index bdc67169a9d..443f70bfcc6 100644 --- a/components/canvas/canvas_paint_task.rs +++ b/components/canvas/canvas_paint_task.rs @@ -77,7 +77,7 @@ impl<'a> CanvasPaintTask<'a> { /// source_rect: the area of the image data to be written /// dest_rect: The area of the canvas where the imagedata will be copied /// smoothing_enabled: if smoothing is applied to the copied pixels - fn write_pixels(&self, imagedata: &Vec, + fn write_pixels(&self, imagedata: &[u8], image_size: Size2D, source_rect: Rect, dest_rect: Rect, @@ -92,7 +92,7 @@ impl<'a> CanvasPaintTask<'a> { Filter::Point }; - let source_surface = self.drawtarget.create_source_surface_from_data(imagedata.as_slice(), + let source_surface = self.drawtarget.create_source_surface_from_data(imagedata, image_size, image_size.width * 4, SurfaceFormat::B8G8R8A8); let draw_surface_options = DrawSurfaceOptions::new(filter, true);