Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "platform/graphics/CompositorMutableState.h" | |
| 6 | |
| 7 #include "base/message_loop/message_loop.h" | |
| 8 #include "cc/test/fake_impl_task_runner_provider.h" | |
| 9 #include "cc/test/fake_layer_tree_host_impl.h" | |
| 10 #include "cc/test/fake_output_surface.h" | |
| 11 #include "cc/test/test_shared_bitmap_manager.h" | |
| 12 #include "cc/test/test_task_graph_runner.h" | |
| 13 #include "cc/trees/layer_tree_host_impl.h" | |
| 14 #include "cc/trees/layer_tree_impl.h" | |
| 15 #include "platform/graphics/CompositorMutableProperties.h" | |
| 16 #include "platform/graphics/CompositorMutableStateProvider.h" | |
| 17 #include "platform/graphics/CompositorMutation.h" | |
| 18 #include "testing/gtest/include/gtest/gtest.h" | |
| 19 #include "wtf/OwnPtr.h" | |
| 20 | |
| 21 namespace blink { | |
| 22 | |
| 23 using cc::FakeImplTaskRunnerProvider; | |
| 24 using cc::FakeLayerTreeHostImpl; | |
| 25 using cc::FakeOutputSurface; | |
| 26 using cc::LayerImpl; | |
| 27 using cc::LayerTreeSettings; | |
| 28 using cc::OutputSurface; | |
| 29 using cc::TestTaskGraphRunner; | |
| 30 using cc::TestSharedBitmapManager; | |
| 31 | |
| 32 class CompositorMutableStateTest : public testing::Test { | |
| 33 public: | |
| 34 CompositorMutableStateTest() | |
| 35 : m_outputSurface(FakeOutputSurface::Create3d()) | |
| 36 { | |
| 37 LayerTreeSettings settings; | |
| 38 settings.layer_transforms_should_scale_layer_contents = true; | |
| 39 settings.verify_property_trees = true; | |
| 40 m_hostImpl.reset(new FakeLayerTreeHostImpl(settings, &m_taskRunnerProvid er, &m_sharedBitmapManager, &m_taskGraphRunner)); | |
| 41 m_hostImpl->SetVisible(true); | |
| 42 EXPECT_TRUE(m_hostImpl->InitializeRenderer(m_outputSurface.get())); | |
| 43 } | |
| 44 | |
| 45 void SetLayerPropertiesForTesting(LayerImpl* layer) | |
| 46 { | |
| 47 layer->SetTransform(gfx::Transform()); | |
| 48 layer->SetTransformOrigin(gfx::Point3F()); | |
| 49 layer->SetPosition(gfx::PointF()); | |
| 50 layer->SetBounds(gfx::Size(100, 100)); | |
| 51 layer->SetShouldFlattenTransform(true); | |
| 52 layer->Set3dSortingContextId(0); | |
| 53 layer->SetForceRenderSurface(true); | |
| 54 layer->SetDrawsContent(true); | |
| 55 } | |
| 56 | |
| 57 FakeLayerTreeHostImpl& hostImpl() { return *m_hostImpl; } | |
| 58 | |
| 59 LayerImpl* rootLayer() { return m_hostImpl->active_tree()->root_layer(); } | |
| 60 | |
| 61 private: | |
| 62 base::MessageLoop m_messageLoop; | |
|
jbroman
2016/01/18 19:07:22
At least a comment explaining why this message loo
Ian Vollick
2016/01/18 21:25:04
Done.
| |
| 63 TestSharedBitmapManager m_sharedBitmapManager; | |
| 64 TestTaskGraphRunner m_taskGraphRunner; | |
| 65 FakeImplTaskRunnerProvider m_taskRunnerProvider; | |
| 66 scoped_ptr<OutputSurface> m_outputSurface; | |
| 67 scoped_ptr<FakeLayerTreeHostImpl> m_hostImpl; | |
| 68 }; | |
| 69 | |
| 70 TEST_F(CompositorMutableStateTest, NoMutableState) | |
| 71 { | |
| 72 // In this test, there are no layers with either an element id or mutable | |
| 73 // properties. We should not be able to get any mutable state. | |
| 74 scoped_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree(), 42) ; | |
| 75 SetLayerPropertiesForTesting(root.get()); | |
| 76 | |
| 77 hostImpl().SetViewportSize(root->bounds()); | |
| 78 hostImpl().active_tree()->SetRootLayer(std::move(root)); | |
| 79 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | |
| 80 | |
| 81 CompositorMutations mutations; | |
| 82 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations ); | |
| 83 OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(42)); | |
| 84 EXPECT_FALSE(state); | |
| 85 } | |
| 86 | |
| 87 TEST_F(CompositorMutableStateTest, MutableStateNoMutableProperties) | |
| 88 { | |
| 89 // In this test, there is a layer with an element id, but no mutable | |
| 90 // properties. This should behave just as if we'd had no element id. | |
| 91 scoped_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree(), 42) ; | |
| 92 SetLayerPropertiesForTesting(root.get()); | |
| 93 root->SetElementId(42); | |
| 94 | |
| 95 hostImpl().SetViewportSize(root->bounds()); | |
| 96 hostImpl().active_tree()->SetRootLayer(std::move(root)); | |
| 97 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | |
| 98 | |
| 99 CompositorMutations mutations; | |
| 100 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations ); | |
| 101 OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(42)); | |
| 102 EXPECT_FALSE(state); | |
| 103 } | |
| 104 | |
| 105 TEST_F(CompositorMutableStateTest, MutableStateMutableProperties) | |
| 106 { | |
| 107 // In this test, there is a layer with an element id and mutable properties. | |
| 108 // In this case, we should get a valid mutable state for this element id tha t | |
| 109 // has a real effect on the corresponding layer. | |
| 110 scoped_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree(), 42) ; | |
| 111 SetLayerPropertiesForTesting(root.get()); | |
| 112 root->SetElementId(42); | |
| 113 root->SetMutableProperties(CompositorMutablePropertyOpacity | CompositorMuta blePropertyTransform | CompositorMutablePropertyScrollLeft | CompositorMutablePr opertyScrollTop); | |
| 114 | |
| 115 hostImpl().SetViewportSize(root->bounds()); | |
| 116 hostImpl().active_tree()->SetRootLayer(std::move(root)); | |
| 117 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); | |
| 118 | |
| 119 CompositorMutations mutations; | |
| 120 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations ); | |
| 121 | |
| 122 OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(42)); | |
| 123 EXPECT_TRUE(state.get()); | |
| 124 | |
| 125 EXPECT_EQ(1.0, rootLayer()->opacity()); | |
| 126 EXPECT_EQ(gfx::Transform().ToString(), rootLayer()->transform().ToString()); | |
| 127 EXPECT_EQ(0.0, rootLayer()->CurrentScrollOffset().x()); | |
| 128 EXPECT_EQ(0.0, rootLayer()->CurrentScrollOffset().y()); | |
| 129 | |
| 130 gfx::Transform zero(0, 0, 0, 0, 0, 0); | |
| 131 state->setOpacity(0.5); | |
| 132 state->setTransform(zero.matrix()); | |
| 133 state->setScrollLeft(1.0); | |
| 134 state->setScrollTop(1.0); | |
| 135 | |
| 136 EXPECT_EQ(0.5, rootLayer()->opacity()); | |
| 137 EXPECT_EQ(zero.ToString(), rootLayer()->transform().ToString()); | |
| 138 EXPECT_EQ(1.0, rootLayer()->CurrentScrollOffset().x()); | |
| 139 EXPECT_EQ(1.0, rootLayer()->CurrentScrollOffset().y()); | |
| 140 | |
| 141 // The corresponding mutation should reflect the changed values. | |
| 142 EXPECT_EQ(1ul, mutations.map.size()); | |
| 143 | |
| 144 const CompositorMutation& mutation = mutations.map[42]; | |
| 145 EXPECT_TRUE(mutation.isOpacityMutated()); | |
| 146 EXPECT_TRUE(mutation.isTransformMutated()); | |
| 147 EXPECT_TRUE(mutation.isScrollLeftMutated()); | |
| 148 EXPECT_TRUE(mutation.isScrollTopMutated()); | |
| 149 | |
| 150 EXPECT_EQ(0.5, mutation.opacity()); | |
| 151 EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString()); | |
| 152 EXPECT_EQ(1.0, mutation.scrollLeft()); | |
| 153 EXPECT_EQ(1.0, mutation.scrollTop()); | |
| 154 } | |
| 155 | |
| 156 } // namespace blink | |
| OLD | NEW |