Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / cc / layers / layer_perftest.cc
blob72b2e1345db28804674b1dcaba45aa90fa3eab35
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 "cc/debug/lap_timer.h"
8 #include "cc/resources/layer_painter.h"
9 #include "cc/test/fake_impl_proxy.h"
10 #include "cc/test/fake_layer_tree_host.h"
11 #include "cc/test/fake_layer_tree_host_client.h"
12 #include "cc/test/fake_layer_tree_host_impl.h"
13 #include "cc/test/test_task_graph_runner.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/perf/perf_test.h"
17 namespace cc {
18 namespace {
20 static const int kTimeLimitMillis = 3000;
21 static const int kWarmupRuns = 5;
22 static const int kTimeCheckInterval = 10;
24 class MockLayerPainter : public LayerPainter {
25 public:
26 void Paint(SkCanvas* canvas, const gfx::Rect& content_rect) override {}
30 class LayerPerfTest : public testing::Test {
31 public:
32 LayerPerfTest()
33 : host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_),
34 fake_client_(FakeLayerTreeHostClient::DIRECT_3D),
35 timer_(kWarmupRuns,
36 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
37 kTimeCheckInterval) {}
39 protected:
40 void SetUp() override {
41 layer_tree_host_ = FakeLayerTreeHost::Create(&fake_client_);
42 layer_tree_host_->InitializeSingleThreaded(
43 &fake_client_, base::MessageLoopProxy::current(), nullptr);
46 void TearDown() override {
47 layer_tree_host_->SetRootLayer(nullptr);
48 layer_tree_host_ = nullptr;
51 FakeImplProxy proxy_;
52 TestSharedBitmapManager shared_bitmap_manager_;
53 TestTaskGraphRunner task_graph_runner_;
54 FakeLayerTreeHostImpl host_impl_;
56 FakeLayerTreeHostClient fake_client_;
57 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
58 LapTimer timer_;
61 TEST_F(LayerPerfTest, PushPropertiesTo) {
62 scoped_refptr<Layer> test_layer = Layer::Create();
63 scoped_ptr<LayerImpl> impl_layer =
64 LayerImpl::Create(host_impl_.active_tree(), 1);
66 layer_tree_host_->SetRootLayer(test_layer);
68 float transform_origin_z = 0;
69 bool scrollable = true;
70 bool contents_opaque = true;
71 bool double_sided = true;
72 bool hide_layer_and_subtree = true;
73 bool masks_to_bounds = true;
75 // Properties changed.
76 timer_.Reset();
77 do {
78 test_layer->SetNeedsDisplayRect(gfx::Rect(5, 5));
79 test_layer->SetTransformOrigin(gfx::Point3F(0.f, 0.f, transform_origin_z));
80 test_layer->SetContentsOpaque(contents_opaque);
81 test_layer->SetDoubleSided(double_sided);
82 test_layer->SetHideLayerAndSubtree(hide_layer_and_subtree);
83 test_layer->SetMasksToBounds(masks_to_bounds);
84 test_layer->SetScrollClipLayerId(scrollable ? test_layer->id()
85 : Layer::INVALID_ID);
86 test_layer->PushPropertiesTo(impl_layer.get());
88 transform_origin_z += 0.01f;
89 scrollable = !scrollable;
90 contents_opaque = !contents_opaque;
91 double_sided = !double_sided;
92 hide_layer_and_subtree = !hide_layer_and_subtree;
93 masks_to_bounds = !masks_to_bounds;
95 timer_.NextLap();
96 } while (!timer_.HasTimeLimitExpired());
98 perf_test::PrintResult("push_properties_to",
99 "",
100 "props_changed",
101 timer_.LapsPerSecond(),
102 "runs/s",
103 true);
105 // Properties didn't change.
106 timer_.Reset();
107 do {
108 test_layer->PushPropertiesTo(impl_layer.get());
109 timer_.NextLap();
110 } while (!timer_.HasTimeLimitExpired());
112 perf_test::PrintResult("push_properties_to",
114 "props_didnt_change",
115 timer_.LapsPerSecond(),
116 "runs/s",
117 true);
121 } // namespace
122 } // namespace cc