OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/layer_tree_host_common.h" | 7 #include "cc/layer_tree_host_common.h" |
8 | 8 |
9 #include "cc/content_layer.h" | 9 #include "cc/content_layer.h" |
10 #include "cc/content_layer_client.h" | 10 #include "cc/content_layer_client.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 void setLayerPropertiesForTesting(Layer* layer, const WebTransformationMatrix& t
ransform, const WebTransformationMatrix& sublayerTransform, const FloatPoint& an
chor, const FloatPoint& position, const IntSize& bounds, bool preserves3D) | 42 void setLayerPropertiesForTesting(Layer* layer, const WebTransformationMatrix& t
ransform, const WebTransformationMatrix& sublayerTransform, const FloatPoint& an
chor, const FloatPoint& position, const IntSize& bounds, bool preserves3D) |
43 { | 43 { |
44 setLayerPropertiesForTestingInternal<Layer>(layer, transform, sublayerTransf
orm, anchor, position, bounds, preserves3D); | 44 setLayerPropertiesForTestingInternal<Layer>(layer, transform, sublayerTransf
orm, anchor, position, bounds, preserves3D); |
45 layer->setAutomaticallyComputeRasterScale(true); | 45 layer->setAutomaticallyComputeRasterScale(true); |
46 } | 46 } |
47 | 47 |
48 void setLayerPropertiesForTesting(LayerImpl* layer, const WebTransformationMatri
x& transform, const WebTransformationMatrix& sublayerTransform, const FloatPoint
& anchor, const FloatPoint& position, const IntSize& bounds, bool preserves3D) | 48 void setLayerPropertiesForTesting(LayerImpl* layer, const WebTransformationMatri
x& transform, const WebTransformationMatrix& sublayerTransform, const FloatPoint
& anchor, const FloatPoint& position, const IntSize& bounds, bool preserves3D) |
49 { | 49 { |
50 setLayerPropertiesForTestingInternal<LayerImpl>(layer, transform, sublayerTr
ansform, anchor, position, bounds, preserves3D); | 50 setLayerPropertiesForTestingInternal<LayerImpl>(layer, transform, sublayerTr
ansform, anchor, position, bounds, preserves3D); |
51 layer->setContentBounds(bounds); | |
52 } | 51 } |
53 | 52 |
54 void executeCalculateDrawTransformsAndVisibility(Layer* rootLayer, float deviceS
caleFactor = 1, float pageScaleFactor = 1) | 53 void executeCalculateDrawTransformsAndVisibility(Layer* rootLayer, float deviceS
caleFactor = 1, float pageScaleFactor = 1) |
55 { | 54 { |
56 WebTransformationMatrix identityMatrix; | 55 WebTransformationMatrix identityMatrix; |
57 std::vector<scoped_refptr<Layer> > dummyRenderSurfaceLayerList; | 56 std::vector<scoped_refptr<Layer> > dummyRenderSurfaceLayerList; |
58 int dummyMaxTextureSize = 512; | 57 int dummyMaxTextureSize = 512; |
59 IntSize deviceViewportSize = IntSize(rootLayer->bounds().width() * deviceSca
leFactor, rootLayer->bounds().height() * deviceScaleFactor); | 58 IntSize deviceViewportSize = IntSize(rootLayer->bounds().width() * deviceSca
leFactor, rootLayer->bounds().height() * deviceScaleFactor); |
60 | 59 |
61 // We are probably not testing what is intended if the rootLayer bounds are
empty. | 60 // We are probably not testing what is intended if the rootLayer bounds are
empty. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 virtual void paintContents(SkCanvas*, const IntRect& clip, FloatRect& opaque
) OVERRIDE { } | 134 virtual void paintContents(SkCanvas*, const IntRect& clip, FloatRect& opaque
) OVERRIDE { } |
136 }; | 135 }; |
137 | 136 |
138 scoped_refptr<ContentLayer> createDrawableContentLayer(ContentLayerClient* deleg
ate) | 137 scoped_refptr<ContentLayer> createDrawableContentLayer(ContentLayerClient* deleg
ate) |
139 { | 138 { |
140 scoped_refptr<ContentLayer> toReturn = ContentLayer::create(delegate); | 139 scoped_refptr<ContentLayer> toReturn = ContentLayer::create(delegate); |
141 toReturn->setIsDrawable(true); | 140 toReturn->setIsDrawable(true); |
142 return toReturn; | 141 return toReturn; |
143 } | 142 } |
144 | 143 |
| 144 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ |
| 145 do { \ |
| 146 EXPECT_FLOAT_EQ(expected, layer->contentsScaleX()); \ |
| 147 EXPECT_FLOAT_EQ(expected, layer->contentsScaleY()); \ |
| 148 } while (false) |
| 149 |
145 TEST(LayerTreeHostCommonTest, verifyTransformsForNoOpLayer) | 150 TEST(LayerTreeHostCommonTest, verifyTransformsForNoOpLayer) |
146 { | 151 { |
147 // Sanity check: For layers positioned at zero, with zero size, | 152 // Sanity check: For layers positioned at zero, with zero size, |
148 // and with identity transforms, then the drawTransform, | 153 // and with identity transforms, then the drawTransform, |
149 // screenSpaceTransform, and the hierarchy passed on to children | 154 // screenSpaceTransform, and the hierarchy passed on to children |
150 // layers should also be identity transforms. | 155 // layers should also be identity transforms. |
151 | 156 |
152 scoped_refptr<Layer> parent = Layer::create(); | 157 scoped_refptr<Layer> parent = Layer::create(); |
153 scoped_refptr<Layer> child = Layer::create(); | 158 scoped_refptr<Layer> child = Layer::create(); |
154 scoped_refptr<Layer> grandChild = Layer::create(); | 159 scoped_refptr<Layer> grandChild = Layer::create(); |
(...skipping 2781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2936 FloatPoint anchor(0, 0); | 2941 FloatPoint anchor(0, 0); |
2937 | 2942 |
2938 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc
hor, FloatPoint(0, 0), IntSize(100, 100), false); | 2943 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc
hor, FloatPoint(0, 0), IntSize(100, 100), false); |
2939 | 2944 |
2940 { | 2945 { |
2941 FloatPoint position(25, 25); | 2946 FloatPoint position(25, 25); |
2942 IntSize bounds(50, 50); | 2947 IntSize bounds(50, 50); |
2943 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345); | 2948 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345); |
2944 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa
trix, anchor, position, bounds, false); | 2949 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa
trix, anchor, position, bounds, false); |
2945 | 2950 |
2946 // override contentBounds | 2951 // override contentsScale |
2947 testLayer->setContentBounds(IntSize(100, 100)); | 2952 testLayer->setContentsScale(2, 2); |
2948 | 2953 |
2949 testLayer->setDrawsContent(true); | 2954 testLayer->setDrawsContent(true); |
2950 root->addChild(testLayer.Pass()); | 2955 root->addChild(testLayer.Pass()); |
2951 } | 2956 } |
2952 | 2957 |
2953 std::vector<LayerImpl*> renderSurfaceLayerList; | 2958 std::vector<LayerImpl*> renderSurfaceLayerList; |
2954 int dummyMaxTextureSize = 512; | 2959 int dummyMaxTextureSize = 512; |
2955 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1,
1, 0, dummyMaxTextureSize, renderSurfaceLayerList); | 2960 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1,
1, 0, dummyMaxTextureSize, renderSurfaceLayerList); |
2956 | 2961 |
2957 // Sanity check the scenario we just created. | 2962 // Sanity check the scenario we just created. |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3430 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); | 3435 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend
erSurfaceLayerList); |
3431 ASSERT_TRUE(resultLayer); | 3436 ASSERT_TRUE(resultLayer); |
3432 EXPECT_EQ(4, resultLayer->id()); | 3437 EXPECT_EQ(4, resultLayer->id()); |
3433 } | 3438 } |
3434 | 3439 |
3435 class NoScaleContentLayer : public ContentLayer | 3440 class NoScaleContentLayer : public ContentLayer |
3436 { | 3441 { |
3437 public: | 3442 public: |
3438 static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client)
{ return make_scoped_refptr(new NoScaleContentLayer(client)); } | 3443 static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client)
{ return make_scoped_refptr(new NoScaleContentLayer(client)); } |
3439 | 3444 |
3440 virtual bool needsContentsScale() const OVERRIDE { return false; } | 3445 virtual IntSize contentBounds() const OVERRIDE { return bounds(); } |
| 3446 virtual float contentsScaleX() const OVERRIDE { return 1.0; } |
| 3447 virtual float contentsScaleY() const OVERRIDE { return 1.0; } |
3441 | 3448 |
3442 protected: | 3449 protected: |
3443 explicit NoScaleContentLayer(ContentLayerClient* client) : ContentLayer(clie
nt) { } | 3450 explicit NoScaleContentLayer(ContentLayerClient* client) : ContentLayer(clie
nt) { } |
3444 virtual ~NoScaleContentLayer() { } | 3451 virtual ~NoScaleContentLayer() { } |
3445 }; | 3452 }; |
3446 | 3453 |
3447 scoped_refptr<NoScaleContentLayer> createNoScaleDrawableContentLayer(ContentLaye
rClient* delegate) | 3454 scoped_refptr<NoScaleContentLayer> createNoScaleDrawableContentLayer(ContentLaye
rClient* delegate) |
3448 { | 3455 { |
3449 scoped_refptr<NoScaleContentLayer> toReturn = NoScaleContentLayer::create(de
legate); | 3456 scoped_refptr<NoScaleContentLayer> toReturn = NoScaleContentLayer::create(de
legate); |
3450 toReturn->setIsDrawable(true); | 3457 toReturn->setIsDrawable(true); |
(...skipping 19 matching lines...) Expand all Loading... |
3470 parent->addChild(childNoScale); | 3477 parent->addChild(childNoScale); |
3471 | 3478 |
3472 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; | 3479 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; |
3473 int dummyMaxTextureSize = 512; | 3480 int dummyMaxTextureSize = 512; |
3474 | 3481 |
3475 const double deviceScaleFactor = 2.5; | 3482 const double deviceScaleFactor = 2.5; |
3476 const double pageScaleFactor = 1; | 3483 const double pageScaleFactor = 1; |
3477 | 3484 |
3478 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(),
deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList
); | 3485 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(),
deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList
); |
3479 | 3486 |
3480 EXPECT_EQ(deviceScaleFactor * pageScaleFactor, parent->contentsScale()); | 3487 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, parent); |
3481 EXPECT_EQ(deviceScaleFactor * pageScaleFactor, child->contentsScale()); | 3488 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, child); |
3482 EXPECT_EQ(1, childNoScale->contentsScale()); | 3489 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); |
3483 | 3490 |
3484 EXPECT_EQ(1u, renderSurfaceLayerList.size()); | 3491 EXPECT_EQ(1u, renderSurfaceLayerList.size()); |
3485 | 3492 |
3486 // Verify parent transforms | 3493 // Verify parent transforms |
3487 WebTransformationMatrix expectedParentTransform; | 3494 WebTransformationMatrix expectedParentTransform; |
3488 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace
Transform()); | 3495 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace
Transform()); |
3489 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo
rm()); | 3496 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo
rm()); |
3490 | 3497 |
3491 // Verify results of transformed parent rects | 3498 // Verify results of transformed parent rects |
3492 FloatRect parentContentBounds(FloatPoint(), FloatSize(parent->contentBounds(
))); | 3499 FloatRect parentContentBounds(FloatPoint(), FloatSize(parent->contentBounds(
))); |
(...skipping 26 matching lines...) Expand all Loading... |
3519 | 3526 |
3520 // Verify childNoScale transforms | 3527 // Verify childNoScale transforms |
3521 WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform
(); | 3528 WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform
(); |
3522 // All transforms operate on content rects. The child's content rect | 3529 // All transforms operate on content rects. The child's content rect |
3523 // incorporates device scale, but the childNoScale does not; add it here. | 3530 // incorporates device scale, but the childNoScale does not; add it here. |
3524 expectedChildNoScaleTransform.scale(deviceScaleFactor); | 3531 expectedChildNoScaleTransform.scale(deviceScaleFactor); |
3525 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale-
>drawTransform()); | 3532 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale-
>drawTransform()); |
3526 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale-
>screenSpaceTransform()); | 3533 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale-
>screenSpaceTransform()); |
3527 } | 3534 } |
3528 | 3535 |
| 3536 TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPIAccurateScaleZeroChi
ldPosition) |
| 3537 { |
| 3538 // Verify draw and screen space transforms of layers not in a surface. |
| 3539 MockContentLayerClient delegate; |
| 3540 WebTransformationMatrix identityMatrix; |
| 3541 |
| 3542 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); |
| 3543 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F
loatPoint(0, 0), FloatPoint(0, 0), IntSize(133, 133), true); |
| 3544 |
| 3545 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate); |
| 3546 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl
oatPoint(0, 0), FloatPoint(0, 0), IntSize(13, 13), true); |
| 3547 |
| 3548 scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableConte
ntLayer(&delegate); |
| 3549 setLayerPropertiesForTesting(childNoScale.get(), identityMatrix, identityMat
rix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(13, 13), true); |
| 3550 |
| 3551 parent->addChild(child); |
| 3552 parent->addChild(childNoScale); |
| 3553 |
| 3554 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; |
| 3555 int dummyMaxTextureSize = 512; |
| 3556 |
| 3557 const double deviceScaleFactor = 1.7; |
| 3558 const double pageScaleFactor = 1; |
| 3559 |
| 3560 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(),
deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList
); |
| 3561 |
| 3562 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, parent); |
| 3563 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, child); |
| 3564 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); |
| 3565 |
| 3566 EXPECT_EQ(1u, renderSurfaceLayerList.size()); |
| 3567 |
| 3568 // Verify parent transforms |
| 3569 WebTransformationMatrix expectedParentTransform; |
| 3570 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace
Transform()); |
| 3571 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo
rm()); |
| 3572 |
| 3573 // Verify results of transformed parent rects |
| 3574 FloatRect parentContentBounds(FloatPoint(), FloatSize(parent->contentBounds(
))); |
| 3575 |
| 3576 FloatRect parentDrawRect = MathUtil::mapClippedRect(parent->drawTransform(),
parentContentBounds); |
| 3577 FloatRect parentScreenSpaceRect = MathUtil::mapClippedRect(parent->screenSpa
ceTransform(), parentContentBounds); |
| 3578 |
| 3579 FloatRect expectedParentDrawRect(FloatPoint(), parent->bounds()); |
| 3580 expectedParentDrawRect.scale(deviceScaleFactor); |
| 3581 expectedParentDrawRect.setWidth(ceil(expectedParentDrawRect.width())); |
| 3582 expectedParentDrawRect.setHeight(ceil(expectedParentDrawRect.height())); |
| 3583 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentDrawRect); |
| 3584 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentScreenSpaceRect); |
| 3585 |
| 3586 // Verify child transforms |
| 3587 WebTransformationMatrix expectedChildTransform; |
| 3588 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform
()); |
| 3589 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->screenSpaceTr
ansform()); |
| 3590 |
| 3591 // Verify results of transformed child rects |
| 3592 FloatRect childContentBounds(FloatPoint(), FloatSize(child->contentBounds())
); |
| 3593 |
| 3594 FloatRect childDrawRect = MathUtil::mapClippedRect(child->drawTransform(), c
hildContentBounds); |
| 3595 FloatRect childScreenSpaceRect = MathUtil::mapClippedRect(child->screenSpace
Transform(), childContentBounds); |
| 3596 |
| 3597 FloatRect expectedChildDrawRect(FloatPoint(), child->bounds()); |
| 3598 expectedChildDrawRect.scale(deviceScaleFactor); |
| 3599 expectedChildDrawRect.setWidth(ceil(expectedChildDrawRect.width())); |
| 3600 expectedChildDrawRect.setHeight(ceil(expectedChildDrawRect.height())); |
| 3601 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childDrawRect); |
| 3602 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childScreenSpaceRect); |
| 3603 |
| 3604 // Verify childNoScale transforms |
| 3605 WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform
(); |
| 3606 // All transforms operate on content rects. The child's content rect |
| 3607 // incorporates device scale, but the childNoScale does not; add it here. |
| 3608 expectedChildNoScaleTransform.scale(deviceScaleFactor); |
| 3609 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale-
>drawTransform()); |
| 3610 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale-
>screenSpaceTransform()); |
| 3611 } |
| 3612 |
3529 TEST(LayerTreeHostCommonTest, verifyContentsScale) | 3613 TEST(LayerTreeHostCommonTest, verifyContentsScale) |
3530 { | 3614 { |
3531 MockContentLayerClient delegate; | 3615 MockContentLayerClient delegate; |
3532 WebTransformationMatrix identityMatrix; | 3616 WebTransformationMatrix identityMatrix; |
3533 | 3617 |
3534 WebTransformationMatrix parentScaleMatrix; | 3618 WebTransformationMatrix parentScaleMatrix; |
3535 const double initialParentScale = 1.75; | 3619 const double initialParentScale = 1.75; |
3536 parentScaleMatrix.scale(initialParentScale); | 3620 parentScaleMatrix.scale(initialParentScale); |
3537 | 3621 |
3538 WebTransformationMatrix childScaleMatrix; | 3622 WebTransformationMatrix childScaleMatrix; |
(...skipping 30 matching lines...) Expand all Loading... |
3569 double deviceScaleFactor = 2.5; | 3653 double deviceScaleFactor = 2.5; |
3570 double pageScaleFactor = 1.5; | 3654 double pageScaleFactor = 1.5; |
3571 | 3655 |
3572 // FIXME: Remove this when pageScaleFactor is applied in the compositor. | 3656 // FIXME: Remove this when pageScaleFactor is applied in the compositor. |
3573 WebTransformationMatrix pageScaleMatrix; | 3657 WebTransformationMatrix pageScaleMatrix; |
3574 pageScaleMatrix.scale(pageScaleFactor); | 3658 pageScaleMatrix.scale(pageScaleFactor); |
3575 parent->setSublayerTransform(pageScaleMatrix); | 3659 parent->setSublayerTransform(pageScaleMatrix); |
3576 | 3660 |
3577 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(),
deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList
); | 3661 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(),
deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList
); |
3578 | 3662 |
3579 EXPECT_FLOAT_EQ(deviceScaleFactor * initialParentScale, parent->contentsScal
e()); | 3663 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent); |
3580 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i
nitialChildScale, childScale->contentsScale()); | 3664 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent
Scale * initialChildScale, childScale); |
3581 EXPECT_FLOAT_EQ(1, childNoScale->contentsScale()); | 3665 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); |
3582 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterScale, chil
dNoAutoScale->contentsScale()); | 3666 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterSc
ale, childNoAutoScale); |
3583 | 3667 |
3584 // The parent is scaled up and shouldn't need to scale during draw. The chil
d that can scale its contents should | 3668 // The parent is scaled up and shouldn't need to scale during draw. The chil
d that can scale its contents should |
3585 // also not need to scale during draw. The other should. | 3669 // also not need to scale during draw. The other should. |
3586 // There is some rounding error due to contentBounds being a rounded integer
. | 3670 // There is some rounding error due to contentBounds being a rounded integer
. |
3587 EXPECT_NEAR(parent->drawTransform().m11(), 1, 0.01); | 3671 EXPECT_NEAR(parent->drawTransform().m11(), 1, 0.01); |
3588 EXPECT_NEAR(parent->drawTransform().m22(), 1, 0.01); | 3672 EXPECT_NEAR(parent->drawTransform().m22(), 1, 0.01); |
3589 EXPECT_NEAR(childScale->drawTransform().m11(), 1, 0.01); | 3673 EXPECT_NEAR(childScale->drawTransform().m11(), 1, 0.01); |
3590 EXPECT_NEAR(childScale->drawTransform().m22(), 1, 0.01); | 3674 EXPECT_NEAR(childScale->drawTransform().m22(), 1, 0.01); |
3591 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i
nitialChildScale, childNoScale->drawTransform().m11()); | 3675 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i
nitialChildScale, childNoScale->drawTransform().m11()); |
3592 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i
nitialChildScale, childNoScale->drawTransform().m22()); | 3676 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i
nitialChildScale, childNoScale->drawTransform().m22()); |
3593 EXPECT_NEAR(childNoAutoScale->drawTransform().m11(), initialParentScale * in
itialChildScale / fixedRasterScale, 0.01); | 3677 EXPECT_NEAR(childNoAutoScale->drawTransform().m11(), initialParentScale * in
itialChildScale / fixedRasterScale, 0.01); |
3594 EXPECT_NEAR(childNoAutoScale->drawTransform().m22(), initialParentScale * in
itialChildScale / fixedRasterScale, 0.01); | 3678 EXPECT_NEAR(childNoAutoScale->drawTransform().m22(), initialParentScale * in
itialChildScale / fixedRasterScale, 0.01); |
3595 | 3679 |
3596 // If the transform changes, we expect the contentsScale to remain unchanged
. | 3680 // If the transform changes, we expect the contentsScale to remain unchanged
. |
3597 childScale->setTransform(identityMatrix); | 3681 childScale->setTransform(identityMatrix); |
3598 | 3682 |
3599 renderSurfaceLayerList.clear(); | 3683 renderSurfaceLayerList.clear(); |
3600 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(),
deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList
); | 3684 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(),
deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList
); |
3601 | 3685 |
3602 EXPECT_FLOAT_EQ(deviceScaleFactor * initialParentScale, parent->contentsScal
e()); | 3686 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent); |
3603 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i
nitialChildScale, childScale->contentsScale()); | 3687 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent
Scale * initialChildScale, childScale); |
3604 EXPECT_FLOAT_EQ(1, childNoScale->contentsScale()); | 3688 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); |
3605 | 3689 |
3606 // But if the deviceScaleFactor or pageScaleFactor changes, then it should b
e updated, but using the initial transform. | 3690 // But if the deviceScaleFactor or pageScaleFactor changes, then it should b
e updated, but using the initial transform. |
3607 deviceScaleFactor = 2.25; | 3691 deviceScaleFactor = 2.25; |
3608 pageScaleFactor = 1.25; | 3692 pageScaleFactor = 1.25; |
3609 | 3693 |
3610 // FIXME: Remove this when pageScaleFactor is applied in the compositor. | 3694 // FIXME: Remove this when pageScaleFactor is applied in the compositor. |
3611 pageScaleMatrix = identityMatrix; | 3695 pageScaleMatrix = identityMatrix; |
3612 pageScaleMatrix.scale(pageScaleFactor); | 3696 pageScaleMatrix.scale(pageScaleFactor); |
3613 parent->setSublayerTransform(pageScaleMatrix); | 3697 parent->setSublayerTransform(pageScaleMatrix); |
3614 | 3698 |
3615 renderSurfaceLayerList.clear(); | 3699 renderSurfaceLayerList.clear(); |
3616 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(),
deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList
); | 3700 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(),
deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList
); |
3617 | 3701 |
3618 EXPECT_FLOAT_EQ(deviceScaleFactor * initialParentScale, parent->contentsScal
e()); | 3702 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent); |
3619 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i
nitialChildScale, childScale->contentsScale()); | 3703 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent
Scale * initialChildScale, childScale); |
3620 EXPECT_FLOAT_EQ(1, childNoScale->contentsScale()); | 3704 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale); |
3621 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterScale, chil
dNoAutoScale->contentsScale()); | 3705 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterSc
ale, childNoAutoScale); |
3622 } | 3706 } |
3623 | 3707 |
3624 TEST(LayerTreeHostCommonTest, verifyContentsScaleForSurfaces) | 3708 TEST(LayerTreeHostCommonTest, verifyContentsScaleForSurfaces) |
3625 { | 3709 { |
3626 MockContentLayerClient delegate; | 3710 MockContentLayerClient delegate; |
3627 WebTransformationMatrix identityMatrix; | 3711 WebTransformationMatrix identityMatrix; |
3628 | 3712 |
3629 WebTransformationMatrix parentScaleMatrix; | 3713 WebTransformationMatrix parentScaleMatrix; |
3630 const double initialParentScale = 2; | 3714 const double initialParentScale = 2; |
3631 parentScaleMatrix.scale(initialParentScale); | 3715 parentScaleMatrix.scale(initialParentScale); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3694 double deviceScaleFactor = 5; | 3778 double deviceScaleFactor = 5; |
3695 double pageScaleFactor = 7; | 3779 double pageScaleFactor = 7; |
3696 | 3780 |
3697 // FIXME: Remove this when pageScaleFactor is applied in the compositor. | 3781 // FIXME: Remove this when pageScaleFactor is applied in the compositor. |
3698 WebTransformationMatrix pageScaleMatrix; | 3782 WebTransformationMatrix pageScaleMatrix; |
3699 pageScaleMatrix.scale(pageScaleFactor); | 3783 pageScaleMatrix.scale(pageScaleFactor); |
3700 parent->setSublayerTransform(pageScaleMatrix); | 3784 parent->setSublayerTransform(pageScaleMatrix); |
3701 | 3785 |
3702 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(),
deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList
); | 3786 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(),
deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList
); |
3703 | 3787 |
3704 EXPECT_EQ(deviceScaleFactor * initialParentScale, parent->contentsScale()); | 3788 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent); |
3705 EXPECT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initial
ChildScale, surfaceScale->contentsScale()); | 3789 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent
Scale * initialChildScale, surfaceScale); |
3706 EXPECT_EQ(1, surfaceNoScale->contentsScale()); | 3790 EXPECT_CONTENTS_SCALE_EQ(1, surfaceNoScale); |
3707 EXPECT_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterScale, surfaceNoA
utoScale->contentsScale()); | 3791 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterSc
ale, surfaceNoAutoScale); |
3708 | 3792 |
3709 EXPECT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initial
ChildScale * initialChildScale, surfaceScaleChildScale->contentsScale()); | 3793 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent
Scale * initialChildScale * initialChildScale, surfaceScaleChildScale); |
3710 EXPECT_EQ(1, surfaceScaleChildNoScale->contentsScale()); | 3794 EXPECT_CONTENTS_SCALE_EQ(1, surfaceScaleChildNoScale); |
3711 EXPECT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initial
ChildScale * initialChildScale, surfaceNoScaleChildScale->contentsScale()); | 3795 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent
Scale * initialChildScale * initialChildScale, surfaceNoScaleChildScale); |
3712 EXPECT_EQ(1, surfaceNoScaleChildNoScale->contentsScale()); | 3796 EXPECT_CONTENTS_SCALE_EQ(1, surfaceNoScaleChildNoScale); |
3713 EXPECT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initial
ChildScale * initialChildScale, surfaceNoAutoScaleChildScale->contentsScale()); | 3797 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent
Scale * initialChildScale * initialChildScale, surfaceNoAutoScaleChildScale); |
3714 EXPECT_EQ(1, surfaceNoAutoScaleChildNoScale->contentsScale()); | 3798 EXPECT_CONTENTS_SCALE_EQ(1, surfaceNoAutoScaleChildNoScale); |
3715 | 3799 |
3716 // The parent is scaled up and shouldn't need to scale during draw. | 3800 // The parent is scaled up and shouldn't need to scale during draw. |
3717 EXPECT_FLOAT_EQ(1, parent->drawTransform().m11()); | 3801 EXPECT_FLOAT_EQ(1, parent->drawTransform().m11()); |
3718 EXPECT_FLOAT_EQ(1, parent->drawTransform().m22()); | 3802 EXPECT_FLOAT_EQ(1, parent->drawTransform().m22()); |
3719 | 3803 |
3720 // RenderSurfaces should always be 1:1 with their target. | 3804 // RenderSurfaces should always be 1:1 with their target. |
3721 EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().m11()); | 3805 EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().m11()); |
3722 EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().m22()); | 3806 EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().m22()); |
3723 | 3807 |
3724 // The surfaceScale can apply contents scale so the layer shouldn't need to
scale during draw. | 3808 // The surfaceScale can apply contents scale so the layer shouldn't need to
scale during draw. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3839 expectedReplicaDrawTransform.setM22(-1); | 3923 expectedReplicaDrawTransform.setM22(-1); |
3840 expectedReplicaDrawTransform.setM41(6); | 3924 expectedReplicaDrawTransform.setM41(6); |
3841 expectedReplicaDrawTransform.setM42(6); | 3925 expectedReplicaDrawTransform.setM42(6); |
3842 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaDrawTransform, child->renderS
urface()->replicaDrawTransform()); | 3926 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaDrawTransform, child->renderS
urface()->replicaDrawTransform()); |
3843 | 3927 |
3844 WebTransformationMatrix expectedReplicaScreenSpaceTransform; | 3928 WebTransformationMatrix expectedReplicaScreenSpaceTransform; |
3845 expectedReplicaScreenSpaceTransform.setM22(-1); | 3929 expectedReplicaScreenSpaceTransform.setM22(-1); |
3846 expectedReplicaScreenSpaceTransform.setM41(6); | 3930 expectedReplicaScreenSpaceTransform.setM41(6); |
3847 expectedReplicaScreenSpaceTransform.setM42(6); | 3931 expectedReplicaScreenSpaceTransform.setM42(6); |
3848 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child->
renderSurface()->replicaScreenSpaceTransform()); | 3932 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child->
renderSurface()->replicaScreenSpaceTransform()); |
| 3933 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child->
renderSurface()->replicaScreenSpaceTransform()); |
| 3934 } |
| 3935 |
| 3936 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPIAccurateScal
eZeroPosition) |
| 3937 { |
| 3938 MockContentLayerClient delegate; |
| 3939 WebTransformationMatrix identityMatrix; |
| 3940 |
| 3941 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate); |
| 3942 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F
loatPoint(0, 0), FloatPoint(0, 0), IntSize(33, 31), true); |
| 3943 |
| 3944 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate); |
| 3945 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl
oatPoint(0, 0), FloatPoint(0, 0), IntSize(13, 11), true); |
| 3946 |
| 3947 WebTransformationMatrix replicaTransform; |
| 3948 replicaTransform.scaleNonUniform(1, -1); |
| 3949 scoped_refptr<ContentLayer> replica = createDrawableContentLayer(&delegate); |
| 3950 setLayerPropertiesForTesting(replica.get(), replicaTransform, identityMatrix
, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(13, 11), true); |
| 3951 |
| 3952 // This layer should end up in the same surface as child, with the same draw |
| 3953 // and screen space transforms. |
| 3954 scoped_refptr<ContentLayer> duplicateChildNonOwner = createDrawableContentLa
yer(&delegate); |
| 3955 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i
dentityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(13, 11), true); |
| 3956 |
| 3957 parent->addChild(child); |
| 3958 child->addChild(duplicateChildNonOwner); |
| 3959 child->setReplicaLayer(replica.get()); |
| 3960 |
| 3961 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; |
| 3962 int dummyMaxTextureSize = 512; |
| 3963 |
| 3964 const double deviceScaleFactor = 1.7; |
| 3965 parent->setContentsScale(deviceScaleFactor); |
| 3966 child->setContentsScale(deviceScaleFactor); |
| 3967 duplicateChildNonOwner->setContentsScale(deviceScaleFactor); |
| 3968 replica->setContentsScale(deviceScaleFactor); |
| 3969 |
| 3970 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(),
deviceScaleFactor, 1, dummyMaxTextureSize, renderSurfaceLayerList); |
| 3971 |
| 3972 // We should have two render surfaces. The root's render surface and child's |
| 3973 // render surface (it needs one because it has a replica layer). |
| 3974 EXPECT_EQ(2u, renderSurfaceLayerList.size()); |
| 3975 |
| 3976 WebTransformationMatrix identityTransform; |
| 3977 |
| 3978 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, parent->screenSpaceTransf
orm()); |
| 3979 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, parent->drawTransform()); |
| 3980 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->drawTransform()); |
| 3981 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->screenSpaceTransfo
rm()); |
| 3982 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, duplicateChildNonOwner->d
rawTransform()); |
| 3983 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, duplicateChildNonOwner->s
creenSpaceTransform()); |
| 3984 EXPECT_RECT_EQ(child->drawableContentRect(), duplicateChildNonOwner->drawabl
eContentRect()); |
| 3985 EXPECT_EQ(child->contentBounds(), duplicateChildNonOwner->contentBounds()); |
| 3986 |
| 3987 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->renderSurface()->d
rawTransform()); |
| 3988 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->renderSurface()->d
rawTransform()); |
| 3989 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->renderSurface()->s
creenSpaceTransform()); |
| 3990 |
| 3991 WebTransformationMatrix expectedReplicaDrawTransform; |
| 3992 expectedReplicaDrawTransform.setM22(-1); |
| 3993 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaDrawTransform, child->renderS
urface()->replicaDrawTransform()); |
| 3994 |
| 3995 WebTransformationMatrix expectedReplicaScreenSpaceTransform; |
| 3996 expectedReplicaScreenSpaceTransform.setM22(-1); |
| 3997 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child->
renderSurface()->replicaScreenSpaceTransform()); |
3849 } | 3998 } |
3850 | 3999 |
3851 TEST(LayerTreeHostCommonTest, verifySubtreeSearch) | 4000 TEST(LayerTreeHostCommonTest, verifySubtreeSearch) |
3852 { | 4001 { |
3853 scoped_refptr<Layer> root = Layer::create(); | 4002 scoped_refptr<Layer> root = Layer::create(); |
3854 scoped_refptr<Layer> child = Layer::create(); | 4003 scoped_refptr<Layer> child = Layer::create(); |
3855 scoped_refptr<Layer> grandChild = Layer::create(); | 4004 scoped_refptr<Layer> grandChild = Layer::create(); |
3856 scoped_refptr<Layer> maskLayer = Layer::create(); | 4005 scoped_refptr<Layer> maskLayer = Layer::create(); |
3857 scoped_refptr<Layer> replicaLayer = Layer::create(); | 4006 scoped_refptr<Layer> replicaLayer = Layer::create(); |
3858 | 4007 |
3859 grandChild->setReplicaLayer(replicaLayer.get()); | 4008 grandChild->setReplicaLayer(replicaLayer.get()); |
3860 child->addChild(grandChild.get()); | 4009 child->addChild(grandChild.get()); |
3861 child->setMaskLayer(maskLayer.get()); | 4010 child->setMaskLayer(maskLayer.get()); |
3862 root->addChild(child.get()); | 4011 root->addChild(child.get()); |
3863 | 4012 |
3864 int nonexistentId = -1; | 4013 int nonexistentId = -1; |
3865 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id
())); | 4014 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id
())); |
3866 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child->
id())); | 4015 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child->
id())); |
3867 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr
andChild->id())); | 4016 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr
andChild->id())); |
3868 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas
kLayer->id())); | 4017 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas
kLayer->id())); |
3869 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(),
replicaLayer->id())); | 4018 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(),
replicaLayer->id())); |
3870 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent
Id)); | 4019 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent
Id)); |
3871 } | 4020 } |
3872 | 4021 |
3873 } // namespace | 4022 } // namespace |
OLD | NEW |