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 "wtf/OwnPtr.h" | 20 #include "wtf/OwnPtr.h" |
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()->SetRootLayer(std::move(root)); | 78 hostImpl().active_tree()->SetRootLayer(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 OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(42)); | 83 OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(42)); |
83 EXPECT_FALSE(state); | 84 EXPECT_FALSE(state); |
84 } | 85 } |
85 | 86 |
86 TEST_F(CompositorMutableStateTest, MutableStateNoMutableProperties) | 87 TEST_F(CompositorMutableStateTest, EnsureNoSubElementIdCollisions) |
87 { | 88 { |
88 // In this test, there is a layer with an element id, but no mutable | 89 // If we happen to do bit shifting in CompositorElementId, try to catch |
jbroman
2016/06/06 14:23:20
Is this test still meaningful with the current pai
Ian Vollick
2016/06/06 16:31:29
Not really. I'd put it in to catch a bug I'd cause
| |
89 // properties. This should behave just as if we'd had no element id. | 90 // cases where we forget to shift before bitwise or'ing. |
90 std::unique_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree() , 42); | 91 const int domNodeId = 42; |
91 SetLayerPropertiesForTesting(root.get()); | 92 CompositorElementId createdWithSubElement = createCompositorElementId(domNod eId, CompositorSubElementId::Scroll); |
92 root->SetElementId(42); | 93 CompositorElementId createdDirectly(static_cast<uint64_t>(domNodeId) | stati c_cast<uint64_t>(CompositorSubElementId::Scroll), 0); |
93 | 94 EXPECT_NE(createdWithSubElement, createdDirectly); |
94 hostImpl().SetViewportSize(root->bounds()); | |
95 hostImpl().active_tree()->SetRootLayer(std::move(root)); | |
96 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | |
97 | |
98 CompositorMutations mutations; | |
99 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations ); | |
100 OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(42)); | |
101 EXPECT_FALSE(state); | |
102 } | 95 } |
103 | 96 |
104 TEST_F(CompositorMutableStateTest, MutableStateMutableProperties) | 97 TEST_F(CompositorMutableStateTest, MutableStateMutableProperties) |
105 { | 98 { |
106 // In this test, there is a layer with an element id and mutable properties. | 99 // 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 | 100 // 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. | 101 // has a real effect on the corresponding layer. |
109 std::unique_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree() , 42); | 102 std::unique_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree() , 42); |
110 | 103 |
111 std::unique_ptr<LayerImpl> scopedLayer = | 104 std::unique_ptr<LayerImpl> scopedLayer = |
112 LayerImpl::Create(hostImpl().active_tree(), 11); | 105 LayerImpl::Create(hostImpl().active_tree(), 11); |
113 LayerImpl* layer = scopedLayer.get(); | 106 LayerImpl* layer = scopedLayer.get(); |
114 layer->SetScrollClipLayer(root->id()); | 107 layer->SetScrollClipLayer(root->id()); |
115 | 108 |
116 root->AddChild(std::move(scopedLayer)); | 109 root->AddChild(std::move(scopedLayer)); |
117 | 110 |
118 SetLayerPropertiesForTesting(layer); | 111 SetLayerPropertiesForTesting(layer); |
119 layer->SetElementId(12); | 112 |
120 root->SetElementId(layer->element_id()); | 113 int primaryId = 12; |
114 root->SetElementId(createCompositorElementId(primaryId, CompositorSubElement Id::Primary)); | |
115 layer->SetElementId(createCompositorElementId(primaryId, CompositorSubElemen tId::Scroll)); | |
121 | 116 |
122 root->SetMutableProperties(CompositorMutableProperty::kOpacity | CompositorM utableProperty::kTransform); | 117 root->SetMutableProperties(CompositorMutableProperty::kOpacity | CompositorM utableProperty::kTransform); |
123 layer->SetMutableProperties(CompositorMutableProperty::kScrollLeft | Composi torMutableProperty::kScrollTop); | 118 layer->SetMutableProperties(CompositorMutableProperty::kScrollLeft | Composi torMutableProperty::kScrollTop); |
124 | 119 |
125 hostImpl().SetViewportSize(layer->bounds()); | 120 hostImpl().SetViewportSize(layer->bounds()); |
126 hostImpl().active_tree()->SetRootLayer(std::move(root)); | 121 hostImpl().active_tree()->SetRootLayer(std::move(root)); |
127 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 122 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
128 | 123 |
129 CompositorMutations mutations; | 124 CompositorMutations mutations; |
130 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations ); | 125 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations ); |
131 | 126 |
132 OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(layer->elem ent_id())); | 127 OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(primaryId)) ; |
133 EXPECT_TRUE(state.get()); | 128 EXPECT_TRUE(state.get()); |
134 | 129 |
135 EXPECT_EQ(1.0, rootLayer()->Opacity()); | 130 EXPECT_EQ(1.0, rootLayer()->Opacity()); |
136 EXPECT_EQ(gfx::Transform().ToString(), rootLayer()->transform().ToString()); | 131 EXPECT_EQ(gfx::Transform().ToString(), rootLayer()->transform().ToString()); |
137 EXPECT_EQ(0.0, layer->CurrentScrollOffset().x()); | 132 EXPECT_EQ(0.0, layer->CurrentScrollOffset().x()); |
138 EXPECT_EQ(0.0, layer->CurrentScrollOffset().y()); | 133 EXPECT_EQ(0.0, layer->CurrentScrollOffset().y()); |
139 | 134 |
140 gfx::Transform zero(0, 0, 0, 0, 0, 0); | 135 gfx::Transform zero(0, 0, 0, 0, 0, 0); |
141 state->setOpacity(0.5); | 136 state->setOpacity(0.5); |
142 state->setTransform(zero.matrix()); | 137 state->setTransform(zero.matrix()); |
143 state->setScrollLeft(1.0); | 138 state->setScrollLeft(1.0); |
144 state->setScrollTop(1.0); | 139 state->setScrollTop(1.0); |
145 | 140 |
146 EXPECT_EQ(0.5, rootLayer()->Opacity()); | 141 EXPECT_EQ(0.5, rootLayer()->Opacity()); |
147 EXPECT_EQ(zero.ToString(), rootLayer()->transform().ToString()); | 142 EXPECT_EQ(zero.ToString(), rootLayer()->transform().ToString()); |
148 EXPECT_EQ(1.0, layer->CurrentScrollOffset().x()); | 143 EXPECT_EQ(1.0, layer->CurrentScrollOffset().x()); |
149 EXPECT_EQ(1.0, layer->CurrentScrollOffset().y()); | 144 EXPECT_EQ(1.0, layer->CurrentScrollOffset().y()); |
150 | 145 |
151 // The corresponding mutation should reflect the changed values. | 146 // The corresponding mutation should reflect the changed values. |
152 EXPECT_EQ(1ul, mutations.map.size()); | 147 EXPECT_EQ(1ul, mutations.map.size()); |
153 | 148 |
154 const CompositorMutation& mutation = *mutations.map.find(layer->element_id() )->value; | 149 const CompositorMutation& mutation = *mutations.map.find(primaryId)->value; |
155 EXPECT_TRUE(mutation.isOpacityMutated()); | 150 EXPECT_TRUE(mutation.isOpacityMutated()); |
156 EXPECT_TRUE(mutation.isTransformMutated()); | 151 EXPECT_TRUE(mutation.isTransformMutated()); |
157 EXPECT_TRUE(mutation.isScrollLeftMutated()); | 152 EXPECT_TRUE(mutation.isScrollLeftMutated()); |
158 EXPECT_TRUE(mutation.isScrollTopMutated()); | 153 EXPECT_TRUE(mutation.isScrollTopMutated()); |
159 | 154 |
160 EXPECT_EQ(0.5, mutation.opacity()); | 155 EXPECT_EQ(0.5, mutation.opacity()); |
161 EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString()); | 156 EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString()); |
162 EXPECT_EQ(1.0, mutation.scrollLeft()); | 157 EXPECT_EQ(1.0, mutation.scrollLeft()); |
163 EXPECT_EQ(1.0, mutation.scrollTop()); | 158 EXPECT_EQ(1.0, mutation.scrollTop()); |
164 } | 159 } |
165 | 160 |
166 } // namespace blink | 161 } // namespace blink |
OLD | NEW |