| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "platform/graphics/CompositorMutableState.h" | 5 #include "platform/graphics/CompositorMutableState.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "cc/test/fake_impl_task_runner_provider.h" | 8 #include "cc/test/fake_impl_task_runner_provider.h" |
| 9 #include "cc/test/fake_layer_tree_host_impl.h" | 9 #include "cc/test/fake_layer_tree_host_impl.h" |
| 10 #include "cc/test/fake_output_surface.h" | 10 #include "cc/test/fake_output_surface.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 { | 45 { |
| 46 layer->SetTransform(gfx::Transform()); | 46 layer->SetTransform(gfx::Transform()); |
| 47 layer->SetPosition(gfx::PointF()); | 47 layer->SetPosition(gfx::PointF()); |
| 48 layer->SetBounds(gfx::Size(100, 100)); | 48 layer->SetBounds(gfx::Size(100, 100)); |
| 49 layer->Set3dSortingContextId(0); | 49 layer->Set3dSortingContextId(0); |
| 50 layer->SetDrawsContent(true); | 50 layer->SetDrawsContent(true); |
| 51 } | 51 } |
| 52 | 52 |
| 53 FakeLayerTreeHostImpl& hostImpl() { return *m_hostImpl; } | 53 FakeLayerTreeHostImpl& hostImpl() { return *m_hostImpl; } |
| 54 | 54 |
| 55 LayerImpl* rootLayer() { return m_hostImpl->active_tree()->root_layer(); } | 55 LayerImpl* rootLayer() { return m_hostImpl->active_tree()->root_layer_for_te
sting(); } |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 // The cc testing machinery has fairly deep dependency on having a main | 58 // The cc testing machinery has fairly deep dependency on having a main |
| 59 // message loop (one example is the task runner provider). We construct one | 59 // message loop (one example is the task runner provider). We construct one |
| 60 // here so that it's installed in TLA and can be found by other cc classes. | 60 // here so that it's installed in TLA and can be found by other cc classes. |
| 61 base::MessageLoop m_messageLoop; | 61 base::MessageLoop m_messageLoop; |
| 62 TestSharedBitmapManager m_sharedBitmapManager; | 62 TestSharedBitmapManager m_sharedBitmapManager; |
| 63 TestTaskGraphRunner m_taskGraphRunner; | 63 TestTaskGraphRunner m_taskGraphRunner; |
| 64 FakeImplTaskRunnerProvider m_taskRunnerProvider; | 64 FakeImplTaskRunnerProvider m_taskRunnerProvider; |
| 65 std::unique_ptr<OutputSurface> m_outputSurface; | 65 std::unique_ptr<OutputSurface> m_outputSurface; |
| 66 std::unique_ptr<FakeLayerTreeHostImpl> m_hostImpl; | 66 std::unique_ptr<FakeLayerTreeHostImpl> m_hostImpl; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 TEST_F(CompositorMutableStateTest, NoMutableState) | 69 TEST_F(CompositorMutableStateTest, NoMutableState) |
| 70 { | 70 { |
| 71 // In this test, there are no layers with either an element id or mutable | 71 // In this test, there are no layers with either an element id or mutable |
| 72 // properties. We should not be able to get any mutable state. | 72 // properties. We should not be able to get any mutable state. |
| 73 std::unique_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree()
, 42); | 73 std::unique_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree()
, 42); |
| 74 SetLayerPropertiesForTesting(root.get()); | 74 SetLayerPropertiesForTesting(root.get()); |
| 75 | 75 |
| 76 hostImpl().SetViewportSize(root->bounds()); | 76 hostImpl().SetViewportSize(root->bounds()); |
| 77 hostImpl().active_tree()->SetRootLayer(std::move(root)); | 77 hostImpl().active_tree()->SetRootLayerForTesting(std::move(root)); |
| 78 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 78 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 79 | 79 |
| 80 CompositorMutations mutations; | 80 CompositorMutations mutations; |
| 81 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations
); | 81 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations
); |
| 82 std::unique_ptr<CompositorMutableState> state(provider.getMutableStateFor(42
)); | 82 std::unique_ptr<CompositorMutableState> state(provider.getMutableStateFor(42
)); |
| 83 EXPECT_FALSE(state); | 83 EXPECT_FALSE(state); |
| 84 } | 84 } |
| 85 | 85 |
| 86 TEST_F(CompositorMutableStateTest, MutableStateNoMutableProperties) | 86 TEST_F(CompositorMutableStateTest, MutableStateNoMutableProperties) |
| 87 { | 87 { |
| 88 // In this test, there is a layer with an element id, but no mutable | 88 // In this test, there is a layer with an element id, but no mutable |
| 89 // properties. This should behave just as if we'd had no element id. | 89 // properties. This should behave just as if we'd had no element id. |
| 90 std::unique_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree()
, 42); | 90 std::unique_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree()
, 42); |
| 91 SetLayerPropertiesForTesting(root.get()); | 91 SetLayerPropertiesForTesting(root.get()); |
| 92 root->SetElementId(42); | 92 root->SetElementId(42); |
| 93 | 93 |
| 94 hostImpl().SetViewportSize(root->bounds()); | 94 hostImpl().SetViewportSize(root->bounds()); |
| 95 hostImpl().active_tree()->SetRootLayer(std::move(root)); | 95 hostImpl().active_tree()->SetRootLayerForTesting(std::move(root)); |
| 96 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 96 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 97 | 97 |
| 98 CompositorMutations mutations; | 98 CompositorMutations mutations; |
| 99 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations
); | 99 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations
); |
| 100 std::unique_ptr<CompositorMutableState> state(provider.getMutableStateFor(42
)); | 100 std::unique_ptr<CompositorMutableState> state(provider.getMutableStateFor(42
)); |
| 101 EXPECT_FALSE(state); | 101 EXPECT_FALSE(state); |
| 102 } | 102 } |
| 103 | 103 |
| 104 TEST_F(CompositorMutableStateTest, MutableStateMutableProperties) | 104 TEST_F(CompositorMutableStateTest, MutableStateMutableProperties) |
| 105 { | 105 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 116 root->test_properties()->AddChild(std::move(scopedLayer)); | 116 root->test_properties()->AddChild(std::move(scopedLayer)); |
| 117 | 117 |
| 118 SetLayerPropertiesForTesting(layer); | 118 SetLayerPropertiesForTesting(layer); |
| 119 layer->SetElementId(12); | 119 layer->SetElementId(12); |
| 120 root->SetElementId(layer->element_id()); | 120 root->SetElementId(layer->element_id()); |
| 121 | 121 |
| 122 root->SetMutableProperties(CompositorMutableProperty::kOpacity | CompositorM
utableProperty::kTransform); | 122 root->SetMutableProperties(CompositorMutableProperty::kOpacity | CompositorM
utableProperty::kTransform); |
| 123 layer->SetMutableProperties(CompositorMutableProperty::kScrollLeft | Composi
torMutableProperty::kScrollTop); | 123 layer->SetMutableProperties(CompositorMutableProperty::kScrollLeft | Composi
torMutableProperty::kScrollTop); |
| 124 | 124 |
| 125 hostImpl().SetViewportSize(layer->bounds()); | 125 hostImpl().SetViewportSize(layer->bounds()); |
| 126 hostImpl().active_tree()->SetRootLayer(std::move(root)); | 126 hostImpl().active_tree()->SetRootLayerForTesting(std::move(root)); |
| 127 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 127 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 128 | 128 |
| 129 CompositorMutations mutations; | 129 CompositorMutations mutations; |
| 130 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations
); | 130 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations
); |
| 131 | 131 |
| 132 std::unique_ptr<CompositorMutableState> state(provider.getMutableStateFor(la
yer->element_id())); | 132 std::unique_ptr<CompositorMutableState> state(provider.getMutableStateFor(la
yer->element_id())); |
| 133 EXPECT_TRUE(state.get()); | 133 EXPECT_TRUE(state.get()); |
| 134 | 134 |
| 135 EXPECT_EQ(1.0, rootLayer()->Opacity()); | 135 EXPECT_EQ(1.0, rootLayer()->Opacity()); |
| 136 EXPECT_EQ(gfx::Transform().ToString(), rootLayer()->transform().ToString()); | 136 EXPECT_EQ(gfx::Transform().ToString(), rootLayer()->transform().ToString()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 157 EXPECT_TRUE(mutation.isScrollLeftMutated()); | 157 EXPECT_TRUE(mutation.isScrollLeftMutated()); |
| 158 EXPECT_TRUE(mutation.isScrollTopMutated()); | 158 EXPECT_TRUE(mutation.isScrollTopMutated()); |
| 159 | 159 |
| 160 EXPECT_EQ(0.5, mutation.opacity()); | 160 EXPECT_EQ(0.5, mutation.opacity()); |
| 161 EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString()); | 161 EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString()); |
| 162 EXPECT_EQ(1.0, mutation.scrollLeft()); | 162 EXPECT_EQ(1.0, mutation.scrollLeft()); |
| 163 EXPECT_EQ(1.0, mutation.scrollTop()); | 163 EXPECT_EQ(1.0, mutation.scrollTop()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 } // namespace blink | 166 } // namespace blink |
| OLD | NEW |