Commit 03d83933 authored by Daniel Bratell's avatar Daniel Bratell Committed by Commit Bot

Avoid converting via or creating IntRect when we want a FloatRect

It's currently easy to use an IntRect when a FloatRect is needed
since there is an implicit (lossy) conversion from IntRect to
FloatRect. This patch changes some code to remove some
unnecessary conversions between the types.

(A float can store all integers up to, but not including,
16,777,217 so it the conversion is most of the time non-lossy)

R=fs@opera.com, pdr@chromium.org

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I324b79c3d78d387574f47a4bda8f7dc7bdad567b
Reviewed-on: https://chromium-review.googlesource.com/1124682Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Commit-Queue: Daniel Bratell <bratell@opera.com>
Cr-Commit-Position: refs/heads/master@{#572306}
parent d08fc246
......@@ -91,8 +91,7 @@ const float kIdealPaddingRatio = 0.3f;
// Returns a rect which is offset and scaled accordingly to |base_rect|'s
// location and size.
FloatRect NormalizeRect(const FloatRect& to_normalize,
const FloatRect& base_rect) {
FloatRect NormalizeRect(const IntRect& to_normalize, const IntRect& base_rect) {
FloatRect result(to_normalize);
result.SetLocation(to_normalize.Location() + (-base_rect.Location()));
result.Scale(1.0 / base_rect.Width(), 1.0 / base_rect.Height());
......
......@@ -299,7 +299,7 @@ class ChromePrintContext : public PrintContext {
// The page rect gets scaled and translated, so specify the entire
// print content area here as the recording rect.
IntRect bounds(0, 0, printed_page_height_, printed_page_width_);
FloatRect bounds(0, 0, printed_page_height_, printed_page_width_);
PaintRecordBuilder builder(&canvas->getMetaData());
builder.Context().SetPrinting(true);
builder.Context().BeginRecording(bounds);
......@@ -326,7 +326,7 @@ class ChromePrintContext : public PrintContext {
const float page_width = page_size_in_pixels.Width();
size_t num_pages = PageRects().size();
int total_height = num_pages * (page_size_in_pixels.Height() + 1) - 1;
IntRect all_pages_rect(0, 0, page_width, total_height);
FloatRect all_pages_rect(0, 0, page_width, total_height);
PaintRecordBuilder builder(&canvas->getMetaData());
GraphicsContext& context = builder.Context();
......
......@@ -165,7 +165,8 @@ TEST_F(LayoutBoxModelObjectTest, StickyPositionInlineConstraints) {
EXPECT_EQ(
IntRect(0, 100, 10, 10),
EnclosingIntRect(GetScrollContainerRelativeStickyBoxRect(constraints)));
EXPECT_EQ(IntRect(0, 50, 100, 100), sticky->ComputeStickyConstrainingRect());
EXPECT_EQ(IntRect(0, 50, 100, 100),
EnclosingIntRect(sticky->ComputeStickyConstrainingRect()));
}
// Verifies that the sticky constraints are correctly computed for sticky with
......@@ -224,7 +225,7 @@ TEST_F(LayoutBoxModelObjectTest, StickyPositionVerticalRLInlineConstraints) {
IntRect(2190, 100, 10, 10),
EnclosingIntRect(GetScrollContainerRelativeStickyBoxRect(constraints)));
EXPECT_EQ(IntRect(2100, 50, 100, 100),
sticky->ComputeStickyConstrainingRect());
EnclosingIntRect(sticky->ComputeStickyConstrainingRect()));
}
// Verifies that the sticky constraints are not affected by transforms
......
......@@ -253,7 +253,7 @@ static bool ExtractImageData(Image* image,
// for layout, which is not allowed. See https://crbug.com/429346
ImageObserverDisabler disabler(image);
PaintFlags flags;
IntRect image_source_rect(IntPoint(), image->Size());
FloatRect image_source_rect(FloatPoint(), FloatSize(image->Size()));
IntRect image_dest_rect(IntPoint(), image_size);
// TODO(ccameron): No color conversion is required here.
std::unique_ptr<cc::PaintCanvas> canvas =
......
......@@ -389,7 +389,7 @@ FloatPoint ConvertToRootFrame(LocalFrameView* view, FloatPoint pt) {
// Adjusts 'point' to the nearest point inside rect, and leaves it unchanged if
// already inside.
void AdjustPointToRect(FloatPoint& point, const FloatRect& rect) {
void AdjustPointToRect(FloatPoint& point, const IntRect& rect) {
if (point.X() < rect.X())
point.SetX(rect.X());
else if (point.X() > rect.MaxX())
......
......@@ -36,7 +36,7 @@ SourceGraphic* SourceGraphic::Create(Filter* filter) {
}
FloatRect SourceGraphic::MapInputs(const FloatRect& rect) const {
return !source_rect_.IsEmpty() ? source_rect_ : rect;
return !source_rect_.IsEmpty() ? FloatRect(source_rect_) : rect;
}
void SourceGraphic::SetSourceRect(const IntRect& source_rect) {
......
......@@ -36,7 +36,7 @@ TEST_F(CullRectTest, IntersectsCullRectWithTransform) {
AffineTransform transform;
transform.Translate(-2, -2);
EXPECT_TRUE(cull_rect.IntersectsCullRect(transform, IntRect(51, 51, 1, 1)));
EXPECT_TRUE(cull_rect.IntersectsCullRect(transform, FloatRect(51, 51, 1, 1)));
EXPECT_FALSE(cull_rect.IntersectsCullRect(IntRect(52, 52, 1, 1)));
}
......
......@@ -358,13 +358,13 @@ TEST_F(RasterInvalidatorTest, ClipPropertyChangeSimple) {
ASSERT_EQ(4u, invalidations.size());
// |clip1| change should trigger incremental raster invalidation.
EXPECT_INCREMENTAL_INVALIDATION(invalidations, 0, artifact->PaintChunks()[1],
IntRect(-1000, -1000, 2000, 500));
FloatRect(-1000, -1000, 2000, 500));
EXPECT_INCREMENTAL_INVALIDATION(invalidations, 1, artifact->PaintChunks()[1],
IntRect(-1000, -500, 500, 1000));
FloatRect(-1000, -500, 500, 1000));
EXPECT_INCREMENTAL_INVALIDATION(invalidations, 2, artifact->PaintChunks()[1],
IntRect(500, -500, 500, 1000));
FloatRect(500, -500, 500, 1000));
EXPECT_INCREMENTAL_INVALIDATION(invalidations, 3, artifact->PaintChunks()[1],
IntRect(-1000, 500, 2000, 500));
FloatRect(-1000, 500, 2000, 500));
invalidator.SetTracksRasterInvalidations(false);
FinishCycle(*artifact);
......@@ -380,7 +380,7 @@ TEST_F(RasterInvalidatorTest, ClipPropertyChangeSimple) {
ASSERT_EQ(1u, invalidations1.size());
// |clip1| change should trigger incremental raster invalidation.
EXPECT_INCREMENTAL_INVALIDATION(invalidations1, 0, artifact->PaintChunks()[1],
IntRect(500, -500, 500, 1000));
FloatRect(500, -500, 500, 1000));
invalidator.SetTracksRasterInvalidations(false);
FinishCycle(*artifact);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment