diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 23:34:45 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 23:34:45 +0000 |
commit | f89f563c49877af2093975735c2abf6a56d1a1e5 (patch) | |
tree | a28df27a2417dfb6fc10a3866e79db1ab6b021a4 /cc/layer_tree_host_common_unittest.cc | |
parent | a7c080169597ddb6a9ec0a160f6dd39caee829d4 (diff) | |
download | chromium_src-f89f563c49877af2093975735c2abf6a56d1a1e5.zip chromium_src-f89f563c49877af2093975735c2abf6a56d1a1e5.tar.gz chromium_src-f89f563c49877af2093975735c2abf6a56d1a1e5.tar.bz2 |
cc: Layer that have empty bounds should still have their contentsScale applied in their transforms.
The change to add contentsScaleX() and contentsScaleY() allows layers to move
between their layer and content space even when they have empty bounds. Now new
code is moving between these spaces by multiplying these scale factors,
regardless of the layer's bounds, and this seems like the correct thing to do.
However, LayerTreeHostCommon is still only applying contentsScaleX|Y() only when
the bounds are not empty. This is inconsistent with other code, and ends up
causing confusion elsewhere, such as in the scrolling and hit testing code.
We remove the if() conditions on the bounds in LTHCommon, so that the transforms
on any layer match the contentsScales on that layer.
Tests:
cc_unittests:LayerTreeHostCommonTest.verifyLayerTransformsInHighDPI
cc_unittests:LayerTreeHostCommonTest.verifyContentsScale
BUG=160834
R=enne
Review URL: https://chromiumcodereview.appspot.com/11312226
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167764 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/layer_tree_host_common_unittest.cc')
-rw-r--r-- | cc/layer_tree_host_common_unittest.cc | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/cc/layer_tree_host_common_unittest.cc b/cc/layer_tree_host_common_unittest.cc index 30aa943..df95dfe 100644 --- a/cc/layer_tree_host_common_unittest.cc +++ b/cc/layer_tree_host_common_unittest.cc @@ -3450,10 +3450,14 @@ TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPI) scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate); setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true); + scoped_refptr<ContentLayer> childEmpty = createDrawableContentLayer(&delegate); + setLayerPropertiesForTesting(childEmpty.get(), identityMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(0, 0), true); + scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableContentLayer(&delegate); setLayerPropertiesForTesting(childNoScale.get(), identityMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true); parent->addChild(child); + parent->addChild(childEmpty); parent->addChild(childNoScale); std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; @@ -3466,6 +3470,7 @@ TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPI) EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, parent); EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, child); + EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, childEmpty); EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); EXPECT_EQ(1u, renderSurfaceLayerList.size()); @@ -3486,22 +3491,29 @@ TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPI) EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentDrawRect); EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentScreenSpaceRect); - // Verify child transforms + // Verify child and childEmpty transforms. They should match. WebTransformationMatrix expectedChildTransform; expectedChildTransform.translate(deviceScaleFactor * child->position().x(), deviceScaleFactor * child->position().y()); EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->screenSpaceTransform()); + EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, childEmpty->drawTransform()); + EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, childEmpty->screenSpaceTransform()); - // Verify results of transformed child rects + // Verify results of transformed child and childEmpty rects. They should match. gfx::RectF childContentBounds(gfx::PointF(), gfx::SizeF(child->contentBounds())); gfx::RectF childDrawRect = MathUtil::mapClippedRect(child->drawTransform(), childContentBounds); gfx::RectF childScreenSpaceRect = MathUtil::mapClippedRect(child->screenSpaceTransform(), childContentBounds); + gfx::RectF childEmptyDrawRect = MathUtil::mapClippedRect(childEmpty->drawTransform(), childContentBounds); + gfx::RectF childEmptyScreenSpaceRect = MathUtil::mapClippedRect(childEmpty->screenSpaceTransform(), childContentBounds); + gfx::RectF expectedChildDrawRect(child->position(), child->bounds()); expectedChildDrawRect.Scale(deviceScaleFactor); EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childDrawRect); EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childScreenSpaceRect); + EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childEmptyDrawRect); + EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childEmptyScreenSpaceRect); // Verify childNoScale transforms WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform(); @@ -3610,6 +3622,9 @@ TEST(LayerTreeHostCommonTest, verifyContentsScale) scoped_refptr<ContentLayer> childScale = createDrawableContentLayer(&delegate); setLayerPropertiesForTesting(childScale.get(), childScaleMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(10, 10), true); + scoped_refptr<ContentLayer> childEmpty = createDrawableContentLayer(&delegate); + setLayerPropertiesForTesting(childEmpty.get(), childScaleMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(2, 2), gfx::Size(0, 0), true); + scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableContentLayer(&delegate); setLayerPropertiesForTesting(childNoScale.get(), childScaleMatrix, identityMatrix, gfx::PointF(0, 0), gfx::PointF(12, 12), gfx::Size(10, 10), true); @@ -3623,6 +3638,7 @@ TEST(LayerTreeHostCommonTest, verifyContentsScale) parent->setBoundsContainPageScale(true); parent->addChild(childScale); + parent->addChild(childEmpty); parent->addChild(childNoScale); parent->addChild(childNoAutoScale); @@ -3641,29 +3657,33 @@ TEST(LayerTreeHostCommonTest, verifyContentsScale) EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent); EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, childScale); + EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, childEmpty); EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterScale, childNoAutoScale); // The parent is scaled up and shouldn't need to scale during draw. The child that can scale its contents should - // also not need to scale during draw. The other should. - // There is some rounding error due to contentBounds being a rounded integer. - EXPECT_NEAR(parent->drawTransform().m11(), 1, 0.01); - EXPECT_NEAR(parent->drawTransform().m22(), 1, 0.01); - EXPECT_NEAR(childScale->drawTransform().m11(), 1, 0.01); - EXPECT_NEAR(childScale->drawTransform().m22(), 1, 0.01); + // also not need to scale during draw. This shouldn't change if the child has empty bounds. The other children should. + EXPECT_FLOAT_EQ(1, parent->drawTransform().m11()); + EXPECT_FLOAT_EQ(1, parent->drawTransform().m22()); + EXPECT_FLOAT_EQ(1, childScale->drawTransform().m11()); + EXPECT_FLOAT_EQ(1, childScale->drawTransform().m22()); + EXPECT_FLOAT_EQ(1, childEmpty->drawTransform().m11()); + EXPECT_FLOAT_EQ(1, childEmpty->drawTransform().m22()); EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, childNoScale->drawTransform().m11()); EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, childNoScale->drawTransform().m22()); - EXPECT_NEAR(childNoAutoScale->drawTransform().m11(), initialParentScale * initialChildScale / fixedRasterScale, 0.01); - EXPECT_NEAR(childNoAutoScale->drawTransform().m22(), initialParentScale * initialChildScale / fixedRasterScale, 0.01); + EXPECT_FLOAT_EQ(initialParentScale * initialChildScale / fixedRasterScale, childNoAutoScale->drawTransform().m11()); + EXPECT_FLOAT_EQ(initialParentScale * initialChildScale / fixedRasterScale, childNoAutoScale->drawTransform().m22()); // If the transform changes, we expect the contentsScale to remain unchanged. childScale->setTransform(identityMatrix); + childEmpty->setTransform(identityMatrix); renderSurfaceLayerList.clear(); LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList); EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent); EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, childScale); + EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, childEmpty); EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); // But if the deviceScaleFactor or pageScaleFactor changes, then it should be updated, but using the initial transform. @@ -3680,6 +3700,7 @@ TEST(LayerTreeHostCommonTest, verifyContentsScale) EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent); EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, childScale); + EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, childEmpty); EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterScale, childNoAutoScale); } |