| 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/tile_manager.h" | 5 #include "cc/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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 state->Set("resolution", TileResolutionAsValue(resolution).release()); | 169 state->Set("resolution", TileResolutionAsValue(resolution).release()); |
| 170 state->Set("time_to_needed_in_seconds", MathUtil::asValueSafely(time_to_needed
_in_seconds).release()); | 170 state->Set("time_to_needed_in_seconds", MathUtil::asValueSafely(time_to_needed
_in_seconds).release()); |
| 171 state->Set("distance_to_visible_in_pixels", MathUtil::asValueSafely(distance_t
o_visible_in_pixels).release()); | 171 state->Set("distance_to_visible_in_pixels", MathUtil::asValueSafely(distance_t
o_visible_in_pixels).release()); |
| 172 return state.PassAs<base::Value>(); | 172 return state.PassAs<base::Value>(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 TileManager::TileManager( | 175 TileManager::TileManager( |
| 176 TileManagerClient* client, | 176 TileManagerClient* client, |
| 177 ResourceProvider* resource_provider, | 177 ResourceProvider* resource_provider, |
| 178 size_t num_raster_threads, | 178 size_t num_raster_threads, |
| 179 bool use_cheapness_estimator) | 179 bool use_cheapness_estimator, |
| 180 bool solid_color_benchmarking) |
| 180 : client_(client), | 181 : client_(client), |
| 181 resource_pool_(ResourcePool::Create(resource_provider)), | 182 resource_pool_(ResourcePool::Create(resource_provider)), |
| 182 raster_worker_pool_(RasterWorkerPool::Create(this, num_raster_threads)), | 183 raster_worker_pool_(RasterWorkerPool::Create(this, num_raster_threads)), |
| 183 manage_tiles_pending_(false), | 184 manage_tiles_pending_(false), |
| 184 manage_tiles_call_count_(0), | 185 manage_tiles_call_count_(0), |
| 185 bytes_pending_upload_(0), | 186 bytes_pending_upload_(0), |
| 186 has_performed_uploads_since_last_flush_(false), | 187 has_performed_uploads_since_last_flush_(false), |
| 187 ever_exceeded_memory_budget_(false), | 188 ever_exceeded_memory_budget_(false), |
| 188 record_rendering_stats_(false), | 189 record_rendering_stats_(false), |
| 189 use_cheapness_estimator_(use_cheapness_estimator), | 190 use_cheapness_estimator_(use_cheapness_estimator), |
| 190 allow_cheap_tasks_(true), | 191 allow_cheap_tasks_(true), |
| 191 did_schedule_cheap_tasks_(false) { | 192 did_schedule_cheap_tasks_(false), |
| 193 solid_color_benchmarking_(solid_color_benchmarking) { |
| 192 for (int i = 0; i < NUM_STATES; ++i) { | 194 for (int i = 0; i < NUM_STATES; ++i) { |
| 193 for (int j = 0; j < NUM_TREES; ++j) { | 195 for (int j = 0; j < NUM_TREES; ++j) { |
| 194 for (int k = 0; k < NUM_BINS; ++k) | 196 for (int k = 0; k < NUM_BINS; ++k) |
| 195 raster_state_count_[i][j][k] = 0; | 197 raster_state_count_[i][j][k] = 0; |
| 196 } | 198 } |
| 197 } | 199 } |
| 198 } | 200 } |
| 199 | 201 |
| 200 TileManager::~TileManager() { | 202 TileManager::~TileManager() { |
| 201 // Reset global state and manage. This should cause | 203 // Reset global state and manage. This should cause |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 base::Passed(&resource), | 812 base::Passed(&resource), |
| 811 manage_tiles_call_count_)); | 813 manage_tiles_call_count_)); |
| 812 did_schedule_cheap_tasks_ |= is_cheap; | 814 did_schedule_cheap_tasks_ |= is_cheap; |
| 813 } | 815 } |
| 814 | 816 |
| 815 TileManager::RasterTaskMetadata TileManager::GetRasterTaskMetadata( | 817 TileManager::RasterTaskMetadata TileManager::GetRasterTaskMetadata( |
| 816 const Tile& tile) const { | 818 const Tile& tile) const { |
| 817 RasterTaskMetadata metadata; | 819 RasterTaskMetadata metadata; |
| 818 const ManagedTileState& mts = tile.managed_state(); | 820 const ManagedTileState& mts = tile.managed_state(); |
| 819 metadata.use_cheapness_estimator = use_cheapness_estimator_; | 821 metadata.use_cheapness_estimator = use_cheapness_estimator_; |
| 822 metadata.solid_color_benchmarking = solid_color_benchmarking_; |
| 820 metadata.is_tile_in_pending_tree_now_bin = | 823 metadata.is_tile_in_pending_tree_now_bin = |
| 821 mts.tree_bin[PENDING_TREE] == NOW_BIN; | 824 mts.tree_bin[PENDING_TREE] == NOW_BIN; |
| 822 metadata.tile_resolution = mts.resolution; | 825 metadata.tile_resolution = mts.resolution; |
| 823 return metadata; | 826 return metadata; |
| 824 } | 827 } |
| 825 | 828 |
| 826 void TileManager::OnRasterTaskCompleted( | 829 void TileManager::OnRasterTaskCompleted( |
| 827 scoped_refptr<Tile> tile, | 830 scoped_refptr<Tile> tile, |
| 828 scoped_ptr<ResourcePool::Resource> resource, | 831 scoped_ptr<ResourcePool::Resource> resource, |
| 829 int manage_tiles_call_count_when_dispatched) { | 832 int manage_tiles_call_count_when_dispatched) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 SkDevice device(bitmap); | 935 SkDevice device(bitmap); |
| 933 SkCanvas canvas(&device); | 936 SkCanvas canvas(&device); |
| 934 | 937 |
| 935 base::TimeTicks begin_time; | 938 base::TimeTicks begin_time; |
| 936 if (stats) | 939 if (stats) |
| 937 begin_time = base::TimeTicks::HighResNow(); | 940 begin_time = base::TimeTicks::HighResNow(); |
| 938 | 941 |
| 939 int64 total_pixels_rasterized = 0; | 942 int64 total_pixels_rasterized = 0; |
| 940 picture_pile->Raster(&canvas, rect, contents_scale, | 943 picture_pile->Raster(&canvas, rect, contents_scale, |
| 941 &total_pixels_rasterized); | 944 &total_pixels_rasterized); |
| 942 | |
| 943 if (stats) { | 945 if (stats) { |
| 944 stats->totalPixelsRasterized += total_pixels_rasterized; | 946 stats->totalPixelsRasterized += total_pixels_rasterized; |
| 945 | 947 |
| 946 base::TimeTicks end_time = base::TimeTicks::HighResNow(); | 948 base::TimeTicks end_time = base::TimeTicks::HighResNow(); |
| 947 base::TimeDelta duration = end_time - begin_time; | 949 base::TimeDelta duration = end_time - begin_time; |
| 948 stats->totalRasterizeTime += duration; | 950 stats->totalRasterizeTime += duration; |
| 949 if (metadata.is_tile_in_pending_tree_now_bin) | 951 if (metadata.is_tile_in_pending_tree_now_bin) |
| 950 stats->totalRasterizeTimeForNowBinsOnPendingTree += duration; | 952 stats->totalRasterizeTimeForNowBinsOnPendingTree += duration; |
| 951 | 953 |
| 952 UMA_HISTOGRAM_CUSTOM_COUNTS("Renderer4.PictureRasterTimeMS", | 954 UMA_HISTOGRAM_CUSTOM_COUNTS("Renderer4.PictureRasterTimeMS", |
| 953 duration.InMilliseconds(), | 955 duration.InMilliseconds(), |
| 954 0, | 956 0, |
| 955 10, | 957 10, |
| 956 10); | 958 10); |
| 957 | 959 |
| 958 if (metadata.use_cheapness_estimator) { | 960 if (metadata.use_cheapness_estimator) { |
| 959 bool is_predicted_cheap = | 961 bool is_predicted_cheap = |
| 960 picture_pile->IsCheapInRect(rect, contents_scale); | 962 picture_pile->IsCheapInRect(rect, contents_scale); |
| 961 bool is_actually_cheap = duration.InMillisecondsF() <= 1.0f; | 963 bool is_actually_cheap = duration.InMillisecondsF() <= 1.0f; |
| 962 RecordCheapnessPredictorResults(is_predicted_cheap, is_actually_cheap); | 964 RecordCheapnessPredictorResults(is_predicted_cheap, is_actually_cheap); |
| 963 } | 965 } |
| 964 } | 966 } |
| 967 |
| 968 if (metadata.solid_color_benchmarking) { |
| 969 SkColor solid_color; |
| 970 bool is_predicted_solid = |
| 971 picture_pile->GetColorIfSolidInRect(rect, contents_scale, &solid_color); |
| 972 |
| 973 RecordSolidColorPredictorResults(buffer, |
| 974 rect.width() * rect.height(), |
| 975 is_predicted_solid, |
| 976 solid_color); |
| 977 } |
| 965 } | 978 } |
| 966 | 979 |
| 967 // static | 980 // static |
| 968 void TileManager::RecordCheapnessPredictorResults(bool is_predicted_cheap, | 981 void TileManager::RecordCheapnessPredictorResults(bool is_predicted_cheap, |
| 969 bool is_actually_cheap) { | 982 bool is_actually_cheap) { |
| 970 if (is_predicted_cheap && !is_actually_cheap) | 983 if (is_predicted_cheap && !is_actually_cheap) |
| 971 UMA_HISTOGRAM_BOOLEAN("Renderer4.CheapPredictorBadlyWrong", true); | 984 UMA_HISTOGRAM_BOOLEAN("Renderer4.CheapPredictorBadlyWrong", true); |
| 972 else if (!is_predicted_cheap && is_actually_cheap) | 985 else if (!is_predicted_cheap && is_actually_cheap) |
| 973 UMA_HISTOGRAM_BOOLEAN("Renderer4.CheapPredictorSafelyWrong", true); | 986 UMA_HISTOGRAM_BOOLEAN("Renderer4.CheapPredictorSafelyWrong", true); |
| 974 | 987 |
| 975 UMA_HISTOGRAM_BOOLEAN("Renderer4.CheapPredictorAccuracy", | 988 UMA_HISTOGRAM_BOOLEAN("Renderer4.CheapPredictorAccuracy", |
| 976 is_predicted_cheap == is_actually_cheap); | 989 is_predicted_cheap == is_actually_cheap); |
| 977 } | 990 } |
| 978 | 991 |
| 992 //static |
| 993 void TileManager::RecordSolidColorPredictorResults(uint8* actual_bytes, |
| 994 size_t pixel_count, |
| 995 bool is_predicted_solid, |
| 996 SkColor predicted_color) { |
| 997 CHECK(pixel_count > 0); |
| 998 |
| 999 bool is_actually_solid = true; |
| 1000 SkColor actual_color = SkColorSetARGB(actual_bytes[3], |
| 1001 actual_bytes[2], |
| 1002 actual_bytes[1], |
| 1003 actual_bytes[0]); |
| 1004 for (int i = (pixel_count-1)*4; i >= 0; i -= 4) { |
| 1005 SkColor current_color = SkColorSetARGB(actual_bytes[i+3], |
| 1006 actual_bytes[i+2], |
| 1007 actual_bytes[i+1], |
| 1008 actual_bytes[i]); |
| 1009 if (current_color != actual_color) { |
| 1010 is_actually_solid = false; |
| 1011 break; |
| 1012 } |
| 1013 } |
| 1014 |
| 1015 if (is_predicted_solid && !is_actually_solid) |
| 1016 UMA_HISTOGRAM_BOOLEAN("Renderer4.ColorPredictor.WrongActualNotSolid", true); |
| 1017 else if (is_predicted_solid && |
| 1018 is_actually_solid && |
| 1019 predicted_color != actual_color) |
| 1020 UMA_HISTOGRAM_BOOLEAN("Renderer4.ColorPredictor.WrongColor", true); |
| 1021 else if(!is_predicted_solid && is_actually_solid) |
| 1022 UMA_HISTOGRAM_BOOLEAN("Renderer4.ColorPredictor.WrongActualSolid", true); |
| 1023 |
| 1024 bool correct_guess = (is_predicted_solid && is_actually_solid && |
| 1025 predicted_color == actual_color) || |
| 1026 (!is_predicted_solid && !is_actually_solid); |
| 1027 UMA_HISTOGRAM_BOOLEAN("Renderer4.ColorPredictor.Accuracy", correct_guess); |
| 1028 |
| 1029 if (correct_guess) |
| 1030 UMA_HISTOGRAM_BOOLEAN("Renderer4.ColorPredictor.IsCorrectSolid", |
| 1031 is_predicted_solid); |
| 1032 } |
| 1033 |
| 979 // static | 1034 // static |
| 980 void TileManager::RunImageDecodeTask(skia::LazyPixelRef* pixel_ref, | 1035 void TileManager::RunImageDecodeTask(skia::LazyPixelRef* pixel_ref, |
| 981 RenderingStats* stats) { | 1036 RenderingStats* stats) { |
| 982 TRACE_EVENT0("cc", "TileManager::RunImageDecodeTask"); | 1037 TRACE_EVENT0("cc", "TileManager::RunImageDecodeTask"); |
| 983 base::TimeTicks decode_begin_time; | 1038 base::TimeTicks decode_begin_time; |
| 984 if (stats) | 1039 if (stats) |
| 985 decode_begin_time = base::TimeTicks::HighResNow(); | 1040 decode_begin_time = base::TimeTicks::HighResNow(); |
| 986 pixel_ref->Decode(); | 1041 pixel_ref->Decode(); |
| 987 if (stats) { | 1042 if (stats) { |
| 988 stats->totalDeferredImageDecodeCount++; | 1043 stats->totalDeferredImageDecodeCount++; |
| 989 stats->totalDeferredImageDecodeTime += | 1044 stats->totalDeferredImageDecodeTime += |
| 990 base::TimeTicks::HighResNow() - decode_begin_time; | 1045 base::TimeTicks::HighResNow() - decode_begin_time; |
| 991 } | 1046 } |
| 992 } | 1047 } |
| 993 | 1048 |
| 994 } // namespace cc | 1049 } // namespace cc |
| OLD | NEW |