diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 40416ed9e8d..224da2ca68d 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -420,7 +420,7 @@ impl StackingContext { // Translate the child's overflow region into our coordinate system. let child_stacking_context_overflow = child_stacking_context.overflow.translate(&child_stacking_context.bounds.origin) - .to_azure_rect(); + .to_nearest_azure_rect(); // Intersect that with the current tile boundaries to find the tile boundaries that the // child covers. @@ -428,7 +428,7 @@ impl StackingContext { .unwrap_or(ZERO_AZURE_RECT); // Translate the resulting rect into the child's coordinate system. - tile_subrect.translate(&-child_stacking_context.bounds.to_azure_rect().origin) + tile_subrect.translate(&-child_stacking_context.bounds.to_nearest_azure_rect().origin) } /// Places all nodes containing the point of interest into `result`, topmost first. Respects diff --git a/components/gfx/paint_context.rs b/components/gfx/paint_context.rs index 7160a31971b..24e7f1f7958 100644 --- a/components/gfx/paint_context.rs +++ b/components/gfx/paint_context.rs @@ -77,7 +77,7 @@ impl<'a> PaintContext<'a> { pub fn draw_solid_color(&self, bounds: &Rect, color: Color) { self.draw_target.make_current(); - self.draw_target.fill_rect(&bounds.to_azure_rect(), + self.draw_target.fill_rect(&bounds.to_nearest_azure_rect(), PatternRef::Color(&ColorPattern::new(color)), None); } @@ -104,7 +104,7 @@ impl<'a> PaintContext<'a> { } pub fn draw_push_clip(&self, bounds: &Rect) { - let rect = bounds.to_azure_rect(); + let rect = bounds.to_nearest_azure_rect(); let path_builder = self.draw_target.create_path_builder(); let left_top = Point2D(rect.origin.x, rect.origin.y); @@ -147,7 +147,7 @@ impl<'a> PaintContext<'a> { source_format); let source_rect = Rect(Point2D(0.0, 0.0), Size2D(image.width as AzFloat, image.height as AzFloat)); - let dest_rect = bounds.to_azure_rect(); + let dest_rect = bounds.to_nearest_azure_rect(); // TODO(pcwalton): According to CSS-IMAGES-3 ยง 5.3, nearest-neighbor interpolation is a // conforming implementation of `crisp-edges`, but it is not the best we could do. @@ -616,7 +616,7 @@ impl<'a> PaintContext<'a> { border: &SideOffsets2D, color: Color, dash_size: DashSize) { - let rect = bounds.to_azure_rect(); + let rect = bounds.to_nearest_azure_rect(); let draw_opts = DrawOptions::new(1 as AzFloat, 0 as uint16_t); let border_width = match direction { Direction::Top => border.top, @@ -671,7 +671,7 @@ impl<'a> PaintContext<'a> { border: &SideOffsets2D, radius: &BorderRadii, color: Color) { - let rect = bounds.to_azure_rect(); + let rect = bounds.to_nearest_azure_rect(); self.draw_border_path(&rect, direction, border, radius, color); } @@ -679,7 +679,7 @@ impl<'a> PaintContext<'a> { bounds: &Rect, border: &SideOffsets2D, shrink_factor: f32) -> Rect { - let rect = bounds.to_azure_rect(); + let rect = bounds.to_nearest_azure_rect(); let scaled_border = SideOffsets2D::new(shrink_factor * border.top, shrink_factor * border.right, shrink_factor * border.bottom, @@ -879,11 +879,11 @@ impl<'a> PaintContext<'a> { self.draw_target.make_current(); let stops = self.draw_target.create_gradient_stops(stops, ExtendMode::Clamp); - let pattern = LinearGradientPattern::new(&start_point.to_azure_point(), - &end_point.to_azure_point(), + let pattern = LinearGradientPattern::new(&start_point.to_nearest_azure_point(), + &end_point.to_nearest_azure_point(), stops, &Matrix2D::identity()); - self.draw_target.fill_rect(&bounds.to_azure_rect(), + self.draw_target.fill_rect(&bounds.to_nearest_azure_rect(), PatternRef::LinearGradient(&pattern), None); } @@ -1095,7 +1095,7 @@ impl<'a> PaintContext<'a> { self.draw_push_clip(&clip_region.main); for complex_region in clip_region.complex.iter() { // FIXME(pcwalton): Actually draw a rounded rect. - self.push_rounded_rect_clip(&complex_region.rect.to_azure_rect(), + self.push_rounded_rect_clip(&complex_region.rect.to_nearest_azure_rect(), &complex_region.radii.to_radii_px()) } self.transient_clip = Some(clip_region) @@ -1103,32 +1103,32 @@ impl<'a> PaintContext<'a> { } pub trait ToAzurePoint { + fn to_nearest_azure_point(&self) -> Point2D; fn to_azure_point(&self) -> Point2D; - fn to_f64_px_azure_point(&self) -> Point2D; } impl ToAzurePoint for Point2D { - fn to_azure_point(&self) -> Point2D { + fn to_nearest_azure_point(&self) -> Point2D { Point2D(self.x.to_nearest_px() as AzFloat, self.y.to_nearest_px() as AzFloat) } - fn to_f64_px_azure_point(&self) -> Point2D { + fn to_azure_point(&self) -> Point2D { Point2D(self.x.to_f32_px(), self.y.to_f32_px()) } } pub trait ToAzureRect { + fn to_nearest_azure_rect(&self) -> Rect; fn to_azure_rect(&self) -> Rect; - fn to_f64_px_azure_rect(&self) -> Rect; } impl ToAzureRect for Rect { - fn to_azure_rect(&self) -> Rect { - Rect(self.origin.to_azure_point(), Size2D(self.size.width.to_nearest_px() as AzFloat, + fn to_nearest_azure_rect(&self) -> Rect { + Rect(self.origin.to_nearest_azure_point(), Size2D(self.size.width.to_nearest_px() as AzFloat, self.size.height.to_nearest_px() as AzFloat)) } - fn to_f64_px_azure_rect(&self) -> Rect { - Rect(self.origin.to_f64_px_azure_point(), Size2D(self.size.width.to_f32_px(), + fn to_azure_rect(&self) -> Rect { + Rect(self.origin.to_azure_point(), Size2D(self.size.width.to_f32_px(), self.size.height.to_f32_px())) } } @@ -1306,7 +1306,7 @@ impl DrawTargetExtensions for DrawTarget { // +-----------+ // 3 4 - let (outer_rect, inner_rect) = (outer_rect.to_azure_rect(), inner_rect.to_azure_rect()); + let (outer_rect, inner_rect) = (outer_rect.to_nearest_azure_rect(), inner_rect.to_nearest_azure_rect()); let path_builder = self.create_path_builder(); path_builder.move_to(Point2D(outer_rect.max_x(), outer_rect.origin.y)); // 1 path_builder.line_to(Point2D(outer_rect.origin.x, outer_rect.origin.y)); // 2 @@ -1323,10 +1323,10 @@ impl DrawTargetExtensions for DrawTarget { fn create_rectangular_path(&self, rect: &Rect) -> Path { let path_builder = self.create_path_builder(); - path_builder.move_to(rect.origin.to_azure_point()); - path_builder.line_to(Point2D(rect.max_x(), rect.origin.y).to_azure_point()); - path_builder.line_to(Point2D(rect.max_x(), rect.max_y()).to_azure_point()); - path_builder.line_to(Point2D(rect.origin.x, rect.max_y()).to_azure_point()); + path_builder.move_to(rect.origin.to_nearest_azure_point()); + path_builder.line_to(Point2D(rect.max_x(), rect.origin.y).to_nearest_azure_point()); + path_builder.line_to(Point2D(rect.max_x(), rect.max_y()).to_nearest_azure_point()); + path_builder.line_to(Point2D(rect.origin.x, rect.max_y()).to_nearest_azure_point()); path_builder.finish() } } @@ -1385,7 +1385,7 @@ impl TemporaryDrawTarget { fn from_bounds(main_draw_target: &DrawTarget, bounds: &Rect) -> TemporaryDrawTarget { let draw_target_transform = main_draw_target.get_transform(); let temporary_draw_target_bounds = - draw_target_transform.transform_rect(&bounds.to_f64_px_azure_rect()); + draw_target_transform.transform_rect(&bounds.to_azure_rect()); let temporary_draw_target_size = Size2D(temporary_draw_target_bounds.size.width.ceil() as i32, temporary_draw_target_bounds.size.height.ceil() as i32);