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 // The cc testing machinery has fairly deep dependency on having a main |
| 63 // message loop (one example is the task runner provider). We construct one |
| 64 // here so that it's installed in TLA and can be found by other cc classes. |
| 65 base::MessageLoop m_messageLoop; |
| 66 TestSharedBitmapManager m_sharedBitmapManager; |
| 67 TestTaskGraphRunner m_taskGraphRunner; |
| 68 FakeImplTaskRunnerProvider m_taskRunnerProvider; |
| 69 scoped_ptr<OutputSurface> m_outputSurface; |
| 70 scoped_ptr<FakeLayerTreeHostImpl> m_hostImpl; |
| 71 }; |
| 72 |
| 73 TEST_F(CompositorMutableStateTest, NoMutableState) |
| 74 { |
| 75 // In this test, there are no layers with either an element id or mutable |
| 76 // properties. We should not be able to get any mutable state. |
| 77 scoped_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree(), 42)
; |
| 78 SetLayerPropertiesForTesting(root.get()); |
| 79 |
| 80 hostImpl().SetViewportSize(root->bounds()); |
| 81 hostImpl().active_tree()->SetRootLayer(std::move(root)); |
| 82 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 83 |
| 84 CompositorMutations mutations; |
| 85 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations
); |
| 86 OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(42)); |
| 87 EXPECT_FALSE(state); |
| 88 } |
| 89 |
| 90 TEST_F(CompositorMutableStateTest, MutableStateNoMutableProperties) |
| 91 { |
| 92 // In this test, there is a layer with an element id, but no mutable |
| 93 // properties. This should behave just as if we'd had no element id. |
| 94 scoped_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree(), 42)
; |
| 95 SetLayerPropertiesForTesting(root.get()); |
| 96 root->SetElementId(42); |
| 97 |
| 98 hostImpl().SetViewportSize(root->bounds()); |
| 99 hostImpl().active_tree()->SetRootLayer(std::move(root)); |
| 100 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 101 |
| 102 CompositorMutations mutations; |
| 103 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations
); |
| 104 OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(42)); |
| 105 EXPECT_FALSE(state); |
| 106 } |
| 107 |
| 108 TEST_F(CompositorMutableStateTest, MutableStateMutableProperties) |
| 109 { |
| 110 // In this test, there is a layer with an element id and mutable properties. |
| 111 // In this case, we should get a valid mutable state for this element id tha
t |
| 112 // has a real effect on the corresponding layer. |
| 113 scoped_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree(), 42)
; |
| 114 SetLayerPropertiesForTesting(root.get()); |
| 115 root->SetElementId(42); |
| 116 root->SetMutableProperties(CompositorMutableProperty::kOpacity | CompositorM
utableProperty::kTransform | CompositorMutableProperty::kScrollLeft | Compositor
MutableProperty::kScrollTop); |
| 117 |
| 118 hostImpl().SetViewportSize(root->bounds()); |
| 119 hostImpl().active_tree()->SetRootLayer(std::move(root)); |
| 120 hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 121 |
| 122 CompositorMutations mutations; |
| 123 CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations
); |
| 124 |
| 125 OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(42)); |
| 126 EXPECT_TRUE(state.get()); |
| 127 |
| 128 EXPECT_EQ(1.0, rootLayer()->opacity()); |
| 129 EXPECT_EQ(gfx::Transform().ToString(), rootLayer()->transform().ToString()); |
| 130 EXPECT_EQ(0.0, rootLayer()->CurrentScrollOffset().x()); |
| 131 EXPECT_EQ(0.0, rootLayer()->CurrentScrollOffset().y()); |
| 132 |
| 133 gfx::Transform zero(0, 0, 0, 0, 0, 0); |
| 134 state->setOpacity(0.5); |
| 135 state->setTransform(zero.matrix()); |
| 136 state->setScrollLeft(1.0); |
| 137 state->setScrollTop(1.0); |
| 138 |
| 139 EXPECT_EQ(0.5, rootLayer()->opacity()); |
| 140 EXPECT_EQ(zero.ToString(), rootLayer()->transform().ToString()); |
| 141 EXPECT_EQ(1.0, rootLayer()->CurrentScrollOffset().x()); |
| 142 EXPECT_EQ(1.0, rootLayer()->CurrentScrollOffset().y()); |
| 143 |
| 144 // The corresponding mutation should reflect the changed values. |
| 145 EXPECT_EQ(1ul, mutations.map.size()); |
| 146 |
| 147 const CompositorMutation& mutation = *mutations.map.find(42)->value; |
| 148 EXPECT_TRUE(mutation.isOpacityMutated()); |
| 149 EXPECT_TRUE(mutation.isTransformMutated()); |
| 150 EXPECT_TRUE(mutation.isScrollLeftMutated()); |
| 151 EXPECT_TRUE(mutation.isScrollTopMutated()); |
| 152 |
| 153 EXPECT_EQ(0.5, mutation.opacity()); |
| 154 EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString()); |
| 155 EXPECT_EQ(1.0, mutation.scrollLeft()); |
| 156 EXPECT_EQ(1.0, mutation.scrollTop()); |
| 157 } |
| 158 |
| 159 } // namespace blink |
OLD | NEW |