From 892edc0048dfad28342e5e2ff247c963eb91ed11 Mon Sep 17 00:00:00 2001 From: hashcatHitman <155700084+hashcatHitman@users.noreply.github.com> Date: Sun, 1 Jun 2025 16:08:17 -0400 Subject: [PATCH] Size2D -> Size2D in canvas_traits::canvas::Canvas2dMsg Changed the variants `canvas_traits::canvas::Canvas2dMsg::DrawEmptyImage` and `canvas_traits::canvas::Canvas2dMsg::DrawImageInOther` to use `euclid::default::Size2D` instead of `euclid::default::Size2D`. Every other change made in this commit is either: - of similar nature, and is the minimum that would allow compilation - resolving lints triggered by the former This commit includes changes to the following components: - canvas - script - shared/canvas Signed-off-by: hashcatHitman <155700084+hashcatHitman@users.noreply.github.com> --- components/canvas/canvas_paint_thread.rs | 4 ++-- components/script/canvas_state.rs | 28 ++++++++++++------------ components/shared/canvas/canvas.rs | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/components/canvas/canvas_paint_thread.rs b/components/canvas/canvas_paint_thread.rs index d225335bf7b..93aff081c35 100644 --- a/components/canvas/canvas_paint_thread.rs +++ b/components/canvas/canvas_paint_thread.rs @@ -187,7 +187,7 @@ impl<'a> CanvasPaintThread<'a> { Canvas2dMsg::DrawEmptyImage(image_size, dest_rect, source_rect) => { self.canvas(canvas_id).draw_image( &vec![0; image_size.area() as usize * 4], - image_size.to_u32(), + image_size, dest_rect, source_rect, false, @@ -203,7 +203,7 @@ impl<'a> CanvasPaintThread<'a> { ) => { let image_data = self .canvas(canvas_id) - .read_pixels(Some(source_rect.to_u32()), Some(image_size.to_u32())); + .read_pixels(Some(source_rect.to_u32()), Some(image_size)); self.canvas(other_canvas_id).draw_image( image_data.data(), source_rect.size.to_u32(), diff --git a/components/script/canvas_state.rs b/components/script/canvas_state.rs index c48f41060a2..139579d2045 100644 --- a/components/script/canvas_state.rs +++ b/components/script/canvas_state.rs @@ -531,11 +531,11 @@ impl CanvasState { }; // Step 4. Establish the source and destination rectangles. - let video_size = snapshot.size().to_f64(); - let dw = dw.unwrap_or(video_size.width); - let dh = dh.unwrap_or(video_size.height); - let sw = sw.unwrap_or(video_size.width); - let sh = sh.unwrap_or(video_size.height); + let video_size = snapshot.size(); + let dw = dw.unwrap_or(video_size.width as f64); + let dh = dh.unwrap_or(video_size.height as f64); + let sw = sw.unwrap_or(video_size.width as f64); + let sh = sh.unwrap_or(video_size.height as f64); let (source_rect, dest_rect) = self.adjust_source_dest_rects(video_size, sx, sy, sw, sh, dx, dy, dw, dh); @@ -577,7 +577,7 @@ impl CanvasState { let sw = sw.unwrap_or(canvas_size.width as f64); let sh = sh.unwrap_or(canvas_size.height as f64); - let image_size = Size2D::new(canvas_size.width as f64, canvas_size.height as f64); + let image_size = Size2D::new(canvas_size.width, canvas_size.height); // 2. Establish the source and destination rectangles let (source_rect, dest_rect) = self.adjust_source_dest_rects(image_size, sx, sy, sw, sh, dx, dy, dw, dh); @@ -632,7 +632,7 @@ impl CanvasState { let sw = sw.unwrap_or(canvas_size.width as f64); let sh = sh.unwrap_or(canvas_size.height as f64); - let image_size = Size2D::new(canvas_size.width as f64, canvas_size.height as f64); + let image_size = Size2D::new(canvas_size.width, canvas_size.height); // 2. Establish the source and destination rectangles let (source_rect, dest_rect) = self.adjust_source_dest_rects(image_size, sx, sy, sw, sh, dx, dy, dw, dh); @@ -702,12 +702,12 @@ impl CanvasState { let snapshot = self .fetch_image_data(url, cors_setting) .ok_or(Error::InvalidState)?; - let image_size = snapshot.size().to_f64(); + let image_size = snapshot.size(); - let dw = dw.unwrap_or(image_size.width); - let dh = dh.unwrap_or(image_size.height); - let sw = sw.unwrap_or(image_size.width); - let sh = sh.unwrap_or(image_size.height); + let dw = dw.unwrap_or(image_size.width as f64); + let dh = dh.unwrap_or(image_size.height as f64); + let sw = sw.unwrap_or(image_size.width as f64); + let sh = sh.unwrap_or(image_size.height as f64); // Establish the source and destination rectangles let (source_rect, dest_rect) = @@ -741,7 +741,7 @@ impl CanvasState { #[allow(clippy::too_many_arguments)] fn adjust_source_dest_rects( &self, - image_size: Size2D, + image_size: Size2D, sx: f64, sy: f64, sw: f64, @@ -766,7 +766,7 @@ impl CanvasState { // When the source rectangle is outside the source image, // the source rectangle must be clipped to the source image let source_rect_clipped = source_rect - .intersection(&image_rect) + .intersection(&image_rect.to_f64()) .unwrap_or(Rect::zero()); // Width and height ratios between the non clipped and clipped source rectangles diff --git a/components/shared/canvas/canvas.rs b/components/shared/canvas/canvas.rs index e129237d3e0..283be0d458e 100644 --- a/components/shared/canvas/canvas.rs +++ b/components/shared/canvas/canvas.rs @@ -89,8 +89,8 @@ pub enum Canvas2dMsg { Arc(Point2D, f32, f32, f32, bool), ArcTo(Point2D, Point2D, f32), DrawImage(IpcSnapshot, Rect, Rect, bool), - DrawEmptyImage(Size2D, Rect, Rect), - DrawImageInOther(CanvasId, Size2D, Rect, Rect, bool), + DrawEmptyImage(Size2D, Rect, Rect), + DrawImageInOther(CanvasId, Size2D, Rect, Rect, bool), BeginPath, BezierCurveTo(Point2D, Point2D, Point2D), ClearRect(Rect),