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

Side by Side Diff: cc/trees/layer_tree_host_unittest_picture.cc

Issue 2175553002: Raster PictureLayerTiling with fractional translation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: combined Created 3 years, 8 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
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/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include "cc/test/fake_content_layer_client.h" 7 #include "cc/test/fake_content_layer_client.h"
8 #include "cc/test/fake_picture_layer.h" 8 #include "cc/test/fake_picture_layer.h"
9 #include "cc/test/fake_picture_layer_impl.h" 9 #include "cc/test/fake_picture_layer_impl.h"
10 #include "cc/test/layer_tree_test.h" 10 #include "cc/test/layer_tree_test.h"
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 451
452 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { 452 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
453 LayerImpl* gchild = impl->sync_tree()->LayerById(picture_->id()); 453 LayerImpl* gchild = impl->sync_tree()->LayerById(picture_->id());
454 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild); 454 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild);
455 ready_to_draw_ = false; 455 ready_to_draw_ = false;
456 456
457 switch (frame_) { 457 switch (frame_) {
458 case 0: 458 case 0:
459 // On 1st commit the pending layer has tilings. 459 // On 1st commit the pending layer has tilings.
460 ASSERT_EQ(1u, picture->tilings()->num_tilings()); 460 ASSERT_EQ(1u, picture->tilings()->num_tilings());
461 EXPECT_EQ(1.f, picture->tilings()->tiling_at(0)->contents_scale()); 461 EXPECT_EQ(ScaleTranslate2d(),
462 picture->tilings()->tiling_at(0)->raster_transform());
462 break; 463 break;
463 case 1: 464 case 1:
464 // On 2nd commit, the pending layer is transparent, so has a stale 465 // On 2nd commit, the pending layer is transparent, so has a stale
465 // value. 466 // value.
466 ASSERT_EQ(1u, picture->tilings()->num_tilings()); 467 ASSERT_EQ(1u, picture->tilings()->num_tilings());
467 EXPECT_EQ(1.f, picture->tilings()->tiling_at(0)->contents_scale()); 468 EXPECT_EQ(ScaleTranslate2d(),
469 picture->tilings()->tiling_at(0)->raster_transform());
468 break; 470 break;
469 case 2: 471 case 2:
470 // On 3rd commit, the pending layer is visible again, so has tilings and 472 // On 3rd commit, the pending layer is visible again, so has tilings and
471 // is updated for the pinch. 473 // is updated for the pinch.
472 ASSERT_EQ(1u, picture->tilings()->num_tilings()); 474 ASSERT_EQ(1u, picture->tilings()->num_tilings());
473 EXPECT_EQ(2.f, picture->tilings()->tiling_at(0)->contents_scale()); 475 EXPECT_EQ(ScaleTranslate2d(2.f, gfx::Vector2dF()),
476 picture->tilings()->tiling_at(0)->raster_transform());
474 } 477 }
475 } 478 }
476 479
477 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { 480 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
478 LayerImpl* gchild = impl->active_tree()->LayerById(picture_->id()); 481 LayerImpl* gchild = impl->active_tree()->LayerById(picture_->id());
479 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild); 482 FakePictureLayerImpl* picture = static_cast<FakePictureLayerImpl*>(gchild);
480 483
481 if (frame_ != last_frame_drawn_) 484 if (frame_ != last_frame_drawn_)
482 draws_in_frame_ = 0; 485 draws_in_frame_ = 0;
483 ++draws_in_frame_; 486 ++draws_in_frame_;
484 last_frame_drawn_ = frame_; 487 last_frame_drawn_ = frame_;
485 488
486 switch (frame_) { 489 switch (frame_) {
487 case 0: 490 case 0:
488 if (draws_in_frame_ == 1) { 491 if (draws_in_frame_ == 1) {
489 // On 1st commit the layer has tilings. 492 // On 1st commit the layer has tilings.
490 EXPECT_GT(picture->tilings()->num_tilings(), 0u); 493 EXPECT_GT(picture->tilings()->num_tilings(), 0u);
491 EXPECT_EQ(1.f, picture->HighResTiling()->contents_scale()); 494 EXPECT_EQ(ScaleTranslate2d(),
495 picture->HighResTiling()->raster_transform());
492 496
493 // Pinch zoom in to change the scale on the active tree. 497 // Pinch zoom in to change the scale on the active tree.
494 impl->PinchGestureBegin(); 498 impl->PinchGestureBegin();
495 impl->PinchGestureUpdate(2.f, gfx::Point(1, 1)); 499 impl->PinchGestureUpdate(2.f, gfx::Point(1, 1));
496 impl->PinchGestureEnd(); 500 impl->PinchGestureEnd();
497 } else if (picture->tilings()->num_tilings() == 1) { 501 } else if (picture->tilings()->num_tilings() == 1) {
498 // If the pinch gesture caused a commit we could get here with a 502 // If the pinch gesture caused a commit we could get here with a
499 // pending tree. 503 // pending tree.
500 EXPECT_FALSE(impl->pending_tree()); 504 EXPECT_FALSE(impl->pending_tree());
501 EXPECT_EQ(2.f, picture->HighResTiling()->contents_scale()); 505 EXPECT_EQ(ScaleTranslate2d(2.f, gfx::Vector2dF()),
506 picture->HighResTiling()->raster_transform());
502 507
503 // Need to wait for ready to draw here so that the pinch is 508 // Need to wait for ready to draw here so that the pinch is
504 // entirely complete, otherwise another draw might come in before 509 // entirely complete, otherwise another draw might come in before
505 // the commit occurs. 510 // the commit occurs.
506 if (ready_to_draw_) { 511 if (ready_to_draw_) {
507 ++frame_; 512 ++frame_;
508 MainThreadTaskRunner()->PostTask( 513 MainThreadTaskRunner()->PostTask(
509 FROM_HERE, 514 FROM_HERE,
510 base::Bind( 515 base::Bind(
511 &LayerTreeHostPictureTestRSLLMembershipWithScale::NextStep, 516 &LayerTreeHostPictureTestRSLLMembershipWithScale::NextStep,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 FakePictureLayerImpl* will_change_layer = 614 FakePictureLayerImpl* will_change_layer =
610 static_cast<FakePictureLayerImpl*>( 615 static_cast<FakePictureLayerImpl*>(
611 impl->active_tree()->LayerById(will_change_layer_->id())); 616 impl->active_tree()->LayerById(will_change_layer_->id()));
612 FakePictureLayerImpl* normal_layer = static_cast<FakePictureLayerImpl*>( 617 FakePictureLayerImpl* normal_layer = static_cast<FakePictureLayerImpl*>(
613 impl->active_tree()->LayerById(normal_layer_->id())); 618 impl->active_tree()->LayerById(normal_layer_->id()));
614 619
615 switch (impl->sync_tree()->source_frame_number()) { 620 switch (impl->sync_tree()->source_frame_number()) {
616 case 0: 621 case 0:
617 // On first commit, both layers are at the default scale. 622 // On first commit, both layers are at the default scale.
618 ASSERT_EQ(1u, will_change_layer->tilings()->num_tilings()); 623 ASSERT_EQ(1u, will_change_layer->tilings()->num_tilings());
619 EXPECT_EQ(1.f, 624 EXPECT_EQ(
620 will_change_layer->tilings()->tiling_at(0)->contents_scale()); 625 ScaleTranslate2d(),
626 will_change_layer->tilings()->tiling_at(0)->raster_transform());
621 ASSERT_EQ(1u, normal_layer->tilings()->num_tilings()); 627 ASSERT_EQ(1u, normal_layer->tilings()->num_tilings());
622 EXPECT_EQ(1.f, normal_layer->tilings()->tiling_at(0)->contents_scale()); 628 EXPECT_EQ(ScaleTranslate2d(),
629 normal_layer->tilings()->tiling_at(0)->raster_transform());
623 630
624 MainThreadTaskRunner()->PostTask( 631 MainThreadTaskRunner()->PostTask(
625 FROM_HERE, 632 FROM_HERE,
626 base::Bind( 633 base::Bind(
627 &LayerTreeHostPictureTestForceRecalculateScales::ScaleRootUp, 634 &LayerTreeHostPictureTestForceRecalculateScales::ScaleRootUp,
628 base::Unretained(this))); 635 base::Unretained(this)));
629 break; 636 break;
630 case 1: 637 case 1:
631 // On 2nd commit after scaling up to 2, the normal layer will adjust its 638 // On 2nd commit after scaling up to 2, the normal layer will adjust its
632 // scale and the will change layer should not (as it is will change. 639 // scale and the will change layer should not (as it is will change.
633 ASSERT_EQ(1u, will_change_layer->tilings()->num_tilings()); 640 ASSERT_EQ(1u, will_change_layer->tilings()->num_tilings());
634 EXPECT_EQ(1.f, 641 EXPECT_EQ(
635 will_change_layer->tilings()->tiling_at(0)->contents_scale()); 642 ScaleTranslate2d(),
643 will_change_layer->tilings()->tiling_at(0)->raster_transform());
636 ASSERT_EQ(1u, normal_layer->tilings()->num_tilings()); 644 ASSERT_EQ(1u, normal_layer->tilings()->num_tilings());
637 EXPECT_EQ(2.f, normal_layer->tilings()->tiling_at(0)->contents_scale()); 645 EXPECT_EQ(ScaleTranslate2d(2.f, gfx::Vector2dF()),
646 normal_layer->tilings()->tiling_at(0)->raster_transform());
638 647
639 MainThreadTaskRunner()->PostTask( 648 MainThreadTaskRunner()->PostTask(
640 FROM_HERE, 649 FROM_HERE,
641 base::Bind(&LayerTreeHostPictureTestForceRecalculateScales:: 650 base::Bind(&LayerTreeHostPictureTestForceRecalculateScales::
642 ScaleRootUpAndRecalculateScales, 651 ScaleRootUpAndRecalculateScales,
643 base::Unretained(this))); 652 base::Unretained(this)));
644 break; 653 break;
645 case 2: 654 case 2:
646 // On 3rd commit, both layers should adjust scales due to forced 655 // On 3rd commit, both layers should adjust scales due to forced
647 // recalculating. 656 // recalculating.
648 ASSERT_EQ(1u, will_change_layer->tilings()->num_tilings()); 657 ASSERT_EQ(1u, will_change_layer->tilings()->num_tilings());
649 EXPECT_EQ(4.f, 658 EXPECT_EQ(
650 will_change_layer->tilings()->tiling_at(0)->contents_scale()); 659 ScaleTranslate2d(4.f, gfx::Vector2dF()),
660 will_change_layer->tilings()->tiling_at(0)->raster_transform());
651 ASSERT_EQ(1u, normal_layer->tilings()->num_tilings()); 661 ASSERT_EQ(1u, normal_layer->tilings()->num_tilings());
652 EXPECT_EQ(4.f, normal_layer->tilings()->tiling_at(0)->contents_scale()); 662 EXPECT_EQ(ScaleTranslate2d(4.f, gfx::Vector2dF()),
663 normal_layer->tilings()->tiling_at(0)->raster_transform());
653 EndTest(); 664 EndTest();
654 break; 665 break;
655 } 666 }
656 } 667 }
657 668
658 void ScaleRootUp() { 669 void ScaleRootUp() {
659 gfx::Transform transform; 670 gfx::Transform transform;
660 transform.Scale(2, 2); 671 transform.Scale(2, 2);
661 layer_tree_host()->root_layer()->SetTransform(transform); 672 layer_tree_host()->root_layer()->SetTransform(transform);
662 } 673 }
663 674
664 void ScaleRootUpAndRecalculateScales() { 675 void ScaleRootUpAndRecalculateScales() {
665 gfx::Transform transform; 676 gfx::Transform transform;
666 transform.Scale(4, 4); 677 transform.Scale(4, 4);
667 layer_tree_host()->root_layer()->SetTransform(transform); 678 layer_tree_host()->root_layer()->SetTransform(transform);
668 layer_tree_host()->SetNeedsRecalculateRasterScales(); 679 layer_tree_host()->SetNeedsRecalculateRasterScales();
669 } 680 }
670 681
671 void AfterTest() override {} 682 void AfterTest() override {}
672 683
673 scoped_refptr<FakePictureLayer> will_change_layer_; 684 scoped_refptr<FakePictureLayer> will_change_layer_;
674 scoped_refptr<FakePictureLayer> normal_layer_; 685 scoped_refptr<FakePictureLayer> normal_layer_;
675 }; 686 };
676 687
677 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostPictureTestForceRecalculateScales); 688 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostPictureTestForceRecalculateScales);
678 689
679 } // namespace 690 } // namespace
680 } // namespace cc 691 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest.cc ('k') | third_party/WebKit/Source/core/layout/compositing/CompositedLayerMapping.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698