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

Side by Side Diff: cc/layer_tree_host_common_unittest.cc

Issue 11503005: cc: Refactor content scale/bounds into draw properties (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updateContentsScale => calculateContentsScale Created 8 years 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
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 "cc/layer_tree_host_common.h" 5 #include "cc/layer_tree_host_common.h"
6 6
7 #include "cc/content_layer.h" 7 #include "cc/content_layer.h"
8 #include "cc/content_layer_client.h" 8 #include "cc/content_layer_client.h"
9 #include "cc/layer.h" 9 #include "cc/layer.h"
10 #include "cc/layer_animation_controller.h" 10 #include "cc/layer_animation_controller.h"
(...skipping 2390 matching lines...) Expand 10 before | Expand all | Expand 10 after
2401 2401
2402 gfx::Transform identityMatrix; 2402 gfx::Transform identityMatrix;
2403 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false); 2403 setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, gfx ::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(100, 100), false);
2404 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(3, 4), false); 2404 setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(3, 4), false);
2405 setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(7, 13), false); 2405 setLayerPropertiesForTesting(renderSurface2.get(), identityMatrix, identityM atrix, gfx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(7, 13), false);
2406 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false); 2406 setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(5, 5), gfx::Size(50, 50), false);
2407 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false); 2407 setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(75, 75), gfx::Size(50, 50), false);
2408 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false); 2408 setLayerPropertiesForTesting(child3.get(), identityMatrix, identityMatrix, g fx::PointF(0, 0), gfx::PointF(125, 125), gfx::Size(50, 50), false);
2409 2409
2410 const double deviceScaleFactor = 2; 2410 const double deviceScaleFactor = 2;
2411 root->setContentsScale(deviceScaleFactor);
2412 renderSurface1->setContentsScale(deviceScaleFactor);
2413 renderSurface2->setContentsScale(deviceScaleFactor);
2414 child1->setContentsScale(deviceScaleFactor);
2415 child2->setContentsScale(deviceScaleFactor);
2416 child3->setContentsScale(deviceScaleFactor);
2417 2411
2418 root->setMasksToBounds(true); 2412 root->setMasksToBounds(true);
2419 renderSurface1->setForceRenderSurface(true); 2413 renderSurface1->setForceRenderSurface(true);
2420 renderSurface2->setForceRenderSurface(true); 2414 renderSurface2->setForceRenderSurface(true);
2421 executeCalculateDrawProperties(root.get(), deviceScaleFactor); 2415 executeCalculateDrawProperties(root.get(), deviceScaleFactor);
2422 2416
2423 ASSERT_TRUE(renderSurface1->renderSurface()); 2417 ASSERT_TRUE(renderSurface1->renderSurface());
2424 ASSERT_TRUE(renderSurface2->renderSurface()); 2418 ASSERT_TRUE(renderSurface2->renderSurface());
2425 2419
2426 // DrawableContentRects for all layers and surfaces are scaled by deviceScal eFactor. 2420 // DrawableContentRects for all layers and surfaces are scaled by deviceScal eFactor.
(...skipping 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after
3971 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList); 3965 resultLayer = LayerTreeHostCommon::findLayerThatIsHitByPointInTouchHandlerRe gion(testPoint, renderSurfaceLayerList);
3972 ASSERT_TRUE(resultLayer); 3966 ASSERT_TRUE(resultLayer);
3973 EXPECT_EQ(456, resultLayer->id()); 3967 EXPECT_EQ(456, resultLayer->id());
3974 } 3968 }
3975 3969
3976 class NoScaleContentLayer : public ContentLayer 3970 class NoScaleContentLayer : public ContentLayer
3977 { 3971 {
3978 public: 3972 public:
3979 static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client) { return make_scoped_refptr(new NoScaleContentLayer(client)); } 3973 static scoped_refptr<NoScaleContentLayer> create(ContentLayerClient* client) { return make_scoped_refptr(new NoScaleContentLayer(client)); }
3980 3974
3981 virtual gfx::Size contentBounds() const OVERRIDE { return bounds(); } 3975 virtual void didUpdateBounds() OVERRIDE
danakj 2012/12/14 22:58:41 You probably don't need this, as the contentScalin
enne (OOO) 2012/12/14 23:06:01 Done.
3982 virtual float contentsScaleX() const OVERRIDE { return 1.0; } 3976 {
3983 virtual float contentsScaleY() const OVERRIDE { return 1.0; } 3977 Layer::didUpdateBounds();
3978 }
3979
3980 virtual void calculateContentsScale(
3981 float idealContentsScale,
3982 float* contentsScaleX,
3983 float* contentsScaleY,
3984 gfx::Size* contentBounds) OVERRIDE
3985 {
3986 Layer::calculateContentsScale(
3987 idealContentsScale,
3988 contentsScaleX,
3989 contentsScaleY,
3990 contentBounds);
3991 }
3984 3992
3985 protected: 3993 protected:
3986 explicit NoScaleContentLayer(ContentLayerClient* client) : ContentLayer(clie nt) { } 3994 explicit NoScaleContentLayer(ContentLayerClient* client) : ContentLayer(clie nt) { }
3987 virtual ~NoScaleContentLayer() { } 3995 virtual ~NoScaleContentLayer() { }
3988 }; 3996 };
3989 3997
3990 scoped_refptr<NoScaleContentLayer> createNoScaleDrawableContentLayer(ContentLaye rClient* delegate) 3998 scoped_refptr<NoScaleContentLayer> createNoScaleDrawableContentLayer(ContentLaye rClient* delegate)
3991 { 3999 {
3992 scoped_refptr<NoScaleContentLayer> toReturn = NoScaleContentLayer::create(de legate); 4000 scoped_refptr<NoScaleContentLayer> toReturn = NoScaleContentLayer::create(de legate);
3993 toReturn->setIsDrawable(true); 4001 toReturn->setIsDrawable(true);
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
4527 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i dentityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), true); 4535 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i dentityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 10), true);
4528 4536
4529 parent->addChild(child); 4537 parent->addChild(child);
4530 child->addChild(duplicateChildNonOwner); 4538 child->addChild(duplicateChildNonOwner);
4531 child->setReplicaLayer(replica.get()); 4539 child->setReplicaLayer(replica.get());
4532 4540
4533 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 4541 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
4534 int dummyMaxTextureSize = 512; 4542 int dummyMaxTextureSize = 512;
4535 4543
4536 const double deviceScaleFactor = 1.5; 4544 const double deviceScaleFactor = 1.5;
4537 parent->setContentsScale(deviceScaleFactor);
4538 child->setContentsScale(deviceScaleFactor);
4539 duplicateChildNonOwner->setContentsScale(deviceScaleFactor);
4540 replica->setContentsScale(deviceScaleFactor);
4541
4542 LayerTreeHostCommon::calculateDrawProperties(parent.get(), parent->bounds(), deviceScaleFactor, 1, dummyMaxTextureSize, false, renderSurfaceLayerList); 4545 LayerTreeHostCommon::calculateDrawProperties(parent.get(), parent->bounds(), deviceScaleFactor, 1, dummyMaxTextureSize, false, renderSurfaceLayerList);
4543 4546
4544 // We should have two render surfaces. The root's render surface and child's 4547 // We should have two render surfaces. The root's render surface and child's
4545 // render surface (it needs one because it has a replica layer). 4548 // render surface (it needs one because it has a replica layer).
4546 EXPECT_EQ(2u, renderSurfaceLayerList.size()); 4549 EXPECT_EQ(2u, renderSurfaceLayerList.size());
4547 4550
4548 gfx::Transform expectedParentTransform; 4551 gfx::Transform expectedParentTransform;
4549 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform()); 4552 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->screenSpace Transform());
4550 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm()); 4553 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedParentTransform, parent->drawTransfo rm());
4551 4554
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
4610 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i dentityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 11), true); 4613 setLayerPropertiesForTesting(duplicateChildNonOwner.get(), identityMatrix, i dentityMatrix, gfx::PointF(0, 0), gfx::PointF(0, 0), gfx::Size(13, 11), true);
4611 4614
4612 parent->addChild(child); 4615 parent->addChild(child);
4613 child->addChild(duplicateChildNonOwner); 4616 child->addChild(duplicateChildNonOwner);
4614 child->setReplicaLayer(replica.get()); 4617 child->setReplicaLayer(replica.get());
4615 4618
4616 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; 4619 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList;
4617 int dummyMaxTextureSize = 512; 4620 int dummyMaxTextureSize = 512;
4618 4621
4619 const float deviceScaleFactor = 1.7f; 4622 const float deviceScaleFactor = 1.7f;
4620 parent->setContentsScale(deviceScaleFactor);
4621 child->setContentsScale(deviceScaleFactor);
4622 duplicateChildNonOwner->setContentsScale(deviceScaleFactor);
4623 replica->setContentsScale(deviceScaleFactor);
4624
4625 LayerTreeHostCommon::calculateDrawProperties(parent.get(), parent->bounds(), deviceScaleFactor, 1, dummyMaxTextureSize, false, renderSurfaceLayerList); 4623 LayerTreeHostCommon::calculateDrawProperties(parent.get(), parent->bounds(), deviceScaleFactor, 1, dummyMaxTextureSize, false, renderSurfaceLayerList);
4626 4624
4627 // We should have two render surfaces. The root's render surface and child's 4625 // We should have two render surfaces. The root's render surface and child's
4628 // render surface (it needs one because it has a replica layer). 4626 // render surface (it needs one because it has a replica layer).
4629 EXPECT_EQ(2u, renderSurfaceLayerList.size()); 4627 EXPECT_EQ(2u, renderSurfaceLayerList.size());
4630 4628
4631 gfx::Transform identityTransform; 4629 gfx::Transform identityTransform;
4632 4630
4633 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, parent->screenSpaceTransf orm()); 4631 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, parent->screenSpaceTransf orm());
4634 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, parent->drawTransform()); 4632 EXPECT_TRANSFORMATION_MATRIX_EQ(identityTransform, parent->drawTransform());
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
4812 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText()); 4810 EXPECT_EQ(m_canUseLCDText, m_grandChild->canUseLCDText());
4813 } 4811 }
4814 4812
4815 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, 4813 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
4816 LCDTextTest, 4814 LCDTextTest,
4817 testing::Combine(testing::Bool(), 4815 testing::Combine(testing::Bool(),
4818 testing::Bool())); 4816 testing::Bool()));
4819 4817
4820 } // namespace 4818 } // namespace
4821 } // namespace cc 4819 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698