Chromium Code Reviews| 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/tile_manager.h" | 5 #include "cc/resources/tile_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 rasterizer_->ScheduleTasks(&empty); | 413 rasterizer_->ScheduleTasks(&empty); |
| 414 orphan_raster_tasks_.clear(); | 414 orphan_raster_tasks_.clear(); |
| 415 | 415 |
| 416 // This should finish all pending tasks and release any uninitialized | 416 // This should finish all pending tasks and release any uninitialized |
| 417 // resources. | 417 // resources. |
| 418 rasterizer_->Shutdown(); | 418 rasterizer_->Shutdown(); |
| 419 rasterizer_->CheckForCompletedTasks(); | 419 rasterizer_->CheckForCompletedTasks(); |
| 420 | 420 |
| 421 DCHECK_EQ(0u, bytes_releasable_); | 421 DCHECK_EQ(0u, bytes_releasable_); |
| 422 DCHECK_EQ(0u, resources_releasable_); | 422 DCHECK_EQ(0u, resources_releasable_); |
| 423 | |
| 424 for (std::vector<PictureLayerImpl*>::iterator it = layers_.begin(); | |
| 425 it != layers_.end(); | |
| 426 ++it) { | |
| 427 (*it)->DidUnregisterLayer(); | |
| 428 } | |
| 429 layers_.clear(); | |
| 430 } | 423 } |
| 431 | 424 |
| 432 void TileManager::Release(Tile* tile) { | 425 void TileManager::Release(Tile* tile) { |
| 433 prioritized_tiles_dirty_ = true; | 426 prioritized_tiles_dirty_ = true; |
| 434 released_tiles_.push_back(tile); | 427 released_tiles_.push_back(tile); |
| 435 } | 428 } |
| 436 | 429 |
| 437 void TileManager::DidChangeTilePriority(Tile* tile) { | 430 void TileManager::DidChangeTilePriority(Tile* tile) { |
| 438 prioritized_tiles_dirty_ = true; | 431 prioritized_tiles_dirty_ = true; |
| 439 } | 432 } |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 !mts.tile_versions[mts.raster_mode].raster_task_) { | 662 !mts.tile_versions[mts.raster_mode].raster_task_) { |
| 670 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | 663 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); |
| 671 continue; | 664 continue; |
| 672 } | 665 } |
| 673 | 666 |
| 674 // Insert the tile into a priority set. | 667 // Insert the tile into a priority set. |
| 675 tiles->InsertTile(tile, mts.bin); | 668 tiles->InsertTile(tile, mts.bin); |
| 676 } | 669 } |
| 677 } | 670 } |
| 678 | 671 |
| 679 void TileManager::CleanUpLayers() { | |
| 680 for (size_t i = 0; i < layers_.size(); ++i) { | |
| 681 if (layers_[i]->IsDrawnRenderSurfaceLayerListMember()) | |
| 682 continue; | |
| 683 | |
| 684 layers_[i]->DidUnregisterLayer(); | |
| 685 std::swap(layers_[i], layers_.back()); | |
| 686 layers_.pop_back(); | |
| 687 --i; | |
| 688 prioritized_tiles_dirty_ = true; | |
| 689 } | |
| 690 } | |
| 691 | |
| 692 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { | 672 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { |
| 693 TRACE_EVENT0("cc", "TileManager::ManageTiles"); | 673 TRACE_EVENT0("cc", "TileManager::ManageTiles"); |
| 694 | 674 |
| 695 // Update internal state. | 675 // Update internal state. |
| 696 if (state != global_state_) { | 676 if (state != global_state_) { |
| 697 global_state_ = state; | 677 global_state_ = state; |
| 698 prioritized_tiles_dirty_ = true; | 678 prioritized_tiles_dirty_ = true; |
| 699 } | 679 } |
| 700 | 680 |
| 701 CleanUpLayers(); | |
| 702 | |
| 703 // We need to call CheckForCompletedTasks() once in-between each call | 681 // We need to call CheckForCompletedTasks() once in-between each call |
| 704 // to ScheduleTasks() to prevent canceled tasks from being scheduled. | 682 // to ScheduleTasks() to prevent canceled tasks from being scheduled. |
| 705 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { | 683 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { |
| 706 rasterizer_->CheckForCompletedTasks(); | 684 rasterizer_->CheckForCompletedTasks(); |
| 707 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 685 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 708 } | 686 } |
| 709 | 687 |
| 710 UpdatePrioritizedTileSetIfNeeded(); | 688 UpdatePrioritizedTileSetIfNeeded(); |
| 711 | 689 |
| 712 TileVector tiles_that_need_to_be_rasterized; | 690 TileVector tiles_that_need_to_be_rasterized; |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1212 source_frame_number, | 1190 source_frame_number, |
| 1213 flags)); | 1191 flags)); |
| 1214 DCHECK(tiles_.find(tile->id()) == tiles_.end()); | 1192 DCHECK(tiles_.find(tile->id()) == tiles_.end()); |
| 1215 | 1193 |
| 1216 tiles_[tile->id()] = tile; | 1194 tiles_[tile->id()] = tile; |
| 1217 used_layer_counts_[tile->layer_id()]++; | 1195 used_layer_counts_[tile->layer_id()]++; |
| 1218 prioritized_tiles_dirty_ = true; | 1196 prioritized_tiles_dirty_ = true; |
| 1219 return tile; | 1197 return tile; |
| 1220 } | 1198 } |
| 1221 | 1199 |
| 1222 void TileManager::RegisterPictureLayerImpl(PictureLayerImpl* layer) { | |
| 1223 DCHECK(std::find(layers_.begin(), layers_.end(), layer) == layers_.end()); | |
| 1224 layers_.push_back(layer); | |
| 1225 } | |
| 1226 | |
| 1227 void TileManager::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | |
| 1228 std::vector<PictureLayerImpl*>::iterator it = | |
| 1229 std::find(layers_.begin(), layers_.end(), layer); | |
| 1230 DCHECK(it != layers_.end()); | |
| 1231 layers_.erase(it); | |
| 1232 } | |
| 1233 | |
| 1234 void TileManager::GetPairedPictureLayers( | 1200 void TileManager::GetPairedPictureLayers( |
|
reveman
2014/06/05 22:15:18
Would it be easier and more efficient to maintain
vmpstr
2014/06/05 22:38:01
You would have to update it every time there's a s
| |
| 1235 std::vector<PairedPictureLayer>* paired_layers) const { | 1201 std::vector<PairedPictureLayer>* paired_layers) const { |
| 1202 const std::vector<PictureLayerImpl*>& layers = client_->GetPictureLayers(); | |
| 1203 | |
| 1236 paired_layers->clear(); | 1204 paired_layers->clear(); |
| 1237 // Reserve a maximum possible paired layers. | 1205 // Reserve a maximum possible paired layers. |
| 1238 paired_layers->reserve(layers_.size()); | 1206 paired_layers->reserve(layers.size()); |
| 1239 | 1207 |
| 1240 for (std::vector<PictureLayerImpl*>::const_iterator it = layers_.begin(); | 1208 for (std::vector<PictureLayerImpl*>::const_iterator it = layers.begin(); |
| 1241 it != layers_.end(); | 1209 it != layers.end(); |
| 1242 ++it) { | 1210 ++it) { |
| 1243 PictureLayerImpl* layer = *it; | 1211 PictureLayerImpl* layer = *it; |
| 1244 | 1212 |
| 1245 // This is a recycle tree layer, we can safely skip since the tiles on this | 1213 if (!layer->IsViableSourceOfRasterAndEvictionTiles()) |
| 1246 // layer have to be accessible via the active tree. | |
| 1247 if (!layer->IsOnActiveOrPendingTree()) | |
| 1248 continue; | 1214 continue; |
| 1249 | 1215 |
| 1250 PictureLayerImpl* twin_layer = layer->GetTwinLayer(); | 1216 PictureLayerImpl* twin_layer = layer->GetTwinLayer(); |
| 1251 | 1217 |
| 1252 // If the twin layer is recycled, it is not a valid twin. | 1218 // Ignore the twin layer if not a viable source of tiles. |
| 1253 if (twin_layer && !twin_layer->IsOnActiveOrPendingTree()) | 1219 if (twin_layer && !twin_layer->IsViableSourceOfRasterAndEvictionTiles()) |
| 1254 twin_layer = NULL; | 1220 twin_layer = NULL; |
| 1255 | 1221 |
| 1256 PairedPictureLayer paired_layer; | 1222 PairedPictureLayer paired_layer; |
| 1257 WhichTree tree = layer->GetTree(); | 1223 WhichTree tree = layer->GetTree(); |
| 1258 | 1224 |
| 1259 // If the current tree is ACTIVE_TREE, then always generate a paired_layer. | 1225 // If the current tree is ACTIVE_TREE, then always generate a paired_layer. |
| 1260 // If current tree is PENDING_TREE, then only generate a paired_layer if | 1226 // If current tree is PENDING_TREE, then only generate a paired_layer if |
| 1261 // there is no twin layer. | 1227 // there is no twin layer. |
| 1262 if (tree == ACTIVE_TREE) { | 1228 if (tree == ACTIVE_TREE) { |
| 1263 DCHECK(!twin_layer || twin_layer->GetTree() == PENDING_TREE); | 1229 DCHECK(!twin_layer || twin_layer->GetTree() == PENDING_TREE); |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1632 } | 1598 } |
| 1633 return a_priority.IsHigherPriorityThan(b_priority); | 1599 return a_priority.IsHigherPriorityThan(b_priority); |
| 1634 } | 1600 } |
| 1635 | 1601 |
| 1636 void TileManager::SetRasterizerForTesting(Rasterizer* rasterizer) { | 1602 void TileManager::SetRasterizerForTesting(Rasterizer* rasterizer) { |
| 1637 rasterizer_ = rasterizer; | 1603 rasterizer_ = rasterizer; |
| 1638 rasterizer_->SetClient(this); | 1604 rasterizer_->SetClient(this); |
| 1639 } | 1605 } |
| 1640 | 1606 |
| 1641 bool TileManager::IsReadyToActivate() const { | 1607 bool TileManager::IsReadyToActivate() const { |
| 1642 for (std::vector<PictureLayerImpl*>::const_iterator it = layers_.begin(); | 1608 const std::vector<PictureLayerImpl*>& layers = client_->GetPictureLayers(); |
| 1643 it != layers_.end(); | 1609 |
| 1610 for (std::vector<PictureLayerImpl*>::const_iterator it = layers.begin(); | |
| 1611 it != layers.end(); | |
| 1644 ++it) { | 1612 ++it) { |
| 1645 if (!(*it)->AllTilesRequiredForActivationAreReadyToDraw()) | 1613 if (!(*it)->AllTilesRequiredForActivationAreReadyToDraw()) |
|
vmpstr
2014/06/05 22:38:01
I'm not sure you want to check all of the layers h
reveman
2014/06/06 17:27:24
Updated AllTilesRequiredForActivationAreReadyToDra
| |
| 1646 return false; | 1614 return false; |
| 1647 } | 1615 } |
| 1648 | 1616 |
| 1649 return true; | 1617 return true; |
| 1650 } | 1618 } |
| 1651 | 1619 |
| 1652 void TileManager::CheckIfReadyToActivate() { | 1620 void TileManager::CheckIfReadyToActivate() { |
| 1653 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); | 1621 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); |
| 1654 | 1622 |
| 1655 rasterizer_->CheckForCompletedTasks(); | 1623 rasterizer_->CheckForCompletedTasks(); |
| 1656 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 1624 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 1657 | 1625 |
| 1658 if (IsReadyToActivate()) | 1626 if (IsReadyToActivate()) |
| 1659 client_->NotifyReadyToActivate(); | 1627 client_->NotifyReadyToActivate(); |
| 1660 } | 1628 } |
| 1661 | 1629 |
| 1662 } // namespace cc | 1630 } // namespace cc |
| OLD | NEW |