Temporarily re-enabling SizeAfterPrefChange test with traces.
[chromium-blink-merge.git] / cc / resources / picture_pile_impl_perftest.cc
blob7ced0eaa1be7635698f5b702a27b3dab928dde63
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 "cc/test/fake_rendering_stats_instrumentation.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/perf/perf_test.h"
13 namespace cc {
14 namespace {
16 const int kTimeLimitMillis = 2000;
17 const int kWarmupRuns = 5;
18 const int kTimeCheckInterval = 10;
20 const int kTileSize = 100;
21 const int kLayerSize = 1000;
23 class PicturePileImplPerfTest : public testing::Test {
24 public:
25 PicturePileImplPerfTest()
26 : timer_(kWarmupRuns,
27 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
28 kTimeCheckInterval) {}
30 void RunAnalyzeTest(const std::string& test_name, float contents_scale) {
31 scoped_refptr<PicturePileImpl> pile = FakePicturePileImpl::CreateFilledPile(
32 gfx::Size(kTileSize, kTileSize), gfx::Size(kLayerSize, kLayerSize));
33 // Content rect that will align with top-left tile at scale 1.0.
34 gfx::Rect content_rect(0, 0, kTileSize, kTileSize);
36 PicturePileImpl::Analysis analysis;
37 timer_.Reset();
38 do {
39 pile->AnalyzeInRect(content_rect, contents_scale, &analysis);
40 timer_.NextLap();
41 } while (!timer_.HasTimeLimitExpired());
43 perf_test::PrintResult(
44 "analyze", "", test_name, timer_.LapsPerSecond(), "runs/s", true);
47 void RunRasterTest(const std::string& test_name, float contents_scale) {
48 scoped_refptr<PicturePileImpl> pile = FakePicturePileImpl::CreateFilledPile(
49 gfx::Size(kTileSize, kTileSize), gfx::Size(kLayerSize, kLayerSize));
50 // Content rect that will align with top-left tile at scale 1.0.
51 gfx::Rect content_rect(0, 0, kTileSize, kTileSize);
53 SkBitmap bitmap;
54 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
55 bitmap.allocPixels();
56 SkCanvas canvas(bitmap);
58 FakeRenderingStatsInstrumentation rendering_stats_instrumentation;
59 timer_.Reset();
60 do {
61 pile->RasterToBitmap(&canvas,
62 content_rect,
63 contents_scale,
64 &rendering_stats_instrumentation);
65 timer_.NextLap();
66 } while (!timer_.HasTimeLimitExpired());
68 perf_test::PrintResult(
69 "raster", "", test_name, timer_.LapsPerSecond(), "runs/s", true);
72 private:
73 LapTimer timer_;
76 TEST_F(PicturePileImplPerfTest, Analyze) {
77 RunAnalyzeTest("1", 1.0f);
78 RunAnalyzeTest("4", 0.5f);
79 RunAnalyzeTest("100", 0.1f);
82 TEST_F(PicturePileImplPerfTest, Raster) {
83 RunRasterTest("1", 1.0f);
84 RunRasterTest("4", 0.5f);
85 RunRasterTest("100", 0.1f);
88 } // namespace
89 } // namespace cc