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"
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_
),
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 FakeLayerTreeHostImpl host_impl_
;
55 FakeLayerTreeHostClient fake_client_
;
56 scoped_ptr
<FakeLayerTreeHost
> layer_tree_host_
;
60 TEST_F(LayerPerfTest
, PushPropertiesTo
) {
61 scoped_refptr
<Layer
> test_layer
= Layer::Create();
62 scoped_ptr
<LayerImpl
> impl_layer
=
63 LayerImpl::Create(host_impl_
.active_tree(), 1);
65 layer_tree_host_
->SetRootLayer(test_layer
);
67 float transform_origin_z
= 0;
68 bool scrollable
= true;
69 bool contents_opaque
= true;
70 bool double_sided
= true;
71 bool hide_layer_and_subtree
= true;
72 bool masks_to_bounds
= true;
74 // Properties changed.
77 test_layer
->SetNeedsDisplayRect(gfx::Rect(5, 5));
78 test_layer
->SetTransformOrigin(gfx::Point3F(0.f
, 0.f
, transform_origin_z
));
79 test_layer
->SetContentsOpaque(contents_opaque
);
80 test_layer
->SetDoubleSided(double_sided
);
81 test_layer
->SetHideLayerAndSubtree(hide_layer_and_subtree
);
82 test_layer
->SetMasksToBounds(masks_to_bounds
);
83 test_layer
->SetScrollClipLayerId(scrollable
? test_layer
->id()
85 test_layer
->PushPropertiesTo(impl_layer
.get());
87 transform_origin_z
+= 0.01f
;
88 scrollable
= !scrollable
;
89 contents_opaque
= !contents_opaque
;
90 double_sided
= !double_sided
;
91 hide_layer_and_subtree
= !hide_layer_and_subtree
;
92 masks_to_bounds
= !masks_to_bounds
;
95 } while (!timer_
.HasTimeLimitExpired());
97 perf_test::PrintResult("push_properties_to",
100 timer_
.LapsPerSecond(),
104 // Properties didn't change.
107 test_layer
->PushPropertiesTo(impl_layer
.get());
109 } while (!timer_
.HasTimeLimitExpired());
111 perf_test::PrintResult("push_properties_to",
113 "props_didnt_change",
114 timer_
.LapsPerSecond(),