Fix flaky PDFExtensionTest
[chromium-blink-merge.git] / cc / layers / layer_perftest.cc
blobfbe00f37c82bc284253b5664049c8ae8abfe467e
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.
5 #include "cc/layers/layer.h"
7 #include "base/thread_task_runner_handle.h"
8 #include "cc/debug/lap_timer.h"
9 #include "cc/resources/layer_painter.h"
10 #include "cc/test/fake_impl_proxy.h"
11 #include "cc/test/fake_layer_tree_host.h"
12 #include "cc/test/fake_layer_tree_host_client.h"
13 #include "cc/test/fake_layer_tree_host_impl.h"
14 #include "cc/test/test_task_graph_runner.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 = 3000;
22 static const int kWarmupRuns = 5;
23 static const int kTimeCheckInterval = 10;
25 class MockLayerPainter : public LayerPainter {
26 public:
27 void Paint(SkCanvas* canvas, const gfx::Rect& content_rect) override {}
31 class LayerPerfTest : public testing::Test {
32 public:
33 LayerPerfTest()
34 : host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_),
35 fake_client_(FakeLayerTreeHostClient::DIRECT_3D),
36 timer_(kWarmupRuns,
37 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
38 kTimeCheckInterval) {}
40 protected:
41 void SetUp() override {
42 layer_tree_host_ = FakeLayerTreeHost::Create(&fake_client_);
43 layer_tree_host_->InitializeSingleThreaded(
44 &fake_client_, base::ThreadTaskRunnerHandle::Get(), nullptr);
47 void TearDown() override {
48 layer_tree_host_->SetRootLayer(nullptr);
49 layer_tree_host_ = nullptr;
52 FakeImplProxy proxy_;
53 TestSharedBitmapManager shared_bitmap_manager_;
54 TestTaskGraphRunner task_graph_runner_;
55 FakeLayerTreeHostImpl host_impl_;
57 FakeLayerTreeHostClient fake_client_;
58 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
59 LapTimer timer_;
62 TEST_F(LayerPerfTest, PushPropertiesTo) {
63 scoped_refptr<Layer> test_layer = Layer::Create(LayerSettings());
64 scoped_ptr<LayerImpl> impl_layer =
65 LayerImpl::Create(host_impl_.active_tree(), 1);
67 layer_tree_host_->SetRootLayer(test_layer);
69 float transform_origin_z = 0;
70 bool scrollable = true;
71 bool contents_opaque = true;
72 bool double_sided = true;
73 bool hide_layer_and_subtree = true;
74 bool masks_to_bounds = true;
76 // Properties changed.
77 timer_.Reset();
78 do {
79 test_layer->SetNeedsDisplayRect(gfx::Rect(5, 5));
80 test_layer->SetTransformOrigin(gfx::Point3F(0.f, 0.f, transform_origin_z));
81 test_layer->SetContentsOpaque(contents_opaque);
82 test_layer->SetDoubleSided(double_sided);
83 test_layer->SetHideLayerAndSubtree(hide_layer_and_subtree);
84 test_layer->SetMasksToBounds(masks_to_bounds);
85 test_layer->SetScrollClipLayerId(scrollable ? test_layer->id()
86 : Layer::INVALID_ID);
87 test_layer->PushPropertiesTo(impl_layer.get());
89 transform_origin_z += 0.01f;
90 scrollable = !scrollable;
91 contents_opaque = !contents_opaque;
92 double_sided = !double_sided;
93 hide_layer_and_subtree = !hide_layer_and_subtree;
94 masks_to_bounds = !masks_to_bounds;
96 timer_.NextLap();
97 } while (!timer_.HasTimeLimitExpired());
99 perf_test::PrintResult("push_properties_to",
101 "props_changed",
102 timer_.LapsPerSecond(),
103 "runs/s",
104 true);
106 // Properties didn't change.
107 timer_.Reset();
108 do {
109 test_layer->PushPropertiesTo(impl_layer.get());
110 timer_.NextLap();
111 } while (!timer_.HasTimeLimitExpired());
113 perf_test::PrintResult("push_properties_to",
115 "props_didnt_change",
116 timer_.LapsPerSecond(),
117 "runs/s",
118 true);
122 } // namespace
123 } // namespace cc