| 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" |
| 11 #include "cc/test/test_shared_bitmap_manager.h" | 11 #include "cc/test/test_shared_bitmap_manager.h" |
| 12 #include "cc/test/test_task_graph_runner.h" | 12 #include "cc/test/test_task_graph_runner.h" |
| 13 #include "cc/trees/layer_tree_host_impl.h" | 13 #include "cc/trees/layer_tree_host_impl.h" |
| 14 #include "cc/trees/layer_tree_impl.h" | 14 #include "cc/trees/layer_tree_impl.h" |
| 15 #include "platform/graphics/CompositorMutableProperties.h" | 15 #include "platform/graphics/CompositorMutableProperties.h" |
| 16 #include "platform/graphics/CompositorMutableStateProvider.h" | 16 #include "platform/graphics/CompositorMutableStateProvider.h" |
| 17 #include "platform/graphics/CompositorMutation.h" | 17 #include "platform/graphics/CompositorMutation.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "wtf/OwnPtr.h" | 19 #include <memory> |
| 20 | 20 |
| 21 namespace blink { | 21 namespace blink { |
| 22 | 22 |
| 23 using cc::FakeImplTaskRunnerProvider; | 23 using cc::FakeImplTaskRunnerProvider; |
| 24 using cc::FakeLayerTreeHostImpl; | 24 using cc::FakeLayerTreeHostImpl; |
| 25 using cc::FakeOutputSurface; | 25 using cc::FakeOutputSurface; |
| 26 using cc::LayerImpl; | 26 using cc::LayerImpl; |
| 27 using cc::LayerTreeSettings; | 27 using cc::LayerTreeSettings; |
| 28 using cc::OutputSurface; | 28 using cc::OutputSurface; |
| 29 using cc::TestTaskGraphRunner; | 29 using cc::TestTaskGraphRunner; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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()->SetRootLayer(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 OwnPtr<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()->SetRootLayer(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 OwnPtr<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 { |
| 106 // In this test, there is a layer with an element id and mutable properties. | 106 // In this test, there is a layer with an element id and mutable properties. |
| 107 // In this case, we should get a valid mutable state for this element id tha
t | 107 // In this case, we should get a valid mutable state for this element id tha
t |
| 108 // has a real effect on the corresponding layer. | 108 // has a real effect on the corresponding layer. |
| 109 std::unique_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree()
, 42); | 109 std::unique_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree()
, 42); |
| 110 | 110 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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()->SetRootLayer(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 OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(layer->elem
ent_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()); |
| 137 EXPECT_EQ(0.0, layer->CurrentScrollOffset().x()); | 137 EXPECT_EQ(0.0, layer->CurrentScrollOffset().x()); |
| 138 EXPECT_EQ(0.0, layer->CurrentScrollOffset().y()); | 138 EXPECT_EQ(0.0, layer->CurrentScrollOffset().y()); |
| 139 | 139 |
| 140 gfx::Transform zero(0, 0, 0, 0, 0, 0); | 140 gfx::Transform zero(0, 0, 0, 0, 0, 0); |
| 141 state->setOpacity(0.5); | 141 state->setOpacity(0.5); |
| 142 state->setTransform(zero.matrix()); | 142 state->setTransform(zero.matrix()); |
| (...skipping 14 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 |