| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/debug/rasterize_and_record_benchmark.h" | 5 #include "cc/debug/rasterize_and_record_benchmark.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "cc/debug/lap_timer.h" | 16 #include "cc/debug/lap_timer.h" |
| 17 #include "cc/debug/rasterize_and_record_benchmark_impl.h" | 17 #include "cc/debug/rasterize_and_record_benchmark_impl.h" |
| 18 #include "cc/layers/content_layer_client.h" | 18 #include "cc/layers/content_layer_client.h" |
| 19 #include "cc/layers/layer.h" | 19 #include "cc/layers/layer.h" |
| 20 #include "cc/layers/picture_layer.h" | |
| 21 #include "cc/playback/display_item_list.h" | 20 #include "cc/playback/display_item_list.h" |
| 22 #include "cc/playback/recording_source.h" | |
| 23 #include "cc/trees/layer_tree_host.h" | 21 #include "cc/trees/layer_tree_host.h" |
| 24 #include "cc/trees/layer_tree_host_common.h" | 22 #include "cc/trees/layer_tree_host_common.h" |
| 25 #include "skia/ext/analysis_canvas.h" | 23 #include "skia/ext/analysis_canvas.h" |
| 26 #include "third_party/skia/include/utils/SkPictureUtils.h" | 24 #include "third_party/skia/include/utils/SkPictureUtils.h" |
| 27 #include "ui/gfx/geometry/rect.h" | 25 #include "ui/gfx/geometry/rect.h" |
| 28 | 26 |
| 29 namespace cc { | 27 namespace cc { |
| 30 | 28 |
| 31 namespace { | 29 namespace { |
| 32 | 30 |
| 33 const int kDefaultRecordRepeatCount = 100; | 31 const int kDefaultRecordRepeatCount = 100; |
| 34 | 32 |
| 35 // Parameters for LapTimer. | 33 // Parameters for LapTimer. |
| 36 const int kTimeLimitMillis = 1; | 34 const int kTimeLimitMillis = 1; |
| 37 const int kWarmupRuns = 0; | 35 const int kWarmupRuns = 0; |
| 38 const int kTimeCheckInterval = 1; | 36 const int kTimeCheckInterval = 1; |
| 39 | 37 |
| 40 const char* kModeSuffixes[RecordingSource::RECORDING_MODE_COUNT] = { | 38 const char* kModeSuffixes[PictureLayer::RECORDING_MODE_COUNT] = { |
| 41 "", | 39 "", |
| 42 "_sk_null_canvas", | 40 "_sk_null_canvas", |
| 43 "_painting_disabled", | 41 "_painting_disabled", |
| 44 "_caching_disabled", | 42 "_caching_disabled", |
| 45 "_construction_disabled", | 43 "_construction_disabled", |
| 46 "_subsequence_caching_disabled"}; | 44 "_subsequence_caching_disabled"}; |
| 47 | 45 |
| 48 } // namespace | 46 } // namespace |
| 49 | 47 |
| 50 RasterizeAndRecordBenchmark::RasterizeAndRecordBenchmark( | 48 RasterizeAndRecordBenchmark::RasterizeAndRecordBenchmark( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 73 host_ = host; | 71 host_ = host; |
| 74 LayerTreeHostCommon::CallFunctionForEveryLayer( | 72 LayerTreeHostCommon::CallFunctionForEveryLayer( |
| 75 host, [this](Layer* layer) { layer->RunMicroBenchmark(this); }); | 73 host, [this](Layer* layer) { layer->RunMicroBenchmark(this); }); |
| 76 | 74 |
| 77 DCHECK(!results_.get()); | 75 DCHECK(!results_.get()); |
| 78 results_ = base::WrapUnique(new base::DictionaryValue); | 76 results_ = base::WrapUnique(new base::DictionaryValue); |
| 79 results_->SetInteger("pixels_recorded", record_results_.pixels_recorded); | 77 results_->SetInteger("pixels_recorded", record_results_.pixels_recorded); |
| 80 results_->SetInteger("picture_memory_usage", | 78 results_->SetInteger("picture_memory_usage", |
| 81 static_cast<int>(record_results_.bytes_used)); | 79 static_cast<int>(record_results_.bytes_used)); |
| 82 | 80 |
| 83 for (int i = 0; i < RecordingSource::RECORDING_MODE_COUNT; i++) { | 81 for (int i = 0; i < PictureLayer::RECORDING_MODE_COUNT; i++) { |
| 84 std::string name = base::StringPrintf("record_time%s_ms", kModeSuffixes[i]); | 82 std::string name = base::StringPrintf("record_time%s_ms", kModeSuffixes[i]); |
| 85 results_->SetDouble(name, | 83 results_->SetDouble(name, |
| 86 record_results_.total_best_time[i].InMillisecondsF()); | 84 record_results_.total_best_time[i].InMillisecondsF()); |
| 87 } | 85 } |
| 88 main_thread_benchmark_done_ = true; | 86 main_thread_benchmark_done_ = true; |
| 89 } | 87 } |
| 90 | 88 |
| 91 void RasterizeAndRecordBenchmark::RecordRasterResults( | 89 void RasterizeAndRecordBenchmark::RecordRasterResults( |
| 92 std::unique_ptr<base::Value> results_value) { | 90 std::unique_ptr<base::Value> results_value) { |
| 93 DCHECK(main_thread_benchmark_done_); | 91 DCHECK(main_thread_benchmark_done_); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 111 } | 109 } |
| 112 | 110 |
| 113 void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) { | 111 void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) { |
| 114 DCHECK(host_); | 112 DCHECK(host_); |
| 115 | 113 |
| 116 if (!layer->DrawsContent()) | 114 if (!layer->DrawsContent()) |
| 117 return; | 115 return; |
| 118 | 116 |
| 119 ContentLayerClient* painter = layer->client(); | 117 ContentLayerClient* painter = layer->client(); |
| 120 | 118 |
| 121 for (int mode_index = 0; mode_index < RecordingSource::RECORDING_MODE_COUNT; | 119 for (int mode_index = 0; mode_index < PictureLayer::RECORDING_MODE_COUNT; |
| 122 mode_index++) { | 120 mode_index++) { |
| 123 ContentLayerClient::PaintingControlSetting painting_control = | 121 ContentLayerClient::PaintingControlSetting painting_control = |
| 124 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL_FOR_TEST; | 122 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL_FOR_TEST; |
| 125 switch (static_cast<RecordingSource::RecordingMode>(mode_index)) { | 123 switch (static_cast<PictureLayer::RecordingMode>(mode_index)) { |
| 126 case RecordingSource::RECORD_NORMALLY: | 124 case PictureLayer::RECORD_NORMALLY: |
| 127 // Already setup for normal recording. | 125 // Already setup for normal recording. |
| 128 break; | 126 break; |
| 129 case RecordingSource::RECORD_WITH_SK_NULL_CANVAS: | 127 case PictureLayer::RECORD_WITH_SK_NULL_CANVAS: |
| 130 // Not supported for Display List recording. | 128 // Not supported for Display List recording. |
| 131 continue; | 129 continue; |
| 132 case RecordingSource::RECORD_WITH_PAINTING_DISABLED: | 130 case PictureLayer::RECORD_WITH_PAINTING_DISABLED: |
| 133 painting_control = ContentLayerClient::DISPLAY_LIST_PAINTING_DISABLED; | 131 painting_control = ContentLayerClient::DISPLAY_LIST_PAINTING_DISABLED; |
| 134 break; | 132 break; |
| 135 case RecordingSource::RECORD_WITH_CACHING_DISABLED: | 133 case PictureLayer::RECORD_WITH_CACHING_DISABLED: |
| 136 painting_control = ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED; | 134 painting_control = ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED; |
| 137 break; | 135 break; |
| 138 case RecordingSource::RECORD_WITH_CONSTRUCTION_DISABLED: | 136 case PictureLayer::RECORD_WITH_CONSTRUCTION_DISABLED: |
| 139 painting_control = | 137 painting_control = |
| 140 ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED; | 138 ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED; |
| 141 break; | 139 break; |
| 142 case RecordingSource::RECORD_WITH_SUBSEQUENCE_CACHING_DISABLED: | 140 case PictureLayer::RECORD_WITH_SUBSEQUENCE_CACHING_DISABLED: |
| 143 painting_control = ContentLayerClient::SUBSEQUENCE_CACHING_DISABLED; | 141 painting_control = ContentLayerClient::SUBSEQUENCE_CACHING_DISABLED; |
| 144 break; | 142 break; |
| 145 default: | 143 default: |
| 146 NOTREACHED(); | 144 NOTREACHED(); |
| 147 } | 145 } |
| 148 base::TimeDelta min_time = base::TimeDelta::Max(); | 146 base::TimeDelta min_time = base::TimeDelta::Max(); |
| 149 size_t memory_used = 0; | 147 size_t memory_used = 0; |
| 150 | 148 |
| 151 scoped_refptr<DisplayItemList> display_list; | 149 scoped_refptr<DisplayItemList> display_list; |
| 152 for (int i = 0; i < record_repeat_count_; ++i) { | 150 for (int i = 0; i < record_repeat_count_; ++i) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 172 } | 170 } |
| 173 | 171 |
| 174 timer.NextLap(); | 172 timer.NextLap(); |
| 175 } while (!timer.HasTimeLimitExpired()); | 173 } while (!timer.HasTimeLimitExpired()); |
| 176 base::TimeDelta duration = | 174 base::TimeDelta duration = |
| 177 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); | 175 base::TimeDelta::FromMillisecondsD(timer.MsPerLap()); |
| 178 if (duration < min_time) | 176 if (duration < min_time) |
| 179 min_time = duration; | 177 min_time = duration; |
| 180 } | 178 } |
| 181 | 179 |
| 182 if (mode_index == RecordingSource::RECORD_NORMALLY) { | 180 if (mode_index == PictureLayer::RECORD_NORMALLY) { |
| 183 record_results_.bytes_used += | 181 record_results_.bytes_used += |
| 184 memory_used + painter->GetApproximateUnsharedMemoryUsage(); | 182 memory_used + painter->GetApproximateUnsharedMemoryUsage(); |
| 185 record_results_.pixels_recorded += painter->PaintableRegion().width() * | 183 record_results_.pixels_recorded += painter->PaintableRegion().width() * |
| 186 painter->PaintableRegion().height(); | 184 painter->PaintableRegion().height(); |
| 187 } | 185 } |
| 188 record_results_.total_best_time[mode_index] += min_time; | 186 record_results_.total_best_time[mode_index] += min_time; |
| 189 } | 187 } |
| 190 } | 188 } |
| 191 | 189 |
| 192 RasterizeAndRecordBenchmark::RecordResults::RecordResults() | 190 RasterizeAndRecordBenchmark::RecordResults::RecordResults() |
| 193 : pixels_recorded(0), bytes_used(0) { | 191 : pixels_recorded(0), bytes_used(0) { |
| 194 } | 192 } |
| 195 | 193 |
| 196 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} | 194 RasterizeAndRecordBenchmark::RecordResults::~RecordResults() {} |
| 197 | 195 |
| 198 } // namespace cc | 196 } // namespace cc |
| OLD | NEW |