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