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