Chromium Code Reviews| 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_compositor_frame_sink.h" | 8 #include "cc/test/fake_compositor_frame_sink.h" |
| 9 #include "cc/test/fake_impl_task_runner_provider.h" | 9 #include "cc/test/fake_impl_task_runner_provider.h" |
| 10 #include "cc/test/fake_layer_tree_host_impl.h" | 10 #include "cc/test/fake_layer_tree_host_impl.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 LayerImpl::Create(hostImpl().active_tree(), 42); | 72 LayerImpl::Create(hostImpl().active_tree(), 42); |
| 73 SetLayerPropertiesForTesting(root.get()); | 73 SetLayerPropertiesForTesting(root.get()); |
| 74 | 74 |
| 75 hostImpl().SetViewportSize(root->bounds()); | 75 hostImpl().SetViewportSize(root->bounds()); |
| 76 hostImpl().active_tree()->SetRootLayerForTesting(std::move(root)); | 76 hostImpl().active_tree()->SetRootLayerForTesting(std::move(root)); |
| 77 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 77 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 78 | 78 |
| 79 CompositorMutations mutations; | 79 CompositorMutations mutations; |
| 80 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations); | 80 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations); |
| 81 std::unique_ptr<CompositorMutableState> state( | 81 std::unique_ptr<CompositorMutableState> state( |
| 82 provider.getMutableStateFor(42)); | 82 provider.getMutableStateFor(42, 42)); |
| 83 EXPECT_FALSE(state); | 83 EXPECT_FALSE(state); |
| 84 } | 84 } |
| 85 | 85 |
| 86 TEST_F(CompositorMutableStateTest, MutableStateMutableProperties) { | 86 TEST_F(CompositorMutableStateTest, MutableStateMutableProperties) { |
| 87 // In this test, there is a layer with an element id and mutable properties. | 87 // In this test, there is a layer with an element id and mutable properties. |
| 88 // In this case, we should get a valid mutable state for this element id that | 88 // In this case, we should get a valid mutable state for this element id that |
| 89 // has a real effect on the corresponding layer. | 89 // has a real effect on the corresponding layer. |
| 90 std::unique_ptr<LayerImpl> root = | 90 std::unique_ptr<LayerImpl> root = |
| 91 LayerImpl::Create(hostImpl().active_tree(), 42); | 91 LayerImpl::Create(hostImpl().active_tree(), 42); |
| 92 | 92 |
| 93 std::unique_ptr<LayerImpl> scopedLayer = | 93 std::unique_ptr<LayerImpl> scopedLayer = |
| 94 LayerImpl::Create(hostImpl().active_tree(), 11); | 94 LayerImpl::Create(hostImpl().active_tree(), 11); |
| 95 LayerImpl* layer = scopedLayer.get(); | 95 LayerImpl* layer = scopedLayer.get(); |
| 96 layer->SetScrollClipLayer(root->id()); | 96 layer->SetScrollClipLayer(root->id()); |
| 97 | 97 |
| 98 root->test_properties()->AddChild(std::move(scopedLayer)); | 98 root->test_properties()->AddChild(std::move(scopedLayer)); |
| 99 | 99 |
| 100 SetLayerPropertiesForTesting(layer); | 100 SetLayerPropertiesForTesting(layer); |
| 101 | 101 |
| 102 int primaryId = 12; | 102 int mainId = 12; |
| 103 int scrollId = 13; | |
|
flackr
2017/03/01 16:31:26
To be accurate to the real implementation, isn't t
| |
| 104 | |
| 103 root->SetElementId( | 105 root->SetElementId( |
| 104 createCompositorElementId(primaryId, CompositorSubElementId::Primary)); | 106 createCompositorElementId(mainId, CompositorSubElementId::Primary)); |
| 105 layer->SetElementId( | 107 layer->SetElementId( |
| 106 createCompositorElementId(primaryId, CompositorSubElementId::Scroll)); | 108 createCompositorElementId(scrollId, CompositorSubElementId::Scroll)); |
| 107 | 109 |
| 108 root->SetMutableProperties(CompositorMutableProperty::kOpacity | | 110 root->SetMutableProperties(CompositorMutableProperty::kOpacity | |
| 109 CompositorMutableProperty::kTransform); | 111 CompositorMutableProperty::kTransform); |
| 110 layer->SetMutableProperties(CompositorMutableProperty::kScrollLeft | | 112 layer->SetMutableProperties(CompositorMutableProperty::kScrollLeft | |
| 111 CompositorMutableProperty::kScrollTop); | 113 CompositorMutableProperty::kScrollTop); |
| 112 | 114 |
| 113 hostImpl().SetViewportSize(layer->bounds()); | 115 hostImpl().SetViewportSize(layer->bounds()); |
| 114 hostImpl().active_tree()->SetRootLayerForTesting(std::move(root)); | 116 hostImpl().active_tree()->SetRootLayerForTesting(std::move(root)); |
| 115 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | 117 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 116 | 118 |
| 117 CompositorMutations mutations; | 119 CompositorMutations mutations; |
| 118 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations); | 120 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations); |
| 119 | 121 |
| 120 std::unique_ptr<CompositorMutableState> state( | 122 std::unique_ptr<CompositorMutableState> state( |
| 121 provider.getMutableStateFor(primaryId)); | 123 provider.getMutableStateFor(mainId, scrollId)); |
| 122 EXPECT_TRUE(state.get()); | 124 EXPECT_TRUE(state.get()); |
| 123 | 125 |
| 124 EXPECT_EQ(1.0, rootLayer()->Opacity()); | 126 EXPECT_EQ(1.0, rootLayer()->Opacity()); |
| 125 EXPECT_EQ(gfx::Transform().ToString(), rootLayer()->Transform().ToString()); | 127 EXPECT_EQ(gfx::Transform().ToString(), rootLayer()->Transform().ToString()); |
| 126 EXPECT_EQ(0.0, layer->CurrentScrollOffset().x()); | 128 EXPECT_EQ(0.0, layer->CurrentScrollOffset().x()); |
| 127 EXPECT_EQ(0.0, layer->CurrentScrollOffset().y()); | 129 EXPECT_EQ(0.0, layer->CurrentScrollOffset().y()); |
| 128 | 130 |
| 129 gfx::Transform zero(0, 0, 0, 0, 0, 0); | 131 gfx::Transform zero(0, 0, 0, 0, 0, 0); |
| 130 state->setOpacity(0.5); | 132 state->setOpacity(0.5); |
| 131 state->setTransform(zero.matrix()); | 133 state->setTransform(zero.matrix()); |
| 132 state->setScrollLeft(1.0); | 134 state->setScrollLeft(1.0); |
| 133 state->setScrollTop(1.0); | 135 state->setScrollTop(1.0); |
| 134 | 136 |
| 135 EXPECT_EQ(0.5, rootLayer()->Opacity()); | 137 EXPECT_EQ(0.5, rootLayer()->Opacity()); |
| 136 EXPECT_EQ(zero.ToString(), rootLayer()->Transform().ToString()); | 138 EXPECT_EQ(zero.ToString(), rootLayer()->Transform().ToString()); |
| 137 EXPECT_EQ(1.0, layer->CurrentScrollOffset().x()); | 139 EXPECT_EQ(1.0, layer->CurrentScrollOffset().x()); |
| 138 EXPECT_EQ(1.0, layer->CurrentScrollOffset().y()); | 140 EXPECT_EQ(1.0, layer->CurrentScrollOffset().y()); |
| 139 | 141 |
| 140 // The corresponding mutation should reflect the changed values. | 142 // The corresponding mutation should reflect the changed values. |
| 141 EXPECT_EQ(1ul, mutations.map.size()); | 143 EXPECT_EQ(1ul, mutations.map.size()); |
| 142 | 144 |
| 143 const CompositorMutation& mutation = *mutations.map.find(primaryId)->value; | 145 const CompositorMutation& mutation = *mutations.map.find(mainId)->value; |
| 144 EXPECT_TRUE(mutation.isOpacityMutated()); | 146 EXPECT_TRUE(mutation.isOpacityMutated()); |
| 145 EXPECT_TRUE(mutation.isTransformMutated()); | 147 EXPECT_TRUE(mutation.isTransformMutated()); |
| 146 EXPECT_TRUE(mutation.isScrollLeftMutated()); | 148 EXPECT_TRUE(mutation.isScrollLeftMutated()); |
| 147 EXPECT_TRUE(mutation.isScrollTopMutated()); | 149 EXPECT_TRUE(mutation.isScrollTopMutated()); |
| 148 | 150 |
| 149 EXPECT_EQ(0.5, mutation.opacity()); | 151 EXPECT_EQ(0.5, mutation.opacity()); |
| 150 EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString()); | 152 EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString()); |
| 151 EXPECT_EQ(1.0, mutation.scrollLeft()); | 153 EXPECT_EQ(1.0, mutation.scrollLeft()); |
| 152 EXPECT_EQ(1.0, mutation.scrollTop()); | 154 EXPECT_EQ(1.0, mutation.scrollTop()); |
| 153 } | 155 } |
| 154 | 156 |
| 157 TEST_F(CompositorMutableStateTest, MutableStateWithoutScrollLayer) { | |
| 158 // There is a main layer with an element id but there is not scroll layer with | |
| 159 // and element id. We should have a valid mutable state given but mutating its | |
| 160 // scroll properties should have no effect. | |
| 161 std::unique_ptr<LayerImpl> root = | |
| 162 LayerImpl::Create(hostImpl().active_tree(), 42); | |
| 163 SetLayerPropertiesForTesting(root.get()); | |
| 164 | |
| 165 root->SetElementId( | |
| 166 createCompositorElementId(42, CompositorSubElementId::Primary)); | |
| 167 | |
| 168 root->SetMutableProperties(CompositorMutableProperty::kOpacity | | |
| 169 CompositorMutableProperty::kTransform); | |
| 170 | |
| 171 hostImpl().SetViewportSize(root->bounds()); | |
| 172 hostImpl().active_tree()->SetRootLayerForTesting(std::move(root)); | |
| 173 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | |
| 174 | |
| 175 CompositorMutations mutations; | |
| 176 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations); | |
| 177 std::unique_ptr<CompositorMutableState> state( | |
| 178 provider.getMutableStateFor(42, 42)); | |
| 179 | |
| 180 EXPECT_TRUE(state.get()); | |
| 181 EXPECT_EQ(1.0, rootLayer()->Opacity()); | |
| 182 EXPECT_EQ(0.0, rootLayer()->CurrentScrollOffset().x()); | |
| 183 EXPECT_EQ(0.0, rootLayer()->CurrentScrollOffset().y()); | |
| 184 | |
| 185 state->setOpacity(0.5); | |
| 186 state->setScrollLeft(1.0); | |
| 187 state->setScrollTop(1.0); | |
| 188 | |
| 189 EXPECT_EQ(1ul, mutations.map.size()); | |
| 190 | |
| 191 const CompositorMutation& mutation = *mutations.map.find(42)->value; | |
| 192 EXPECT_TRUE(mutation.isOpacityMutated()); | |
| 193 EXPECT_FALSE(mutation.isScrollLeftMutated()); | |
| 194 EXPECT_FALSE(mutation.isScrollTopMutated()); | |
| 195 | |
| 196 EXPECT_EQ(0.5, rootLayer()->Opacity()); | |
| 197 EXPECT_EQ(0.0, rootLayer()->CurrentScrollOffset().x()); | |
| 198 EXPECT_EQ(0.0, rootLayer()->CurrentScrollOffset().y()); | |
| 199 } | |
| 200 | |
| 155 } // namespace blink | 201 } // namespace blink |
| OLD | NEW |