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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 203 |
204 // Stop creating tiles so that any invalidations are left as holes. | 204 // Stop creating tiles so that any invalidations are left as holes. |
205 client_.set_allow_create_tile(false); | 205 client_.set_allow_create_tile(false); |
206 | 206 |
207 Region invalidation = | 207 Region invalidation = |
208 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); | 208 SubtractRegions(gfx::Rect(tile_size), gfx::Rect(original_layer_size)); |
209 tiling_->UpdateTilesToCurrentPile(invalidation, gfx::Size(200, 200)); | 209 tiling_->UpdateTilesToCurrentPile(invalidation, gfx::Size(200, 200)); |
210 EXPECT_FALSE(tiling_->TileAt(0, 0)); | 210 EXPECT_FALSE(tiling_->TileAt(0, 0)); |
211 } | 211 } |
212 | 212 |
| 213 TEST_F(PictureLayerTilingIteratorTest, ResizeLiveTileRectOverTileBorders) { |
| 214 // The tiling has three rows and columns. |
| 215 Initialize(gfx::Size(100, 100), 1, gfx::Size(250, 250)); |
| 216 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); |
| 217 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); |
| 218 |
| 219 // The live tiles rect covers the whole tiling. |
| 220 SetLiveRectAndVerifyTiles(gfx::Rect(250, 250)); |
| 221 |
| 222 // Tiles in the right row and column exist. |
| 223 EXPECT_TRUE(tiling_->TileAt(2, 0)); |
| 224 EXPECT_TRUE(tiling_->TileAt(2, 1)); |
| 225 EXPECT_TRUE(tiling_->TileAt(2, 2)); |
| 226 EXPECT_TRUE(tiling_->TileAt(1, 2)); |
| 227 EXPECT_TRUE(tiling_->TileAt(0, 2)); |
| 228 |
| 229 // Shrink the live tiles rect to the very edge of the right-most and |
| 230 // bottom-most tiles. Their border pixels would still be inside the live |
| 231 // tiles rect, but the tiles should not exist just for that. |
| 232 int right = tiling_->TilingDataForTesting().TileBounds(2, 2).x(); |
| 233 int bottom = tiling_->TilingDataForTesting().TileBounds(2, 2).y(); |
| 234 |
| 235 SetLiveRectAndVerifyTiles(gfx::Rect(right, bottom)); |
| 236 EXPECT_FALSE(tiling_->TileAt(2, 0)); |
| 237 EXPECT_FALSE(tiling_->TileAt(2, 1)); |
| 238 EXPECT_FALSE(tiling_->TileAt(2, 2)); |
| 239 EXPECT_FALSE(tiling_->TileAt(1, 2)); |
| 240 EXPECT_FALSE(tiling_->TileAt(0, 2)); |
| 241 |
| 242 // Including the bottom row and right column again, should create the tiles. |
| 243 SetLiveRectAndVerifyTiles(gfx::Rect(right + 1, bottom + 1)); |
| 244 |
| 245 EXPECT_TRUE(tiling_->TileAt(2, 0)); |
| 246 EXPECT_TRUE(tiling_->TileAt(2, 1)); |
| 247 EXPECT_TRUE(tiling_->TileAt(2, 2)); |
| 248 EXPECT_TRUE(tiling_->TileAt(1, 2)); |
| 249 EXPECT_TRUE(tiling_->TileAt(0, 2)); |
| 250 |
| 251 // Shrink the live tiles rect to the very edge of the left-most and |
| 252 // top-most tiles. Their border pixels would still be inside the live |
| 253 // tiles rect, but the tiles should not exist just for that. |
| 254 int left = tiling_->TilingDataForTesting().TileBounds(0, 0).right(); |
| 255 int top = tiling_->TilingDataForTesting().TileBounds(0, 0).bottom(); |
| 256 |
| 257 SetLiveRectAndVerifyTiles(gfx::Rect(left, top, 250 - left, 250 - top)); |
| 258 EXPECT_FALSE(tiling_->TileAt(0, 2)); |
| 259 EXPECT_FALSE(tiling_->TileAt(0, 1)); |
| 260 EXPECT_FALSE(tiling_->TileAt(0, 0)); |
| 261 EXPECT_FALSE(tiling_->TileAt(1, 0)); |
| 262 EXPECT_FALSE(tiling_->TileAt(2, 0)); |
| 263 |
| 264 // Including the top row and left column again, should create the tiles. |
| 265 SetLiveRectAndVerifyTiles( |
| 266 gfx::Rect(left - 1, top - 1, 250 - left, 250 - top)); |
| 267 |
| 268 EXPECT_TRUE(tiling_->TileAt(0, 2)); |
| 269 EXPECT_TRUE(tiling_->TileAt(0, 1)); |
| 270 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
| 271 EXPECT_TRUE(tiling_->TileAt(1, 0)); |
| 272 EXPECT_TRUE(tiling_->TileAt(2, 0)); |
| 273 } |
| 274 |
| 275 TEST_F(PictureLayerTilingIteratorTest, ResizeLiveTileRectOverSameTiles) { |
| 276 // The tiling has three rows and columns. |
| 277 Initialize(gfx::Size(100, 100), 1, gfx::Size(250, 250)); |
| 278 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_x()); |
| 279 EXPECT_EQ(3, tiling_->TilingDataForTesting().num_tiles_y()); |
| 280 |
| 281 // The live tiles rect covers the whole tiling. |
| 282 SetLiveRectAndVerifyTiles(gfx::Rect(250, 250)); |
| 283 |
| 284 // All tiles exist. |
| 285 for (int i = 0; i < 3; ++i) { |
| 286 for (int j = 0; j < 3; ++j) |
| 287 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j; |
| 288 } |
| 289 |
| 290 // Shrink the live tiles rect, but still cover all the tiles. |
| 291 SetLiveRectAndVerifyTiles(gfx::Rect(1, 1, 249, 249)); |
| 292 |
| 293 // All tiles still exist. |
| 294 for (int i = 0; i < 3; ++i) { |
| 295 for (int j = 0; j < 3; ++j) |
| 296 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j; |
| 297 } |
| 298 |
| 299 // Grow the live tiles rect, but still cover all the same tiles. |
| 300 SetLiveRectAndVerifyTiles(gfx::Rect(0, 0, 250, 250)); |
| 301 |
| 302 // All tiles still exist. |
| 303 for (int i = 0; i < 3; ++i) { |
| 304 for (int j = 0; j < 3; ++j) |
| 305 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j; |
| 306 } |
| 307 } |
| 308 |
213 TEST_F(PictureLayerTilingIteratorTest, ResizeOverBorderPixelsDeletesTiles) { | 309 TEST_F(PictureLayerTilingIteratorTest, ResizeOverBorderPixelsDeletesTiles) { |
214 // Verifies that a resize with invalidation for newly exposed pixels will | 310 // Verifies that a resize with invalidation for newly exposed pixels will |
215 // deletes tiles that intersect that invalidation. | 311 // deletes tiles that intersect that invalidation. |
216 gfx::Size tile_size(100, 100); | 312 gfx::Size tile_size(100, 100); |
217 gfx::Size original_layer_size(99, 99); | 313 gfx::Size original_layer_size(99, 99); |
218 Initialize(tile_size, 1.f, original_layer_size); | 314 Initialize(tile_size, 1.f, original_layer_size); |
219 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); | 315 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); |
220 | 316 |
221 // Tiling only has one tile, since its total size is less than one. | 317 // Tiling only has one tile, since its total size is less than one. |
222 EXPECT_TRUE(tiling_->TileAt(0, 0)); | 318 EXPECT_TRUE(tiling_->TileAt(0, 0)); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 // or EVENTUALLY, with the exception of tiles that are between 0 and 312 | 602 // or EVENTUALLY, with the exception of tiles that are between 0 and 312 |
507 // pixels away from the viewport, which will be in the SOON bin. | 603 // pixels away from the viewport, which will be in the SOON bin. |
508 bool have_now = false; | 604 bool have_now = false; |
509 bool have_eventually = false; | 605 bool have_eventually = false; |
510 bool have_soon = false; | 606 bool have_soon = false; |
511 for (int i = 0; i < 47; ++i) { | 607 for (int i = 0; i < 47; ++i) { |
512 for (int j = 0; j < 47; ++j) { | 608 for (int j = 0; j < 47; ++j) { |
513 Tile* tile = tiling->TileAt(i, j); | 609 Tile* tile = tiling->TileAt(i, j); |
514 TilePriority priority = tile->priority(ACTIVE_TREE); | 610 TilePriority priority = tile->priority(ACTIVE_TREE); |
515 | 611 |
516 if (viewport_in_content_space.Intersects(tile->content_rect())) { | 612 gfx::Rect tile_rect = tiling->TilingDataForTesting().TileBounds(i, j); |
| 613 if (viewport_in_content_space.Intersects(tile_rect)) { |
517 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 614 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
518 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 615 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
519 have_now = true; | 616 have_now = true; |
520 } else if (soon_rect_in_content_space.Intersects(tile->content_rect())) { | 617 } else if (soon_rect_in_content_space.Intersects(tile_rect)) { |
521 EXPECT_EQ(TilePriority::SOON, priority.priority_bin); | 618 EXPECT_EQ(TilePriority::SOON, priority.priority_bin); |
522 have_soon = true; | 619 have_soon = true; |
523 } else { | 620 } else { |
524 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin); | 621 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin); |
525 EXPECT_GT(priority.distance_to_visible, 0.f); | 622 EXPECT_GT(priority.distance_to_visible, 0.f); |
526 have_eventually = true; | 623 have_eventually = true; |
527 } | 624 } |
528 } | 625 } |
529 } | 626 } |
530 | 627 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 have_eventually = false; | 671 have_eventually = false; |
575 have_soon = false; | 672 have_soon = false; |
576 | 673 |
577 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and | 674 // Viewport moved, so we expect to find some NOW tiles, some SOON tiles and |
578 // some EVENTUALLY tiles. | 675 // some EVENTUALLY tiles. |
579 for (int i = 0; i < 47; ++i) { | 676 for (int i = 0; i < 47; ++i) { |
580 for (int j = 0; j < 47; ++j) { | 677 for (int j = 0; j < 47; ++j) { |
581 Tile* tile = tiling->TileAt(i, j); | 678 Tile* tile = tiling->TileAt(i, j); |
582 TilePriority priority = tile->priority(ACTIVE_TREE); | 679 TilePriority priority = tile->priority(ACTIVE_TREE); |
583 | 680 |
584 if (viewport_in_content_space.Intersects(tile->content_rect())) { | 681 gfx::Rect tile_rect = tiling->TilingDataForTesting().TileBounds(i, j); |
| 682 if (viewport_in_content_space.Intersects(tile_rect)) { |
585 EXPECT_EQ(TilePriority::NOW, priority.priority_bin) << "i: " << i | 683 EXPECT_EQ(TilePriority::NOW, priority.priority_bin) << "i: " << i |
586 << " j: " << j; | 684 << " j: " << j; |
587 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible) << "i: " << i | 685 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible) << "i: " << i |
588 << " j: " << j; | 686 << " j: " << j; |
589 have_now = true; | 687 have_now = true; |
590 } else if (skewport.Intersects(tile->content_rect()) || | 688 } else if (skewport.Intersects(tile_rect) || |
591 soon_rect_in_content_space.Intersects(tile->content_rect())) { | 689 soon_rect_in_content_space.Intersects(tile_rect)) { |
592 EXPECT_EQ(TilePriority::SOON, priority.priority_bin) << "i: " << i | 690 EXPECT_EQ(TilePriority::SOON, priority.priority_bin) << "i: " << i |
593 << " j: " << j; | 691 << " j: " << j; |
594 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i | 692 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i |
595 << " j: " << j; | 693 << " j: " << j; |
596 have_soon = true; | 694 have_soon = true; |
597 } else { | 695 } else { |
598 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin) | 696 EXPECT_EQ(TilePriority::EVENTUALLY, priority.priority_bin) |
599 << "i: " << i << " j: " << j; | 697 << "i: " << i << " j: " << j; |
600 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i | 698 EXPECT_GT(priority.distance_to_visible, 0.f) << "i: " << i |
601 << " j: " << j; | 699 << " j: " << j; |
602 have_eventually = true; | 700 have_eventually = true; |
603 } | 701 } |
604 } | 702 } |
605 } | 703 } |
606 | 704 |
607 EXPECT_TRUE(have_now); | 705 EXPECT_TRUE(have_now); |
608 EXPECT_TRUE(have_soon); | 706 EXPECT_TRUE(have_soon); |
609 EXPECT_TRUE(have_eventually); | 707 EXPECT_TRUE(have_eventually); |
610 | 708 |
611 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | 709 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
612 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); | 710 EXPECT_FLOAT_EQ(68.f, priority.distance_to_visible); |
613 | 711 |
614 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | 712 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
615 EXPECT_FLOAT_EQ(28.f, priority.distance_to_visible); | 713 EXPECT_FLOAT_EQ(28.f, priority.distance_to_visible); |
616 | 714 |
617 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); | 715 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); |
618 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 716 EXPECT_FLOAT_EQ(4.f, priority.distance_to_visible); |
619 | 717 |
620 // Change the underlying layer scale. | 718 // Change the underlying layer scale. |
621 tiling->UpdateTilePriorities( | 719 tiling->UpdateTilePriorities( |
622 ACTIVE_TREE, viewport, 2.0f, 3.0, NULL, NULL, gfx::Transform()); | 720 ACTIVE_TREE, viewport, 2.0f, 3.0, NULL, NULL, gfx::Transform()); |
623 | 721 |
624 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | 722 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
625 EXPECT_FLOAT_EQ(136.f, priority.distance_to_visible); | 723 EXPECT_FLOAT_EQ(136.f, priority.distance_to_visible); |
626 | 724 |
627 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | 725 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
628 EXPECT_FLOAT_EQ(56.f, priority.distance_to_visible); | 726 EXPECT_FLOAT_EQ(56.f, priority.distance_to_visible); |
629 | 727 |
630 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); | 728 priority = tiling->TileAt(3, 4)->priority(ACTIVE_TREE); |
631 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 729 EXPECT_FLOAT_EQ(8.f, priority.distance_to_visible); |
632 | 730 |
633 // Test additional scales. | 731 // Test additional scales. |
634 tiling = TestablePictureLayerTiling::Create(0.2f, layer_bounds, &client); | 732 tiling = TestablePictureLayerTiling::Create(0.2f, layer_bounds, &client); |
635 tiling->UpdateTilePriorities( | 733 tiling->UpdateTilePriorities( |
636 ACTIVE_TREE, viewport, 1.0f, 4.0, NULL, NULL, gfx::Transform()); | 734 ACTIVE_TREE, viewport, 1.0f, 4.0, NULL, NULL, gfx::Transform()); |
637 | 735 |
638 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); | 736 priority = tiling->TileAt(5, 1)->priority(ACTIVE_TREE); |
639 EXPECT_FLOAT_EQ(110.f, priority.distance_to_visible); | 737 EXPECT_FLOAT_EQ(110.f, priority.distance_to_visible); |
640 | 738 |
641 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); | 739 priority = tiling->TileAt(2, 5)->priority(ACTIVE_TREE); |
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1943 for (std::vector<scoped_refptr<Tile> >::const_iterator it = tiles.begin(); | 2041 for (std::vector<scoped_refptr<Tile> >::const_iterator it = tiles.begin(); |
1944 it != tiles.end(); | 2042 it != tiles.end(); |
1945 ++it) { | 2043 ++it) { |
1946 EXPECT_EQ(TilePriority(), (*it)->priority(ACTIVE_TREE)); | 2044 EXPECT_EQ(TilePriority(), (*it)->priority(ACTIVE_TREE)); |
1947 } | 2045 } |
1948 tiles.clear(); | 2046 tiles.clear(); |
1949 } | 2047 } |
1950 | 2048 |
1951 } // namespace | 2049 } // namespace |
1952 } // namespace cc | 2050 } // namespace cc |
OLD | NEW |