aw: Move SharedRendererState out of AwContents
[chromium-blink-merge.git] / cc / resources / picture_pile_impl_perftest.cc
blob7e24724197cdfdca559b4b5518b719aef307e265
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"
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, contents_scale);
59 timer_.NextLap();
60 } while (!timer_.HasTimeLimitExpired());
62 perf_test::PrintResult(
63 "raster", "", test_name, timer_.LapsPerSecond(), "runs/s", true);
66 private:
67 LapTimer timer_;
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);
82 } // namespace
83 } // namespace cc