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/resources/picture_pile_impl.h"
7 #include "cc/debug/lap_timer.h"
8 #include "cc/test/fake_picture_pile_impl.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/perf/perf_test.h"
15 const int kTimeLimitMillis
= 2000;
16 const int kWarmupRuns
= 5;
17 const int kTimeCheckInterval
= 10;
19 const int kTileSize
= 100;
20 const int kLayerSize
= 1000;
22 class PicturePileImplPerfTest
: public testing::Test
{
24 PicturePileImplPerfTest()
26 base::TimeDelta::FromMilliseconds(kTimeLimitMillis
),
27 kTimeCheckInterval
) {}
29 void RunAnalyzeTest(const std::string
& test_name
, float contents_scale
) {
30 scoped_refptr
<PicturePileImpl
> pile
= FakePicturePileImpl::CreateFilledPile(
31 gfx::Size(kTileSize
, kTileSize
), gfx::Size(kLayerSize
, kLayerSize
));
32 // Content rect that will align with top-left tile at scale 1.0.
33 gfx::Rect
content_rect(0, 0, kTileSize
, kTileSize
);
35 RasterSource::SolidColorAnalysis analysis
;
38 pile
->PerformSolidColorAnalysis(content_rect
, contents_scale
, &analysis
);
40 } while (!timer_
.HasTimeLimitExpired());
42 perf_test::PrintResult(
43 "analyze", "", test_name
, timer_
.LapsPerSecond(), "runs/s", true);
46 void RunRasterTest(const std::string
& test_name
, float contents_scale
) {
47 scoped_refptr
<PicturePileImpl
> pile
= FakePicturePileImpl::CreateFilledPile(
48 gfx::Size(kTileSize
, kTileSize
), gfx::Size(kLayerSize
, kLayerSize
));
49 // Content rect that will align with top-left tile at scale 1.0.
50 gfx::Rect
content_rect(0, 0, kTileSize
, kTileSize
);
53 bitmap
.allocN32Pixels(1, 1);
54 SkCanvas
canvas(bitmap
);
58 pile
->PlaybackToCanvas(&canvas
, content_rect
, contents_scale
);
60 } while (!timer_
.HasTimeLimitExpired());
62 perf_test::PrintResult(
63 "raster", "", test_name
, timer_
.LapsPerSecond(), "runs/s", true);
70 TEST_F(PicturePileImplPerfTest
, Analyze
) {
71 RunAnalyzeTest("1", 1.0f
);
72 RunAnalyzeTest("4", 0.5f
);
73 RunAnalyzeTest("100", 0.1f
);
76 TEST_F(PicturePileImplPerfTest
, Raster
) {
77 RunRasterTest("1", 1.0f
);
78 RunRasterTest("4", 0.5f
);
79 RunRasterTest("100", 0.1f
);