Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / cc / resources / picture_pile_impl_perftest.cc
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.
4
5 #include "cc/resources/picture_pile_impl.h"
6
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"
11
12 namespace cc {
13 namespace {
14
15 const int kTimeLimitMillis = 2000;
16 const int kWarmupRuns = 5;
17 const int kTimeCheckInterval = 10;
18
19 const int kTileSize = 100;
20 const int kLayerSize = 1000;
21
22 class PicturePileImplPerfTest : public testing::Test {
23  public:
24   PicturePileImplPerfTest()
25       : timer_(kWarmupRuns,
26                base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
27                kTimeCheckInterval) {}
28
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);
34
35     RasterSource::SolidColorAnalysis analysis;
36     timer_.Reset();
37     do {
38       pile->PerformSolidColorAnalysis(content_rect, contents_scale, &analysis);
39       timer_.NextLap();
40     } while (!timer_.HasTimeLimitExpired());
41
42     perf_test::PrintResult(
43         "analyze", "", test_name, timer_.LapsPerSecond(), "runs/s", true);
44   }
45
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);
51
52     SkBitmap bitmap;
53     bitmap.allocN32Pixels(1, 1);
54     SkCanvas canvas(bitmap);
55
56     timer_.Reset();
57     do {
58       pile->PlaybackToCanvas(&canvas, content_rect, contents_scale);
59       timer_.NextLap();
60     } while (!timer_.HasTimeLimitExpired());
61
62     perf_test::PrintResult(
63         "raster", "", test_name, timer_.LapsPerSecond(), "runs/s", true);
64   }
65
66  private:
67   LapTimer timer_;
68 };
69
70 TEST_F(PicturePileImplPerfTest, Analyze) {
71   RunAnalyzeTest("1", 1.0f);
72   RunAnalyzeTest("4", 0.5f);
73   RunAnalyzeTest("100", 0.1f);
74 }
75
76 TEST_F(PicturePileImplPerfTest, Raster) {
77   RunRasterTest("1", 1.0f);
78   RunRasterTest("4", 0.5f);
79   RunRasterTest("100", 0.1f);
80 }
81
82 }  // namespace
83 }  // namespace cc