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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 source_frame_number_(source_frame_number), | 58 source_frame_number_(source_frame_number), |
59 analyze_picture_(analyze_picture), | 59 analyze_picture_(analyze_picture), |
60 rendering_stats_(rendering_stats), | 60 rendering_stats_(rendering_stats), |
61 reply_(reply), | 61 reply_(reply), |
62 canvas_(NULL) {} | 62 canvas_(NULL) {} |
63 | 63 |
64 // Overridden from Task: | 64 // Overridden from Task: |
65 virtual void RunOnWorkerThread() OVERRIDE { | 65 virtual void RunOnWorkerThread() OVERRIDE { |
66 TRACE_EVENT0("cc", "RasterizerTaskImpl::RunOnWorkerThread"); | 66 TRACE_EVENT0("cc", "RasterizerTaskImpl::RunOnWorkerThread"); |
67 | 67 |
68 DCHECK(picture_pile_); | 68 DCHECK(picture_pile_.get()); |
69 if (!canvas_) | 69 if (!canvas_) |
70 return; | 70 return; |
71 | 71 |
72 if (analyze_picture_) { | 72 if (analyze_picture_) { |
73 Analyze(picture_pile_.get()); | 73 Analyze(picture_pile_.get()); |
74 if (analysis_.is_solid_color) | 74 if (analysis_.is_solid_color) |
75 return; | 75 return; |
76 } | 76 } |
77 | 77 |
78 Raster(picture_pile_.get()); | 78 Raster(picture_pile_.get()); |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 prioritized_tiles_dirty_(false), | 366 prioritized_tiles_dirty_(false), |
367 all_tiles_that_need_to_be_rasterized_have_memory_(true), | 367 all_tiles_that_need_to_be_rasterized_have_memory_(true), |
368 all_tiles_required_for_activation_have_memory_(true), | 368 all_tiles_required_for_activation_have_memory_(true), |
369 bytes_releasable_(0), | 369 bytes_releasable_(0), |
370 resources_releasable_(0), | 370 resources_releasable_(0), |
371 ever_exceeded_memory_budget_(false), | 371 ever_exceeded_memory_budget_(false), |
372 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 372 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
373 did_initialize_visible_tile_(false), | 373 did_initialize_visible_tile_(false), |
374 did_check_for_completed_tasks_since_last_schedule_tasks_(true), | 374 did_check_for_completed_tasks_since_last_schedule_tasks_(true), |
375 ready_to_activate_check_notifier_( | 375 ready_to_activate_check_notifier_( |
376 task_runner_, | 376 task_runner_.get(), |
377 base::Bind(&TileManager::CheckIfReadyToActivate, | 377 base::Bind(&TileManager::CheckIfReadyToActivate, |
378 base::Unretained(this))) { | 378 base::Unretained(this))) { |
379 rasterizer_->SetClient(this); | 379 rasterizer_->SetClient(this); |
380 } | 380 } |
381 | 381 |
382 TileManager::~TileManager() { | 382 TileManager::~TileManager() { |
383 // Reset global state and manage. This should cause | 383 // Reset global state and manage. This should cause |
384 // our memory usage to drop to zero. | 384 // our memory usage to drop to zero. |
385 global_state_ = GlobalStateThatImpactsTilePriority(); | 385 global_state_ = GlobalStateThatImpactsTilePriority(); |
386 | 386 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 | 549 |
550 // For each tree, bin into different categories of tiles. | 550 // For each tree, bin into different categories of tiles. |
551 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 551 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
552 Tile* tile = it->second; | 552 Tile* tile = it->second; |
553 ManagedTileState& mts = tile->managed_state(); | 553 ManagedTileState& mts = tile->managed_state(); |
554 | 554 |
555 const ManagedTileState::TileVersion& tile_version = | 555 const ManagedTileState::TileVersion& tile_version = |
556 tile->GetTileVersionForDrawing(); | 556 tile->GetTileVersionForDrawing(); |
557 bool tile_is_ready_to_draw = tile_version.IsReadyToDraw(); | 557 bool tile_is_ready_to_draw = tile_version.IsReadyToDraw(); |
558 bool tile_is_active = tile_is_ready_to_draw || | 558 bool tile_is_active = tile_is_ready_to_draw || |
559 mts.tile_versions[mts.raster_mode].raster_task_; | 559 mts.tile_versions[mts.raster_mode].raster_task_.get(); |
560 | 560 |
561 // Get the active priority and bin. | 561 // Get the active priority and bin. |
562 TilePriority active_priority = tile->priority(ACTIVE_TREE); | 562 TilePriority active_priority = tile->priority(ACTIVE_TREE); |
563 ManagedTileBin active_bin = BinFromTilePriority(active_priority); | 563 ManagedTileBin active_bin = BinFromTilePriority(active_priority); |
564 | 564 |
565 // Get the pending priority and bin. | 565 // Get the pending priority and bin. |
566 TilePriority pending_priority = tile->priority(PENDING_TREE); | 566 TilePriority pending_priority = tile->priority(PENDING_TREE); |
567 ManagedTileBin pending_bin = BinFromTilePriority(pending_priority); | 567 ManagedTileBin pending_bin = BinFromTilePriority(pending_priority); |
568 | 568 |
569 bool pending_is_low_res = pending_priority.resolution == LOW_RESOLUTION; | 569 bool pending_is_low_res = pending_priority.resolution == LOW_RESOLUTION; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 // initialized. | 635 // initialized. |
636 DCHECK(!mts.required_for_activation || mts.bin != NEVER_BIN || | 636 DCHECK(!mts.required_for_activation || mts.bin != NEVER_BIN || |
637 tree_priority == SMOOTHNESS_TAKES_PRIORITY || | 637 tree_priority == SMOOTHNESS_TAKES_PRIORITY || |
638 memory_policy == ALLOW_NOTHING); | 638 memory_policy == ALLOW_NOTHING); |
639 | 639 |
640 // If the tile is in NEVER_BIN and it does not have an active task, then we | 640 // If the tile is in NEVER_BIN and it does not have an active task, then we |
641 // can release the resources early. If it does have the task however, we | 641 // can release the resources early. If it does have the task however, we |
642 // should keep it in the prioritized tile set to ensure that AssignGpuMemory | 642 // should keep it in the prioritized tile set to ensure that AssignGpuMemory |
643 // can visit it. | 643 // can visit it. |
644 if (mts.bin == NEVER_BIN && | 644 if (mts.bin == NEVER_BIN && |
645 !mts.tile_versions[mts.raster_mode].raster_task_) { | 645 !mts.tile_versions[mts.raster_mode].raster_task_.get()) { |
646 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | 646 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); |
647 continue; | 647 continue; |
648 } | 648 } |
649 | 649 |
650 // Insert the tile into a priority set. | 650 // Insert the tile into a priority set. |
651 tiles->InsertTile(tile, mts.bin); | 651 tiles->InsertTile(tile, mts.bin); |
652 } | 652 } |
653 } | 653 } |
654 | 654 |
655 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { | 655 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 } | 821 } |
822 | 822 |
823 // Allow lower priority tiles with initialized resources to keep | 823 // Allow lower priority tiles with initialized resources to keep |
824 // their memory by only assigning memory to new raster tasks if | 824 // their memory by only assigning memory to new raster tasks if |
825 // they can be scheduled. | 825 // they can be scheduled. |
826 bool reached_scheduled_raster_tasks_limit = | 826 bool reached_scheduled_raster_tasks_limit = |
827 tiles_that_need_to_be_rasterized->size() >= kScheduledRasterTasksLimit; | 827 tiles_that_need_to_be_rasterized->size() >= kScheduledRasterTasksLimit; |
828 if (!reached_scheduled_raster_tasks_limit) { | 828 if (!reached_scheduled_raster_tasks_limit) { |
829 // If we don't have the required version, and it's not in flight | 829 // If we don't have the required version, and it's not in flight |
830 // then we'll have to pay to create a new task. | 830 // then we'll have to pay to create a new task. |
831 if (!tile_version.resource_ && !tile_version.raster_task_) { | 831 if (!tile_version.resource_ && !tile_version.raster_task_.get()) { |
832 tile_bytes += bytes_if_allocated; | 832 tile_bytes += bytes_if_allocated; |
833 tile_resources++; | 833 tile_resources++; |
834 } | 834 } |
835 } | 835 } |
836 | 836 |
837 // Tile is OOM. | 837 // Tile is OOM. |
838 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) { | 838 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) { |
839 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | 839 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); |
840 | 840 |
841 // This tile was already on screen and now its resources have been | 841 // This tile was already on screen and now its resources have been |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 it != tiles_that_need_to_be_rasterized.end(); | 964 it != tiles_that_need_to_be_rasterized.end(); |
965 ++it) { | 965 ++it) { |
966 Tile* tile = *it; | 966 Tile* tile = *it; |
967 ManagedTileState& mts = tile->managed_state(); | 967 ManagedTileState& mts = tile->managed_state(); |
968 ManagedTileState::TileVersion& tile_version = | 968 ManagedTileState::TileVersion& tile_version = |
969 mts.tile_versions[mts.raster_mode]; | 969 mts.tile_versions[mts.raster_mode]; |
970 | 970 |
971 DCHECK(tile_version.requires_resource()); | 971 DCHECK(tile_version.requires_resource()); |
972 DCHECK(!tile_version.resource_); | 972 DCHECK(!tile_version.resource_); |
973 | 973 |
974 if (!tile_version.raster_task_) | 974 if (!tile_version.raster_task_.get()) |
975 tile_version.raster_task_ = CreateRasterTask(tile); | 975 tile_version.raster_task_ = CreateRasterTask(tile); |
976 | 976 |
977 raster_queue_.items.push_back(RasterTaskQueue::Item( | 977 raster_queue_.items.push_back(RasterTaskQueue::Item( |
978 tile_version.raster_task_.get(), tile->required_for_activation())); | 978 tile_version.raster_task_.get(), tile->required_for_activation())); |
979 raster_queue_.required_for_activation_count += | 979 raster_queue_.required_for_activation_count += |
980 tile->required_for_activation(); | 980 tile->required_for_activation(); |
981 } | 981 } |
982 | 982 |
983 // We must reduce the amount of unused resoruces before calling | 983 // We must reduce the amount of unused resoruces before calling |
984 // ScheduleTasks to prevent usage from rising above limits. | 984 // ScheduleTasks to prevent usage from rising above limits. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 Tile::Id tile_id, | 1085 Tile::Id tile_id, |
1086 scoped_ptr<ScopedResource> resource, | 1086 scoped_ptr<ScopedResource> resource, |
1087 RasterMode raster_mode, | 1087 RasterMode raster_mode, |
1088 const PicturePileImpl::Analysis& analysis, | 1088 const PicturePileImpl::Analysis& analysis, |
1089 bool was_canceled) { | 1089 bool was_canceled) { |
1090 DCHECK(tiles_.find(tile_id) != tiles_.end()); | 1090 DCHECK(tiles_.find(tile_id) != tiles_.end()); |
1091 | 1091 |
1092 Tile* tile = tiles_[tile_id]; | 1092 Tile* tile = tiles_[tile_id]; |
1093 ManagedTileState& mts = tile->managed_state(); | 1093 ManagedTileState& mts = tile->managed_state(); |
1094 ManagedTileState::TileVersion& tile_version = mts.tile_versions[raster_mode]; | 1094 ManagedTileState::TileVersion& tile_version = mts.tile_versions[raster_mode]; |
1095 DCHECK(tile_version.raster_task_); | 1095 DCHECK(tile_version.raster_task_.get()); |
1096 orphan_raster_tasks_.push_back(tile_version.raster_task_); | 1096 orphan_raster_tasks_.push_back(tile_version.raster_task_); |
1097 tile_version.raster_task_ = NULL; | 1097 tile_version.raster_task_ = NULL; |
1098 | 1098 |
1099 if (was_canceled) { | 1099 if (was_canceled) { |
1100 ++update_visible_tiles_stats_.canceled_count; | 1100 ++update_visible_tiles_stats_.canceled_count; |
1101 resource_pool_->ReleaseResource(resource.Pass()); | 1101 resource_pool_->ReleaseResource(resource.Pass()); |
1102 return; | 1102 return; |
1103 } | 1103 } |
1104 | 1104 |
1105 ++update_visible_tiles_stats_.completed_count; | 1105 ++update_visible_tiles_stats_.completed_count; |
(...skipping 28 matching lines...) Expand all Loading... |
1134 picture_pile, | 1134 picture_pile, |
1135 tile_size, | 1135 tile_size, |
1136 content_rect, | 1136 content_rect, |
1137 opaque_rect, | 1137 opaque_rect, |
1138 contents_scale, | 1138 contents_scale, |
1139 layer_id, | 1139 layer_id, |
1140 source_frame_number, | 1140 source_frame_number, |
1141 flags)); | 1141 flags)); |
1142 DCHECK(tiles_.find(tile->id()) == tiles_.end()); | 1142 DCHECK(tiles_.find(tile->id()) == tiles_.end()); |
1143 | 1143 |
1144 tiles_[tile->id()] = tile; | 1144 tiles_[tile->id()] = tile.get(); |
1145 used_layer_counts_[tile->layer_id()]++; | 1145 used_layer_counts_[tile->layer_id()]++; |
1146 prioritized_tiles_dirty_ = true; | 1146 prioritized_tiles_dirty_ = true; |
1147 return tile; | 1147 return tile; |
1148 } | 1148 } |
1149 | 1149 |
1150 void TileManager::SetRasterizerForTesting(Rasterizer* rasterizer) { | 1150 void TileManager::SetRasterizerForTesting(Rasterizer* rasterizer) { |
1151 rasterizer_ = rasterizer; | 1151 rasterizer_ = rasterizer; |
1152 rasterizer_->SetClient(this); | 1152 rasterizer_->SetClient(this); |
1153 } | 1153 } |
1154 | 1154 |
(...skipping 14 matching lines...) Expand all Loading... |
1169 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); | 1169 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); |
1170 | 1170 |
1171 rasterizer_->CheckForCompletedTasks(); | 1171 rasterizer_->CheckForCompletedTasks(); |
1172 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 1172 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
1173 | 1173 |
1174 if (IsReadyToActivate()) | 1174 if (IsReadyToActivate()) |
1175 client_->NotifyReadyToActivate(); | 1175 client_->NotifyReadyToActivate(); |
1176 } | 1176 } |
1177 | 1177 |
1178 } // namespace cc | 1178 } // namespace cc |
OLD | NEW |