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 <algorithm> | |
6 #include <vector> | |
7 | |
8 #include "cc/resources/managed_tile_state.h" | |
9 #include "cc/resources/prioritized_tile_set.h" | |
10 #include "cc/resources/tile.h" | |
11 #include "cc/test/fake_output_surface.h" | |
12 #include "cc/test/fake_output_surface_client.h" | |
13 #include "cc/test/fake_picture_pile_impl.h" | |
14 #include "cc/test/fake_tile_manager.h" | |
15 #include "cc/test/fake_tile_manager_client.h" | |
16 #include "cc/test/test_shared_bitmap_manager.h" | |
17 #include "cc/test/test_tile_priorities.h" | |
18 #include "testing/gtest/include/gtest/gtest.h" | |
19 | |
20 namespace cc { | |
21 | |
22 class BinComparator { | |
23 public: | |
24 bool operator()(const scoped_refptr<Tile>& a, | |
25 const scoped_refptr<Tile>& b) const { | |
26 const ManagedTileState& ams = a->managed_state(); | |
27 const ManagedTileState& bms = b->managed_state(); | |
28 | |
29 if (ams.priority_bin != bms.priority_bin) | |
30 return ams.priority_bin < bms.priority_bin; | |
31 | |
32 if (ams.required_for_activation != bms.required_for_activation) | |
33 return ams.required_for_activation; | |
34 | |
35 if (ams.resolution != bms.resolution) | |
36 return ams.resolution < bms.resolution; | |
37 | |
38 if (ams.distance_to_visible != bms.distance_to_visible) | |
39 return ams.distance_to_visible < bms.distance_to_visible; | |
40 | |
41 gfx::Rect a_rect = a->content_rect(); | |
42 gfx::Rect b_rect = b->content_rect(); | |
43 if (a_rect.y() != b_rect.y()) | |
44 return a_rect.y() < b_rect.y(); | |
45 return a_rect.x() < b_rect.x(); | |
46 } | |
47 }; | |
48 | |
49 namespace { | |
50 | |
51 class PrioritizedTileSetTest : public testing::Test { | |
52 public: | |
53 PrioritizedTileSetTest() { | |
54 output_surface_ = FakeOutputSurface::Create3d().Pass(); | |
55 CHECK(output_surface_->BindToClient(&output_surface_client_)); | |
56 | |
57 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); | |
58 resource_provider_ = | |
59 ResourceProvider::Create( | |
60 output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1, | |
61 false) | |
62 .Pass(); | |
63 resource_pool_ = ResourcePool::Create( | |
64 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); | |
65 tile_manager_.reset( | |
66 new FakeTileManager(&tile_manager_client_, resource_pool_.get())); | |
67 picture_pile_ = FakePicturePileImpl::CreateInfiniteFilledPile(); | |
68 } | |
69 | |
70 scoped_refptr<Tile> CreateTile() { | |
71 return tile_manager_->CreateTile(picture_pile_.get(), | |
72 settings_.default_tile_size, | |
73 gfx::Rect(), | |
74 gfx::Rect(), | |
75 1.0, | |
76 0, | |
77 0, | |
78 0); | |
79 } | |
80 | |
81 private: | |
82 LayerTreeSettings settings_; | |
83 FakeOutputSurfaceClient output_surface_client_; | |
84 scoped_ptr<FakeOutputSurface> output_surface_; | |
85 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | |
86 scoped_ptr<ResourceProvider> resource_provider_; | |
87 scoped_ptr<ResourcePool> resource_pool_; | |
88 FakeTileManagerClient tile_manager_client_; | |
89 scoped_ptr<FakeTileManager> tile_manager_; | |
90 scoped_refptr<FakePicturePileImpl> picture_pile_; | |
91 }; | |
92 | |
93 TEST_F(PrioritizedTileSetTest, EmptyIterator) { | |
94 // Creating an iterator to an empty set should work (but create iterator that | |
95 // isn't valid). | |
96 | |
97 PrioritizedTileSet set; | |
98 | |
99 PrioritizedTileSet::Iterator it(&set, true); | |
100 EXPECT_FALSE(it); | |
101 } | |
102 | |
103 TEST_F(PrioritizedTileSetTest, NonEmptyIterator) { | |
104 PrioritizedTileSet set; | |
105 scoped_refptr<Tile> tile = CreateTile(); | |
106 set.InsertTile(tile, NOW_BIN); | |
107 | |
108 PrioritizedTileSet::Iterator it(&set, true); | |
109 EXPECT_TRUE(it); | |
110 EXPECT_TRUE(*it == tile.get()); | |
111 ++it; | |
112 EXPECT_FALSE(it); | |
113 } | |
114 | |
115 TEST_F(PrioritizedTileSetTest, NowAndReadyToDrawBin) { | |
116 // Ensure that tiles in NOW_AND_READY_TO_DRAW_BIN aren't sorted. | |
117 | |
118 PrioritizedTileSet set; | |
119 TilePriority priorities[4] = { | |
120 TilePriorityForEventualBin(), | |
121 TilePriorityForNowBin(), | |
122 TilePriority(), | |
123 TilePriorityForSoonBin()}; | |
124 | |
125 std::vector<scoped_refptr<Tile> > tiles; | |
126 for (int priority = 0; priority < 4; ++priority) { | |
127 for (int i = 0; i < 5; ++i) { | |
128 scoped_refptr<Tile> tile = CreateTile(); | |
129 tile->SetPriority(ACTIVE_TREE, priorities[priority]); | |
130 tile->SetPriority(PENDING_TREE, priorities[priority]); | |
131 tiles.push_back(tile); | |
132 set.InsertTile(tile, NOW_AND_READY_TO_DRAW_BIN); | |
133 } | |
134 } | |
135 | |
136 // Tiles should appear in the same order as inserted. | |
137 int i = 0; | |
138 for (PrioritizedTileSet::Iterator it(&set, true); | |
139 it; | |
140 ++it) { | |
141 EXPECT_TRUE(*it == tiles[i].get()); | |
142 ++i; | |
143 } | |
144 EXPECT_EQ(20, i); | |
145 } | |
146 | |
147 TEST_F(PrioritizedTileSetTest, NowBin) { | |
148 // Ensure that tiles in NOW_BIN are sorted according to BinComparator. | |
149 | |
150 PrioritizedTileSet set; | |
151 TilePriority priorities[4] = { | |
152 TilePriorityForEventualBin(), | |
153 TilePriorityForNowBin(), | |
154 TilePriority(), | |
155 TilePriorityForSoonBin()}; | |
156 | |
157 std::vector<scoped_refptr<Tile> > tiles; | |
158 for (int priority = 0; priority < 4; ++priority) { | |
159 for (int i = 0; i < 5; ++i) { | |
160 scoped_refptr<Tile> tile = CreateTile(); | |
161 tile->SetPriority(ACTIVE_TREE, priorities[priority]); | |
162 tile->SetPriority(PENDING_TREE, priorities[priority]); | |
163 tiles.push_back(tile); | |
164 set.InsertTile(tile, NOW_BIN); | |
165 } | |
166 } | |
167 | |
168 // Tiles should appear in BinComparator order. | |
169 std::sort(tiles.begin(), tiles.end(), BinComparator()); | |
170 | |
171 int i = 0; | |
172 for (PrioritizedTileSet::Iterator it(&set, true); | |
173 it; | |
174 ++it) { | |
175 EXPECT_TRUE(*it == tiles[i].get()); | |
176 ++i; | |
177 } | |
178 EXPECT_EQ(20, i); | |
179 } | |
180 | |
181 TEST_F(PrioritizedTileSetTest, SoonBin) { | |
182 // Ensure that tiles in SOON_BIN are sorted according to BinComparator. | |
183 | |
184 PrioritizedTileSet set; | |
185 TilePriority priorities[4] = { | |
186 TilePriorityForEventualBin(), | |
187 TilePriorityForNowBin(), | |
188 TilePriority(), | |
189 TilePriorityForSoonBin()}; | |
190 | |
191 std::vector<scoped_refptr<Tile> > tiles; | |
192 for (int priority = 0; priority < 4; ++priority) { | |
193 for (int i = 0; i < 5; ++i) { | |
194 scoped_refptr<Tile> tile = CreateTile(); | |
195 tile->SetPriority(ACTIVE_TREE, priorities[priority]); | |
196 tile->SetPriority(PENDING_TREE, priorities[priority]); | |
197 tiles.push_back(tile); | |
198 set.InsertTile(tile, SOON_BIN); | |
199 } | |
200 } | |
201 | |
202 // Tiles should appear in BinComparator order. | |
203 std::sort(tiles.begin(), tiles.end(), BinComparator()); | |
204 | |
205 int i = 0; | |
206 for (PrioritizedTileSet::Iterator it(&set, true); | |
207 it; | |
208 ++it) { | |
209 EXPECT_TRUE(*it == tiles[i].get()); | |
210 ++i; | |
211 } | |
212 EXPECT_EQ(20, i); | |
213 } | |
214 | |
215 TEST_F(PrioritizedTileSetTest, SoonBinNoPriority) { | |
216 // Ensure that when not using priority iterator, SOON_BIN tiles | |
217 // are not sorted. | |
218 | |
219 PrioritizedTileSet set; | |
220 TilePriority priorities[4] = { | |
221 TilePriorityForEventualBin(), | |
222 TilePriorityForNowBin(), | |
223 TilePriority(), | |
224 TilePriorityForSoonBin()}; | |
225 | |
226 std::vector<scoped_refptr<Tile> > tiles; | |
227 for (int priority = 0; priority < 4; ++priority) { | |
228 for (int i = 0; i < 5; ++i) { | |
229 scoped_refptr<Tile> tile = CreateTile(); | |
230 tile->SetPriority(ACTIVE_TREE, priorities[priority]); | |
231 tile->SetPriority(PENDING_TREE, priorities[priority]); | |
232 tiles.push_back(tile); | |
233 set.InsertTile(tile, SOON_BIN); | |
234 } | |
235 } | |
236 | |
237 int i = 0; | |
238 for (PrioritizedTileSet::Iterator it(&set, false); | |
239 it; | |
240 ++it) { | |
241 EXPECT_TRUE(*it == tiles[i].get()); | |
242 ++i; | |
243 } | |
244 EXPECT_EQ(20, i); | |
245 } | |
246 | |
247 TEST_F(PrioritizedTileSetTest, EventuallyAndActiveBin) { | |
248 // Ensure that EVENTUALLY_AND_ACTIVE_BIN tiles are sorted. | |
249 | |
250 PrioritizedTileSet set; | |
251 TilePriority priorities[4] = { | |
252 TilePriorityForEventualBin(), | |
253 TilePriorityForNowBin(), | |
254 TilePriority(), | |
255 TilePriorityForSoonBin()}; | |
256 | |
257 std::vector<scoped_refptr<Tile> > tiles; | |
258 for (int priority = 0; priority < 4; ++priority) { | |
259 for (int i = 0; i < 5; ++i) { | |
260 scoped_refptr<Tile> tile = CreateTile(); | |
261 tile->SetPriority(ACTIVE_TREE, priorities[priority]); | |
262 tile->SetPriority(PENDING_TREE, priorities[priority]); | |
263 tiles.push_back(tile); | |
264 set.InsertTile(tile, EVENTUALLY_AND_ACTIVE_BIN); | |
265 } | |
266 } | |
267 | |
268 // Tiles should appear in BinComparator order. | |
269 std::sort(tiles.begin(), tiles.end(), BinComparator()); | |
270 | |
271 int i = 0; | |
272 for (PrioritizedTileSet::Iterator it(&set, true); | |
273 it; | |
274 ++it) { | |
275 EXPECT_TRUE(*it == tiles[i].get()); | |
276 ++i; | |
277 } | |
278 EXPECT_EQ(20, i); | |
279 } | |
280 | |
281 TEST_F(PrioritizedTileSetTest, EventuallyBin) { | |
282 // Ensure that EVENTUALLY_BIN tiles are sorted. | |
283 | |
284 PrioritizedTileSet set; | |
285 TilePriority priorities[4] = { | |
286 TilePriorityForEventualBin(), | |
287 TilePriorityForNowBin(), | |
288 TilePriority(), | |
289 TilePriorityForSoonBin()}; | |
290 | |
291 std::vector<scoped_refptr<Tile> > tiles; | |
292 for (int priority = 0; priority < 4; ++priority) { | |
293 for (int i = 0; i < 5; ++i) { | |
294 scoped_refptr<Tile> tile = CreateTile(); | |
295 tile->SetPriority(ACTIVE_TREE, priorities[priority]); | |
296 tile->SetPriority(PENDING_TREE, priorities[priority]); | |
297 tiles.push_back(tile); | |
298 set.InsertTile(tile, EVENTUALLY_BIN); | |
299 } | |
300 } | |
301 | |
302 // Tiles should appear in BinComparator order. | |
303 std::sort(tiles.begin(), tiles.end(), BinComparator()); | |
304 | |
305 int i = 0; | |
306 for (PrioritizedTileSet::Iterator it(&set, true); | |
307 it; | |
308 ++it) { | |
309 EXPECT_TRUE(*it == tiles[i].get()); | |
310 ++i; | |
311 } | |
312 EXPECT_EQ(20, i); | |
313 } | |
314 | |
315 TEST_F(PrioritizedTileSetTest, AtLastAndActiveBin) { | |
316 // Ensure that AT_LAST_AND_ACTIVE_BIN tiles are sorted. | |
317 | |
318 PrioritizedTileSet set; | |
319 TilePriority priorities[4] = { | |
320 TilePriorityForEventualBin(), | |
321 TilePriorityForNowBin(), | |
322 TilePriority(), | |
323 TilePriorityForSoonBin()}; | |
324 | |
325 std::vector<scoped_refptr<Tile> > tiles; | |
326 for (int priority = 0; priority < 4; ++priority) { | |
327 for (int i = 0; i < 5; ++i) { | |
328 scoped_refptr<Tile> tile = CreateTile(); | |
329 tile->SetPriority(ACTIVE_TREE, priorities[priority]); | |
330 tile->SetPriority(PENDING_TREE, priorities[priority]); | |
331 tiles.push_back(tile); | |
332 set.InsertTile(tile, AT_LAST_AND_ACTIVE_BIN); | |
333 } | |
334 } | |
335 | |
336 // Tiles should appear in BinComparator order. | |
337 std::sort(tiles.begin(), tiles.end(), BinComparator()); | |
338 | |
339 int i = 0; | |
340 for (PrioritizedTileSet::Iterator it(&set, true); | |
341 it; | |
342 ++it) { | |
343 EXPECT_TRUE(*it == tiles[i].get()); | |
344 ++i; | |
345 } | |
346 EXPECT_EQ(20, i); | |
347 } | |
348 | |
349 TEST_F(PrioritizedTileSetTest, AtLastBin) { | |
350 // Ensure that AT_LAST_BIN tiles are sorted. | |
351 | |
352 PrioritizedTileSet set; | |
353 TilePriority priorities[4] = { | |
354 TilePriorityForEventualBin(), | |
355 TilePriorityForNowBin(), | |
356 TilePriority(), | |
357 TilePriorityForSoonBin()}; | |
358 | |
359 std::vector<scoped_refptr<Tile> > tiles; | |
360 for (int priority = 0; priority < 4; ++priority) { | |
361 for (int i = 0; i < 5; ++i) { | |
362 scoped_refptr<Tile> tile = CreateTile(); | |
363 tile->SetPriority(ACTIVE_TREE, priorities[priority]); | |
364 tile->SetPriority(PENDING_TREE, priorities[priority]); | |
365 tiles.push_back(tile); | |
366 set.InsertTile(tile, AT_LAST_BIN); | |
367 } | |
368 } | |
369 | |
370 // Tiles should appear in BinComparator order. | |
371 std::sort(tiles.begin(), tiles.end(), BinComparator()); | |
372 | |
373 int i = 0; | |
374 for (PrioritizedTileSet::Iterator it(&set, true); | |
375 it; | |
376 ++it) { | |
377 EXPECT_TRUE(*it == tiles[i].get()); | |
378 ++i; | |
379 } | |
380 EXPECT_EQ(20, i); | |
381 } | |
382 | |
383 TEST_F(PrioritizedTileSetTest, TilesForEachBin) { | |
384 // Aggregate test with one tile for each of the bins, which | |
385 // should appear in order of the bins. | |
386 | |
387 scoped_refptr<Tile> now_and_ready_to_draw_bin = CreateTile(); | |
388 scoped_refptr<Tile> now_bin = CreateTile(); | |
389 scoped_refptr<Tile> soon_bin = CreateTile(); | |
390 scoped_refptr<Tile> eventually_and_active_bin = CreateTile(); | |
391 scoped_refptr<Tile> eventually_bin = CreateTile(); | |
392 scoped_refptr<Tile> at_last_bin = CreateTile(); | |
393 scoped_refptr<Tile> at_last_and_active_bin = CreateTile(); | |
394 | |
395 PrioritizedTileSet set; | |
396 set.InsertTile(soon_bin, SOON_BIN); | |
397 set.InsertTile(at_last_and_active_bin, AT_LAST_AND_ACTIVE_BIN); | |
398 set.InsertTile(eventually_bin, EVENTUALLY_BIN); | |
399 set.InsertTile(now_bin, NOW_BIN); | |
400 set.InsertTile(eventually_and_active_bin, EVENTUALLY_AND_ACTIVE_BIN); | |
401 set.InsertTile(at_last_bin, AT_LAST_BIN); | |
402 set.InsertTile(now_and_ready_to_draw_bin, NOW_AND_READY_TO_DRAW_BIN); | |
403 | |
404 // Tiles should appear in order. | |
405 PrioritizedTileSet::Iterator it(&set, true); | |
406 EXPECT_TRUE(*it == now_and_ready_to_draw_bin.get()); | |
407 ++it; | |
408 EXPECT_TRUE(*it == now_bin.get()); | |
409 ++it; | |
410 EXPECT_TRUE(*it == soon_bin.get()); | |
411 ++it; | |
412 EXPECT_TRUE(*it == eventually_and_active_bin.get()); | |
413 ++it; | |
414 EXPECT_TRUE(*it == eventually_bin.get()); | |
415 ++it; | |
416 EXPECT_TRUE(*it == at_last_and_active_bin.get()); | |
417 ++it; | |
418 EXPECT_TRUE(*it == at_last_bin.get()); | |
419 ++it; | |
420 EXPECT_FALSE(it); | |
421 } | |
422 | |
423 TEST_F(PrioritizedTileSetTest, ManyTilesForEachBin) { | |
424 // Aggregate test with many tiles in each of the bins of various | |
425 // priorities. Ensure that they are all returned in a sorted order. | |
426 | |
427 std::vector<scoped_refptr<Tile> > now_and_ready_to_draw_bins; | |
428 std::vector<scoped_refptr<Tile> > now_bins; | |
429 std::vector<scoped_refptr<Tile> > soon_bins; | |
430 std::vector<scoped_refptr<Tile> > eventually_and_active_bins; | |
431 std::vector<scoped_refptr<Tile> > eventually_bins; | |
432 std::vector<scoped_refptr<Tile> > at_last_bins; | |
433 std::vector<scoped_refptr<Tile> > at_last_and_active_bins; | |
434 | |
435 TilePriority priorities[4] = { | |
436 TilePriorityForEventualBin(), | |
437 TilePriorityForNowBin(), | |
438 TilePriority(), | |
439 TilePriorityForSoonBin()}; | |
440 | |
441 PrioritizedTileSet set; | |
442 for (int priority = 0; priority < 4; ++priority) { | |
443 for (int i = 0; i < 5; ++i) { | |
444 scoped_refptr<Tile> tile = CreateTile(); | |
445 tile->SetPriority(ACTIVE_TREE, priorities[priority]); | |
446 tile->SetPriority(PENDING_TREE, priorities[priority]); | |
447 | |
448 now_and_ready_to_draw_bins.push_back(tile); | |
449 now_bins.push_back(tile); | |
450 soon_bins.push_back(tile); | |
451 eventually_and_active_bins.push_back(tile); | |
452 eventually_bins.push_back(tile); | |
453 at_last_bins.push_back(tile); | |
454 at_last_and_active_bins.push_back(tile); | |
455 | |
456 set.InsertTile(tile, NOW_AND_READY_TO_DRAW_BIN); | |
457 set.InsertTile(tile, NOW_BIN); | |
458 set.InsertTile(tile, SOON_BIN); | |
459 set.InsertTile(tile, EVENTUALLY_AND_ACTIVE_BIN); | |
460 set.InsertTile(tile, EVENTUALLY_BIN); | |
461 set.InsertTile(tile, AT_LAST_BIN); | |
462 set.InsertTile(tile, AT_LAST_AND_ACTIVE_BIN); | |
463 } | |
464 } | |
465 | |
466 PrioritizedTileSet::Iterator it(&set, true); | |
467 std::vector<scoped_refptr<Tile> >::iterator vector_it; | |
468 | |
469 // Now and ready are not sorted. | |
470 for (vector_it = now_and_ready_to_draw_bins.begin(); | |
471 vector_it != now_and_ready_to_draw_bins.end(); | |
472 ++vector_it) { | |
473 EXPECT_TRUE(*vector_it == *it); | |
474 ++it; | |
475 } | |
476 | |
477 // Now bins are sorted. | |
478 std::sort(now_bins.begin(), now_bins.end(), BinComparator()); | |
479 for (vector_it = now_bins.begin(); vector_it != now_bins.end(); ++vector_it) { | |
480 EXPECT_TRUE(*vector_it == *it); | |
481 ++it; | |
482 } | |
483 | |
484 // Soon bins are sorted. | |
485 std::sort(soon_bins.begin(), soon_bins.end(), BinComparator()); | |
486 for (vector_it = soon_bins.begin(); vector_it != soon_bins.end(); | |
487 ++vector_it) { | |
488 EXPECT_TRUE(*vector_it == *it); | |
489 ++it; | |
490 } | |
491 | |
492 // Eventually and active bins are sorted. | |
493 std::sort(eventually_and_active_bins.begin(), | |
494 eventually_and_active_bins.end(), | |
495 BinComparator()); | |
496 for (vector_it = eventually_and_active_bins.begin(); | |
497 vector_it != eventually_and_active_bins.end(); | |
498 ++vector_it) { | |
499 EXPECT_TRUE(*vector_it == *it); | |
500 ++it; | |
501 } | |
502 | |
503 // Eventually bins are sorted. | |
504 std::sort(eventually_bins.begin(), eventually_bins.end(), BinComparator()); | |
505 for (vector_it = eventually_bins.begin(); vector_it != eventually_bins.end(); | |
506 ++vector_it) { | |
507 EXPECT_TRUE(*vector_it == *it); | |
508 ++it; | |
509 } | |
510 | |
511 // At last and active bins are sorted. | |
512 std::sort(at_last_and_active_bins.begin(), | |
513 at_last_and_active_bins.end(), | |
514 BinComparator()); | |
515 for (vector_it = at_last_and_active_bins.begin(); | |
516 vector_it != at_last_and_active_bins.end(); | |
517 ++vector_it) { | |
518 EXPECT_TRUE(*vector_it == *it); | |
519 ++it; | |
520 } | |
521 | |
522 // At last bins are sorted. | |
523 std::sort(at_last_bins.begin(), at_last_bins.end(), BinComparator()); | |
524 for (vector_it = at_last_bins.begin(); vector_it != at_last_bins.end(); | |
525 ++vector_it) { | |
526 EXPECT_TRUE(*vector_it == *it); | |
527 ++it; | |
528 } | |
529 | |
530 EXPECT_FALSE(it); | |
531 } | |
532 | |
533 TEST_F(PrioritizedTileSetTest, ManyTilesForEachBinDisablePriority) { | |
534 // Aggregate test with many tiles for each of the bins. Tiles should | |
535 // appear in order, until DisablePriorityOrdering is called. After that | |
536 // tiles should appear in the order they were inserted. | |
537 | |
538 std::vector<scoped_refptr<Tile> > now_and_ready_to_draw_bins; | |
539 std::vector<scoped_refptr<Tile> > now_bins; | |
540 std::vector<scoped_refptr<Tile> > soon_bins; | |
541 std::vector<scoped_refptr<Tile> > eventually_and_active_bins; | |
542 std::vector<scoped_refptr<Tile> > eventually_bins; | |
543 std::vector<scoped_refptr<Tile> > at_last_bins; | |
544 std::vector<scoped_refptr<Tile> > at_last_and_active_bins; | |
545 | |
546 TilePriority priorities[4] = { | |
547 TilePriorityForEventualBin(), | |
548 TilePriorityForNowBin(), | |
549 TilePriority(), | |
550 TilePriorityForSoonBin()}; | |
551 | |
552 PrioritizedTileSet set; | |
553 for (int priority = 0; priority < 4; ++priority) { | |
554 for (int i = 0; i < 5; ++i) { | |
555 scoped_refptr<Tile> tile = CreateTile(); | |
556 tile->SetPriority(ACTIVE_TREE, priorities[priority]); | |
557 tile->SetPriority(PENDING_TREE, priorities[priority]); | |
558 | |
559 now_and_ready_to_draw_bins.push_back(tile); | |
560 now_bins.push_back(tile); | |
561 soon_bins.push_back(tile); | |
562 eventually_and_active_bins.push_back(tile); | |
563 eventually_bins.push_back(tile); | |
564 at_last_bins.push_back(tile); | |
565 at_last_and_active_bins.push_back(tile); | |
566 | |
567 set.InsertTile(tile, NOW_AND_READY_TO_DRAW_BIN); | |
568 set.InsertTile(tile, NOW_BIN); | |
569 set.InsertTile(tile, SOON_BIN); | |
570 set.InsertTile(tile, EVENTUALLY_AND_ACTIVE_BIN); | |
571 set.InsertTile(tile, EVENTUALLY_BIN); | |
572 set.InsertTile(tile, AT_LAST_BIN); | |
573 set.InsertTile(tile, AT_LAST_AND_ACTIVE_BIN); | |
574 } | |
575 } | |
576 | |
577 PrioritizedTileSet::Iterator it(&set, true); | |
578 std::vector<scoped_refptr<Tile> >::iterator vector_it; | |
579 | |
580 // Now and ready are not sorted. | |
581 for (vector_it = now_and_ready_to_draw_bins.begin(); | |
582 vector_it != now_and_ready_to_draw_bins.end(); | |
583 ++vector_it) { | |
584 EXPECT_TRUE(*vector_it == *it); | |
585 ++it; | |
586 } | |
587 | |
588 // Now bins are sorted. | |
589 std::sort(now_bins.begin(), now_bins.end(), BinComparator()); | |
590 for (vector_it = now_bins.begin(); vector_it != now_bins.end(); ++vector_it) { | |
591 EXPECT_TRUE(*vector_it == *it); | |
592 ++it; | |
593 } | |
594 | |
595 // Soon bins are sorted. | |
596 std::sort(soon_bins.begin(), soon_bins.end(), BinComparator()); | |
597 for (vector_it = soon_bins.begin(); vector_it != soon_bins.end(); | |
598 ++vector_it) { | |
599 EXPECT_TRUE(*vector_it == *it); | |
600 ++it; | |
601 } | |
602 | |
603 // After we disable priority ordering, we already have sorted the next vector. | |
604 it.DisablePriorityOrdering(); | |
605 | |
606 // Eventually and active bins are sorted. | |
607 std::sort(eventually_and_active_bins.begin(), | |
608 eventually_and_active_bins.end(), | |
609 BinComparator()); | |
610 for (vector_it = eventually_and_active_bins.begin(); | |
611 vector_it != eventually_and_active_bins.end(); | |
612 ++vector_it) { | |
613 EXPECT_TRUE(*vector_it == *it); | |
614 ++it; | |
615 } | |
616 | |
617 // Eventually bins are not sorted. | |
618 for (vector_it = eventually_bins.begin(); vector_it != eventually_bins.end(); | |
619 ++vector_it) { | |
620 EXPECT_TRUE(*vector_it == *it); | |
621 ++it; | |
622 } | |
623 | |
624 // At last and active bins are not sorted. | |
625 for (vector_it = at_last_and_active_bins.begin(); | |
626 vector_it != at_last_and_active_bins.end(); | |
627 ++vector_it) { | |
628 EXPECT_TRUE(*vector_it == *it); | |
629 ++it; | |
630 } | |
631 | |
632 // At last bins are not sorted. | |
633 for (vector_it = at_last_bins.begin(); vector_it != at_last_bins.end(); | |
634 ++vector_it) { | |
635 EXPECT_TRUE(*vector_it == *it); | |
636 ++it; | |
637 } | |
638 | |
639 EXPECT_FALSE(it); | |
640 } | |
641 | |
642 TEST_F(PrioritizedTileSetTest, TilesForFirstAndLastBins) { | |
643 // Make sure that if we have empty lists between two non-empty lists, | |
644 // we just get two tiles from the iterator. | |
645 | |
646 scoped_refptr<Tile> now_and_ready_to_draw_bin = CreateTile(); | |
647 scoped_refptr<Tile> at_last_bin = CreateTile(); | |
648 | |
649 PrioritizedTileSet set; | |
650 set.InsertTile(at_last_bin, AT_LAST_BIN); | |
651 set.InsertTile(now_and_ready_to_draw_bin, NOW_AND_READY_TO_DRAW_BIN); | |
652 | |
653 // Only two tiles should appear and they should appear in order. | |
654 PrioritizedTileSet::Iterator it(&set, true); | |
655 EXPECT_TRUE(*it == now_and_ready_to_draw_bin.get()); | |
656 ++it; | |
657 EXPECT_TRUE(*it == at_last_bin.get()); | |
658 ++it; | |
659 EXPECT_FALSE(it); | |
660 } | |
661 | |
662 TEST_F(PrioritizedTileSetTest, MultipleIterators) { | |
663 // Ensure that multiple iterators don't interfere with each other. | |
664 | |
665 scoped_refptr<Tile> now_and_ready_to_draw_bin = CreateTile(); | |
666 scoped_refptr<Tile> now_bin = CreateTile(); | |
667 scoped_refptr<Tile> soon_bin = CreateTile(); | |
668 scoped_refptr<Tile> eventually_bin = CreateTile(); | |
669 scoped_refptr<Tile> at_last_bin = CreateTile(); | |
670 | |
671 PrioritizedTileSet set; | |
672 set.InsertTile(soon_bin, SOON_BIN); | |
673 set.InsertTile(eventually_bin, EVENTUALLY_BIN); | |
674 set.InsertTile(now_bin, NOW_BIN); | |
675 set.InsertTile(at_last_bin, AT_LAST_BIN); | |
676 set.InsertTile(now_and_ready_to_draw_bin, NOW_AND_READY_TO_DRAW_BIN); | |
677 | |
678 // Tiles should appear in order. | |
679 PrioritizedTileSet::Iterator it(&set, true); | |
680 EXPECT_TRUE(*it == now_and_ready_to_draw_bin.get()); | |
681 ++it; | |
682 EXPECT_TRUE(*it == now_bin.get()); | |
683 ++it; | |
684 EXPECT_TRUE(*it == soon_bin.get()); | |
685 ++it; | |
686 EXPECT_TRUE(*it == eventually_bin.get()); | |
687 ++it; | |
688 EXPECT_TRUE(*it == at_last_bin.get()); | |
689 ++it; | |
690 EXPECT_FALSE(it); | |
691 | |
692 // Creating multiple iterators shouldn't affect old iterators. | |
693 PrioritizedTileSet::Iterator second_it(&set, true); | |
694 EXPECT_TRUE(second_it); | |
695 EXPECT_FALSE(it); | |
696 | |
697 ++second_it; | |
698 EXPECT_TRUE(second_it); | |
699 ++second_it; | |
700 EXPECT_TRUE(second_it); | |
701 EXPECT_FALSE(it); | |
702 | |
703 PrioritizedTileSet::Iterator third_it(&set, true); | |
704 EXPECT_TRUE(third_it); | |
705 ++second_it; | |
706 ++second_it; | |
707 EXPECT_TRUE(second_it); | |
708 EXPECT_TRUE(third_it); | |
709 EXPECT_FALSE(it); | |
710 | |
711 ++third_it; | |
712 ++third_it; | |
713 EXPECT_TRUE(third_it); | |
714 EXPECT_TRUE(*third_it == soon_bin.get()); | |
715 EXPECT_TRUE(second_it); | |
716 EXPECT_TRUE(*second_it == at_last_bin.get()); | |
717 EXPECT_FALSE(it); | |
718 | |
719 ++second_it; | |
720 EXPECT_TRUE(third_it); | |
721 EXPECT_FALSE(second_it); | |
722 EXPECT_FALSE(it); | |
723 | |
724 set.Clear(); | |
725 | |
726 PrioritizedTileSet::Iterator empty_it(&set, true); | |
727 EXPECT_FALSE(empty_it); | |
728 } | |
729 | |
730 } // namespace | |
731 } // namespace cc | |
732 | |
OLD | NEW |