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