cc: Remove ResourceUpdateQueue and ResourceUpdateController.
[chromium-blink-merge.git] / cc / layers / layer_perftest.cc
blob0c0fb4185a4741e5ccead2ef6732ed0da2d51c6c
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/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 LayerPerfTest : public testing::Test {
25 public:
26 LayerPerfTest()
27 : host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_),
28 fake_client_(FakeLayerTreeHostClient::DIRECT_3D),
29 timer_(kWarmupRuns,
30 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
31 kTimeCheckInterval) {}
33 protected:
34 void SetUp() override {
35 layer_tree_host_ =
36 FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_);
37 layer_tree_host_->InitializeSingleThreaded(
38 &fake_client_, base::ThreadTaskRunnerHandle::Get(), nullptr);
41 void TearDown() override {
42 layer_tree_host_->SetRootLayer(nullptr);
43 layer_tree_host_ = nullptr;
46 FakeImplProxy proxy_;
47 TestSharedBitmapManager shared_bitmap_manager_;
48 TestTaskGraphRunner task_graph_runner_;
49 FakeLayerTreeHostImpl host_impl_;
51 FakeLayerTreeHostClient fake_client_;
52 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
53 LapTimer timer_;
56 TEST_F(LayerPerfTest, PushPropertiesTo) {
57 scoped_refptr<Layer> test_layer = Layer::Create(LayerSettings());
58 scoped_ptr<LayerImpl> impl_layer =
59 LayerImpl::Create(host_impl_.active_tree(), 1);
61 layer_tree_host_->SetRootLayer(test_layer);
63 float transform_origin_z = 0;
64 bool scrollable = true;
65 bool contents_opaque = true;
66 bool double_sided = true;
67 bool hide_layer_and_subtree = true;
68 bool masks_to_bounds = true;
70 // Properties changed.
71 timer_.Reset();
72 do {
73 test_layer->SetNeedsDisplayRect(gfx::Rect(5, 5));
74 test_layer->SetTransformOrigin(gfx::Point3F(0.f, 0.f, transform_origin_z));
75 test_layer->SetContentsOpaque(contents_opaque);
76 test_layer->SetDoubleSided(double_sided);
77 test_layer->SetHideLayerAndSubtree(hide_layer_and_subtree);
78 test_layer->SetMasksToBounds(masks_to_bounds);
79 test_layer->SetScrollClipLayerId(scrollable ? test_layer->id()
80 : Layer::INVALID_ID);
81 test_layer->PushPropertiesTo(impl_layer.get());
83 transform_origin_z += 0.01f;
84 scrollable = !scrollable;
85 contents_opaque = !contents_opaque;
86 double_sided = !double_sided;
87 hide_layer_and_subtree = !hide_layer_and_subtree;
88 masks_to_bounds = !masks_to_bounds;
90 timer_.NextLap();
91 } while (!timer_.HasTimeLimitExpired());
93 perf_test::PrintResult("push_properties_to",
94 "",
95 "props_changed",
96 timer_.LapsPerSecond(),
97 "runs/s",
98 true);
100 // Properties didn't change.
101 timer_.Reset();
102 do {
103 test_layer->PushPropertiesTo(impl_layer.get());
104 timer_.NextLap();
105 } while (!timer_.HasTimeLimitExpired());
107 perf_test::PrintResult("push_properties_to",
109 "props_didnt_change",
110 timer_.LapsPerSecond(),
111 "runs/s",
112 true);
116 } // namespace
117 } // namespace cc