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/run_loop.h"
6 #include "base/thread_task_runner_handle.h"
7 #include "cc/playback/display_list_raster_source.h"
8 #include "cc/playback/display_list_recording_source.h"
9 #include "cc/resources/resource_pool.h"
10 #include "cc/test/begin_frame_args_test.h"
11 #include "cc/test/fake_display_list_recording_source.h"
12 #include "cc/test/fake_impl_proxy.h"
13 #include "cc/test/fake_layer_tree_host_impl.h"
14 #include "cc/test/fake_output_surface.h"
15 #include "cc/test/fake_output_surface_client.h"
16 #include "cc/test/fake_picture_layer_impl.h"
17 #include "cc/test/fake_picture_layer_tiling_client.h"
18 #include "cc/test/fake_picture_pile_impl.h"
19 #include "cc/test/fake_tile_manager.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/tiles/eviction_tile_priority_queue.h"
24 #include "cc/tiles/raster_tile_priority_queue.h"
25 #include "cc/tiles/tile.h"
26 #include "cc/tiles/tile_priority.h"
27 #include "cc/tiles/tiling_set_raster_queue_all.h"
28 #include "cc/trees/layer_tree_impl.h"
29 #include "testing/gmock/include/gmock/gmock.h"
30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "third_party/skia/include/core/SkSurface.h"
36 class LowResTilingsSettings
: public LayerTreeSettings
{
38 LowResTilingsSettings() { create_low_res_tiling
= true; }
41 class TileManagerTilePriorityQueueTest
: public testing::Test
{
43 TileManagerTilePriorityQueueTest()
44 : memory_limit_policy_(ALLOW_ANYTHING
),
46 ready_to_activate_(false),
48 proxy_(base::ThreadTaskRunnerHandle::Get()),
49 host_impl_(LowResTilingsSettings(),
51 &shared_bitmap_manager_
,
52 &task_graph_runner_
) {}
54 void SetTreePriority(TreePriority tree_priority
) {
55 GlobalStateThatImpactsTilePriority state
;
56 gfx::Size
tile_size(256, 256);
58 state
.soft_memory_limit_in_bytes
= 100 * 1000 * 1000;
59 state
.num_resources_limit
= max_tiles_
;
60 state
.hard_memory_limit_in_bytes
= state
.soft_memory_limit_in_bytes
* 2;
61 state
.memory_limit_policy
= memory_limit_policy_
;
62 state
.tree_priority
= tree_priority
;
64 global_state_
= state
;
65 host_impl_
.resource_pool()->SetResourceUsageLimits(
66 state
.soft_memory_limit_in_bytes
,
67 state
.num_resources_limit
);
68 host_impl_
.tile_manager()->SetGlobalStateForTesting(state
);
71 void SetUp() override
{
73 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES
);
76 virtual void InitializeRenderer() {
77 host_impl_
.InitializeRenderer(FakeOutputSurface::Create3d());
80 void SetupDefaultTrees(const gfx::Size
& layer_bounds
) {
81 gfx::Size
tile_size(100, 100);
83 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
84 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
85 scoped_refptr
<FakePicturePileImpl
> active_pile
=
86 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
88 SetupTrees(pending_pile
, active_pile
);
91 // This matches picture_layer_impl_unittest's ActivateTree.
93 host_impl_
.ActivateSyncTree();
94 CHECK(!host_impl_
.pending_tree());
95 pending_layer_
= NULL
;
96 active_layer_
= static_cast<FakePictureLayerImpl
*>(
97 host_impl_
.active_tree()->LayerById(id_
));
98 bool update_lcd_text
= false;
99 host_impl_
.active_tree()->UpdateDrawProperties(update_lcd_text
);
102 void SetupDefaultTreesWithFixedTileSize(const gfx::Size
& layer_bounds
,
103 const gfx::Size
& tile_size
) {
104 SetupDefaultTrees(layer_bounds
);
105 pending_layer_
->set_fixed_tile_size(tile_size
);
106 active_layer_
->set_fixed_tile_size(tile_size
);
109 void SetupTrees(scoped_refptr
<PicturePileImpl
> pending_pile
,
110 scoped_refptr
<PicturePileImpl
> active_pile
) {
111 SetupPendingTree(active_pile
);
113 SetupPendingTree(pending_pile
);
116 void SetupPendingTree(scoped_refptr
<RasterSource
> pile
) {
117 host_impl_
.CreatePendingTree();
118 LayerTreeImpl
* pending_tree
= host_impl_
.pending_tree();
120 // Steal from the recycled tree.
121 scoped_ptr
<LayerImpl
> old_pending_root
= pending_tree
->DetachLayerTree();
122 DCHECK_IMPLIES(old_pending_root
, old_pending_root
->id() == id_
);
124 scoped_ptr
<FakePictureLayerImpl
> pending_layer
;
125 if (old_pending_root
) {
127 static_cast<FakePictureLayerImpl
*>(old_pending_root
.release()));
128 pending_layer
->SetRasterSourceOnPending(pile
, Region());
131 FakePictureLayerImpl::CreateWithRasterSource(pending_tree
, id_
, pile
);
132 pending_layer
->SetDrawsContent(true);
133 pending_layer
->SetHasRenderSurface(true);
135 // The bounds() just mirror the pile size.
136 pending_layer
->SetBounds(pending_layer
->raster_source()->GetSize());
137 pending_tree
->SetRootLayer(pending_layer
.Pass());
139 pending_layer_
= static_cast<FakePictureLayerImpl
*>(
140 host_impl_
.pending_tree()->LayerById(id_
));
142 // Add tilings/tiles for the layer.
143 bool update_lcd_text
= false;
144 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
147 TileManager
* tile_manager() { return host_impl_
.tile_manager(); }
150 GlobalStateThatImpactsTilePriority global_state_
;
152 TestSharedBitmapManager shared_bitmap_manager_
;
153 TestTaskGraphRunner task_graph_runner_
;
154 TileMemoryLimitPolicy memory_limit_policy_
;
156 bool ready_to_activate_
;
158 FakeImplProxy proxy_
;
159 FakeLayerTreeHostImpl host_impl_
;
160 FakePictureLayerImpl
* pending_layer_
;
161 FakePictureLayerImpl
* active_layer_
;
164 TEST_F(TileManagerTilePriorityQueueTest
, RasterTilePriorityQueue
) {
165 const gfx::Size
layer_bounds(1000, 1000);
166 host_impl_
.SetViewportSize(layer_bounds
);
167 SetupDefaultTrees(layer_bounds
);
169 scoped_ptr
<RasterTilePriorityQueue
> queue(host_impl_
.BuildRasterQueue(
170 SAME_PRIORITY_FOR_BOTH_TREES
, RasterTilePriorityQueue::Type::ALL
));
171 EXPECT_FALSE(queue
->IsEmpty());
173 size_t tile_count
= 0;
174 std::set
<Tile
*> all_tiles
;
175 while (!queue
->IsEmpty()) {
176 EXPECT_TRUE(queue
->Top().tile());
177 all_tiles
.insert(queue
->Top().tile());
182 EXPECT_EQ(tile_count
, all_tiles
.size());
183 EXPECT_EQ(16u, tile_count
);
185 // Sanity check, all tiles should be visible.
186 std::set
<Tile
*> smoothness_tiles
;
187 queue
= host_impl_
.BuildRasterQueue(SMOOTHNESS_TAKES_PRIORITY
,
188 RasterTilePriorityQueue::Type::ALL
);
189 bool had_low_res
= false;
190 while (!queue
->IsEmpty()) {
191 PrioritizedTile prioritized_tile
= queue
->Top();
192 EXPECT_TRUE(prioritized_tile
.tile());
193 EXPECT_EQ(TilePriority::NOW
, prioritized_tile
.priority().priority_bin
);
194 if (prioritized_tile
.priority().resolution
== LOW_RESOLUTION
)
197 smoothness_tiles
.insert(prioritized_tile
.tile());
200 EXPECT_EQ(all_tiles
, smoothness_tiles
);
201 EXPECT_TRUE(had_low_res
);
203 // Check that everything is required for activation.
204 queue
= host_impl_
.BuildRasterQueue(
205 SMOOTHNESS_TAKES_PRIORITY
,
206 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
);
207 std::set
<Tile
*> required_for_activation_tiles
;
208 while (!queue
->IsEmpty()) {
209 PrioritizedTile prioritized_tile
= queue
->Top();
210 EXPECT_TRUE(prioritized_tile
.tile()->required_for_activation());
211 required_for_activation_tiles
.insert(prioritized_tile
.tile());
214 EXPECT_EQ(all_tiles
, required_for_activation_tiles
);
216 // Check that everything is required for draw.
217 queue
= host_impl_
.BuildRasterQueue(
218 SMOOTHNESS_TAKES_PRIORITY
,
219 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW
);
220 std::set
<Tile
*> required_for_draw_tiles
;
221 while (!queue
->IsEmpty()) {
222 PrioritizedTile prioritized_tile
= queue
->Top();
223 EXPECT_TRUE(prioritized_tile
.tile()->required_for_draw());
224 required_for_draw_tiles
.insert(prioritized_tile
.tile());
227 EXPECT_EQ(all_tiles
, required_for_draw_tiles
);
229 Region
invalidation(gfx::Rect(0, 0, 500, 500));
231 // Invalidate the pending tree.
232 pending_layer_
->set_invalidation(invalidation
);
233 pending_layer_
->HighResTiling()->Invalidate(invalidation
);
235 // Renew all of the tile priorities.
236 gfx::Rect
viewport(50, 50, 100, 100);
237 pending_layer_
->HighResTiling()->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0,
239 active_layer_
->HighResTiling()->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0,
241 active_layer_
->LowResTiling()->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0,
244 // Populate all tiles directly from the tilings.
246 std::set
<Tile
*> high_res_tiles
;
247 std::vector
<Tile
*> pending_high_res_tiles
=
248 pending_layer_
->HighResTiling()->AllTilesForTesting();
249 for (size_t i
= 0; i
< pending_high_res_tiles
.size(); ++i
) {
250 all_tiles
.insert(pending_high_res_tiles
[i
]);
251 high_res_tiles
.insert(pending_high_res_tiles
[i
]);
254 std::vector
<Tile
*> active_high_res_tiles
=
255 active_layer_
->HighResTiling()->AllTilesForTesting();
256 for (size_t i
= 0; i
< active_high_res_tiles
.size(); ++i
) {
257 all_tiles
.insert(active_high_res_tiles
[i
]);
258 high_res_tiles
.insert(active_high_res_tiles
[i
]);
261 std::vector
<Tile
*> active_low_res_tiles
=
262 active_layer_
->LowResTiling()->AllTilesForTesting();
263 for (size_t i
= 0; i
< active_low_res_tiles
.size(); ++i
)
264 all_tiles
.insert(active_low_res_tiles
[i
]);
266 PrioritizedTile last_tile
;
267 smoothness_tiles
.clear();
269 size_t correct_order_tiles
= 0u;
270 // Here we expect to get increasing ACTIVE_TREE priority_bin.
271 queue
= host_impl_
.BuildRasterQueue(SMOOTHNESS_TAKES_PRIORITY
,
272 RasterTilePriorityQueue::Type::ALL
);
273 std::set
<Tile
*> expected_required_for_draw_tiles
;
274 std::set
<Tile
*> expected_required_for_activation_tiles
;
275 while (!queue
->IsEmpty()) {
276 PrioritizedTile prioritized_tile
= queue
->Top();
277 EXPECT_TRUE(prioritized_tile
.tile());
279 if (!last_tile
.tile())
280 last_tile
= prioritized_tile
;
282 EXPECT_LE(last_tile
.priority().priority_bin
,
283 prioritized_tile
.priority().priority_bin
);
284 bool skip_updating_last_tile
= false;
285 if (last_tile
.priority().priority_bin
==
286 prioritized_tile
.priority().priority_bin
) {
287 correct_order_tiles
+= last_tile
.priority().distance_to_visible
<=
288 prioritized_tile
.priority().distance_to_visible
;
289 } else if (prioritized_tile
.priority().priority_bin
== TilePriority::NOW
) {
290 // Since we'd return pending tree now tiles before the eventually tiles on
291 // the active tree, update the value.
292 ++correct_order_tiles
;
293 skip_updating_last_tile
= true;
296 if (prioritized_tile
.priority().priority_bin
== TilePriority::NOW
&&
297 last_tile
.priority().resolution
!=
298 prioritized_tile
.priority().resolution
) {
299 // Low resolution should come first.
300 EXPECT_EQ(LOW_RESOLUTION
, last_tile
.priority().resolution
);
303 if (!skip_updating_last_tile
)
304 last_tile
= prioritized_tile
;
306 smoothness_tiles
.insert(prioritized_tile
.tile());
307 if (prioritized_tile
.tile()->required_for_draw())
308 expected_required_for_draw_tiles
.insert(prioritized_tile
.tile());
309 if (prioritized_tile
.tile()->required_for_activation())
310 expected_required_for_activation_tiles
.insert(prioritized_tile
.tile());
314 EXPECT_EQ(tile_count
, smoothness_tiles
.size());
315 EXPECT_EQ(all_tiles
, smoothness_tiles
);
316 // Since we don't guarantee increasing distance due to spiral iterator, we
317 // should check that we're _mostly_ right.
318 EXPECT_GT(correct_order_tiles
, 3 * tile_count
/ 4);
320 // Check that we have consistent required_for_activation tiles.
321 queue
= host_impl_
.BuildRasterQueue(
322 SMOOTHNESS_TAKES_PRIORITY
,
323 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
);
324 required_for_activation_tiles
.clear();
325 while (!queue
->IsEmpty()) {
326 PrioritizedTile prioritized_tile
= queue
->Top();
327 EXPECT_TRUE(prioritized_tile
.tile()->required_for_activation());
328 required_for_activation_tiles
.insert(prioritized_tile
.tile());
331 EXPECT_EQ(expected_required_for_activation_tiles
,
332 required_for_activation_tiles
);
333 EXPECT_NE(all_tiles
, required_for_activation_tiles
);
335 // Check that we have consistent required_for_draw tiles.
336 queue
= host_impl_
.BuildRasterQueue(
337 SMOOTHNESS_TAKES_PRIORITY
,
338 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW
);
339 required_for_draw_tiles
.clear();
340 while (!queue
->IsEmpty()) {
341 PrioritizedTile prioritized_tile
= queue
->Top();
342 EXPECT_TRUE(prioritized_tile
.tile()->required_for_draw());
343 required_for_draw_tiles
.insert(prioritized_tile
.tile());
346 EXPECT_EQ(expected_required_for_draw_tiles
, required_for_draw_tiles
);
347 EXPECT_NE(all_tiles
, required_for_draw_tiles
);
349 std::set
<Tile
*> new_content_tiles
;
350 last_tile
= PrioritizedTile();
351 size_t increasing_distance_tiles
= 0u;
352 // Here we expect to get increasing PENDING_TREE priority_bin.
353 queue
= host_impl_
.BuildRasterQueue(NEW_CONTENT_TAKES_PRIORITY
,
354 RasterTilePriorityQueue::Type::ALL
);
356 while (!queue
->IsEmpty()) {
357 PrioritizedTile prioritized_tile
= queue
->Top();
358 EXPECT_TRUE(prioritized_tile
.tile());
360 if (!last_tile
.tile())
361 last_tile
= prioritized_tile
;
363 EXPECT_LE(last_tile
.priority().priority_bin
,
364 prioritized_tile
.priority().priority_bin
);
365 if (last_tile
.priority().priority_bin
==
366 prioritized_tile
.priority().priority_bin
) {
367 increasing_distance_tiles
+=
368 last_tile
.priority().distance_to_visible
<=
369 prioritized_tile
.priority().distance_to_visible
;
372 if (prioritized_tile
.priority().priority_bin
== TilePriority::NOW
&&
373 last_tile
.priority().resolution
!=
374 prioritized_tile
.priority().resolution
) {
375 // High resolution should come first.
376 EXPECT_EQ(HIGH_RESOLUTION
, last_tile
.priority().resolution
);
379 last_tile
= prioritized_tile
;
380 new_content_tiles
.insert(prioritized_tile
.tile());
385 EXPECT_EQ(tile_count
, new_content_tiles
.size());
386 EXPECT_EQ(high_res_tiles
, new_content_tiles
);
387 // Since we don't guarantee increasing distance due to spiral iterator, we
388 // should check that we're _mostly_ right.
389 EXPECT_GE(increasing_distance_tiles
, 3 * tile_count
/ 4);
391 // Check that we have consistent required_for_activation tiles.
392 queue
= host_impl_
.BuildRasterQueue(
393 NEW_CONTENT_TAKES_PRIORITY
,
394 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
);
395 required_for_activation_tiles
.clear();
396 while (!queue
->IsEmpty()) {
397 PrioritizedTile prioritized_tile
= queue
->Top();
398 EXPECT_TRUE(prioritized_tile
.tile()->required_for_activation());
399 required_for_activation_tiles
.insert(prioritized_tile
.tile());
402 EXPECT_EQ(expected_required_for_activation_tiles
,
403 required_for_activation_tiles
);
404 EXPECT_NE(new_content_tiles
, required_for_activation_tiles
);
406 // Check that we have consistent required_for_draw tiles.
407 queue
= host_impl_
.BuildRasterQueue(
408 NEW_CONTENT_TAKES_PRIORITY
,
409 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW
);
410 required_for_draw_tiles
.clear();
411 while (!queue
->IsEmpty()) {
412 PrioritizedTile prioritized_tile
= queue
->Top();
413 EXPECT_TRUE(prioritized_tile
.tile()->required_for_draw());
414 required_for_draw_tiles
.insert(prioritized_tile
.tile());
417 EXPECT_EQ(expected_required_for_draw_tiles
, required_for_draw_tiles
);
418 EXPECT_NE(new_content_tiles
, required_for_draw_tiles
);
421 TEST_F(TileManagerTilePriorityQueueTest
,
422 RasterTilePriorityQueueHighNonIdealTilings
) {
423 const gfx::Size
layer_bounds(1000, 1000);
424 const gfx::Size
viewport(800, 800);
425 host_impl_
.SetViewportSize(viewport
);
426 SetupDefaultTrees(layer_bounds
);
428 pending_layer_
->tilings()->AddTiling(1.5f
, pending_layer_
->raster_source());
429 active_layer_
->tilings()->AddTiling(1.5f
, active_layer_
->raster_source());
430 pending_layer_
->tilings()->AddTiling(1.7f
, pending_layer_
->raster_source());
431 active_layer_
->tilings()->AddTiling(1.7f
, active_layer_
->raster_source());
433 pending_layer_
->tilings()->UpdateTilePriorities(gfx::Rect(viewport
), 1.f
, 5.0,
435 active_layer_
->tilings()->UpdateTilePriorities(gfx::Rect(viewport
), 1.f
, 5.0,
438 std::set
<Tile
*> all_expected_tiles
;
439 for (size_t i
= 0; i
< pending_layer_
->num_tilings(); ++i
) {
440 PictureLayerTiling
* tiling
= pending_layer_
->tilings()->tiling_at(i
);
441 if (tiling
->contents_scale() == 1.f
) {
442 tiling
->set_resolution(HIGH_RESOLUTION
);
443 const auto& all_tiles
= tiling
->AllTilesForTesting();
444 all_expected_tiles
.insert(all_tiles
.begin(), all_tiles
.end());
446 tiling
->set_resolution(NON_IDEAL_RESOLUTION
);
450 for (size_t i
= 0; i
< active_layer_
->num_tilings(); ++i
) {
451 PictureLayerTiling
* tiling
= active_layer_
->tilings()->tiling_at(i
);
452 if (tiling
->contents_scale() == 1.5f
) {
453 tiling
->set_resolution(HIGH_RESOLUTION
);
454 const auto& all_tiles
= tiling
->AllTilesForTesting();
455 all_expected_tiles
.insert(all_tiles
.begin(), all_tiles
.end());
457 tiling
->set_resolution(NON_IDEAL_RESOLUTION
);
458 // Non ideal tilings with a high res pending twin have to be processed
459 // because of possible activation tiles.
460 if (tiling
->contents_scale() == 1.f
) {
461 tiling
->UpdateAndGetAllPrioritizedTilesForTesting();
462 const auto& all_tiles
= tiling
->AllTilesForTesting();
463 for (auto* tile
: all_tiles
)
464 EXPECT_TRUE(tile
->required_for_activation());
465 all_expected_tiles
.insert(all_tiles
.begin(), all_tiles
.end());
470 scoped_ptr
<RasterTilePriorityQueue
> queue(host_impl_
.BuildRasterQueue(
471 SMOOTHNESS_TAKES_PRIORITY
, RasterTilePriorityQueue::Type::ALL
));
472 EXPECT_FALSE(queue
->IsEmpty());
474 size_t tile_count
= 0;
475 std::set
<Tile
*> all_actual_tiles
;
476 while (!queue
->IsEmpty()) {
477 EXPECT_TRUE(queue
->Top().tile());
478 all_actual_tiles
.insert(queue
->Top().tile());
483 EXPECT_EQ(tile_count
, all_actual_tiles
.size());
484 EXPECT_EQ(all_expected_tiles
.size(), all_actual_tiles
.size());
485 EXPECT_EQ(all_expected_tiles
, all_actual_tiles
);
488 TEST_F(TileManagerTilePriorityQueueTest
, RasterTilePriorityQueueInvalidation
) {
489 const gfx::Size
layer_bounds(1000, 1000);
490 host_impl_
.SetViewportSize(gfx::Size(500, 500));
491 SetupDefaultTrees(layer_bounds
);
493 // Use a tile's content rect as an invalidation. We should inset it a bit to
494 // ensure that border math doesn't invalidate neighbouring tiles.
495 gfx::Rect invalidation
=
496 active_layer_
->HighResTiling()->TileAt(1, 0)->content_rect();
497 invalidation
.Inset(2, 2);
499 pending_layer_
->set_invalidation(invalidation
);
500 pending_layer_
->HighResTiling()->Invalidate(invalidation
);
501 pending_layer_
->HighResTiling()->CreateMissingTilesInLiveTilesRect();
503 // Sanity checks: Tile at 0, 0 not exist on the pending tree (it's not
504 // invalidated). Tile 1, 0 should exist on both.
505 EXPECT_FALSE(pending_layer_
->HighResTiling()->TileAt(0, 0));
506 EXPECT_TRUE(active_layer_
->HighResTiling()->TileAt(0, 0));
507 EXPECT_TRUE(pending_layer_
->HighResTiling()->TileAt(1, 0));
508 EXPECT_TRUE(active_layer_
->HighResTiling()->TileAt(1, 0));
509 EXPECT_NE(pending_layer_
->HighResTiling()->TileAt(1, 0),
510 active_layer_
->HighResTiling()->TileAt(1, 0));
512 std::set
<Tile
*> expected_now_tiles
;
513 std::set
<Tile
*> expected_required_for_draw_tiles
;
514 std::set
<Tile
*> expected_required_for_activation_tiles
;
515 for (int i
= 0; i
<= 1; ++i
) {
516 for (int j
= 0; j
<= 1; ++j
) {
517 bool have_pending_tile
= false;
518 if (pending_layer_
->HighResTiling()->TileAt(i
, j
)) {
519 expected_now_tiles
.insert(
520 pending_layer_
->HighResTiling()->TileAt(i
, j
));
521 expected_required_for_activation_tiles
.insert(
522 pending_layer_
->HighResTiling()->TileAt(i
, j
));
523 have_pending_tile
= true;
525 Tile
* active_tile
= active_layer_
->HighResTiling()->TileAt(i
, j
);
526 EXPECT_TRUE(active_tile
);
527 expected_now_tiles
.insert(active_tile
);
528 expected_required_for_draw_tiles
.insert(active_tile
);
529 if (!have_pending_tile
)
530 expected_required_for_activation_tiles
.insert(active_tile
);
533 // Expect 3 shared tiles and 1 unshared tile in total.
534 EXPECT_EQ(5u, expected_now_tiles
.size());
535 // Expect 4 tiles for each draw and activation, but not all the same.
536 EXPECT_EQ(4u, expected_required_for_activation_tiles
.size());
537 EXPECT_EQ(4u, expected_required_for_draw_tiles
.size());
538 EXPECT_NE(expected_required_for_draw_tiles
,
539 expected_required_for_activation_tiles
);
541 std::set
<Tile
*> expected_all_tiles
;
542 for (int i
= 0; i
<= 3; ++i
) {
543 for (int j
= 0; j
<= 3; ++j
) {
544 if (pending_layer_
->HighResTiling()->TileAt(i
, j
))
545 expected_all_tiles
.insert(
546 pending_layer_
->HighResTiling()->TileAt(i
, j
));
547 EXPECT_TRUE(active_layer_
->HighResTiling()->TileAt(i
, j
));
548 expected_all_tiles
.insert(active_layer_
->HighResTiling()->TileAt(i
, j
));
551 // Expect 15 shared tiles and 1 unshared tile.
552 EXPECT_EQ(17u, expected_all_tiles
.size());
554 // The actual test will now build different queues and verify that the queues
555 // return the same information as computed manually above.
556 scoped_ptr
<RasterTilePriorityQueue
> queue(host_impl_
.BuildRasterQueue(
557 SAME_PRIORITY_FOR_BOTH_TREES
, RasterTilePriorityQueue::Type::ALL
));
558 std::set
<Tile
*> actual_now_tiles
;
559 std::set
<Tile
*> actual_all_tiles
;
560 while (!queue
->IsEmpty()) {
561 PrioritizedTile prioritized_tile
= queue
->Top();
563 if (prioritized_tile
.priority().priority_bin
== TilePriority::NOW
)
564 actual_now_tiles
.insert(prioritized_tile
.tile());
565 actual_all_tiles
.insert(prioritized_tile
.tile());
567 EXPECT_EQ(expected_now_tiles
, actual_now_tiles
);
568 EXPECT_EQ(expected_all_tiles
, actual_all_tiles
);
570 queue
= host_impl_
.BuildRasterQueue(
571 SAME_PRIORITY_FOR_BOTH_TREES
,
572 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW
);
573 std::set
<Tile
*> actual_required_for_draw_tiles
;
574 while (!queue
->IsEmpty()) {
575 PrioritizedTile prioritized_tile
= queue
->Top();
577 actual_required_for_draw_tiles
.insert(prioritized_tile
.tile());
579 EXPECT_EQ(expected_required_for_draw_tiles
, actual_required_for_draw_tiles
);
581 queue
= host_impl_
.BuildRasterQueue(
582 SAME_PRIORITY_FOR_BOTH_TREES
,
583 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION
);
584 std::set
<Tile
*> actual_required_for_activation_tiles
;
585 while (!queue
->IsEmpty()) {
586 Tile
* tile
= queue
->Top().tile();
588 actual_required_for_activation_tiles
.insert(tile
);
590 EXPECT_EQ(expected_required_for_activation_tiles
,
591 actual_required_for_activation_tiles
);
594 TEST_F(TileManagerTilePriorityQueueTest
, ActivationComesBeforeEventually
) {
595 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
597 gfx::Size
layer_bounds(1000, 1000);
598 SetupDefaultTrees(layer_bounds
);
600 // Create a pending child layer.
601 gfx::Size
tile_size(256, 256);
602 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
603 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
604 scoped_ptr
<FakePictureLayerImpl
> pending_child
=
605 FakePictureLayerImpl::CreateWithRasterSource(host_impl_
.pending_tree(),
606 id_
+ 1, pending_pile
);
607 FakePictureLayerImpl
* pending_child_raw
= pending_child
.get();
608 pending_child_raw
->SetDrawsContent(true);
609 pending_layer_
->AddChild(pending_child
.Pass());
611 // Set a small viewport, so we have soon and eventually tiles.
612 host_impl_
.SetViewportSize(gfx::Size(200, 200));
613 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
614 bool update_lcd_text
= false;
615 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
617 host_impl_
.SetRequiresHighResToDraw();
618 scoped_ptr
<RasterTilePriorityQueue
> queue(host_impl_
.BuildRasterQueue(
619 SMOOTHNESS_TAKES_PRIORITY
, RasterTilePriorityQueue::Type::ALL
));
620 EXPECT_FALSE(queue
->IsEmpty());
622 // Get all the tiles that are NOW or SOON and make sure they are ready to
624 std::vector
<Tile
*> all_tiles
;
625 while (!queue
->IsEmpty()) {
626 PrioritizedTile prioritized_tile
= queue
->Top();
627 if (prioritized_tile
.priority().priority_bin
>= TilePriority::EVENTUALLY
)
630 all_tiles
.push_back(prioritized_tile
.tile());
634 tile_manager()->InitializeTilesWithResourcesForTesting(
635 std::vector
<Tile
*>(all_tiles
.begin(), all_tiles
.end()));
637 // Ensure we can activate.
638 EXPECT_TRUE(tile_manager()->IsReadyToActivate());
641 TEST_F(TileManagerTilePriorityQueueTest
, EvictionTilePriorityQueue
) {
642 const gfx::Size
layer_bounds(1000, 1000);
643 host_impl_
.SetViewportSize(layer_bounds
);
644 SetupDefaultTrees(layer_bounds
);
645 ASSERT_TRUE(active_layer_
->HighResTiling());
646 ASSERT_TRUE(active_layer_
->LowResTiling());
647 ASSERT_TRUE(pending_layer_
->HighResTiling());
648 EXPECT_FALSE(pending_layer_
->LowResTiling());
650 scoped_ptr
<EvictionTilePriorityQueue
> empty_queue(
651 host_impl_
.BuildEvictionQueue(SAME_PRIORITY_FOR_BOTH_TREES
));
652 EXPECT_TRUE(empty_queue
->IsEmpty());
653 std::set
<Tile
*> all_tiles
;
654 size_t tile_count
= 0;
656 scoped_ptr
<RasterTilePriorityQueue
> raster_queue(host_impl_
.BuildRasterQueue(
657 SAME_PRIORITY_FOR_BOTH_TREES
, RasterTilePriorityQueue::Type::ALL
));
658 while (!raster_queue
->IsEmpty()) {
660 EXPECT_TRUE(raster_queue
->Top().tile());
661 all_tiles
.insert(raster_queue
->Top().tile());
665 EXPECT_EQ(tile_count
, all_tiles
.size());
666 EXPECT_EQ(16u, tile_count
);
668 tile_manager()->InitializeTilesWithResourcesForTesting(
669 std::vector
<Tile
*>(all_tiles
.begin(), all_tiles
.end()));
671 scoped_ptr
<EvictionTilePriorityQueue
> queue(
672 host_impl_
.BuildEvictionQueue(SMOOTHNESS_TAKES_PRIORITY
));
673 EXPECT_FALSE(queue
->IsEmpty());
675 // Sanity check, all tiles should be visible.
676 std::set
<Tile
*> smoothness_tiles
;
677 while (!queue
->IsEmpty()) {
678 PrioritizedTile prioritized_tile
= queue
->Top();
679 EXPECT_TRUE(prioritized_tile
.tile());
680 EXPECT_EQ(TilePriority::NOW
, prioritized_tile
.priority().priority_bin
);
681 EXPECT_TRUE(prioritized_tile
.tile()->draw_info().has_resource());
682 smoothness_tiles
.insert(prioritized_tile
.tile());
685 EXPECT_EQ(all_tiles
, smoothness_tiles
);
687 tile_manager()->ReleaseTileResourcesForTesting(
688 std::vector
<Tile
*>(all_tiles
.begin(), all_tiles
.end()));
690 Region
invalidation(gfx::Rect(0, 0, 500, 500));
692 // Invalidate the pending tree.
693 pending_layer_
->set_invalidation(invalidation
);
694 pending_layer_
->HighResTiling()->Invalidate(invalidation
);
695 pending_layer_
->HighResTiling()->CreateMissingTilesInLiveTilesRect();
696 EXPECT_FALSE(pending_layer_
->LowResTiling());
698 // Renew all of the tile priorities.
699 gfx::Rect
viewport(50, 50, 100, 100);
700 pending_layer_
->HighResTiling()->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0,
702 active_layer_
->HighResTiling()->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0,
704 active_layer_
->LowResTiling()->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0,
707 // Populate all tiles directly from the tilings.
709 std::vector
<Tile
*> pending_high_res_tiles
=
710 pending_layer_
->HighResTiling()->AllTilesForTesting();
711 for (size_t i
= 0; i
< pending_high_res_tiles
.size(); ++i
)
712 all_tiles
.insert(pending_high_res_tiles
[i
]);
714 std::vector
<Tile
*> active_high_res_tiles
=
715 active_layer_
->HighResTiling()->AllTilesForTesting();
716 for (size_t i
= 0; i
< active_high_res_tiles
.size(); ++i
)
717 all_tiles
.insert(active_high_res_tiles
[i
]);
719 std::vector
<Tile
*> active_low_res_tiles
=
720 active_layer_
->LowResTiling()->AllTilesForTesting();
721 for (size_t i
= 0; i
< active_low_res_tiles
.size(); ++i
)
722 all_tiles
.insert(active_low_res_tiles
[i
]);
724 tile_manager()->InitializeTilesWithResourcesForTesting(
725 std::vector
<Tile
*>(all_tiles
.begin(), all_tiles
.end()));
727 PrioritizedTile last_tile
;
728 smoothness_tiles
.clear();
730 // Here we expect to get increasing combined priority_bin.
731 queue
= host_impl_
.BuildEvictionQueue(SMOOTHNESS_TAKES_PRIORITY
);
732 int distance_increasing
= 0;
733 int distance_decreasing
= 0;
734 while (!queue
->IsEmpty()) {
735 PrioritizedTile prioritized_tile
= queue
->Top();
736 Tile
* tile
= prioritized_tile
.tile();
738 EXPECT_TRUE(tile
->draw_info().has_resource());
740 if (!last_tile
.tile())
741 last_tile
= prioritized_tile
;
743 const TilePriority
& last_priority
= last_tile
.priority();
744 const TilePriority
& priority
= prioritized_tile
.priority();
746 EXPECT_GE(last_priority
.priority_bin
, priority
.priority_bin
);
747 if (last_priority
.priority_bin
== priority
.priority_bin
) {
748 EXPECT_LE(last_tile
.tile()->required_for_activation(),
749 tile
->required_for_activation());
750 if (last_tile
.tile()->required_for_activation() ==
751 tile
->required_for_activation()) {
752 if (last_priority
.distance_to_visible
>= priority
.distance_to_visible
)
753 ++distance_decreasing
;
755 ++distance_increasing
;
759 last_tile
= prioritized_tile
;
761 smoothness_tiles
.insert(tile
);
765 // Ensure that the distance is decreasing many more times than increasing.
766 EXPECT_EQ(3, distance_increasing
);
767 EXPECT_EQ(16, distance_decreasing
);
768 EXPECT_EQ(tile_count
, smoothness_tiles
.size());
769 EXPECT_EQ(all_tiles
, smoothness_tiles
);
771 std::set
<Tile
*> new_content_tiles
;
772 last_tile
= PrioritizedTile();
773 // Again, we expect to get increasing combined priority_bin.
774 queue
= host_impl_
.BuildEvictionQueue(NEW_CONTENT_TAKES_PRIORITY
);
775 distance_decreasing
= 0;
776 distance_increasing
= 0;
777 while (!queue
->IsEmpty()) {
778 PrioritizedTile prioritized_tile
= queue
->Top();
779 Tile
* tile
= prioritized_tile
.tile();
782 if (!last_tile
.tile())
783 last_tile
= prioritized_tile
;
785 const TilePriority
& last_priority
= last_tile
.priority();
786 const TilePriority
& priority
= prioritized_tile
.priority();
788 EXPECT_GE(last_priority
.priority_bin
, priority
.priority_bin
);
789 if (last_priority
.priority_bin
== priority
.priority_bin
) {
790 EXPECT_LE(last_tile
.tile()->required_for_activation(),
791 tile
->required_for_activation());
792 if (last_tile
.tile()->required_for_activation() ==
793 tile
->required_for_activation()) {
794 if (last_priority
.distance_to_visible
>= priority
.distance_to_visible
)
795 ++distance_decreasing
;
797 ++distance_increasing
;
801 last_tile
= prioritized_tile
;
802 new_content_tiles
.insert(tile
);
806 // Ensure that the distance is decreasing many more times than increasing.
807 EXPECT_EQ(3, distance_increasing
);
808 EXPECT_EQ(16, distance_decreasing
);
809 EXPECT_EQ(tile_count
, new_content_tiles
.size());
810 EXPECT_EQ(all_tiles
, new_content_tiles
);
813 TEST_F(TileManagerTilePriorityQueueTest
,
814 EvictionTilePriorityQueueWithOcclusion
) {
815 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
817 gfx::Size
tile_size(102, 102);
818 gfx::Size
layer_bounds(1000, 1000);
820 host_impl_
.SetViewportSize(layer_bounds
);
822 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
823 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
824 SetupPendingTree(pending_pile
);
826 scoped_ptr
<FakePictureLayerImpl
> pending_child
=
827 FakePictureLayerImpl::CreateWithRasterSource(host_impl_
.pending_tree(), 2,
829 pending_layer_
->AddChild(pending_child
.Pass());
831 FakePictureLayerImpl
* pending_child_layer
=
832 static_cast<FakePictureLayerImpl
*>(pending_layer_
->children()[0]);
833 pending_child_layer
->SetDrawsContent(true);
835 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
836 bool update_lcd_text
= false;
837 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
840 SetupPendingTree(pending_pile
);
842 FakePictureLayerImpl
* active_child_layer
=
843 static_cast<FakePictureLayerImpl
*>(active_layer_
->children()[0]);
845 std::set
<Tile
*> all_tiles
;
846 size_t tile_count
= 0;
847 scoped_ptr
<RasterTilePriorityQueue
> raster_queue(host_impl_
.BuildRasterQueue(
848 SAME_PRIORITY_FOR_BOTH_TREES
, RasterTilePriorityQueue::Type::ALL
));
849 while (!raster_queue
->IsEmpty()) {
851 EXPECT_TRUE(raster_queue
->Top().tile());
852 all_tiles
.insert(raster_queue
->Top().tile());
855 EXPECT_EQ(tile_count
, all_tiles
.size());
856 EXPECT_EQ(32u, tile_count
);
858 // Renew all of the tile priorities.
859 gfx::Rect
viewport(layer_bounds
);
860 pending_layer_
->HighResTiling()->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0,
862 pending_child_layer
->HighResTiling()->ComputeTilePriorityRects(
863 viewport
, 1.0f
, 1.0, Occlusion());
865 active_layer_
->HighResTiling()->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0,
867 active_layer_
->LowResTiling()->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0,
869 active_child_layer
->HighResTiling()->ComputeTilePriorityRects(
870 viewport
, 1.0f
, 1.0, Occlusion());
871 active_child_layer
->LowResTiling()->ComputeTilePriorityRects(
872 viewport
, 1.0f
, 1.0, Occlusion());
874 // Populate all tiles directly from the tilings.
876 std::vector
<Tile
*> pending_high_res_tiles
=
877 pending_layer_
->HighResTiling()->AllTilesForTesting();
878 all_tiles
.insert(pending_high_res_tiles
.begin(),
879 pending_high_res_tiles
.end());
881 // Set all tiles on the pending_child_layer as occluded on the pending tree.
882 std::vector
<Tile
*> pending_child_high_res_tiles
=
883 pending_child_layer
->HighResTiling()->AllTilesForTesting();
884 pending_child_layer
->HighResTiling()->SetAllTilesOccludedForTesting();
885 active_child_layer
->HighResTiling()->SetAllTilesOccludedForTesting();
886 active_child_layer
->LowResTiling()->SetAllTilesOccludedForTesting();
888 tile_manager()->InitializeTilesWithResourcesForTesting(
889 std::vector
<Tile
*>(all_tiles
.begin(), all_tiles
.end()));
891 // Verify occlusion is considered by EvictionTilePriorityQueue.
892 TreePriority tree_priority
= NEW_CONTENT_TAKES_PRIORITY
;
893 size_t occluded_count
= 0u;
894 PrioritizedTile last_tile
;
895 scoped_ptr
<EvictionTilePriorityQueue
> queue(
896 host_impl_
.BuildEvictionQueue(tree_priority
));
897 while (!queue
->IsEmpty()) {
898 PrioritizedTile prioritized_tile
= queue
->Top();
899 if (!last_tile
.tile())
900 last_tile
= prioritized_tile
;
902 bool tile_is_occluded
= prioritized_tile
.is_occluded();
904 // The only way we will encounter an occluded tile after an unoccluded
905 // tile is if the priorty bin decreased, the tile is required for
906 // activation, or the scale changed.
907 if (tile_is_occluded
) {
910 bool last_tile_is_occluded
= last_tile
.is_occluded();
911 if (!last_tile_is_occluded
) {
912 TilePriority::PriorityBin tile_priority_bin
=
913 prioritized_tile
.priority().priority_bin
;
914 TilePriority::PriorityBin last_tile_priority_bin
=
915 last_tile
.priority().priority_bin
;
917 EXPECT_TRUE((tile_priority_bin
< last_tile_priority_bin
) ||
918 prioritized_tile
.tile()->required_for_activation() ||
919 (prioritized_tile
.tile()->contents_scale() !=
920 last_tile
.tile()->contents_scale()));
923 last_tile
= prioritized_tile
;
926 size_t expected_occluded_count
= pending_child_high_res_tiles
.size();
927 EXPECT_EQ(expected_occluded_count
, occluded_count
);
930 TEST_F(TileManagerTilePriorityQueueTest
,
931 EvictionTilePriorityQueueWithTransparentLayer
) {
932 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
934 gfx::Size
tile_size(102, 102);
935 gfx::Size
layer_bounds(1000, 1000);
937 scoped_refptr
<FakePicturePileImpl
> pending_pile
=
938 FakePicturePileImpl::CreateFilledPile(tile_size
, layer_bounds
);
939 SetupPendingTree(pending_pile
);
941 scoped_ptr
<FakePictureLayerImpl
> pending_child
=
942 FakePictureLayerImpl::CreateWithRasterSource(host_impl_
.pending_tree(), 2,
944 FakePictureLayerImpl
* pending_child_layer
= pending_child
.get();
945 pending_layer_
->AddChild(pending_child
.Pass());
947 // Create a fully transparent child layer so that its tile priorities are not
948 // considered to be valid.
949 pending_child_layer
->SetDrawsContent(true);
951 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
952 bool update_lcd_text
= false;
953 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
955 pending_child_layer
->SetOpacity(0.0);
957 host_impl_
.AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1));
958 host_impl_
.pending_tree()->UpdateDrawProperties(update_lcd_text
);
960 // Renew all of the tile priorities.
961 gfx::Rect
viewport(layer_bounds
);
962 pending_layer_
->HighResTiling()->ComputeTilePriorityRects(viewport
, 1.0f
, 1.0,
964 pending_child_layer
->HighResTiling()->ComputeTilePriorityRects(
965 viewport
, 1.0f
, 1.0, Occlusion());
967 // Populate all tiles directly from the tilings.
968 std::set
<Tile
*> all_pending_tiles
;
969 std::vector
<Tile
*> pending_high_res_tiles
=
970 pending_layer_
->HighResTiling()->AllTilesForTesting();
971 all_pending_tiles
.insert(pending_high_res_tiles
.begin(),
972 pending_high_res_tiles
.end());
973 EXPECT_EQ(16u, pending_high_res_tiles
.size());
975 std::set
<Tile
*> all_pending_child_tiles
;
976 std::vector
<Tile
*> pending_child_high_res_tiles
=
977 pending_child_layer
->HighResTiling()->AllTilesForTesting();
978 all_pending_child_tiles
.insert(pending_child_high_res_tiles
.begin(),
979 pending_child_high_res_tiles
.end());
980 EXPECT_EQ(16u, pending_child_high_res_tiles
.size());
982 std::set
<Tile
*> all_tiles
= all_pending_tiles
;
983 all_tiles
.insert(all_pending_child_tiles
.begin(),
984 all_pending_child_tiles
.end());
986 tile_manager()->InitializeTilesWithResourcesForTesting(
987 std::vector
<Tile
*>(all_tiles
.begin(), all_tiles
.end()));
989 EXPECT_TRUE(pending_layer_
->HasValidTilePriorities());
990 EXPECT_FALSE(pending_child_layer
->HasValidTilePriorities());
992 // Verify that eviction queue returns tiles also from layers without valid
993 // tile priorities and that the tile priority bin of those tiles is (at most)
995 TreePriority tree_priority
= NEW_CONTENT_TAKES_PRIORITY
;
996 std::set
<Tile
*> new_content_tiles
;
997 size_t tile_count
= 0;
998 scoped_ptr
<EvictionTilePriorityQueue
> queue(
999 host_impl_
.BuildEvictionQueue(tree_priority
));
1000 while (!queue
->IsEmpty()) {
1001 PrioritizedTile prioritized_tile
= queue
->Top();
1002 Tile
* tile
= prioritized_tile
.tile();
1003 const TilePriority
& pending_priority
= prioritized_tile
.priority();
1004 EXPECT_NE(std::numeric_limits
<float>::infinity(),
1005 pending_priority
.distance_to_visible
);
1006 if (all_pending_child_tiles
.find(tile
) != all_pending_child_tiles
.end())
1007 EXPECT_EQ(TilePriority::EVENTUALLY
, pending_priority
.priority_bin
);
1009 EXPECT_EQ(TilePriority::NOW
, pending_priority
.priority_bin
);
1010 new_content_tiles
.insert(tile
);
1014 EXPECT_EQ(tile_count
, new_content_tiles
.size());
1015 EXPECT_EQ(all_tiles
, new_content_tiles
);
1018 TEST_F(TileManagerTilePriorityQueueTest
, RasterTilePriorityQueueEmptyLayers
) {
1019 const gfx::Size
layer_bounds(1000, 1000);
1020 host_impl_
.SetViewportSize(layer_bounds
);
1021 SetupDefaultTrees(layer_bounds
);
1023 scoped_ptr
<RasterTilePriorityQueue
> queue(host_impl_
.BuildRasterQueue(
1024 SAME_PRIORITY_FOR_BOTH_TREES
, RasterTilePriorityQueue::Type::ALL
));
1025 EXPECT_FALSE(queue
->IsEmpty());
1027 size_t tile_count
= 0;
1028 std::set
<Tile
*> all_tiles
;
1029 while (!queue
->IsEmpty()) {
1030 EXPECT_TRUE(queue
->Top().tile());
1031 all_tiles
.insert(queue
->Top().tile());
1036 EXPECT_EQ(tile_count
, all_tiles
.size());
1037 EXPECT_EQ(16u, tile_count
);
1039 for (int i
= 1; i
< 10; ++i
) {
1040 scoped_ptr
<FakePictureLayerImpl
> pending_layer
=
1041 FakePictureLayerImpl::Create(host_impl_
.pending_tree(), id_
+ i
);
1042 pending_layer
->SetDrawsContent(true);
1043 pending_layer
->set_has_valid_tile_priorities(true);
1044 pending_layer_
->AddChild(pending_layer
.Pass());
1047 queue
= host_impl_
.BuildRasterQueue(SAME_PRIORITY_FOR_BOTH_TREES
,
1048 RasterTilePriorityQueue::Type::ALL
);
1049 EXPECT_FALSE(queue
->IsEmpty());
1053 while (!queue
->IsEmpty()) {
1054 EXPECT_TRUE(queue
->Top().tile());
1055 all_tiles
.insert(queue
->Top().tile());
1059 EXPECT_EQ(tile_count
, all_tiles
.size());
1060 EXPECT_EQ(16u, tile_count
);
1063 TEST_F(TileManagerTilePriorityQueueTest
, EvictionTilePriorityQueueEmptyLayers
) {
1064 const gfx::Size
layer_bounds(1000, 1000);
1065 host_impl_
.SetViewportSize(layer_bounds
);
1066 SetupDefaultTrees(layer_bounds
);
1068 scoped_ptr
<RasterTilePriorityQueue
> raster_queue(host_impl_
.BuildRasterQueue(
1069 SAME_PRIORITY_FOR_BOTH_TREES
, RasterTilePriorityQueue::Type::ALL
));
1070 EXPECT_FALSE(raster_queue
->IsEmpty());
1072 size_t tile_count
= 0;
1073 std::set
<Tile
*> all_tiles
;
1074 while (!raster_queue
->IsEmpty()) {
1075 EXPECT_TRUE(raster_queue
->Top().tile());
1076 all_tiles
.insert(raster_queue
->Top().tile());
1078 raster_queue
->Pop();
1080 EXPECT_EQ(tile_count
, all_tiles
.size());
1081 EXPECT_EQ(16u, tile_count
);
1083 std::vector
<Tile
*> tiles(all_tiles
.begin(), all_tiles
.end());
1084 host_impl_
.tile_manager()->InitializeTilesWithResourcesForTesting(tiles
);
1086 for (int i
= 1; i
< 10; ++i
) {
1087 scoped_ptr
<FakePictureLayerImpl
> pending_layer
=
1088 FakePictureLayerImpl::Create(host_impl_
.pending_tree(), id_
+ i
);
1089 pending_layer
->SetDrawsContent(true);
1090 pending_layer
->set_has_valid_tile_priorities(true);
1091 pending_layer_
->AddChild(pending_layer
.Pass());
1094 scoped_ptr
<EvictionTilePriorityQueue
> queue(
1095 host_impl_
.BuildEvictionQueue(SAME_PRIORITY_FOR_BOTH_TREES
));
1096 EXPECT_FALSE(queue
->IsEmpty());
1100 while (!queue
->IsEmpty()) {
1101 EXPECT_TRUE(queue
->Top().tile());
1102 all_tiles
.insert(queue
->Top().tile());
1106 EXPECT_EQ(tile_count
, all_tiles
.size());
1107 EXPECT_EQ(16u, tile_count
);
1110 TEST_F(TileManagerTilePriorityQueueTest
,
1111 RasterTilePriorityQueueStaticViewport
) {
1112 FakePictureLayerTilingClient client
;
1114 gfx::Rect
viewport(50, 50, 500, 500);
1115 gfx::Size
layer_bounds(1600, 1600);
1117 float inset
= PictureLayerTiling::CalculateSoonBorderDistance(viewport
, 1.0f
);
1118 gfx::Rect soon_rect
= viewport
;
1119 soon_rect
.Inset(-inset
, -inset
);
1121 client
.SetTileSize(gfx::Size(30, 30));
1122 LayerTreeSettings settings
;
1124 scoped_ptr
<PictureLayerTilingSet
> tiling_set
= PictureLayerTilingSet::Create(
1125 ACTIVE_TREE
, &client
, settings
.tiling_interest_area_padding
,
1126 settings
.skewport_target_time_in_seconds
,
1127 settings
.skewport_extrapolation_limit_in_content_pixels
);
1129 scoped_refptr
<FakePicturePileImpl
> pile
=
1130 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
1131 PictureLayerTiling
* tiling
= tiling_set
->AddTiling(1.0f
, pile
);
1132 tiling
->set_resolution(HIGH_RESOLUTION
);
1134 tiling_set
->UpdateTilePriorities(viewport
, 1.0f
, 1.0, Occlusion(), true);
1135 std::vector
<Tile
*> all_tiles
= tiling
->AllTilesForTesting();
1137 EXPECT_EQ(3364u, all_tiles
.size());
1139 // The explanation of each iteration is as follows:
1140 // 1. First iteration tests that we can get all of the tiles correctly.
1141 // 2. Second iteration ensures that we can get all of the tiles again (first
1142 // iteration didn't change any tiles), as well set all tiles to be ready to
1144 // 3. Third iteration ensures that no tiles are returned, since they were all
1145 // marked as ready to draw.
1146 for (int i
= 0; i
< 3; ++i
) {
1147 scoped_ptr
<TilingSetRasterQueueAll
> queue(
1148 new TilingSetRasterQueueAll(tiling_set
.get(), false));
1150 // There are 3 bins in TilePriority.
1151 bool have_tiles
[3] = {};
1153 // On the third iteration, we should get no tiles since everything was
1154 // marked as ready to draw.
1156 EXPECT_TRUE(queue
->IsEmpty());
1160 EXPECT_FALSE(queue
->IsEmpty());
1161 std::set
<Tile
*> unique_tiles
;
1162 unique_tiles
.insert(queue
->Top().tile());
1163 PrioritizedTile last_tile
= queue
->Top();
1164 have_tiles
[last_tile
.priority().priority_bin
] = true;
1166 // On the second iteration, mark everything as ready to draw (solid color).
1168 TileDrawInfo
& draw_info
= last_tile
.tile()->draw_info();
1169 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
1172 int eventually_bin_order_correct_count
= 0;
1173 int eventually_bin_order_incorrect_count
= 0;
1174 while (!queue
->IsEmpty()) {
1175 PrioritizedTile new_tile
= queue
->Top();
1177 unique_tiles
.insert(new_tile
.tile());
1179 TilePriority last_priority
= last_tile
.priority();
1180 TilePriority new_priority
= new_tile
.priority();
1181 EXPECT_LE(last_priority
.priority_bin
, new_priority
.priority_bin
);
1182 if (last_priority
.priority_bin
== new_priority
.priority_bin
) {
1183 if (last_priority
.priority_bin
== TilePriority::EVENTUALLY
) {
1184 bool order_correct
= last_priority
.distance_to_visible
<=
1185 new_priority
.distance_to_visible
;
1186 eventually_bin_order_correct_count
+= order_correct
;
1187 eventually_bin_order_incorrect_count
+= !order_correct
;
1188 } else if (!soon_rect
.Intersects(new_tile
.tile()->content_rect()) &&
1189 !soon_rect
.Intersects(last_tile
.tile()->content_rect())) {
1190 EXPECT_LE(last_priority
.distance_to_visible
,
1191 new_priority
.distance_to_visible
);
1192 EXPECT_EQ(TilePriority::NOW
, new_priority
.priority_bin
);
1193 } else if (new_priority
.distance_to_visible
> 0.f
) {
1194 EXPECT_EQ(TilePriority::SOON
, new_priority
.priority_bin
);
1197 have_tiles
[new_priority
.priority_bin
] = true;
1199 last_tile
= new_tile
;
1201 // On the second iteration, mark everything as ready to draw (solid
1204 TileDrawInfo
& draw_info
= last_tile
.tile()->draw_info();
1205 draw_info
.SetSolidColorForTesting(SK_ColorRED
);
1209 EXPECT_GT(eventually_bin_order_correct_count
,
1210 eventually_bin_order_incorrect_count
);
1212 // We should have now and eventually tiles, as well as soon tiles from
1213 // the border region.
1214 EXPECT_TRUE(have_tiles
[TilePriority::NOW
]);
1215 EXPECT_TRUE(have_tiles
[TilePriority::SOON
]);
1216 EXPECT_TRUE(have_tiles
[TilePriority::EVENTUALLY
]);
1218 EXPECT_EQ(unique_tiles
.size(), all_tiles
.size());
1222 TEST_F(TileManagerTilePriorityQueueTest
,
1223 RasterTilePriorityQueueMovingViewport
) {
1224 FakePictureLayerTilingClient client
;
1226 gfx::Rect
viewport(50, 0, 100, 100);
1227 gfx::Rect
moved_viewport(50, 0, 100, 500);
1228 gfx::Size
layer_bounds(1000, 1000);
1230 client
.SetTileSize(gfx::Size(30, 30));
1231 LayerTreeSettings settings
;
1233 scoped_ptr
<PictureLayerTilingSet
> tiling_set
= PictureLayerTilingSet::Create(
1234 ACTIVE_TREE
, &client
, settings
.tiling_interest_area_padding
,
1235 settings
.skewport_target_time_in_seconds
,
1236 settings
.skewport_extrapolation_limit_in_content_pixels
);
1238 scoped_refptr
<FakePicturePileImpl
> pile
=
1239 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
1240 PictureLayerTiling
* tiling
= tiling_set
->AddTiling(1.0f
, pile
);
1241 tiling
->set_resolution(HIGH_RESOLUTION
);
1243 tiling_set
->UpdateTilePriorities(viewport
, 1.0f
, 1.0, Occlusion(), true);
1244 tiling_set
->UpdateTilePriorities(moved_viewport
, 1.0f
, 2.0, Occlusion(),
1248 PictureLayerTiling::CalculateSoonBorderDistance(moved_viewport
, 1.0f
);
1249 gfx::Rect soon_rect
= moved_viewport
;
1250 soon_rect
.Inset(-inset
, -inset
);
1252 // There are 3 bins in TilePriority.
1253 bool have_tiles
[3] = {};
1254 PrioritizedTile last_tile
;
1255 int eventually_bin_order_correct_count
= 0;
1256 int eventually_bin_order_incorrect_count
= 0;
1257 scoped_ptr
<TilingSetRasterQueueAll
> queue(
1258 new TilingSetRasterQueueAll(tiling_set
.get(), false));
1259 for (; !queue
->IsEmpty(); queue
->Pop()) {
1260 if (!last_tile
.tile())
1261 last_tile
= queue
->Top();
1263 const PrioritizedTile
& new_tile
= queue
->Top();
1265 TilePriority last_priority
= last_tile
.priority();
1266 TilePriority new_priority
= new_tile
.priority();
1268 have_tiles
[new_priority
.priority_bin
] = true;
1270 EXPECT_LE(last_priority
.priority_bin
, new_priority
.priority_bin
);
1271 if (last_priority
.priority_bin
== new_priority
.priority_bin
) {
1272 if (last_priority
.priority_bin
== TilePriority::EVENTUALLY
) {
1273 bool order_correct
= last_priority
.distance_to_visible
<=
1274 new_priority
.distance_to_visible
;
1275 eventually_bin_order_correct_count
+= order_correct
;
1276 eventually_bin_order_incorrect_count
+= !order_correct
;
1277 } else if (!soon_rect
.Intersects(new_tile
.tile()->content_rect()) &&
1278 !soon_rect
.Intersects(last_tile
.tile()->content_rect())) {
1279 EXPECT_LE(last_priority
.distance_to_visible
,
1280 new_priority
.distance_to_visible
);
1281 } else if (new_priority
.distance_to_visible
> 0.f
) {
1282 EXPECT_EQ(TilePriority::SOON
, new_priority
.priority_bin
);
1285 last_tile
= new_tile
;
1288 EXPECT_GT(eventually_bin_order_correct_count
,
1289 eventually_bin_order_incorrect_count
);
1291 EXPECT_TRUE(have_tiles
[TilePriority::NOW
]);
1292 EXPECT_TRUE(have_tiles
[TilePriority::SOON
]);
1293 EXPECT_TRUE(have_tiles
[TilePriority::EVENTUALLY
]);
1296 TEST_F(TileManagerTilePriorityQueueTest
, SetIsLikelyToRequireADraw
) {
1297 const gfx::Size
layer_bounds(1000, 1000);
1298 host_impl_
.SetViewportSize(layer_bounds
);
1299 SetupDefaultTrees(layer_bounds
);
1301 // Verify that the queue has a required for draw tile at Top.
1302 scoped_ptr
<RasterTilePriorityQueue
> queue(host_impl_
.BuildRasterQueue(
1303 SAME_PRIORITY_FOR_BOTH_TREES
, RasterTilePriorityQueue::Type::ALL
));
1304 EXPECT_FALSE(queue
->IsEmpty());
1305 EXPECT_TRUE(queue
->Top().tile()->required_for_draw());
1307 EXPECT_FALSE(host_impl_
.is_likely_to_require_a_draw());
1308 host_impl_
.tile_manager()->PrepareTiles(host_impl_
.global_tile_state());
1309 EXPECT_TRUE(host_impl_
.is_likely_to_require_a_draw());
1312 TEST_F(TileManagerTilePriorityQueueTest
,
1313 SetIsLikelyToRequireADrawOnZeroMemoryBudget
) {
1314 const gfx::Size
layer_bounds(1000, 1000);
1315 host_impl_
.SetViewportSize(layer_bounds
);
1316 SetupDefaultTrees(layer_bounds
);
1318 // Verify that the queue has a required for draw tile at Top.
1319 scoped_ptr
<RasterTilePriorityQueue
> queue(host_impl_
.BuildRasterQueue(
1320 SAME_PRIORITY_FOR_BOTH_TREES
, RasterTilePriorityQueue::Type::ALL
));
1321 EXPECT_FALSE(queue
->IsEmpty());
1322 EXPECT_TRUE(queue
->Top().tile()->required_for_draw());
1324 ManagedMemoryPolicy policy
= host_impl_
.ActualManagedMemoryPolicy();
1325 policy
.bytes_limit_when_visible
= 0;
1326 host_impl_
.SetMemoryPolicy(policy
);
1328 EXPECT_FALSE(host_impl_
.is_likely_to_require_a_draw());
1329 host_impl_
.tile_manager()->PrepareTiles(host_impl_
.global_tile_state());
1330 EXPECT_FALSE(host_impl_
.is_likely_to_require_a_draw());
1333 TEST_F(TileManagerTilePriorityQueueTest
,
1334 SetIsLikelyToRequireADrawOnLimitedMemoryBudget
) {
1335 const gfx::Size
layer_bounds(1000, 1000);
1336 host_impl_
.SetViewportSize(layer_bounds
);
1337 SetupDefaultTrees(layer_bounds
);
1339 // Verify that the queue has a required for draw tile at Top.
1340 scoped_ptr
<RasterTilePriorityQueue
> queue(host_impl_
.BuildRasterQueue(
1341 SAME_PRIORITY_FOR_BOTH_TREES
, RasterTilePriorityQueue::Type::ALL
));
1342 EXPECT_FALSE(queue
->IsEmpty());
1343 EXPECT_TRUE(queue
->Top().tile()->required_for_draw());
1344 EXPECT_EQ(gfx::Size(256, 256), queue
->Top().tile()->desired_texture_size());
1345 EXPECT_EQ(RGBA_8888
, host_impl_
.resource_provider()->best_texture_format());
1347 ManagedMemoryPolicy policy
= host_impl_
.ActualManagedMemoryPolicy();
1348 policy
.bytes_limit_when_visible
= ResourceUtil::UncheckedSizeInBytes
<size_t>(
1349 gfx::Size(256, 256), RGBA_8888
);
1350 host_impl_
.SetMemoryPolicy(policy
);
1352 EXPECT_FALSE(host_impl_
.is_likely_to_require_a_draw());
1353 host_impl_
.tile_manager()->PrepareTiles(host_impl_
.global_tile_state());
1354 EXPECT_TRUE(host_impl_
.is_likely_to_require_a_draw());
1356 Resource
* resource
= host_impl_
.resource_pool()->AcquireResource(
1357 gfx::Size(256, 256), RGBA_8888
);
1359 host_impl_
.tile_manager()->CheckIfMoreTilesNeedToBePreparedForTesting();
1360 EXPECT_FALSE(host_impl_
.is_likely_to_require_a_draw());
1362 host_impl_
.resource_pool()->ReleaseResource(resource
, 0);
1365 TEST_F(TileManagerTilePriorityQueueTest
, RasterQueueAllUsesCorrectTileBounds
) {
1366 // Verify that we use the real tile bounds when advancing phases during the
1368 gfx::Size
layer_bounds(1, 1);
1370 scoped_refptr
<FakePicturePileImpl
> pile
=
1371 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds
);
1373 FakePictureLayerTilingClient pending_client
;
1374 pending_client
.SetTileSize(gfx::Size(64, 64));
1376 scoped_ptr
<PictureLayerTilingSet
> tiling_set
= PictureLayerTilingSet::Create(
1377 WhichTree::ACTIVE_TREE
, &pending_client
, 1.0f
, 1.0f
, 1000);
1378 pending_client
.set_twin_tiling_set(tiling_set
.get());
1380 auto* tiling
= tiling_set
->AddTiling(1.0f
, pile
);
1382 tiling
->set_resolution(HIGH_RESOLUTION
);
1383 tiling
->CreateAllTilesForTesting();
1385 // The tile is (0, 0, 1, 1), create an intersecting and non-intersecting
1386 // rectangle to test the advance phase with. The tile size is (64, 64), so
1387 // both rectangles intersect the tile content size, but only one should
1388 // intersect the actual size.
1389 gfx::Rect
non_intersecting_rect(2, 2, 10, 10);
1390 gfx::Rect
intersecting_rect(0, 0, 10, 10);
1392 tiling
->SetTilePriorityRectsForTesting(
1393 non_intersecting_rect
, // Visible rect.
1394 intersecting_rect
, // Skewport rect.
1395 intersecting_rect
, // Soon rect.
1396 intersecting_rect
); // Eventually rect.
1397 scoped_ptr
<TilingSetRasterQueueAll
> queue(
1398 new TilingSetRasterQueueAll(tiling_set
.get(), false));
1399 EXPECT_FALSE(queue
->IsEmpty());
1402 tiling
->SetTilePriorityRectsForTesting(
1403 non_intersecting_rect
, // Visible rect.
1404 non_intersecting_rect
, // Skewport rect.
1405 intersecting_rect
, // Soon rect.
1406 intersecting_rect
); // Eventually rect.
1407 scoped_ptr
<TilingSetRasterQueueAll
> queue(
1408 new TilingSetRasterQueueAll(tiling_set
.get(), false));
1409 EXPECT_FALSE(queue
->IsEmpty());
1412 tiling
->SetTilePriorityRectsForTesting(
1413 non_intersecting_rect
, // Visible rect.
1414 non_intersecting_rect
, // Skewport rect.
1415 non_intersecting_rect
, // Soon rect.
1416 intersecting_rect
); // Eventually rect.
1417 scoped_ptr
<TilingSetRasterQueueAll
> queue(
1418 new TilingSetRasterQueueAll(tiling_set
.get(), false));
1419 EXPECT_FALSE(queue
->IsEmpty());
1423 class TileManagerTest
: public testing::Test
{
1426 : host_impl_(&proxy_
, &shared_bitmap_manager_
, &task_graph_runner_
) {}
1429 // MockLayerTreeHostImpl allows us to intercept tile manager callbacks.
1430 class MockLayerTreeHostImpl
: public FakeLayerTreeHostImpl
{
1432 MockLayerTreeHostImpl(Proxy
* proxy
,
1433 SharedBitmapManager
* manager
,
1434 TaskGraphRunner
* task_graph_runner
)
1435 : FakeLayerTreeHostImpl(proxy
, manager
, task_graph_runner
) {
1436 InitializeRenderer(FakeOutputSurface::CreateSoftware(
1437 make_scoped_ptr(new SoftwareOutputDevice
)));
1440 MOCK_METHOD0(NotifyAllTileTasksCompleted
, void());
1443 TestSharedBitmapManager shared_bitmap_manager_
;
1444 TestTaskGraphRunner task_graph_runner_
;
1445 FakeImplProxy proxy_
;
1446 MockLayerTreeHostImpl host_impl_
;
1449 // Test to ensure that we call NotifyAllTileTasksCompleted when PrepareTiles is
1451 TEST_F(TileManagerTest
, AllWorkFinishedTest
) {
1452 // Check with no tile work enqueued.
1454 base::RunLoop run_loop
;
1455 EXPECT_FALSE(host_impl_
.tile_manager()->HasScheduledTileTasksForTesting());
1456 EXPECT_CALL(host_impl_
, NotifyAllTileTasksCompleted())
1457 .WillOnce(testing::Invoke([&run_loop
]() { run_loop
.Quit(); }));
1458 host_impl_
.tile_manager()->PrepareTiles(host_impl_
.global_tile_state());
1459 EXPECT_TRUE(host_impl_
.tile_manager()->HasScheduledTileTasksForTesting());
1463 // Check that the "schedule more work" path also triggers the expected
1466 base::RunLoop run_loop
;
1467 EXPECT_FALSE(host_impl_
.tile_manager()->HasScheduledTileTasksForTesting());
1468 EXPECT_CALL(host_impl_
, NotifyAllTileTasksCompleted())
1469 .WillOnce(testing::Invoke([&run_loop
]() { run_loop
.Quit(); }));
1470 host_impl_
.tile_manager()->PrepareTiles(host_impl_
.global_tile_state());
1471 host_impl_
.tile_manager()->SetMoreTilesNeedToBeRasterizedForTesting();
1472 EXPECT_TRUE(host_impl_
.tile_manager()->HasScheduledTileTasksForTesting());
1477 TEST_F(TileManagerTest
, LowResHasNoImage
) {
1478 gfx::Size
size(10, 12);
1479 TileResolution resolutions
[] = {HIGH_RESOLUTION
, LOW_RESOLUTION
};
1481 for (size_t i
= 0; i
< arraysize(resolutions
); ++i
) {
1482 SCOPED_TRACE(resolutions
[i
]);
1484 // Make a RasterSource that will draw a blue bitmap image.
1485 skia::RefPtr
<SkSurface
> surface
= skia::AdoptRef(
1486 SkSurface::NewRasterN32Premul(size
.width(), size
.height()));
1487 ASSERT_NE(surface
, nullptr);
1488 surface
->getCanvas()->clear(SK_ColorBLUE
);
1489 skia::RefPtr
<SkImage
> blue_image
=
1490 skia::AdoptRef(surface
->newImageSnapshot());
1492 scoped_ptr
<FakeDisplayListRecordingSource
> recording_source
=
1493 FakeDisplayListRecordingSource::CreateFilledRecordingSource(size
);
1494 recording_source
->SetBackgroundColor(SK_ColorTRANSPARENT
);
1495 recording_source
->SetRequiresClear(true);
1496 recording_source
->SetClearCanvasWithDebugColor(false);
1498 paint
.setColor(SK_ColorGREEN
);
1499 recording_source
->add_draw_rect_with_paint(gfx::Rect(size
), paint
);
1500 recording_source
->add_draw_image(blue_image
.get(), gfx::Point());
1501 recording_source
->Rerecord();
1502 scoped_refptr
<DisplayListRasterSource
> raster
=
1503 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
1504 recording_source
.get(), false);
1506 FakePictureLayerTilingClient tiling_client
;
1507 tiling_client
.SetTileSize(size
);
1509 scoped_ptr
<PictureLayerImpl
> layer
=
1510 PictureLayerImpl::Create(host_impl_
.active_tree(), 1, false, nullptr);
1511 PictureLayerTilingSet
* tiling_set
= layer
->picture_layer_tiling_set();
1513 auto* tiling
= tiling_set
->AddTiling(1.0f
, raster
);
1514 tiling
->set_resolution(resolutions
[i
]);
1515 tiling
->CreateAllTilesForTesting();
1516 tiling
->SetTilePriorityRectsForTesting(
1517 gfx::Rect(size
), // Visible rect.
1518 gfx::Rect(size
), // Skewport rect.
1519 gfx::Rect(size
), // Soon rect.
1520 gfx::Rect(size
)); // Eventually rect.
1522 // SMOOTHNESS_TAKES_PRIORITY ensures that we will actually raster
1523 // LOW_RESOLUTION tiles, otherwise they are skipped.
1524 host_impl_
.SetTreePriority(SMOOTHNESS_TAKES_PRIORITY
);
1526 // Call PrepareTiles and wait for it to complete.
1527 auto* tile_manager
= host_impl_
.tile_manager();
1528 base::RunLoop run_loop
;
1529 EXPECT_CALL(host_impl_
, NotifyAllTileTasksCompleted())
1530 .WillOnce(testing::Invoke([&run_loop
]() { run_loop
.Quit(); }));
1531 tile_manager
->PrepareTiles(host_impl_
.global_tile_state());
1533 tile_manager
->Flush();
1535 Tile
* tile
= tiling
->TileAt(0, 0);
1536 // The tile in the tiling was rastered.
1537 EXPECT_EQ(TileDrawInfo::RESOURCE_MODE
, tile
->draw_info().mode());
1538 EXPECT_TRUE(tile
->draw_info().IsReadyToDraw());
1540 ResourceProvider::ScopedReadLockSoftware
lock(
1541 host_impl_
.resource_provider(), tile
->draw_info().resource_id());
1542 const SkBitmap
* bitmap
= lock
.sk_bitmap();
1543 for (int x
= 0; x
< size
.width(); ++x
) {
1544 for (int y
= 0; y
< size
.height(); ++y
) {
1547 if (resolutions
[i
] == LOW_RESOLUTION
) {
1548 // Since it's low res, the bitmap was not drawn, and the background
1549 // (green) is visible instead.
1550 ASSERT_EQ(SK_ColorGREEN
, bitmap
->getColor(x
, y
));
1552 EXPECT_EQ(HIGH_RESOLUTION
, resolutions
[i
]);
1553 // Since it's high res, the bitmap (blue) was drawn, and the
1554 // background is not visible.
1555 ASSERT_EQ(SK_ColorBLUE
, bitmap
->getColor(x
, y
));