Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / cc / layers / picture_layer_impl_perftest.cc
blob5279c92708f2af278f50562bc30c3f9d5fc781f5
1 // Copyright 2014 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.
5 #include "cc/layers/picture_layer_impl.h"
7 #include "cc/test/fake_impl_proxy.h"
8 #include "cc/test/fake_layer_tree_host_impl.h"
9 #include "cc/test/fake_output_surface.h"
10 #include "cc/test/fake_picture_layer_impl.h"
11 #include "cc/test/fake_picture_pile_impl.h"
12 #include "cc/test/impl_side_painting_settings.h"
13 #include "cc/test/test_shared_bitmap_manager.h"
14 #include "cc/trees/layer_tree_impl.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/perf/perf_test.h"
18 namespace cc {
19 namespace {
21 static const int kTimeLimitMillis = 2000;
22 static const int kWarmupRuns = 5;
23 static const int kTimeCheckInterval = 10;
25 class PictureLayerImplPerfTest : public testing::Test {
26 public:
27 PictureLayerImplPerfTest()
28 : num_runs_(0),
29 proxy_(base::MessageLoopProxy::current()),
30 host_impl_(ImplSidePaintingSettings(),
31 &proxy_,
32 &shared_bitmap_manager_) {}
34 virtual void SetUp() OVERRIDE {
35 host_impl_.InitializeRenderer(
36 FakeOutputSurface::Create3d().PassAs<OutputSurface>());
39 void SetupPendingTree(const gfx::Size& layer_bounds,
40 const gfx::Size& tile_size) {
41 scoped_refptr<FakePicturePileImpl> pile =
42 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
43 host_impl_.CreatePendingTree();
44 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
45 pending_tree->DetachLayerTree();
47 scoped_ptr<FakePictureLayerImpl> pending_layer =
48 FakePictureLayerImpl::CreateWithPile(pending_tree, 7, pile);
49 pending_layer->SetDrawsContent(true);
50 pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>());
52 pending_layer_ = static_cast<FakePictureLayerImpl*>(
53 host_impl_.pending_tree()->LayerById(7));
54 pending_layer_->DoPostCommitInitializationIfNeeded();
57 void EndTest() { elapsed_ = base::TimeTicks::HighResNow() - start_time_; }
59 bool DidRun() {
60 ++num_runs_;
61 if (num_runs_ == kWarmupRuns)
62 start_time_ = base::TimeTicks::HighResNow();
64 if (!start_time_.is_null() && (num_runs_ % kTimeCheckInterval) == 0) {
65 base::TimeDelta elapsed = base::TimeTicks::HighResNow() - start_time_;
66 if (elapsed >= base::TimeDelta::FromMilliseconds(kTimeLimitMillis)) {
67 elapsed_ = elapsed;
68 return false;
71 return true;
74 void RunLayerRasterTileIteratorTest(const std::string& test_name,
75 int num_tiles,
76 const gfx::Size& viewport_size) {
77 start_time_ = base::TimeTicks();
78 num_runs_ = 0;
80 host_impl_.SetViewportSize(viewport_size);
81 host_impl_.pending_tree()->UpdateDrawProperties();
83 do {
84 int count = num_tiles;
85 for (PictureLayerImpl::LayerRasterTileIterator it(pending_layer_, false);
86 it && count;
87 ++it) {
88 --count;
90 } while (DidRun());
92 perf_test::PrintResult("layer_raster_tile_iterator",
93 "",
94 test_name,
95 num_runs_ / elapsed_.InSecondsF(),
96 "runs/s",
97 true);
100 protected:
101 base::TimeTicks start_time_;
102 base::TimeDelta elapsed_;
103 int num_runs_;
105 TestSharedBitmapManager shared_bitmap_manager_;
106 FakeImplProxy proxy_;
107 FakeLayerTreeHostImpl host_impl_;
108 FakePictureLayerImpl* pending_layer_;
110 private:
111 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest);
114 TEST_F(PictureLayerImplPerfTest, LayerRasterTileIterator) {
115 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
117 float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
119 pending_layer_->AddTiling(low_res_factor);
120 pending_layer_->AddTiling(0.3f);
121 pending_layer_->AddTiling(0.7f);
122 pending_layer_->AddTiling(1.0f);
123 pending_layer_->AddTiling(2.0f);
125 RunLayerRasterTileIteratorTest("32_100x100", 32, gfx::Size(100, 100));
126 RunLayerRasterTileIteratorTest("32_500x500", 32, gfx::Size(500, 500));
127 RunLayerRasterTileIteratorTest("64_100x100", 64, gfx::Size(100, 100));
128 RunLayerRasterTileIteratorTest("64_500x500", 64, gfx::Size(500, 500));
131 } // namespace
132 } // namespace cc