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"
20 static const int kTimeLimitMillis
= 3000;
21 static const int kWarmupRuns
= 5;
22 static const int kTimeCheckInterval
= 10;
24 class MockLayerPainter
: public LayerPainter
{
26 void Paint(SkCanvas
* canvas
, const gfx::Rect
& content_rect
) override
{}
30 class LayerPerfTest
: public testing::Test
{
33 : host_impl_(&proxy_
, &shared_bitmap_manager_
, &task_graph_runner_
),
34 fake_client_(FakeLayerTreeHostClient::DIRECT_3D
),
36 base::TimeDelta::FromMilliseconds(kTimeLimitMillis
),
37 kTimeCheckInterval
) {}
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;
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_
;
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.
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()
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
;
96 } while (!timer_
.HasTimeLimitExpired());
98 perf_test::PrintResult("push_properties_to",
101 timer_
.LapsPerSecond(),
105 // Properties didn't change.
108 test_layer
->PushPropertiesTo(impl_layer
.get());
110 } while (!timer_
.HasTimeLimitExpired());
112 perf_test::PrintResult("push_properties_to",
114 "props_didnt_change",
115 timer_
.LapsPerSecond(),