Roll src/third_party/WebKit 095aee4:2f230fd (svn 197498:197508)
[chromium-blink-merge.git] / cc / playback / picture_pile_impl_perftest.cc
blobe1560400f22cea8e93023cce74d7ea2176262e33
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/playback/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"
12 namespace cc {
13 namespace {
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 {
23 public:
24 PicturePileImplPerfTest()
25 : timer_(kWarmupRuns,
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;
36 timer_.Reset();
37 do {
38 pile->PerformSolidColorAnalysis(content_rect, contents_scale, &analysis);
39 timer_.NextLap();
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);
52 SkBitmap bitmap;
53 bitmap.allocN32Pixels(1, 1);
54 SkCanvas canvas(bitmap);
56 timer_.Reset();
57 do {
58 pile->PlaybackToCanvas(&canvas, content_rect, content_rect,
59 contents_scale);
60 timer_.NextLap();
61 } while (!timer_.HasTimeLimitExpired());
63 perf_test::PrintResult(
64 "raster", "", test_name, timer_.LapsPerSecond(), "runs/s", true);
67 private:
68 LapTimer timer_;
71 TEST_F(PicturePileImplPerfTest, Analyze) {
72 RunAnalyzeTest("1", 1.0f);
73 RunAnalyzeTest("4", 0.5f);
74 RunAnalyzeTest("100", 0.1f);
77 TEST_F(PicturePileImplPerfTest, Raster) {
78 RunRasterTest("1", 1.0f);
79 RunRasterTest("4", 0.5f);
80 RunRasterTest("100", 0.1f);
83 } // namespace
84 } // namespace cc