Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/debug/rasterize_and_record_benchmark_impl.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 #include <limits> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/values.h" | |
| 12 #include "cc/layers/layer_impl.h" | |
| 13 #include "cc/layers/picture_layer_impl.h" | |
| 14 #include "cc/trees/layer_tree_host_common.h" | |
| 15 #include "cc/trees/layer_tree_host_impl.h" | |
| 16 #include "ui/gfx/rect.h" | |
| 17 | |
| 18 namespace cc { | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 const int kDefaultRasterizeRepeatCount = 100; | |
| 23 | |
| 24 base::TimeTicks Now() { | |
| 25 return base::TimeTicks::IsThreadNowSupported() | |
| 26 ? base::TimeTicks::ThreadNow() | |
| 27 : base::TimeTicks::HighResNow(); | |
| 28 } | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 RasterizeAndRecordBenchmarkImpl::RasterizeAndRecordBenchmarkImpl( | |
| 33 scoped_refptr<base::MessageLoopProxy> origin_loop, | |
| 34 base::Value* value, | |
| 35 const MicroBenchmarkImpl::DoneCallback& callback) | |
| 36 : MicroBenchmarkImpl(callback, origin_loop), | |
| 37 rasterize_repeat_count_(kDefaultRasterizeRepeatCount) { | |
| 38 base::DictionaryValue* settings = NULL; | |
| 39 value->GetAsDictionary(&settings); | |
| 40 if (!settings) | |
| 41 return; | |
| 42 | |
| 43 if (settings->HasKey("rasterize_repeat_count")) | |
| 44 settings->GetInteger("rasterize_repeat_count", &rasterize_repeat_count_); | |
| 45 } | |
| 46 | |
| 47 RasterizeAndRecordBenchmarkImpl::~RasterizeAndRecordBenchmarkImpl() {} | |
| 48 | |
| 49 void RasterizeAndRecordBenchmarkImpl::DidCompleteCommit( | |
| 50 LayerTreeHostImpl* host) { | |
| 51 LayerTreeHostCommon::CallFunctionForSubtree( | |
| 52 host->RootLayer(), | |
| 53 base::Bind(&RasterizeAndRecordBenchmarkImpl::Run, | |
| 54 base::Unretained(this))); | |
| 55 | |
| 56 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | |
| 57 result->SetInteger("pixels_rasterized", rasterize_results_.pixels_rasterized); | |
| 58 result->SetDouble("rasterize_time_ms", | |
| 59 rasterize_results_.total_best_time.InMillisecondsF()); | |
| 60 | |
| 61 NotifyDone(result.PassAs<base::Value>()); | |
| 62 } | |
| 63 | |
| 64 void RasterizeAndRecordBenchmarkImpl::Run(LayerImpl* layer) { | |
| 65 layer->RunMicroBenchmark(this); | |
| 66 } | |
| 67 | |
| 68 void RasterizeAndRecordBenchmarkImpl::RunOnLayer(PictureLayerImpl* layer) { | |
|
enne (OOO)
2013/11/11 19:47:14
I don't understand why this has to run on the comp
vmpstr
2013/11/11 22:38:38
So I tried putting this on the main thread (which
| |
| 69 if (layer->visible_content_rect().IsEmpty()) | |
| 70 return; | |
| 71 | |
| 72 PictureLayerTilingSet tiling_set(layer, layer->content_bounds()); | |
| 73 | |
| 74 PictureLayerTiling* tiling = tiling_set.AddTiling(layer->contents_scale_x()); | |
| 75 tiling->CreateAllTilesForTesting(); | |
|
vmpstr
2013/11/09 01:05:52
This was the only way I could figure out how to cr
enne (OOO)
2013/11/11 19:47:14
I'm not sure why you need tiles here at all. The
vmpstr
2013/11/11 22:38:38
Geometry rect (from the coverage iterator) returns
| |
| 76 for (PictureLayerTiling::CoverageIterator it( | |
| 77 tiling, layer->contents_scale_x(), layer->visible_content_rect()); | |
| 78 it; | |
| 79 ++it) { | |
| 80 DCHECK(*it); | |
| 81 | |
| 82 PicturePileImpl* picture_pile = (*it)->picture_pile(); | |
| 83 gfx::Rect content_rect = (*it)->content_rect(); | |
| 84 float contents_scale = (*it)->contents_scale(); | |
| 85 | |
| 86 base::TimeDelta min_time = | |
| 87 base::TimeDelta::FromInternalValue(std::numeric_limits<int64>::max()); | |
| 88 for (int i = 0; i < rasterize_repeat_count_; ++i) { | |
| 89 SkBitmap bitmap; | |
| 90 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | |
| 91 content_rect.width(), | |
| 92 content_rect.height()); | |
| 93 bitmap.allocPixels(); | |
| 94 | |
| 95 SkBitmapDevice device(bitmap); | |
| 96 SkCanvas canvas(&device); | |
| 97 | |
| 98 base::TimeTicks start = Now(); | |
| 99 picture_pile->RasterToBitmap(&canvas, content_rect, contents_scale, NULL); | |
| 100 base::TimeTicks end = Now(); | |
| 101 base::TimeDelta duration = end - start; | |
| 102 if (duration < min_time) | |
| 103 min_time = duration; | |
| 104 } | |
| 105 | |
| 106 rasterize_results_.pixels_rasterized += | |
| 107 content_rect.width() * content_rect.height(); | |
| 108 rasterize_results_.total_best_time += min_time; | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 RasterizeAndRecordBenchmarkImpl::RasterizeResults::RasterizeResults() | |
| 113 : pixels_rasterized(0) {} | |
| 114 | |
| 115 RasterizeAndRecordBenchmarkImpl::RasterizeResults::~RasterizeResults() {} | |
| 116 | |
| 117 } // namespace cc | |
| OLD | NEW |