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