| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 "<unknown TileRasterState value>")); | 145 "<unknown TileRasterState value>")); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 TileManager::TileManager( | 149 TileManager::TileManager( |
| 150 TileManagerClient* client, | 150 TileManagerClient* client, |
| 151 ResourceProvider* resource_provider, | 151 ResourceProvider* resource_provider, |
| 152 size_t num_raster_threads, | 152 size_t num_raster_threads, |
| 153 bool use_cheapness_estimator, | 153 bool use_cheapness_estimator, |
| 154 bool use_color_estimator, | 154 bool use_color_estimator, |
| 155 bool prediction_benchmarking) | 155 bool prediction_benchmarking, |
| 156 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
| 156 : client_(client), | 157 : client_(client), |
| 157 resource_pool_(ResourcePool::Create(resource_provider)), | 158 resource_pool_(ResourcePool::Create(resource_provider)), |
| 158 raster_worker_pool_(RasterWorkerPool::Create(this, num_raster_threads)), | 159 raster_worker_pool_(RasterWorkerPool::Create(this, num_raster_threads)), |
| 159 manage_tiles_pending_(false), | 160 manage_tiles_pending_(false), |
| 160 manage_tiles_call_count_(0), | 161 manage_tiles_call_count_(0), |
| 161 bytes_pending_upload_(0), | 162 bytes_pending_upload_(0), |
| 162 has_performed_uploads_since_last_flush_(false), | 163 has_performed_uploads_since_last_flush_(false), |
| 163 ever_exceeded_memory_budget_(false), | 164 ever_exceeded_memory_budget_(false), |
| 164 record_rendering_stats_(false), | |
| 165 use_cheapness_estimator_(use_cheapness_estimator), | 165 use_cheapness_estimator_(use_cheapness_estimator), |
| 166 use_color_estimator_(use_color_estimator), | 166 use_color_estimator_(use_color_estimator), |
| 167 prediction_benchmarking_(prediction_benchmarking), | 167 prediction_benchmarking_(prediction_benchmarking), |
| 168 pending_tasks_(0), | 168 pending_tasks_(0), |
| 169 max_pending_tasks_(kMaxNumPendingTasksPerThread * num_raster_threads) { | 169 max_pending_tasks_(kMaxNumPendingTasksPerThread * num_raster_threads), |
| 170 rendering_stats_instrumentation_(rendering_stats_instrumentation) { |
| 170 for (int i = 0; i < NUM_STATES; ++i) { | 171 for (int i = 0; i < NUM_STATES; ++i) { |
| 171 for (int j = 0; j < NUM_TREES; ++j) { | 172 for (int j = 0; j < NUM_TREES; ++j) { |
| 172 for (int k = 0; k < NUM_BINS; ++k) | 173 for (int k = 0; k < NUM_BINS; ++k) |
| 173 raster_state_count_[i][j][k] = 0; | 174 raster_state_count_[i][j][k] = 0; |
| 174 } | 175 } |
| 175 } | 176 } |
| 176 } | 177 } |
| 177 | 178 |
| 178 TileManager::~TileManager() { | 179 TileManager::~TileManager() { |
| 179 // Reset global state and manage. This should cause | 180 // Reset global state and manage. This should cause |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 GetMemoryStats(&memory_required_bytes, | 488 GetMemoryStats(&memory_required_bytes, |
| 488 &memory_nice_to_have_bytes, | 489 &memory_nice_to_have_bytes, |
| 489 &memory_used_bytes); | 490 &memory_used_bytes); |
| 490 requirements->SetInteger("memory_required_bytes", memory_required_bytes); | 491 requirements->SetInteger("memory_required_bytes", memory_required_bytes); |
| 491 requirements->SetInteger("memory_nice_to_have_bytes", | 492 requirements->SetInteger("memory_nice_to_have_bytes", |
| 492 memory_nice_to_have_bytes); | 493 memory_nice_to_have_bytes); |
| 493 requirements->SetInteger("memory_used_bytes", memory_used_bytes); | 494 requirements->SetInteger("memory_used_bytes", memory_used_bytes); |
| 494 return requirements.PassAs<base::Value>(); | 495 return requirements.PassAs<base::Value>(); |
| 495 } | 496 } |
| 496 | 497 |
| 497 void TileManager::SetRecordRenderingStats(bool record_rendering_stats) { | |
| 498 if (record_rendering_stats_ == record_rendering_stats) | |
| 499 return; | |
| 500 | |
| 501 record_rendering_stats_ = record_rendering_stats; | |
| 502 raster_worker_pool_->SetRecordRenderingStats(record_rendering_stats); | |
| 503 } | |
| 504 | |
| 505 void TileManager::GetRenderingStats(RenderingStats* stats) { | |
| 506 CHECK(record_rendering_stats_); | |
| 507 raster_worker_pool_->GetRenderingStats(stats); | |
| 508 stats->totalDeferredImageCacheHitCount = | |
| 509 rendering_stats_.totalDeferredImageCacheHitCount; | |
| 510 stats->totalImageGatheringCount = rendering_stats_.totalImageGatheringCount; | |
| 511 stats->totalImageGatheringTime = | |
| 512 rendering_stats_.totalImageGatheringTime; | |
| 513 } | |
| 514 | |
| 515 bool TileManager::HasPendingWorkScheduled(WhichTree tree) const { | 498 bool TileManager::HasPendingWorkScheduled(WhichTree tree) const { |
| 516 // Always true when ManageTiles() call is pending. | 499 // Always true when ManageTiles() call is pending. |
| 517 if (manage_tiles_pending_) | 500 if (manage_tiles_pending_) |
| 518 return true; | 501 return true; |
| 519 | 502 |
| 520 for (int i = 0; i < NUM_STATES; ++i) { | 503 for (int i = 0; i < NUM_STATES; ++i) { |
| 521 switch (i) { | 504 switch (i) { |
| 522 case WAITING_FOR_RASTER_STATE: | 505 case WAITING_FOR_RASTER_STATE: |
| 523 case RASTER_STATE: | 506 case RASTER_STATE: |
| 524 case UPLOAD_STATE: | 507 case UPLOAD_STATE: |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 tile->drawing_info().set_transparent(); | 714 tile->drawing_info().set_transparent(); |
| 732 DidFinishTileInitialization(tile); | 715 DidFinishTileInitialization(tile); |
| 733 } | 716 } |
| 734 } | 717 } |
| 735 } | 718 } |
| 736 | 719 |
| 737 void TileManager::GatherPixelRefsForTile(Tile* tile) { | 720 void TileManager::GatherPixelRefsForTile(Tile* tile) { |
| 738 TRACE_EVENT0("cc", "TileManager::GatherPixelRefsForTile"); | 721 TRACE_EVENT0("cc", "TileManager::GatherPixelRefsForTile"); |
| 739 ManagedTileState& managed_tile_state = tile->managed_state(); | 722 ManagedTileState& managed_tile_state = tile->managed_state(); |
| 740 if (managed_tile_state.need_to_gather_pixel_refs) { | 723 if (managed_tile_state.need_to_gather_pixel_refs) { |
| 741 base::TimeTicks gather_begin_time; | 724 base::TimeTicks start_time = |
| 742 if (record_rendering_stats_) | 725 rendering_stats_instrumentation_->StartRecording(); |
| 743 gather_begin_time = base::TimeTicks::HighResNow(); | |
| 744 tile->picture_pile()->GatherPixelRefs( | 726 tile->picture_pile()->GatherPixelRefs( |
| 745 tile->content_rect_, | 727 tile->content_rect_, |
| 746 tile->contents_scale_, | 728 tile->contents_scale_, |
| 747 managed_tile_state.pending_pixel_refs); | 729 managed_tile_state.pending_pixel_refs); |
| 748 managed_tile_state.need_to_gather_pixel_refs = false; | 730 managed_tile_state.need_to_gather_pixel_refs = false; |
| 749 if (record_rendering_stats_) { | 731 base::TimeDelta duration = |
| 750 rendering_stats_.totalImageGatheringCount++; | 732 rendering_stats_instrumentation_->EndRecording(start_time); |
| 751 rendering_stats_.totalImageGatheringTime += | 733 rendering_stats_instrumentation_->AddImageGathering(duration); |
| 752 base::TimeTicks::HighResNow() - gather_begin_time; | |
| 753 } | |
| 754 } | 734 } |
| 755 } | 735 } |
| 756 | 736 |
| 757 void TileManager::DispatchImageDecodeTasksForTile(Tile* tile) { | 737 void TileManager::DispatchImageDecodeTasksForTile(Tile* tile) { |
| 758 GatherPixelRefsForTile(tile); | 738 GatherPixelRefsForTile(tile); |
| 759 std::list<skia::LazyPixelRef*>& pending_pixel_refs = | 739 std::list<skia::LazyPixelRef*>& pending_pixel_refs = |
| 760 tile->managed_state().pending_pixel_refs; | 740 tile->managed_state().pending_pixel_refs; |
| 761 std::list<skia::LazyPixelRef*>::iterator it = pending_pixel_refs.begin(); | 741 std::list<skia::LazyPixelRef*>::iterator it = pending_pixel_refs.begin(); |
| 762 while (it != pending_pixel_refs.end()) { | 742 while (it != pending_pixel_refs.end()) { |
| 763 if (pending_decode_tasks_.end() != pending_decode_tasks_.find( | 743 if (pending_decode_tasks_.end() != pending_decode_tasks_.find( |
| 764 (*it)->getGenerationID())) { | 744 (*it)->getGenerationID())) { |
| 765 ++it; | 745 ++it; |
| 766 continue; | 746 continue; |
| 767 } | 747 } |
| 768 // TODO(qinmin): passing correct image size to PrepareToDecode(). | 748 // TODO(qinmin): passing correct image size to PrepareToDecode(). |
| 769 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) { | 749 if ((*it)->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) { |
| 770 rendering_stats_.totalDeferredImageCacheHitCount++; | 750 rendering_stats_instrumentation_->IncrementDeferredImageCacheHitCount(); |
| 771 pending_pixel_refs.erase(it++); | 751 pending_pixel_refs.erase(it++); |
| 772 } else { | 752 } else { |
| 773 if (pending_tasks_ >= max_pending_tasks_) | 753 if (pending_tasks_ >= max_pending_tasks_) |
| 774 return; | 754 return; |
| 775 DispatchOneImageDecodeTask(tile, *it); | 755 DispatchOneImageDecodeTask(tile, *it); |
| 776 ++it; | 756 ++it; |
| 777 } | 757 } |
| 778 } | 758 } |
| 779 } | 759 } |
| 780 | 760 |
| 781 void TileManager::DispatchOneImageDecodeTask( | 761 void TileManager::DispatchOneImageDecodeTask( |
| 782 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref) { | 762 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref) { |
| 783 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodeTask"); | 763 TRACE_EVENT0("cc", "TileManager::DispatchOneImageDecodeTask"); |
| 784 uint32_t pixel_ref_id = pixel_ref->getGenerationID(); | 764 uint32_t pixel_ref_id = pixel_ref->getGenerationID(); |
| 785 DCHECK(pending_decode_tasks_.end() == | 765 DCHECK(pending_decode_tasks_.end() == |
| 786 pending_decode_tasks_.find(pixel_ref_id)); | 766 pending_decode_tasks_.find(pixel_ref_id)); |
| 787 pending_decode_tasks_[pixel_ref_id] = pixel_ref; | 767 pending_decode_tasks_[pixel_ref_id] = pixel_ref; |
| 788 | 768 |
| 789 raster_worker_pool_->PostTaskAndReply( | 769 raster_worker_pool_->PostTaskAndReply( |
| 790 base::Bind(&TileManager::RunImageDecodeTask, pixel_ref), | 770 base::Bind(&TileManager::RunImageDecodeTask, |
| 771 pixel_ref, |
| 772 rendering_stats_instrumentation_), |
| 791 base::Bind(&TileManager::OnImageDecodeTaskCompleted, | 773 base::Bind(&TileManager::OnImageDecodeTaskCompleted, |
| 792 base::Unretained(this), | 774 base::Unretained(this), |
| 793 tile, | 775 tile, |
| 794 pixel_ref_id)); | 776 pixel_ref_id)); |
| 795 pending_tasks_++; | 777 pending_tasks_++; |
| 796 } | 778 } |
| 797 | 779 |
| 798 void TileManager::OnImageDecodeTaskCompleted( | 780 void TileManager::OnImageDecodeTaskCompleted( |
| 799 scoped_refptr<Tile> tile, uint32_t pixel_ref_id) { | 781 scoped_refptr<Tile> tile, uint32_t pixel_ref_id) { |
| 800 TRACE_EVENT0("cc", "TileManager::OnImageDecodeTaskCompleted"); | 782 TRACE_EVENT0("cc", "TileManager::OnImageDecodeTaskCompleted"); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 resource_pool_->resource_provider()->MapPixelBuffer(resource_id); | 837 resource_pool_->resource_provider()->MapPixelBuffer(resource_id); |
| 856 | 838 |
| 857 ManagedTileState& managed_tile_state = tile->managed_state(); | 839 ManagedTileState& managed_tile_state = tile->managed_state(); |
| 858 raster_worker_pool_->PostRasterTaskAndReply( | 840 raster_worker_pool_->PostRasterTaskAndReply( |
| 859 tile->picture_pile(), | 841 tile->picture_pile(), |
| 860 managed_tile_state.picture_pile_analysis.is_cheap_to_raster, | 842 managed_tile_state.picture_pile_analysis.is_cheap_to_raster, |
| 861 base::Bind(&TileManager::RunRasterTask, | 843 base::Bind(&TileManager::RunRasterTask, |
| 862 buffer, | 844 buffer, |
| 863 tile->content_rect(), | 845 tile->content_rect(), |
| 864 tile->contents_scale(), | 846 tile->contents_scale(), |
| 865 GetRasterTaskMetadata(*tile)), | 847 GetRasterTaskMetadata(*tile), |
| 848 rendering_stats_instrumentation_), |
| 866 base::Bind(&TileManager::OnRasterTaskCompleted, | 849 base::Bind(&TileManager::OnRasterTaskCompleted, |
| 867 base::Unretained(this), | 850 base::Unretained(this), |
| 868 tile, | 851 tile, |
| 869 base::Passed(&resource), | 852 base::Passed(&resource), |
| 870 manage_tiles_call_count_)); | 853 manage_tiles_call_count_)); |
| 871 pending_tasks_++; | 854 pending_tasks_++; |
| 872 } | 855 } |
| 873 | 856 |
| 874 TileManager::RasterTaskMetadata TileManager::GetRasterTaskMetadata( | 857 TileManager::RasterTaskMetadata TileManager::GetRasterTaskMetadata( |
| 875 const Tile& tile) const { | 858 const Tile& tile) const { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 --raster_state_count_[mts.raster_state][tree][mts.tree_bin[tree]]; | 948 --raster_state_count_[mts.raster_state][tree][mts.tree_bin[tree]]; |
| 966 DCHECK_GE(raster_state_count_[mts.raster_state][tree][mts.tree_bin[tree]], 0); | 949 DCHECK_GE(raster_state_count_[mts.raster_state][tree][mts.tree_bin[tree]], 0); |
| 967 | 950 |
| 968 // Increment count for new bin. | 951 // Increment count for new bin. |
| 969 ++raster_state_count_[mts.raster_state][tree][new_tree_bin]; | 952 ++raster_state_count_[mts.raster_state][tree][new_tree_bin]; |
| 970 | 953 |
| 971 mts.tree_bin[tree] = new_tree_bin; | 954 mts.tree_bin[tree] = new_tree_bin; |
| 972 } | 955 } |
| 973 | 956 |
| 974 // static | 957 // static |
| 975 void TileManager::RunRasterTask(uint8* buffer, | 958 void TileManager::RunRasterTask( |
| 976 const gfx::Rect& rect, | 959 uint8* buffer, |
| 977 float contents_scale, | 960 const gfx::Rect& rect, |
| 978 const RasterTaskMetadata& metadata, | 961 float contents_scale, |
| 979 PicturePileImpl* picture_pile, | 962 const RasterTaskMetadata& metadata, |
| 980 RenderingStats* stats) { | 963 RenderingStatsInstrumentation* stats_instrumentation, |
| 964 PicturePileImpl* picture_pile) { |
| 981 TRACE_EVENT2( | 965 TRACE_EVENT2( |
| 982 "cc", "TileManager::RunRasterTask", | 966 "cc", "TileManager::RunRasterTask", |
| 983 "is_on_pending_tree", | 967 "is_on_pending_tree", |
| 984 metadata.is_tile_in_pending_tree_now_bin, | 968 metadata.is_tile_in_pending_tree_now_bin, |
| 985 "is_low_res", | 969 "is_low_res", |
| 986 metadata.tile_resolution == LOW_RESOLUTION); | 970 metadata.tile_resolution == LOW_RESOLUTION); |
| 987 devtools_instrumentation::ScopedRasterTask raster_task(metadata.layer_id); | 971 devtools_instrumentation::ScopedRasterTask raster_task(metadata.layer_id); |
| 988 | 972 |
| 989 DCHECK(picture_pile); | 973 DCHECK(picture_pile); |
| 990 DCHECK(buffer); | 974 DCHECK(buffer); |
| 991 | 975 |
| 992 SkBitmap bitmap; | 976 SkBitmap bitmap; |
| 993 bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); | 977 bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); |
| 994 bitmap.setPixels(buffer); | 978 bitmap.setPixels(buffer); |
| 995 SkDevice device(bitmap); | 979 SkDevice device(bitmap); |
| 996 SkCanvas canvas(&device); | 980 SkCanvas canvas(&device); |
| 997 | 981 |
| 998 base::TimeTicks begin_time; | 982 base::TimeTicks start_time = stats_instrumentation->StartRecording(); |
| 999 if (stats) | |
| 1000 begin_time = base::TimeTicks::HighResNow(); | |
| 1001 | 983 |
| 1002 int64 total_pixels_rasterized = 0; | 984 int64 total_pixels_rasterized = 0; |
| 1003 picture_pile->Raster(&canvas, rect, contents_scale, | 985 picture_pile->Raster(&canvas, rect, contents_scale, |
| 1004 &total_pixels_rasterized); | 986 &total_pixels_rasterized); |
| 1005 | 987 |
| 1006 if (stats) { | 988 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); |
| 1007 stats->totalPixelsRasterized += total_pixels_rasterized; | |
| 1008 | 989 |
| 1009 base::TimeTicks end_time = base::TimeTicks::HighResNow(); | 990 if (stats_instrumentation->record_rendering_stats()) { |
| 1010 base::TimeDelta duration = end_time - begin_time; | 991 stats_instrumentation->AddRaster(duration, |
| 1011 stats->totalRasterizeTime += duration; | 992 total_pixels_rasterized, |
| 1012 if (metadata.is_tile_in_pending_tree_now_bin) | 993 metadata.is_tile_in_pending_tree_now_bin); |
| 1013 stats->totalRasterizeTimeForNowBinsOnPendingTree += duration; | |
| 1014 | 994 |
| 1015 UMA_HISTOGRAM_CUSTOM_COUNTS("Renderer4.PictureRasterTimeMS", | 995 UMA_HISTOGRAM_CUSTOM_COUNTS("Renderer4.PictureRasterTimeMS", |
| 1016 duration.InMilliseconds(), | 996 duration.InMilliseconds(), |
| 1017 0, | 997 0, |
| 1018 10, | 998 10, |
| 1019 10); | 999 10); |
| 1020 | 1000 |
| 1021 if (metadata.prediction_benchmarking) { | 1001 if (metadata.prediction_benchmarking) { |
| 1022 PicturePileImpl::Analysis analysis; | 1002 PicturePileImpl::Analysis analysis; |
| 1023 picture_pile->AnalyzeInRect(rect, contents_scale, &analysis); | 1003 picture_pile->AnalyzeInRect(rect, contents_scale, &analysis); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 | 1076 |
| 1097 if (is_predicted_transparent) | 1077 if (is_predicted_transparent) |
| 1098 UMA_HISTOGRAM_BOOLEAN( | 1078 UMA_HISTOGRAM_BOOLEAN( |
| 1099 "Renderer4.ColorPredictor.PredictedTransparentIsActually", | 1079 "Renderer4.ColorPredictor.PredictedTransparentIsActually", |
| 1100 is_transparent); | 1080 is_transparent); |
| 1101 UMA_HISTOGRAM_BOOLEAN("Renderer4.ColorPredictor.IsActuallyTransparent", | 1081 UMA_HISTOGRAM_BOOLEAN("Renderer4.ColorPredictor.IsActuallyTransparent", |
| 1102 is_transparent); | 1082 is_transparent); |
| 1103 } | 1083 } |
| 1104 | 1084 |
| 1105 // static | 1085 // static |
| 1106 void TileManager::RunImageDecodeTask(skia::LazyPixelRef* pixel_ref, | 1086 void TileManager::RunImageDecodeTask( |
| 1107 RenderingStats* stats) { | 1087 skia::LazyPixelRef* pixel_ref, |
| 1088 RenderingStatsInstrumentation* stats_instrumentation) { |
| 1108 TRACE_EVENT0("cc", "TileManager::RunImageDecodeTask"); | 1089 TRACE_EVENT0("cc", "TileManager::RunImageDecodeTask"); |
| 1109 base::TimeTicks decode_begin_time; | 1090 base::TimeTicks start_time = stats_instrumentation->StartRecording(); |
| 1110 if (stats) | |
| 1111 decode_begin_time = base::TimeTicks::HighResNow(); | |
| 1112 pixel_ref->Decode(); | 1091 pixel_ref->Decode(); |
| 1113 if (stats) { | 1092 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); |
| 1114 stats->totalDeferredImageDecodeCount++; | 1093 stats_instrumentation->AddDeferredImageDecode(duration); |
| 1115 stats->totalDeferredImageDecodeTime += | |
| 1116 base::TimeTicks::HighResNow() - decode_begin_time; | |
| 1117 } | |
| 1118 } | 1094 } |
| 1119 | 1095 |
| 1120 } // namespace cc | 1096 } // namespace cc |
| OLD | NEW |