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

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

Issue 497493004: cc: Stop testing occlusion by making awkward queries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unoccluded: replicaqueries Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « cc/test/test_occlusion_tracker.h ('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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/occlusion_tracker.h" 5 #include "cc/trees/occlusion_tracker.h"
6 6
7 #include "cc/animation/layer_animation_controller.h" 7 #include "cc/animation/layer_animation_controller.h"
8 #include "cc/base/math_util.h" 8 #include "cc/base/math_util.h"
9 #include "cc/layers/layer.h" 9 #include "cc/layers/layer.h"
10 #include "cc/layers/layer_impl.h" 10 #include "cc/layers/layer_impl.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 // Gives an unoccluded sub-rect of |content_rect| in the content space of the 92 // Gives an unoccluded sub-rect of |content_rect| in the content space of the
93 // layer. Simple wrapper around UnoccludedContentRect. 93 // layer. Simple wrapper around UnoccludedContentRect.
94 gfx::Rect UnoccludedLayerContentRect(const LayerType* layer, 94 gfx::Rect UnoccludedLayerContentRect(const LayerType* layer,
95 const gfx::Rect& content_rect) const { 95 const gfx::Rect& content_rect) const {
96 DCHECK(layer->visible_content_rect().Contains(content_rect)); 96 DCHECK(layer->visible_content_rect().Contains(content_rect));
97 return this->UnoccludedContentRect(content_rect, layer->draw_transform()); 97 return this->UnoccludedContentRect(content_rect, layer->draw_transform());
98 } 98 }
99 99
100 gfx::Rect UnoccludedSurfaceContentRect(const LayerType* layer, 100 gfx::Rect UnoccludedSurfaceContentRect(const LayerType* layer,
101 bool for_replica,
102 const gfx::Rect& content_rect) const { 101 const gfx::Rect& content_rect) const {
103 typename LayerType::RenderSurfaceType* surface = layer->render_surface(); 102 typename LayerType::RenderSurfaceType* surface = layer->render_surface();
104 gfx::Transform draw_transform = for_replica 103 return this->UnoccludedContributingSurfaceContentRect(
105 ? surface->replica_draw_transform() 104 content_rect, surface->draw_transform());
106 : surface->draw_transform();
107 return this->UnoccludedContributingSurfaceContentRect(content_rect,
108 draw_transform);
109 } 105 }
110 }; 106 };
111 107
112 struct OcclusionTrackerTestMainThreadTypes { 108 struct OcclusionTrackerTestMainThreadTypes {
113 typedef Layer LayerType; 109 typedef Layer LayerType;
114 typedef FakeLayerTreeHost HostType; 110 typedef FakeLayerTreeHost HostType;
115 typedef RenderSurface RenderSurfaceType; 111 typedef RenderSurface RenderSurfaceType;
116 typedef TestContentLayer ContentLayerType; 112 typedef TestContentLayer ContentLayerType;
117 typedef scoped_refptr<Layer> LayerPtrType; 113 typedef scoped_refptr<Layer> LayerPtrType;
118 typedef scoped_refptr<ContentLayerType> ContentLayerPtrType; 114 typedef scoped_refptr<ContentLayerType> ContentLayerPtrType;
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion( 538 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
543 gfx::Rect(0, 0, 1000, 1000)); 539 gfx::Rect(0, 0, 1000, 1000));
544 540
545 this->VisitLayer(layer, &occlusion); 541 this->VisitLayer(layer, &occlusion);
546 this->EnterLayer(parent, &occlusion); 542 this->EnterLayer(parent, &occlusion);
547 543
548 EXPECT_EQ(gfx::Rect().ToString(), 544 EXPECT_EQ(gfx::Rect().ToString(),
549 occlusion.occlusion_from_outside_target().ToString()); 545 occlusion.occlusion_from_outside_target().ToString());
550 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), 546 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
551 occlusion.occlusion_from_inside_target().ToString()); 547 occlusion.occlusion_from_inside_target().ToString());
552
553 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
554 parent, gfx::Rect(30, 30, 70, 70)).IsEmpty());
555 EXPECT_EQ(gfx::Rect(29, 30, 1, 70),
556 occlusion.UnoccludedLayerContentRect(parent,
557 gfx::Rect(29, 30, 70, 70)));
558 EXPECT_EQ(gfx::Rect(29, 29, 70, 70),
559 occlusion.UnoccludedLayerContentRect(parent,
560 gfx::Rect(29, 29, 70, 70)));
561 EXPECT_EQ(gfx::Rect(30, 29, 70, 1),
562 occlusion.UnoccludedLayerContentRect(parent,
563 gfx::Rect(30, 29, 70, 70)));
564 EXPECT_EQ(gfx::Rect(31, 29, 69, 1),
565 occlusion.UnoccludedLayerContentRect(parent,
566 gfx::Rect(31, 29, 69, 70)));
567 EXPECT_EQ(gfx::Rect(),
568 occlusion.UnoccludedLayerContentRect(parent,
569 gfx::Rect(31, 30, 69, 70)));
570 EXPECT_EQ(gfx::Rect(),
571 occlusion.UnoccludedLayerContentRect(parent,
572 gfx::Rect(31, 31, 69, 69)));
573 EXPECT_EQ(gfx::Rect(),
574 occlusion.UnoccludedLayerContentRect(parent,
575 gfx::Rect(30, 31, 70, 69)));
576 EXPECT_EQ(gfx::Rect(29, 31, 1, 69),
577 occlusion.UnoccludedLayerContentRect(parent,
578 gfx::Rect(29, 31, 70, 69)));
579 } 548 }
580 }; 549 };
581 550
582 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms); 551 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestIdentityTransforms);
583 552
584 template <class Types> 553 template <class Types>
585 class OcclusionTrackerTestQuadsMismatchLayer
586 : public OcclusionTrackerTest<Types> {
587 protected:
588 explicit OcclusionTrackerTestQuadsMismatchLayer(bool opaque_layers)
589 : OcclusionTrackerTest<Types>(opaque_layers) {}
590 void RunMyTest() {
591 gfx::Transform layer_transform;
592 layer_transform.Translate(10.0, 10.0);
593
594 typename Types::ContentLayerType* parent = this->CreateRoot(
595 this->identity_matrix, gfx::Point(0, 0), gfx::Size(100, 100));
596 typename Types::ContentLayerType* layer1 = this->CreateDrawingLayer(
597 parent, layer_transform, gfx::PointF(), gfx::Size(90, 90), true);
598 typename Types::ContentLayerType* layer2 = this->CreateDrawingLayer(
599 layer1, layer_transform, gfx::PointF(), gfx::Size(50, 50), true);
600 this->CalcDrawEtc(parent);
601
602 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
603 gfx::Rect(0, 0, 1000, 1000));
604
605 this->VisitLayer(layer2, &occlusion);
606 this->EnterLayer(layer1, &occlusion);
607
608 EXPECT_EQ(gfx::Rect().ToString(),
609 occlusion.occlusion_from_outside_target().ToString());
610 EXPECT_EQ(gfx::Rect(20, 20, 50, 50).ToString(),
611 occlusion.occlusion_from_inside_target().ToString());
612
613 // This checks cases where the quads don't match their "containing"
614 // layers, e.g. in terms of transforms or clip rect. This is typical for
615 // DelegatedRendererLayer.
616
617 gfx::Transform quad_transform;
618 quad_transform.Translate(30.0, 30.0);
619
620 EXPECT_TRUE(occlusion.UnoccludedContentRect(gfx::Rect(0, 0, 10, 10),
621 quad_transform).IsEmpty());
622 EXPECT_EQ(gfx::Rect(40, 40, 10, 10),
623 occlusion.UnoccludedContentRect(gfx::Rect(40, 40, 10, 10),
624 quad_transform));
625 EXPECT_EQ(gfx::Rect(40, 30, 5, 10),
626 occlusion.UnoccludedContentRect(gfx::Rect(35, 30, 10, 10),
627 quad_transform));
628 }
629 };
630
631 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestQuadsMismatchLayer);
632
633 template <class Types>
634 class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest<Types> { 554 class OcclusionTrackerTestRotatedChild : public OcclusionTrackerTest<Types> {
635 protected: 555 protected:
636 explicit OcclusionTrackerTestRotatedChild(bool opaque_layers) 556 explicit OcclusionTrackerTestRotatedChild(bool opaque_layers)
637 : OcclusionTrackerTest<Types>(opaque_layers) {} 557 : OcclusionTrackerTest<Types>(opaque_layers) {}
638 void RunMyTest() { 558 void RunMyTest() {
639 gfx::Transform layer_transform; 559 gfx::Transform layer_transform;
640 layer_transform.Translate(250.0, 250.0); 560 layer_transform.Translate(250.0, 250.0);
641 layer_transform.Rotate(90.0); 561 layer_transform.Rotate(90.0);
642 layer_transform.Translate(-250.0, -250.0); 562 layer_transform.Translate(-250.0, -250.0);
643 563
(...skipping 13 matching lines...) Expand all
657 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion( 577 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
658 gfx::Rect(0, 0, 1000, 1000)); 578 gfx::Rect(0, 0, 1000, 1000));
659 579
660 this->VisitLayer(layer, &occlusion); 580 this->VisitLayer(layer, &occlusion);
661 this->EnterLayer(parent, &occlusion); 581 this->EnterLayer(parent, &occlusion);
662 582
663 EXPECT_EQ(gfx::Rect().ToString(), 583 EXPECT_EQ(gfx::Rect().ToString(),
664 occlusion.occlusion_from_outside_target().ToString()); 584 occlusion.occlusion_from_outside_target().ToString());
665 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(), 585 EXPECT_EQ(gfx::Rect(30, 30, 70, 70).ToString(),
666 occlusion.occlusion_from_inside_target().ToString()); 586 occlusion.occlusion_from_inside_target().ToString());
667
668 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
669 parent, gfx::Rect(30, 30, 70, 70)).IsEmpty());
670 EXPECT_EQ(gfx::Rect(29, 30, 1, 70),
671 occlusion.UnoccludedLayerContentRect(parent,
672 gfx::Rect(29, 30, 69, 70)));
673 EXPECT_EQ(gfx::Rect(29, 29, 70, 70),
674 occlusion.UnoccludedLayerContentRect(parent,
675 gfx::Rect(29, 29, 70, 70)));
676 EXPECT_EQ(gfx::Rect(30, 29, 70, 1),
677 occlusion.UnoccludedLayerContentRect(parent,
678 gfx::Rect(30, 29, 70, 70)));
679 EXPECT_EQ(gfx::Rect(31, 29, 69, 1),
680 occlusion.UnoccludedLayerContentRect(parent,
681 gfx::Rect(31, 29, 69, 70)));
682 EXPECT_EQ(gfx::Rect(),
683 occlusion.UnoccludedLayerContentRect(parent,
684 gfx::Rect(31, 30, 69, 70)));
685 EXPECT_EQ(gfx::Rect(),
686 occlusion.UnoccludedLayerContentRect(parent,
687 gfx::Rect(31, 31, 69, 69)));
688 EXPECT_EQ(gfx::Rect(),
689 occlusion.UnoccludedLayerContentRect(parent,
690 gfx::Rect(30, 31, 70, 69)));
691 EXPECT_EQ(gfx::Rect(29, 31, 1, 69),
692 occlusion.UnoccludedLayerContentRect(parent,
693 gfx::Rect(29, 31, 70, 69)));
694 } 587 }
695 }; 588 };
696 589
697 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild); 590 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestRotatedChild);
698 591
699 template <class Types> 592 template <class Types>
700 class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest<Types> { 593 class OcclusionTrackerTestTranslatedChild : public OcclusionTrackerTest<Types> {
701 protected: 594 protected:
702 explicit OcclusionTrackerTestTranslatedChild(bool opaque_layers) 595 explicit OcclusionTrackerTestTranslatedChild(bool opaque_layers)
703 : OcclusionTrackerTest<Types>(opaque_layers) {} 596 : OcclusionTrackerTest<Types>(opaque_layers) {}
(...skipping 17 matching lines...) Expand all
721 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion( 614 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
722 gfx::Rect(0, 0, 1000, 1000)); 615 gfx::Rect(0, 0, 1000, 1000));
723 616
724 this->VisitLayer(layer, &occlusion); 617 this->VisitLayer(layer, &occlusion);
725 this->EnterLayer(parent, &occlusion); 618 this->EnterLayer(parent, &occlusion);
726 619
727 EXPECT_EQ(gfx::Rect().ToString(), 620 EXPECT_EQ(gfx::Rect().ToString(),
728 occlusion.occlusion_from_outside_target().ToString()); 621 occlusion.occlusion_from_outside_target().ToString());
729 EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(), 622 EXPECT_EQ(gfx::Rect(50, 50, 50, 50).ToString(),
730 occlusion.occlusion_from_inside_target().ToString()); 623 occlusion.occlusion_from_inside_target().ToString());
731
732 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
733 parent, gfx::Rect(50, 50, 50, 50)).IsEmpty());
734 EXPECT_EQ(gfx::Rect(49, 50, 1, 50),
735 occlusion.UnoccludedLayerContentRect(parent,
736 gfx::Rect(49, 50, 50, 50)));
737 EXPECT_EQ(gfx::Rect(49, 49, 50, 50),
738 occlusion.UnoccludedLayerContentRect(parent,
739 gfx::Rect(49, 49, 50, 50)));
740 EXPECT_EQ(gfx::Rect(50, 49, 50, 1),
741 occlusion.UnoccludedLayerContentRect(parent,
742 gfx::Rect(50, 49, 50, 50)));
743 EXPECT_EQ(gfx::Rect(51, 49, 49, 1),
744 occlusion.UnoccludedLayerContentRect(parent,
745 gfx::Rect(51, 49, 49, 50)));
746 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
747 parent, gfx::Rect(51, 50, 49, 50)).IsEmpty());
748 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
749 parent, gfx::Rect(51, 51, 49, 49)).IsEmpty());
750 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
751 parent, gfx::Rect(50, 51, 50, 49)).IsEmpty());
752 EXPECT_EQ(gfx::Rect(49, 51, 1, 49),
753 occlusion.UnoccludedLayerContentRect(parent,
754 gfx::Rect(49, 51, 50, 49)));
755 } 624 }
756 }; 625 };
757 626
758 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild); 627 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestTranslatedChild);
759 628
760 template <class Types> 629 template <class Types>
761 class OcclusionTrackerTestChildInRotatedChild 630 class OcclusionTrackerTestChildInRotatedChild
762 : public OcclusionTrackerTest<Types> { 631 : public OcclusionTrackerTest<Types> {
763 protected: 632 protected:
764 explicit OcclusionTrackerTestChildInRotatedChild(bool opaque_layers) 633 explicit OcclusionTrackerTestChildInRotatedChild(bool opaque_layers)
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion( 755 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
887 gfx::Rect(0, 0, 1000, 1000)); 756 gfx::Rect(0, 0, 1000, 1000));
888 757
889 this->VisitLayer(occluder, &occlusion); 758 this->VisitLayer(occluder, &occlusion);
890 this->EnterLayer(layer2, &occlusion); 759 this->EnterLayer(layer2, &occlusion);
891 760
892 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(), 761 EXPECT_EQ(gfx::Rect(100, 100, 100, 100).ToString(),
893 occlusion.occlusion_from_outside_target().ToString()); 762 occlusion.occlusion_from_outside_target().ToString());
894 EXPECT_EQ(gfx::Rect().ToString(), 763 EXPECT_EQ(gfx::Rect().ToString(),
895 occlusion.occlusion_from_inside_target().ToString()); 764 occlusion.occlusion_from_inside_target().ToString());
896
897 EXPECT_EQ(
898 gfx::Rect(0, 0, 25, 25),
899 occlusion.UnoccludedLayerContentRect(layer2, gfx::Rect(0, 0, 25, 25)));
900 EXPECT_EQ(gfx::Rect(10, 25, 15, 25),
901 occlusion.UnoccludedLayerContentRect(layer2,
902 gfx::Rect(10, 25, 25, 25)));
903 EXPECT_EQ(gfx::Rect(25, 10, 25, 15),
904 occlusion.UnoccludedLayerContentRect(layer2,
905 gfx::Rect(25, 10, 25, 25)));
906 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
907 layer2, gfx::Rect(25, 25, 25, 25)).IsEmpty());
908 } 765 }
909 }; 766 };
910 767
911 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface); 768 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestScaledRenderSurface);
912 769
913 template <class Types> 770 template <class Types>
914 class OcclusionTrackerTestVisitTargetTwoTimes 771 class OcclusionTrackerTestVisitTargetTwoTimes
915 : public OcclusionTrackerTest<Types> { 772 : public OcclusionTrackerTest<Types> {
916 protected: 773 protected:
917 explicit OcclusionTrackerTestVisitTargetTwoTimes(bool opaque_layers) 774 explicit OcclusionTrackerTestVisitTargetTwoTimes(bool opaque_layers)
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 EXPECT_EQ(clipped_layer_in_child.ToString(), 873 EXPECT_EQ(clipped_layer_in_child.ToString(),
1017 occlusion.occlusion_from_inside_target().ToString()); 874 occlusion.occlusion_from_inside_target().ToString());
1018 875
1019 this->LeaveContributingSurface(child, &occlusion); 876 this->LeaveContributingSurface(child, &occlusion);
1020 this->EnterLayer(parent, &occlusion); 877 this->EnterLayer(parent, &occlusion);
1021 878
1022 EXPECT_EQ(gfx::Rect().ToString(), 879 EXPECT_EQ(gfx::Rect().ToString(),
1023 occlusion.occlusion_from_outside_target().ToString()); 880 occlusion.occlusion_from_outside_target().ToString());
1024 EXPECT_EQ(gfx::Rect().ToString(), 881 EXPECT_EQ(gfx::Rect().ToString(),
1025 occlusion.occlusion_from_inside_target().ToString()); 882 occlusion.occlusion_from_inside_target().ToString());
1026
1027 EXPECT_EQ(
1028 gfx::Rect(75, 55, 1, 1),
1029 occlusion.UnoccludedLayerContentRect(parent, gfx::Rect(75, 55, 1, 1)));
1030 } 883 }
1031 }; 884 };
1032 885
1033 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis); 886 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceRotatedOffAxis);
1034 887
1035 template <class Types> 888 template <class Types>
1036 class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren 889 class OcclusionTrackerTestSurfaceWithTwoOpaqueChildren
1037 : public OcclusionTrackerTest<Types> { 890 : public OcclusionTrackerTest<Types> {
1038 protected: 891 protected:
1039 explicit OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaque_layers) 892 explicit OcclusionTrackerTestSurfaceWithTwoOpaqueChildren(bool opaque_layers)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 this->VisitLayer(layer2, &occlusion); 929 this->VisitLayer(layer2, &occlusion);
1077 this->VisitLayer(layer1, &occlusion); 930 this->VisitLayer(layer1, &occlusion);
1078 this->VisitLayer(child, &occlusion); 931 this->VisitLayer(child, &occlusion);
1079 this->EnterContributingSurface(child, &occlusion); 932 this->EnterContributingSurface(child, &occlusion);
1080 933
1081 EXPECT_EQ(gfx::Rect().ToString(), 934 EXPECT_EQ(gfx::Rect().ToString(),
1082 occlusion.occlusion_from_outside_target().ToString()); 935 occlusion.occlusion_from_outside_target().ToString());
1083 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(), 936 EXPECT_EQ(gfx::Rect(10, 430, 60, 70).ToString(),
1084 occlusion.occlusion_from_inside_target().ToString()); 937 occlusion.occlusion_from_inside_target().ToString());
1085 938
1086 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1087 child, gfx::Rect(10, 430, 60, 70)).IsEmpty());
1088 EXPECT_EQ(
1089 gfx::Rect(9, 430, 1, 70),
1090 occlusion.UnoccludedLayerContentRect(child, gfx::Rect(9, 430, 60, 70)));
1091 EXPECT_EQ(gfx::Rect(),
1092 occlusion.UnoccludedLayerContentRect(child,
1093 gfx::Rect(11, 430, 59, 70)));
1094 EXPECT_EQ(gfx::Rect(),
1095 occlusion.UnoccludedLayerContentRect(child,
1096 gfx::Rect(10, 431, 60, 69)));
1097
1098 this->LeaveContributingSurface(child, &occlusion); 939 this->LeaveContributingSurface(child, &occlusion);
1099 this->EnterLayer(parent, &occlusion); 940 this->EnterLayer(parent, &occlusion);
1100 941
1101 EXPECT_EQ(gfx::Rect().ToString(), 942 EXPECT_EQ(gfx::Rect().ToString(),
1102 occlusion.occlusion_from_outside_target().ToString()); 943 occlusion.occlusion_from_outside_target().ToString());
1103 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(), 944 EXPECT_EQ(gfx::Rect(30, 40, 70, 60).ToString(),
1104 occlusion.occlusion_from_inside_target().ToString()); 945 occlusion.occlusion_from_inside_target().ToString());
1105 946
1106 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1107 parent, gfx::Rect(30, 40, 70, 60)).IsEmpty());
1108 EXPECT_EQ(gfx::Rect(29, 40, 1, 60),
1109 occlusion.UnoccludedLayerContentRect(parent,
1110 gfx::Rect(29, 40, 70, 60)));
1111 EXPECT_EQ(gfx::Rect(30, 39, 70, 1),
1112 occlusion.UnoccludedLayerContentRect(parent,
1113 gfx::Rect(30, 39, 70, 60)));
1114 EXPECT_EQ(gfx::Rect(),
1115 occlusion.UnoccludedLayerContentRect(parent,
1116 gfx::Rect(31, 40, 69, 60)));
1117 EXPECT_EQ(gfx::Rect(),
1118 occlusion.UnoccludedLayerContentRect(parent,
1119 gfx::Rect(30, 41, 70, 59)));
1120
1121 /* Justification for the above occlusion from |layer1| and |layer2|: 947 /* Justification for the above occlusion from |layer1| and |layer2|:
1122 948
1123 +---------------------+ 949 +---------------------+
1124 | |30 Visible region of |layer1|: ///// 950 | |30 Visible region of |layer1|: /////
1125 | | Visible region of |layer2|: \\\\\ 951 | | Visible region of |layer2|: \\\\\
1126 | +---------------------------------+ 952 | +---------------------------------+
1127 | | |10 | 953 | | |10 |
1128 | +---------------+-----------------+ | 954 | +---------------+-----------------+ |
1129 | | |\\\\\\\\\\\\|//| 420 | | 955 | | |\\\\\\\\\\\\|//| 420 | |
1130 | | |\\\\\\\\\\\\|//|60 | | 956 | | |\\\\\\\\\\\\|//|60 | |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 this->EnterLayer(child2, &occlusion); 1082 this->EnterLayer(child2, &occlusion);
1257 1083
1258 EXPECT_EQ(gfx::Rect().ToString(), 1084 EXPECT_EQ(gfx::Rect().ToString(),
1259 occlusion.occlusion_from_outside_target().ToString()); 1085 occlusion.occlusion_from_outside_target().ToString());
1260 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(), 1086 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
1261 occlusion.occlusion_from_inside_target().ToString()); 1087 occlusion.occlusion_from_inside_target().ToString());
1262 1088
1263 this->LeaveLayer(child2, &occlusion); 1089 this->LeaveLayer(child2, &occlusion);
1264 this->EnterContributingSurface(child2, &occlusion); 1090 this->EnterContributingSurface(child2, &occlusion);
1265 1091
1266 // There is nothing above child2's surface in the z-order. 1092 EXPECT_EQ(gfx::Rect().ToString(),
1267 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80), 1093 occlusion.occlusion_from_outside_target().ToString());
1268 occlusion.UnoccludedSurfaceContentRect( 1094 EXPECT_EQ(gfx::Rect(-10, 420, 70, 80).ToString(),
1269 child2, false, gfx::Rect(-10, 420, 70, 80))); 1095 occlusion.occlusion_from_inside_target().ToString());
1270 1096
1271 this->LeaveContributingSurface(child2, &occlusion); 1097 this->LeaveContributingSurface(child2, &occlusion);
1272 this->VisitLayer(layer1, &occlusion); 1098 this->VisitLayer(layer1, &occlusion);
1273 this->EnterContributingSurface(child1, &occlusion); 1099 this->EnterContributingSurface(child1, &occlusion);
1274 1100
1275 EXPECT_EQ(gfx::Rect(420, -10, 70, 80).ToString(), 1101 EXPECT_EQ(gfx::Rect(420, -10, 70, 80).ToString(),
1276 occlusion.occlusion_from_outside_target().ToString()); 1102 occlusion.occlusion_from_outside_target().ToString());
1277 EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(), 1103 EXPECT_EQ(gfx::Rect(420, -20, 80, 90).ToString(),
1278 occlusion.occlusion_from_inside_target().ToString()); 1104 occlusion.occlusion_from_inside_target().ToString());
1279 1105
1280 // child2's contents will occlude child1 below it.
1281 EXPECT_EQ(gfx::Rect(20, 30, 80, 70).ToString(),
1282 occlusion.occlusion_on_contributing_surface_from_inside_target()
1283 .ToString());
1284 EXPECT_EQ(gfx::Rect().ToString(),
1285 occlusion.occlusion_on_contributing_surface_from_outside_target()
1286 .ToString());
1287
1288 this->LeaveContributingSurface(child1, &occlusion); 1106 this->LeaveContributingSurface(child1, &occlusion);
1289 this->EnterLayer(parent, &occlusion); 1107 this->EnterLayer(parent, &occlusion);
1290 1108
1291 EXPECT_EQ(gfx::Rect().ToString(), 1109 EXPECT_EQ(gfx::Rect().ToString(),
1292 occlusion.occlusion_from_outside_target().ToString()); 1110 occlusion.occlusion_from_outside_target().ToString());
1293 EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(), 1111 EXPECT_EQ(gfx::Rect(10, 20, 90, 80).ToString(),
1294 occlusion.occlusion_from_inside_target().ToString()); 1112 occlusion.occlusion_from_inside_target().ToString());
1295 1113
1296 /* Justification for the above occlusion: 1114 /* Justification for the above occlusion:
1297 100 1115 100
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 1441
1624 EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(), 1442 EXPECT_EQ(gfx::Rect(250, 250, 50, 50).ToString(),
1625 occlusion.occlusion_from_inside_target().ToString()); 1443 occlusion.occlusion_from_inside_target().ToString());
1626 } 1444 }
1627 } 1445 }
1628 }; 1446 };
1629 1447
1630 MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty); 1448 MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTestOpaqueContentsRegionNonEmpty);
1631 1449
1632 template <class Types> 1450 template <class Types>
1633 class OcclusionTrackerTest3dTransform : public OcclusionTrackerTest<Types> {
1634 protected:
1635 explicit OcclusionTrackerTest3dTransform(bool opaque_layers)
1636 : OcclusionTrackerTest<Types>(opaque_layers) {}
1637 void RunMyTest() {
1638 gfx::Transform transform;
1639 transform.RotateAboutYAxis(30.0);
1640
1641 typename Types::ContentLayerType* parent = this->CreateRoot(
1642 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1643 typename Types::LayerType* container = this->CreateLayer(
1644 parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1645 typename Types::ContentLayerType* layer =
1646 this->CreateDrawingLayer(container,
1647 transform,
1648 gfx::PointF(100.f, 100.f),
1649 gfx::Size(200, 200),
1650 true);
1651 this->CalcDrawEtc(parent);
1652
1653 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
1654 gfx::Rect(0, 0, 1000, 1000));
1655 this->EnterLayer(layer, &occlusion);
1656
1657 // The layer is rotated in 3d but without preserving 3d, so it only gets
1658 // resized.
1659 EXPECT_EQ(
1660 gfx::Rect(0, 0, 200, 200),
1661 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 200, 200)));
1662 }
1663 };
1664
1665 MAIN_AND_IMPL_THREAD_TEST(OcclusionTrackerTest3dTransform);
1666
1667 template <class Types>
1668 class OcclusionTrackerTestUnsorted3dLayers 1451 class OcclusionTrackerTestUnsorted3dLayers
1669 : public OcclusionTrackerTest<Types> { 1452 : public OcclusionTrackerTest<Types> {
1670 protected: 1453 protected:
1671 explicit OcclusionTrackerTestUnsorted3dLayers(bool opaque_layers) 1454 explicit OcclusionTrackerTestUnsorted3dLayers(bool opaque_layers)
1672 : OcclusionTrackerTest<Types>(opaque_layers) {} 1455 : OcclusionTrackerTest<Types>(opaque_layers) {}
1673 void RunMyTest() { 1456 void RunMyTest() {
1674 // Currently, The main thread layer iterator does not iterate over 3d items 1457 // Currently, The main thread layer iterator does not iterate over 3d items
1675 // in sorted order, because layer sorting is not performed on the main 1458 // in sorted order, because layer sorting is not performed on the main
1676 // thread. Because of this, the occlusion tracker cannot assume that a 3d 1459 // thread. Because of this, the occlusion tracker cannot assume that a 3d
1677 // layer occludes other layers that have not yet been iterated over. For 1460 // layer occludes other layers that have not yet been iterated over. For
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); 1493 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty());
1711 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); 1494 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty());
1712 } 1495 }
1713 }; 1496 };
1714 1497
1715 // This test will have different layer ordering on the impl thread; the test 1498 // This test will have different layer ordering on the impl thread; the test
1716 // will only work on the main thread. 1499 // will only work on the main thread.
1717 MAIN_THREAD_TEST(OcclusionTrackerTestUnsorted3dLayers); 1500 MAIN_THREAD_TEST(OcclusionTrackerTestUnsorted3dLayers);
1718 1501
1719 template <class Types> 1502 template <class Types>
1720 class OcclusionTrackerTestPerspectiveTransform
1721 : public OcclusionTrackerTest<Types> {
1722 protected:
1723 explicit OcclusionTrackerTestPerspectiveTransform(bool opaque_layers)
1724 : OcclusionTrackerTest<Types>(opaque_layers) {}
1725 void RunMyTest() {
1726 gfx::Transform transform;
1727 transform.Translate(150.0, 150.0);
1728 transform.ApplyPerspectiveDepth(400.0);
1729 transform.RotateAboutXAxis(-30.0);
1730 transform.Translate(-150.0, -150.0);
1731
1732 typename Types::ContentLayerType* parent = this->CreateRoot(
1733 this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1734 typename Types::LayerType* container = this->CreateLayer(
1735 parent, this->identity_matrix, gfx::PointF(), gfx::Size(300, 300));
1736 typename Types::ContentLayerType* layer =
1737 this->CreateDrawingLayer(container,
1738 transform,
1739 gfx::PointF(100.f, 100.f),
1740 gfx::Size(200, 200),
1741 true);
1742 container->SetShouldFlattenTransform(false);
1743 container->Set3dSortingContextId(1);
1744 layer->Set3dSortingContextId(1);
1745 layer->SetShouldFlattenTransform(false);
1746
1747 this->CalcDrawEtc(parent);
1748
1749 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
1750 gfx::Rect(0, 0, 1000, 1000));
1751 this->EnterLayer(layer, &occlusion);
1752
1753 EXPECT_EQ(
1754 gfx::Rect(0, 0, 200, 200),
1755 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 200, 200)));
1756 }
1757 };
1758
1759 // This test requires accumulating occlusion of 3d layers, which are skipped by
1760 // the occlusion tracker on the main thread. So this test should run on the impl
1761 // thread.
1762 IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransform);
1763 template <class Types>
1764 class OcclusionTrackerTestPerspectiveTransformBehindCamera
1765 : public OcclusionTrackerTest<Types> {
1766 protected:
1767 explicit OcclusionTrackerTestPerspectiveTransformBehindCamera(
1768 bool opaque_layers)
1769 : OcclusionTrackerTest<Types>(opaque_layers) {}
1770 void RunMyTest() {
1771 // This test is based on the platform/chromium/compositing/3d-corners.html
1772 // layout test.
1773 gfx::Transform transform;
1774 transform.Translate(250.0, 50.0);
1775 transform.ApplyPerspectiveDepth(10.0);
1776 transform.Translate(-250.0, -50.0);
1777 transform.Translate(250.0, 50.0);
1778 transform.RotateAboutXAxis(-167.0);
1779 transform.Translate(-250.0, -50.0);
1780
1781 typename Types::ContentLayerType* parent = this->CreateRoot(
1782 this->identity_matrix, gfx::PointF(), gfx::Size(500, 100));
1783 typename Types::LayerType* container = this->CreateLayer(
1784 parent, this->identity_matrix, gfx::PointF(), gfx::Size(500, 500));
1785 typename Types::ContentLayerType* layer = this->CreateDrawingLayer(
1786 container, transform, gfx::PointF(), gfx::Size(500, 500), true);
1787 container->SetShouldFlattenTransform(false);
1788 container->Set3dSortingContextId(1);
1789 layer->SetShouldFlattenTransform(false);
1790 layer->Set3dSortingContextId(1);
1791 this->CalcDrawEtc(parent);
1792
1793 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
1794 gfx::Rect(0, 0, 1000, 1000));
1795 this->EnterLayer(layer, &occlusion);
1796
1797 // The bottom 11 pixel rows of this layer remain visible inside the
1798 // container, after translation to the target surface. When translated back,
1799 // this will include many more pixels but must include at least the bottom
1800 // 11 rows.
1801 EXPECT_TRUE(occlusion.UnoccludedLayerContentRect(
1802 layer, gfx::Rect(0, 26, 500, 474)).
1803 Contains(gfx::Rect(0, 489, 500, 11)));
1804 }
1805 };
1806
1807 // This test requires accumulating occlusion of 3d layers, which are skipped by
1808 // the occlusion tracker on the main thread. So this test should run on the impl
1809 // thread.
1810 IMPL_THREAD_TEST(OcclusionTrackerTestPerspectiveTransformBehindCamera);
1811
1812 template <class Types>
1813 class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude 1503 class OcclusionTrackerTestLayerBehindCameraDoesNotOcclude
1814 : public OcclusionTrackerTest<Types> { 1504 : public OcclusionTrackerTest<Types> {
1815 protected: 1505 protected:
1816 explicit OcclusionTrackerTestLayerBehindCameraDoesNotOcclude( 1506 explicit OcclusionTrackerTestLayerBehindCameraDoesNotOcclude(
1817 bool opaque_layers) 1507 bool opaque_layers)
1818 : OcclusionTrackerTest<Types>(opaque_layers) {} 1508 : OcclusionTrackerTest<Types>(opaque_layers) {}
1819 void RunMyTest() { 1509 void RunMyTest() {
1820 gfx::Transform transform; 1510 gfx::Transform transform;
1821 transform.Translate(50.0, 50.0); 1511 transform.Translate(50.0, 50.0);
1822 transform.ApplyPerspectiveDepth(100.0); 1512 transform.ApplyPerspectiveDepth(100.0);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 1646
1957 EXPECT_TRUE(layer->draw_opacity_is_animating()); 1647 EXPECT_TRUE(layer->draw_opacity_is_animating());
1958 EXPECT_FALSE(surface->draw_opacity_is_animating()); 1648 EXPECT_FALSE(surface->draw_opacity_is_animating());
1959 EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating()); 1649 EXPECT_TRUE(surface->render_surface()->draw_opacity_is_animating());
1960 1650
1961 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion( 1651 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
1962 gfx::Rect(0, 0, 1000, 1000)); 1652 gfx::Rect(0, 0, 1000, 1000));
1963 1653
1964 this->VisitLayer(topmost, &occlusion); 1654 this->VisitLayer(topmost, &occlusion);
1965 this->EnterLayer(parent2, &occlusion); 1655 this->EnterLayer(parent2, &occlusion);
1656
1966 // This occlusion will affect all surfaces. 1657 // This occlusion will affect all surfaces.
1658 EXPECT_EQ(gfx::Rect().ToString(),
1659 occlusion.occlusion_from_outside_target().ToString());
1967 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), 1660 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1968 occlusion.occlusion_from_inside_target().ToString()); 1661 occlusion.occlusion_from_inside_target().ToString());
1969 EXPECT_EQ(gfx::Rect().ToString(), 1662
1970 occlusion.occlusion_from_outside_target().ToString());
1971 EXPECT_EQ(gfx::Rect(0, 0, 250, 300).ToString(),
1972 occlusion.UnoccludedLayerContentRect(
1973 parent2, gfx::Rect(0, 0, 300, 300)).ToString());
1974 this->LeaveLayer(parent2, &occlusion); 1663 this->LeaveLayer(parent2, &occlusion);
1975
1976 this->VisitLayer(surface_child2, &occlusion); 1664 this->VisitLayer(surface_child2, &occlusion);
1977 this->EnterLayer(surface_child, &occlusion); 1665 this->EnterLayer(surface_child, &occlusion);
1666 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1667 occlusion.occlusion_from_outside_target().ToString());
1978 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(), 1668 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
1979 occlusion.occlusion_from_inside_target().ToString()); 1669 occlusion.occlusion_from_inside_target().ToString());
1670
1671 this->LeaveLayer(surface_child, &occlusion);
1672 this->EnterLayer(surface, &occlusion);
1980 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), 1673 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
1981 occlusion.occlusion_from_outside_target().ToString()); 1674 occlusion.occlusion_from_outside_target().ToString());
1982 EXPECT_EQ(gfx::Rect(100, 0, 100, 300),
1983 occlusion.UnoccludedLayerContentRect(surface_child,
1984 gfx::Rect(0, 0, 200, 300)));
1985 this->LeaveLayer(surface_child, &occlusion);
1986 this->EnterLayer(surface, &occlusion);
1987 EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(), 1675 EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(),
1988 occlusion.occlusion_from_inside_target().ToString()); 1676 occlusion.occlusion_from_inside_target().ToString());
1989 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), 1677
1990 occlusion.occlusion_from_outside_target().ToString());
1991 EXPECT_EQ(gfx::Rect(200, 0, 50, 300),
1992 occlusion.UnoccludedLayerContentRect(surface,
1993 gfx::Rect(0, 0, 300, 300)));
1994 this->LeaveLayer(surface, &occlusion); 1678 this->LeaveLayer(surface, &occlusion);
1995
1996 this->EnterContributingSurface(surface, &occlusion); 1679 this->EnterContributingSurface(surface, &occlusion);
1997 // Occlusion within the surface is lost when leaving the animating surface. 1680 // Occlusion within the surface is lost when leaving the animating surface.
1998 EXPECT_EQ(gfx::Rect().ToString(), 1681 EXPECT_EQ(gfx::Rect().ToString(),
1682 occlusion.occlusion_from_outside_target().ToString());
1683 EXPECT_EQ(gfx::Rect().ToString(),
1999 occlusion.occlusion_from_inside_target().ToString()); 1684 occlusion.occlusion_from_inside_target().ToString());
2000 EXPECT_EQ(gfx::Rect().ToString(), 1685
2001 occlusion.occlusion_from_outside_target().ToString());
2002 EXPECT_EQ(gfx::Rect(0, 0, 250, 300),
2003 occlusion.UnoccludedSurfaceContentRect(
2004 surface, false, gfx::Rect(0, 0, 300, 300)));
2005 this->LeaveContributingSurface(surface, &occlusion); 1686 this->LeaveContributingSurface(surface, &occlusion);
2006
2007 // Occlusion from outside the animating surface still exists. 1687 // Occlusion from outside the animating surface still exists.
2008 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), 1688 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2009 occlusion.occlusion_from_inside_target().ToString()); 1689 occlusion.occlusion_from_inside_target().ToString());
2010 EXPECT_EQ(gfx::Rect().ToString(), 1690 EXPECT_EQ(gfx::Rect().ToString(),
2011 occlusion.occlusion_from_outside_target().ToString()); 1691 occlusion.occlusion_from_outside_target().ToString());
2012 1692
2013 this->VisitLayer(layer, &occlusion); 1693 this->VisitLayer(layer, &occlusion);
2014 this->EnterLayer(parent, &occlusion); 1694 this->EnterLayer(parent, &occlusion);
2015 1695
2016 // Occlusion is not added for the animating |layer|. 1696 // Occlusion is not added for the animating |layer|.
2017 EXPECT_EQ(gfx::Rect(0, 0, 250, 300), 1697 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2018 occlusion.UnoccludedLayerContentRect(parent, 1698 occlusion.occlusion_from_inside_target().ToString());
2019 gfx::Rect(0, 0, 300, 300))); 1699 EXPECT_EQ(gfx::Rect().ToString(),
1700 occlusion.occlusion_from_outside_target().ToString());
2020 } 1701 }
2021 }; 1702 };
2022 1703
2023 MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity1OnMainThread); 1704 MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity1OnMainThread);
2024 1705
2025 template <class Types> 1706 template <class Types>
2026 class OcclusionTrackerTestAnimationOpacity0OnMainThread 1707 class OcclusionTrackerTestAnimationOpacity0OnMainThread
2027 : public OcclusionTrackerTest<Types> { 1708 : public OcclusionTrackerTest<Types> {
2028 protected: 1709 protected:
2029 explicit OcclusionTrackerTestAnimationOpacity0OnMainThread(bool opaque_layers) 1710 explicit OcclusionTrackerTestAnimationOpacity0OnMainThread(bool opaque_layers)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2081 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion( 1762 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
2082 gfx::Rect(0, 0, 1000, 1000)); 1763 gfx::Rect(0, 0, 1000, 1000));
2083 1764
2084 this->VisitLayer(topmost, &occlusion); 1765 this->VisitLayer(topmost, &occlusion);
2085 this->EnterLayer(parent2, &occlusion); 1766 this->EnterLayer(parent2, &occlusion);
2086 // This occlusion will affect all surfaces. 1767 // This occlusion will affect all surfaces.
2087 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), 1768 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2088 occlusion.occlusion_from_inside_target().ToString()); 1769 occlusion.occlusion_from_inside_target().ToString());
2089 EXPECT_EQ(gfx::Rect().ToString(), 1770 EXPECT_EQ(gfx::Rect().ToString(),
2090 occlusion.occlusion_from_outside_target().ToString()); 1771 occlusion.occlusion_from_outside_target().ToString());
2091 EXPECT_EQ(gfx::Rect(0, 0, 250, 300), 1772
2092 occlusion.UnoccludedLayerContentRect(parent,
2093 gfx::Rect(0, 0, 300, 300)));
2094 this->LeaveLayer(parent2, &occlusion); 1773 this->LeaveLayer(parent2, &occlusion);
2095
2096 this->VisitLayer(surface_child2, &occlusion); 1774 this->VisitLayer(surface_child2, &occlusion);
2097 this->EnterLayer(surface_child, &occlusion); 1775 this->EnterLayer(surface_child, &occlusion);
2098 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(), 1776 EXPECT_EQ(gfx::Rect(0, 0, 100, 300).ToString(),
2099 occlusion.occlusion_from_inside_target().ToString()); 1777 occlusion.occlusion_from_inside_target().ToString());
2100 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), 1778 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2101 occlusion.occlusion_from_outside_target().ToString()); 1779 occlusion.occlusion_from_outside_target().ToString());
2102 EXPECT_EQ(gfx::Rect(100, 0, 100, 300), 1780
2103 occlusion.UnoccludedLayerContentRect(surface_child,
2104 gfx::Rect(0, 0, 200, 300)));
2105 this->LeaveLayer(surface_child, &occlusion); 1781 this->LeaveLayer(surface_child, &occlusion);
2106 this->EnterLayer(surface, &occlusion); 1782 this->EnterLayer(surface, &occlusion);
2107 EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(), 1783 EXPECT_EQ(gfx::Rect(0, 0, 200, 300).ToString(),
2108 occlusion.occlusion_from_inside_target().ToString()); 1784 occlusion.occlusion_from_inside_target().ToString());
2109 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), 1785 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2110 occlusion.occlusion_from_outside_target().ToString()); 1786 occlusion.occlusion_from_outside_target().ToString());
2111 EXPECT_EQ(gfx::Rect(200, 0, 50, 300), 1787
2112 occlusion.UnoccludedLayerContentRect(surface,
2113 gfx::Rect(0, 0, 300, 300)));
2114 this->LeaveLayer(surface, &occlusion); 1788 this->LeaveLayer(surface, &occlusion);
2115
2116 this->EnterContributingSurface(surface, &occlusion); 1789 this->EnterContributingSurface(surface, &occlusion);
2117 // Occlusion within the surface is lost when leaving the animating surface. 1790 // Occlusion within the surface is lost when leaving the animating surface.
2118 EXPECT_EQ(gfx::Rect().ToString(), 1791 EXPECT_EQ(gfx::Rect().ToString(),
2119 occlusion.occlusion_from_inside_target().ToString()); 1792 occlusion.occlusion_from_inside_target().ToString());
2120 EXPECT_EQ(gfx::Rect().ToString(), 1793 EXPECT_EQ(gfx::Rect().ToString(),
2121 occlusion.occlusion_from_outside_target().ToString()); 1794 occlusion.occlusion_from_outside_target().ToString());
2122 EXPECT_EQ(gfx::Rect(0, 0, 250, 300), 1795
2123 occlusion.UnoccludedSurfaceContentRect(
2124 surface, false, gfx::Rect(0, 0, 300, 300)));
2125 this->LeaveContributingSurface(surface, &occlusion); 1796 this->LeaveContributingSurface(surface, &occlusion);
2126
2127 // Occlusion from outside the animating surface still exists. 1797 // Occlusion from outside the animating surface still exists.
2128 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(), 1798 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2129 occlusion.occlusion_from_inside_target().ToString()); 1799 occlusion.occlusion_from_inside_target().ToString());
2130 EXPECT_EQ(gfx::Rect().ToString(), 1800 EXPECT_EQ(gfx::Rect().ToString(),
2131 occlusion.occlusion_from_outside_target().ToString()); 1801 occlusion.occlusion_from_outside_target().ToString());
2132 1802
2133 this->VisitLayer(layer, &occlusion); 1803 this->VisitLayer(layer, &occlusion);
2134 this->EnterLayer(parent, &occlusion); 1804 this->EnterLayer(parent, &occlusion);
2135 1805
2136 // Occlusion is not added for the animating |layer|. 1806 // Occlusion is not added for the animating |layer|.
2137 EXPECT_EQ(gfx::Rect(0, 0, 250, 300), 1807 EXPECT_EQ(gfx::Rect(250, 0, 50, 300).ToString(),
2138 occlusion.UnoccludedLayerContentRect(parent, 1808 occlusion.occlusion_from_inside_target().ToString());
2139 gfx::Rect(0, 0, 300, 300))); 1809 EXPECT_EQ(gfx::Rect().ToString(),
1810 occlusion.occlusion_from_outside_target().ToString());
2140 } 1811 }
2141 }; 1812 };
2142 1813
2143 MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity0OnMainThread); 1814 MAIN_THREAD_TEST(OcclusionTrackerTestAnimationOpacity0OnMainThread);
2144 1815
2145 template <class Types> 1816 template <class Types>
2146 class OcclusionTrackerTestAnimationTranslateOnMainThread 1817 class OcclusionTrackerTestAnimationTranslateOnMainThread
2147 : public OcclusionTrackerTest<Types> { 1818 : public OcclusionTrackerTest<Types> {
2148 protected: 1819 protected:
2149 explicit OcclusionTrackerTestAnimationTranslateOnMainThread( 1820 explicit OcclusionTrackerTestAnimationTranslateOnMainThread(
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2357 occlusion.occlusion_from_outside_target().ToString()); 2028 occlusion.occlusion_from_outside_target().ToString());
2358 EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(), 2029 EXPECT_EQ(gfx::Rect(0, 0, 300, 200).ToString(),
2359 occlusion.occlusion_from_inside_target().ToString()); 2030 occlusion.occlusion_from_inside_target().ToString());
2360 } 2031 }
2361 }; 2032 };
2362 2033
2363 MAIN_AND_IMPL_THREAD_TEST( 2034 MAIN_AND_IMPL_THREAD_TEST(
2364 OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping); 2035 OcclusionTrackerTestSurfaceOcclusionTranslatesWithClipping);
2365 2036
2366 template <class Types> 2037 template <class Types>
2367 class OcclusionTrackerTestReplicaOccluded : public OcclusionTrackerTest<Types> {
2368 protected:
2369 explicit OcclusionTrackerTestReplicaOccluded(bool opaque_layers)
2370 : OcclusionTrackerTest<Types>(opaque_layers) {}
2371 void RunMyTest() {
2372 typename Types::ContentLayerType* parent = this->CreateRoot(
2373 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
2374 typename Types::LayerType* surface =
2375 this->CreateDrawingSurface(parent,
2376 this->identity_matrix,
2377 gfx::PointF(),
2378 gfx::Size(100, 100),
2379 true);
2380 this->CreateReplicaLayer(surface,
2381 this->identity_matrix,
2382 gfx::PointF(0.f, 100.f),
2383 gfx::Size(100, 100));
2384 typename Types::LayerType* topmost =
2385 this->CreateDrawingLayer(parent,
2386 this->identity_matrix,
2387 gfx::PointF(0.f, 100.f),
2388 gfx::Size(100, 100),
2389 true);
2390 this->CalcDrawEtc(parent);
2391
2392 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
2393 gfx::Rect(0, 0, 1000, 1000));
2394
2395 // |topmost| occludes the replica, but not the surface itself.
2396 this->VisitLayer(topmost, &occlusion);
2397
2398 EXPECT_EQ(gfx::Rect().ToString(),
2399 occlusion.occlusion_from_outside_target().ToString());
2400 EXPECT_EQ(gfx::Rect(0, 100, 100, 100).ToString(),
2401 occlusion.occlusion_from_inside_target().ToString());
2402
2403 this->VisitLayer(surface, &occlusion);
2404
2405 // Render target with replica ignores occlusion from outside.
2406 EXPECT_EQ(gfx::Rect().ToString(),
2407 occlusion.occlusion_from_outside_target().ToString());
2408 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
2409 occlusion.occlusion_from_inside_target().ToString());
2410
2411 this->EnterContributingSurface(surface, &occlusion);
2412
2413 // Surface is not occluded so it shouldn't think it is.
2414 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2415 occlusion.UnoccludedSurfaceContentRect(
2416 surface, false, gfx::Rect(0, 0, 100, 100)));
2417 }
2418 };
2419
2420 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestReplicaOccluded);
2421
2422 template <class Types>
2423 class OcclusionTrackerTestSurfaceWithReplicaUnoccluded 2038 class OcclusionTrackerTestSurfaceWithReplicaUnoccluded
2424 : public OcclusionTrackerTest<Types> { 2039 : public OcclusionTrackerTest<Types> {
2425 protected: 2040 protected:
2426 explicit OcclusionTrackerTestSurfaceWithReplicaUnoccluded(bool opaque_layers) 2041 explicit OcclusionTrackerTestSurfaceWithReplicaUnoccluded(bool opaque_layers)
2427 : OcclusionTrackerTest<Types>(opaque_layers) {} 2042 : OcclusionTrackerTest<Types>(opaque_layers) {}
2428 void RunMyTest() { 2043 void RunMyTest() {
2429 typename Types::ContentLayerType* parent = this->CreateRoot( 2044 typename Types::ContentLayerType* parent = this->CreateRoot(
2430 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); 2045 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
2431 typename Types::LayerType* surface = 2046 typename Types::LayerType* surface =
2432 this->CreateDrawingSurface(parent, 2047 this->CreateDrawingSurface(parent,
(...skipping 27 matching lines...) Expand all
2460 this->VisitLayer(surface, &occlusion); 2075 this->VisitLayer(surface, &occlusion);
2461 2076
2462 // Render target with replica ignores occlusion from outside. 2077 // Render target with replica ignores occlusion from outside.
2463 EXPECT_EQ(gfx::Rect().ToString(), 2078 EXPECT_EQ(gfx::Rect().ToString(),
2464 occlusion.occlusion_from_outside_target().ToString()); 2079 occlusion.occlusion_from_outside_target().ToString());
2465 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), 2080 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
2466 occlusion.occlusion_from_inside_target().ToString()); 2081 occlusion.occlusion_from_inside_target().ToString());
2467 2082
2468 this->EnterContributingSurface(surface, &occlusion); 2083 this->EnterContributingSurface(surface, &occlusion);
2469 2084
2470 // Surface is occluded, but only the top 10px of the replica. 2085 // Only occlusion from outside the surface occludes the surface/replica.
2471 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), 2086 EXPECT_EQ(gfx::Rect().ToString(),
2472 occlusion.UnoccludedSurfaceContentRect( 2087 occlusion.occlusion_on_contributing_surface_from_outside_target()
2473 surface, false, gfx::Rect(0, 0, 100, 100))); 2088 .ToString());
2474 EXPECT_EQ(gfx::Rect(0, 10, 100, 90), 2089 EXPECT_EQ(gfx::Rect(0, 0, 100, 110).ToString(),
2475 occlusion.UnoccludedSurfaceContentRect( 2090 occlusion.occlusion_on_contributing_surface_from_inside_target()
2476 surface, true, gfx::Rect(0, 0, 100, 100))); 2091 .ToString());
2477 } 2092 }
2478 }; 2093 };
2479 2094
2480 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithReplicaUnoccluded); 2095 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceWithReplicaUnoccluded);
2481 2096
2482 template <class Types> 2097 template <class Types>
2483 class OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently
2484 : public OcclusionTrackerTest<Types> {
2485 protected:
2486 explicit OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently(
2487 bool opaque_layers)
2488 : OcclusionTrackerTest<Types>(opaque_layers) {}
2489 void RunMyTest() {
2490 typename Types::ContentLayerType* parent = this->CreateRoot(
2491 this->identity_matrix, gfx::PointF(), gfx::Size(200, 100));
2492 typename Types::LayerType* surface =
2493 this->CreateDrawingSurface(parent,
2494 this->identity_matrix,
2495 gfx::PointF(),
2496 gfx::Size(100, 100),
2497 true);
2498 this->CreateReplicaLayer(surface,
2499 this->identity_matrix,
2500 gfx::PointF(100.f, 0.f),
2501 gfx::Size(100, 100));
2502 typename Types::LayerType* over_surface =
2503 this->CreateDrawingLayer(parent,
2504 this->identity_matrix,
2505 gfx::PointF(60.f, 0.f),
2506 gfx::Size(40, 100),
2507 true);
2508 typename Types::LayerType* over_replica =
2509 this->CreateDrawingLayer(parent,
2510 this->identity_matrix,
2511 gfx::PointF(100.f, 0.f),
2512 gfx::Size(50, 100),
2513 true);
2514 this->CalcDrawEtc(parent);
2515
2516 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
2517 gfx::Rect(0, 0, 1000, 1000));
2518
2519 // These occlude the surface and replica differently, so we can test each
2520 // one.
2521 this->VisitLayer(over_replica, &occlusion);
2522 this->VisitLayer(over_surface, &occlusion);
2523
2524 EXPECT_EQ(gfx::Rect().ToString(),
2525 occlusion.occlusion_from_outside_target().ToString());
2526 EXPECT_EQ(gfx::Rect(60, 0, 90, 100).ToString(),
2527 occlusion.occlusion_from_inside_target().ToString());
2528
2529 this->VisitLayer(surface, &occlusion);
2530
2531 // Render target with replica ignores occlusion from outside.
2532 EXPECT_EQ(gfx::Rect().ToString(),
2533 occlusion.occlusion_from_outside_target().ToString());
2534 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
2535 occlusion.occlusion_from_inside_target().ToString());
2536
2537 this->EnterContributingSurface(surface, &occlusion);
2538
2539 // Surface and replica are occluded different amounts.
2540 EXPECT_EQ(gfx::Rect(0, 0, 60, 100),
2541 occlusion.UnoccludedSurfaceContentRect(
2542 surface, false, gfx::Rect(0, 0, 100, 100)));
2543 EXPECT_EQ(gfx::Rect(50, 0, 50, 100),
2544 occlusion.UnoccludedSurfaceContentRect(
2545 surface, true, gfx::Rect(0, 0, 100, 100)));
2546 }
2547 };
2548
2549 ALL_OCCLUSIONTRACKER_TEST(
2550 OcclusionTrackerTestSurfaceAndReplicaOccludedDifferently);
2551
2552 template <class Types>
2553 class OcclusionTrackerTestSurfaceChildOfSurface 2098 class OcclusionTrackerTestSurfaceChildOfSurface
2554 : public OcclusionTrackerTest<Types> { 2099 : public OcclusionTrackerTest<Types> {
2555 protected: 2100 protected:
2556 explicit OcclusionTrackerTestSurfaceChildOfSurface(bool opaque_layers) 2101 explicit OcclusionTrackerTestSurfaceChildOfSurface(bool opaque_layers)
2557 : OcclusionTrackerTest<Types>(opaque_layers) {} 2102 : OcclusionTrackerTest<Types>(opaque_layers) {}
2558 void RunMyTest() { 2103 void RunMyTest() {
2559 // This test verifies that the surface cliprect does not end up empty and 2104 // This test verifies that the surface cliprect does not end up empty and
2560 // clip away the entire unoccluded rect. 2105 // clip away the entire unoccluded rect.
2561 2106
2562 typename Types::ContentLayerType* parent = this->CreateRoot( 2107 typename Types::ContentLayerType* parent = this->CreateRoot(
2563 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200)); 2108 this->identity_matrix, gfx::PointF(), gfx::Size(100, 200));
2564 typename Types::LayerType* surface = 2109 typename Types::LayerType* surface =
2565 this->CreateDrawingSurface(parent, 2110 this->CreateDrawingSurface(parent,
2566 this->identity_matrix, 2111 this->identity_matrix,
2567 gfx::PointF(), 2112 gfx::PointF(),
2568 gfx::Size(100, 100), 2113 gfx::Size(100, 100),
2569 true); 2114 false);
2570 typename Types::LayerType* surface_child = 2115 typename Types::LayerType* surface_child =
2571 this->CreateDrawingSurface(surface, 2116 this->CreateDrawingSurface(surface,
2572 this->identity_matrix, 2117 this->identity_matrix,
2573 gfx::PointF(0.f, 10.f), 2118 gfx::PointF(0.f, 10.f),
2574 gfx::Size(100, 50), 2119 gfx::Size(100, 50),
2575 true); 2120 true);
2576 typename Types::LayerType* topmost = this->CreateDrawingLayer( 2121 typename Types::LayerType* topmost = this->CreateDrawingLayer(
2577 parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true); 2122 parent, this->identity_matrix, gfx::PointF(), gfx::Size(100, 50), true);
2578 this->CalcDrawEtc(parent); 2123 this->CalcDrawEtc(parent);
2579 2124
(...skipping 18 matching lines...) Expand all
2598 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), 2143 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2599 occlusion.occlusion_from_inside_target().ToString()); 2144 occlusion.occlusion_from_inside_target().ToString());
2600 2145
2601 // The root layer always has a clip rect. So the parent of |surface| has a 2146 // The root layer always has a clip rect. So the parent of |surface| has a
2602 // clip rect. However, the owning layer for |surface| does not mask to 2147 // clip rect. However, the owning layer for |surface| does not mask to
2603 // bounds, so it doesn't have a clip rect of its own. Thus the parent of 2148 // bounds, so it doesn't have a clip rect of its own. Thus the parent of
2604 // |surface_child| exercises different code paths as its parent does not 2149 // |surface_child| exercises different code paths as its parent does not
2605 // have a clip rect. 2150 // have a clip rect.
2606 2151
2607 this->EnterContributingSurface(surface_child, &occlusion); 2152 this->EnterContributingSurface(surface_child, &occlusion);
2608 // The surface_child's parent does not have a clip rect as it owns a render 2153 // The |surface_child| can't occlude its own surface, but occlusion from
2609 // surface. Make sure the unoccluded rect does not get clipped away 2154 // |topmost| can.
2610 // inappropriately. 2155 EXPECT_EQ(gfx::Rect().ToString(),
2611 EXPECT_EQ(gfx::Rect(0, 40, 100, 10), 2156 occlusion.occlusion_on_contributing_surface_from_outside_target()
2612 occlusion.UnoccludedSurfaceContentRect( 2157 .ToString());
2613 surface_child, false, gfx::Rect(0, 0, 100, 50))); 2158 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2159 occlusion.occlusion_on_contributing_surface_from_inside_target()
2160 .ToString());
2614 this->LeaveContributingSurface(surface_child, &occlusion); 2161 this->LeaveContributingSurface(surface_child, &occlusion);
2615 2162
2616 // When the surface_child's occlusion is transformed up to its parent, make 2163 // When the surface_child's occlusion is transformed up to its parent, make
2617 // sure it is not clipped away inappropriately also. 2164 // sure it is not clipped away inappropriately.
2618 this->EnterLayer(surface, &occlusion); 2165 this->EnterLayer(surface, &occlusion);
2619 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(), 2166 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2620 occlusion.occlusion_from_outside_target().ToString()); 2167 occlusion.occlusion_from_outside_target().ToString());
2621 EXPECT_EQ(gfx::Rect(0, 10, 100, 50).ToString(), 2168 EXPECT_EQ(gfx::Rect(0, 10, 100, 50).ToString(),
2622 occlusion.occlusion_from_inside_target().ToString()); 2169 occlusion.occlusion_from_inside_target().ToString());
2623 this->LeaveLayer(surface, &occlusion); 2170 this->LeaveLayer(surface, &occlusion);
2624 2171
2625 this->EnterContributingSurface(surface, &occlusion); 2172 this->EnterContributingSurface(surface, &occlusion);
2626 // The surface's parent does have a clip rect as it is the root layer. 2173 // The occlusion from inside |surface| can't affect the surface, but
2627 EXPECT_EQ(gfx::Rect(0, 50, 100, 50), 2174 // |topmost| can.
2628 occlusion.UnoccludedSurfaceContentRect( 2175 EXPECT_EQ(gfx::Rect().ToString(),
2629 surface, false, gfx::Rect(0, 0, 100, 100))); 2176 occlusion.occlusion_on_contributing_surface_from_outside_target()
2177 .ToString());
2178 EXPECT_EQ(gfx::Rect(0, 0, 100, 50).ToString(),
2179 occlusion.occlusion_on_contributing_surface_from_inside_target()
2180 .ToString());
2181
2182 this->LeaveContributingSurface(surface, &occlusion);
2183 this->EnterLayer(parent, &occlusion);
2184 // The occlusion in |surface| and without are merged into the parent.
2185 EXPECT_EQ(gfx::Rect().ToString(),
2186 occlusion.occlusion_from_outside_target().ToString());
2187 EXPECT_EQ(gfx::Rect(0, 0, 100, 60).ToString(),
2188 occlusion.occlusion_from_inside_target().ToString());
2630 } 2189 }
2631 }; 2190 };
2632 2191
2633 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface); 2192 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestSurfaceChildOfSurface);
2634 2193
2635 template <class Types> 2194 template <class Types>
2636 class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter 2195 class OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter
2637 : public OcclusionTrackerTest<Types> { 2196 : public OcclusionTrackerTest<Types> {
2638 protected: 2197 protected:
2639 explicit OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter( 2198 explicit OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter(
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
3402 // Full occlusion from both, is occluded. 2961 // Full occlusion from both, is occluded.
3403 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100))); 2962 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 100, 100)));
3404 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10))); 2963 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(40, 30, 10, 10)));
3405 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10))); 2964 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(130, 120, 10, 10)));
3406 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50))); 2965 EXPECT_TRUE(occlusion.OccludedLayer(layer, gfx::Rect(80, 70, 50, 50)));
3407 } 2966 }
3408 }; 2967 };
3409 2968
3410 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOccludedLayer) 2969 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestOccludedLayer)
3411 2970
2971 template <class Types>
2972 class OcclusionTrackerTestUnoccludedLayerQuery
2973 : public OcclusionTrackerTest<Types> {
2974 protected:
2975 explicit OcclusionTrackerTestUnoccludedLayerQuery(bool opaque_layers)
2976 : OcclusionTrackerTest<Types>(opaque_layers) {}
2977 void RunMyTest() {
2978 gfx::Transform translate;
2979 translate.Translate(10.0, 20.0);
2980 typename Types::ContentLayerType* root = this->CreateRoot(
2981 this->identity_matrix, gfx::Point(), gfx::Size(200, 200));
2982 typename Types::LayerType* surface = this->CreateSurface(
2983 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200));
2984 typename Types::LayerType* layer = this->CreateDrawingLayer(
2985 surface, translate, gfx::Point(), gfx::Size(200, 200), false);
2986 typename Types::ContentLayerType* outside_layer = this->CreateDrawingLayer(
2987 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200), false);
2988 this->CalcDrawEtc(root);
2989
2990 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
2991 gfx::Rect(0, 0, 200, 200));
2992 this->VisitLayer(outside_layer, &occlusion);
2993 this->EnterLayer(layer, &occlusion);
2994
2995 // No occlusion, is not occluded.
2996 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
2997 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
2998 EXPECT_EQ(gfx::Rect(100, 100),
2999 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(100, 100)));
3000
3001 // Partial occlusion from outside.
3002 occlusion.set_occlusion_from_outside_target(
3003 SimpleEnclosedRegion(50, 50, 100, 100));
3004 occlusion.set_occlusion_from_inside_target(SimpleEnclosedRegion());
3005 EXPECT_EQ(
3006 gfx::Rect(0, 0, 100, 100),
3007 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
3008 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
3009 occlusion.UnoccludedLayerContentRect(
3010 layer, gfx::Rect(90, 30, 100, 100)));
3011 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3012 occlusion.UnoccludedLayerContentRect(layer,
3013 gfx::Rect(40, 0, 100, 100)));
3014 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3015 occlusion.UnoccludedLayerContentRect(
3016 layer, gfx::Rect(40, 80, 100, 100)));
3017 EXPECT_EQ(
3018 gfx::Rect(0, 0, 80, 100),
3019 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
3020 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3021 occlusion.UnoccludedLayerContentRect(
3022 layer, gfx::Rect(90, 80, 100, 100)));
3023 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3024 occlusion.UnoccludedLayerContentRect(layer,
3025 gfx::Rect(0, 80, 100, 100)));
3026 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3027 occlusion.UnoccludedLayerContentRect(layer,
3028 gfx::Rect(90, 0, 100, 100)));
3029
3030 // Full occlusion from outside, is occluded.
3031 EXPECT_EQ(gfx::Rect(),
3032 occlusion.UnoccludedLayerContentRect(
3033 layer, gfx::Rect(40, 30, 100, 100)));
3034 EXPECT_EQ(
3035 gfx::Rect(),
3036 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
3037 EXPECT_EQ(gfx::Rect(),
3038 occlusion.UnoccludedLayerContentRect(
3039 layer, gfx::Rect(130, 120, 10, 10)));
3040 EXPECT_EQ(
3041 gfx::Rect(),
3042 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
3043
3044 // Partial occlusion from inside, is not occluded.
3045 occlusion.set_occlusion_from_outside_target(SimpleEnclosedRegion());
3046 occlusion.set_occlusion_from_inside_target(
3047 SimpleEnclosedRegion(50, 50, 100, 100));
3048 EXPECT_EQ(
3049 gfx::Rect(0, 0, 100, 100),
3050 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
3051 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
3052 occlusion.UnoccludedLayerContentRect(
3053 layer, gfx::Rect(90, 30, 100, 100)));
3054 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3055 occlusion.UnoccludedLayerContentRect(layer,
3056 gfx::Rect(40, 0, 100, 100)));
3057 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3058 occlusion.UnoccludedLayerContentRect(
3059 layer, gfx::Rect(40, 80, 100, 100)));
3060 EXPECT_EQ(
3061 gfx::Rect(0, 0, 80, 100),
3062 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
3063 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3064 occlusion.UnoccludedLayerContentRect(
3065 layer, gfx::Rect(90, 80, 100, 100)));
3066 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3067 occlusion.UnoccludedLayerContentRect(layer,
3068 gfx::Rect(0, 80, 100, 100)));
3069 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3070 occlusion.UnoccludedLayerContentRect(layer,
3071 gfx::Rect(90, 0, 100, 100)));
3072
3073 // Full occlusion from inside, is occluded.
3074 EXPECT_EQ(gfx::Rect(),
3075 occlusion.UnoccludedLayerContentRect(
3076 layer, gfx::Rect(40, 30, 100, 100)));
3077 EXPECT_EQ(
3078 gfx::Rect(),
3079 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
3080 EXPECT_EQ(gfx::Rect(),
3081 occlusion.UnoccludedLayerContentRect(
3082 layer, gfx::Rect(130, 120, 10, 10)));
3083 EXPECT_EQ(
3084 gfx::Rect(),
3085 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
3086
3087 // Partial occlusion from both, is not occluded.
3088 occlusion.set_occlusion_from_outside_target(
3089 SimpleEnclosedRegion(50, 50, 100, 50));
3090 occlusion.set_occlusion_from_inside_target(
3091 SimpleEnclosedRegion(50, 100, 100, 50));
3092 EXPECT_EQ(
3093 gfx::Rect(0, 0, 100, 100),
3094 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 100, 100)));
3095 // This could be (140, 30, 50, 100). But because we do a lossy subtract,
3096 // it's larger.
3097 EXPECT_EQ(gfx::Rect(90, 30, 100, 100),
3098 occlusion.UnoccludedLayerContentRect(
3099 layer, gfx::Rect(90, 30, 100, 100)));
3100 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3101 occlusion.UnoccludedLayerContentRect(layer,
3102 gfx::Rect(40, 0, 100, 100)));
3103 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3104 occlusion.UnoccludedLayerContentRect(
3105 layer, gfx::Rect(40, 80, 100, 100)));
3106 EXPECT_EQ(
3107 gfx::Rect(0, 0, 80, 100),
3108 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(0, 0, 80, 100)));
3109 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3110 occlusion.UnoccludedLayerContentRect(
3111 layer, gfx::Rect(90, 80, 100, 100)));
3112 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3113 occlusion.UnoccludedLayerContentRect(layer,
3114 gfx::Rect(0, 80, 100, 100)));
3115 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3116 occlusion.UnoccludedLayerContentRect(layer,
3117 gfx::Rect(90, 0, 100, 100)));
3118
3119 // Full occlusion from both, is occluded.
3120 EXPECT_EQ(gfx::Rect(),
3121 occlusion.UnoccludedLayerContentRect(
3122 layer, gfx::Rect(40, 30, 100, 100)));
3123 EXPECT_EQ(
3124 gfx::Rect(),
3125 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(40, 30, 10, 10)));
3126 EXPECT_EQ(gfx::Rect(),
3127 occlusion.UnoccludedLayerContentRect(
3128 layer, gfx::Rect(130, 120, 10, 10)));
3129 EXPECT_EQ(
3130 gfx::Rect(),
3131 occlusion.UnoccludedLayerContentRect(layer, gfx::Rect(80, 70, 50, 50)));
3132 }
3133 };
3134
3135 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedLayerQuery)
3136
3137 template <class Types>
3138 class OcclusionTrackerTestUnoccludedSurfaceQuery
3139 : public OcclusionTrackerTest<Types> {
3140 protected:
3141 explicit OcclusionTrackerTestUnoccludedSurfaceQuery(bool opaque_layers)
3142 : OcclusionTrackerTest<Types>(opaque_layers) {}
3143 void RunMyTest() {
3144 gfx::Transform translate;
3145 translate.Translate(10.0, 20.0);
3146 typename Types::ContentLayerType* root = this->CreateRoot(
3147 this->identity_matrix, gfx::Point(), gfx::Size(200, 200));
3148 typename Types::LayerType* surface =
3149 this->CreateSurface(root, translate, gfx::Point(), gfx::Size(200, 200));
3150 typename Types::LayerType* layer =
3151 this->CreateDrawingLayer(surface,
3152 this->identity_matrix,
3153 gfx::Point(),
3154 gfx::Size(200, 200),
3155 false);
3156 typename Types::ContentLayerType* outside_layer = this->CreateDrawingLayer(
3157 root, this->identity_matrix, gfx::Point(), gfx::Size(200, 200), false);
3158 this->CalcDrawEtc(root);
3159
3160 TestOcclusionTrackerWithClip<typename Types::LayerType> occlusion(
3161 gfx::Rect(0, 0, 200, 200));
3162 this->VisitLayer(outside_layer, &occlusion);
3163 this->VisitLayer(layer, &occlusion);
3164 this->EnterContributingSurface(surface, &occlusion);
3165
3166 // No occlusion, is not occluded.
3167 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
3168 SimpleEnclosedRegion());
3169 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
3170 SimpleEnclosedRegion());
3171 EXPECT_EQ(
3172 gfx::Rect(100, 100),
3173 occlusion.UnoccludedSurfaceContentRect(surface, gfx::Rect(100, 100)));
3174
3175 // Partial occlusion from outside.
3176 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
3177 SimpleEnclosedRegion(50, 50, 100, 100));
3178 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
3179 SimpleEnclosedRegion());
3180 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3181 occlusion.UnoccludedSurfaceContentRect(
3182 surface, gfx::Rect(0, 0, 100, 100)));
3183 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
3184 occlusion.UnoccludedSurfaceContentRect(
3185 surface, gfx::Rect(90, 30, 100, 100)));
3186 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3187 occlusion.UnoccludedSurfaceContentRect(
3188 surface, gfx::Rect(40, 0, 100, 100)));
3189 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3190 occlusion.UnoccludedSurfaceContentRect(
3191 surface, gfx::Rect(40, 80, 100, 100)));
3192 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
3193 occlusion.UnoccludedSurfaceContentRect(surface,
3194 gfx::Rect(0, 0, 80, 100)));
3195 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3196 occlusion.UnoccludedSurfaceContentRect(
3197 surface, gfx::Rect(90, 80, 100, 100)));
3198 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3199 occlusion.UnoccludedSurfaceContentRect(
3200 surface, gfx::Rect(0, 80, 100, 100)));
3201 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3202 occlusion.UnoccludedSurfaceContentRect(
3203 surface, gfx::Rect(90, 0, 100, 100)));
3204
3205 // Full occlusion from outside, is occluded.
3206 EXPECT_EQ(gfx::Rect(),
3207 occlusion.UnoccludedSurfaceContentRect(
3208 surface, gfx::Rect(40, 30, 100, 100)));
3209 EXPECT_EQ(gfx::Rect(),
3210 occlusion.UnoccludedSurfaceContentRect(
3211 surface, gfx::Rect(40, 30, 10, 10)));
3212 EXPECT_EQ(gfx::Rect(),
3213 occlusion.UnoccludedSurfaceContentRect(
3214 surface, gfx::Rect(130, 120, 10, 10)));
3215 EXPECT_EQ(gfx::Rect(),
3216 occlusion.UnoccludedSurfaceContentRect(
3217 surface, gfx::Rect(80, 70, 50, 50)));
3218
3219 // Partial occlusion from inside, is not occluded.
3220 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
3221 SimpleEnclosedRegion());
3222 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
3223 SimpleEnclosedRegion(50, 50, 100, 100));
3224 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3225 occlusion.UnoccludedSurfaceContentRect(
3226 surface, gfx::Rect(0, 0, 100, 100)));
3227 EXPECT_EQ(gfx::Rect(140, 30, 50, 100),
3228 occlusion.UnoccludedSurfaceContentRect(
3229 surface, gfx::Rect(90, 30, 100, 100)));
3230 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3231 occlusion.UnoccludedSurfaceContentRect(
3232 surface, gfx::Rect(40, 0, 100, 100)));
3233 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3234 occlusion.UnoccludedSurfaceContentRect(
3235 surface, gfx::Rect(40, 80, 100, 100)));
3236 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
3237 occlusion.UnoccludedSurfaceContentRect(surface,
3238 gfx::Rect(0, 0, 80, 100)));
3239 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3240 occlusion.UnoccludedSurfaceContentRect(
3241 surface, gfx::Rect(90, 80, 100, 100)));
3242 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3243 occlusion.UnoccludedSurfaceContentRect(
3244 surface, gfx::Rect(0, 80, 100, 100)));
3245 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3246 occlusion.UnoccludedSurfaceContentRect(
3247 surface, gfx::Rect(90, 0, 100, 100)));
3248
3249 // Full occlusion from inside, is occluded.
3250 EXPECT_EQ(gfx::Rect(),
3251 occlusion.UnoccludedSurfaceContentRect(
3252 surface, gfx::Rect(40, 30, 100, 100)));
3253 EXPECT_EQ(gfx::Rect(),
3254 occlusion.UnoccludedSurfaceContentRect(
3255 surface, gfx::Rect(40, 30, 10, 10)));
3256 EXPECT_EQ(gfx::Rect(),
3257 occlusion.UnoccludedSurfaceContentRect(
3258 surface, gfx::Rect(130, 120, 10, 10)));
3259 EXPECT_EQ(gfx::Rect(),
3260 occlusion.UnoccludedSurfaceContentRect(
3261 surface, gfx::Rect(80, 70, 50, 50)));
3262
3263 // Partial occlusion from both, is not occluded.
3264 occlusion.set_occlusion_on_contributing_surface_from_outside_target(
3265 SimpleEnclosedRegion(50, 50, 100, 50));
3266 occlusion.set_occlusion_on_contributing_surface_from_inside_target(
3267 SimpleEnclosedRegion(50, 100, 100, 50));
3268 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3269 occlusion.UnoccludedSurfaceContentRect(
3270 surface, gfx::Rect(0, 0, 100, 100)));
3271 // This could be (140, 30, 50, 100). But because we do a lossy subtract,
3272 // it's larger.
3273 EXPECT_EQ(gfx::Rect(90, 30, 100, 100),
3274 occlusion.UnoccludedSurfaceContentRect(
3275 surface, gfx::Rect(90, 30, 100, 100)));
3276 EXPECT_EQ(gfx::Rect(40, 0, 100, 30),
3277 occlusion.UnoccludedSurfaceContentRect(
3278 surface, gfx::Rect(40, 0, 100, 100)));
3279 EXPECT_EQ(gfx::Rect(40, 130, 100, 50),
3280 occlusion.UnoccludedSurfaceContentRect(
3281 surface, gfx::Rect(40, 80, 100, 100)));
3282 EXPECT_EQ(gfx::Rect(0, 0, 80, 100),
3283 occlusion.UnoccludedSurfaceContentRect(surface,
3284 gfx::Rect(0, 0, 80, 100)));
3285 EXPECT_EQ(gfx::Rect(90, 80, 100, 100),
3286 occlusion.UnoccludedSurfaceContentRect(
3287 surface, gfx::Rect(90, 80, 100, 100)));
3288 EXPECT_EQ(gfx::Rect(0, 80, 100, 100),
3289 occlusion.UnoccludedSurfaceContentRect(
3290 surface, gfx::Rect(0, 80, 100, 100)));
3291 EXPECT_EQ(gfx::Rect(90, 0, 100, 100),
3292 occlusion.UnoccludedSurfaceContentRect(
3293 surface, gfx::Rect(90, 0, 100, 100)));
3294
3295 // Full occlusion from both, is occluded.
3296 EXPECT_EQ(gfx::Rect(),
3297 occlusion.UnoccludedSurfaceContentRect(
3298 surface, gfx::Rect(40, 30, 100, 100)));
3299 EXPECT_EQ(gfx::Rect(),
3300 occlusion.UnoccludedSurfaceContentRect(
3301 surface, gfx::Rect(40, 30, 10, 10)));
3302 EXPECT_EQ(gfx::Rect(),
3303 occlusion.UnoccludedSurfaceContentRect(
3304 surface, gfx::Rect(130, 120, 10, 10)));
3305 EXPECT_EQ(gfx::Rect(),
3306 occlusion.UnoccludedSurfaceContentRect(
3307 surface, gfx::Rect(80, 70, 50, 50)));
3308 }
3309 };
3310
3311 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedSurfaceQuery)
3312
3412 } // namespace 3313 } // namespace
3413 } // namespace cc 3314 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/test_occlusion_tracker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698