Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: cc/layers/picture_layer_impl_unittest.cc

Issue 874613003: cc: Stop pushing properties every activation for picture layers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pli-pushprops: fixscrolling Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/picture_layer_impl.cc ('k') | cc/resources/picture_layer_tiling.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 id_(7), 76 parent_id_(7),
77 id_(8),
77 pending_layer_(nullptr), 78 pending_layer_(nullptr),
78 old_pending_layer_(nullptr), 79 old_pending_layer_(nullptr),
79 active_layer_(nullptr) { 80 active_layer_(nullptr) {
80 host_impl_.SetViewportSize(gfx::Size(10000, 10000)); 81 host_impl_.SetViewportSize(gfx::Size(10000, 10000));
81 } 82 }
82 83
83 explicit PictureLayerImplTest(const LayerTreeSettings& settings) 84 explicit PictureLayerImplTest(const LayerTreeSettings& settings)
84 : proxy_(base::MessageLoopProxy::current()), 85 : proxy_(base::MessageLoopProxy::current()),
85 host_impl_(settings, &proxy_, &shared_bitmap_manager_), 86 host_impl_(settings, &proxy_, &shared_bitmap_manager_),
86 root_id_(6), 87 root_id_(6),
87 id_(7) { 88 parent_id_(7),
89 id_(8) {
88 host_impl_.SetViewportSize(gfx::Size(10000, 10000)); 90 host_impl_.SetViewportSize(gfx::Size(10000, 10000));
89 } 91 }
90 92
91 ~PictureLayerImplTest() override {} 93 ~PictureLayerImplTest() override {}
92 94
93 void SetUp() override { InitializeRenderer(); } 95 void SetUp() override { InitializeRenderer(); }
94 96
95 virtual void InitializeRenderer() { 97 virtual void InitializeRenderer() {
96 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d()); 98 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d());
97 } 99 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 191
190 void SetupPendingTreeInternal(scoped_refptr<RasterSource> raster_source, 192 void SetupPendingTreeInternal(scoped_refptr<RasterSource> raster_source,
191 const gfx::Size& tile_size, 193 const gfx::Size& tile_size,
192 const Region& invalidation) { 194 const Region& invalidation) {
193 host_impl_.CreatePendingTree(); 195 host_impl_.CreatePendingTree();
194 host_impl_.pending_tree()->PushPageScaleFromMainThread(1.f, 0.25f, 100.f); 196 host_impl_.pending_tree()->PushPageScaleFromMainThread(1.f, 0.25f, 100.f);
195 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); 197 LayerTreeImpl* pending_tree = host_impl_.pending_tree();
196 198
197 // Steal from the recycled tree if possible. 199 // Steal from the recycled tree if possible.
198 scoped_ptr<LayerImpl> pending_root = pending_tree->DetachLayerTree(); 200 scoped_ptr<LayerImpl> pending_root = pending_tree->DetachLayerTree();
201 scoped_ptr<LayerImpl> pending_parent;
199 scoped_ptr<FakePictureLayerImpl> pending_layer; 202 scoped_ptr<FakePictureLayerImpl> pending_layer;
200 DCHECK_IMPLIES(pending_root, pending_root->id() == root_id_); 203 DCHECK_IMPLIES(pending_root, pending_root->id() == root_id_);
201 if (!pending_root) { 204 if (!pending_root) {
202 pending_root = LayerImpl::Create(pending_tree, root_id_); 205 pending_root = LayerImpl::Create(pending_tree, root_id_);
206 pending_parent = LayerImpl::Create(pending_tree, parent_id_);
203 pending_layer = FakePictureLayerImpl::Create(pending_tree, id_); 207 pending_layer = FakePictureLayerImpl::Create(pending_tree, id_);
204 if (!tile_size.IsEmpty()) 208 if (!tile_size.IsEmpty())
205 pending_layer->set_fixed_tile_size(tile_size); 209 pending_layer->set_fixed_tile_size(tile_size);
206 pending_layer->SetDrawsContent(true); 210 pending_layer->SetDrawsContent(true);
207 } else { 211 } else {
212 pending_parent = pending_root->RemoveChild(pending_root->children()[0]);
208 pending_layer.reset(static_cast<FakePictureLayerImpl*>( 213 pending_layer.reset(static_cast<FakePictureLayerImpl*>(
209 pending_root->RemoveChild(pending_root->children()[0]).release())); 214 pending_parent->RemoveChild(pending_parent->children()[0])
215 .release()));
210 if (!tile_size.IsEmpty()) 216 if (!tile_size.IsEmpty())
211 pending_layer->set_fixed_tile_size(tile_size); 217 pending_layer->set_fixed_tile_size(tile_size);
212 } 218 }
213 pending_root->SetHasRenderSurface(true); 219 pending_root->SetHasRenderSurface(true);
214 // The bounds() just mirror the pile size. 220 // The bounds() just mirror the pile size.
215 pending_layer->SetBounds(raster_source->GetSize()); 221 pending_layer->SetBounds(raster_source->GetSize());
216 pending_layer->SetContentBounds(raster_source->GetSize()); 222 pending_layer->SetContentBounds(raster_source->GetSize());
217 pending_layer->SetRasterSourceOnPending(raster_source, invalidation); 223 pending_layer->SetRasterSourceOnPending(raster_source, invalidation);
218 224
219 pending_root->AddChild(pending_layer.Pass()); 225 pending_parent->AddChild(pending_layer.Pass());
226 pending_root->AddChild(pending_parent.Pass());
220 pending_tree->SetRootLayer(pending_root.Pass()); 227 pending_tree->SetRootLayer(pending_root.Pass());
221 228
222 pending_layer_ = static_cast<FakePictureLayerImpl*>( 229 pending_layer_ = static_cast<FakePictureLayerImpl*>(
223 host_impl_.pending_tree()->LayerById(id_)); 230 host_impl_.pending_tree()->LayerById(id_));
224 231
225 // Add tilings/tiles for the layer. 232 // Add tilings/tiles for the layer.
226 host_impl_.pending_tree()->UpdateDrawProperties(); 233 host_impl_.pending_tree()->UpdateDrawProperties();
227 } 234 }
228 235
229 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl* layer, 236 void SetupDrawPropertiesAndUpdateTiles(FakePictureLayerImpl* layer,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 EXPECT_GT(tiles.size(), 0u); 306 EXPECT_GT(tiles.size(), 0u);
300 } 307 }
301 308
302 protected: 309 protected:
303 void TestQuadsForSolidColor(bool test_for_solid); 310 void TestQuadsForSolidColor(bool test_for_solid);
304 311
305 FakeImplProxy proxy_; 312 FakeImplProxy proxy_;
306 TestSharedBitmapManager shared_bitmap_manager_; 313 TestSharedBitmapManager shared_bitmap_manager_;
307 FakeLayerTreeHostImpl host_impl_; 314 FakeLayerTreeHostImpl host_impl_;
308 int root_id_; 315 int root_id_;
316 int parent_id_;
309 int id_; 317 int id_;
310 FakePictureLayerImpl* pending_layer_; 318 FakePictureLayerImpl* pending_layer_;
311 FakePictureLayerImpl* old_pending_layer_; 319 FakePictureLayerImpl* old_pending_layer_;
312 FakePictureLayerImpl* active_layer_; 320 FakePictureLayerImpl* active_layer_;
313 321
314 private: 322 private:
315 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest); 323 DISALLOW_COPY_AND_ASSIGN(PictureLayerImplTest);
316 }; 324 };
317 325
318 class NoLowResPictureLayerImplTest : public PictureLayerImplTest { 326 class NoLowResPictureLayerImplTest : public PictureLayerImplTest {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 388
381 EXPECT_EQ(pending_layer_->tilings()->num_tilings(), 389 EXPECT_EQ(pending_layer_->tilings()->num_tilings(),
382 active_layer_->tilings()->num_tilings()); 390 active_layer_->tilings()->num_tilings());
383 391
384 const PictureLayerTilingSet* tilings = pending_layer_->tilings(); 392 const PictureLayerTilingSet* tilings = pending_layer_->tilings();
385 EXPECT_GT(tilings->num_tilings(), 0u); 393 EXPECT_GT(tilings->num_tilings(), 0u);
386 for (size_t i = 0; i < tilings->num_tilings(); ++i) 394 for (size_t i = 0; i < tilings->num_tilings(); ++i)
387 VerifyAllTilesExistAndHavePile(tilings->tiling_at(i), pending_pile.get()); 395 VerifyAllTilesExistAndHavePile(tilings->tiling_at(i), pending_pile.get());
388 } 396 }
389 397
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
390 TEST_F(PictureLayerImplTest, ExternalViewportRectForPrioritizingTiles) { 547 TEST_F(PictureLayerImplTest, ExternalViewportRectForPrioritizingTiles) {
391 base::TimeTicks time_ticks; 548 base::TimeTicks time_ticks;
392 time_ticks += base::TimeDelta::FromMilliseconds(1); 549 time_ticks += base::TimeDelta::FromMilliseconds(1);
393 host_impl_.SetCurrentBeginFrameArgs( 550 host_impl_.SetCurrentBeginFrameArgs(
394 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks)); 551 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, time_ticks));
395 gfx::Size tile_size(100, 100); 552 gfx::Size tile_size(100, 100);
396 gfx::Size layer_bounds(400, 400); 553 gfx::Size layer_bounds(400, 400);
397 554
398 scoped_refptr<FakePicturePileImpl> pending_pile = 555 scoped_refptr<FakePicturePileImpl> pending_pile =
399 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); 556 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
(...skipping 4479 matching lines...) Expand 10 before | Expand all | Expand 10 after
4879 result = layer->CalculateTileSize(gfx::Size(447, 400)); 5036 result = layer->CalculateTileSize(gfx::Size(447, 400));
4880 EXPECT_EQ(result.width(), 448); 5037 EXPECT_EQ(result.width(), 448);
4881 EXPECT_EQ(result.height(), 448); 5038 EXPECT_EQ(result.height(), 448);
4882 result = layer->CalculateTileSize(gfx::Size(500, 499)); 5039 result = layer->CalculateTileSize(gfx::Size(500, 499));
4883 EXPECT_EQ(result.width(), 512); 5040 EXPECT_EQ(result.width(), 512);
4884 EXPECT_EQ(result.height(), 500 + 2); 5041 EXPECT_EQ(result.height(), 500 + 2);
4885 } 5042 }
4886 5043
4887 } // namespace 5044 } // namespace
4888 } // namespace cc 5045 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer_impl.cc ('k') | cc/resources/picture_layer_tiling.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698