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