summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cc/layer_tree_host_common.cc16
-rw-r--r--cc/layer_tree_host_common_unittest.cc41
2 files changed, 36 insertions, 21 deletions
diff --git a/cc/layer_tree_host_common.cc b/cc/layer_tree_host_common.cc
index 52b7200..9147ecd 100644
--- a/cc/layer_tree_host_common.cc
+++ b/cc/layer_tree_host_common.cc
@@ -531,11 +531,8 @@ static void calculateDrawTransformsInternal(LayerType* layer, const WebTransform
// The drawTransform that gets computed below is effectively the layer's drawTransform, unless
// the layer itself creates a renderSurface. In that case, the renderSurface re-parents the transforms.
WebTransformationMatrix drawTransform = combinedTransform;
- if (!layer->contentBounds().IsEmpty() && !layer->bounds().IsEmpty()) {
- // M[draw] = M[parent] * LT * S[layer2content]
- drawTransform.scaleNonUniform(1.0 / layer->contentsScaleX(),
- 1.0 / layer->contentsScaleY());
- }
+ // M[draw] = M[parent] * LT * S[layer2content]
+ drawTransform.scaleNonUniform(1.0 / layer->contentsScaleX(), 1.0 / layer->contentsScaleY());
// layerScreenSpaceTransform represents the transform between root layer's "screen space" and local content space.
WebTransformationMatrix layerScreenSpaceTransform = fullHierarchyMatrix;
@@ -566,16 +563,14 @@ static void calculateDrawTransformsInternal(LayerType* layer, const WebTransform
// The owning layer's draw transform has a scale from content to layer space which we need to undo and
// replace with a scale from the surface's subtree into layer space.
- if (!layer->contentBounds().IsEmpty() && !layer->bounds().IsEmpty())
- drawTransform.scaleNonUniform(layer->contentsScaleX(), layer->contentsScaleY());
+ drawTransform.scaleNonUniform(layer->contentsScaleX(), layer->contentsScaleY());
drawTransform.scaleNonUniform(1 / renderSurfaceSublayerScale.x(), 1 / renderSurfaceSublayerScale.y());
renderSurface->setDrawTransform(drawTransform);
// The origin of the new surface is the upper left corner of the layer.
WebTransformationMatrix layerDrawTransform;
layerDrawTransform.scaleNonUniform(renderSurfaceSublayerScale.x(), renderSurfaceSublayerScale.y());
- if (!layer->contentBounds().IsEmpty() && !layer->bounds().IsEmpty())
- layerDrawTransform.scaleNonUniform(1.0 / layer->contentsScaleX(), 1.0 / layer->contentsScaleY());
+ layerDrawTransform.scaleNonUniform(1.0 / layer->contentsScaleX(), 1.0 / layer->contentsScaleY());
layer->setDrawTransform(layerDrawTransform);
// Inside the surface's subtree, we scale everything to the owning layer's scale.
@@ -747,8 +742,7 @@ static void calculateDrawTransformsInternal(LayerType* layer, const WebTransform
// The owning layer's screenSpaceTransform has a scale from content to layer space which we need to undo and
// replace with a scale from the surface's subtree into layer space.
WebTransformationMatrix screenSpaceTransform = layer->screenSpaceTransform();
- if (!layer->contentBounds().IsEmpty() && !layer->bounds().IsEmpty())
- screenSpaceTransform.scaleNonUniform(layer->contentsScaleX(), layer->contentsScaleY());
+ screenSpaceTransform.scaleNonUniform(layer->contentsScaleX(), layer->contentsScaleY());
screenSpaceTransform.scaleNonUniform(1 / renderSurfaceSublayerScale.x(), 1 / renderSurfaceSublayerScale.y());
renderSurface->setScreenSpaceTransform(screenSpaceTransform);
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);
}