1 // Copyright 2013 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_layer_tiling.h" 6 #include "cc/test/fake_picture_layer_tiling_client.h" 7 8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/perf/perf_test.h" 10 11 namespace cc { 12 13 namespace { 14 15 static const int kTimeLimitMillis = 2000; 16 static const int kWarmupRuns = 5; 17 static const int kTimeCheckInterval = 10; 18 19 class PictureLayerTilingPerfTest : public testing::Test { 20 public: 21 PictureLayerTilingPerfTest() : num_runs_(0) {} 22 23 virtual void SetUp() OVERRIDE { 24 picture_layer_tiling_client_.SetTileSize(gfx::Size(256, 256)); 25 picture_layer_tiling_ = PictureLayerTiling::Create( 26 1, gfx::Size(256 * 50, 256 * 50), &picture_layer_tiling_client_); 27 picture_layer_tiling_->CreateAllTilesForTesting(); 28 } 29 30 virtual void TearDown() OVERRIDE { 31 picture_layer_tiling_.reset(NULL); 32 } 33 34 void EndTest() { 35 elapsed_ = base::TimeTicks::HighResNow() - start_time_; 36 } 37 38 bool DidRun() { 39 ++num_runs_; 40 if (num_runs_ == kWarmupRuns) 41 start_time_ = base::TimeTicks::HighResNow(); 42 43 if (!start_time_.is_null() && (num_runs_ % kTimeCheckInterval) == 0) { 44 base::TimeDelta elapsed = base::TimeTicks::HighResNow() - start_time_; 45 if (elapsed >= base::TimeDelta::FromMilliseconds(kTimeLimitMillis)) { 46 elapsed_ = elapsed; 47 return false; 48 } 49 } 50 return true; 51 } 52 53 void RunInvalidateTest(const std::string& test_name, const Region& region) { 54 start_time_ = base::TimeTicks(); 55 num_runs_ = 0; 56 do { 57 picture_layer_tiling_->Invalidate(region); 58 } while (DidRun()); 59 60 perf_test::PrintResult("invalidation", "", test_name, 61 num_runs_ / elapsed_.InSecondsF(), "runs/s", true); 62 } 63 64 void RunUpdateTilePrioritiesStationaryTest( 65 const std::string& test_name, 66 const gfx::Transform& transform) { 67 start_time_ = base::TimeTicks(); 68 num_runs_ = 0; 69 70 gfx::Size layer_bounds(50 * 256, 50 * 256); 71 do { 72 picture_layer_tiling_->UpdateTilePriorities( 73 ACTIVE_TREE, 74 layer_bounds, 75 gfx::Rect(layer_bounds), 76 gfx::Rect(layer_bounds), 77 layer_bounds, 78 layer_bounds, 79 1.f, 80 1.f, 81 transform, 82 transform, 83 num_runs_ + 1, 84 250); 85 } while (DidRun()); 86 87 perf_test::PrintResult("update_tile_priorities_stationary", "", test_name, 88 num_runs_ / elapsed_.InSecondsF(), "runs/s", true); 89 } 90 91 void RunUpdateTilePrioritiesScrollingTest( 92 const std::string& test_name, 93 const gfx::Transform& transform) { 94 start_time_ = base::TimeTicks(); 95 num_runs_ = 0; 96 97 gfx::Size layer_bounds(50 * 256, 50 * 256); 98 gfx::Size viewport_size(1024, 768); 99 gfx::Rect viewport_rect(viewport_size); 100 int xoffsets[] = {10, 0, -10, 0}; 101 int yoffsets[] = {0, 10, 0, -10}; 102 int offsetIndex = 0; 103 int offsetCount = 0; 104 const int maxOffsetCount = 1000; 105 do { 106 picture_layer_tiling_->UpdateTilePriorities( 107 ACTIVE_TREE, 108 viewport_size, 109 viewport_rect, 110 gfx::Rect(layer_bounds), 111 layer_bounds, 112 layer_bounds, 113 1.f, 114 1.f, 115 transform, 116 transform, 117 num_runs_ + 1, 118 250); 119 120 viewport_rect = gfx::Rect( 121 viewport_rect.x() + xoffsets[offsetIndex], 122 viewport_rect.y() + yoffsets[offsetIndex], 123 viewport_rect.width(), 124 viewport_rect.height()); 125 126 if (++offsetCount > maxOffsetCount) { 127 offsetCount = 0; 128 offsetIndex = (offsetIndex + 1) % 4; 129 } 130 } while (DidRun()); 131 132 perf_test::PrintResult("update_tile_priorities_scrolling", "", test_name, 133 num_runs_ / elapsed_.InSecondsF(), "runs/s", true); 134 } 135 136 private: 137 FakePictureLayerTilingClient picture_layer_tiling_client_; 138 scoped_ptr<PictureLayerTiling> picture_layer_tiling_; 139 140 base::TimeTicks start_time_; 141 base::TimeDelta elapsed_; 142 int num_runs_; 143 }; 144 145 TEST_F(PictureLayerTilingPerfTest, Invalidate) { 146 Region one_tile(gfx::Rect(256, 256)); 147 RunInvalidateTest("1x1", one_tile); 148 149 Region half_region(gfx::Rect(25 * 256, 50 * 256)); 150 RunInvalidateTest("25x50", half_region); 151 152 Region full_region(gfx::Rect(50 * 256, 50 * 256)); 153 RunInvalidateTest("50x50", full_region); 154 } 155 156 #if defined(OS_ANDROID) 157 // TODO(vmpstr): Investigate why this is noisy (crbug.com/310220). 158 TEST_F(PictureLayerTilingPerfTest, DISABLED_UpdateTilePriorities) { 159 #else 160 TEST_F(PictureLayerTilingPerfTest, UpdateTilePriorities) { 161 #endif // defined(OS_ANDROID) 162 gfx::Transform transform; 163 RunUpdateTilePrioritiesStationaryTest("no_transform", transform); 164 RunUpdateTilePrioritiesScrollingTest("no_transform", transform); 165 166 transform.Rotate(10); 167 RunUpdateTilePrioritiesStationaryTest("rotation", transform); 168 RunUpdateTilePrioritiesScrollingTest("rotation", transform); 169 170 transform.ApplyPerspectiveDepth(10); 171 RunUpdateTilePrioritiesStationaryTest("perspective", transform); 172 RunUpdateTilePrioritiesScrollingTest("perspective", transform); 173 } 174 175 } // namespace 176 177 } // namespace cc 178