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