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/CompositorElementId.h" |
15 #include "platform/graphics/CompositorMutableProperties.h" | 16 #include "platform/graphics/CompositorMutableProperties.h" |
16 #include "platform/graphics/CompositorMutableStateProvider.h" | 17 #include "platform/graphics/CompositorMutableStateProvider.h" |
17 #include "platform/graphics/CompositorMutation.h" | 18 #include "platform/graphics/CompositorMutation.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 #include <memory> | 20 #include <memory> |
20 | 21 |
21 namespace blink { | 22 namespace blink { |
22 | 23 |
23 using cc::FakeImplTaskRunnerProvider; | 24 using cc::FakeImplTaskRunnerProvider; |
24 using cc::FakeLayerTreeHostImpl; | 25 using cc::FakeLayerTreeHostImpl; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 hostImpl().SetViewportSize(root->bounds()); | 77 hostImpl().SetViewportSize(root->bounds()); |
77 hostImpl().active_tree()->SetRootLayerForTesting(std::move(root)); | 78 hostImpl().active_tree()->SetRootLayerForTesting(std::move(root)); |
78 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 79 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
79 | 80 |
80 CompositorMutations mutations; | 81 CompositorMutations mutations; |
81 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations
); | 82 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations
); |
82 std::unique_ptr<CompositorMutableState> state(provider.getMutableStateFor(42
)); | 83 std::unique_ptr<CompositorMutableState> state(provider.getMutableStateFor(42
)); |
83 EXPECT_FALSE(state); | 84 EXPECT_FALSE(state); |
84 } | 85 } |
85 | 86 |
86 TEST_F(CompositorMutableStateTest, MutableStateNoMutableProperties) | |
87 { | |
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. | |
90 std::unique_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree()
, 42); | |
91 SetLayerPropertiesForTesting(root.get()); | |
92 root->SetElementId(42); | |
93 | |
94 hostImpl().SetViewportSize(root->bounds()); | |
95 hostImpl().active_tree()->SetRootLayerForTesting(std::move(root)); | |
96 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | |
97 | |
98 CompositorMutations mutations; | |
99 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations
); | |
100 std::unique_ptr<CompositorMutableState> state(provider.getMutableStateFor(42
)); | |
101 EXPECT_FALSE(state); | |
102 } | |
103 | |
104 TEST_F(CompositorMutableStateTest, MutableStateMutableProperties) | 87 TEST_F(CompositorMutableStateTest, MutableStateMutableProperties) |
105 { | 88 { |
106 // In this test, there is a layer with an element id and mutable properties. | 89 // 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 | 90 // 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. | 91 // has a real effect on the corresponding layer. |
109 std::unique_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree()
, 42); | 92 std::unique_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree()
, 42); |
110 | 93 |
111 std::unique_ptr<LayerImpl> scopedLayer = | 94 std::unique_ptr<LayerImpl> scopedLayer = |
112 LayerImpl::Create(hostImpl().active_tree(), 11); | 95 LayerImpl::Create(hostImpl().active_tree(), 11); |
113 LayerImpl* layer = scopedLayer.get(); | 96 LayerImpl* layer = scopedLayer.get(); |
114 layer->SetScrollClipLayer(root->id()); | 97 layer->SetScrollClipLayer(root->id()); |
115 | 98 |
116 root->test_properties()->AddChild(std::move(scopedLayer)); | 99 root->test_properties()->AddChild(std::move(scopedLayer)); |
117 | 100 |
118 SetLayerPropertiesForTesting(layer); | 101 SetLayerPropertiesForTesting(layer); |
119 layer->SetElementId(12); | 102 |
120 root->SetElementId(layer->element_id()); | 103 int primaryId = 12; |
| 104 root->SetElementId(createCompositorElementId(primaryId, CompositorSubElement
Id::Primary)); |
| 105 layer->SetElementId(createCompositorElementId(primaryId, CompositorSubElemen
tId::Scroll)); |
121 | 106 |
122 root->SetMutableProperties(CompositorMutableProperty::kOpacity | CompositorM
utableProperty::kTransform); | 107 root->SetMutableProperties(CompositorMutableProperty::kOpacity | CompositorM
utableProperty::kTransform); |
123 layer->SetMutableProperties(CompositorMutableProperty::kScrollLeft | Composi
torMutableProperty::kScrollTop); | 108 layer->SetMutableProperties(CompositorMutableProperty::kScrollLeft | Composi
torMutableProperty::kScrollTop); |
124 | 109 |
125 hostImpl().SetViewportSize(layer->bounds()); | 110 hostImpl().SetViewportSize(layer->bounds()); |
126 hostImpl().active_tree()->SetRootLayerForTesting(std::move(root)); | 111 hostImpl().active_tree()->SetRootLayerForTesting(std::move(root)); |
127 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 112 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
128 | 113 |
129 CompositorMutations mutations; | 114 CompositorMutations mutations; |
130 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations
); | 115 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations
); |
131 | 116 |
132 std::unique_ptr<CompositorMutableState> state(provider.getMutableStateFor(la
yer->element_id())); | 117 std::unique_ptr<CompositorMutableState> state(provider.getMutableStateFor(pr
imaryId)); |
133 EXPECT_TRUE(state.get()); | 118 EXPECT_TRUE(state.get()); |
134 | 119 |
135 EXPECT_EQ(1.0, rootLayer()->Opacity()); | 120 EXPECT_EQ(1.0, rootLayer()->Opacity()); |
136 EXPECT_EQ(gfx::Transform().ToString(), rootLayer()->transform().ToString()); | 121 EXPECT_EQ(gfx::Transform().ToString(), rootLayer()->transform().ToString()); |
137 EXPECT_EQ(0.0, layer->CurrentScrollOffset().x()); | 122 EXPECT_EQ(0.0, layer->CurrentScrollOffset().x()); |
138 EXPECT_EQ(0.0, layer->CurrentScrollOffset().y()); | 123 EXPECT_EQ(0.0, layer->CurrentScrollOffset().y()); |
139 | 124 |
140 gfx::Transform zero(0, 0, 0, 0, 0, 0); | 125 gfx::Transform zero(0, 0, 0, 0, 0, 0); |
141 state->setOpacity(0.5); | 126 state->setOpacity(0.5); |
142 state->setTransform(zero.matrix()); | 127 state->setTransform(zero.matrix()); |
143 state->setScrollLeft(1.0); | 128 state->setScrollLeft(1.0); |
144 state->setScrollTop(1.0); | 129 state->setScrollTop(1.0); |
145 | 130 |
146 EXPECT_EQ(0.5, rootLayer()->Opacity()); | 131 EXPECT_EQ(0.5, rootLayer()->Opacity()); |
147 EXPECT_EQ(zero.ToString(), rootLayer()->transform().ToString()); | 132 EXPECT_EQ(zero.ToString(), rootLayer()->transform().ToString()); |
148 EXPECT_EQ(1.0, layer->CurrentScrollOffset().x()); | 133 EXPECT_EQ(1.0, layer->CurrentScrollOffset().x()); |
149 EXPECT_EQ(1.0, layer->CurrentScrollOffset().y()); | 134 EXPECT_EQ(1.0, layer->CurrentScrollOffset().y()); |
150 | 135 |
151 // The corresponding mutation should reflect the changed values. | 136 // The corresponding mutation should reflect the changed values. |
152 EXPECT_EQ(1ul, mutations.map.size()); | 137 EXPECT_EQ(1ul, mutations.map.size()); |
153 | 138 |
154 const CompositorMutation& mutation = *mutations.map.find(layer->element_id()
)->value; | 139 const CompositorMutation& mutation = *mutations.map.find(primaryId)->value; |
155 EXPECT_TRUE(mutation.isOpacityMutated()); | 140 EXPECT_TRUE(mutation.isOpacityMutated()); |
156 EXPECT_TRUE(mutation.isTransformMutated()); | 141 EXPECT_TRUE(mutation.isTransformMutated()); |
157 EXPECT_TRUE(mutation.isScrollLeftMutated()); | 142 EXPECT_TRUE(mutation.isScrollLeftMutated()); |
158 EXPECT_TRUE(mutation.isScrollTopMutated()); | 143 EXPECT_TRUE(mutation.isScrollTopMutated()); |
159 | 144 |
160 EXPECT_EQ(0.5, mutation.opacity()); | 145 EXPECT_EQ(0.5, mutation.opacity()); |
161 EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString()); | 146 EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString()); |
162 EXPECT_EQ(1.0, mutation.scrollLeft()); | 147 EXPECT_EQ(1.0, mutation.scrollLeft()); |
163 EXPECT_EQ(1.0, mutation.scrollTop()); | 148 EXPECT_EQ(1.0, mutation.scrollTop()); |
164 } | 149 } |
165 | 150 |
166 } // namespace blink | 151 } // namespace blink |
OLD | NEW |