OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/resources/picture_pile_impl.h" | 5 #include "cc/resources/picture_pile_impl.h" |
6 | 6 |
7 #include "cc/debug/lap_timer.h" | 7 #include "cc/debug/lap_timer.h" |
8 #include "cc/test/fake_picture_pile_impl.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" | 9 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/perf/perf_test.h" | 10 #include "testing/perf/perf_test.h" |
12 | 11 |
13 namespace cc { | 12 namespace cc { |
14 namespace { | 13 namespace { |
15 | 14 |
16 const int kTimeLimitMillis = 2000; | 15 const int kTimeLimitMillis = 2000; |
17 const int kWarmupRuns = 5; | 16 const int kWarmupRuns = 5; |
18 const int kTimeCheckInterval = 10; | 17 const int kTimeCheckInterval = 10; |
19 | 18 |
20 const int kTileSize = 100; | 19 const int kTileSize = 100; |
21 const int kLayerSize = 1000; | 20 const int kLayerSize = 1000; |
22 | 21 |
23 class PicturePileImplPerfTest : public testing::Test { | 22 class PicturePileImplPerfTest : public testing::Test { |
24 public: | 23 public: |
25 PicturePileImplPerfTest() | 24 PicturePileImplPerfTest() |
26 : timer_(kWarmupRuns, | 25 : timer_(kWarmupRuns, |
27 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | 26 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
28 kTimeCheckInterval) {} | 27 kTimeCheckInterval) {} |
29 | 28 |
30 void RunAnalyzeTest(const std::string& test_name, float contents_scale) { | 29 void RunAnalyzeTest(const std::string& test_name, float contents_scale) { |
31 scoped_refptr<PicturePileImpl> pile = FakePicturePileImpl::CreateFilledPile( | 30 scoped_refptr<PicturePileImpl> pile = FakePicturePileImpl::CreateFilledPile( |
32 gfx::Size(kTileSize, kTileSize), gfx::Size(kLayerSize, kLayerSize)); | 31 gfx::Size(kTileSize, kTileSize), gfx::Size(kLayerSize, kLayerSize)); |
33 // Content rect that will align with top-left tile at scale 1.0. | 32 // Content rect that will align with top-left tile at scale 1.0. |
34 gfx::Rect content_rect(0, 0, kTileSize, kTileSize); | 33 gfx::Rect content_rect(0, 0, kTileSize, kTileSize); |
35 | 34 |
36 RasterSource::SolidColorAnalysis analysis; | 35 RasterSource::SolidColorAnalysis analysis; |
37 timer_.Reset(); | 36 timer_.Reset(); |
38 do { | 37 do { |
39 pile->PerformSolidColorAnalysis( | 38 pile->PerformSolidColorAnalysis(content_rect, contents_scale, &analysis); |
40 content_rect, contents_scale, &analysis, nullptr); | |
41 timer_.NextLap(); | 39 timer_.NextLap(); |
42 } while (!timer_.HasTimeLimitExpired()); | 40 } while (!timer_.HasTimeLimitExpired()); |
43 | 41 |
44 perf_test::PrintResult( | 42 perf_test::PrintResult( |
45 "analyze", "", test_name, timer_.LapsPerSecond(), "runs/s", true); | 43 "analyze", "", test_name, timer_.LapsPerSecond(), "runs/s", true); |
46 } | 44 } |
47 | 45 |
48 void RunRasterTest(const std::string& test_name, float contents_scale) { | 46 void RunRasterTest(const std::string& test_name, float contents_scale) { |
49 scoped_refptr<PicturePileImpl> pile = FakePicturePileImpl::CreateFilledPile( | 47 scoped_refptr<PicturePileImpl> pile = FakePicturePileImpl::CreateFilledPile( |
50 gfx::Size(kTileSize, kTileSize), gfx::Size(kLayerSize, kLayerSize)); | 48 gfx::Size(kTileSize, kTileSize), gfx::Size(kLayerSize, kLayerSize)); |
51 // Content rect that will align with top-left tile at scale 1.0. | 49 // Content rect that will align with top-left tile at scale 1.0. |
52 gfx::Rect content_rect(0, 0, kTileSize, kTileSize); | 50 gfx::Rect content_rect(0, 0, kTileSize, kTileSize); |
53 | 51 |
54 SkBitmap bitmap; | 52 SkBitmap bitmap; |
55 bitmap.allocN32Pixels(1, 1); | 53 bitmap.allocN32Pixels(1, 1); |
56 SkCanvas canvas(bitmap); | 54 SkCanvas canvas(bitmap); |
57 | 55 |
58 FakeRenderingStatsInstrumentation rendering_stats_instrumentation; | |
59 timer_.Reset(); | 56 timer_.Reset(); |
60 do { | 57 do { |
61 pile->PlaybackToCanvas(&canvas, | 58 pile->PlaybackToCanvas(&canvas, content_rect, contents_scale); |
62 content_rect, | |
63 contents_scale, | |
64 &rendering_stats_instrumentation); | |
65 timer_.NextLap(); | 59 timer_.NextLap(); |
66 } while (!timer_.HasTimeLimitExpired()); | 60 } while (!timer_.HasTimeLimitExpired()); |
67 | 61 |
68 perf_test::PrintResult( | 62 perf_test::PrintResult( |
69 "raster", "", test_name, timer_.LapsPerSecond(), "runs/s", true); | 63 "raster", "", test_name, timer_.LapsPerSecond(), "runs/s", true); |
70 } | 64 } |
71 | 65 |
72 private: | 66 private: |
73 LapTimer timer_; | 67 LapTimer timer_; |
74 }; | 68 }; |
75 | 69 |
76 TEST_F(PicturePileImplPerfTest, Analyze) { | 70 TEST_F(PicturePileImplPerfTest, Analyze) { |
77 RunAnalyzeTest("1", 1.0f); | 71 RunAnalyzeTest("1", 1.0f); |
78 RunAnalyzeTest("4", 0.5f); | 72 RunAnalyzeTest("4", 0.5f); |
79 RunAnalyzeTest("100", 0.1f); | 73 RunAnalyzeTest("100", 0.1f); |
80 } | 74 } |
81 | 75 |
82 TEST_F(PicturePileImplPerfTest, Raster) { | 76 TEST_F(PicturePileImplPerfTest, Raster) { |
83 RunRasterTest("1", 1.0f); | 77 RunRasterTest("1", 1.0f); |
84 RunRasterTest("4", 0.5f); | 78 RunRasterTest("4", 0.5f); |
85 RunRasterTest("100", 0.1f); | 79 RunRasterTest("100", 0.1f); |
86 } | 80 } |
87 | 81 |
88 } // namespace | 82 } // namespace |
89 } // namespace cc | 83 } // namespace cc |
OLD | NEW |