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

Unified Diff: cc/CCLayerTreeHostCommonTest.cpp

Issue 10915313: cc: Apply the layer's initial CSS scale to the contentsScale to render text at the right resolution. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
Index: cc/CCLayerTreeHostCommonTest.cpp
diff --git a/cc/CCLayerTreeHostCommonTest.cpp b/cc/CCLayerTreeHostCommonTest.cpp
index c23ae328f217cbfbbb50fbba8e57f998036508b6..8b9ce26120c826095b8561603e5ab4bd093fb82c 100644
--- a/cc/CCLayerTreeHostCommonTest.cpp
+++ b/cc/CCLayerTreeHostCommonTest.cpp
@@ -51,7 +51,7 @@ void setLayerPropertiesForTesting(CCLayerImpl* layer, const WebTransformationMat
layer->setContentBounds(bounds);
}
-void executeCalculateDrawTransformsAndVisibility(LayerChromium* rootLayer, float deviceScaleFactor = 1)
+void executeCalculateDrawTransformsAndVisibility(LayerChromium* rootLayer, float deviceScaleFactor = 1, float pageScaleFactor = 1)
{
WebTransformationMatrix identityMatrix;
Vector<RefPtr<LayerChromium> > dummyRenderSurfaceLayerList;
@@ -60,11 +60,11 @@ void executeCalculateDrawTransformsAndVisibility(LayerChromium* rootLayer, float
// We are probably not testing what is intended if the rootLayer bounds are empty.
ASSERT(!rootLayer->bounds().isEmpty());
- CCLayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, dummyMaxTextureSize, dummyRenderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, dummyRenderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(dummyRenderSurfaceLayerList);
}
-void executeCalculateDrawTransformsAndVisibility(CCLayerImpl* rootLayer, float deviceScaleFactor = 1)
+void executeCalculateDrawTransformsAndVisibility(CCLayerImpl* rootLayer, float deviceScaleFactor = 1, float pageScaleFactor = 1)
{
// Note: this version skips layer sorting.
@@ -75,7 +75,7 @@ void executeCalculateDrawTransformsAndVisibility(CCLayerImpl* rootLayer, float d
// We are probably not testing what is intended if the rootLayer bounds are empty.
ASSERT(!rootLayer->bounds().isEmpty());
- CCLayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, 0, dummyMaxTextureSize, dummyRenderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, pageScaleFactor, 0, dummyMaxTextureSize, dummyRenderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(dummyRenderSurfaceLayerList);
}
@@ -654,7 +654,7 @@ TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceListForRenderSurfaceWithClipp
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
// The child layer's content is entirely outside the parent's clip rect, so the intermediate
@@ -682,7 +682,7 @@ TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceListForTransparentChild)
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
// Since the layer is transparent, renderSurface1->renderSurface() should not have gotten added anywhere.
@@ -715,7 +715,7 @@ TEST(CCLayerTreeHostCommonTest, verifyForceRenderSurface)
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
// The root layer always creates a renderSurface
EXPECT_TRUE(parent->renderSurface());
@@ -724,7 +724,7 @@ TEST(CCLayerTreeHostCommonTest, verifyForceRenderSurface)
renderSurfaceLayerList.clear();
renderSurface1->setForceRenderSurface(false);
- CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
EXPECT_TRUE(parent->renderSurface());
EXPECT_FALSE(renderSurface1->renderSurface());
EXPECT_EQ(1U, renderSurfaceLayerList.size());
@@ -1338,7 +1338,7 @@ TEST(CCLayerTreeHostCommonTest, verifyClipRectCullsRenderSurfaces)
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
@@ -1385,7 +1385,7 @@ TEST(CCLayerTreeHostCommonTest, verifyClipRectCullsSurfaceWithoutVisibleContent)
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
// Without an animation, we should cull child and grandChild from the renderSurfaceLayerList.
ASSERT_EQ(1U, renderSurfaceLayerList.size());
@@ -1399,7 +1399,7 @@ TEST(CCLayerTreeHostCommonTest, verifyClipRectCullsSurfaceWithoutVisibleContent)
grandChild->clearRenderSurface();
renderSurfaceLayerList.clear();
- CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
// With an animating transform, we should keep child and grandChild in the renderSurfaceLayerList.
ASSERT_EQ(3U, renderSurfaceLayerList.size());
@@ -1451,7 +1451,7 @@ TEST(CCLayerTreeHostCommonTest, verifyDrawableContentRectForLayers)
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
EXPECT_RECT_EQ(IntRect(IntPoint(5, 5), IntSize(10, 10)), grandChild1->drawableContentRect());
@@ -1517,7 +1517,7 @@ TEST(CCLayerTreeHostCommonTest, verifyClipRectIsPropagatedCorrectlyToSurfaces)
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
ASSERT_TRUE(grandChild1->renderSurface());
@@ -2360,7 +2360,7 @@ TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithoutPreserves3d)
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
// Verify which renderSurfaces were created.
EXPECT_FALSE(frontFacingChild->renderSurface());
@@ -2459,7 +2459,7 @@ TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3d)
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
// Verify which renderSurfaces were created.
EXPECT_FALSE(frontFacingChild->renderSurface());
@@ -2539,7 +2539,7 @@ TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithAnimatingTransforms)
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
EXPECT_FALSE(child->renderSurface());
@@ -2606,7 +2606,7 @@ TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3dForFlattenin
Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, 1, dummyMaxTextureSize, renderSurfaceLayerList);
// Verify which renderSurfaces were created.
EXPECT_TRUE(frontFacingSurface->renderSurface());
@@ -2660,7 +2660,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSingleLayer)
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
// Sanity check the scenario we just created.
@@ -2710,7 +2710,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForUninvertibleTransform)
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
// Sanity check the scenario we just created.
@@ -2765,7 +2765,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSinglePositionedLayer)
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
// Sanity check the scenario we just created.
@@ -2813,7 +2813,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer)
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
// Sanity check the scenario we just created.
@@ -2870,7 +2870,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSinglePerspectiveLayer)
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
// Sanity check the scenario we just created.
@@ -2935,7 +2935,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSingleLayerWithScaledContents
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
// Sanity check the scenario we just created.
@@ -3000,7 +3000,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSimpleClippedLayer)
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
// Sanity check the scenario we just created.
@@ -3091,7 +3091,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForMultiClippedRotatedLayer)
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
// Sanity check the scenario we just created.
@@ -3174,7 +3174,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer)
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
// Sanity check the scenario we just created.
@@ -3255,7 +3255,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForMultipleLayers)
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
// Sanity check the scenario we just created.
@@ -3364,7 +3364,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists)
Vector<CCLayerImpl*> renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
- CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
CCLayerTreeHostCommon::calculateVisibleRects(renderSurfaceLayerList);
// Sanity check the scenario we just created.
@@ -3421,6 +3421,25 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists)
EXPECT_EQ(4, resultLayer->id());
}
+class NoScaleContentLayerChromium : public ContentLayerChromium
+{
+public:
+ static PassRefPtr<NoScaleContentLayerChromium> create(ContentLayerChromiumClient* client) { return adoptRef(new NoScaleContentLayerChromium(client)); }
+ virtual ~NoScaleContentLayerChromium() { }
+
+ virtual bool needsContentsScale() const OVERRIDE { return false; }
+
+protected:
+ explicit NoScaleContentLayerChromium(ContentLayerChromiumClient* client) : ContentLayerChromium(client) { }
+};
+
+PassRefPtr<NoScaleContentLayerChromium> createNoScaleDrawableContentLayerChromium(ContentLayerChromiumClient* delegate)
+{
+ RefPtr<NoScaleContentLayerChromium> toReturn = NoScaleContentLayerChromium::create(delegate);
+ toReturn->setIsDrawable(true);
+ return toReturn.release();
+}
+
TEST(CCLayerTreeHostCommonTest, verifyLayerTransformsInHighDPI)
{
// Verify draw and screen space transforms of layers not in a surface.
@@ -3433,7 +3452,7 @@ TEST(CCLayerTreeHostCommonTest, verifyLayerTransformsInHighDPI)
RefPtr<ContentLayerChromium> child = createDrawableContentLayerChromium(&delegate);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true);
- RefPtr<ContentLayerChromium> childNoScale = createDrawableContentLayerChromium(&delegate);
+ RefPtr<NoScaleContentLayerChromium> childNoScale = createNoScaleDrawableContentLayerChromium(&delegate);
setLayerPropertiesForTesting(childNoScale.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true);
parent->addChild(child);
@@ -3443,11 +3462,13 @@ TEST(CCLayerTreeHostCommonTest, verifyLayerTransformsInHighDPI)
int dummyMaxTextureSize = 512;
const double deviceScaleFactor = 2.5;
- parent->setContentsScale(deviceScaleFactor);
- child->setContentsScale(deviceScaleFactor);
- EXPECT_EQ(childNoScale->contentsScale(), 1);
+ const double pageScaleFactor = 1;
+
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList);
- CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList);
+ EXPECT_EQ(deviceScaleFactor * pageScaleFactor, parent->contentsScale());
+ EXPECT_EQ(deviceScaleFactor * pageScaleFactor, child->contentsScale());
+ EXPECT_EQ(1, childNoScale->contentsScale());
EXPECT_EQ(1u, renderSurfaceLayerList.size());
@@ -3494,6 +3515,201 @@ TEST(CCLayerTreeHostCommonTest, verifyLayerTransformsInHighDPI)
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale->screenSpaceTransform());
}
+TEST(CCLayerTreeHostCommonTest, verifyContentsScale)
+{
+ MockContentLayerChromiumClient delegate;
+ WebTransformationMatrix identityMatrix;
+
+ WebTransformationMatrix parentScaleMatrix;
+ const double initialParentScale = 1.75;
+ parentScaleMatrix.scale(initialParentScale);
+
+ WebTransformationMatrix childScaleMatrix;
+ const double initialChildScale = 1.25;
+ childScaleMatrix.scale(initialChildScale);
+
+ RefPtr<ContentLayerChromium> parent = createDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true);
+
+ RefPtr<ContentLayerChromium> childScale = createDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(childScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true);
+
+ RefPtr<NoScaleContentLayerChromium> childNoScale = createNoScaleDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(childNoScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(12, 12), IntSize(10, 10), true);
+
+ // FIXME: Remove this when pageScaleFactor is applied in the compositor.
+ // Page scale should not apply to the parent.
+ parent->setBoundsContainPageScale(true);
+
+ parent->addChild(childScale);
+ parent->addChild(childNoScale);
+
+ Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
+ int dummyMaxTextureSize = 512;
+
+ double deviceScaleFactor = 2.5;
+ double pageScaleFactor = 1.5;
+
+ // FIXME: Remove this when pageScaleFactor is applied in the compositor.
+ WebTransformationMatrix pageScaleMatrix;
+ pageScaleMatrix.scale(pageScaleFactor);
+ parent->setSublayerTransform(pageScaleMatrix);
+
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList);
+
+ EXPECT_FLOAT_EQ(deviceScaleFactor * initialParentScale, parent->contentsScale());
+ EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, childScale->contentsScale());
+ EXPECT_FLOAT_EQ(1, childNoScale->contentsScale());
+
+ // 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);
+ EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, childNoScale->drawTransform().m11());
+ EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, childNoScale->drawTransform().m22());
+
+ // If the transform changes, we expect the contentsScale to remain unchanged.
+ childScale->setTransform(identityMatrix);
+
+ renderSurfaceLayerList.clear();
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList);
+
+ EXPECT_FLOAT_EQ(deviceScaleFactor * initialParentScale, parent->contentsScale());
+ EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, childScale->contentsScale());
+ EXPECT_FLOAT_EQ(1, childNoScale->contentsScale());
+
+ // But if the deviceScaleFactor or pageScaleFactor changes, then it should be updated, but using the initial transform.
+ deviceScaleFactor = 2.25;
+ pageScaleFactor = 1.25;
+
+ // FIXME: Remove this when pageScaleFactor is applied in the compositor.
+ pageScaleMatrix = identityMatrix;
+ pageScaleMatrix.scale(pageScaleFactor);
+ parent->setSublayerTransform(pageScaleMatrix);
+
+ renderSurfaceLayerList.clear();
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList);
+
+ EXPECT_FLOAT_EQ(deviceScaleFactor * initialParentScale, parent->contentsScale());
+ EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, childScale->contentsScale());
+ EXPECT_FLOAT_EQ(1, childNoScale->contentsScale());
+}
+
+TEST(CCLayerTreeHostCommonTest, verifyContentsScaleForSurfaces)
+{
+ MockContentLayerChromiumClient delegate;
+ WebTransformationMatrix identityMatrix;
+
+ WebTransformationMatrix parentScaleMatrix;
+ const double initialParentScale = 2;
+ parentScaleMatrix.scale(initialParentScale);
+
+ WebTransformationMatrix childScaleMatrix;
+ const double initialChildScale = 3;
+ childScaleMatrix.scale(initialChildScale);
+
+ RefPtr<ContentLayerChromium> parent = createDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true);
+
+ RefPtr<ContentLayerChromium> surfaceScale = createDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(surfaceScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true);
+
+ RefPtr<ContentLayerChromium> surfaceScaleChildScale = createDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(surfaceScaleChildScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true);
+
+ RefPtr<NoScaleContentLayerChromium> surfaceScaleChildNoScale = createNoScaleDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(surfaceScaleChildNoScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true);
+
+ RefPtr<NoScaleContentLayerChromium> surfaceNoScale = createNoScaleDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(surfaceNoScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(12, 12), IntSize(10, 10), true);
+
+ RefPtr<ContentLayerChromium> surfaceNoScaleChildScale = createDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(surfaceNoScaleChildScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true);
+
+ RefPtr<NoScaleContentLayerChromium> surfaceNoScaleChildNoScale = createNoScaleDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(surfaceNoScaleChildNoScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true);
+
+ // FIXME: Remove this when pageScaleFactor is applied in the compositor.
+ // Page scale should not apply to the parent.
+ parent->setBoundsContainPageScale(true);
+
+ parent->addChild(surfaceScale);
+ parent->addChild(surfaceNoScale);
+
+ surfaceScale->setForceRenderSurface(true);
+ surfaceScale->addChild(surfaceScaleChildScale);
+ surfaceScale->addChild(surfaceScaleChildNoScale);
+
+ surfaceNoScale->setForceRenderSurface(true);
+ surfaceNoScale->addChild(surfaceNoScaleChildScale);
+ surfaceNoScale->addChild(surfaceNoScaleChildNoScale);
+
+ Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
+ int dummyMaxTextureSize = 512;
+
+ double deviceScaleFactor = 5;
+ double pageScaleFactor = 7;
+
+ // FIXME: Remove this when pageScaleFactor is applied in the compositor.
+ WebTransformationMatrix pageScaleMatrix;
+ pageScaleMatrix.scale(pageScaleFactor);
+ parent->setSublayerTransform(pageScaleMatrix);
+
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList);
+
+ EXPECT_EQ(deviceScaleFactor * initialParentScale, parent->contentsScale());
+ EXPECT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, surfaceScale->contentsScale());
+ EXPECT_EQ(1, surfaceNoScale->contentsScale());
+ // If the surface it draws into is scaling, then the contents scale should reflect both the layer's scale plus the surface's scale.
+ EXPECT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale * initialChildScale, surfaceScaleChildScale->contentsScale());
+ EXPECT_EQ(1, surfaceScaleChildNoScale->contentsScale());
+ // If the surface it draws into won't scale, then the contents scale should just reflect the size it will appear in its target surface.
+ EXPECT_EQ(initialChildScale, surfaceNoScaleChildScale->contentsScale());
+ EXPECT_EQ(1, surfaceNoScaleChildNoScale->contentsScale());
+
+ // The parent is scaled up and shouldn't need to scale during draw.
+ EXPECT_FLOAT_EQ(1, parent->drawTransform().m11());
+ EXPECT_FLOAT_EQ(1, parent->drawTransform().m22());
+
+ // The surfaceScale can apply contents scale so it's owned RenderSurface is scaled also, and the layer shouldn't need to scale during draw.
+ EXPECT_FLOAT_EQ(1, surfaceScale->drawTransform().m11());
+ EXPECT_FLOAT_EQ(1, surfaceScale->drawTransform().m22());
+
+ // The surfaceScale RenderSurface will be scaled by its owning layer's contentsScale, so it shouldn't need to scale during draw.
+ EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().m11());
+ EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().m22());
+
+ // The surfaceScaleChildScale can apply contents scale so it shouldn't need to scale during draw.
+ EXPECT_FLOAT_EQ(1, surfaceScaleChildScale->drawTransform().m11());
+ EXPECT_FLOAT_EQ(1, surfaceScaleChildScale->drawTransform().m22());
+
+ // The surfaceScaleChildNoScale can not apply contents scale, so it needs to be scaled during draw.
+ // It will be scaled to draw at the scale of its target surface, along with its own scale.
+ EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale * initialChildScale, surfaceScaleChildNoScale->drawTransform().m11());
+ EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale * initialChildScale, surfaceScaleChildNoScale->drawTransform().m22());
+
+ // The surfaceNoScale can not apply contents scale so it's owned RenderSurface is not scaled. So the layer should not be scaled while drawing to its surface.
+ EXPECT_FLOAT_EQ(1, surfaceNoScale->drawTransform().m11());
+ EXPECT_FLOAT_EQ(1, surfaceNoScale->drawTransform().m22());
+
+ // The surfaceScale RenderSurface will not be scaled by its owning layer's contentsScale, so it should be scaled during draw.
+ EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, surfaceNoScale->renderSurface()->drawTransform().m11());
+ EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, surfaceNoScale->renderSurface()->drawTransform().m22());
+
+ // The surfaceScaleChildScale can apply contents scale so it shouldn't need to scale during draw.
+ EXPECT_FLOAT_EQ(1, surfaceNoScaleChildScale->drawTransform().m11());
+ EXPECT_FLOAT_EQ(1, surfaceNoScaleChildScale->drawTransform().m22());
+
+ // The surfaceScaleChildNoScale can not apply contents scale, so it needs to be scaled during draw.
+ // Since its target surface is not scaled, it should only be scaled by its own scale.
+ EXPECT_FLOAT_EQ(initialChildScale, surfaceNoScaleChildNoScale->drawTransform().m11());
+ EXPECT_FLOAT_EQ(initialChildScale, surfaceNoScaleChildNoScale->drawTransform().m22());
+
+}
+
TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPI)
{
MockContentLayerChromiumClient delegate;
@@ -3528,7 +3744,7 @@ TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPI)
duplicateChildNonOwner->setContentsScale(deviceScaleFactor);
replica->setContentsScale(deviceScaleFactor);
- CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList);
+ CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, 1, dummyMaxTextureSize, renderSurfaceLayerList);
// We should have two render surfaces. The root's render surface and child's
// render surface (it needs one because it has a replica layer).

Powered by Google App Engine
This is Rietveld 408576698