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

Unified Diff: cc/layer_tree_host_common_unittest.cc

Issue 11017044: Remove root layer specialness in calculateDrawTransforms (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added assertion that rounding does not affect exact coverage testing Created 8 years, 2 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
« no previous file with comments | « cc/layer_tree_host_common.cc ('k') | cc/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8e924f66e2b36bdc98f403803fc43a4f842d8527..cf864f9f6b08799ce8290d76654e387b66b09bf8 100644
--- a/cc/layer_tree_host_common_unittest.cc
+++ b/cc/layer_tree_host_common_unittest.cc
@@ -173,11 +173,15 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSingleLayer)
WebTransformationMatrix identityMatrix;
scoped_refptr<Layer> layer = Layer::create();
+ scoped_refptr<Layer> root = Layer::create();
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(1, 2), false);
+ root->addChild(layer);
+
// Case 1: setting the sublayer transform should not affect this layer's draw transform or screen-space transform.
WebTransformationMatrix arbitraryTranslation;
arbitraryTranslation.translate(10, 20);
setLayerPropertiesForTesting(layer.get(), identityMatrix, arbitraryTranslation, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
- executeCalculateDrawTransformsAndVisibility(layer.get());
+ executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedDrawTransform = identityMatrix;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedDrawTransform, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform());
@@ -186,13 +190,13 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSingleLayer)
WebTransformationMatrix translationToCenter;
translationToCenter.translate(5, 6);
setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 12), false);
- executeCalculateDrawTransformsAndVisibility(layer.get());
+ executeCalculateDrawTransformsAndVisibility(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform());
// Case 3: The anchor point by itself (without a layer transform) should have no effect on the transforms.
setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
- executeCalculateDrawTransformsAndVisibility(layer.get());
+ executeCalculateDrawTransformsAndVisibility(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform());
@@ -200,7 +204,7 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSingleLayer)
WebTransformationMatrix positionTransform;
positionTransform.translate(0, 1.2);
setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 1.2f), IntSize(10, 12), false);
- executeCalculateDrawTransformsAndVisibility(layer.get());
+ executeCalculateDrawTransformsAndVisibility(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->screenSpaceTransform());
@@ -209,7 +213,7 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSingleLayer)
WebTransformationMatrix layerTransform;
layerTransform.scale3d(2, 2, 1);
setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 12), false);
- executeCalculateDrawTransformsAndVisibility(layer.get());
+ executeCalculateDrawTransformsAndVisibility(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->screenSpaceTransform());
@@ -218,7 +222,7 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSingleLayer)
translationToAnchor.translate(5, 0);
WebTransformationMatrix expectedResult = translationToAnchor * layerTransform * translationToAnchor.inverse();
setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, FloatPoint(0.5, 0), FloatPoint(0, 0), IntSize(10, 12), false);
- executeCalculateDrawTransformsAndVisibility(layer.get());
+ executeCalculateDrawTransformsAndVisibility(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform());
@@ -227,7 +231,7 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSingleLayer)
// still worth testing to detect accidental regressions.
expectedResult = positionTransform * translationToAnchor * layerTransform * translationToAnchor.inverse();
setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, FloatPoint(0.5, 0), FloatPoint(0, 1.2f), IntSize(10, 12), false);
- executeCalculateDrawTransformsAndVisibility(layer.get());
+ executeCalculateDrawTransformsAndVisibility(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform());
}
@@ -235,17 +239,22 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSingleLayer)
TEST(LayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy)
{
WebTransformationMatrix identityMatrix;
+ scoped_refptr<Layer> root = Layer::create();
scoped_refptr<Layer> parent = Layer::create();
scoped_refptr<Layer> child = Layer::create();
scoped_refptr<Layer> grandChild = Layer::create();
+ root->addChild(parent);
parent->addChild(child);
child->addChild(grandChild);
+ // One-time setup of root layer
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(1, 2), false);
+
// Case 1: parent's anchorPoint should not affect child or grandChild.
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
- executeCalculateDrawTransformsAndVisibility(parent.get());
+ executeCalculateDrawTransformsAndVisibility(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform());
@@ -257,7 +266,7 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy)
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 1.2f), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
- executeCalculateDrawTransformsAndVisibility(parent.get());
+ executeCalculateDrawTransformsAndVisibility(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->drawTransform());
@@ -272,7 +281,7 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy)
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, identityMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
- executeCalculateDrawTransformsAndVisibility(parent.get());
+ executeCalculateDrawTransformsAndVisibility(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTransform());
@@ -293,7 +302,7 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy)
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSublayerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
- executeCalculateDrawTransformsAndVisibility(parent.get());
+ executeCalculateDrawTransformsAndVisibility(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->drawTransform());
@@ -304,7 +313,7 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy)
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSublayerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), true);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
- executeCalculateDrawTransformsAndVisibility(parent.get());
+ executeCalculateDrawTransformsAndVisibility(root.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTransform());
@@ -313,16 +322,21 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy)
TEST(LayerTreeHostCommonTest, verifyTransformsForSingleRenderSurface)
{
+ scoped_refptr<Layer> root = Layer::create();
scoped_refptr<Layer> parent = Layer::create();
scoped_refptr<Layer> child = Layer::create();
scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(new LayerWithForcedDrawsContent());
+ root->addChild(parent);
parent->addChild(child);
child->addChild(grandChild);
+ // One-time setup of root layer
+ WebTransformationMatrix identityMatrix;
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(1, 2), false);
+
// Child is set up so that a new render surface should be created.
child->setOpacity(0.5);
- WebTransformationMatrix identityMatrix;
WebTransformationMatrix parentLayerTransform;
parentLayerTransform.scale3d(1, 0.9, 1);
WebTransformationMatrix parentTranslationToAnchor;
@@ -344,7 +358,7 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSingleRenderSurface)
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSublayerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(100, 120), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(8, 10), false);
- executeCalculateDrawTransformsAndVisibility(parent.get());
+ executeCalculateDrawTransformsAndVisibility(root.get());
// Render surface should have been created now.
ASSERT_TRUE(child->renderSurface());
@@ -365,18 +379,23 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForSingleRenderSurface)
TEST(LayerTreeHostCommonTest, verifyTransformsForReplica)
{
+ scoped_refptr<Layer> root = Layer::create();
scoped_refptr<Layer> parent = Layer::create();
scoped_refptr<Layer> child = Layer::create();
scoped_refptr<Layer> childReplica = Layer::create();
scoped_refptr<LayerWithForcedDrawsContent> grandChild = make_scoped_refptr(new LayerWithForcedDrawsContent());
+ root->addChild(parent);
parent->addChild(child);
child->addChild(grandChild);
child->setReplicaLayer(childReplica.get());
+ // One-time setup of root layer
+ WebTransformationMatrix identityMatrix;
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(1, 2), false);
+
// Child is set up so that a new render surface should be created.
child->setOpacity(0.5);
- WebTransformationMatrix identityMatrix;
WebTransformationMatrix parentLayerTransform;
parentLayerTransform.scale3d(2, 2, 1);
WebTransformationMatrix parentTranslationToAnchor;
@@ -403,7 +422,7 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForReplica)
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(-0.5, -0.5), IntSize(1, 1), false);
setLayerPropertiesForTesting(childReplica.get(), replicaLayerTransform, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(0, 0), false);
- executeCalculateDrawTransformsAndVisibility(parent.get());
+ executeCalculateDrawTransformsAndVisibility(root.get());
// Render surface should have been created now.
ASSERT_TRUE(child->renderSurface());
@@ -422,6 +441,7 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForRenderSurfaceHierarchy)
// - Sanity check on recursion: verify transforms of layers described w.r.t. a render surface that is described w.r.t. an ancestor render surface.
// - verifying that each layer has a reference to the correct renderSurface and renderTarget values.
+ scoped_refptr<Layer> root = Layer::create();
scoped_refptr<Layer> parent = Layer::create();
scoped_refptr<Layer> renderSurface1 = Layer::create();
scoped_refptr<Layer> renderSurface2 = Layer::create();
@@ -433,6 +453,7 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForRenderSurfaceHierarchy)
scoped_refptr<Layer> grandChildOfRoot = Layer::create();
scoped_refptr<LayerWithForcedDrawsContent> grandChildOfRS1 = make_scoped_refptr(new LayerWithForcedDrawsContent());
scoped_refptr<LayerWithForcedDrawsContent> grandChildOfRS2 = make_scoped_refptr(new LayerWithForcedDrawsContent());
+ root->addChild(parent);
parent->addChild(renderSurface1);
parent->addChild(childOfRoot);
renderSurface1->addChild(childOfRS1);
@@ -448,6 +469,10 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForRenderSurfaceHierarchy)
renderSurface1->setOpacity(0.5);
renderSurface2->setOpacity(0.33f);
+ // One-time setup of root layer
+ WebTransformationMatrix identityMatrix;
+ setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(1, 2), false);
+
// All layers in the tree are initialized with an anchor at .25 and a size of (10,10).
// matrix "A" is the composite layer transform used in all layers, centered about the anchor point
// matrix "B" is the sublayer transform used in all layers, centered about the center position of the layer.
@@ -469,7 +494,6 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForRenderSurfaceHierarchy)
WebTransformationMatrix A = translationToAnchor * layerTransform * translationToAnchor.inverse();
WebTransformationMatrix B = translationToCenter * sublayerTransform * translationToCenter.inverse();
WebTransformationMatrix R = A * translationToAnchor * replicaLayerTransform * translationToAnchor.inverse();
- WebTransformationMatrix identityMatrix;
FloatPoint surface1ParentTransformScale = MathUtil::computeTransform2dScaleComponents(A * B);
WebTransformationMatrix surface1SublayerTransform;
@@ -501,11 +525,11 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForRenderSurfaceHierarchy)
setLayerPropertiesForTesting(replicaOfRS1.get(), replicaLayerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(), false);
setLayerPropertiesForTesting(replicaOfRS2.get(), replicaLayerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(), false);
- executeCalculateDrawTransformsAndVisibility(parent.get());
+ executeCalculateDrawTransformsAndVisibility(root.get());
// Only layers that are associated with render surfaces should have an actual renderSurface() value.
//
- ASSERT_TRUE(parent->renderSurface());
+ ASSERT_TRUE(root->renderSurface());
ASSERT_FALSE(childOfRoot->renderSurface());
ASSERT_FALSE(grandChildOfRoot->renderSurface());
@@ -519,9 +543,9 @@ TEST(LayerTreeHostCommonTest, verifyTransformsForRenderSurfaceHierarchy)
// Verify all renderTarget accessors
//
- EXPECT_EQ(parent, parent->renderTarget());
- EXPECT_EQ(parent, childOfRoot->renderTarget());
- EXPECT_EQ(parent, grandChildOfRoot->renderTarget());
+ EXPECT_EQ(root, parent->renderTarget());
+ EXPECT_EQ(root, childOfRoot->renderTarget());
+ EXPECT_EQ(root, grandChildOfRoot->renderTarget());
EXPECT_EQ(renderSurface1, renderSurface1->renderTarget());
EXPECT_EQ(renderSurface1, childOfRS1->renderTarget());
@@ -1297,25 +1321,25 @@ TEST(LayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerThatH
root->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
- WebTransformationMatrix expectedChildTransform;
- expectedChildTransform.multiply(rotationByZ);
-
- WebTransformationMatrix expectedGrandChildTransform;
- expectedGrandChildTransform.multiply(rotationByZ);
+ WebTransformationMatrix identityMatrix;
- EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform());
// Case 2: root scrollDelta of 10, 10
- root->setScrollDelta(IntSize(10, 10));
+ root->setScrollDelta(IntSize(10, 20));
executeCalculateDrawTransformsAndVisibility(root.get());
- // Here the child is affected by scrollDelta, but the fixed position grandChild should not be affected.
- expectedChildTransform.makeIdentity();
- expectedChildTransform.translate(-10, -10); // the scrollDelta
- expectedChildTransform.multiply(rotationByZ);
+ // The child is affected by scrollDelta, but it is already implcitly accounted for by
+ // the child's target surface (i.e. the root renderSurface). The grandChild is not
+ // affected by the scrollDelta, so its drawTransform needs to explicitly
+ // inverse-compensate for the scroll that's embedded in the target surface.
+ WebTransformationMatrix expectedGrandChildTransform;
+ expectedGrandChildTransform.multiply(rotationByZ.inverse());
+ expectedGrandChildTransform.translate(10, 20); // explicit canceling out the scrollDelta that gets embedded in the fixed position layer's surface.
+ expectedGrandChildTransform.multiply(rotationByZ);
- EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
}
« no previous file with comments | « cc/layer_tree_host_common.cc ('k') | cc/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698