OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/resources/picture_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 | 862 |
863 TEST(PictureLayerTilingTest, ExpandRectSmaller) { | 863 TEST(PictureLayerTilingTest, ExpandRectSmaller) { |
864 gfx::Rect in(40, 50, 100, 200); | 864 gfx::Rect in(40, 50, 100, 200); |
865 gfx::Rect bounds(-1000, -1000, 10000, 10000); | 865 gfx::Rect bounds(-1000, -1000, 10000, 10000); |
866 int64 target_area = 100 * 100; | 866 int64 target_area = 100 * 100; |
867 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 867 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
868 in, target_area, bounds, NULL); | 868 in, target_area, bounds, NULL); |
869 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | 869 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); |
870 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); | 870 EXPECT_EQ(out.right() - in.right(), in.x() - out.x()); |
871 EXPECT_EQ(out.width() - in.width(), out.height() - in.height()); | 871 EXPECT_EQ(out.width() - in.width(), out.height() - in.height()); |
872 EXPECT_NEAR(100 * 100, out.width() * out.height(), 50); | 872 |
| 873 // |in| represents the visible rect, and |out| represents the eventually rect. |
| 874 // If the eventually rect doesn't contain the visible rect, we will start |
| 875 // losing tiles. |
| 876 EXPECT_TRUE(out.Contains(in)); |
873 EXPECT_TRUE(bounds.Contains(out)); | 877 EXPECT_TRUE(bounds.Contains(out)); |
874 } | 878 } |
875 | 879 |
876 TEST(PictureLayerTilingTest, ExpandRectUnbounded) { | 880 TEST(PictureLayerTilingTest, ExpandRectUnbounded) { |
877 gfx::Rect in(40, 50, 100, 200); | 881 gfx::Rect in(40, 50, 100, 200); |
878 gfx::Rect bounds(-1000, -1000, 10000, 10000); | 882 gfx::Rect bounds(-1000, -1000, 10000, 10000); |
879 int64 target_area = 200 * 200; | 883 int64 target_area = 200 * 200; |
880 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 884 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
881 in, target_area, bounds, NULL); | 885 in, target_area, bounds, NULL); |
882 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); | 886 EXPECT_EQ(out.bottom() - in.bottom(), in.y() - out.y()); |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1442 1.f, // current contents scale | 1446 1.f, // current contents scale |
1443 1.0, // current frame time | 1447 1.0, // current frame time |
1444 NULL, // occlusion tracker | 1448 NULL, // occlusion tracker |
1445 NULL, // render target | 1449 NULL, // render target |
1446 gfx::Transform()); // draw transform | 1450 gfx::Transform()); // draw transform |
1447 VerifyTiles(1.f, | 1451 VerifyTiles(1.f, |
1448 gfx::Rect(layer_bounds), | 1452 gfx::Rect(layer_bounds), |
1449 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); | 1453 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); |
1450 } | 1454 } |
1451 | 1455 |
1452 static void CountExistingTiles(int *count, | |
1453 Tile* tile, | |
1454 const gfx::Rect& geometry_rect) { | |
1455 if (tile != NULL) | |
1456 ++(*count); | |
1457 } | |
1458 | |
1459 TEST_F(PictureLayerTilingIteratorTest, | |
1460 TilesExistLargeViewportAndLayerWithLargeVisibleArea) { | |
1461 gfx::Size layer_bounds(10000, 10000); | |
1462 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | |
1463 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | |
1464 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | |
1465 | |
1466 client_.set_tree(ACTIVE_TREE); | |
1467 set_max_tiles_for_interest_area(1); | |
1468 tiling_->UpdateTilePriorities( | |
1469 ACTIVE_TREE, | |
1470 gfx::Rect(layer_bounds), // visible content rect | |
1471 1.f, // current contents scale | |
1472 1.0, // current frame time | |
1473 NULL, // occlusion tracker | |
1474 NULL, // render target | |
1475 gfx::Transform()); // draw transform | |
1476 | |
1477 int num_tiles = 0; | |
1478 VerifyTiles(1.f, | |
1479 gfx::Rect(layer_bounds), | |
1480 base::Bind(&CountExistingTiles, &num_tiles)); | |
1481 // If we're making a rect the size of one tile, it can only overlap up to 4 | |
1482 // tiles depending on its position. | |
1483 EXPECT_LE(num_tiles, 4); | |
1484 VerifyTiles(1.f, gfx::Rect(), base::Bind(&TileExists, false)); | |
1485 } | |
1486 | |
1487 TEST_F(PictureLayerTilingIteratorTest, AddTilingsToMatchScale) { | 1456 TEST_F(PictureLayerTilingIteratorTest, AddTilingsToMatchScale) { |
1488 gfx::Size layer_bounds(1099, 801); | 1457 gfx::Size layer_bounds(1099, 801); |
1489 gfx::Size tile_size(100, 100); | 1458 gfx::Size tile_size(100, 100); |
1490 | 1459 |
1491 client_.SetTileSize(tile_size); | 1460 client_.SetTileSize(tile_size); |
1492 client_.set_tree(PENDING_TREE); | 1461 client_.set_tree(PENDING_TREE); |
1493 | 1462 |
1494 PictureLayerTilingSet active_set(&client_, layer_bounds); | 1463 PictureLayerTilingSet active_set(&client_, layer_bounds); |
1495 | 1464 |
1496 active_set.AddTiling(1.f); | 1465 active_set.AddTiling(1.f); |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2276 EXPECT_EQ(active_tiling->TileAt(0, 0), recycle_tiling->TileAt(0, 0)); | 2245 EXPECT_EQ(active_tiling->TileAt(0, 0), recycle_tiling->TileAt(0, 0)); |
2277 | 2246 |
2278 // Reset the active tiling. The recycle tiles should be released too. | 2247 // Reset the active tiling. The recycle tiles should be released too. |
2279 active_tiling->Reset(); | 2248 active_tiling->Reset(); |
2280 EXPECT_FALSE(active_tiling->TileAt(0, 0)); | 2249 EXPECT_FALSE(active_tiling->TileAt(0, 0)); |
2281 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); | 2250 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); |
2282 } | 2251 } |
2283 | 2252 |
2284 } // namespace | 2253 } // namespace |
2285 } // namespace cc | 2254 } // namespace cc |
OLD | NEW |