OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "cc/blink/web_compositor_mutable_state_impl.h" |
| 6 |
| 7 #include "cc/animation/layer_tree_mutation.h" |
| 8 #include "cc/blink/web_compositor_mutable_state_provider_impl.h" |
| 9 #include "cc/test/fake_impl_task_runner_provider.h" |
| 10 #include "cc/test/fake_layer_tree_host_impl.h" |
| 11 #include "cc/test/fake_output_surface.h" |
| 12 #include "cc/test/layer_tree_host_common_test.h" |
| 13 #include "cc/test/test_shared_bitmap_manager.h" |
| 14 #include "cc/test/test_task_graph_runner.h" |
| 15 #include "cc/trees/layer_tree_host_impl.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 |
| 18 namespace cc_blink { |
| 19 namespace { |
| 20 |
| 21 using cc::FakeImplTaskRunnerProvider; |
| 22 using cc::FakeLayerTreeHostImpl; |
| 23 using cc::FakeOutputSurface; |
| 24 using cc::LayerImpl; |
| 25 using cc::LayerImplList; |
| 26 using cc::LayerTreeHostCommonTest; |
| 27 using cc::LayerTreeMutation; |
| 28 using cc::LayerTreeMutationMap; |
| 29 using cc::LayerTreeSettings; |
| 30 using cc::OutputSurface; |
| 31 using cc::TestTaskGraphRunner; |
| 32 using cc::TestSharedBitmapManager; |
| 33 |
| 34 using blink::WebCompositorMutableState; |
| 35 |
| 36 class WebCompositorMutableStateTest : public LayerTreeHostCommonTest { |
| 37 public: |
| 38 WebCompositorMutableStateTest() |
| 39 : output_surface_(FakeOutputSurface::Create3d()) { |
| 40 LayerTreeSettings settings; |
| 41 settings.layer_transforms_should_scale_layer_contents = true; |
| 42 settings.verify_property_trees = true; |
| 43 host_impl_.reset(new FakeLayerTreeHostImpl(settings, &task_runner_provider_, |
| 44 &shared_bitmap_manager_, |
| 45 &task_graph_runner_)); |
| 46 host_impl_->SetVisible(true); |
| 47 EXPECT_TRUE(host_impl_->InitializeRenderer(output_surface_.get())); |
| 48 } |
| 49 |
| 50 FakeLayerTreeHostImpl& host_impl() { return *host_impl_; } |
| 51 |
| 52 LayerImpl* root_layer() { return host_impl_->active_tree()->root_layer(); } |
| 53 |
| 54 private: |
| 55 TestSharedBitmapManager shared_bitmap_manager_; |
| 56 TestTaskGraphRunner task_graph_runner_; |
| 57 FakeImplTaskRunnerProvider task_runner_provider_; |
| 58 scoped_ptr<OutputSurface> output_surface_; |
| 59 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; |
| 60 }; |
| 61 |
| 62 TEST_F(WebCompositorMutableStateTest, NoMutableState) { |
| 63 // In this test, there are no layers with either an element id or mutable |
| 64 // properties. We should not be able to get any mutable state. |
| 65 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 42); |
| 66 |
| 67 gfx::Transform identity_matrix; |
| 68 gfx::Point3F transform_origin; |
| 69 gfx::PointF position; |
| 70 gfx::Size bounds(100, 100); |
| 71 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
| 72 position, bounds, true, false, true); |
| 73 root->SetDrawsContent(true); |
| 74 |
| 75 host_impl().SetViewportSize(root->bounds()); |
| 76 host_impl().active_tree()->SetRootLayer(root.Pass()); |
| 77 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 78 |
| 79 LayerTreeMutationMap mutations; |
| 80 WebCompositorMutableStateProviderImpl provider(host_impl().active_tree(), |
| 81 &mutations); |
| 82 EXPECT_FALSE(provider.getMutableStateFor(42)); |
| 83 } |
| 84 |
| 85 TEST_F(WebCompositorMutableStateTest, MutableStateNoMutableProperties) { |
| 86 // In this test, there is a layer with an element id, but no mutable |
| 87 // properties. This should behave just as if we'd had no element id. |
| 88 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 42); |
| 89 |
| 90 gfx::Transform identity_matrix; |
| 91 gfx::Point3F transform_origin; |
| 92 gfx::PointF position; |
| 93 gfx::Size bounds(100, 100); |
| 94 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
| 95 position, bounds, true, false, true); |
| 96 root->SetDrawsContent(true); |
| 97 root->SetElementId(42); |
| 98 |
| 99 host_impl().SetViewportSize(root->bounds()); |
| 100 host_impl().active_tree()->SetRootLayer(root.Pass()); |
| 101 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 102 |
| 103 LayerTreeMutationMap mutations; |
| 104 WebCompositorMutableStateProviderImpl provider(host_impl().active_tree(), |
| 105 &mutations); |
| 106 EXPECT_FALSE(provider.getMutableStateFor(42)); |
| 107 } |
| 108 |
| 109 TEST_F(WebCompositorMutableStateTest, MutableStateMutableProperties) { |
| 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 that |
| 112 // has a real effect on the corresponding layer. |
| 113 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 42); |
| 114 |
| 115 gfx::Transform identity_matrix; |
| 116 gfx::Point3F transform_origin; |
| 117 gfx::PointF position; |
| 118 gfx::Size bounds(100, 100); |
| 119 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
| 120 position, bounds, true, false, true); |
| 121 root->SetDrawsContent(true); |
| 122 root->SetElementId(42); |
| 123 root->SetMutableProperties( |
| 124 cc::kMutablePropertyOpacity | cc::kMutablePropertyTransform | |
| 125 cc::kMutablePropertyScrollLeft | cc::kMutablePropertyScrollTop); |
| 126 |
| 127 host_impl().SetViewportSize(root->bounds()); |
| 128 host_impl().active_tree()->SetRootLayer(root.Pass()); |
| 129 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); |
| 130 |
| 131 LayerTreeMutationMap mutations; |
| 132 WebCompositorMutableStateProviderImpl provider(host_impl().active_tree(), |
| 133 &mutations); |
| 134 scoped_ptr<WebCompositorMutableState> state(provider.getMutableStateFor(42)); |
| 135 EXPECT_TRUE(state.get()); |
| 136 |
| 137 EXPECT_EQ(1.0, root_layer()->opacity()); |
| 138 EXPECT_EQ(identity_matrix.ToString(), root_layer()->transform().ToString()); |
| 139 EXPECT_EQ(0.0, root_layer()->CurrentScrollOffset().x()); |
| 140 EXPECT_EQ(0.0, root_layer()->CurrentScrollOffset().y()); |
| 141 |
| 142 gfx::Transform zero(0, 0, 0, 0, 0, 0); |
| 143 state->setOpacity(0.5); |
| 144 state->setTransform(zero.matrix()); |
| 145 state->setScrollLeft(1.0); |
| 146 state->setScrollTop(1.0); |
| 147 |
| 148 EXPECT_EQ(0.5, root_layer()->opacity()); |
| 149 EXPECT_EQ(zero.ToString(), root_layer()->transform().ToString()); |
| 150 EXPECT_EQ(1.0, root_layer()->CurrentScrollOffset().x()); |
| 151 EXPECT_EQ(1.0, root_layer()->CurrentScrollOffset().y()); |
| 152 |
| 153 // The corresponding mutation should reflect the changed values. |
| 154 EXPECT_EQ(1ul, mutations.size()); |
| 155 |
| 156 const LayerTreeMutation& mutation = mutations[42]; |
| 157 EXPECT_TRUE(mutation.is_opacity_mutated()); |
| 158 EXPECT_TRUE(mutation.is_transform_mutated()); |
| 159 EXPECT_TRUE(mutation.is_scroll_left_mutated()); |
| 160 EXPECT_TRUE(mutation.is_scroll_top_mutated()); |
| 161 |
| 162 EXPECT_EQ(0.5, mutation.opacity()); |
| 163 EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString()); |
| 164 EXPECT_EQ(1.0, mutation.scroll_left()); |
| 165 EXPECT_EQ(1.0, mutation.scroll_top()); |
| 166 } |
| 167 |
| 168 } // namespace |
| 169 } // namespace cc_blink |
OLD | NEW |