OLD | NEW |
| (Empty) |
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 "base/time/time.h" | |
6 #include "cc/debug/lap_timer.h" | |
7 #include "cc/resources/raster_buffer.h" | |
8 #include "cc/resources/tile.h" | |
9 #include "cc/resources/tile_priority.h" | |
10 #include "cc/test/begin_frame_args_test.h" | |
11 #include "cc/test/fake_impl_proxy.h" | |
12 #include "cc/test/fake_layer_tree_host_impl.h" | |
13 #include "cc/test/fake_output_surface.h" | |
14 #include "cc/test/fake_output_surface_client.h" | |
15 #include "cc/test/fake_picture_layer_impl.h" | |
16 #include "cc/test/fake_picture_pile_impl.h" | |
17 #include "cc/test/fake_tile_manager.h" | |
18 #include "cc/test/fake_tile_manager_client.h" | |
19 #include "cc/test/impl_side_painting_settings.h" | |
20 #include "cc/test/test_shared_bitmap_manager.h" | |
21 #include "cc/test/test_task_graph_runner.h" | |
22 #include "cc/test/test_tile_priorities.h" | |
23 #include "cc/trees/layer_tree_impl.h" | |
24 | |
25 #include "testing/gtest/include/gtest/gtest.h" | |
26 #include "testing/perf/perf_test.h" | |
27 | |
28 #include "ui/gfx/frame_time.h" | |
29 | |
30 namespace cc { | |
31 namespace { | |
32 | |
33 static const int kTimeLimitMillis = 2000; | |
34 static const int kWarmupRuns = 5; | |
35 static const int kTimeCheckInterval = 10; | |
36 | |
37 class FakeTileTaskRunnerImpl : public TileTaskRunner, public TileTaskClient { | |
38 public: | |
39 // Overridden from TileTaskRunner: | |
40 void SetClient(TileTaskRunnerClient* client) override {} | |
41 void Shutdown() override {} | |
42 void ScheduleTasks(TileTaskQueue* queue) override { | |
43 for (TileTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); | |
44 it != queue->items.end(); ++it) { | |
45 RasterTask* task = it->task; | |
46 | |
47 task->WillSchedule(); | |
48 task->ScheduleOnOriginThread(this); | |
49 task->DidSchedule(); | |
50 | |
51 completed_tasks_.push_back(task); | |
52 } | |
53 } | |
54 void CheckForCompletedTasks() override { | |
55 for (RasterTask::Vector::iterator it = completed_tasks_.begin(); | |
56 it != completed_tasks_.end(); | |
57 ++it) { | |
58 RasterTask* task = it->get(); | |
59 | |
60 task->WillComplete(); | |
61 task->CompleteOnOriginThread(this); | |
62 task->DidComplete(); | |
63 | |
64 task->RunReplyOnOriginThread(); | |
65 } | |
66 completed_tasks_.clear(); | |
67 } | |
68 ResourceFormat GetResourceFormat() override { | |
69 return RGBA_8888; | |
70 } | |
71 | |
72 // Overridden from TileTaskClient: | |
73 scoped_ptr<RasterBuffer> AcquireBufferForRaster( | |
74 const Resource* resource) override { | |
75 return nullptr; | |
76 } | |
77 void ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer) override {} | |
78 | |
79 private: | |
80 RasterTask::Vector completed_tasks_; | |
81 }; | |
82 base::LazyInstance<FakeTileTaskRunnerImpl> g_fake_tile_task_runner = | |
83 LAZY_INSTANCE_INITIALIZER; | |
84 | |
85 class TileManagerPerfTest : public testing::Test { | |
86 public: | |
87 TileManagerPerfTest() | |
88 : memory_limit_policy_(ALLOW_ANYTHING), | |
89 max_tiles_(10000), | |
90 id_(7), | |
91 proxy_(base::MessageLoopProxy::current()), | |
92 host_impl_(ImplSidePaintingSettings(10000), | |
93 &proxy_, | |
94 &shared_bitmap_manager_, | |
95 &task_graph_runner_), | |
96 timer_(kWarmupRuns, | |
97 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | |
98 kTimeCheckInterval) {} | |
99 | |
100 void SetTreePriority(TreePriority tree_priority) { | |
101 GlobalStateThatImpactsTilePriority state; | |
102 gfx::Size tile_size(256, 256); | |
103 | |
104 state.soft_memory_limit_in_bytes = 100 * 1000 * 1000; | |
105 state.num_resources_limit = max_tiles_; | |
106 state.hard_memory_limit_in_bytes = state.soft_memory_limit_in_bytes * 2; | |
107 state.memory_limit_policy = memory_limit_policy_; | |
108 state.tree_priority = tree_priority; | |
109 | |
110 global_state_ = state; | |
111 host_impl_.resource_pool()->SetResourceUsageLimits( | |
112 state.soft_memory_limit_in_bytes, 0, state.num_resources_limit); | |
113 host_impl_.tile_manager()->SetGlobalStateForTesting(state); | |
114 } | |
115 | |
116 void SetUp() override { | |
117 InitializeRenderer(); | |
118 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
119 } | |
120 | |
121 virtual void InitializeRenderer() { | |
122 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d().Pass()); | |
123 tile_manager()->SetTileTaskRunnerForTesting( | |
124 g_fake_tile_task_runner.Pointer()); | |
125 } | |
126 | |
127 void SetupDefaultTrees(const gfx::Size& layer_bounds) { | |
128 scoped_refptr<FakePicturePileImpl> pending_pile = | |
129 FakePicturePileImpl::CreateFilledPile(kDefaultTileSize, layer_bounds); | |
130 scoped_refptr<FakePicturePileImpl> active_pile = | |
131 FakePicturePileImpl::CreateFilledPile(kDefaultTileSize, layer_bounds); | |
132 | |
133 SetupTrees(pending_pile, active_pile); | |
134 } | |
135 | |
136 void ActivateTree() { | |
137 host_impl_.ActivateSyncTree(); | |
138 CHECK(!host_impl_.pending_tree()); | |
139 pending_root_layer_ = NULL; | |
140 active_root_layer_ = static_cast<FakePictureLayerImpl*>( | |
141 host_impl_.active_tree()->LayerById(id_)); | |
142 } | |
143 | |
144 void SetupDefaultTreesWithFixedTileSize(const gfx::Size& layer_bounds, | |
145 const gfx::Size& tile_size) { | |
146 SetupDefaultTrees(layer_bounds); | |
147 pending_root_layer_->set_fixed_tile_size(tile_size); | |
148 active_root_layer_->set_fixed_tile_size(tile_size); | |
149 } | |
150 | |
151 void SetupTrees(scoped_refptr<PicturePileImpl> pending_pile, | |
152 scoped_refptr<PicturePileImpl> active_pile) { | |
153 SetupPendingTree(active_pile); | |
154 ActivateTree(); | |
155 SetupPendingTree(pending_pile); | |
156 } | |
157 | |
158 void SetupPendingTree(scoped_refptr<PicturePileImpl> pile) { | |
159 host_impl_.CreatePendingTree(); | |
160 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); | |
161 // Clear recycled tree. | |
162 pending_tree->DetachLayerTree(); | |
163 | |
164 scoped_ptr<FakePictureLayerImpl> pending_layer = | |
165 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, id_, pile); | |
166 pending_layer->SetDrawsContent(true); | |
167 pending_layer->SetHasRenderSurface(true); | |
168 pending_tree->SetRootLayer(pending_layer.Pass()); | |
169 | |
170 pending_root_layer_ = static_cast<FakePictureLayerImpl*>( | |
171 host_impl_.pending_tree()->LayerById(id_)); | |
172 } | |
173 | |
174 void RunRasterQueueConstructTest(const std::string& test_name, | |
175 int layer_count) { | |
176 TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES, | |
177 SMOOTHNESS_TAKES_PRIORITY, | |
178 NEW_CONTENT_TAKES_PRIORITY}; | |
179 int priority_count = 0; | |
180 | |
181 std::vector<FakePictureLayerImpl*> layers = CreateLayers(layer_count, 10); | |
182 bool resourceless_software_draw = false; | |
183 for (const auto& layer : layers) | |
184 layer->UpdateTiles(resourceless_software_draw); | |
185 | |
186 timer_.Reset(); | |
187 do { | |
188 scoped_ptr<RasterTilePriorityQueue> queue(host_impl_.BuildRasterQueue( | |
189 priorities[priority_count], RasterTilePriorityQueue::Type::ALL)); | |
190 priority_count = (priority_count + 1) % arraysize(priorities); | |
191 timer_.NextLap(); | |
192 } while (!timer_.HasTimeLimitExpired()); | |
193 | |
194 perf_test::PrintResult("tile_manager_raster_tile_queue_construct", | |
195 "", | |
196 test_name, | |
197 timer_.LapsPerSecond(), | |
198 "runs/s", | |
199 true); | |
200 } | |
201 | |
202 void RunRasterQueueConstructAndIterateTest(const std::string& test_name, | |
203 int layer_count, | |
204 int tile_count) { | |
205 TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES, | |
206 SMOOTHNESS_TAKES_PRIORITY, | |
207 NEW_CONTENT_TAKES_PRIORITY}; | |
208 | |
209 std::vector<FakePictureLayerImpl*> layers = CreateLayers(layer_count, 100); | |
210 bool resourceless_software_draw = false; | |
211 for (const auto& layer : layers) | |
212 layer->UpdateTiles(resourceless_software_draw); | |
213 | |
214 int priority_count = 0; | |
215 timer_.Reset(); | |
216 do { | |
217 int count = tile_count; | |
218 scoped_ptr<RasterTilePriorityQueue> queue(host_impl_.BuildRasterQueue( | |
219 priorities[priority_count], RasterTilePriorityQueue::Type::ALL)); | |
220 while (count--) { | |
221 ASSERT_FALSE(queue->IsEmpty()); | |
222 ASSERT_TRUE(queue->Top() != NULL); | |
223 queue->Pop(); | |
224 } | |
225 priority_count = (priority_count + 1) % arraysize(priorities); | |
226 timer_.NextLap(); | |
227 } while (!timer_.HasTimeLimitExpired()); | |
228 | |
229 perf_test::PrintResult( | |
230 "tile_manager_raster_tile_queue_construct_and_iterate", | |
231 "", | |
232 test_name, | |
233 timer_.LapsPerSecond(), | |
234 "runs/s", | |
235 true); | |
236 } | |
237 | |
238 void RunEvictionQueueConstructTest(const std::string& test_name, | |
239 int layer_count) { | |
240 TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES, | |
241 SMOOTHNESS_TAKES_PRIORITY, | |
242 NEW_CONTENT_TAKES_PRIORITY}; | |
243 int priority_count = 0; | |
244 | |
245 std::vector<FakePictureLayerImpl*> layers = CreateLayers(layer_count, 10); | |
246 bool resourceless_software_draw = false; | |
247 for (const auto& layer : layers) { | |
248 layer->UpdateTiles(resourceless_software_draw); | |
249 for (size_t i = 0; i < layer->num_tilings(); ++i) { | |
250 tile_manager()->InitializeTilesWithResourcesForTesting( | |
251 layer->tilings()->tiling_at(i)->AllTilesForTesting()); | |
252 } | |
253 } | |
254 | |
255 timer_.Reset(); | |
256 do { | |
257 scoped_ptr<EvictionTilePriorityQueue> queue( | |
258 host_impl_.BuildEvictionQueue(priorities[priority_count])); | |
259 priority_count = (priority_count + 1) % arraysize(priorities); | |
260 timer_.NextLap(); | |
261 } while (!timer_.HasTimeLimitExpired()); | |
262 | |
263 perf_test::PrintResult("tile_manager_eviction_tile_queue_construct", | |
264 "", | |
265 test_name, | |
266 timer_.LapsPerSecond(), | |
267 "runs/s", | |
268 true); | |
269 } | |
270 | |
271 void RunEvictionQueueConstructAndIterateTest(const std::string& test_name, | |
272 int layer_count, | |
273 int tile_count) { | |
274 TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES, | |
275 SMOOTHNESS_TAKES_PRIORITY, | |
276 NEW_CONTENT_TAKES_PRIORITY}; | |
277 int priority_count = 0; | |
278 | |
279 std::vector<FakePictureLayerImpl*> layers = | |
280 CreateLayers(layer_count, tile_count); | |
281 bool resourceless_software_draw = false; | |
282 for (const auto& layer : layers) { | |
283 layer->UpdateTiles(resourceless_software_draw); | |
284 for (size_t i = 0; i < layer->num_tilings(); ++i) { | |
285 tile_manager()->InitializeTilesWithResourcesForTesting( | |
286 layer->tilings()->tiling_at(i)->AllTilesForTesting()); | |
287 } | |
288 } | |
289 | |
290 timer_.Reset(); | |
291 do { | |
292 int count = tile_count; | |
293 scoped_ptr<EvictionTilePriorityQueue> queue( | |
294 host_impl_.BuildEvictionQueue(priorities[priority_count])); | |
295 while (count--) { | |
296 ASSERT_FALSE(queue->IsEmpty()); | |
297 ASSERT_TRUE(queue->Top() != NULL); | |
298 queue->Pop(); | |
299 } | |
300 priority_count = (priority_count + 1) % arraysize(priorities); | |
301 timer_.NextLap(); | |
302 } while (!timer_.HasTimeLimitExpired()); | |
303 | |
304 perf_test::PrintResult( | |
305 "tile_manager_eviction_tile_queue_construct_and_iterate", | |
306 "", | |
307 test_name, | |
308 timer_.LapsPerSecond(), | |
309 "runs/s", | |
310 true); | |
311 } | |
312 | |
313 std::vector<FakePictureLayerImpl*> CreateLayers(int layer_count, | |
314 int tiles_per_layer_count) { | |
315 // Compute the width/height required for high res to get | |
316 // tiles_per_layer_count tiles. | |
317 float width = std::sqrt(static_cast<float>(tiles_per_layer_count)); | |
318 float height = tiles_per_layer_count / width; | |
319 | |
320 // Adjust the width and height to account for the fact that tiles | |
321 // are bigger than 1x1. Also, account for the fact that that we | |
322 // will be creating one high res and one low res tiling. That is, | |
323 // width and height should be smaller by sqrt(1 + low_res_scale). | |
324 // This gives us _approximately_ correct counts. | |
325 width *= settings_.default_tile_size.width() / | |
326 std::sqrt(1 + settings_.low_res_contents_scale_factor); | |
327 height *= settings_.default_tile_size.height() / | |
328 std::sqrt(1 + settings_.low_res_contents_scale_factor); | |
329 | |
330 // Ensure that we start with blank trees and no tiles. | |
331 host_impl_.ResetTreesForTesting(); | |
332 tile_manager()->FreeResourcesAndCleanUpReleasedTilesForTesting(); | |
333 | |
334 gfx::Size layer_bounds(width, height); | |
335 gfx::Size viewport(width / 5, height / 5); | |
336 host_impl_.SetViewportSize(viewport); | |
337 SetupDefaultTreesWithFixedTileSize(layer_bounds, | |
338 settings_.default_tile_size); | |
339 | |
340 std::vector<FakePictureLayerImpl*> layers; | |
341 | |
342 // Pending layer counts as one layer. | |
343 layers.push_back(pending_root_layer_); | |
344 int next_id = id_ + 1; | |
345 | |
346 // Create the rest of the layers as children of the root layer. | |
347 scoped_refptr<FakePicturePileImpl> pile = | |
348 FakePicturePileImpl::CreateFilledPile(kDefaultTileSize, layer_bounds); | |
349 while (static_cast<int>(layers.size()) < layer_count) { | |
350 scoped_ptr<FakePictureLayerImpl> layer = | |
351 FakePictureLayerImpl::CreateWithRasterSource( | |
352 host_impl_.pending_tree(), next_id, pile); | |
353 layer->SetBounds(layer_bounds); | |
354 layer->SetDrawsContent(true); | |
355 layers.push_back(layer.get()); | |
356 pending_root_layer_->AddChild(layer.Pass()); | |
357 ++next_id; | |
358 } | |
359 | |
360 bool update_lcd_text = false; | |
361 host_impl_.pending_tree()->UpdateDrawProperties(update_lcd_text); | |
362 for (FakePictureLayerImpl* layer : layers) | |
363 layer->CreateAllTiles(); | |
364 | |
365 return layers; | |
366 } | |
367 | |
368 GlobalStateThatImpactsTilePriority GlobalStateForTest() { | |
369 GlobalStateThatImpactsTilePriority state; | |
370 gfx::Size tile_size = settings_.default_tile_size; | |
371 state.soft_memory_limit_in_bytes = | |
372 10000u * 4u * | |
373 static_cast<size_t>(tile_size.width() * tile_size.height()); | |
374 state.hard_memory_limit_in_bytes = state.soft_memory_limit_in_bytes; | |
375 state.num_resources_limit = 10000; | |
376 state.memory_limit_policy = ALLOW_ANYTHING; | |
377 state.tree_priority = SMOOTHNESS_TAKES_PRIORITY; | |
378 return state; | |
379 } | |
380 | |
381 void RunPrepareTilesTest(const std::string& test_name, | |
382 int layer_count, | |
383 int approximate_tile_count_per_layer) { | |
384 std::vector<FakePictureLayerImpl*> layers = | |
385 CreateLayers(layer_count, approximate_tile_count_per_layer); | |
386 timer_.Reset(); | |
387 bool resourceless_software_draw = false; | |
388 do { | |
389 BeginFrameArgs args = | |
390 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); | |
391 host_impl_.UpdateCurrentBeginFrameArgs(args); | |
392 for (const auto& layer : layers) | |
393 layer->UpdateTiles(resourceless_software_draw); | |
394 | |
395 GlobalStateThatImpactsTilePriority global_state(GlobalStateForTest()); | |
396 tile_manager()->PrepareTiles(global_state); | |
397 tile_manager()->UpdateVisibleTiles(global_state); | |
398 timer_.NextLap(); | |
399 host_impl_.ResetCurrentBeginFrameArgsForNextFrame(); | |
400 } while (!timer_.HasTimeLimitExpired()); | |
401 | |
402 perf_test::PrintResult("prepare_tiles", "", test_name, | |
403 timer_.LapsPerSecond(), "runs/s", true); | |
404 } | |
405 | |
406 TileManager* tile_manager() { return host_impl_.tile_manager(); } | |
407 | |
408 protected: | |
409 GlobalStateThatImpactsTilePriority global_state_; | |
410 | |
411 TestSharedBitmapManager shared_bitmap_manager_; | |
412 TestTaskGraphRunner task_graph_runner_; | |
413 TileMemoryLimitPolicy memory_limit_policy_; | |
414 int max_tiles_; | |
415 int id_; | |
416 FakeImplProxy proxy_; | |
417 FakeLayerTreeHostImpl host_impl_; | |
418 FakePictureLayerImpl* pending_root_layer_; | |
419 FakePictureLayerImpl* active_root_layer_; | |
420 LapTimer timer_; | |
421 LayerTreeSettings settings_; | |
422 | |
423 static const gfx::Size kDefaultTileSize; | |
424 }; | |
425 | |
426 const gfx::Size TileManagerPerfTest::kDefaultTileSize(100, 100); | |
427 | |
428 TEST_F(TileManagerPerfTest, PrepareTiles) { | |
429 RunPrepareTilesTest("2_100", 2, 100); | |
430 RunPrepareTilesTest("2_500", 2, 500); | |
431 RunPrepareTilesTest("2_1000", 2, 1000); | |
432 RunPrepareTilesTest("10_100", 10, 100); | |
433 RunPrepareTilesTest("10_500", 10, 500); | |
434 RunPrepareTilesTest("10_1000", 10, 1000); | |
435 RunPrepareTilesTest("50_100", 100, 100); | |
436 RunPrepareTilesTest("50_500", 100, 500); | |
437 RunPrepareTilesTest("50_1000", 100, 1000); | |
438 } | |
439 | |
440 TEST_F(TileManagerPerfTest, RasterTileQueueConstruct) { | |
441 RunRasterQueueConstructTest("2", 2); | |
442 RunRasterQueueConstructTest("10", 10); | |
443 RunRasterQueueConstructTest("50", 50); | |
444 } | |
445 | |
446 TEST_F(TileManagerPerfTest, RasterTileQueueConstructAndIterate) { | |
447 RunRasterQueueConstructAndIterateTest("2_16", 2, 16); | |
448 RunRasterQueueConstructAndIterateTest("2_32", 2, 32); | |
449 RunRasterQueueConstructAndIterateTest("2_64", 2, 64); | |
450 RunRasterQueueConstructAndIterateTest("2_128", 2, 128); | |
451 RunRasterQueueConstructAndIterateTest("10_16", 10, 16); | |
452 RunRasterQueueConstructAndIterateTest("10_32", 10, 32); | |
453 RunRasterQueueConstructAndIterateTest("10_64", 10, 64); | |
454 RunRasterQueueConstructAndIterateTest("10_128", 10, 128); | |
455 RunRasterQueueConstructAndIterateTest("50_16", 50, 16); | |
456 RunRasterQueueConstructAndIterateTest("50_32", 50, 32); | |
457 RunRasterQueueConstructAndIterateTest("50_64", 50, 64); | |
458 RunRasterQueueConstructAndIterateTest("50_128", 50, 128); | |
459 } | |
460 | |
461 TEST_F(TileManagerPerfTest, EvictionTileQueueConstruct) { | |
462 RunEvictionQueueConstructTest("2", 2); | |
463 RunEvictionQueueConstructTest("10", 10); | |
464 RunEvictionQueueConstructTest("50", 50); | |
465 } | |
466 | |
467 TEST_F(TileManagerPerfTest, EvictionTileQueueConstructAndIterate) { | |
468 RunEvictionQueueConstructAndIterateTest("2_16", 2, 16); | |
469 RunEvictionQueueConstructAndIterateTest("2_32", 2, 32); | |
470 RunEvictionQueueConstructAndIterateTest("2_64", 2, 64); | |
471 RunEvictionQueueConstructAndIterateTest("2_128", 2, 128); | |
472 RunEvictionQueueConstructAndIterateTest("10_16", 10, 16); | |
473 RunEvictionQueueConstructAndIterateTest("10_32", 10, 32); | |
474 RunEvictionQueueConstructAndIterateTest("10_64", 10, 64); | |
475 RunEvictionQueueConstructAndIterateTest("10_128", 10, 128); | |
476 RunEvictionQueueConstructAndIterateTest("50_16", 50, 16); | |
477 RunEvictionQueueConstructAndIterateTest("50_32", 50, 32); | |
478 RunEvictionQueueConstructAndIterateTest("50_64", 50, 64); | |
479 RunEvictionQueueConstructAndIterateTest("50_128", 50, 128); | |
480 } | |
481 | |
482 } // namespace | |
483 } // namespace cc | |
OLD | NEW |