Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / layers / layer_perftest.cc
blob1c4519a45fb40fe79850ef991f97145ca645d613
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"
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 virtual void Paint(SkCanvas* canvas,
27 const gfx::Rect& content_rect,
28 gfx::RectF* opaque) OVERRIDE {}
32 class LayerPerfTest : public testing::Test {
33 public:
34 LayerPerfTest()
35 : host_impl_(&proxy_, &shared_bitmap_manager_),
36 fake_client_(FakeLayerTreeHostClient::DIRECT_3D),
37 timer_(kWarmupRuns,
38 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
39 kTimeCheckInterval) {}
41 protected:
42 virtual void SetUp() OVERRIDE {
43 layer_tree_host_ = FakeLayerTreeHost::Create();
44 layer_tree_host_->InitializeSingleThreaded(&fake_client_);
47 virtual void TearDown() OVERRIDE {
48 layer_tree_host_->SetRootLayer(NULL);
49 layer_tree_host_.reset();
52 FakeImplProxy proxy_;
53 TestSharedBitmapManager shared_bitmap_manager_;
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::RectF(0.f, 0.f, 5.f, 5.f));
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