| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/contents_scaling_layer.h" | 5 #include "cc/contents_scaling_layer.h" |
| 6 | 6 |
| 7 #include "cc/test/geometry_test_utils.h" | 7 #include "cc/test/geometry_test_utils.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace cc { | 10 namespace cc { |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 class MockContentsScalingLayer : public ContentsScalingLayer { | 13 class MockContentsScalingLayer : public ContentsScalingLayer { |
| 14 public: | 14 public: |
| 15 MockContentsScalingLayer() | 15 MockContentsScalingLayer() |
| 16 : ContentsScalingLayer() { | 16 : ContentsScalingLayer() { |
| 17 } | 17 } |
| 18 | 18 |
| 19 virtual void setNeedsDisplayRect(const gfx::RectF& dirtyRect) OVERRIDE { | 19 virtual void SetNeedsDisplayRect(const gfx::RectF& dirtyRect) OVERRIDE { |
| 20 m_lastNeedsDisplayRect = dirtyRect; | 20 m_lastNeedsDisplayRect = dirtyRect; |
| 21 ContentsScalingLayer::setNeedsDisplayRect(dirtyRect); | 21 ContentsScalingLayer::SetNeedsDisplayRect(dirtyRect); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void resetNeedsDisplay() { | 24 void resetNeedsDisplay() { |
| 25 m_needsDisplay = false; | 25 needs_display_ = false; |
| 26 } | 26 } |
| 27 | 27 |
| 28 const gfx::RectF& lastNeedsDisplayRect() const { | 28 const gfx::RectF& lastNeedsDisplayRect() const { |
| 29 return m_lastNeedsDisplayRect; | 29 return m_lastNeedsDisplayRect; |
| 30 } | 30 } |
| 31 | 31 |
| 32 void updateContentsScale(float contentsScale) { | 32 void updateContentsScale(float contentsScale) { |
| 33 // Simulate calcDrawProperties. | 33 // Simulate calcDrawProperties. |
| 34 calculateContentsScale( | 34 CalculateContentsScale( |
| 35 contentsScale, | 35 contentsScale, |
| 36 false, // animating_transform_to_screen | 36 false, // animating_transform_to_screen |
| 37 &drawProperties().contents_scale_x, | 37 &draw_properties().contents_scale_x, |
| 38 &drawProperties().contents_scale_y, | 38 &draw_properties().contents_scale_y, |
| 39 &drawProperties().content_bounds); | 39 &draw_properties().content_bounds); |
| 40 } | 40 } |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 virtual ~MockContentsScalingLayer() { | 43 virtual ~MockContentsScalingLayer() { |
| 44 } | 44 } |
| 45 | 45 |
| 46 gfx::RectF m_lastNeedsDisplayRect; | 46 gfx::RectF m_lastNeedsDisplayRect; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 void calcDrawProps(Layer* root, float deviceScale) | 49 void calcDrawProps(Layer* root, float deviceScale) |
| 50 { | 50 { |
| 51 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; | 51 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; |
| 52 LayerTreeHostCommon::calculateDrawProperties( | 52 LayerTreeHostCommon::calculateDrawProperties( |
| 53 root, | 53 root, |
| 54 gfx::Size(500, 500), | 54 gfx::Size(500, 500), |
| 55 deviceScale, | 55 deviceScale, |
| 56 1, | 56 1, |
| 57 1024, | 57 1024, |
| 58 false, | 58 false, |
| 59 renderSurfaceLayerList); | 59 renderSurfaceLayerList); |
| 60 } | 60 } |
| 61 | 61 |
| 62 TEST(ContentsScalingLayerTest, checkContentsBounds) { | 62 TEST(ContentsScalingLayerTest, checkContentsBounds) { |
| 63 scoped_refptr<MockContentsScalingLayer> testLayer = | 63 scoped_refptr<MockContentsScalingLayer> testLayer = |
| 64 make_scoped_refptr(new MockContentsScalingLayer()); | 64 make_scoped_refptr(new MockContentsScalingLayer()); |
| 65 | 65 |
| 66 scoped_refptr<Layer> root = Layer::create(); | 66 scoped_refptr<Layer> root = Layer::Create(); |
| 67 root->addChild(testLayer); | 67 root->AddChild(testLayer); |
| 68 | 68 |
| 69 testLayer->setBounds(gfx::Size(320, 240)); | 69 testLayer->SetBounds(gfx::Size(320, 240)); |
| 70 calcDrawProps(root, 1.0); | 70 calcDrawProps(root, 1.0); |
| 71 EXPECT_FLOAT_EQ(1.0, testLayer->contentsScaleX()); | 71 EXPECT_FLOAT_EQ(1.0, testLayer->contents_scale_x()); |
| 72 EXPECT_FLOAT_EQ(1.0, testLayer->contentsScaleY()); | 72 EXPECT_FLOAT_EQ(1.0, testLayer->contents_scale_y()); |
| 73 EXPECT_EQ(320, testLayer->contentBounds().width()); | 73 EXPECT_EQ(320, testLayer->content_bounds().width()); |
| 74 EXPECT_EQ(240, testLayer->contentBounds().height()); | 74 EXPECT_EQ(240, testLayer->content_bounds().height()); |
| 75 | 75 |
| 76 calcDrawProps(root, 2.0); | 76 calcDrawProps(root, 2.0); |
| 77 EXPECT_EQ(640, testLayer->contentBounds().width()); | 77 EXPECT_EQ(640, testLayer->content_bounds().width()); |
| 78 EXPECT_EQ(480, testLayer->contentBounds().height()); | 78 EXPECT_EQ(480, testLayer->content_bounds().height()); |
| 79 | 79 |
| 80 testLayer->setBounds(gfx::Size(10, 20)); | 80 testLayer->SetBounds(gfx::Size(10, 20)); |
| 81 calcDrawProps(root, 2.0); | 81 calcDrawProps(root, 2.0); |
| 82 EXPECT_EQ(20, testLayer->contentBounds().width()); | 82 EXPECT_EQ(20, testLayer->content_bounds().width()); |
| 83 EXPECT_EQ(40, testLayer->contentBounds().height()); | 83 EXPECT_EQ(40, testLayer->content_bounds().height()); |
| 84 | 84 |
| 85 calcDrawProps(root, 1.33f); | 85 calcDrawProps(root, 1.33f); |
| 86 EXPECT_EQ(14, testLayer->contentBounds().width()); | 86 EXPECT_EQ(14, testLayer->content_bounds().width()); |
| 87 EXPECT_EQ(27, testLayer->contentBounds().height()); | 87 EXPECT_EQ(27, testLayer->content_bounds().height()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 } // namespace | 90 } // namespace |
| 91 } // namespace cc | 91 } // namespace cc |
| OLD | NEW |