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