Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Unified Diff: cc/picture_layer_tiling_unittest.cc

Issue 12287027: cc: Compute the inflated rect to cover a fixed number of tiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use sqrt(double) for android Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« cc/picture_layer_tiling.cc ('K') | « cc/picture_layer_tiling.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/picture_layer_tiling_unittest.cc
diff --git a/cc/picture_layer_tiling_unittest.cc b/cc/picture_layer_tiling_unittest.cc
index 8b825d1a4a46155bb2f20a28e9b8b5592923c135..bb34ceee6bfa435219e721d8cc9ad1cdf66c7284 100644
--- a/cc/picture_layer_tiling_unittest.cc
+++ b/cc/picture_layer_tiling_unittest.cc
@@ -179,5 +179,168 @@ TEST_F(PictureLayerTilingIteratorTest, NonContainedDestRect) {
VerifyTilesCoverNonContainedRect(0.5f, gfx::Rect(-1000, 100, 2000, 100));
}
+TEST(PictureLayerTilingTest, ExpandRectEqual) {
+ gfx::Rect in(40, 50, 100, 200);
+ gfx::Rect bounds(-1000, -1000, 10000, 10000);
+ int64 target_area = 100 * 200;
+ gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
+ in, target_area, bounds);
+ EXPECT_EQ(in.ToString(), out.ToString());
+}
+
+TEST(PictureLayerTilingTest, ExpandRectSmaller) {
+ gfx::Rect in(40, 50, 100, 200);
+ gfx::Rect bounds(-1000, -1000, 10000, 10000);
+ int64 target_area = 100 * 100;
+ gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
+ in, target_area, bounds);
+ EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y());
+ EXPECT_EQ(out.right() - in.right(), in.x() - out.x());
+ EXPECT_EQ(out.width() - in.width(), out.height() - in.height());
+ EXPECT_NEAR(100 * 100, out.width() * out.height(), 50);
+ EXPECT_TRUE(bounds.Contains(out));
+}
+
+TEST(PictureLayerTilingTest, ExpandRectUnbounded) {
+ gfx::Rect in(40, 50, 100, 200);
+ gfx::Rect bounds(-1000, -1000, 10000, 10000);
+ int64 target_area = 200 * 200;
+ gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
+ in, target_area, bounds);
+ EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y());
+ EXPECT_EQ(out.right() - in.right(), in.x() - out.x());
+ EXPECT_EQ(out.width() - in.width(), out.height() - in.height());
+ EXPECT_NEAR(200 * 200, out.width() * out.height(), 100);
+ EXPECT_TRUE(bounds.Contains(out));
+}
+
+TEST(PictureLayerTilingTest, ExpandRectBoundedSmaller) {
+ gfx::Rect in(40, 50, 100, 200);
+ gfx::Rect bounds(50, 60, 40, 30);
+ int64 target_area = 200 * 200;
+ gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
+ in, target_area, bounds);
+ EXPECT_EQ(bounds.ToString(), out.ToString());
+}
+
+TEST(PictureLayerTilingTest, ExpandRectBoundedEqual) {
+ gfx::Rect in(40, 50, 100, 200);
+ gfx::Rect bounds = in;
+ int64 target_area = 200 * 200;
+ gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
+ in, target_area, bounds);
+ EXPECT_EQ(bounds.ToString(), out.ToString());
+}
+
+TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchVertical) {
+ gfx::Rect in(40, 50, 100, 200);
+ gfx::Rect bounds(45, 0, 90, 300);
+ int64 target_area = 200 * 200;
+ gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
+ in, target_area, bounds);
+ EXPECT_EQ(bounds.ToString(), out.ToString());
+}
+
+TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchVertical) {
+ gfx::Rect in(40, 50, 100, 200);
+ gfx::Rect bounds(40, 0, 100, 300);
+ int64 target_area = 200 * 200;
+ gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
+ in, target_area, bounds);
+ EXPECT_EQ(bounds.ToString(), out.ToString());
+}
+
+TEST(PictureLayerTilingTest, ExpandRectBoundedSmallerStretchHorizontal) {
+ gfx::Rect in(40, 50, 100, 200);
+ gfx::Rect bounds(0, 55, 180, 190);
+ int64 target_area = 200 * 200;
+ gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
+ in, target_area, bounds);
+ EXPECT_EQ(bounds.ToString(), out.ToString());
+}
+
+TEST(PictureLayerTilingTest, ExpandRectBoundedEqualStretchHorizontal) {
+ gfx::Rect in(40, 50, 100, 200);
+ gfx::Rect bounds(0, 50, 180, 200);
+ int64 target_area = 200 * 200;
+ gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
+ in, target_area, bounds);
+ EXPECT_EQ(bounds.ToString(), out.ToString());
+}
+
+TEST(PictureLayerTilingTest, ExpandRectBoundedLeft) {
+ gfx::Rect in(40, 50, 100, 200);
+ gfx::Rect bounds(20, -1000, 10000, 10000);
+ int64 target_area = 200 * 200;
+ gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
+ in, target_area, bounds);
+ EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y());
+ EXPECT_EQ(out.bottom() - in.bottom(), out.right() - in.right());
+ EXPECT_NEAR(200 * 200, out.width() * out.height(), 500);
+ EXPECT_TRUE(bounds.Contains(out));
+}
+
+TEST(PictureLayerTilingTest, ExpandRectBoundedRight) {
+ gfx::Rect in(40, 50, 100, 200);
+ gfx::Rect bounds(-1000, -1000, 1000+120, 10000);
+ int64 target_area = 200 * 200;
+ gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
+ in, target_area, bounds);
+ EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y());
+ EXPECT_EQ(out.bottom() - in.bottom(), in.x() - out.x());
+ EXPECT_NEAR(200 * 200, out.width() * out.height(), 500);
+ EXPECT_TRUE(bounds.Contains(out));
+}
+
+TEST(PictureLayerTilingTest, ExpandRectBoundedTop) {
+ gfx::Rect in(40, 50, 100, 200);
+ gfx::Rect bounds(-1000, 30, 10000, 10000);
+ int64 target_area = 200 * 200;
+ gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
+ in, target_area, bounds);
+ EXPECT_EQ(out.right() - in.right(), in.x() - out.x());
+ EXPECT_EQ(out.right() - in.right(), out.bottom() - in.bottom());
+ EXPECT_NEAR(200 * 200, out.width() * out.height(), 500);
+ EXPECT_TRUE(bounds.Contains(out));
+}
+
+TEST(PictureLayerTilingTest, ExpandRectBoundedBottom) {
+ gfx::Rect in(40, 50, 100, 200);
+ gfx::Rect bounds(-1000, -1000, 10000, 1000 + 220);
+ int64 target_area = 200 * 200;
+ gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
+ in, target_area, bounds);
+ EXPECT_EQ(out.right() - in.right(), in.x() - out.x());
+ EXPECT_EQ(out.right() - in.right(), in.y() - out.y());
+ EXPECT_NEAR(200 * 200, out.width() * out.height(), 500);
+ EXPECT_TRUE(bounds.Contains(out));
+}
+
+TEST(PictureLayerTilingTest, ExpandRectSquishedHorizontally) {
+ gfx::Rect in(40, 50, 100, 200);
+ gfx::Rect bounds(0, -4000, 100+40+20, 100000);
+ int64 target_area = 400 * 400;
+ gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
+ in, target_area, bounds);
+ EXPECT_EQ(20, out.right() - in.right());
+ EXPECT_EQ(40, in.x() - out.x());
+ EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y());
+ EXPECT_NEAR(400 * 400, out.width() * out.height(), 500);
+ EXPECT_TRUE(bounds.Contains(out));
+}
+
+TEST(PictureLayerTilingTest, ExpandRectSquishedVertically) {
+ gfx::Rect in(40, 50, 100, 200);
+ gfx::Rect bounds(-4000, 0, 100000, 200+50+30);
+ int64 target_area = 400 * 400;
+ gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
+ in, target_area, bounds);
+ EXPECT_EQ(30, out.bottom() - in.bottom());
+ EXPECT_EQ(50, in.y() - out.y());
+ EXPECT_EQ(out.right() - in.right(), in.x() - out.x());
+ EXPECT_NEAR(400 * 400, out.width() * out.height(), 500);
+ EXPECT_TRUE(bounds.Contains(out));
+}
+
} // namespace
} // namespace cc
« cc/picture_layer_tiling.cc ('K') | « cc/picture_layer_tiling.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698