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

Side by Side Diff: cc/layer_tree_host_common_unittest.cc

Issue 11276060: Pass accurate contentsScale to LayerImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layer_tree_host_common.cc ('k') | cc/layer_tree_host_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 virtual void paintContents(SkCanvas*, const gfx::Rect& clip, gfx::RectF& opa que) OVERRIDE { } 135 virtual void paintContents(SkCanvas*, const gfx::Rect& clip, gfx::RectF& opa que) OVERRIDE { }
136 }; 136 };
137 137
138 scoped_refptr<ContentLayer> createDrawableContentLayer(ContentLayerClient* deleg ate) 138 scoped_refptr<ContentLayer> createDrawableContentLayer(ContentLayerClient* deleg ate)
139 { 139 {
140 scoped_refptr<ContentLayer> toReturn = ContentLayer::create(delegate); 140 scoped_refptr<ContentLayer> toReturn = ContentLayer::create(delegate);
141 toReturn->setIsDrawable(true); 141 toReturn->setIsDrawable(true);
142 return toReturn; 142 return toReturn;
143 } 143 }
144 144
145 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
146 do { \
147 EXPECT_FLOAT_EQ(expected, layer->contentsScaleX()); \
148 EXPECT_FLOAT_EQ(expected, layer->contentsScaleY()); \
149 } while (false)
150
145 TEST(LayerTreeHostCommonTest, verifyTransformsForNoOpLayer) 151 TEST(LayerTreeHostCommonTest, verifyTransformsForNoOpLayer)
146 { 152 {
147 // Sanity check: For layers positioned at zero, with zero size, 153 // Sanity check: For layers positioned at zero, with zero size,
148 // and with identity transforms, then the drawTransform, 154 // and with identity transforms, then the drawTransform,
149 // screenSpaceTransform, and the hierarchy passed on to children 155 // screenSpaceTransform, and the hierarchy passed on to children
150 // layers should also be identity transforms. 156 // layers should also be identity transforms.
151 157
152 scoped_refptr<Layer> parent = Layer::create(); 158 scoped_refptr<Layer> parent = Layer::create();
153 scoped_refptr<Layer> child = Layer::create(); 159 scoped_refptr<Layer> child = Layer::create();
154 scoped_refptr<Layer> grandChild = Layer::create(); 160 scoped_refptr<Layer> grandChild = Layer::create();
(...skipping 2805 matching lines...) Expand 10 before | Expand all | Expand 10 after
2960 FloatPoint anchor(0, 0); 2966 FloatPoint anchor(0, 0);
2961 2967
2962 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, FloatPoint(0, 0), IntSize(100, 100), false); 2968 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, anc hor, FloatPoint(0, 0), IntSize(100, 100), false);
2963 2969
2964 { 2970 {
2965 FloatPoint position(25, 25); 2971 FloatPoint position(25, 25);
2966 IntSize bounds(50, 50); 2972 IntSize bounds(50, 50);
2967 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345); 2973 scoped_ptr<LayerImpl> testLayer = LayerImpl::create(12345);
2968 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false); 2974 setLayerPropertiesForTesting(testLayer.get(), identityMatrix, identityMa trix, anchor, position, bounds, false);
2969 2975
2970 // override contentBounds 2976 // override contentBounds and contentsScale
2971 testLayer->setContentBounds(IntSize(100, 100)); 2977 testLayer->setContentBounds(IntSize(100, 100));
2978 testLayer->setContentsScale(2, 2);
2972 2979
2973 testLayer->setDrawsContent(true); 2980 testLayer->setDrawsContent(true);
2974 root->addChild(testLayer.Pass()); 2981 root->addChild(testLayer.Pass());
2975 } 2982 }
2976 2983
2977 std::vector<LayerImpl*> renderSurfaceLayerList; 2984 std::vector<LayerImpl*> renderSurfaceLayerList;
2978 int dummyMaxTextureSize = 512; 2985 int dummyMaxTextureSize = 512;
2979 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList); 2986 LayerTreeHostCommon::calculateDrawTransforms(root.get(), root->bounds(), 1, 1, 0, dummyMaxTextureSize, renderSurfaceLayerList);
2980 2987
2981 // Sanity check the scenario we just created. 2988 // Sanity check the scenario we just created.
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
3454 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList); 3461 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPoint(testPoint, rend erSurfaceLayerList);
3455 ASSERT_TRUE(resultLayer); 3462 ASSERT_TRUE(resultLayer);
3456 EXPECT_EQ(4, resultLayer->id()); 3463 EXPECT_EQ(4, resultLayer->id());
3457 } 3464 }
3458 3465
3459 class NoScaleContentLayer : public ContentLayer 3466 class NoScaleContentLayer : public ContentLayer
3460 { 3467 {
3461 public: 3468 public:
3462 static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client) { return make_scoped_refptr(new NoScaleContentLayer(client)); } 3469 static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client) { return make_scoped_refptr(new NoScaleContentLayer(client)); }
3463 3470
3464 virtual bool needsContentsScale() const OVERRIDE { return false; } 3471 virtual IntSize contentBounds() const OVERRIDE { return bounds(); }
3472 virtual float contentsScaleX() const OVERRIDE { return 1.0; }
3473 virtual float contentsScaleY() const OVERRIDE { return 1.0; }
3465 3474
3466 protected: 3475 protected:
3467 explicit NoScaleContentLayer(ContentLayerClient* client) : ContentLayer(clie nt) { } 3476 explicit NoScaleContentLayer(ContentLayerClient* client) : ContentLayer(clie nt) { }
3468 virtual ~NoScaleContentLayer() { } 3477 virtual ~NoScaleContentLayer() { }
3469 }; 3478 };
3470 3479
3471 scoped_refptr<NoScaleContentLayer> createNoScaleDrawableContentLayer(ContentLaye rClient* delegate) 3480 scoped_refptr<NoScaleContentLayer> createNoScaleDrawableContentLayer(ContentLaye rClient* delegate)
3472 { 3481 {
3473 scoped_refptr<NoScaleContentLayer> toReturn = NoScaleContentLayer::create(de legate); 3482 scoped_refptr<NoScaleContentLayer> toReturn = NoScaleContentLayer::create(de legate);
3474 toReturn->setIsDrawable(true); 3483 toReturn->setIsDrawable(true);
(...skipping 19 matching lines...) Expand all
3494 parent->addChild(childNoScale); 3503 parent->addChild(childNoScale);
3495 3504
3496 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 3505 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
3497 int dummyMaxTextureSize = 512; 3506 int dummyMaxTextureSize = 512;
3498 3507
3499 const double deviceScaleFactor = 2.5; 3508 const double deviceScaleFactor = 2.5;
3500 const double pageScaleFactor = 1; 3509 const double pageScaleFactor = 1;
3501 3510
3502 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 3511 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
3503 3512
3504 EXPECT_EQ(deviceScaleFactor * pageScaleFactor, parent->contentsScale()); 3513 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, parent);
3505 EXPECT_EQ(deviceScaleFactor * pageScaleFactor, child->contentsScale()); 3514 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, child);
3506 EXPECT_EQ(1, childNoScale->contentsScale()); 3515 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale);
3507 3516
3508 EXPECT_EQ(1u, renderSurfaceLayerList.size()); 3517 EXPECT_EQ(1u, renderSurfaceLayerList.size());
3509 3518
3510 // Verify parent transforms 3519 // Verify parent transforms
3511 WebTransformationMatrix expectedParentTransform; 3520 WebTransformationMatrix expectedParentTransform;
3512 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform()); 3521 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform());
3513 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm()); 3522 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm());
3514 3523
3515 // Verify results of transformed parent rects 3524 // Verify results of transformed parent rects
3516 FloatRect parentContentBounds(FloatPoint(), FloatSize(parent->contentBounds( ))); 3525 FloatRect parentContentBounds(FloatPoint(), FloatSize(parent->contentBounds( )));
(...skipping 26 matching lines...) Expand all
3543 3552
3544 // Verify childNoScale transforms 3553 // Verify childNoScale transforms
3545 WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform (); 3554 WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform ();
3546 // All transforms operate on content rects. The child's content rect 3555 // All transforms operate on content rects. The child's content rect
3547 // incorporates device scale, but the childNoScale does not; add it here. 3556 // incorporates device scale, but the childNoScale does not; add it here.
3548 expectedChildNoScaleTransform.scale(deviceScaleFactor); 3557 expectedChildNoScaleTransform.scale(deviceScaleFactor);
3549 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >drawTransform()); 3558 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >drawTransform());
3550 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >screenSpaceTransform()); 3559 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >screenSpaceTransform());
3551 } 3560 }
3552 3561
3562 TEST(LayerTreeHostCommonTest, verifyLayerTransformsInHighDPIAccurateScaleZeroChi ldPosition)
3563 {
3564 // Verify draw and screen space transforms of layers not in a surface.
3565 MockContentLayerClient delegate;
3566 WebTransformationMatrix identityMatrix;
3567
3568 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
3569 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(133, 133), true);
3570
3571 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate);
3572 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(13, 13), true);
3573
3574 scoped_refptr<NoScaleContentLayer> childNoScale = createNoScaleDrawableConte ntLayer(&delegate);
3575 setLayerPropertiesForTesting(childNoScale.get(), identityMatrix, identityMat rix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(13, 13), true);
3576
3577 parent->addChild(child);
3578 parent->addChild(childNoScale);
3579
3580 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
3581 int dummyMaxTextureSize = 512;
3582
3583 const float deviceScaleFactor = 1.7f;
3584 const float pageScaleFactor = 1;
3585
3586 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
3587
3588 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, parent);
3589 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor, child);
3590 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale);
3591
3592 EXPECT_EQ(1u, renderSurfaceLayerList.size());
3593
3594 // Verify parent transforms
3595 WebTransformationMatrix expectedParentTransform;
3596 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform());
3597 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm());
3598
3599 // Verify results of transformed parent rects
3600 FloatRect parentContentBounds(FloatPoint(), FloatSize(parent->contentBounds( )));
3601
3602 FloatRect parentDrawRect = MathUtil::mapClippedRect(parent->drawTransform(), parentContentBounds);
3603 FloatRect parentScreenSpaceRect = MathUtil::mapClippedRect(parent->screenSpa ceTransform(), parentContentBounds);
3604
3605 FloatRect expectedParentDrawRect(FloatPoint(), parent->bounds());
3606 expectedParentDrawRect.scale(deviceScaleFactor);
3607 expectedParentDrawRect.setWidth(ceil(expectedParentDrawRect.width()));
3608 expectedParentDrawRect.setHeight(ceil(expectedParentDrawRect.height()));
3609 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentDrawRect);
3610 EXPECT_FLOAT_RECT_EQ(expectedParentDrawRect, parentScreenSpaceRect);
3611
3612 // Verify child transforms
3613 WebTransformationMatrix expectedChildTransform;
3614 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform ());
3615 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->screenSpaceTr ansform());
3616
3617 // Verify results of transformed child rects
3618 FloatRect childContentBounds(FloatPoint(), FloatSize(child->contentBounds()) );
3619
3620 FloatRect childDrawRect = MathUtil::mapClippedRect(child->drawTransform(), c hildContentBounds);
3621 FloatRect childScreenSpaceRect = MathUtil::mapClippedRect(child->screenSpace Transform(), childContentBounds);
3622
3623 FloatRect expectedChildDrawRect(FloatPoint(), child->bounds());
3624 expectedChildDrawRect.scale(deviceScaleFactor);
3625 expectedChildDrawRect.setWidth(ceil(expectedChildDrawRect.width()));
3626 expectedChildDrawRect.setHeight(ceil(expectedChildDrawRect.height()));
3627 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childDrawRect);
3628 EXPECT_FLOAT_RECT_EQ(expectedChildDrawRect, childScreenSpaceRect);
3629
3630 // Verify childNoScale transforms
3631 WebTransformationMatrix expectedChildNoScaleTransform = child->drawTransform ();
3632 // All transforms operate on content rects. The child's content rect
3633 // incorporates device scale, but the childNoScale does not; add it here.
3634 expectedChildNoScaleTransform.scale(deviceScaleFactor);
3635 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >drawTransform());
3636 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildNoScaleTransform, childNoScale- >screenSpaceTransform());
3637 }
3638
3553 TEST(LayerTreeHostCommonTest, verifyContentsScale) 3639 TEST(LayerTreeHostCommonTest, verifyContentsScale)
3554 { 3640 {
3555 MockContentLayerClient delegate; 3641 MockContentLayerClient delegate;
3556 WebTransformationMatrix identityMatrix; 3642 WebTransformationMatrix identityMatrix;
3557 3643
3558 WebTransformationMatrix parentScaleMatrix; 3644 WebTransformationMatrix parentScaleMatrix;
3559 const double initialParentScale = 1.75; 3645 const double initialParentScale = 1.75;
3560 parentScaleMatrix.scale(initialParentScale); 3646 parentScaleMatrix.scale(initialParentScale);
3561 3647
3562 WebTransformationMatrix childScaleMatrix; 3648 WebTransformationMatrix childScaleMatrix;
(...skipping 30 matching lines...) Expand all
3593 double deviceScaleFactor = 2.5; 3679 double deviceScaleFactor = 2.5;
3594 double pageScaleFactor = 1.5; 3680 double pageScaleFactor = 1.5;
3595 3681
3596 // FIXME: Remove this when pageScaleFactor is applied in the compositor. 3682 // FIXME: Remove this when pageScaleFactor is applied in the compositor.
3597 WebTransformationMatrix pageScaleMatrix; 3683 WebTransformationMatrix pageScaleMatrix;
3598 pageScaleMatrix.scale(pageScaleFactor); 3684 pageScaleMatrix.scale(pageScaleFactor);
3599 parent->setSublayerTransform(pageScaleMatrix); 3685 parent->setSublayerTransform(pageScaleMatrix);
3600 3686
3601 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 3687 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
3602 3688
3603 EXPECT_FLOAT_EQ(deviceScaleFactor * initialParentScale, parent->contentsScal e()); 3689 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent);
3604 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale, childScale->contentsScale()); 3690 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, childScale);
3605 EXPECT_FLOAT_EQ(1, childNoScale->contentsScale()); 3691 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale);
3606 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterScale, chil dNoAutoScale->contentsScale()); 3692 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterSc ale, childNoAutoScale);
3607 3693
3608 // The parent is scaled up and shouldn't need to scale during draw. The chil d that can scale its contents should 3694 // The parent is scaled up and shouldn't need to scale during draw. The chil d that can scale its contents should
3609 // also not need to scale during draw. The other should. 3695 // also not need to scale during draw. The other should.
3610 // There is some rounding error due to contentBounds being a rounded integer . 3696 // There is some rounding error due to contentBounds being a rounded integer .
3611 EXPECT_NEAR(parent->drawTransform().m11(), 1, 0.01); 3697 EXPECT_NEAR(parent->drawTransform().m11(), 1, 0.01);
3612 EXPECT_NEAR(parent->drawTransform().m22(), 1, 0.01); 3698 EXPECT_NEAR(parent->drawTransform().m22(), 1, 0.01);
3613 EXPECT_NEAR(childScale->drawTransform().m11(), 1, 0.01); 3699 EXPECT_NEAR(childScale->drawTransform().m11(), 1, 0.01);
3614 EXPECT_NEAR(childScale->drawTransform().m22(), 1, 0.01); 3700 EXPECT_NEAR(childScale->drawTransform().m22(), 1, 0.01);
3615 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale, childNoScale->drawTransform().m11()); 3701 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale, childNoScale->drawTransform().m11());
3616 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale, childNoScale->drawTransform().m22()); 3702 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale, childNoScale->drawTransform().m22());
3617 EXPECT_NEAR(childNoAutoScale->drawTransform().m11(), initialParentScale * in itialChildScale / fixedRasterScale, 0.01); 3703 EXPECT_NEAR(childNoAutoScale->drawTransform().m11(), initialParentScale * in itialChildScale / fixedRasterScale, 0.01);
3618 EXPECT_NEAR(childNoAutoScale->drawTransform().m22(), initialParentScale * in itialChildScale / fixedRasterScale, 0.01); 3704 EXPECT_NEAR(childNoAutoScale->drawTransform().m22(), initialParentScale * in itialChildScale / fixedRasterScale, 0.01);
3619 3705
3620 // If the transform changes, we expect the contentsScale to remain unchanged . 3706 // If the transform changes, we expect the contentsScale to remain unchanged .
3621 childScale->setTransform(identityMatrix); 3707 childScale->setTransform(identityMatrix);
3622 3708
3623 renderSurfaceLayerList.clear(); 3709 renderSurfaceLayerList.clear();
3624 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 3710 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
3625 3711
3626 EXPECT_FLOAT_EQ(deviceScaleFactor * initialParentScale, parent->contentsScal e()); 3712 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent);
3627 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale, childScale->contentsScale()); 3713 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, childScale);
3628 EXPECT_FLOAT_EQ(1, childNoScale->contentsScale()); 3714 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale);
3629 3715
3630 // But if the deviceScaleFactor or pageScaleFactor changes, then it should b e updated, but using the initial transform. 3716 // But if the deviceScaleFactor or pageScaleFactor changes, then it should b e updated, but using the initial transform.
3631 deviceScaleFactor = 2.25; 3717 deviceScaleFactor = 2.25;
3632 pageScaleFactor = 1.25; 3718 pageScaleFactor = 1.25;
3633 3719
3634 // FIXME: Remove this when pageScaleFactor is applied in the compositor. 3720 // FIXME: Remove this when pageScaleFactor is applied in the compositor.
3635 pageScaleMatrix = identityMatrix; 3721 pageScaleMatrix = identityMatrix;
3636 pageScaleMatrix.scale(pageScaleFactor); 3722 pageScaleMatrix.scale(pageScaleFactor);
3637 parent->setSublayerTransform(pageScaleMatrix); 3723 parent->setSublayerTransform(pageScaleMatrix);
3638 3724
3639 renderSurfaceLayerList.clear(); 3725 renderSurfaceLayerList.clear();
3640 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 3726 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
3641 3727
3642 EXPECT_FLOAT_EQ(deviceScaleFactor * initialParentScale, parent->contentsScal e()); 3728 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent);
3643 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * i nitialChildScale, childScale->contentsScale()); 3729 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, childScale);
3644 EXPECT_FLOAT_EQ(1, childNoScale->contentsScale()); 3730 EXPECT_CONTENTS_SCALE_EQ(1, childNoScale);
3645 EXPECT_FLOAT_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterScale, chil dNoAutoScale->contentsScale()); 3731 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterSc ale, childNoAutoScale);
3646 } 3732 }
3647 3733
3648 TEST(LayerTreeHostCommonTest, verifyContentsScaleForSurfaces) 3734 TEST(LayerTreeHostCommonTest, verifyContentsScaleForSurfaces)
3649 { 3735 {
3650 MockContentLayerClient delegate; 3736 MockContentLayerClient delegate;
3651 WebTransformationMatrix identityMatrix; 3737 WebTransformationMatrix identityMatrix;
3652 3738
3653 WebTransformationMatrix parentScaleMatrix; 3739 WebTransformationMatrix parentScaleMatrix;
3654 const double initialParentScale = 2; 3740 const double initialParentScale = 2;
3655 parentScaleMatrix.scale(initialParentScale); 3741 parentScaleMatrix.scale(initialParentScale);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3718 double deviceScaleFactor = 5; 3804 double deviceScaleFactor = 5;
3719 double pageScaleFactor = 7; 3805 double pageScaleFactor = 7;
3720 3806
3721 // FIXME: Remove this when pageScaleFactor is applied in the compositor. 3807 // FIXME: Remove this when pageScaleFactor is applied in the compositor.
3722 WebTransformationMatrix pageScaleMatrix; 3808 WebTransformationMatrix pageScaleMatrix;
3723 pageScaleMatrix.scale(pageScaleFactor); 3809 pageScaleMatrix.scale(pageScaleFactor);
3724 parent->setSublayerTransform(pageScaleMatrix); 3810 parent->setSublayerTransform(pageScaleMatrix);
3725 3811
3726 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList ); 3812 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, pageScaleFactor, dummyMaxTextureSize, renderSurfaceLayerList );
3727 3813
3728 EXPECT_EQ(deviceScaleFactor * initialParentScale, parent->contentsScale()); 3814 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * initialParentScale, parent);
3729 EXPECT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initial ChildScale, surfaceScale->contentsScale()); 3815 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale, surfaceScale);
3730 EXPECT_EQ(1, surfaceNoScale->contentsScale()); 3816 EXPECT_CONTENTS_SCALE_EQ(1, surfaceNoScale);
3731 EXPECT_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterScale, surfaceNoA utoScale->contentsScale()); 3817 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * fixedRasterSc ale, surfaceNoAutoScale);
3732 3818
3733 EXPECT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initial ChildScale * initialChildScale, surfaceScaleChildScale->contentsScale()); 3819 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale * initialChildScale, surfaceScaleChildScale);
3734 EXPECT_EQ(1, surfaceScaleChildNoScale->contentsScale()); 3820 EXPECT_CONTENTS_SCALE_EQ(1, surfaceScaleChildNoScale);
3735 EXPECT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initial ChildScale * initialChildScale, surfaceNoScaleChildScale->contentsScale()); 3821 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale * initialChildScale, surfaceNoScaleChildScale);
3736 EXPECT_EQ(1, surfaceNoScaleChildNoScale->contentsScale()); 3822 EXPECT_CONTENTS_SCALE_EQ(1, surfaceNoScaleChildNoScale);
3737 EXPECT_EQ(deviceScaleFactor * pageScaleFactor * initialParentScale * initial ChildScale * initialChildScale, surfaceNoAutoScaleChildScale->contentsScale()); 3823 EXPECT_CONTENTS_SCALE_EQ(deviceScaleFactor * pageScaleFactor * initialParent Scale * initialChildScale * initialChildScale, surfaceNoAutoScaleChildScale);
3738 EXPECT_EQ(1, surfaceNoAutoScaleChildNoScale->contentsScale()); 3824 EXPECT_CONTENTS_SCALE_EQ(1, surfaceNoAutoScaleChildNoScale);
3739 3825
3740 // The parent is scaled up and shouldn't need to scale during draw. 3826 // The parent is scaled up and shouldn't need to scale during draw.
3741 EXPECT_FLOAT_EQ(1, parent->drawTransform().m11()); 3827 EXPECT_FLOAT_EQ(1, parent->drawTransform().m11());
3742 EXPECT_FLOAT_EQ(1, parent->drawTransform().m22()); 3828 EXPECT_FLOAT_EQ(1, parent->drawTransform().m22());
3743 3829
3744 // RenderSurfaces should always be 1:1 with their target. 3830 // RenderSurfaces should always be 1:1 with their target.
3745 EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().m11()); 3831 EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().m11());
3746 EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().m22()); 3832 EXPECT_FLOAT_EQ(1, surfaceScale->renderSurface()->drawTransform().m22());
3747 3833
3748 // The surfaceScale can apply contents scale so the layer shouldn't need to scale during draw. 3834 // 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
3863 expectedReplicaDrawTransform.setM22(-1); 3949 expectedReplicaDrawTransform.setM22(-1);
3864 expectedReplicaDrawTransform.setM41(6); 3950 expectedReplicaDrawTransform.setM41(6);
3865 expectedReplicaDrawTransform.setM42(6); 3951 expectedReplicaDrawTransform.setM42(6);
3866 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaDrawTransform, child->renderS urface()->replicaDrawTransform()); 3952 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaDrawTransform, child->renderS urface()->replicaDrawTransform());
3867 3953
3868 WebTransformationMatrix expectedReplicaScreenSpaceTransform; 3954 WebTransformationMatrix expectedReplicaScreenSpaceTransform;
3869 expectedReplicaScreenSpaceTransform.setM22(-1); 3955 expectedReplicaScreenSpaceTransform.setM22(-1);
3870 expectedReplicaScreenSpaceTransform.setM41(6); 3956 expectedReplicaScreenSpaceTransform.setM41(6);
3871 expectedReplicaScreenSpaceTransform.setM42(6); 3957 expectedReplicaScreenSpaceTransform.setM42(6);
3872 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child-> renderSurface()->replicaScreenSpaceTransform()); 3958 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child-> renderSurface()->replicaScreenSpaceTransform());
3959 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child-> renderSurface()->replicaScreenSpaceTransform());
3960 }
3961
3962 TEST(LayerTreeHostCommonTest, verifyRenderSurfaceTransformsInHighDPIAccurateScal eZeroPosition)
3963 {
3964 MockContentLayerClient delegate;
3965 WebTransformationMatrix identityMatrix;
3966
3967 scoped_refptr<ContentLayer> parent = createDrawableContentLayer(&delegate);
3968 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, F loatPoint(0, 0), FloatPoint(0, 0), IntSize(33, 31), true);
3969
3970 scoped_refptr<ContentLayer> child = createDrawableContentLayer(&delegate);
3971 setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, Fl oatPoint(0, 0), FloatPoint(0, 0), IntSize(13, 11), true);
3972
3973 WebTransformationMatrix replicaTransform;
3974 replicaTransform.scaleNonUniform(1, -1);
3975 scoped_refptr<ContentLayer> replica = createDrawableContentLayer(&delegate);
3976 setLayerPropertiesForTesting(replica.get(), replicaTransform, identityMatrix , FloatPoint(0, 0), FloatPoint(0, 0), IntSize(13, 11), true);
3977
3978 // This layer should end up in the same surface as child, with the same draw
3979 // and screen space transforms.
3980 scoped_refptr<ContentLayer> duplicateChildNonOwner = createDrawableContentLa yer(&delegate);
3981 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i dentityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(13, 11), true);
3982
3983 parent->addChild(child);
3984 child->addChild(duplicateChildNonOwner);
3985 child->setReplicaLayer(replica.get());
3986
3987 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
3988 int dummyMaxTextureSize = 512;
3989
3990 const float deviceScaleFactor = 1.7f;
3991 parent->setContentsScale(deviceScaleFactor);
3992 child->setContentsScale(deviceScaleFactor);
3993 duplicateChildNonOwner->setContentsScale(deviceScaleFactor);
3994 replica->setContentsScale(deviceScaleFactor);
3995
3996 LayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), deviceScaleFactor, 1, dummyMaxTextureSize, renderSurfaceLayerList);
3997
3998 // We should have two render surfaces. The root's render surface and child's
3999 // render surface (it needs one because it has a replica layer).
4000 EXPECT_EQ(2u, renderSurfaceLayerList.size());
4001
4002 WebTransformationMatrix identityTransform;
4003
4004 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, parent->screenSpaceTransf orm());
4005 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, parent->drawTransform());
4006 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->drawTransform());
4007 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->screenSpaceTransfo rm());
4008 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, duplicateChildNonOwner->d rawTransform());
4009 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, duplicateChildNonOwner->s creenSpaceTransform());
4010 EXPECT_RECT_EQ(child->drawableContentRect(), duplicateChildNonOwner->drawabl eContentRect());
4011 EXPECT_EQ(child->contentBounds(), duplicateChildNonOwner->contentBounds());
4012
4013 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->renderSurface()->d rawTransform());
4014 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->renderSurface()->d rawTransform());
4015 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, child->renderSurface()->s creenSpaceTransform());
4016
4017 WebTransformationMatrix expectedReplicaDrawTransform;
4018 expectedReplicaDrawTransform.setM22(-1);
4019 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaDrawTransform, child->renderS urface()->replicaDrawTransform());
4020
4021 WebTransformationMatrix expectedReplicaScreenSpaceTransform;
4022 expectedReplicaScreenSpaceTransform.setM22(-1);
4023 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedReplicaScreenSpaceTransform, child-> renderSurface()->replicaScreenSpaceTransform());
3873 } 4024 }
3874 4025
3875 TEST(LayerTreeHostCommonTest, verifySubtreeSearch) 4026 TEST(LayerTreeHostCommonTest, verifySubtreeSearch)
3876 { 4027 {
3877 scoped_refptr<Layer> root = Layer::create(); 4028 scoped_refptr<Layer> root = Layer::create();
3878 scoped_refptr<Layer> child = Layer::create(); 4029 scoped_refptr<Layer> child = Layer::create();
3879 scoped_refptr<Layer> grandChild = Layer::create(); 4030 scoped_refptr<Layer> grandChild = Layer::create();
3880 scoped_refptr<Layer> maskLayer = Layer::create(); 4031 scoped_refptr<Layer> maskLayer = Layer::create();
3881 scoped_refptr<Layer> replicaLayer = Layer::create(); 4032 scoped_refptr<Layer> replicaLayer = Layer::create();
3882 4033
3883 grandChild->setReplicaLayer(replicaLayer.get()); 4034 grandChild->setReplicaLayer(replicaLayer.get());
3884 child->addChild(grandChild.get()); 4035 child->addChild(grandChild.get());
3885 child->setMaskLayer(maskLayer.get()); 4036 child->setMaskLayer(maskLayer.get());
3886 root->addChild(child.get()); 4037 root->addChild(child.get());
3887 4038
3888 int nonexistentId = -1; 4039 int nonexistentId = -1;
3889 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id ())); 4040 EXPECT_EQ(root, LayerTreeHostCommon::findLayerInSubtree(root.get(), root->id ()));
3890 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child-> id())); 4041 EXPECT_EQ(child, LayerTreeHostCommon::findLayerInSubtree(root.get(), child-> id()));
3891 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr andChild->id())); 4042 EXPECT_EQ(grandChild, LayerTreeHostCommon::findLayerInSubtree(root.get(), gr andChild->id()));
3892 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas kLayer->id())); 4043 EXPECT_EQ(maskLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), mas kLayer->id()));
3893 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), replicaLayer->id())); 4044 EXPECT_EQ(replicaLayer, LayerTreeHostCommon::findLayerInSubtree(root.get(), replicaLayer->id()));
3894 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent Id)); 4045 EXPECT_EQ(0, LayerTreeHostCommon::findLayerInSubtree(root.get(), nonexistent Id));
3895 } 4046 }
3896 4047
3897 } // namespace 4048 } // namespace
OLDNEW
« 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