OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 public: | 66 public: |
67 LowResTilingsSettings() { create_low_res_tiling = true; } | 67 LowResTilingsSettings() { create_low_res_tiling = true; } |
68 }; | 68 }; |
69 | 69 |
70 class PictureLayerImplTest : public testing::Test { | 70 class PictureLayerImplTest : public testing::Test { |
71 public: | 71 public: |
72 PictureLayerImplTest() | 72 PictureLayerImplTest() |
73 : proxy_(base::MessageLoopProxy::current()), | 73 : proxy_(base::MessageLoopProxy::current()), |
74 host_impl_(LowResTilingsSettings(), &proxy_, &shared_bitmap_manager_), | 74 host_impl_(LowResTilingsSettings(), &proxy_, &shared_bitmap_manager_), |
75 root_id_(6), | 75 root_id_(6), |
76 parent_id_(7), | 76 id_(7), |
77 id_(8), | |
78 pending_layer_(nullptr), | 77 pending_layer_(nullptr), |
79 old_pending_layer_(nullptr), | 78 old_pending_layer_(nullptr), |
80 active_layer_(nullptr) { | 79 active_layer_(nullptr) { |
81 host_impl_.SetViewportSize(gfx::Size(10000, 10000)); | 80 host_impl_.SetViewportSize(gfx::Size(10000, 10000)); |
82 } | 81 } |
83 | 82 |
84 explicit PictureLayerImplTest(const LayerTreeSettings& settings) | 83 explicit PictureLayerImplTest(const LayerTreeSettings& settings) |
85 : proxy_(base::MessageLoopProxy::current()), | 84 : proxy_(base::MessageLoopProxy::current()), |
86 host_impl_(settings, &proxy_, &shared_bitmap_manager_), | 85 host_impl_(settings, &proxy_, &shared_bitmap_manager_), |
87 root_id_(6), | 86 root_id_(6), |
88 parent_id_(7), | 87 id_(7) { |
89 id_(8) { | |
90 host_impl_.SetViewportSize(gfx::Size(10000, 10000)); | 88 host_impl_.SetViewportSize(gfx::Size(10000, 10000)); |
91 } | 89 } |
92 | 90 |
93 ~PictureLayerImplTest() override {} | 91 ~PictureLayerImplTest() override {} |
94 | 92 |
95 void SetUp() override { InitializeRenderer(); } | 93 void SetUp() override { InitializeRenderer(); } |
96 | 94 |
97 virtual void InitializeRenderer() { | 95 virtual void InitializeRenderer() { |
98 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d()); | 96 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d()); |
99 } | 97 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 189 |
192 void SetupPendingTreeInternal(scoped_refptr<RasterSource> raster_source, | 190 void SetupPendingTreeInternal(scoped_refptr<RasterSource> raster_source, |
193 const gfx::Size& tile_size, | 191 const gfx::Size& tile_size, |
194 const Region& invalidation) { | 192 const Region& invalidation) { |
195 host_impl_.CreatePendingTree(); | 193 host_impl_.CreatePendingTree(); |
196 host_impl_.pending_tree()->PushPageScaleFromMainThread(1.f, 0.25f, 100.f); | 194 host_impl_.pending_tree()->PushPageScaleFromMainThread(1.f, 0.25f, 100.f); |
197 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); | 195 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); |
198 | 196 |
199 // Steal from the recycled tree if possible. | 197 // Steal from the recycled tree if possible. |
200 scoped_ptr<LayerImpl> pending_root = pending_tree->DetachLayerTree(); | 198 scoped_ptr<LayerImpl> pending_root = pending_tree->DetachLayerTree(); |
201 scoped_ptr<LayerImpl> pending_parent; | |
202 scoped_ptr<FakePictureLayerImpl> pending_layer; | 199 scoped_ptr<FakePictureLayerImpl> pending_layer; |
203 DCHECK_IMPLIES(pending_root, pending_root->id() == root_id_); | 200 DCHECK_IMPLIES(pending_root, pending_root->id() == root_id_); |
204 if (!pending_root) { | 201 if (!pending_root) { |
205 pending_root = LayerImpl::Create(pending_tree, root_id_); | 202 pending_root = LayerImpl::Create(pending_tree, root_id_); |
206 pending_parent = LayerImpl::Create(pending_tree, parent_id_); | |
207 pending_layer = FakePictureLayerImpl::Create(pending_tree, id_); | 203 pending_layer = FakePictureLayerImpl::Create(pending_tree, id_); |
208 if (!tile_size.IsEmpty()) | 204 if (!tile_size.IsEmpty()) |
209 pending_layer->set_fixed_tile_size(tile_size); | 205 pending_layer->set_fixed_tile_size(tile_size); |
210 pending_layer->SetDrawsContent(true); | 206 pending_layer->SetDrawsContent(true); |
211 } else { | 207 } else { |
212 pending_parent = pending_root->RemoveChild(pending_root->children()[0]); | |
213 pending_layer.reset(static_cast<FakePictureLayerImpl*>( | 208 pending_layer.reset(static_cast<FakePictureLayerImpl*>( |
214 pending_parent->RemoveChild(pending_parent->children()[0]) | 209 pending_root->RemoveChild(pending_root->children()[0]).release())); |
215 .release())); | |
216 if (!tile_size.IsEmpty()) | 210 if (!tile_size.IsEmpty()) |
217 pending_layer->set_fixed_tile_size(tile_size); | 211 pending_layer->set_fixed_tile_size(tile_size); |
218 } | 212 } |
219 pending_root->SetHasRenderSurface(true); | 213 pending_root->SetHasRenderSurface(true); |
220 // The bounds() just mirror the pile size. | 214 // The bounds() just mirror the pile size. |
221 pending_layer->SetBounds(raster_source->GetSize()); | 215 pending_layer->SetBounds(raster_source->GetSize()); |
222 pending_layer->SetContentBounds(raster_source->GetSize()); | 216 pending_layer->SetContentBounds(raster_source->GetSize()); |
223 pending_layer->SetRasterSourceOnPending(raster_source, invalidation); | 217 pending_layer->SetRasterSourceOnPending(raster_source, invalidation); |
224 | 218 |
225 pending_parent->AddChild(pending_layer.Pass()); | 219 pending_root->AddChild(pending_layer.Pass()); |
226 pending_root->AddChild(pending_parent.Pass()); | |
227 pending_tree->SetRootLayer(pending_root.Pass()); | 220 pending_tree->SetRootLayer(pending_root.Pass()); |
228 | 221 |
229 pending_layer_ = static_cast<FakePictureLayerImpl*>( | 222 pending_layer_ = static_cast<FakePictureLayerImpl*>( |
230 host_impl_.pending_tree()->LayerById(id_)); | 223 host_impl_.pending_tree()->LayerById(id_)); |
231 | 224 |
232 // Add tilings/tiles for the layer. | 225 // Add tilings/tiles for the layer. |
233 host_impl_.pending_tree()->UpdateDrawProperties(); | 226 host_impl_.pending_tree()->UpdateDrawProperties(); |
234 } | 227 } |
235 | 228 |
236 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl* layer, | 229 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl* layer, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 EXPECT_GT(tiles.size(), 0u); | 299 EXPECT_GT(tiles.size(), 0u); |
307 } | 300 } |
308 | 301 |
309 protected: | 302 protected: |
310 void TestQuadsForSolidColor(bool test_for_solid); | 303 void TestQuadsForSolidColor(bool test_for_solid); |
311 | 304 |
312 FakeImplProxy proxy_; | 305 FakeImplProxy proxy_; |
313 TestSharedBitmapManager shared_bitmap_manager_; | 306 TestSharedBitmapManager shared_bitmap_manager_; |
314 FakeLayerTreeHostImpl host_impl_; | 307 FakeLayerTreeHostImpl host_impl_; |
315 int root_id_; | 308 int root_id_; |
316 int parent_id_; | |
317 int id_; | 309 int id_; |
318 FakePictureLayerImpl* pending_layer_; | 310 FakePictureLayerImpl* pending_layer_; |
319 FakePictureLayerImpl* old_pending_layer_; | 311 FakePictureLayerImpl* old_pending_layer_; |
320 FakePictureLayerImpl* active_layer_; | 312 FakePictureLayerImpl* active_layer_; |
321 | 313 |
322 private: | 314 private: |
323 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest); | 315 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest); |
324 }; | 316 }; |
325 | 317 |
326 class NoLowResPictureLayerImplTest : public PictureLayerImplTest { | 318 class NoLowResPictureLayerImplTest : public PictureLayerImplTest { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 380 |
389 EXPECT_EQ(pending_layer_->tilings()->num_tilings(), | 381 EXPECT_EQ(pending_layer_->tilings()->num_tilings(), |
390 active_layer_->tilings()->num_tilings()); | 382 active_layer_->tilings()->num_tilings()); |
391 | 383 |
392 const PictureLayerTilingSet* tilings = pending_layer_->tilings(); | 384 const PictureLayerTilingSet* tilings = pending_layer_->tilings(); |
393 EXPECT_GT(tilings->num_tilings(), 0u); | 385 EXPECT_GT(tilings->num_tilings(), 0u); |
394 for (size_t i = 0; i < tilings->num_tilings(); ++i) | 386 for (size_t i = 0; i < tilings->num_tilings(); ++i) |
395 VerifyAllTilesExistAndHavePile(tilings->tiling_at(i), pending_pile.get()); | 387 VerifyAllTilesExistAndHavePile(tilings->tiling_at(i), pending_pile.get()); |
396 } | 388 } |
397 | 389 |
398 TEST_F(PictureLayerImplTest, PushPropertiesForNewRasterSource) { | |
399 gfx::Size tile_size(100, 100); | |
400 gfx::Size layer_bounds(400, 400); | |
401 | |
402 scoped_refptr<FakePicturePileImpl> filled_pile = | |
403 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
404 scoped_refptr<FakePicturePileImpl> empty_pile = | |
405 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | |
406 | |
407 // A new layer needs to push properties. | |
408 SetupPendingTree(filled_pile); | |
409 EXPECT_TRUE(pending_layer_->needs_push_properties()); | |
410 | |
411 host_impl_.ActivateSyncTree(); | |
412 | |
413 // By default a layer has nothing to push. | |
414 host_impl_.CreatePendingTree(); | |
415 EXPECT_FALSE(pending_layer_->needs_push_properties()); | |
416 | |
417 // Setting a new raster source will require pushing. | |
418 pending_layer_->SetRasterSourceOnPending(filled_pile, Region()); | |
419 EXPECT_TRUE(pending_layer_->needs_push_properties()); | |
420 | |
421 host_impl_.ActivateSyncTree(); | |
422 host_impl_.CreatePendingTree(); | |
423 EXPECT_FALSE(pending_layer_->needs_push_properties()); | |
424 | |
425 // A new source that changes CanHaveTilings also requires pushing. | |
426 EXPECT_TRUE(pending_layer_->CanHaveTilings()); | |
427 pending_layer_->SetRasterSourceOnPending(empty_pile, Region()); | |
428 EXPECT_FALSE(pending_layer_->CanHaveTilings()); | |
429 EXPECT_TRUE(pending_layer_->needs_push_properties()); | |
430 } | |
431 | |
432 TEST_F(PictureLayerImplTest, PushPropertiesForNewTiling) { | |
433 base::TimeTicks time_ticks; | |
434 time_ticks += base::TimeDelta::FromMilliseconds(1); | |
435 host_impl_.SetCurrentBeginFrameArgs( | |
436 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); | |
437 | |
438 gfx::Size tile_size(100, 100); | |
439 gfx::Size layer_bounds(400, 400); | |
440 | |
441 scoped_refptr<FakePicturePileImpl> filled_pile = | |
442 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
443 scoped_refptr<FakePicturePileImpl> empty_pile = | |
444 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | |
445 | |
446 // A new layer needs to push properties. | |
447 SetupPendingTree(filled_pile); | |
448 EXPECT_TRUE(pending_layer_->needs_push_properties()); | |
449 | |
450 host_impl_.ActivateSyncTree(); | |
451 | |
452 // By default a layer has nothing to push. | |
453 host_impl_.CreatePendingTree(); | |
454 host_impl_.pending_tree()->PushPageScaleFromMainThread(1.f, 0.25f, 100.f); | |
455 EXPECT_FALSE(pending_layer_->needs_push_properties()); | |
456 | |
457 // Update tiles without changing the scale, shouldn't need to push properties. | |
458 time_ticks += base::TimeDelta::FromMilliseconds(200); | |
459 host_impl_.SetCurrentBeginFrameArgs( | |
460 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); | |
461 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 1.f, 1.f, 1.f, 1.f, false); | |
462 | |
463 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale()); | |
464 EXPECT_FALSE(pending_layer_->needs_push_properties()); | |
465 | |
466 // Change the scale on the layer, which should make a new high res tiling. | |
467 time_ticks += base::TimeDelta::FromMilliseconds(200); | |
468 host_impl_.SetCurrentBeginFrameArgs( | |
469 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); | |
470 SetupDrawPropertiesAndUpdateTiles(pending_layer_, 6.f, 1.f, 6.f, 1.f, false); | |
471 | |
472 EXPECT_EQ(6.f, pending_layer_->HighResTiling()->contents_scale()); | |
473 EXPECT_TRUE(pending_layer_->needs_push_properties()); | |
474 } | |
475 | |
476 TEST_F(PictureLayerImplTest, PushPropertiesForNewTiles) { | |
477 base::TimeTicks time_ticks; | |
478 time_ticks += base::TimeDelta::FromMilliseconds(1); | |
479 host_impl_.SetCurrentBeginFrameArgs( | |
480 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); | |
481 | |
482 gfx::Size tile_size(100, 100); | |
483 gfx::Size layer_bounds(400, 100000); | |
484 | |
485 host_impl_.SetViewportSize(gfx::Size(100, 100)); | |
486 | |
487 scoped_refptr<FakePicturePileImpl> filled_pile = | |
488 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | |
489 scoped_refptr<FakePicturePileImpl> empty_pile = | |
490 FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); | |
491 | |
492 // A new layer needs to push properties. | |
493 SetupPendingTree(filled_pile); | |
494 EXPECT_TRUE(pending_layer_->needs_push_properties()); | |
495 | |
496 host_impl_.ActivateSyncTree(); | |
497 | |
498 // By default a layer has nothing to push. | |
499 host_impl_.CreatePendingTree(); | |
500 EXPECT_FALSE(pending_layer_->needs_push_properties()); | |
501 | |
502 host_impl_.pending_tree()->PushPageScaleFromMainThread(1.f, 0.25f, 100.f); | |
503 | |
504 int num_tiles_y = | |
505 pending_layer_->HighResTiling()->TilingDataForTesting().num_tiles_y(); | |
506 | |
507 // Verify a bit about current pending tree's current tiles. | |
508 EXPECT_EQ(1.f, pending_layer_->HighResTiling()->contents_scale()); | |
509 EXPECT_TRUE(pending_layer_->HighResTiling()->TileAt(0, 0)); | |
510 EXPECT_FALSE(pending_layer_->HighResTiling()->TileAt(0, num_tiles_y - 1)); | |
511 | |
512 // Update tiles without changing the viewport, nothing new to push. | |
513 time_ticks += base::TimeDelta::FromMilliseconds(1); | |
514 host_impl_.SetCurrentBeginFrameArgs( | |
515 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); | |
516 host_impl_.pending_tree()->UpdateDrawProperties(); | |
517 | |
518 // Same tiles on the pending tree. | |
519 EXPECT_TRUE(pending_layer_->HighResTiling()->TileAt(0, 0)); | |
520 EXPECT_FALSE(pending_layer_->HighResTiling()->TileAt(0, num_tiles_y - 1)); | |
521 // Means nothing new to push. | |
522 EXPECT_FALSE(pending_layer_->needs_push_properties()); | |
523 | |
524 host_impl_.ActivateSyncTree(); | |
525 host_impl_.CreatePendingTree(); | |
526 EXPECT_FALSE(pending_layer_->needs_push_properties()); | |
527 | |
528 host_impl_.pending_tree()->PushPageScaleFromMainThread(1.f, 0.25f, 100.f); | |
529 | |
530 // Change what part of the layer is visible in the viewport and update draw | |
531 // properties and tile priorities. This should create new tiles on the layer. | |
532 pending_layer_->parent()->SetPosition( | |
533 gfx::PointF(0.f, -layer_bounds.height() + 100.f)); | |
534 | |
535 time_ticks += base::TimeDelta::FromMilliseconds(1); | |
536 host_impl_.SetCurrentBeginFrameArgs( | |
537 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); | |
538 host_impl_.pending_tree()->UpdateDrawProperties(); | |
539 | |
540 // There are new tiles on the pending tree now. | |
541 EXPECT_FALSE(pending_layer_->HighResTiling()->TileAt(0, 0)); | |
542 EXPECT_TRUE(pending_layer_->HighResTiling()->TileAt(0, num_tiles_y - 1)); | |
543 // So the layer needs to push properties to sync the new tiles. | |
544 EXPECT_TRUE(pending_layer_->needs_push_properties()); | |
545 } | |
546 | |
547 TEST_F(PictureLayerImplTest, ExternalViewportRectForPrioritizingTiles) { | 390 TEST_F(PictureLayerImplTest, ExternalViewportRectForPrioritizingTiles) { |
548 base::TimeTicks time_ticks; | 391 base::TimeTicks time_ticks; |
549 time_ticks += base::TimeDelta::FromMilliseconds(1); | 392 time_ticks += base::TimeDelta::FromMilliseconds(1); |
550 host_impl_.SetCurrentBeginFrameArgs( | 393 host_impl_.SetCurrentBeginFrameArgs( |
551 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); | 394 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); |
552 gfx::Size tile_size(100, 100); | 395 gfx::Size tile_size(100, 100); |
553 gfx::Size layer_bounds(400, 400); | 396 gfx::Size layer_bounds(400, 400); |
554 | 397 |
555 scoped_refptr<FakePicturePileImpl> pending_pile = | 398 scoped_refptr<FakePicturePileImpl> pending_pile = |
556 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 399 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
(...skipping 4479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5036 result = layer->CalculateTileSize(gfx::Size(447, 400)); | 4879 result = layer->CalculateTileSize(gfx::Size(447, 400)); |
5037 EXPECT_EQ(result.width(), 448); | 4880 EXPECT_EQ(result.width(), 448); |
5038 EXPECT_EQ(result.height(), 448); | 4881 EXPECT_EQ(result.height(), 448); |
5039 result = layer->CalculateTileSize(gfx::Size(500, 499)); | 4882 result = layer->CalculateTileSize(gfx::Size(500, 499)); |
5040 EXPECT_EQ(result.width(), 512); | 4883 EXPECT_EQ(result.width(), 512); |
5041 EXPECT_EQ(result.height(), 500 + 2); | 4884 EXPECT_EQ(result.height(), 500 + 2); |
5042 } | 4885 } |
5043 | 4886 |
5044 } // namespace | 4887 } // namespace |
5045 } // namespace cc | 4888 } // namespace cc |
OLD | NEW |