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

Unified Diff: cc/layer_tree_host_common_unittest.cc

Issue 12280014: cc: Don't consider HUD layer for touches (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moved funcs around Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: cc/layer_tree_host_common_unittest.cc
diff --git a/cc/layer_tree_host_common_unittest.cc b/cc/layer_tree_host_common_unittest.cc
index 3724971481965ee38f3ab54f8f52b95460c83997..db2e0016eaeb849f5da9fac837e0e37381a50e26 100644
--- a/cc/layer_tree_host_common_unittest.cc
+++ b/cc/layer_tree_host_common_unittest.cc
@@ -2906,786 +2906,6 @@ TEST(LayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3dForFlatteningS
EXPECT_EQ(child1->id(), renderSurfaceLayerList[1]->renderSurface()->layerList()[1]->id());
}
-TEST(LayerTreeHostCommonTest, verifyHitTestingForEmptyLayerList)
-{
- // Hit testing on an empty renderSurfaceLayerList should return a null pointer.
- std::vector<LayerImpl*> renderSurfaceLayerList;
-
- gfx::Point testPoint(0, 0);
- LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- testPoint = gfx::Point(10, 20);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-}
-
-TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayer)
-{
- FakeImplProxy proxy;
- FakeLayerTreeHostImpl hostImpl(&proxy);
- scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345);
-
- gfx::Transform identityMatrix;
- gfx::PointF anchor(0, 0);
- gfx::PointF position(0, 0);
- gfx::Size bounds(100, 100);
- setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- root->setDrawsContent(true);
-
- std::vector<LayerImpl*> renderSurfaceLayerList;
- int dummyMaxTextureSize = 512;
- LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1, 1, dummyMaxTextureSize, false, renderSurfaceLayerList, false);
-
- // Sanity check the scenario we just created.
- ASSERT_EQ(1u, renderSurfaceLayerList.size());
- ASSERT_EQ(1u, root->renderSurface()->layerList().size());
-
- // Hit testing for a point outside the layer should return a null pointer.
- gfx::Point testPoint(101, 101);
- LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- testPoint = gfx::Point(-1, -1);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- // Hit testing for a point inside should return the root layer.
- testPoint = gfx::Point(1, 1);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(12345, resultLayer->id());
-
- testPoint = gfx::Point(99, 99);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(12345, resultLayer->id());
-}
-
-TEST(LayerTreeHostCommonTest, verifyHitTestingForUninvertibleTransform)
-{
- FakeImplProxy proxy;
- FakeLayerTreeHostImpl hostImpl(&proxy);
- scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345);
-
- gfx::Transform uninvertibleTransform;
- uninvertibleTransform.matrix().setDouble(0, 0, 0);
- uninvertibleTransform.matrix().setDouble(1, 1, 0);
- uninvertibleTransform.matrix().setDouble(2, 2, 0);
- uninvertibleTransform.matrix().setDouble(3, 3, 0);
- ASSERT_FALSE(uninvertibleTransform.IsInvertible());
-
- gfx::Transform identityMatrix;
- gfx::PointF anchor(0, 0);
- gfx::PointF position(0, 0);
- gfx::Size bounds(100, 100);
- setLayerPropertiesForTesting(root.get(), uninvertibleTransform, identityMatrix, anchor, position, bounds, false);
- root->setDrawsContent(true);
-
- std::vector<LayerImpl*> renderSurfaceLayerList;
- int dummyMaxTextureSize = 512;
- LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1, 1, dummyMaxTextureSize, false, renderSurfaceLayerList, false);
-
- // Sanity check the scenario we just created.
- ASSERT_EQ(1u, renderSurfaceLayerList.size());
- ASSERT_EQ(1u, root->renderSurface()->layerList().size());
- ASSERT_FALSE(root->screenSpaceTransform().IsInvertible());
-
- // Hit testing any point should not hit the layer. If the invertible matrix is
- // accidentally ignored and treated like an identity, then the hit testing will
- // incorrectly hit the layer when it shouldn't.
- gfx::Point testPoint(1, 1);
- LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- testPoint = gfx::Point(10, 10);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- testPoint = gfx::Point(10, 30);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- testPoint = gfx::Point(50, 50);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- testPoint = gfx::Point(67, 48);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- testPoint = gfx::Point(99, 99);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- testPoint = gfx::Point(-1, -1);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-}
-
-TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePositionedLayer)
-{
- FakeImplProxy proxy;
- FakeLayerTreeHostImpl hostImpl(&proxy);
- scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345);
-
- gfx::Transform identityMatrix;
- gfx::PointF anchor(0, 0);
- gfx::PointF position(50, 50); // this layer is positioned, and hit testing should correctly know where the layer is located.
- gfx::Size bounds(100, 100);
- setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- root->setDrawsContent(true);
-
- std::vector<LayerImpl*> renderSurfaceLayerList;
- int dummyMaxTextureSize = 512;
- LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1, 1, dummyMaxTextureSize, false, renderSurfaceLayerList, false);
-
- // Sanity check the scenario we just created.
- ASSERT_EQ(1u, renderSurfaceLayerList.size());
- ASSERT_EQ(1u, root->renderSurface()->layerList().size());
-
- // Hit testing for a point outside the layer should return a null pointer.
- gfx::Point testPoint(49, 49);
- LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- // Even though the layer exists at (101, 101), it should not be visible there since the root renderSurface would clamp it.
- testPoint = gfx::Point(101, 101);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- // Hit testing for a point inside should return the root layer.
- testPoint = gfx::Point(51, 51);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(12345, resultLayer->id());
-
- testPoint = gfx::Point(99, 99);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(12345, resultLayer->id());
-}
-
-TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer)
-{
- FakeImplProxy proxy;
- FakeLayerTreeHostImpl hostImpl(&proxy);
- scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345);
-
- gfx::Transform identityMatrix;
- gfx::Transform rotation45DegreesAboutCenter;
- rotation45DegreesAboutCenter.Translate(50, 50);
- rotation45DegreesAboutCenter.RotateAboutZAxis(45);
- rotation45DegreesAboutCenter.Translate(-50, -50);
- gfx::PointF anchor(0, 0);
- gfx::PointF position(0, 0);
- gfx::Size bounds(100, 100);
- setLayerPropertiesForTesting(root.get(), rotation45DegreesAboutCenter, identityMatrix, anchor, position, bounds, false);
- root->setDrawsContent(true);
-
- std::vector<LayerImpl*> renderSurfaceLayerList;
- int dummyMaxTextureSize = 512;
- LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1, 1, dummyMaxTextureSize, false, renderSurfaceLayerList, false);
-
- // Sanity check the scenario we just created.
- ASSERT_EQ(1u, renderSurfaceLayerList.size());
- ASSERT_EQ(1u, root->renderSurface()->layerList().size());
-
- // Hit testing for points outside the layer.
- // These corners would have been inside the un-transformed layer, but they should not hit the correctly transformed layer.
- gfx::Point testPoint(99, 99);
- LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- testPoint = gfx::Point(1, 1);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- // Hit testing for a point inside should return the root layer.
- testPoint = gfx::Point(1, 50);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(12345, resultLayer->id());
-
- // Hit testing the corners that would overlap the unclipped layer, but are outside the clipped region.
- testPoint = gfx::Point(50, -1);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_FALSE(resultLayer);
-
- testPoint = gfx::Point(-1, 50);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_FALSE(resultLayer);
-}
-
-TEST(LayerTreeHostCommonTest, verifyHitTestingForSinglePerspectiveLayer)
-{
- FakeImplProxy proxy;
- FakeLayerTreeHostImpl hostImpl(&proxy);
- scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 12345);
-
- gfx::Transform identityMatrix;
-
- // perspectiveProjectionAboutCenter * translationByZ is designed so that the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50).
- gfx::Transform perspectiveProjectionAboutCenter;
- perspectiveProjectionAboutCenter.Translate(50, 50);
- perspectiveProjectionAboutCenter.ApplyPerspectiveDepth(1);
- perspectiveProjectionAboutCenter.Translate(-50, -50);
- gfx::Transform translationByZ;
- translationByZ.Translate3d(0, 0, -1);
-
- gfx::PointF anchor(0, 0);
- gfx::PointF position(0, 0);
- gfx::Size bounds(100, 100);
- setLayerPropertiesForTesting(root.get(), perspectiveProjectionAboutCenter * translationByZ, identityMatrix, anchor, position, bounds, false);
- root->setDrawsContent(true);
-
- std::vector<LayerImpl*> renderSurfaceLayerList;
- int dummyMaxTextureSize = 512;
- LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1, 1, dummyMaxTextureSize, false, renderSurfaceLayerList, false);
-
- // Sanity check the scenario we just created.
- ASSERT_EQ(1u, renderSurfaceLayerList.size());
- ASSERT_EQ(1u, root->renderSurface()->layerList().size());
-
- // Hit testing for points outside the layer.
- // These corners would have been inside the un-transformed layer, but they should not hit the correctly transformed layer.
- gfx::Point testPoint(24, 24);
- LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- testPoint = gfx::Point(76, 76);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- // Hit testing for a point inside should return the root layer.
- testPoint = gfx::Point(26, 26);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(12345, resultLayer->id());
-
- testPoint = gfx::Point(74, 74);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(12345, resultLayer->id());
-}
-
-TEST(LayerTreeHostCommonTest, verifyHitTestingForSingleLayerWithScaledContents)
-{
- // A layer's visibleContentRect is actually in the layer's content space. The
- // screenSpaceTransform converts from the layer's origin space to screen space. This
- // test makes sure that hit testing works correctly accounts for the contents scale.
- // A contentsScale that is not 1 effectively forces a non-identity transform between
- // layer's content space and layer's origin space. The hit testing code must take this into account.
- //
- // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
- // contentsScale is ignored, then hit testing will mis-interpret the visibleContentRect
- // as being larger than the actual bounds of the layer.
- //
- FakeImplProxy proxy;
- FakeLayerTreeHostImpl hostImpl(&proxy);
- scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 1);
-
- gfx::Transform identityMatrix;
- gfx::PointF anchor(0, 0);
-
- setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
-
- {
- gfx::PointF position(25, 25);
- gfx::Size bounds(50, 50);
- scoped_ptr<LayerImpl> testLayer = LayerImpl::create(hostImpl.activeTree(), 12345);
- setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
-
- // override contentBounds and contentsScale
- testLayer->setContentBounds(gfx::Size(100, 100));
- testLayer->setContentsScale(2, 2);
-
- testLayer->setDrawsContent(true);
- root->addChild(testLayer.Pass());
- }
-
- std::vector<LayerImpl*> renderSurfaceLayerList;
- int dummyMaxTextureSize = 512;
- LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1, 1, dummyMaxTextureSize, false, renderSurfaceLayerList, false);
-
- // Sanity check the scenario we just created.
- // The visibleContentRect for testLayer is actually 100x100, even though its layout size is 50x50, positioned at 25x25.
- LayerImpl* testLayer = root->children()[0];
- EXPECT_RECT_EQ(gfx::Rect(gfx::Point(), gfx::Size(100, 100)), testLayer->visibleContentRect());
- ASSERT_EQ(1u, renderSurfaceLayerList.size());
- ASSERT_EQ(1u, root->renderSurface()->layerList().size());
-
- // Hit testing for a point outside the layer should return a null pointer (the root layer does not draw content, so it will not be hit tested either).
- gfx::Point testPoint(101, 101);
- LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- testPoint = gfx::Point(24, 24);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- testPoint = gfx::Point(76, 76);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- // Hit testing for a point inside should return the test layer.
- testPoint = gfx::Point(26, 26);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(12345, resultLayer->id());
-
- testPoint = gfx::Point(74, 74);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(12345, resultLayer->id());
-}
-
-TEST(LayerTreeHostCommonTest, verifyHitTestingForSimpleClippedLayer)
-{
- // Test that hit-testing will only work for the visible portion of a layer, and not
- // the entire layer bounds. Here we just test the simple axis-aligned case.
- gfx::Transform identityMatrix;
- gfx::PointF anchor(0, 0);
-
- FakeImplProxy proxy;
- FakeLayerTreeHostImpl hostImpl(&proxy);
- scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 1);
- setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
-
- {
- scoped_ptr<LayerImpl> clippingLayer = LayerImpl::create(hostImpl.activeTree(), 123);
- gfx::PointF position(25, 25); // this layer is positioned, and hit testing should correctly know where the layer is located.
- gfx::Size bounds(50, 50);
- setLayerPropertiesForTesting(clippingLayer.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- clippingLayer->setMasksToBounds(true);
-
- scoped_ptr<LayerImpl> child = LayerImpl::create(hostImpl.activeTree(), 456);
- position = gfx::PointF(-50, -50);
- bounds = gfx::Size(300, 300);
- setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- child->setDrawsContent(true);
- clippingLayer->addChild(child.Pass());
- root->addChild(clippingLayer.Pass());
- }
-
- std::vector<LayerImpl*> renderSurfaceLayerList;
- int dummyMaxTextureSize = 512;
- LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1, 1, dummyMaxTextureSize, false, renderSurfaceLayerList, false);
-
- // Sanity check the scenario we just created.
- ASSERT_EQ(1u, renderSurfaceLayerList.size());
- ASSERT_EQ(1u, root->renderSurface()->layerList().size());
- ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id());
-
- // Hit testing for a point outside the layer should return a null pointer.
- // Despite the child layer being very large, it should be clipped to the root layer's bounds.
- gfx::Point testPoint(24, 24);
- LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- // Even though the layer exists at (101, 101), it should not be visible there since the clippingLayer would clamp it.
- testPoint = gfx::Point(76, 76);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- // Hit testing for a point inside should return the child layer.
- testPoint = gfx::Point(26, 26);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(456, resultLayer->id());
-
- testPoint = gfx::Point(74, 74);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(456, resultLayer->id());
-}
-
-TEST(LayerTreeHostCommonTest, verifyHitTestingForMultiClippedRotatedLayer)
-{
- // This test checks whether hit testing correctly avoids hit testing with multiple
- // ancestors that clip in non axis-aligned ways. To pass this test, the hit testing
- // algorithm needs to recognize that multiple parent layers may clip the layer, and
- // should not actually hit those clipped areas.
- //
- // The child and grandChild layers are both initialized to clip the rotatedLeaf. The
- // child layer is rotated about the top-left corner, so that the root + child clips
- // combined create a triangle. The rotatedLeaf will only be visible where it overlaps
- // this triangle.
- //
- FakeImplProxy proxy;
- FakeLayerTreeHostImpl hostImpl(&proxy);
- scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 123);
-
- gfx::Transform identityMatrix;
- gfx::PointF anchor(0, 0);
- gfx::PointF position(0, 0);
- gfx::Size bounds(100, 100);
- setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- root->setMasksToBounds(true);
-
- {
- scoped_ptr<LayerImpl> child = LayerImpl::create(hostImpl.activeTree(), 456);
- scoped_ptr<LayerImpl> grandChild = LayerImpl::create(hostImpl.activeTree(), 789);
- scoped_ptr<LayerImpl> rotatedLeaf = LayerImpl::create(hostImpl.activeTree(), 2468);
-
- position = gfx::PointF(10, 10);
- bounds = gfx::Size(80, 80);
- setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- child->setMasksToBounds(true);
-
- gfx::Transform rotation45DegreesAboutCorner;
- rotation45DegreesAboutCorner.RotateAboutZAxis(45);
-
- position = gfx::PointF(0, 0); // remember, positioned with respect to its parent which is already at 10, 10
- bounds = gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100.
- setLayerPropertiesForTesting(grandChild.get(), rotation45DegreesAboutCorner, identityMatrix, anchor, position, bounds, false);
- grandChild->setMasksToBounds(true);
-
- // Rotates about the center of the layer
- gfx::Transform rotatedLeafTransform;
- rotatedLeafTransform.Translate(-10, -10); // cancel out the grandParent's position
- rotatedLeafTransform.RotateAboutZAxis(-45); // cancel out the corner 45-degree rotation of the parent.
- rotatedLeafTransform.Translate(50, 50);
- rotatedLeafTransform.RotateAboutZAxis(45);
- rotatedLeafTransform.Translate(-50, -50);
- position = gfx::PointF(0, 0);
- bounds = gfx::Size(100, 100);
- setLayerPropertiesForTesting(rotatedLeaf.get(), rotatedLeafTransform, identityMatrix, anchor, position, bounds, false);
- rotatedLeaf->setDrawsContent(true);
-
- grandChild->addChild(rotatedLeaf.Pass());
- child->addChild(grandChild.Pass());
- root->addChild(child.Pass());
- }
-
- std::vector<LayerImpl*> renderSurfaceLayerList;
- int dummyMaxTextureSize = 512;
- LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1, 1, dummyMaxTextureSize, false, renderSurfaceLayerList, false);
-
- // Sanity check the scenario we just created.
- // The grandChild is expected to create a renderSurface because it masksToBounds and is not axis aligned.
- ASSERT_EQ(2u, renderSurfaceLayerList.size());
- ASSERT_EQ(1u, renderSurfaceLayerList[0]->renderSurface()->layerList().size());
- ASSERT_EQ(789, renderSurfaceLayerList[0]->renderSurface()->layerList()[0]->id()); // grandChild's surface.
- ASSERT_EQ(1u, renderSurfaceLayerList[1]->renderSurface()->layerList().size());
- ASSERT_EQ(2468, renderSurfaceLayerList[1]->renderSurface()->layerList()[0]->id());
-
- // (11, 89) is close to the the bottom left corner within the clip, but it is not inside the layer.
- gfx::Point testPoint(11, 89);
- LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- // Closer inwards from the bottom left will overlap the layer.
- testPoint = gfx::Point(25, 75);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(2468, resultLayer->id());
-
- // (4, 50) is inside the unclipped layer, but that corner of the layer should be
- // clipped away by the grandParent and should not get hit. If hit testing blindly uses
- // visibleContentRect without considering how parent may clip the layer, then hit
- // testing would accidentally think that the point successfully hits the layer.
- testPoint = gfx::Point(4, 50);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- // (11, 50) is inside the layer and within the clipped area.
- testPoint = gfx::Point(11, 50);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(2468, resultLayer->id());
-
- // Around the middle, just to the right and up, would have hit the layer except that
- // that area should be clipped away by the parent.
- testPoint = gfx::Point(51, 51);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- // Around the middle, just to the left and down, should successfully hit the layer.
- testPoint = gfx::Point(49, 51);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(2468, resultLayer->id());
-}
-
-TEST(LayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer)
-{
- // This test checks that hit testing code does not accidentally clip to layer
- // bounds for a layer that actually does not clip.
- gfx::Transform identityMatrix;
- gfx::PointF anchor(0, 0);
-
- FakeImplProxy proxy;
- FakeLayerTreeHostImpl hostImpl(&proxy);
- scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 1);
- setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, gfx::PointF(0, 0), gfx::Size(100, 100), false);
-
- {
- scoped_ptr<LayerImpl> intermediateLayer = LayerImpl::create(hostImpl.activeTree(), 123);
- gfx::PointF position(10, 10); // this layer is positioned, and hit testing should correctly know where the layer is located.
- gfx::Size bounds(50, 50);
- setLayerPropertiesForTesting(intermediateLayer.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- // Sanity check the intermediate layer should not clip.
- ASSERT_FALSE(intermediateLayer->masksToBounds());
- ASSERT_FALSE(intermediateLayer->maskLayer());
-
- // The child of the intermediateLayer is translated so that it does not overlap intermediateLayer at all.
- // If child is incorrectly clipped, we would not be able to hit it successfully.
- scoped_ptr<LayerImpl> child = LayerImpl::create(hostImpl.activeTree(), 456);
- position = gfx::PointF(60, 60); // 70, 70 in screen space
- bounds = gfx::Size(20, 20);
- setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- child->setDrawsContent(true);
- intermediateLayer->addChild(child.Pass());
- root->addChild(intermediateLayer.Pass());
- }
-
- std::vector<LayerImpl*> renderSurfaceLayerList;
- int dummyMaxTextureSize = 512;
- LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1, 1, dummyMaxTextureSize, false, renderSurfaceLayerList, false);
-
- // Sanity check the scenario we just created.
- ASSERT_EQ(1u, renderSurfaceLayerList.size());
- ASSERT_EQ(1u, root->renderSurface()->layerList().size());
- ASSERT_EQ(456, root->renderSurface()->layerList()[0]->id());
-
- // Hit testing for a point outside the layer should return a null pointer.
- gfx::Point testPoint(69, 69);
- LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- testPoint = gfx::Point(91, 91);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- EXPECT_FALSE(resultLayer);
-
- // Hit testing for a point inside should return the child layer.
- testPoint = gfx::Point(71, 71);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(456, resultLayer->id());
-
- testPoint = gfx::Point(89, 89);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(456, resultLayer->id());
-}
-
-
-TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayers)
-{
- FakeImplProxy proxy;
- FakeLayerTreeHostImpl hostImpl(&proxy);
- scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 1);
-
- gfx::Transform identityMatrix;
- gfx::PointF anchor(0, 0);
- gfx::PointF position(0, 0);
- gfx::Size bounds(100, 100);
- setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- root->setDrawsContent(true);
-
- {
- // child 1 and child2 are initialized to overlap between x=50 and x=60.
- // grandChild is set to overlap both child1 and child2 between y=50 and y=60.
- // The expected stacking order is:
- // (front) child2, (second) grandChild, (third) child1, and (back) the root layer behind all other layers.
-
- scoped_ptr<LayerImpl> child1 = LayerImpl::create(hostImpl.activeTree(), 2);
- scoped_ptr<LayerImpl> child2 = LayerImpl::create(hostImpl.activeTree(), 3);
- scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(hostImpl.activeTree(), 4);
-
- position = gfx::PointF(10, 10);
- bounds = gfx::Size(50, 50);
- setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- child1->setDrawsContent(true);
-
- position = gfx::PointF(50, 10);
- bounds = gfx::Size(50, 50);
- setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- child2->setDrawsContent(true);
-
- // Remember that grandChild is positioned with respect to its parent (i.e. child1).
- // In screen space, the intended position is (10, 50), with size 100 x 50.
- position = gfx::PointF(0, 40);
- bounds = gfx::Size(100, 50);
- setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- grandChild1->setDrawsContent(true);
-
- child1->addChild(grandChild1.Pass());
- root->addChild(child1.Pass());
- root->addChild(child2.Pass());
- }
-
- LayerImpl* child1 = root->children()[0];
- LayerImpl* child2 = root->children()[1];
- LayerImpl* grandChild1 = child1->children()[0];
-
- std::vector<LayerImpl*> renderSurfaceLayerList;
- int dummyMaxTextureSize = 512;
- LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1, 1, dummyMaxTextureSize, false, renderSurfaceLayerList, false);
-
- // Sanity check the scenario we just created.
- ASSERT_TRUE(child1);
- ASSERT_TRUE(child2);
- ASSERT_TRUE(grandChild1);
- ASSERT_EQ(1u, renderSurfaceLayerList.size());
- ASSERT_EQ(4u, root->renderSurface()->layerList().size());
- ASSERT_EQ(1, root->renderSurface()->layerList()[0]->id()); // root layer
- ASSERT_EQ(2, root->renderSurface()->layerList()[1]->id()); // child1
- ASSERT_EQ(4, root->renderSurface()->layerList()[2]->id()); // grandChild1
- ASSERT_EQ(3, root->renderSurface()->layerList()[3]->id()); // child2
-
- // Nothing overlaps the rootLayer at (1, 1), so hit testing there should find the root layer.
- gfx::Point testPoint = gfx::Point(1, 1);
- LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(1, resultLayer->id());
-
- // At (15, 15), child1 and root are the only layers. child1 is expected to be on top.
- testPoint = gfx::Point(15, 15);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(2, resultLayer->id());
-
- // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
- testPoint = gfx::Point(51, 20);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(3, resultLayer->id());
-
- // At (80, 51), child2 and grandChild1 overlap. child2 is expected to be on top.
- testPoint = gfx::Point(80, 51);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(3, resultLayer->id());
-
- // At (51, 51), all layers overlap each other. child2 is expected to be on top of all other layers.
- testPoint = gfx::Point(51, 51);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(3, resultLayer->id());
-
- // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to be on top.
- testPoint = gfx::Point(20, 51);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(4, resultLayer->id());
-}
-
-TEST(LayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists)
-{
- //
- // The geometry is set up similarly to the previous case, but
- // all layers are forced to be renderSurfaces now.
- //
- FakeImplProxy proxy;
- FakeLayerTreeHostImpl hostImpl(&proxy);
- scoped_ptr<LayerImpl> root = LayerImpl::create(hostImpl.activeTree(), 1);
-
- gfx::Transform identityMatrix;
- gfx::PointF anchor(0, 0);
- gfx::PointF position(0, 0);
- gfx::Size bounds(100, 100);
- setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- root->setDrawsContent(true);
-
- {
- // child 1 and child2 are initialized to overlap between x=50 and x=60.
- // grandChild is set to overlap both child1 and child2 between y=50 and y=60.
- // The expected stacking order is:
- // (front) child2, (second) grandChild, (third) child1, and (back) the root layer behind all other layers.
-
- scoped_ptr<LayerImpl> child1 = LayerImpl::create(hostImpl.activeTree(), 2);
- scoped_ptr<LayerImpl> child2 = LayerImpl::create(hostImpl.activeTree(), 3);
- scoped_ptr<LayerImpl> grandChild1 = LayerImpl::create(hostImpl.activeTree(), 4);
-
- position = gfx::PointF(10, 10);
- bounds = gfx::Size(50, 50);
- setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- child1->setDrawsContent(true);
- child1->setForceRenderSurface(true);
-
- position = gfx::PointF(50, 10);
- bounds = gfx::Size(50, 50);
- setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- child2->setDrawsContent(true);
- child2->setForceRenderSurface(true);
-
- // Remember that grandChild is positioned with respect to its parent (i.e. child1).
- // In screen space, the intended position is (10, 50), with size 100 x 50.
- position = gfx::PointF(0, 40);
- bounds = gfx::Size(100, 50);
- setLayerPropertiesForTesting(grandChild1.get(), identityMatrix, identityMatrix, anchor, position, bounds, false);
- grandChild1->setDrawsContent(true);
- grandChild1->setForceRenderSurface(true);
-
- child1->addChild(grandChild1.Pass());
- root->addChild(child1.Pass());
- root->addChild(child2.Pass());
- }
-
- LayerImpl* child1 = root->children()[0];
- LayerImpl* child2 = root->children()[1];
- LayerImpl* grandChild1 = child1->children()[0];
-
- std::vector<LayerImpl*> renderSurfaceLayerList;
- int dummyMaxTextureSize = 512;
- LayerTreeHostCommon::calculateDrawProperties(root.get(), root->bounds(), 1, 1, dummyMaxTextureSize, false, renderSurfaceLayerList, false);
-
- // Sanity check the scenario we just created.
- ASSERT_TRUE(child1);
- ASSERT_TRUE(child2);
- ASSERT_TRUE(grandChild1);
- ASSERT_TRUE(child1->renderSurface());
- ASSERT_TRUE(child2->renderSurface());
- ASSERT_TRUE(grandChild1->renderSurface());
- ASSERT_EQ(4u, renderSurfaceLayerList.size());
- ASSERT_EQ(3u, root->renderSurface()->layerList().size()); // The root surface has the root layer, and child1's and child2's renderSurfaces.
- ASSERT_EQ(2u, child1->renderSurface()->layerList().size()); // The child1 surface has the child1 layer and grandChild1's renderSurface.
- ASSERT_EQ(1u, child2->renderSurface()->layerList().size());
- ASSERT_EQ(1u, grandChild1->renderSurface()->layerList().size());
- ASSERT_EQ(1, renderSurfaceLayerList[0]->id()); // root layer
- ASSERT_EQ(2, renderSurfaceLayerList[1]->id()); // child1
- ASSERT_EQ(4, renderSurfaceLayerList[2]->id()); // grandChild1
- ASSERT_EQ(3, renderSurfaceLayerList[3]->id()); // child2
-
- // Nothing overlaps the rootLayer at (1, 1), so hit testing there should find the root layer.
- gfx::Point testPoint = gfx::Point(1, 1);
- LayerImpl* resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(1, resultLayer->id());
-
- // At (15, 15), child1 and root are the only layers. child1 is expected to be on top.
- testPoint = gfx::Point(15, 15);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(2, resultLayer->id());
-
- // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
- testPoint = gfx::Point(51, 20);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(3, resultLayer->id());
-
- // At (80, 51), child2 and grandChild1 overlap. child2 is expected to be on top.
- testPoint = gfx::Point(80, 51);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(3, resultLayer->id());
-
- // At (51, 51), all layers overlap each other. child2 is expected to be on top of all other layers.
- testPoint = gfx::Point(51, 51);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(3, resultLayer->id());
-
- // At (20, 51), child1 and grandChild1 overlap. grandChild1 is expected to be on top.
- testPoint = gfx::Point(20, 51);
- resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, renderSurfaceLayerList);
- ASSERT_TRUE(resultLayer);
- EXPECT_EQ(4, resultLayer->id());
-}
-
TEST(LayerTreeHostCommonTest, verifyHitCheckingTouchHandlerRegionsForEmptyLayerList)
{
// Hit checking on an empty renderSurfaceLayerList should return a null pointer.

Powered by Google App Engine
This is Rietveld 408576698