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

Side by Side Diff: Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp

Issue 9958025: Merge 112436 - [chromium] layer->clipRect() is not initialized for layers that create a renderSurfa… (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1084/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(45, 45), IntSize(10, 10), false); 618 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(45, 45), IntSize(10, 10), false);
619 setLayerPropertiesForTesting(greatGrandChild.get(), identityMatrix, identity Matrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false); 619 setLayerPropertiesForTesting(greatGrandChild.get(), identityMatrix, identity Matrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false);
620 setLayerPropertiesForTesting(leafNode1.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false); 620 setLayerPropertiesForTesting(leafNode1.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false);
621 setLayerPropertiesForTesting(leafNode2.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false); 621 setLayerPropertiesForTesting(leafNode2.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false);
622 622
623 child->setMasksToBounds(true); 623 child->setMasksToBounds(true);
624 child->setOpacity(0.4); 624 child->setOpacity(0.4);
625 grandChild->setOpacity(0.5); 625 grandChild->setOpacity(0.5);
626 greatGrandChild->setOpacity(0.4); 626 greatGrandChild->setOpacity(0.4);
627 627
628 Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
629 Vector<RefPtr<LayerChromium> > dummyLayerList;
630 int dummyMaxTextureSize = 512;
631
632 // FIXME: when we fix this "root-layer special case" behavior in CCLayerTree Host, we will have to fix it here, too.
633 parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
634 renderSurfaceLayerList.append(parent.get());
635
636 CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), pa rent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerLi st, dummyMaxTextureSize);
637
638 ASSERT_EQ(2U, renderSurfaceLayerList.size());
639 EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
640 EXPECT_EQ(child->id(), renderSurfaceLayerList[1]->id());
641 }
642
643 TEST(CCLayerTreeHostCommonTest, verifyClipRectCullsRenderSurfacesCrashRepro)
644 {
645 // This is a similar situation as verifyClipRectCullsRenderSurfaces, except that
646 // it reproduces a crash bug http://code.google.com/p/chromium/issues/detail ?id=106734.
647
648 const TransformationMatrix identityMatrix;
649 RefPtr<LayerChromium> parent = LayerChromium::create();
650 RefPtr<LayerChromium> child = LayerChromium::create();
651 RefPtr<LayerChromium> grandChild = LayerChromium::create();
652 RefPtr<LayerChromium> greatGrandChild = LayerChromium::create();
653 RefPtr<LayerChromiumWithForcedDrawsContent> leafNode1 = adoptRef(new LayerCh romiumWithForcedDrawsContent());
654 RefPtr<LayerChromiumWithForcedDrawsContent> leafNode2 = adoptRef(new LayerCh romiumWithForcedDrawsContent());
655 parent->createRenderSurface();
656 parent->addChild(child);
657 child->addChild(grandChild);
658 grandChild->addChild(greatGrandChild);
659
660 // leafNode1 ensures that parent and child are kept on the renderSurfaceLaye rList,
661 // even though grandChild and greatGrandChild should be clipped.
662 child->addChild(leafNode1);
663 greatGrandChild->addChild(leafNode2);
664
665 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false);
666 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false);
667 setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatri x, FloatPoint(0, 0), FloatPoint(45, 45), IntSize(10, 10), false);
668 setLayerPropertiesForTesting(greatGrandChild.get(), identityMatrix, identity Matrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false);
669 setLayerPropertiesForTesting(leafNode1.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false);
670 setLayerPropertiesForTesting(leafNode2.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false);
671
672 child->setMasksToBounds(true);
673 child->setOpacity(0.4);
674 grandChild->setOpacity(0.5);
675 greatGrandChild->setOpacity(0.4);
676
628 // Contaminate the grandChild and greatGrandChild's clipRect to reproduce th e crash 677 // Contaminate the grandChild and greatGrandChild's clipRect to reproduce th e crash
629 // bug found in http://code.google.com/p/chromium/issues/detail?id=106734. I n this 678 // bug found in http://code.google.com/p/chromium/issues/detail?id=106734. I n this
630 // bug, the clipRect was not re-computed for layers that create RenderSurfac es, and 679 // bug, the clipRect was not re-computed for layers that create RenderSurfac es, and
631 // therefore leafNode2 thinks it should draw itself. As a result, an extra 680 // therefore leafNode2 thinks it should draw itself. As a result, an extra
632 // renderSurface remains on the renderSurfaceLayerList, which violates the a ssumption 681 // renderSurface remains on the renderSurfaceLayerList, which violates the a ssumption
633 // that an empty renderSurface will always be the last item on the list, whi ch 682 // that an empty renderSurface will always be the last item on the list, whi ch
634 // ultimately caused the crash. 683 // ultimately caused the crash.
635 //
636 // FIXME: it is also useful to test with this commented out. Eventually we s hould
637 // create several test cases that test clipRect/drawableContentRect computat ion.
638 child->setClipRect(IntRect(IntPoint::zero(), IntSize(20, 20))); 684 child->setClipRect(IntRect(IntPoint::zero(), IntSize(20, 20)));
639 greatGrandChild->setClipRect(IntRect(IntPoint::zero(), IntSize(1234, 1234))) ; 685 greatGrandChild->setClipRect(IntRect(IntPoint::zero(), IntSize(1234, 1234))) ;
640 686
641 Vector<RefPtr<LayerChromium> > renderSurfaceLayerList; 687 Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
642 Vector<RefPtr<LayerChromium> > dummyLayerList; 688 Vector<RefPtr<LayerChromium> > dummyLayerList;
643 int dummyMaxTextureSize = 512; 689 int dummyMaxTextureSize = 512;
644 690
645 // FIXME: when we fix this "root-layer special case" behavior in CCLayerTree Host, we will have to fix it here, too. 691 // FIXME: when we fix this "root-layer special case" behavior in CCLayerTree Host, we will have to fix it here, too.
646 parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds())); 692 parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
647 renderSurfaceLayerList.append(parent.get()); 693 renderSurfaceLayerList.append(parent.get());
648 694
649 CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), pa rent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerLi st, dummyMaxTextureSize); 695 CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), pa rent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerLi st, dummyMaxTextureSize);
650 696
651 ASSERT_EQ(2U, renderSurfaceLayerList.size()); 697 ASSERT_EQ(2U, renderSurfaceLayerList.size());
652 EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id()); 698 EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
653 EXPECT_EQ(child->id(), renderSurfaceLayerList[1]->id()); 699 EXPECT_EQ(child->id(), renderSurfaceLayerList[1]->id());
654 } 700 }
655 701
702 TEST(CCLayerTreeHostCommonTest, verifyClipRectIsPropagatedCorrectlyToLayers)
703 {
704 // Verify that layers get the appropriate clipRects when their parent masksT oBounds is true.
705 //
706 // grandChild1 - completely inside the region; clipRect should be the mask region (larger than this layer's bounds).
707 // grandChild2 - partially clipped but NOT masksToBounds; the clipRect sho uld be the parent's clipRect regardless of the layer's bounds.
708 // grandChild3 - partially clipped and masksToBounds; the clipRect will be the intersection of layerBounds and the mask region.
709 // grandChild4 - outside parent's clipRect, and masksToBounds; the clipRec t should be empty.
710 //
711
712 const TransformationMatrix identityMatrix;
713 RefPtr<LayerChromium> parent = LayerChromium::create();
714 RefPtr<LayerChromium> child = LayerChromium::create();
715 RefPtr<LayerChromium> grandChild1 = LayerChromium::create();
716 RefPtr<LayerChromium> grandChild2 = LayerChromium::create();
717 RefPtr<LayerChromium> grandChild3 = LayerChromium::create();
718 RefPtr<LayerChromium> grandChild4 = LayerChromium::create();
719
720 parent->createRenderSurface();
721 parent->addChild(child);
722 child->addChild(grandChild1);
723 child->addChild(grandChild2);
724 child->addChild(grandChild3);
725 child->addChild(grandChild4);
726
727 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false);
728 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false);
729 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(10, 10), false);
730 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false);
731 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false);
732 setLayerPropertiesForTesting(grandChild4.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(45, 45), IntSize(10, 10), false);
733
734 child->setMasksToBounds(true);
735 grandChild3->setMasksToBounds(true);
736 grandChild4->setMasksToBounds(true);
737
738 // Force everyone to be a render surface.
739 child->setOpacity(0.4);
740 grandChild1->setOpacity(0.5);
741 grandChild2->setOpacity(0.5);
742 grandChild3->setOpacity(0.5);
743 grandChild4->setOpacity(0.5);
744
745 Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
746 Vector<RefPtr<LayerChromium> > dummyLayerList;
747 int dummyMaxTextureSize = 512;
748
749 // FIXME: when we fix this "root-layer special case" behavior in CCLayerTree Host, we will have to fix it here, too.
750 parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
751 renderSurfaceLayerList.append(parent.get());
752
753 CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), pa rent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerLi st, dummyMaxTextureSize);
754
755 EXPECT_INT_RECT_EQ(IntRect(IntPoint::zero(), IntSize(20, 20)), grandChild1-> clipRect());
756 EXPECT_INT_RECT_EQ(IntRect(IntPoint::zero(), IntSize(20, 20)), grandChild2-> clipRect());
757 EXPECT_INT_RECT_EQ(IntRect(IntPoint(15, 15), IntSize(5, 5)), grandChild3->cl ipRect());
758 EXPECT_TRUE(grandChild4->clipRect().isEmpty());
759 }
760
761 TEST(CCLayerTreeHostCommonTest, verifyClipRectIsPropagatedCorrectlyToSurfaces)
762 {
763 // Verify that renderSurfaces (and their layers) get the appropriate clipRec ts when their parent masksToBounds is true.
764 //
765 // Layers that own renderSurfaces (at least for now) do not inherit any clip Rect;
766 // instead the surface will enforce the clip for the entire subtree. They ma y still
767 // have a clipRect of their own layer bounds, however, if masksToBounds was true.
768 //
769
770 const TransformationMatrix identityMatrix;
771 RefPtr<LayerChromium> parent = LayerChromium::create();
772 RefPtr<LayerChromium> child = LayerChromium::create();
773 RefPtr<LayerChromium> grandChild1 = LayerChromium::create();
774 RefPtr<LayerChromium> grandChild2 = LayerChromium::create();
775 RefPtr<LayerChromium> grandChild3 = LayerChromium::create();
776 RefPtr<LayerChromium> grandChild4 = LayerChromium::create();
777 RefPtr<LayerChromiumWithForcedDrawsContent> leafNode1 = adoptRef(new LayerCh romiumWithForcedDrawsContent());
778 RefPtr<LayerChromiumWithForcedDrawsContent> leafNode2 = adoptRef(new LayerCh romiumWithForcedDrawsContent());
779 RefPtr<LayerChromiumWithForcedDrawsContent> leafNode3 = adoptRef(new LayerCh romiumWithForcedDrawsContent());
780 RefPtr<LayerChromiumWithForcedDrawsContent> leafNode4 = adoptRef(new LayerCh romiumWithForcedDrawsContent());
781
782 parent->createRenderSurface();
783 parent->addChild(child);
784 child->addChild(grandChild1);
785 child->addChild(grandChild2);
786 child->addChild(grandChild3);
787 child->addChild(grandChild4);
788
789 // the leaf nodes ensure that these grandChildren become renderSurfaces for this test.
790 grandChild1->addChild(leafNode1);
791 grandChild2->addChild(leafNode2);
792 grandChild3->addChild(leafNode3);
793 grandChild4->addChild(leafNode4);
794
795 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(500, 500), false);
796 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(20, 20), false);
797 setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(5, 5), IntSize(10, 10), false);
798 setLayerPropertiesForTesting(grandChild2.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false);
799 setLayerPropertiesForTesting(grandChild3.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(15, 15), IntSize(10, 10), false);
800 setLayerPropertiesForTesting(grandChild4.get(), identityMatrix, identityMatr ix, FloatPoint(0, 0), FloatPoint(45, 45), IntSize(10, 10), false);
801 setLayerPropertiesForTesting(leafNode1.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false);
802 setLayerPropertiesForTesting(leafNode2.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false);
803 setLayerPropertiesForTesting(leafNode3.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false);
804 setLayerPropertiesForTesting(leafNode4.get(), identityMatrix, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), false);
805
806 child->setMasksToBounds(true);
807 grandChild3->setMasksToBounds(true);
808 grandChild4->setMasksToBounds(true);
809
810 // Force everyone to be a render surface.
811 child->setOpacity(0.4);
812 grandChild1->setOpacity(0.5);
813 grandChild2->setOpacity(0.5);
814 grandChild3->setOpacity(0.5);
815 grandChild4->setOpacity(0.5);
816
817 Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
818 Vector<RefPtr<LayerChromium> > dummyLayerList;
819 int dummyMaxTextureSize = 512;
820
821 // FIXME: when we fix this "root-layer special case" behavior in CCLayerTree Host, we will have to fix it here, too.
822 parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
823 renderSurfaceLayerList.append(parent.get());
824
825 CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), pa rent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerLi st, dummyMaxTextureSize);
826
827 ASSERT_TRUE(grandChild1->renderSurface());
828 ASSERT_TRUE(grandChild2->renderSurface());
829 ASSERT_TRUE(grandChild3->renderSurface());
830 EXPECT_FALSE(grandChild4->renderSurface()); // Because grandChild4 is entire ly clipped, it is expected to not have a renderSurface.
831
832 // Surfaces are clipped by their parent, but un-affected by the owning layer 's masksToBounds.
833 EXPECT_INT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild1->re nderSurface()->clipRect());
834 EXPECT_INT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild2->re nderSurface()->clipRect());
835 EXPECT_INT_RECT_EQ(IntRect(IntPoint(0, 0), IntSize(20, 20)), grandChild3->re nderSurface()->clipRect());
836
837 // Layers do not inherit the clipRect from their owned surfaces, but if mask sToBounds is true, they do create their own clipRect.
838 EXPECT_FALSE(grandChild1->usesLayerClipping());
839 EXPECT_FALSE(grandChild2->usesLayerClipping());
840 EXPECT_TRUE(grandChild3->usesLayerClipping());
841 EXPECT_TRUE(grandChild4->usesLayerClipping());
842 }
843
656 TEST(CCLayerTreeHostCommonTest, verifyAnimationsForRenderSurfaceHierarchy) 844 TEST(CCLayerTreeHostCommonTest, verifyAnimationsForRenderSurfaceHierarchy)
657 { 845 {
658 RefPtr<LayerChromium> parent = LayerChromium::create(); 846 RefPtr<LayerChromium> parent = LayerChromium::create();
659 RefPtr<LayerChromium> renderSurface1 = LayerChromium::create(); 847 RefPtr<LayerChromium> renderSurface1 = LayerChromium::create();
660 RefPtr<LayerChromium> renderSurface2 = LayerChromium::create(); 848 RefPtr<LayerChromium> renderSurface2 = LayerChromium::create();
661 RefPtr<LayerChromium> childOfRoot = LayerChromium::create(); 849 RefPtr<LayerChromium> childOfRoot = LayerChromium::create();
662 RefPtr<LayerChromium> childOfRS1 = LayerChromium::create(); 850 RefPtr<LayerChromium> childOfRS1 = LayerChromium::create();
663 RefPtr<LayerChromium> childOfRS2 = LayerChromium::create(); 851 RefPtr<LayerChromium> childOfRS2 = LayerChromium::create();
664 RefPtr<LayerChromium> grandChildOfRoot = LayerChromium::create(); 852 RefPtr<LayerChromium> grandChildOfRoot = LayerChromium::create();
665 RefPtr<LayerChromiumWithForcedDrawsContent> grandChildOfRS1 = adoptRef(new L ayerChromiumWithForcedDrawsContent()); 853 RefPtr<LayerChromiumWithForcedDrawsContent> grandChildOfRS1 = adoptRef(new L ayerChromiumWithForcedDrawsContent());
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 // - add a case that checks if a render surface's replicaTransform is computed correctly. 986 // - add a case that checks if a render surface's replicaTransform is computed correctly.
799 // - test all the conditions under which render surfaces are created 987 // - test all the conditions under which render surfaces are created
800 // - if possible, test all conditions under which render surfaces are not creat ed 988 // - if possible, test all conditions under which render surfaces are not creat ed
801 // - verify that the layer lists of render surfaces are correct, verify that "t argetRenderSurface" values for each layer are correct. 989 // - verify that the layer lists of render surfaces are correct, verify that "t argetRenderSurface" values for each layer are correct.
802 // - test the computation of clip rects and content rects 990 // - test the computation of clip rects and content rects
803 // - test the special cases for mask layers and replica layers 991 // - test the special cases for mask layers and replica layers
804 // - test the other functions in CCLayerTreeHostCommon 992 // - test the other functions in CCLayerTreeHostCommon
805 // 993 //
806 994
807 } // namespace 995 } // namespace
OLDNEW
« no previous file with comments | « Source/WebCore/platform/graphics/chromium/cc/CCSharedQuadState.h ('k') | Source/WebKit/chromium/tests/CCLayerTreeTestCommon.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698