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/playback/picture_pile_impl.h" | 5 #include "cc/playback/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/skia_common.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "testing/perf/perf_test.h" | 11 #include "testing/perf/perf_test.h" |
11 | 12 |
12 namespace cc { | 13 namespace cc { |
13 namespace { | 14 namespace { |
14 | 15 |
15 const int kTimeLimitMillis = 2000; | 16 const int kTimeLimitMillis = 2000; |
16 const int kWarmupRuns = 5; | 17 const int kWarmupRuns = 5; |
17 const int kTimeCheckInterval = 10; | 18 const int kTimeCheckInterval = 10; |
18 | 19 |
(...skipping 17 matching lines...) Expand all Loading... |
36 timer_.Reset(); | 37 timer_.Reset(); |
37 do { | 38 do { |
38 pile->PerformSolidColorAnalysis(content_rect, contents_scale, &analysis); | 39 pile->PerformSolidColorAnalysis(content_rect, contents_scale, &analysis); |
39 timer_.NextLap(); | 40 timer_.NextLap(); |
40 } while (!timer_.HasTimeLimitExpired()); | 41 } while (!timer_.HasTimeLimitExpired()); |
41 | 42 |
42 perf_test::PrintResult( | 43 perf_test::PrintResult( |
43 "analyze", "", test_name, timer_.LapsPerSecond(), "runs/s", true); | 44 "analyze", "", test_name, timer_.LapsPerSecond(), "runs/s", true); |
44 } | 45 } |
45 | 46 |
46 void RunRasterTest(const std::string& test_name, float contents_scale) { | 47 void RunRasterTest(const std::string& test_name, |
47 scoped_refptr<PicturePileImpl> pile = FakePicturePileImpl::CreateFilledPile( | 48 float contents_scale, |
48 gfx::Size(kTileSize, kTileSize), gfx::Size(kLayerSize, kLayerSize)); | 49 const gfx::Size& tile_size, |
49 // Content rect that will align with top-left tile at scale 1.0. | 50 const gfx::Size& layer_bounds, |
50 gfx::Rect content_rect(0, 0, kTileSize, kTileSize); | 51 const gfx::Size& drawing_size, |
| 52 int drawing_iterations) { |
| 53 scoped_ptr<FakePicturePile> drawing = |
| 54 FakePicturePile::CreateFilledPile(tile_size, layer_bounds); |
| 55 // Content rect that will align with given layer at scale 1.0. |
| 56 gfx::Rect content_rect(0, 0, layer_bounds.width(), layer_bounds.height()); |
| 57 |
| 58 AddDrawing(drawing.get(), drawing_size, drawing_iterations); |
| 59 |
| 60 scoped_refptr<PicturePileImpl> pile = |
| 61 FakePicturePileImpl::CreateFromPile(drawing.get(), nullptr); |
51 | 62 |
52 SkBitmap bitmap; | 63 SkBitmap bitmap; |
53 bitmap.allocN32Pixels(1, 1); | 64 bitmap.allocN32Pixels(layer_bounds.width(), layer_bounds.height()); |
54 SkCanvas canvas(bitmap); | 65 SkCanvas canvas(bitmap); |
55 | 66 |
56 timer_.Reset(); | 67 timer_.Reset(); |
57 do { | 68 do { |
58 pile->PlaybackToCanvas(&canvas, content_rect, content_rect, | 69 pile->PlaybackToCanvas(&canvas, content_rect, content_rect, |
59 contents_scale); | 70 contents_scale); |
60 timer_.NextLap(); | 71 timer_.NextLap(); |
61 } while (!timer_.HasTimeLimitExpired()); | 72 } while (!timer_.HasTimeLimitExpired()); |
62 | 73 |
63 perf_test::PrintResult( | 74 perf_test::PrintResult( |
64 "raster", "", test_name, timer_.LapsPerSecond(), "runs/s", true); | 75 "raster", "", test_name, timer_.LapsPerSecond(), "runs/s", true); |
65 } | 76 } |
66 | 77 |
| 78 void AddDrawing(FakePicturePile* drawing, |
| 79 const gfx::Size& drawing_size, |
| 80 int drawing_iterations) { |
| 81 if ((drawing_iterations <= 0) || drawing_size.IsEmpty()) |
| 82 return; |
| 83 |
| 84 int x_pos = 0; |
| 85 int y_pos = 0; |
| 86 int width = drawing_size.width(); |
| 87 int height = drawing_size.height(); |
| 88 int color = 0; |
| 89 |
| 90 // Create full drawing size bitmap so that it will cover the all tiles |
| 91 // needed for given drawing size. |
| 92 SkBitmap bitmap; |
| 93 CreateBitmap(gfx::Size(width, height), "bitmap", &bitmap); |
| 94 // TODO(prashant.n): Initialize bitmpa pixels, so that every test run gets |
| 95 // same bitmap data. |
| 96 |
| 97 SkPaint paint; |
| 98 |
| 99 for (int i = 0; i < drawing_iterations; ++i) { |
| 100 // Delimit location in drawing size area so that something gets drawn on |
| 101 // the layer. |
| 102 x_pos = ++x_pos % drawing_size.width(); |
| 103 y_pos = ++y_pos % drawing_size.height(); |
| 104 width = (--width) ? width : drawing_size.width(); |
| 105 height = (--height) ? height : drawing_size.height(); |
| 106 color = ++color % 255; |
| 107 paint.setColor(SkColorSetARGB(color, color, color, color)); |
| 108 gfx::Rect rect(x_pos, y_pos, width, height); |
| 109 drawing->add_draw_rect_with_paint(rect, paint); |
| 110 drawing->add_draw_bitmap_with_paint(bitmap, gfx::Point(x_pos, y_pos), |
| 111 paint); |
| 112 } |
| 113 |
| 114 // Record again. |
| 115 for (int x = 0; x < drawing->tiling().num_tiles_x(); ++x) { |
| 116 for (int y = 0; y < drawing->tiling().num_tiles_y(); ++y) { |
| 117 drawing->RemoveRecordingAt(x, y); |
| 118 drawing->AddRecordingAt(x, y); |
| 119 } |
| 120 } |
| 121 } |
| 122 |
67 private: | 123 private: |
68 LapTimer timer_; | 124 LapTimer timer_; |
69 }; | 125 }; |
70 | 126 |
71 TEST_F(PicturePileImplPerfTest, Analyze) { | 127 TEST_F(PicturePileImplPerfTest, Analyze) { |
72 RunAnalyzeTest("1", 1.0f); | 128 RunAnalyzeTest("1", 1.0f); |
73 RunAnalyzeTest("4", 0.5f); | 129 RunAnalyzeTest("4", 0.5f); |
74 RunAnalyzeTest("100", 0.1f); | 130 RunAnalyzeTest("100", 0.1f); |
75 } | 131 } |
76 | 132 |
77 TEST_F(PicturePileImplPerfTest, Raster) { | 133 TEST_F(PicturePileImplPerfTest, Raster) { |
78 RunRasterTest("1", 1.0f); | 134 gfx::Size tile_size(kTileSize, kTileSize); |
79 RunRasterTest("4", 0.5f); | 135 gfx::Size layer_bounds(kLayerSize, kLayerSize); |
80 RunRasterTest("100", 0.1f); | 136 |
| 137 RunRasterTest("1", 1.0f, tile_size, layer_bounds, layer_bounds, 0); |
| 138 RunRasterTest("4", 0.5f, tile_size, layer_bounds, layer_bounds, 0); |
| 139 RunRasterTest("100", 0.1f, tile_size, layer_bounds, layer_bounds, 0); |
| 140 |
| 141 RunRasterTest("1_1", 1.0f, tile_size, layer_bounds, layer_bounds, 1); |
| 142 RunRasterTest("4_1", 0.5f, tile_size, layer_bounds, layer_bounds, 1); |
| 143 RunRasterTest("100_1", 0.1f, tile_size, layer_bounds, layer_bounds, 1); |
| 144 |
| 145 RunRasterTest("1_64", 1.0f, tile_size, layer_bounds, layer_bounds, 64); |
| 146 RunRasterTest("4_64", 0.5f, tile_size, layer_bounds, layer_bounds, 64); |
| 147 RunRasterTest("100_64", 0.1f, tile_size, layer_bounds, layer_bounds, 64); |
81 } | 148 } |
82 | 149 |
83 } // namespace | 150 } // namespace |
84 } // namespace cc | 151 } // namespace cc |
OLD | NEW |