| 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 | 8 |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/resources/picture_layer_tiling_set.h" | 10 #include "cc/resources/picture_layer_tiling_set.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 void Initialize(gfx::Size tile_size, | 60 void Initialize(gfx::Size tile_size, |
| 61 float contents_scale, | 61 float contents_scale, |
| 62 gfx::Size layer_bounds) { | 62 gfx::Size layer_bounds) { |
| 63 client_.SetTileSize(tile_size); | 63 client_.SetTileSize(tile_size); |
| 64 tiling_ = TestablePictureLayerTiling::Create(contents_scale, | 64 tiling_ = TestablePictureLayerTiling::Create(contents_scale, |
| 65 layer_bounds, | 65 layer_bounds, |
| 66 &client_); | 66 &client_); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void SetLiveRectAndVerifyTiles(gfx::Rect live_tiles_rect) { | 69 void SetLiveRectAndVerifyTiles(const gfx::Rect& live_tiles_rect) { |
| 70 tiling_->SetLiveTilesRect(live_tiles_rect); | 70 tiling_->SetLiveTilesRect(live_tiles_rect); |
| 71 | 71 |
| 72 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); | 72 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); |
| 73 for (std::vector<Tile*>::iterator iter = tiles.begin(); | 73 for (std::vector<Tile*>::iterator iter = tiles.begin(); |
| 74 iter != tiles.end(); | 74 iter != tiles.end(); |
| 75 ++iter) { | 75 ++iter) { |
| 76 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect())); | 76 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect())); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 void VerifyTilesExactlyCoverRect( | 80 void VerifyTilesExactlyCoverRect( |
| 81 float rect_scale, | 81 float rect_scale, |
| 82 gfx::Rect request_rect, | 82 const gfx::Rect& request_rect, |
| 83 gfx::Rect expect_rect) { | 83 const gfx::Rect& expect_rect) { |
| 84 EXPECT_TRUE(request_rect.Contains(expect_rect)); | 84 EXPECT_TRUE(request_rect.Contains(expect_rect)); |
| 85 | 85 |
| 86 // Iterators are not valid if this ratio is too large (i.e. the | 86 // Iterators are not valid if this ratio is too large (i.e. the |
| 87 // tiling is too high-res for a low-res destination rect.) This is an | 87 // tiling is too high-res for a low-res destination rect.) This is an |
| 88 // artifact of snapping geometry to integer coordinates and then mapping | 88 // artifact of snapping geometry to integer coordinates and then mapping |
| 89 // back to floating point texture coordinates. | 89 // back to floating point texture coordinates. |
| 90 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; | 90 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; |
| 91 ASSERT_LE(dest_to_contents_scale, 2.0); | 91 ASSERT_LE(dest_to_contents_scale, 2.0); |
| 92 | 92 |
| 93 Region remaining = expect_rect; | 93 Region remaining = expect_rect; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 108 EXPECT_LE(texture_rect.right(), client_.TileSize().width()); | 108 EXPECT_LE(texture_rect.right(), client_.TileSize().width()); |
| 109 EXPECT_LE(texture_rect.bottom(), client_.TileSize().height()); | 109 EXPECT_LE(texture_rect.bottom(), client_.TileSize().height()); |
| 110 | 110 |
| 111 EXPECT_EQ(iter.texture_size(), client_.TileSize()); | 111 EXPECT_EQ(iter.texture_size(), client_.TileSize()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // The entire rect must be filled by geometry from the tiling. | 114 // The entire rect must be filled by geometry from the tiling. |
| 115 EXPECT_TRUE(remaining.IsEmpty()); | 115 EXPECT_TRUE(remaining.IsEmpty()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void VerifyTilesExactlyCoverRect(float rect_scale, gfx::Rect rect) { | 118 void VerifyTilesExactlyCoverRect(float rect_scale, const gfx::Rect& rect) { |
| 119 VerifyTilesExactlyCoverRect(rect_scale, rect, rect); | 119 VerifyTilesExactlyCoverRect(rect_scale, rect, rect); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void VerifyTiles( | 122 void VerifyTiles( |
| 123 float rect_scale, | 123 float rect_scale, |
| 124 gfx::Rect rect, | 124 const gfx::Rect& rect, |
| 125 base::Callback<void(Tile* tile, gfx::Rect geometry_rect)> callback) { | 125 base::Callback<void(Tile* tile, |
| 126 const gfx::Rect& geometry_rect)> callback) { |
| 126 VerifyTiles(tiling_.get(), | 127 VerifyTiles(tiling_.get(), |
| 127 rect_scale, | 128 rect_scale, |
| 128 rect, | 129 rect, |
| 129 callback); | 130 callback); |
| 130 } | 131 } |
| 131 | 132 |
| 132 void VerifyTiles( | 133 void VerifyTiles( |
| 133 PictureLayerTiling* tiling, | 134 PictureLayerTiling* tiling, |
| 134 float rect_scale, | 135 float rect_scale, |
| 135 gfx::Rect rect, | 136 const gfx::Rect& rect, |
| 136 base::Callback<void(Tile* tile, gfx::Rect geometry_rect)> callback) { | 137 base::Callback<void(Tile* tile, |
| 138 const gfx::Rect& geometry_rect)> callback) { |
| 137 Region remaining = rect; | 139 Region remaining = rect; |
| 138 for (PictureLayerTiling::CoverageIterator iter(tiling, rect_scale, rect); | 140 for (PictureLayerTiling::CoverageIterator iter(tiling, rect_scale, rect); |
| 139 iter; | 141 iter; |
| 140 ++iter) { | 142 ++iter) { |
| 141 remaining.Subtract(iter.geometry_rect()); | 143 remaining.Subtract(iter.geometry_rect()); |
| 142 callback.Run(*iter, iter.geometry_rect()); | 144 callback.Run(*iter, iter.geometry_rect()); |
| 143 } | 145 } |
| 144 EXPECT_TRUE(remaining.IsEmpty()); | 146 EXPECT_TRUE(remaining.IsEmpty()); |
| 145 } | 147 } |
| 146 | 148 |
| 147 void VerifyTilesCoverNonContainedRect(float rect_scale, gfx::Rect dest_rect) { | 149 void VerifyTilesCoverNonContainedRect(float rect_scale, |
| 150 const gfx::Rect& dest_rect) { |
| 148 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; | 151 float dest_to_contents_scale = tiling_->contents_scale() / rect_scale; |
| 149 gfx::Rect clamped_rect = gfx::ScaleToEnclosingRect( | 152 gfx::Rect clamped_rect = gfx::ScaleToEnclosingRect( |
| 150 tiling_->ContentRect(), 1.f / dest_to_contents_scale); | 153 tiling_->ContentRect(), 1.f / dest_to_contents_scale); |
| 151 clamped_rect.Intersect(dest_rect); | 154 clamped_rect.Intersect(dest_rect); |
| 152 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); | 155 VerifyTilesExactlyCoverRect(rect_scale, dest_rect, clamped_rect); |
| 153 } | 156 } |
| 154 | 157 |
| 155 protected: | 158 protected: |
| 156 FakePictureLayerTilingClient client_; | 159 FakePictureLayerTilingClient client_; |
| 157 scoped_ptr<TestablePictureLayerTiling> tiling_; | 160 scoped_ptr<TestablePictureLayerTiling> tiling_; |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 // If a layer has a non-invertible transform, then the starting rect | 475 // If a layer has a non-invertible transform, then the starting rect |
| 473 // for the layer would be empty. | 476 // for the layer would be empty. |
| 474 gfx::Rect in(40, 40, 0, 0); | 477 gfx::Rect in(40, 40, 0, 0); |
| 475 gfx::Rect bounds(0, 0, 10, 10); | 478 gfx::Rect bounds(0, 0, 10, 10); |
| 476 int64 target_area = 400 * 400; | 479 int64 target_area = 400 * 400; |
| 477 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( | 480 gfx::Rect out = PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
| 478 in, target_area, bounds, NULL); | 481 in, target_area, bounds, NULL); |
| 479 EXPECT_TRUE(out.IsEmpty()); | 482 EXPECT_TRUE(out.IsEmpty()); |
| 480 } | 483 } |
| 481 | 484 |
| 482 static void TileExists(bool exists, Tile* tile, gfx::Rect geometry_rect) { | 485 static void TileExists(bool exists, Tile* tile, |
| 486 const gfx::Rect& geometry_rect) { |
| 483 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); | 487 EXPECT_EQ(exists, tile != NULL) << geometry_rect.ToString(); |
| 484 } | 488 } |
| 485 | 489 |
| 486 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { | 490 TEST_F(PictureLayerTilingIteratorTest, TilesExist) { |
| 487 gfx::Size layer_bounds(1099, 801); | 491 gfx::Size layer_bounds(1099, 801); |
| 488 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 492 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
| 489 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 493 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
| 490 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 494 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
| 491 | 495 |
| 492 tiling_->UpdateTilePriorities( | 496 tiling_->UpdateTilePriorities( |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 layer_bounds, // current layer bounds | 585 layer_bounds, // current layer bounds |
| 582 1.f, // last contents scale | 586 1.f, // last contents scale |
| 583 1.f, // current contents scale | 587 1.f, // current contents scale |
| 584 gfx::Transform(), // last screen transform | 588 gfx::Transform(), // last screen transform |
| 585 gfx::Transform(), // current screen transform | 589 gfx::Transform(), // current screen transform |
| 586 1.0, // current frame time | 590 1.0, // current frame time |
| 587 10000); // max tiles in tile manager | 591 10000); // max tiles in tile manager |
| 588 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); | 592 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, true)); |
| 589 } | 593 } |
| 590 | 594 |
| 591 static void TilesIntersectingRectExist(gfx::Rect rect, | 595 static void TilesIntersectingRectExist(const gfx::Rect& rect, |
| 592 bool intersect_exists, | 596 bool intersect_exists, |
| 593 Tile* tile, | 597 Tile* tile, |
| 594 gfx::Rect geometry_rect) { | 598 const gfx::Rect& geometry_rect) { |
| 595 bool intersects = rect.Intersects(geometry_rect); | 599 bool intersects = rect.Intersects(geometry_rect); |
| 596 bool expected_exists = intersect_exists ? intersects : !intersects; | 600 bool expected_exists = intersect_exists ? intersects : !intersects; |
| 597 EXPECT_EQ(expected_exists, tile != NULL) | 601 EXPECT_EQ(expected_exists, tile != NULL) |
| 598 << "Rects intersecting " << rect.ToString() << " should exist. " | 602 << "Rects intersecting " << rect.ToString() << " should exist. " |
| 599 << "Current tile rect is " << geometry_rect.ToString(); | 603 << "Current tile rect is " << geometry_rect.ToString(); |
| 600 } | 604 } |
| 601 | 605 |
| 602 TEST_F(PictureLayerTilingIteratorTest, | 606 TEST_F(PictureLayerTilingIteratorTest, |
| 603 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { | 607 TilesExistLargeViewportAndLayerWithSmallVisibleArea) { |
| 604 gfx::Size layer_bounds(10000, 10000); | 608 gfx::Size layer_bounds(10000, 10000); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 621 gfx::Transform(), // current screen transform | 625 gfx::Transform(), // current screen transform |
| 622 1.0, // current frame time | 626 1.0, // current frame time |
| 623 1); // max tiles in tile manager | 627 1); // max tiles in tile manager |
| 624 VerifyTiles(1.f, | 628 VerifyTiles(1.f, |
| 625 gfx::Rect(layer_bounds), | 629 gfx::Rect(layer_bounds), |
| 626 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); | 630 base::Bind(&TilesIntersectingRectExist, visible_rect, true)); |
| 627 } | 631 } |
| 628 | 632 |
| 629 static void CountExistingTiles(int *count, | 633 static void CountExistingTiles(int *count, |
| 630 Tile* tile, | 634 Tile* tile, |
| 631 gfx::Rect geometry_rect) { | 635 const gfx::Rect& geometry_rect) { |
| 632 if (tile != NULL) | 636 if (tile != NULL) |
| 633 ++(*count); | 637 ++(*count); |
| 634 } | 638 } |
| 635 | 639 |
| 636 TEST_F(PictureLayerTilingIteratorTest, | 640 TEST_F(PictureLayerTilingIteratorTest, |
| 637 TilesExistLargeViewportAndLayerWithLargeVisibleArea) { | 641 TilesExistLargeViewportAndLayerWithLargeVisibleArea) { |
| 638 gfx::Size layer_bounds(10000, 10000); | 642 gfx::Size layer_bounds(10000, 10000); |
| 639 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); | 643 Initialize(gfx::Size(100, 100), 1.f, layer_bounds); |
| 640 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); | 644 VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds)); |
| 641 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); | 645 VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false)); |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1404 EXPECT_GT(priority.time_to_visible_in_seconds, 0.f); | 1408 EXPECT_GT(priority.time_to_visible_in_seconds, 0.f); |
| 1405 | 1409 |
| 1406 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1410 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1407 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); | 1411 EXPECT_GT(priority.distance_to_visible_in_pixels, 0.f); |
| 1408 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), | 1412 EXPECT_FLOAT_EQ(std::numeric_limits<float>::infinity(), |
| 1409 priority.time_to_visible_in_seconds); | 1413 priority.time_to_visible_in_seconds); |
| 1410 } | 1414 } |
| 1411 | 1415 |
| 1412 } // namespace | 1416 } // namespace |
| 1413 } // namespace cc | 1417 } // namespace cc |
| OLD | NEW |