Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: cc/resources/tile_manager.cc

Issue 322443002: cc: Refactor how picture layers are exposed to the tile manager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix tile manager perf tests Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/resources/tile_manager.h ('k') | cc/resources/tile_manager_perftest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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(
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 // TODO(vmpstr): Iterators and should handle this instead. crbug.com/381704
1246 // layer have to be accessible via the active tree. 1214 if (!layer->HasValidTilePriorities())
1247 if (!layer->IsOnActiveOrPendingTree())
1248 continue; 1215 continue;
1249 1216
1250 PictureLayerImpl* twin_layer = layer->GetTwinLayer(); 1217 PictureLayerImpl* twin_layer = layer->GetTwinLayer();
1251 1218
1252 // If the twin layer is recycled, it is not a valid twin. 1219 // Ignore the twin layer when tile priorities are invalid.
1253 if (twin_layer && !twin_layer->IsOnActiveOrPendingTree()) 1220 // TODO(vmpstr): Iterators should handle this instead. crbug.com/381704
1221 if (twin_layer && !twin_layer->HasValidTilePriorities())
1254 twin_layer = NULL; 1222 twin_layer = NULL;
1255 1223
1256 PairedPictureLayer paired_layer; 1224 PairedPictureLayer paired_layer;
1257 WhichTree tree = layer->GetTree(); 1225 WhichTree tree = layer->GetTree();
1258 1226
1259 // If the current tree is ACTIVE_TREE, then always generate a paired_layer. 1227 // 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 1228 // If current tree is PENDING_TREE, then only generate a paired_layer if
1261 // there is no twin layer. 1229 // there is no twin layer.
1262 if (tree == ACTIVE_TREE) { 1230 if (tree == ACTIVE_TREE) {
1263 DCHECK(!twin_layer || twin_layer->GetTree() == PENDING_TREE); 1231 DCHECK(!twin_layer || twin_layer->GetTree() == PENDING_TREE);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 const TilePriority& a_priority = 1411 const TilePriority& a_priority =
1444 a_tile->priority_for_tree_priority(tree_priority_); 1412 a_tile->priority_for_tree_priority(tree_priority_);
1445 const TilePriority& b_priority = 1413 const TilePriority& b_priority =
1446 b_tile->priority_for_tree_priority(tree_priority_); 1414 b_tile->priority_for_tree_priority(tree_priority_);
1447 bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY; 1415 bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY;
1448 1416
1449 // Now we have to return true iff b is higher priority than a. 1417 // Now we have to return true iff b is higher priority than a.
1450 1418
1451 // If the bin is the same but the resolution is not, then the order will be 1419 // If the bin is the same but the resolution is not, then the order will be
1452 // determined by whether we prioritize low res or not. 1420 // determined by whether we prioritize low res or not.
1421 // TODO(vmpstr): Remove this when TilePriority is no longer a member of Tile
1422 // class but instead produced by the iterators.
1453 if (b_priority.priority_bin == a_priority.priority_bin && 1423 if (b_priority.priority_bin == a_priority.priority_bin &&
1454 b_priority.resolution != a_priority.resolution) { 1424 b_priority.resolution != a_priority.resolution) {
1455 // Non ideal resolution should be sorted lower than other resolutions. 1425 // Non ideal resolution should be sorted lower than other resolutions.
1456 if (a_priority.resolution == NON_IDEAL_RESOLUTION) 1426 if (a_priority.resolution == NON_IDEAL_RESOLUTION)
1457 return true; 1427 return true;
1458 1428
1459 if (b_priority.resolution == NON_IDEAL_RESOLUTION) 1429 if (b_priority.resolution == NON_IDEAL_RESOLUTION)
1460 return false; 1430 return false;
1461 1431
1462 if (prioritize_low_res) 1432 if (prioritize_low_res)
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 } 1602 }
1633 return a_priority.IsHigherPriorityThan(b_priority); 1603 return a_priority.IsHigherPriorityThan(b_priority);
1634 } 1604 }
1635 1605
1636 void TileManager::SetRasterizerForTesting(Rasterizer* rasterizer) { 1606 void TileManager::SetRasterizerForTesting(Rasterizer* rasterizer) {
1637 rasterizer_ = rasterizer; 1607 rasterizer_ = rasterizer;
1638 rasterizer_->SetClient(this); 1608 rasterizer_->SetClient(this);
1639 } 1609 }
1640 1610
1641 bool TileManager::IsReadyToActivate() const { 1611 bool TileManager::IsReadyToActivate() const {
1642 for (std::vector<PictureLayerImpl*>::const_iterator it = layers_.begin(); 1612 const std::vector<PictureLayerImpl*>& layers = client_->GetPictureLayers();
1643 it != layers_.end(); 1613
1614 for (std::vector<PictureLayerImpl*>::const_iterator it = layers.begin();
1615 it != layers.end();
1644 ++it) { 1616 ++it) {
1645 if (!(*it)->AllTilesRequiredForActivationAreReadyToDraw()) 1617 if (!(*it)->AllTilesRequiredForActivationAreReadyToDraw())
1646 return false; 1618 return false;
1647 } 1619 }
1648 1620
1649 return true; 1621 return true;
1650 } 1622 }
1651 1623
1652 void TileManager::CheckIfReadyToActivate() { 1624 void TileManager::CheckIfReadyToActivate() {
1653 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); 1625 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate");
1654 1626
1655 rasterizer_->CheckForCompletedTasks(); 1627 rasterizer_->CheckForCompletedTasks();
1656 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; 1628 did_check_for_completed_tasks_since_last_schedule_tasks_ = true;
1657 1629
1658 if (IsReadyToActivate()) 1630 if (IsReadyToActivate())
1659 client_->NotifyReadyToActivate(); 1631 client_->NotifyReadyToActivate();
1660 } 1632 }
1661 1633
1662 } // namespace cc 1634 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/tile_manager.h ('k') | cc/resources/tile_manager_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698