Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: cc/blink/web_compositor_mutable_state_impl_unittest.cc

Issue 1447893002: compositor-worker: Introduce WebCompositorMutableState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review response. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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(std::move(root));
77 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
78
79 LayerTreeMutationMap mutations;
80 WebCompositorMutableStateProviderImpl provider(host_impl().active_tree(),
81 &mutations);
82 scoped_ptr<WebCompositorMutableState> state(
83 provider.getMutableStateFor(42).release());
84 EXPECT_FALSE(state);
85 }
86
87 TEST_F(WebCompositorMutableStateTest, MutableStateNoMutableProperties) {
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 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 42);
91
92 gfx::Transform identity_matrix;
93 gfx::Point3F transform_origin;
94 gfx::PointF position;
95 gfx::Size bounds(100, 100);
96 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
97 position, bounds, true, false, true);
98 root->SetDrawsContent(true);
99 root->SetElementId(42);
100
101 host_impl().SetViewportSize(root->bounds());
102 host_impl().active_tree()->SetRootLayer(std::move(root));
103 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
104
105 LayerTreeMutationMap mutations;
106 WebCompositorMutableStateProviderImpl provider(host_impl().active_tree(),
107 &mutations);
108 scoped_ptr<WebCompositorMutableState> state(
109 provider.getMutableStateFor(42).release());
110 EXPECT_FALSE(state);
111 }
112
113 TEST_F(WebCompositorMutableStateTest, MutableStateMutableProperties) {
114 // In this test, there is a layer with an element id and mutable properties.
115 // In this case, we should get a valid mutable state for this element id that
116 // has a real effect on the corresponding layer.
117 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 42);
118
119 gfx::Transform identity_matrix;
120 gfx::Point3F transform_origin;
121 gfx::PointF position;
122 gfx::Size bounds(100, 100);
123 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
124 position, bounds, true, false, true);
125 root->SetDrawsContent(true);
126 root->SetElementId(42);
127 root->SetMutableProperties(
128 cc::kMutablePropertyOpacity | cc::kMutablePropertyTransform |
129 cc::kMutablePropertyScrollLeft | cc::kMutablePropertyScrollTop);
130
131 host_impl().SetViewportSize(root->bounds());
132 host_impl().active_tree()->SetRootLayer(std::move(root));
133 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
134
135 LayerTreeMutationMap mutations;
136 WebCompositorMutableStateProviderImpl provider(host_impl().active_tree(),
137 &mutations);
138
139 scoped_ptr<WebCompositorMutableState> state(
140 provider.getMutableStateFor(42).release());
esprehn 2016/01/06 19:48:37 just use a WebOwnPtr, why use a scoped_ptr and add
Ian Vollick 2016/01/08 03:01:53 I took your offline suggestion and made a conversi
141 EXPECT_TRUE(state.get());
142
143 EXPECT_EQ(1.0, root_layer()->opacity());
144 EXPECT_EQ(identity_matrix.ToString(), root_layer()->transform().ToString());
145 EXPECT_EQ(0.0, root_layer()->CurrentScrollOffset().x());
146 EXPECT_EQ(0.0, root_layer()->CurrentScrollOffset().y());
147
148 gfx::Transform zero(0, 0, 0, 0, 0, 0);
149 state->setOpacity(0.5);
150 state->setTransform(zero.matrix());
151 state->setScrollLeft(1.0);
152 state->setScrollTop(1.0);
153
154 EXPECT_EQ(0.5, root_layer()->opacity());
155 EXPECT_EQ(zero.ToString(), root_layer()->transform().ToString());
156 EXPECT_EQ(1.0, root_layer()->CurrentScrollOffset().x());
157 EXPECT_EQ(1.0, root_layer()->CurrentScrollOffset().y());
158
159 // The corresponding mutation should reflect the changed values.
160 EXPECT_EQ(1ul, mutations.size());
161
162 const LayerTreeMutation& mutation = mutations[42];
163 EXPECT_TRUE(mutation.is_opacity_mutated());
164 EXPECT_TRUE(mutation.is_transform_mutated());
165 EXPECT_TRUE(mutation.is_scroll_left_mutated());
166 EXPECT_TRUE(mutation.is_scroll_top_mutated());
167
168 EXPECT_EQ(0.5, mutation.opacity());
169 EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString());
170 EXPECT_EQ(1.0, mutation.scroll_left());
171 EXPECT_EQ(1.0, mutation.scroll_top());
172 }
173
174 } // namespace
175 } // namespace cc_blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698