summaryrefslogtreecommitdiffstats
path: root/chromium/cc/resources/picture_pile_impl_perftest.cc
blob: 7ced0eaa1be7635698f5b702a27b3dab928dde63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/resources/picture_pile_impl.h"

#include "cc/debug/lap_timer.h"
#include "cc/test/fake_picture_pile_impl.h"
#include "cc/test/fake_rendering_stats_instrumentation.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/perf/perf_test.h"

namespace cc {
namespace {

const int kTimeLimitMillis = 2000;
const int kWarmupRuns = 5;
const int kTimeCheckInterval = 10;

const int kTileSize = 100;
const int kLayerSize = 1000;

class PicturePileImplPerfTest : public testing::Test {
 public:
  PicturePileImplPerfTest()
      : timer_(kWarmupRuns,
               base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
               kTimeCheckInterval) {}

  void RunAnalyzeTest(const std::string& test_name, float contents_scale) {
    scoped_refptr<PicturePileImpl> pile = FakePicturePileImpl::CreateFilledPile(
        gfx::Size(kTileSize, kTileSize), gfx::Size(kLayerSize, kLayerSize));
    // Content rect that will align with top-left tile at scale 1.0.
    gfx::Rect content_rect(0, 0, kTileSize, kTileSize);

    PicturePileImpl::Analysis analysis;
    timer_.Reset();
    do {
      pile->AnalyzeInRect(content_rect, contents_scale, &analysis);
      timer_.NextLap();
    } while (!timer_.HasTimeLimitExpired());

    perf_test::PrintResult(
        "analyze", "", test_name, timer_.LapsPerSecond(), "runs/s", true);
  }

  void RunRasterTest(const std::string& test_name, float contents_scale) {
    scoped_refptr<PicturePileImpl> pile = FakePicturePileImpl::CreateFilledPile(
        gfx::Size(kTileSize, kTileSize), gfx::Size(kLayerSize, kLayerSize));
    // Content rect that will align with top-left tile at scale 1.0.
    gfx::Rect content_rect(0, 0, kTileSize, kTileSize);

    SkBitmap bitmap;
    bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
    bitmap.allocPixels();
    SkCanvas canvas(bitmap);

    FakeRenderingStatsInstrumentation rendering_stats_instrumentation;
    timer_.Reset();
    do {
      pile->RasterToBitmap(&canvas,
                           content_rect,
                           contents_scale,
                           &rendering_stats_instrumentation);
      timer_.NextLap();
    } while (!timer_.HasTimeLimitExpired());

    perf_test::PrintResult(
        "raster", "", test_name, timer_.LapsPerSecond(), "runs/s", true);
  }

 private:
  LapTimer timer_;
};

TEST_F(PicturePileImplPerfTest, Analyze) {
  RunAnalyzeTest("1", 1.0f);
  RunAnalyzeTest("4", 0.5f);
  RunAnalyzeTest("100", 0.1f);
}

TEST_F(PicturePileImplPerfTest, Raster) {
  RunRasterTest("1", 1.0f);
  RunRasterTest("4", 0.5f);
  RunRasterTest("100", 0.1f);
}

}  // namespace
}  // namespace cc