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

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

Powered by Google App Engine
This is Rietveld 408576698