| 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 "cc/layer.h" | 5 #include "cc/layer.h" |
| 6 | 6 |
| 7 #include "cc/keyframed_animation_curve.h" | 7 #include "cc/keyframed_animation_curve.h" |
| 8 #include "cc/layer_impl.h" | 8 #include "cc/layer_impl.h" |
| 9 #include "cc/layer_painter.h" | 9 #include "cc/layer_painter.h" |
| 10 #include "cc/layer_tree_host.h" | 10 #include "cc/layer_tree_host.h" |
| 11 #include "cc/settings.h" | |
| 12 #include "cc/single_thread_proxy.h" | 11 #include "cc/single_thread_proxy.h" |
| 13 #include "cc/thread.h" | 12 #include "cc/thread.h" |
| 14 #include "cc/test/fake_layer_tree_host_client.h" | 13 #include "cc/test/fake_layer_tree_host_client.h" |
| 15 #include "cc/test/geometry_test_utils.h" | 14 #include "cc/test/geometry_test_utils.h" |
| 16 #include "cc/test/test_common.h" | |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include <public/WebTransformationMatrix.h> | 17 #include <public/WebTransformationMatrix.h> |
| 20 | 18 |
| 21 using namespace WebKitTests; | 19 using namespace WebKitTests; |
| 22 using WebKit::WebTransformationMatrix; | 20 using WebKit::WebTransformationMatrix; |
| 23 using ::testing::Mock; | 21 using ::testing::Mock; |
| 24 using ::testing::_; | 22 using ::testing::_; |
| 25 using ::testing::AtLeast; | 23 using ::testing::AtLeast; |
| 26 using ::testing::AnyNumber; | 24 using ::testing::AnyNumber; |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 | 539 |
| 542 // If we do clear the LayerImpl side, then the next updateRect should be fre
sh without accumulation. | 540 // If we do clear the LayerImpl side, then the next updateRect should be fre
sh without accumulation. |
| 543 implLayer->resetAllChangeTrackingForSubtree(); | 541 implLayer->resetAllChangeTrackingForSubtree(); |
| 544 testLayer->setNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5,
5))); | 542 testLayer->setNeedsDisplayRect(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5,
5))); |
| 545 testLayer->pushPropertiesTo(implLayer.get()); | 543 testLayer->pushPropertiesTo(implLayer.get()); |
| 546 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5)), impl
Layer->updateRect()); | 544 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(10, 10), gfx::SizeF(5, 5)), impl
Layer->updateRect()); |
| 547 } | 545 } |
| 548 | 546 |
| 549 class FakeLayerImplTreeHost : public LayerTreeHost { | 547 class FakeLayerImplTreeHost : public LayerTreeHost { |
| 550 public: | 548 public: |
| 551 static scoped_ptr<FakeLayerImplTreeHost> create() | 549 static scoped_ptr<FakeLayerImplTreeHost> create(const LayerTreeSettings& set
tings = LayerTreeSettings()) |
| 552 { | 550 { |
| 553 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost); | 551 scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost(setting
s)); |
| 554 // The initialize call will fail, since our client doesn't provide a val
id GraphicsContext3D, but it doesn't matter in the tests that use this fake so i
gnore the return value. | 552 // The initialize call will fail, since our client doesn't provide a val
id GraphicsContext3D, but it doesn't matter in the tests that use this fake so i
gnore the return value. |
| 555 host->initialize(scoped_ptr<Thread>(NULL)); | 553 host->initialize(scoped_ptr<Thread>(NULL)); |
| 556 return host.Pass(); | 554 return host.Pass(); |
| 557 } | 555 } |
| 558 | 556 |
| 559 private: | 557 private: |
| 560 FakeLayerImplTreeHost() | 558 FakeLayerImplTreeHost(const LayerTreeSettings& settings) |
| 561 : LayerTreeHost(&m_client, LayerTreeSettings()) | 559 : LayerTreeHost(&m_client, settings) |
| 562 { | 560 { |
| 563 } | 561 } |
| 564 | 562 |
| 565 FakeLayerImplTreeHostClient m_client; | 563 FakeLayerImplTreeHostClient m_client; |
| 566 }; | 564 }; |
| 567 | 565 |
| 568 void assertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host) | 566 void assertLayerTreeHostMatchesForSubtree(Layer* layer, LayerTreeHost* host) |
| 569 { | 567 { |
| 570 EXPECT_EQ(host, layer->layerTreeHost()); | 568 EXPECT_EQ(host, layer->layerTreeHost()); |
| 571 | 569 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 return layer->addAnimation(animation.Pass()); | 749 return layer->addAnimation(animation.Pass()); |
| 752 } | 750 } |
| 753 | 751 |
| 754 TEST(LayerLayerTreeHostTest, shouldNotAddAnimationWithoutLayerTreeHost) | 752 TEST(LayerLayerTreeHostTest, shouldNotAddAnimationWithoutLayerTreeHost) |
| 755 { | 753 { |
| 756 // Currently, WebCore assumes that animations will be started immediately /
very soon | 754 // Currently, WebCore assumes that animations will be started immediately /
very soon |
| 757 // if a composited layer's addAnimation() returns true. However, without a l
ayerTreeHost, | 755 // if a composited layer's addAnimation() returns true. However, without a l
ayerTreeHost, |
| 758 // layers cannot actually animate yet. So, to prevent violating this WebCore
assumption, | 756 // layers cannot actually animate yet. So, to prevent violating this WebCore
assumption, |
| 759 // the animation should not be accepted if the layer doesn't already have a
layerTreeHost. | 757 // the animation should not be accepted if the layer doesn't already have a
layerTreeHost. |
| 760 | 758 |
| 761 ScopedSettings scopedSettings; | 759 LayerTreeSettings settings; |
| 762 Settings::setAcceleratedAnimationEnabled(true); | 760 settings.acceleratedAnimationEnabled = true; |
| 763 | 761 |
| 764 scoped_refptr<Layer> layer = Layer::create(); | 762 scoped_refptr<Layer> layer = Layer::create(); |
| 765 | 763 |
| 766 // Case 1: without a layerTreeHost, the animation should not be accepted. | 764 // Case 1: without a layerTreeHost, the animation should not be accepted. |
| 767 EXPECT_FALSE(addTestAnimation(layer.get())); | 765 EXPECT_FALSE(addTestAnimation(layer.get())); |
| 768 | 766 |
| 769 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat
e()); | 767 scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::creat
e(settings)); |
| 770 layerTreeHost->setRootLayer(layer.get()); | 768 layerTreeHost->setRootLayer(layer.get()); |
| 771 layer->setLayerTreeHost(layerTreeHost.get()); | 769 layer->setLayerTreeHost(layerTreeHost.get()); |
| 772 assertLayerTreeHostMatchesForSubtree(layer.get(), layerTreeHost.get()); | 770 assertLayerTreeHostMatchesForSubtree(layer.get(), layerTreeHost.get()); |
| 773 | 771 |
| 774 // Case 2: with a layerTreeHost, the animation should be accepted. | 772 // Case 2: with a layerTreeHost, the animation should be accepted. |
| 775 EXPECT_TRUE(addTestAnimation(layer.get())); | 773 EXPECT_TRUE(addTestAnimation(layer.get())); |
| 776 } | 774 } |
| 777 | 775 |
| 778 class MockLayer : public Layer { | 776 class MockLayer : public Layer { |
| 779 public: | 777 public: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 790 scoped_refptr<MockLayer> layer(new MockLayer); | 788 scoped_refptr<MockLayer> layer(new MockLayer); |
| 791 EXPECT_FALSE(layer->needsDisplay()); | 789 EXPECT_FALSE(layer->needsDisplay()); |
| 792 layer->setBounds(gfx::Size(0, 10)); | 790 layer->setBounds(gfx::Size(0, 10)); |
| 793 EXPECT_FALSE(layer->needsDisplay()); | 791 EXPECT_FALSE(layer->needsDisplay()); |
| 794 layer->setBounds(gfx::Size(10, 10)); | 792 layer->setBounds(gfx::Size(10, 10)); |
| 795 EXPECT_TRUE(layer->needsDisplay()); | 793 EXPECT_TRUE(layer->needsDisplay()); |
| 796 } | 794 } |
| 797 | 795 |
| 798 } // namespace | 796 } // namespace |
| 799 } // namespace cc | 797 } // namespace cc |
| OLD | NEW |