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/debug/lap_timer.h"
8 #include "cc/test/fake_impl_proxy.h"
9 #include "cc/test/fake_layer_tree_host_impl.h"
10 #include "cc/test/fake_output_surface.h"
11 #include "cc/test/fake_picture_layer_impl.h"
12 #include "cc/test/fake_picture_pile_impl.h"
13 #include "cc/test/impl_side_painting_settings.h"
14 #include "cc/test/test_shared_bitmap_manager.h"
15 #include "cc/trees/layer_tree_impl.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/perf/perf_test.h"
22 static const int kTimeLimitMillis
= 2000;
23 static const int kWarmupRuns
= 5;
24 static const int kTimeCheckInterval
= 10;
26 class PictureLayerImplPerfTest
: public testing::Test
{
28 PictureLayerImplPerfTest()
29 : proxy_(base::MessageLoopProxy::current()),
30 host_impl_(ImplSidePaintingSettings(),
32 &shared_bitmap_manager_
),
34 base::TimeDelta::FromMilliseconds(kTimeLimitMillis
),
35 kTimeCheckInterval
) {}
37 virtual void SetUp() OVERRIDE
{
38 host_impl_
.InitializeRenderer(
39 FakeOutputSurface::Create3d().PassAs
<OutputSurface
>());
42 void SetupPendingTree(const gfx::Size
& layer_bounds
,
43 const gfx::Size
& tile_size
) {
44 scoped_refptr
<FakePicturePileImpl
> pile
=
45 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
46 host_impl_
.CreatePendingTree();
47 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
48 pending_tree
->DetachLayerTree();
50 scoped_ptr
<FakePictureLayerImpl
> pending_layer
=
51 FakePictureLayerImpl::CreateWithPile(pending_tree
, 7, pile
);
52 pending_layer
->SetDrawsContent(true);
53 pending_tree
->SetRootLayer(pending_layer
.PassAs
<LayerImpl
>());
55 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
56 host_impl_
.pending_tree()->LayerById(7));
57 pending_layer_
->DoPostCommitInitializationIfNeeded();
60 void RunLayerRasterTileIteratorTest(const std::string
& test_name
,
62 const gfx::Size
& viewport_size
) {
63 host_impl_
.SetViewportSize(viewport_size
);
64 host_impl_
.pending_tree()->UpdateDrawProperties();
68 int count
= num_tiles
;
69 for (PictureLayerImpl::LayerRasterTileIterator
it(pending_layer_
, false);
75 } while (!timer_
.HasTimeLimitExpired());
77 perf_test::PrintResult("layer_raster_tile_iterator",
80 timer_
.LapsPerSecond(),
86 TestSharedBitmapManager shared_bitmap_manager_
;
88 FakeLayerTreeHostImpl host_impl_
;
89 FakePictureLayerImpl
* pending_layer_
;
93 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest
);
96 TEST_F(PictureLayerImplPerfTest
, LayerRasterTileIterator
) {
97 SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
99 float low_res_factor
= host_impl_
.settings().low_res_contents_scale_factor
;
101 pending_layer_
->AddTiling(low_res_factor
);
102 pending_layer_
->AddTiling(0.3f
);
103 pending_layer_
->AddTiling(0.7f
);
104 pending_layer_
->AddTiling(1.0f
);
105 pending_layer_
->AddTiling(2.0f
);
107 RunLayerRasterTileIteratorTest("32_100x100", 32, gfx::Size(100, 100));
108 RunLayerRasterTileIteratorTest("32_500x500", 32, gfx::Size(500, 500));
109 RunLayerRasterTileIteratorTest("64_100x100", 64, gfx::Size(100, 100));
110 RunLayerRasterTileIteratorTest("64_500x500", 64, gfx::Size(500, 500));