| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/tile.h" | 5 #include "cc/resources/tile.h" |
| 6 #include "cc/resources/tile_priority.h" | 6 #include "cc/resources/tile_priority.h" |
| 7 #include "cc/test/fake_impl_proxy.h" | 7 #include "cc/test/fake_impl_proxy.h" |
| 8 #include "cc/test/fake_layer_tree_host_impl.h" | 8 #include "cc/test/fake_layer_tree_host_impl.h" |
| 9 #include "cc/test/fake_output_surface.h" | 9 #include "cc/test/fake_output_surface.h" |
| 10 #include "cc/test/fake_output_surface_client.h" | 10 #include "cc/test/fake_output_surface_client.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 const gfx::Size& tile_size) { | 95 const gfx::Size& tile_size) { |
| 96 TileVector tiles; | 96 TileVector tiles; |
| 97 for (int i = 0; i < count; ++i) { | 97 for (int i = 0; i < count; ++i) { |
| 98 scoped_refptr<Tile> tile = tile_manager_->CreateTile(picture_pile_.get(), | 98 scoped_refptr<Tile> tile = tile_manager_->CreateTile(picture_pile_.get(), |
| 99 tile_size, | 99 tile_size, |
| 100 gfx::Rect(), | 100 gfx::Rect(), |
| 101 gfx::Rect(), | 101 gfx::Rect(), |
| 102 1.0, | 102 1.0, |
| 103 0, | 103 0, |
| 104 0, | 104 0, |
| 105 Tile::USE_LCD_TEXT); | 105 0); |
| 106 tile->SetPriority(ACTIVE_TREE, active_priority); | 106 tile->SetPriority(ACTIVE_TREE, active_priority); |
| 107 tile->SetPriority(PENDING_TREE, pending_priority); | 107 tile->SetPriority(PENDING_TREE, pending_priority); |
| 108 tiles.push_back(tile); | 108 tiles.push_back(tile); |
| 109 } | 109 } |
| 110 return tiles; | 110 return tiles; |
| 111 } | 111 } |
| 112 | 112 |
| 113 TileVector CreateTiles(int count, | 113 TileVector CreateTiles(int count, |
| 114 TilePriority active_priority, | 114 TilePriority active_priority, |
| 115 TilePriority pending_priority) { | 115 TilePriority pending_priority) { |
| 116 return CreateTilesWithSize( | 116 return CreateTilesWithSize( |
| 117 count, active_priority, pending_priority, settings_.default_tile_size); | 117 count, active_priority, pending_priority, settings_.default_tile_size); |
| 118 } | 118 } |
| 119 | 119 |
| 120 FakeTileManager* tile_manager() { return tile_manager_.get(); } | 120 FakeTileManager* tile_manager() { return tile_manager_.get(); } |
| 121 | 121 |
| 122 int AssignedMemoryCount(const TileVector& tiles) { | 122 int AssignedMemoryCount(const TileVector& tiles) { |
| 123 int has_memory_count = 0; | 123 int has_memory_count = 0; |
| 124 for (TileVector::const_iterator it = tiles.begin(); it != tiles.end(); | 124 for (TileVector::const_iterator it = tiles.begin(); it != tiles.end(); |
| 125 ++it) { | 125 ++it) { |
| 126 if (tile_manager_->HasBeenAssignedMemory(*it)) | 126 if (tile_manager_->HasBeenAssignedMemory(*it)) |
| 127 ++has_memory_count; | 127 ++has_memory_count; |
| 128 } | 128 } |
| 129 return has_memory_count; | 129 return has_memory_count; |
| 130 } | 130 } |
| 131 | 131 |
| 132 int TilesWithLCDCount(const TileVector& tiles) { | |
| 133 int has_lcd_count = 0; | |
| 134 for (TileVector::const_iterator it = tiles.begin(); it != tiles.end(); | |
| 135 ++it) { | |
| 136 if ((*it)->GetRasterModeForTesting() == HIGH_QUALITY_RASTER_MODE) | |
| 137 ++has_lcd_count; | |
| 138 } | |
| 139 return has_lcd_count; | |
| 140 } | |
| 141 | |
| 142 bool ready_to_activate() const { return ready_to_activate_; } | 132 bool ready_to_activate() const { return ready_to_activate_; } |
| 143 | 133 |
| 144 // The parametrization specifies whether the max tile limit should | 134 // The parametrization specifies whether the max tile limit should |
| 145 // be applied to memory or resources. | 135 // be applied to memory or resources. |
| 146 bool UsingResourceLimit() { return !GetParam(); } | 136 bool UsingResourceLimit() { return !GetParam(); } |
| 147 bool UsingMemoryLimit() { return GetParam(); } | 137 bool UsingMemoryLimit() { return GetParam(); } |
| 148 | 138 |
| 149 protected: | 139 protected: |
| 150 GlobalStateThatImpactsTilePriority global_state_; | 140 GlobalStateThatImpactsTilePriority global_state_; |
| 151 | 141 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 | 411 |
| 422 // The pending tree is now more important. Active tiles will take higher | 412 // The pending tree is now more important. Active tiles will take higher |
| 423 // priority if they are ready-to-draw in practice. Importantly though, | 413 // priority if they are ready-to-draw in practice. Importantly though, |
| 424 // pending tiles also utilize the hard-limit. | 414 // pending tiles also utilize the hard-limit. |
| 425 SetTreePriority(NEW_CONTENT_TAKES_PRIORITY); | 415 SetTreePriority(NEW_CONTENT_TAKES_PRIORITY); |
| 426 tile_manager()->AssignMemoryToTiles(global_state_); | 416 tile_manager()->AssignMemoryToTiles(global_state_); |
| 427 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | 417 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); |
| 428 EXPECT_EQ(10, AssignedMemoryCount(pending_tree_tiles)); | 418 EXPECT_EQ(10, AssignedMemoryCount(pending_tree_tiles)); |
| 429 } | 419 } |
| 430 | 420 |
| 431 TEST_P(TileManagerTest, RasterAsLCD) { | |
| 432 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 433 TileVector active_tree_tiles = | |
| 434 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
| 435 TileVector pending_tree_tiles = | |
| 436 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
| 437 | |
| 438 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 439 | |
| 440 EXPECT_EQ(5, TilesWithLCDCount(active_tree_tiles)); | |
| 441 EXPECT_EQ(5, TilesWithLCDCount(pending_tree_tiles)); | |
| 442 } | |
| 443 | |
| 444 TEST_P(TileManagerTest, RasterAsNoLCD) { | |
| 445 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 446 TileVector active_tree_tiles = | |
| 447 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
| 448 TileVector pending_tree_tiles = | |
| 449 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
| 450 | |
| 451 for (TileVector::iterator it = active_tree_tiles.begin(); | |
| 452 it != active_tree_tiles.end(); | |
| 453 ++it) { | |
| 454 (*it)->set_can_use_lcd_text(false); | |
| 455 } | |
| 456 for (TileVector::iterator it = pending_tree_tiles.begin(); | |
| 457 it != pending_tree_tiles.end(); | |
| 458 ++it) { | |
| 459 (*it)->set_can_use_lcd_text(false); | |
| 460 } | |
| 461 | |
| 462 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 463 | |
| 464 EXPECT_EQ(0, TilesWithLCDCount(active_tree_tiles)); | |
| 465 EXPECT_EQ(0, TilesWithLCDCount(pending_tree_tiles)); | |
| 466 } | |
| 467 | |
| 468 TEST_P(TileManagerTest, ReRasterAsNoLCD) { | |
| 469 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 470 TileVector active_tree_tiles = | |
| 471 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
| 472 TileVector pending_tree_tiles = | |
| 473 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
| 474 | |
| 475 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 476 | |
| 477 EXPECT_EQ(5, TilesWithLCDCount(active_tree_tiles)); | |
| 478 EXPECT_EQ(5, TilesWithLCDCount(pending_tree_tiles)); | |
| 479 | |
| 480 for (TileVector::iterator it = active_tree_tiles.begin(); | |
| 481 it != active_tree_tiles.end(); | |
| 482 ++it) { | |
| 483 (*it)->set_can_use_lcd_text(false); | |
| 484 } | |
| 485 for (TileVector::iterator it = pending_tree_tiles.begin(); | |
| 486 it != pending_tree_tiles.end(); | |
| 487 ++it) { | |
| 488 (*it)->set_can_use_lcd_text(false); | |
| 489 } | |
| 490 | |
| 491 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 492 | |
| 493 EXPECT_EQ(0, TilesWithLCDCount(active_tree_tiles)); | |
| 494 EXPECT_EQ(0, TilesWithLCDCount(pending_tree_tiles)); | |
| 495 } | |
| 496 | |
| 497 TEST_P(TileManagerTest, NoTextDontReRasterAsNoLCD) { | |
| 498 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 499 TileVector active_tree_tiles = | |
| 500 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
| 501 TileVector pending_tree_tiles = | |
| 502 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
| 503 | |
| 504 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 505 | |
| 506 EXPECT_EQ(5, TilesWithLCDCount(active_tree_tiles)); | |
| 507 EXPECT_EQ(5, TilesWithLCDCount(pending_tree_tiles)); | |
| 508 | |
| 509 for (TileVector::iterator it = active_tree_tiles.begin(); | |
| 510 it != active_tree_tiles.end(); | |
| 511 ++it) { | |
| 512 ManagedTileState::TileVersion& tile_version = | |
| 513 (*it)->GetTileVersionForTesting(HIGH_QUALITY_RASTER_MODE); | |
| 514 tile_version.SetSolidColorForTesting(SkColorSetARGB(0, 0, 0, 0)); | |
| 515 (*it)->set_can_use_lcd_text(false); | |
| 516 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
| 517 } | |
| 518 for (TileVector::iterator it = pending_tree_tiles.begin(); | |
| 519 it != pending_tree_tiles.end(); | |
| 520 ++it) { | |
| 521 ManagedTileState::TileVersion& tile_version = | |
| 522 (*it)->GetTileVersionForTesting(HIGH_QUALITY_RASTER_MODE); | |
| 523 tile_version.SetSolidColorForTesting(SkColorSetARGB(0, 0, 0, 0)); | |
| 524 (*it)->set_can_use_lcd_text(false); | |
| 525 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
| 526 } | |
| 527 | |
| 528 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 529 | |
| 530 EXPECT_EQ(5, TilesWithLCDCount(active_tree_tiles)); | |
| 531 EXPECT_EQ(5, TilesWithLCDCount(pending_tree_tiles)); | |
| 532 } | |
| 533 | |
| 534 TEST_P(TileManagerTest, TextReRasterAsNoLCD) { | |
| 535 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 536 TileVector active_tree_tiles = | |
| 537 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
| 538 TileVector pending_tree_tiles = | |
| 539 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
| 540 | |
| 541 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 542 | |
| 543 EXPECT_EQ(5, TilesWithLCDCount(active_tree_tiles)); | |
| 544 EXPECT_EQ(5, TilesWithLCDCount(pending_tree_tiles)); | |
| 545 | |
| 546 for (TileVector::iterator it = active_tree_tiles.begin(); | |
| 547 it != active_tree_tiles.end(); | |
| 548 ++it) { | |
| 549 ManagedTileState::TileVersion& tile_version = | |
| 550 (*it)->GetTileVersionForTesting(HIGH_QUALITY_RASTER_MODE); | |
| 551 tile_version.SetSolidColorForTesting(SkColorSetARGB(0, 0, 0, 0)); | |
| 552 tile_version.SetHasTextForTesting(true); | |
| 553 (*it)->set_can_use_lcd_text(false); | |
| 554 | |
| 555 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
| 556 } | |
| 557 for (TileVector::iterator it = pending_tree_tiles.begin(); | |
| 558 it != pending_tree_tiles.end(); | |
| 559 ++it) { | |
| 560 ManagedTileState::TileVersion& tile_version = | |
| 561 (*it)->GetTileVersionForTesting(HIGH_QUALITY_RASTER_MODE); | |
| 562 tile_version.SetSolidColorForTesting(SkColorSetARGB(0, 0, 0, 0)); | |
| 563 tile_version.SetHasTextForTesting(true); | |
| 564 (*it)->set_can_use_lcd_text(false); | |
| 565 | |
| 566 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
| 567 } | |
| 568 | |
| 569 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 570 | |
| 571 EXPECT_EQ(0, TilesWithLCDCount(active_tree_tiles)); | |
| 572 EXPECT_EQ(0, TilesWithLCDCount(pending_tree_tiles)); | |
| 573 } | |
| 574 | |
| 575 TEST_P(TileManagerTest, RespectMemoryLimit) { | 421 TEST_P(TileManagerTest, RespectMemoryLimit) { |
| 576 if (UsingResourceLimit()) | 422 if (UsingResourceLimit()) |
| 577 return; | 423 return; |
| 578 | 424 |
| 579 Initialize(5, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | 425 Initialize(5, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
| 580 | 426 |
| 581 // We use double the tiles since the hard-limit is double. | 427 // We use double the tiles since the hard-limit is double. |
| 582 TileVector large_tiles = | 428 TileVector large_tiles = |
| 583 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); | 429 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); |
| 584 | 430 |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 | 947 |
| 1102 last_tile = tile; | 948 last_tile = tile; |
| 1103 new_content_tiles.insert(tile); | 949 new_content_tiles.insert(tile); |
| 1104 } | 950 } |
| 1105 | 951 |
| 1106 EXPECT_EQ(tile_count, new_content_tiles.size()); | 952 EXPECT_EQ(tile_count, new_content_tiles.size()); |
| 1107 EXPECT_EQ(all_tiles, new_content_tiles); | 953 EXPECT_EQ(all_tiles, new_content_tiles); |
| 1108 } | 954 } |
| 1109 } // namespace | 955 } // namespace |
| 1110 } // namespace cc | 956 } // namespace cc |
| OLD | NEW |