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 15776469e6911b7405d9179195c8d3e60451b0b2..88dee5b8e60ed2d0ea98412a8491c35ea946598e 100644 |
--- a/cc/layer_tree_host_common_unittest.cc |
+++ b/cc/layer_tree_host_common_unittest.cc |
@@ -113,6 +113,22 @@ private: |
} |
}; |
+class LayerCanClipSelf : public Layer { |
+public: |
+ LayerCanClipSelf() |
+ : Layer() |
+ { |
+ } |
+ |
+ virtual bool drawsContent() const OVERRIDE { return true; } |
+ virtual bool canClipSelf() const OVERRIDE { return true; } |
+ |
+private: |
+ virtual ~LayerCanClipSelf() |
+ { |
+ } |
+}; |
+ |
class MockContentLayerClient : public ContentLayerClient { |
public: |
MockContentLayerClient() { } |
@@ -335,6 +351,7 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSingleRenderSurface) |
parentTranslationToAnchor.Translate(25, 30); |
gfx::Transform parentSublayerMatrix; |
parentSublayerMatrix.Scale3d(0.9, 1, 3.3); |
+ |
gfx::Transform parentTranslationToCenter; |
parentTranslationToCenter.Translate(50, 60); |
gfx::Transform parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * MathUtil::inverse(parentTranslationToAnchor) |
@@ -369,6 +386,91 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSingleRenderSurface) |
EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->renderTarget()->renderSurface()->screenSpaceTransform()); |
} |
+TEST(LayerTreeHostCommonTest, verifySeparateRenderTargetRequirement) |
+{ |
+ { |
+ scoped_refptr<Layer> root = Layer::create(); |
+ scoped_refptr<Layer> parent = Layer::create(); |
+ scoped_refptr<Layer> child = Layer::create(); |
+ scoped_refptr<Layer> grandChild = make_scoped_refptr(new LayerCanClipSelf()); |
+ root->addChild(parent); |
+ parent->addChild(child); |
+ child->addChild(grandChild); |
+ parent->setMasksToBounds(true); |
+ child->setMasksToBounds(true); |
+ |
+ gfx::Transform identityMatrix; |
+ gfx::Transform parentLayerTransform; |
+ gfx::Transform parentSublayerMatrix; |
+ gfx::Transform childLayerMatrix; |
+ |
+ // No render surface should exist yet. |
+ ASSERT_FALSE(root->renderSurface()); |
danakj
2012/12/19 22:46:56
nit: you can use EXPECT_ for these tests. generall
|
+ ASSERT_FALSE(parent->renderSurface()); |
+ ASSERT_FALSE(child->renderSurface()); |
+ ASSERT_FALSE(grandChild->renderSurface()); |
+ |
+ // One-time setup of root layer |
+ parentLayerTransform.Scale3d(1, 0.9, 1); |
+ parentSublayerMatrix.Scale3d(0.9, 1, 3.3); |
+ childLayerMatrix.Rotate(20); |
+ |
+ setLayerPropertiesForTesting(root .get(), identityMatrix , identityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 1, 2), false); |
danakj
2012/12/19 22:46:56
these extra spaces are funny, i'd remove them. lin
whunt
2013/01/04 19:12:27
I'm actually surprised about the push-back I get f
|
+ setLayerPropertiesForTesting(parent .get(), parentLayerTransform, parentSublayerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), false); |
+ setLayerPropertiesForTesting(child .get(), childLayerMatrix , identityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 16, 18), false); |
+ setLayerPropertiesForTesting(grandChild.get(), identityMatrix , identityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 8, 10), false); |
+ |
+ executeCalculateDrawProperties(root.get()); |
+ |
+ // Render surfaces should have been created according to clipping rules now (grandchild can clip self). |
+ ASSERT_TRUE(root->renderSurface()); |
+ ASSERT_FALSE(parent->renderSurface()); |
+ ASSERT_FALSE(child->renderSurface()); |
+ ASSERT_FALSE(grandChild->renderSurface()); |
+ } |
+ { |
danakj
2012/12/19 22:46:56
if you made LayerCanClipSelf let you change the ca
|
+ scoped_refptr<Layer> root = Layer::create(); |
+ scoped_refptr<Layer> parent = Layer::create(); |
+ scoped_refptr<Layer> child = Layer::create(); |
+ // This layer cannot clip itself, a feature we are testing here. |
+ scoped_refptr<Layer> grandChild = make_scoped_refptr(new LayerWithForcedDrawsContent()); |
+ root->addChild(parent); |
+ parent->addChild(child); |
+ child->addChild(grandChild); |
+ parent->setMasksToBounds(true); |
+ child->setMasksToBounds(true); |
+ |
+ gfx::Transform identityMatrix; |
+ gfx::Transform parentLayerTransform; |
+ gfx::Transform parentSublayerMatrix; |
+ gfx::Transform childLayerMatrix; |
+ |
+ // No render surface should exist yet. |
+ ASSERT_FALSE(root->renderSurface()); |
+ ASSERT_FALSE(parent->renderSurface()); |
+ ASSERT_FALSE(child->renderSurface()); |
+ ASSERT_FALSE(grandChild->renderSurface()); |
+ |
+ // One-time setup of root layer |
+ parentLayerTransform.Scale3d(1, 0.9, 1); |
+ parentSublayerMatrix.Scale3d(0.9, 1, 3.3); |
+ childLayerMatrix.Rotate(20); |
+ |
+ setLayerPropertiesForTesting(root .get(), identityMatrix , identityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 1, 2), false); |
danakj
2012/12/19 22:46:56
same here
|
+ setLayerPropertiesForTesting(parent .get(), parentLayerTransform, parentSublayerMatrix, gfx::PointF(0.25, 0.25), gfx::PointF(0, 0), gfx::Size(100, 120), false); |
+ setLayerPropertiesForTesting(child .get(), childLayerMatrix , identityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 16, 18), false); |
+ setLayerPropertiesForTesting(grandChild.get(), identityMatrix , identityMatrix , gfx::PointF( 0, 0), gfx::PointF(0, 0), gfx::Size( 8, 10), false); |
+ |
+ executeCalculateDrawProperties(root.get()); |
+ |
+ // Render surfaces should have been created according to clipping rules now (grandchild can't clip self). |
+ ASSERT_TRUE(root->renderSurface()); |
+ ASSERT_FALSE(parent->renderSurface()); |
+ ASSERT_TRUE(child->renderSurface()); |
+ ASSERT_FALSE(grandChild->renderSurface()); |
+ } |
+} |
+ |
TEST(LayerTreeHostCommonTest, verifyTransformsForReplica) |
{ |
scoped_refptr<Layer> root = Layer::create(); |