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

Side by Side Diff: ui/gfx/compositor/layer_unittest.cc

Issue 8368013: Improve Aura overdraw by changing hole calculation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resetting git state Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/compositor/layer.cc ('k') | views/view_unittest.cc » ('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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/canvas_skia.h" 9 #include "ui/gfx/canvas_skia.h"
10 #include "ui/gfx/compositor/compositor_observer.h" 10 #include "ui/gfx/compositor/compositor_observer.h"
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 // Verifies that when there are many potential holes, the largest one is picked. 564 // Verifies that when there are many potential holes, the largest one is picked.
565 TEST_F(LayerWithNullDelegateTest, LargestHole) { 565 TEST_F(LayerWithNullDelegateTest, LargestHole) {
566 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400))); 566 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
567 567
568 scoped_ptr<Layer> child1(CreateTextureLayer(gfx::Rect(50, 50, 100, 100))); 568 scoped_ptr<Layer> child1(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
569 parent->Add(child1.get()); 569 parent->Add(child1.get());
570 570
571 scoped_ptr<Layer> child2(CreateTextureLayer(gfx::Rect(75, 75, 200, 200))); 571 scoped_ptr<Layer> child2(CreateTextureLayer(gfx::Rect(75, 75, 200, 200)));
572 parent->Add(child2.get()); 572 parent->Add(child2.get());
573 573
574 Draw();
575
574 EXPECT_EQ(gfx::Rect(75, 75, 200, 200), parent->hole_rect()); 576 EXPECT_EQ(gfx::Rect(75, 75, 200, 200), parent->hole_rect());
575 } 577 }
576 578
579 // Verifies that the largest hole in the draw order is picked
580 TEST_F(LayerWithNullDelegateTest, HoleGeneratedFromLeaf) {
581 // Layer tree looks like:
582 // node 1
583 // |_ node 11
584 // |_ node 111
585 // |_ node 12
586 // |_ node 121
587
588 scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
589
590 scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
591 node1->Add(node11.get());
592
593 scoped_ptr<Layer> node12(CreateTextureLayer(gfx::Rect(75, 75, 200, 200)));
594 node1->Add(node12.get());
595
596 scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
597 node11->Add(node111.get());
598
599 scoped_ptr<Layer> node121(CreateTextureLayer(gfx::Rect(10, 10, 190, 190)));
600 node12->Add(node121.get());
601
602 Draw();
603
604 EXPECT_EQ(gfx::Rect(75, 75, 200, 200), node1->hole_rect());
605 EXPECT_EQ(gfx::Rect(25, 25, 75, 75), node11->hole_rect());
606 EXPECT_EQ(gfx::Rect(10, 10, 190, 190), node12->hole_rect());
607 }
608
609 // Verifies that a hole can only punched into a layer with opacity = 1.0f.
610 TEST_F(LayerWithNullDelegateTest, NoHoleWhenPartialOpacity) {
611 // Layer tree looks like:
612 // node 1
613 // |_ node 11
614 // |_ node 111
615
616 scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
617
618 scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
619 node1->Add(node11.get());
620
621 scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
622 node11->Add(node111.get());
623
624 Draw();
625 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), node1->hole_rect());
626 EXPECT_EQ(gfx::Rect(10, 10, 20, 20), node11->hole_rect());
627
628
629 node11->SetOpacity(0.5f);
630 Draw();
631 EXPECT_TRUE(node1->hole_rect().IsEmpty());
632 EXPECT_TRUE(node11->hole_rect().IsEmpty());
633 }
634
635 // Verifies that a non visible layer or any of its children is not a hole.
636 TEST_F(LayerWithNullDelegateTest, NonVisibleLayerCannotBeHole) {
637 // Layer tree looks like:
638 // node 1
639 // |_ node 11
640 // |_ node 111
641
642 scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
643
644 scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
645 node1->Add(node11.get());
646
647 scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
648 node11->Add(node111.get());
649
650 Draw();
651 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), node1->hole_rect());
652 EXPECT_EQ(gfx::Rect(10, 10, 20, 20), node11->hole_rect());
653
654
655 node11->SetVisible(false);
656 Draw();
657 EXPECT_TRUE(node1->hole_rect().IsEmpty());
658 EXPECT_TRUE(node11->hole_rect().IsEmpty());
659 }
660
661 // Verifies that a layer which doesn't fill its bounds opaquely cannot punch a
662 // hole. However its children should still be able to punch a hole.
663 TEST_F(LayerWithNullDelegateTest, LayerNotFillingBoundsOpaquelyCannotBeHole) {
664 // Layer tree looks like:
665 // node 1
666 // |_ node 11
667 // |_ node 111
668
669 scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
670
671 scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
672 node1->Add(node11.get());
673
674 scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
675 node11->Add(node111.get());
676
677 Draw();
678 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), node1->hole_rect());
679 EXPECT_EQ(gfx::Rect(10, 10, 20, 20), node11->hole_rect());
680
681
682 node11->SetFillsBoundsOpaquely(false);
683 Draw();
684 EXPECT_EQ(gfx::Rect(60, 60, 20, 20), node1->hole_rect());
685 EXPECT_TRUE(node11->hole_rect().IsEmpty());
686 }
687
577 // Verifies that the hole is with respect to the local bounds of its parent. 688 // Verifies that the hole is with respect to the local bounds of its parent.
578 TEST_F(LayerWithNullDelegateTest, HoleLocalBounds) { 689 TEST_F(LayerWithNullDelegateTest, HoleLocalBounds) {
579 scoped_ptr<Layer> parent(CreateTextureRootLayer( 690 scoped_ptr<Layer> parent(CreateTextureRootLayer(
580 gfx::Rect(100, 100, 150, 150))); 691 gfx::Rect(100, 100, 150, 150)));
581 692
582 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100))); 693 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
583 parent->Add(child.get()); 694 parent->Add(child.get());
584 695
696 Draw();
697
585 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), parent->hole_rect()); 698 EXPECT_EQ(gfx::Rect(50, 50, 100, 100), parent->hole_rect());
586 } 699 }
587 700
588 // Verifies that there is no hole present when one of the child layers has a 701 // Verifies that there is no hole present when one of the child layers has a
589 // transform. 702 // transform.
590 TEST_F(LayerWithNullDelegateTest, NoHoleWithTransform) { 703 TEST_F(LayerWithNullDelegateTest, NoHoleWithTransform) {
591 scoped_ptr<Layer> parent(CreateTextureLayer(gfx::Rect(0, 0, 400, 400))); 704 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
592 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100))); 705 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
593 parent->Add(child.get()); 706 parent->Add(child.get());
594 707
708 Draw();
709
595 EXPECT_TRUE(!parent->hole_rect().IsEmpty()); 710 EXPECT_TRUE(!parent->hole_rect().IsEmpty());
596 711
597 ui::Transform t; 712 ui::Transform t;
598 t.SetTranslate(-50, -50); 713 t.SetTranslate(-50, -50);
599 t.ConcatRotate(45.0f); 714 t.ConcatRotate(45.0f);
600 t.ConcatTranslate(50, 50); 715 t.ConcatTranslate(50, 50);
601 child->SetTransform(t); 716 child->SetTransform(t);
602 717
718 Draw();
719
603 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), parent->hole_rect()); 720 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), parent->hole_rect());
604 } 721 }
605 722
606 // Verifies that if the child layer is rotated by a multiple of ninety degrees 723 // Verifies that if the child layer is rotated by a multiple of ninety degrees
607 // we punch a hole 724 // we punch a hole
608 TEST_F(LayerWithNullDelegateTest, HoleWithNinetyDegreeTransforms) { 725 TEST_F(LayerWithNullDelegateTest, HoleWithNinetyDegreeTransforms) {
609 scoped_ptr<Layer> parent(CreateTextureLayer(gfx::Rect(0, 0, 400, 400))); 726 scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
610 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 50, 50))); 727 scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 50, 50)));
611 parent->Add(child.get()); 728 parent->Add(child.get());
612 729
730 Draw();
731
613 EXPECT_TRUE(!parent->hole_rect().IsEmpty()); 732 EXPECT_TRUE(!parent->hole_rect().IsEmpty());
614 733
615 for (int i = -4; i <= 4; ++i) { 734 for (int i = -4; i <= 4; ++i) {
616 SCOPED_TRACE(::testing::Message() << "Iteration " << i); 735 SCOPED_TRACE(::testing::Message() << "Iteration " << i);
617 736
618 ui::Transform t; 737 ui::Transform t;
619 // Need to rotate in local coordinates. 738 // Need to rotate in local coordinates.
620 t.SetTranslate(-25, -25); 739 t.SetTranslate(-25, -25);
621 t.ConcatRotate(90.0f * i); 740 t.ConcatRotate(90.0f * i);
622 t.ConcatTranslate(25, 25); 741 t.ConcatTranslate(25, 25);
623 child->SetTransform(t); 742 child->SetTransform(t);
624 743
625 gfx::Rect target_rect(child->bounds().size()); 744 gfx::Rect target_rect(child->bounds().size());
626 t.ConcatTranslate(child->bounds().x(), child->bounds().y()); 745 t.ConcatTranslate(child->bounds().x(), child->bounds().y());
627 t.TransformRect(&target_rect); 746 t.TransformRect(&target_rect);
628 747
748 Draw();
749
629 EXPECT_EQ(target_rect, parent->hole_rect()); 750 EXPECT_EQ(target_rect, parent->hole_rect());
630 } 751 }
631 } 752 }
632 753
754 // Verifies that a layer which doesn't have a texture cannot punch a
755 // hole. However its children should still be able to punch a hole.
756 TEST_F(LayerWithNullDelegateTest, HoleWithRelativeNinetyDegreeTransforms) {
757 // Layer tree looks like:
758 // node 1
759 // |_ node 11
760 // |_ node 12
761
762 scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
763
764 scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 50, 50)));
765 node1->Add(node11.get());
766
767 scoped_ptr<Layer> node12(CreateTextureLayer(gfx::Rect(50, 50, 50, 50)));
768 node1->Add(node12.get());
769
770 Draw();
771
772 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), node11->hole_rect());
773 EXPECT_TRUE(node12->hole_rect().IsEmpty());
774
775 ui::Transform t1;
776 // Need to rotate in local coordinates.
777 t1.SetTranslate(-25, -25);
778 t1.ConcatRotate(45.0f);
779 t1.ConcatTranslate(25, 25);
780 node11->SetTransform(t1);
781
782 Draw();
783
784 EXPECT_TRUE(node12->hole_rect().IsEmpty());
785 EXPECT_TRUE(node11->hole_rect().IsEmpty());
786
787 ui::Transform t2;
788 // Need to rotate in local coordinates.
789 t2.SetTranslate(-25, -25);
790 t2.ConcatRotate(-135.0f);
791 t2.ConcatTranslate(25, 25);
792 node12->SetTransform(t2);
793
794 // Do translation of target rect in order to account for inprecision of
795 // using floating point matrices vs integer rects.
796 ui::Transform t3;
797 gfx::Rect target_rect = gfx::Rect(node11->bounds().size());
798 t3.ConcatTransform(t2);
799 t1.GetInverse(&t1);
800 t3.ConcatTransform(t1);
801 t3.TransformRect(&target_rect);
802
803 Draw();
804
805 EXPECT_TRUE(node12->hole_rect().IsEmpty());
806 EXPECT_EQ(target_rect, node11->hole_rect());
807 }
808
633 // Create this hierarchy: 809 // Create this hierarchy:
634 // L1 (no texture) 810 // L1 (no texture)
635 // +- L11 (texture) 811 // +- L11 (texture)
636 // +- L12 (no texture) (added after L1 is already set as root-layer) 812 // +- L12 (no texture) (added after L1 is already set as root-layer)
637 // +- L121 (texture) 813 // +- L121 (texture)
638 // +- L122 (texture) 814 // +- L122 (texture)
639 TEST_F(LayerWithNullDelegateTest, 815 TEST_F(LayerWithNullDelegateTest,
640 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(NoCompositor)) { 816 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(NoCompositor)) {
641 scoped_ptr<Layer> l1(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE)); 817 scoped_ptr<Layer> l1(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE));
642 scoped_ptr<Layer> l11(CreateLayer(Layer::LAYER_HAS_TEXTURE)); 818 scoped_ptr<Layer> l11(CreateLayer(Layer::LAYER_HAS_TEXTURE));
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 SkAutoLockPixels lock(bitmap); 974 SkAutoLockPixels lock(bitmap);
799 bool is_all_red = true; 975 bool is_all_red = true;
800 for (int x = 0; is_all_red && x < 500; x++) 976 for (int x = 0; is_all_red && x < 500; x++)
801 for (int y = 0; is_all_red && y < 500; y++) 977 for (int y = 0; is_all_red && y < 500; y++)
802 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED); 978 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED);
803 979
804 EXPECT_TRUE(is_all_red); 980 EXPECT_TRUE(is_all_red);
805 } 981 }
806 982
807 } // namespace ui 983 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/layer.cc ('k') | views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698