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

Unified Diff: cc/layer_tree_host_common_unittest.cc

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: rebase 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.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 af74b1fed513b421d04bb68c99e7859ab6aff162..e91b8ff617c5cc631f196f57bf368df8c7c5041f 100644
--- a/cc/layer_tree_host_common_unittest.cc
+++ b/cc/layer_tree_host_common_unittest.cc
@@ -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;
std::vector<scoped_refptr<LayerChromium> > dummyRenderSurfaceLayerList;
@@ -60,10 +60,10 @@ 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);
}
-void executeCalculateDrawTransformsAndVisibility(CCLayerImpl* rootLayer, float deviceScaleFactor = 1)
+void executeCalculateDrawTransformsAndVisibility(CCLayerImpl* rootLayer, float deviceScaleFactor = 1, float pageScaleFactor = 1)
{
// Note: this version skips layer sorting.
@@ -74,7 +74,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);
}
WebTransformationMatrix remove3DComponentOfMatrix(const WebTransformationMatrix& mat)
@@ -333,6 +333,10 @@ TEST(CCLayerTreeHostCommonTest, verifyTransformsForSingleRenderSurface)
parentTranslationToCenter.translate(50, 60);
WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
* parentTranslationToCenter * parentSublayerMatrix * parentTranslationToCenter.inverse();
+ FloatPoint parentCompositeScale = CCMathUtil::computeTransform2dScaleComponents(parentCompositeTransform);
+ WebTransformationMatrix surfaceSublayerTransform;
+ surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCompositeScale.y());
+ WebTransformationMatrix surfaceSublayerCompositeTransform = parentCompositeTransform * surfaceSublayerTransform.inverse();
// Child's render surface should not exist yet.
ASSERT_FALSE(child->renderSurface());
@@ -348,14 +352,15 @@ TEST(CCLayerTreeHostCommonTest, verifyTransformsForSingleRenderSurface)
// The child layer's draw transform should refer to its new render surface.
// The screen-space transform, however, should still refer to the root.
- EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
// Because the grandChild is the only drawable content, the child's renderSurface will tighten its bounds to the grandChild.
- EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->renderTarget()->renderSurface()->drawTransform());
+ // The scale at which the surface's subtree is drawn must be removed from the composite transform.
+ EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->renderTarget()->renderSurface()->drawTransform());
// The screen space is the same as the target since the child surface draws into the root.
- EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->renderTarget()->renderSurface()->screenSpaceTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(surfaceSublayerCompositeTransform, child->renderTarget()->renderSurface()->screenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForReplica)
@@ -386,7 +391,10 @@ TEST(CCLayerTreeHostCommonTest, verifyTransformsForReplica)
childTranslationToCenter.translate(8, 9);
WebTransformationMatrix replicaLayerTransform;
replicaLayerTransform.scale3d(3, 3, 1);
- WebTransformationMatrix replicaCompositeTransform = parentCompositeTransform * replicaLayerTransform;
+ FloatPoint parentCompositeScale = CCMathUtil::computeTransform2dScaleComponents(parentCompositeTransform);
+ WebTransformationMatrix surfaceSublayerTransform;
+ surfaceSublayerTransform.scaleNonUniform(parentCompositeScale.x(), parentCompositeScale.y());
+ WebTransformationMatrix replicaCompositeTransform = parentCompositeTransform * replicaLayerTransform * surfaceSublayerTransform.inverse();
// Child's render surface should not exist yet.
ASSERT_FALSE(child->renderSurface());
@@ -463,6 +471,24 @@ TEST(CCLayerTreeHostCommonTest, verifyTransformsForRenderSurfaceHierarchy)
WebTransformationMatrix R = A * translationToAnchor * replicaLayerTransform * translationToAnchor.inverse();
WebTransformationMatrix identityMatrix;
+ FloatPoint surface1ParentTransformScale = CCMathUtil::computeTransform2dScaleComponents(A * B);
+ WebTransformationMatrix surface1SublayerTransform;
+ surface1SublayerTransform.scaleNonUniform(surface1ParentTransformScale.x(), surface1ParentTransformScale.y());
+
+ // SS1 = transform given to the subtree of renderSurface1
+ WebTransformationMatrix SS1 = surface1SublayerTransform;
+ // S1 = transform to move from renderSurface1 pixels to the layer space of the owning layer
+ WebTransformationMatrix S1 = surface1SublayerTransform.inverse();
+
+ FloatPoint surface2ParentTransformScale = CCMathUtil::computeTransform2dScaleComponents(SS1 * A * B);
+ WebTransformationMatrix surface2SublayerTransform;
+ surface2SublayerTransform.scaleNonUniform(surface2ParentTransformScale.x(), surface2ParentTransformScale.y());
+
+ // SS2 = transform given to the subtree of renderSurface2
+ WebTransformationMatrix SS2 = surface2SublayerTransform;
+ // S2 = transform to move from renderSurface2 pixels to the layer space of the owning layer
+ WebTransformationMatrix S2 = surface2SublayerTransform.inverse();
+
setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
@@ -513,13 +539,13 @@ TEST(CCLayerTreeHostCommonTest, verifyTransformsForRenderSurfaceHierarchy)
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, childOfRoot->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A, grandChildOfRoot->drawTransform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, renderSurface1->drawTransform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(B * A, childOfRS1->drawTransform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(B * A * B * A, grandChildOfRS1->drawTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, renderSurface1->drawTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * A, childOfRS1->drawTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * A * B * A, grandChildOfRS1->drawTransform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, renderSurface2->drawTransform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(B * A, childOfRS2->drawTransform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(B * A * B * A, grandChildOfRS2->drawTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, renderSurface2->drawTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * B * A, childOfRS2->drawTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * B * A * B * A, grandChildOfRS2->drawTransform());
// Verify layer screen-space transforms
//
@@ -538,15 +564,15 @@ TEST(CCLayerTreeHostCommonTest, verifyTransformsForRenderSurfaceHierarchy)
// Verify render surface transforms.
//
// Draw transform of render surface 1 is described with respect to root.
- EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, renderSurface1->renderSurface()->drawTransform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * R, renderSurface1->renderSurface()->replicaDrawTransform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, renderSurface1->renderSurface()->screenSpaceTransform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * R, renderSurface1->renderSurface()->replicaScreenSpaceTransform());
- // Draw transform of render surface 2 is described with respect to render surface 2.
- EXPECT_TRANSFORMATION_MATRIX_EQ(B * A, renderSurface2->renderSurface()->drawTransform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(B * R, renderSurface2->renderSurface()->replicaDrawTransform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A, renderSurface2->renderSurface()->screenSpaceTransform());
- EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * R, renderSurface2->renderSurface()->replicaScreenSpaceTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * S1, renderSurface1->renderSurface()->drawTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * R * S1, renderSurface1->renderSurface()->replicaDrawTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * S1, renderSurface1->renderSurface()->screenSpaceTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * R * S1, renderSurface1->renderSurface()->replicaScreenSpaceTransform());
+ // Draw transform of render surface 2 is described with respect to render surface 1.
+ EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * A * S2, renderSurface2->renderSurface()->drawTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * B * R * S2, renderSurface2->renderSurface()->replicaDrawTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * S2, renderSurface2->renderSurface()->screenSpaceTransform());
+ EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * R * S2, renderSurface2->renderSurface()->replicaScreenSpaceTransform());
// Sanity check. If these fail there is probably a bug in the test itself.
// It is expected that we correctly set up transforms so that the y-component of the screen-space transform
@@ -657,7 +683,7 @@ TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceListForRenderSurfaceWithClipp
std::vector<scoped_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 child layer's content is entirely outside the parent's clip rect, so the intermediate
// render surface should not be listed here, even if it was forced to be created. Render surfaces without children or visible
@@ -684,7 +710,7 @@ TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceListForTransparentChild)
std::vector<scoped_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);
// Since the layer is transparent, renderSurface1->renderSurface() should not have gotten added anywhere.
// Also, the drawable content rect should not have been extended by the children.
@@ -716,7 +742,7 @@ TEST(CCLayerTreeHostCommonTest, verifyForceRenderSurface)
std::vector<scoped_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());
@@ -725,7 +751,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());
@@ -1339,7 +1365,7 @@ TEST(CCLayerTreeHostCommonTest, verifyClipRectCullsRenderSurfaces)
std::vector<scoped_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);
ASSERT_EQ(2U, renderSurfaceLayerList.size());
EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
@@ -1384,7 +1410,7 @@ TEST(CCLayerTreeHostCommonTest, verifyClipRectCullsSurfaceWithoutVisibleContent)
std::vector<scoped_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());
@@ -1398,7 +1424,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());
@@ -1450,7 +1476,7 @@ TEST(CCLayerTreeHostCommonTest, verifyDrawableContentRectForLayers)
std::vector<scoped_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);
EXPECT_RECT_EQ(IntRect(IntPoint(5, 5), IntSize(10, 10)), grandChild1->drawableContentRect());
EXPECT_RECT_EQ(IntRect(IntPoint(15, 15), IntSize(5, 5)), grandChild3->drawableContentRect());
@@ -1515,7 +1541,7 @@ TEST(CCLayerTreeHostCommonTest, verifyClipRectIsPropagatedCorrectlyToSurfaces)
std::vector<scoped_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);
ASSERT_TRUE(grandChild1->renderSurface());
ASSERT_TRUE(grandChild2->renderSurface());
@@ -2357,7 +2383,7 @@ TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithoutPreserves3d)
std::vector<scoped_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());
@@ -2456,7 +2482,7 @@ TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3d)
std::vector<scoped_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());
@@ -2536,7 +2562,7 @@ TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithAnimatingTransforms)
std::vector<scoped_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);
EXPECT_FALSE(child->renderSurface());
EXPECT_TRUE(animatingSurface->renderSurface());
@@ -2602,7 +2628,7 @@ TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3dForFlattenin
std::vector<scoped_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());
@@ -2656,7 +2682,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSingleLayer)
std::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);
// Sanity check the scenario we just created.
ASSERT_EQ(1u, renderSurfaceLayerList.size());
@@ -2705,7 +2731,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForUninvertibleTransform)
std::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);
// Sanity check the scenario we just created.
ASSERT_EQ(1u, renderSurfaceLayerList.size());
@@ -2759,7 +2785,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSinglePositionedLayer)
std::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);
// Sanity check the scenario we just created.
ASSERT_EQ(1u, renderSurfaceLayerList.size());
@@ -2806,7 +2832,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSingleRotatedLayer)
std::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);
// Sanity check the scenario we just created.
ASSERT_EQ(1u, renderSurfaceLayerList.size());
@@ -2862,7 +2888,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSinglePerspectiveLayer)
std::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);
// Sanity check the scenario we just created.
ASSERT_EQ(1u, renderSurfaceLayerList.size());
@@ -2926,7 +2952,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSingleLayerWithScaledContents
std::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);
// Sanity check the scenario we just created.
// The visibleContentRect for testLayer is actually 100x100, even though its layout size is 50x50, positioned at 25x25.
@@ -2990,7 +3016,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForSimpleClippedLayer)
std::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);
// Sanity check the scenario we just created.
ASSERT_EQ(1u, renderSurfaceLayerList.size());
@@ -3080,7 +3106,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForMultiClippedRotatedLayer)
std::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);
// Sanity check the scenario we just created.
// The grandChild is expected to create a renderSurface because it masksToBounds and is not axis aligned.
@@ -3162,7 +3188,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForNonClippingIntermediateLayer)
std::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);
// Sanity check the scenario we just created.
ASSERT_EQ(1u, renderSurfaceLayerList.size());
@@ -3242,7 +3268,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForMultipleLayers)
std::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);
// Sanity check the scenario we just created.
ASSERT_TRUE(child1);
@@ -3350,7 +3376,7 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists)
std::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);
// Sanity check the scenario we just created.
ASSERT_TRUE(child1);
@@ -3406,6 +3432,25 @@ TEST(CCLayerTreeHostCommonTest, verifyHitTestingForMultipleLayerLists)
EXPECT_EQ(4, resultLayer->id());
}
+class NoScaleContentLayerChromium : public ContentLayerChromium
+{
+public:
+ static scoped_refptr<NoScaleContentLayerChromium> create(ContentLayerChromiumClient* client) { return make_scoped_refptr(new NoScaleContentLayerChromium(client)); }
+
+ virtual bool needsContentsScale() const OVERRIDE { return false; }
+
+protected:
+ explicit NoScaleContentLayerChromium(ContentLayerChromiumClient* client) : ContentLayerChromium(client) { }
+ virtual ~NoScaleContentLayerChromium() { }
+};
+
+scoped_refptr<NoScaleContentLayerChromium> createNoScaleDrawableContentLayerChromium(ContentLayerChromiumClient* delegate)
+{
+ scoped_refptr<NoScaleContentLayerChromium> toReturn = NoScaleContentLayerChromium::create(delegate);
+ toReturn->setIsDrawable(true);
+ return toReturn;
+}
+
TEST(CCLayerTreeHostCommonTest, verifyLayerTransformsInHighDPI)
{
// Verify draw and screen space transforms of layers not in a surface.
@@ -3418,7 +3463,7 @@ TEST(CCLayerTreeHostCommonTest, verifyLayerTransformsInHighDPI)
scoped_refptr<ContentLayerChromium> child = createDrawableContentLayerChromium(&delegate);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true);
- scoped_refptr<ContentLayerChromium> childNoScale = createDrawableContentLayerChromium(&delegate);
+ scoped_refptr<NoScaleContentLayerChromium> childNoScale = createNoScaleDrawableContentLayerChromium(&delegate);
setLayerPropertiesForTesting(childNoScale.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true);
parent->addChild(child);
@@ -3428,11 +3473,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());
@@ -3479,6 +3526,197 @@ 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);
+
+ scoped_refptr<ContentLayerChromium> parent = createDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true);
+
+ scoped_refptr<ContentLayerChromium> childScale = createDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(childScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true);
+
+ scoped_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);
+
+ std::vector<scoped_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);
+
+ scoped_refptr<ContentLayerChromium> parent = createDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(parent.get(), parentScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true);
+
+ scoped_refptr<ContentLayerChromium> surfaceScale = createDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(surfaceScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(2, 2), IntSize(10, 10), true);
+
+ scoped_refptr<ContentLayerChromium> surfaceScaleChildScale = createDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(surfaceScaleChildScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true);
+
+ scoped_refptr<NoScaleContentLayerChromium> surfaceScaleChildNoScale = createNoScaleDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(surfaceScaleChildNoScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true);
+
+ scoped_refptr<NoScaleContentLayerChromium> surfaceNoScale = createNoScaleDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(surfaceNoScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(12, 12), IntSize(10, 10), true);
+
+ scoped_refptr<ContentLayerChromium> surfaceNoScaleChildScale = createDrawableContentLayerChromium(&delegate);
+ setLayerPropertiesForTesting(surfaceNoScaleChildScale.get(), childScaleMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 10), true);
+
+ scoped_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);
+
+ std::vector<scoped_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());
+ EXPECT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale * initialChildScale, surfaceScaleChildScale->contentsScale());
+ EXPECT_EQ(1, surfaceScaleChildNoScale->contentsScale());
+ EXPECT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale * 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());
+
+ // RenderSurfaces should always be 1:1 with their target.
+ EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().m11());
+ EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().m22());
+
+ // The surfaceScale can apply contents scale so the layer shouldn't need to scale during draw.
+ EXPECT_FLOAT_EQ(1, surfaceScale->drawTransform().m11());
+ EXPECT_FLOAT_EQ(1, surfaceScale->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.
+ EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale * initialChildScale, surfaceScaleChildNoScale->drawTransform().m11());
+ EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale * initialChildScale, surfaceScaleChildNoScale->drawTransform().m22());
+
+ // RenderSurfaces should always be 1:1 with their target.
+ EXPECT_FLOAT_EQ(1, surfaceNoScale->renderSurface()->drawTransform().m11());
+ EXPECT_FLOAT_EQ(1, surfaceNoScale->renderSurface()->drawTransform().m22());
+
+ // The surfaceScale layer can not apply contents scale, so it needs to be scaled during draw.
+ EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, surfaceNoScale->drawTransform().m11());
+ EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale, surfaceNoScale->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.
+ EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale * initialChildScale, surfaceNoScaleChildNoScale->drawTransform().m11());
+ EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initialChildScale * initialChildScale, surfaceNoScaleChildNoScale->drawTransform().m22());
+
+}
+
TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPI)
{
MockContentLayerChromiumClient delegate;
@@ -3513,7 +3751,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).
« no previous file with comments | « cc/layer_tree_host_common.cc ('k') | cc/layer_tree_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698