1 // Copyright 2014 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/picture_layer_impl.h"
7 #include "cc/test/fake_impl_proxy.h"
8 #include "cc/test/fake_layer_tree_host_impl.h"
9 #include "cc/test/fake_output_surface.h"
10 #include "cc/test/fake_picture_layer_impl.h"
11 #include "cc/test/fake_picture_pile_impl.h"
12 #include "cc/test/impl_side_painting_settings.h"
13 #include "cc/test/test_shared_bitmap_manager.h"
14 #include "cc/trees/layer_tree_impl.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/perf/perf_test.h"
21 static const int kTimeLimitMillis
= 2000;
22 static const int kWarmupRuns
= 5;
23 static const int kTimeCheckInterval
= 10;
25 class PictureLayerImplPerfTest
: public testing::Test
{
27 PictureLayerImplPerfTest()
29 proxy_(base::MessageLoopProxy::current()),
30 host_impl_(ImplSidePaintingSettings(),
32 &shared_bitmap_manager_
) {}
34 virtual void SetUp() OVERRIDE
{
35 host_impl_
.InitializeRenderer(
36 FakeOutputSurface::Create3d().PassAs
<OutputSurface
>());
39 void SetupPendingTree(const gfx::Size
& layer_bounds
,
40 const gfx::Size
& tile_size
) {
41 scoped_refptr
<FakePicturePileImpl
> pile
=
42 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
43 host_impl_
.CreatePendingTree();
44 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
45 pending_tree
->DetachLayerTree();
47 scoped_ptr
<FakePictureLayerImpl
> pending_layer
=
48 FakePictureLayerImpl::CreateWithPile(pending_tree
, 7, pile
);
49 pending_layer
->SetDrawsContent(true);
50 pending_tree
->SetRootLayer(pending_layer
.PassAs
<LayerImpl
>());
52 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
53 host_impl_
.pending_tree()->LayerById(7));
54 pending_layer_
->DoPostCommitInitializationIfNeeded();
57 void EndTest() { elapsed_
= base::TimeTicks::HighResNow() - start_time_
; }
61 if (num_runs_
== kWarmupRuns
)
62 start_time_
= base::TimeTicks::HighResNow();
64 if (!start_time_
.is_null() && (num_runs_
% kTimeCheckInterval
) == 0) {
65 base::TimeDelta elapsed
= base::TimeTicks::HighResNow() - start_time_
;
66 if (elapsed
>= base::TimeDelta::FromMilliseconds(kTimeLimitMillis
)) {
74 void RunLayerRasterTileIteratorTest(const std::string
& test_name
,
76 const gfx::Size
& viewport_size
) {
77 start_time_
= base::TimeTicks();
80 host_impl_
.SetViewportSize(viewport_size
);
81 host_impl_
.pending_tree()->UpdateDrawProperties();
84 int count
= num_tiles
;
85 for (PictureLayerImpl::LayerRasterTileIterator
it(pending_layer_
, false);
92 perf_test::PrintResult("layer_raster_tile_iterator",
95 num_runs_
/ elapsed_
.InSecondsF(),
101 base::TimeTicks start_time_
;
102 base::TimeDelta elapsed_
;
105 TestSharedBitmapManager shared_bitmap_manager_
;
106 FakeImplProxy proxy_
;
107 FakeLayerTreeHostImpl host_impl_
;
108 FakePictureLayerImpl
* pending_layer_
;
111 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest
);
114 TEST_F(PictureLayerImplPerfTest
, LayerRasterTileIterator
) {
115 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
117 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
119 pending_layer_
->AddTiling(low_res_factor
);
120 pending_layer_
->AddTiling(0.3f
);
121 pending_layer_
->AddTiling(0.7f
);
122 pending_layer_
->AddTiling(1.0f
);
123 pending_layer_
->AddTiling(2.0f
);
125 RunLayerRasterTileIteratorTest("32_100x100", 32, gfx::Size(100, 100));
126 RunLayerRasterTileIteratorTest("32_500x500", 32, gfx::Size(500, 500));
127 RunLayerRasterTileIteratorTest("64_100x100", 64, gfx::Size(100, 100));
128 RunLayerRasterTileIteratorTest("64_500x500", 64, gfx::Size(500, 500));