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

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: Address review feedback. Created 4 years, 11 months 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(provider.getMutableStateFor(42));
83 EXPECT_FALSE(state);
84 }
85
86 TEST_F(WebCompositorMutableStateTest, MutableStateNoMutableProperties) {
87 // In this test, there is a layer with an element id, but no mutable
88 // properties. This should behave just as if we'd had no element id.
89 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 42);
90
91 gfx::Transform identity_matrix;
92 gfx::Point3F transform_origin;
93 gfx::PointF position;
94 gfx::Size bounds(100, 100);
95 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
96 position, bounds, true, false, true);
97 root->SetDrawsContent(true);
98 root->SetElementId(42);
99
100 host_impl().SetViewportSize(root->bounds());
101 host_impl().active_tree()->SetRootLayer(std::move(root));
102 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
103
104 LayerTreeMutationMap mutations;
105 WebCompositorMutableStateProviderImpl provider(host_impl().active_tree(),
106 &mutations);
107 scoped_ptr<WebCompositorMutableState> state(provider.getMutableStateFor(42));
108 EXPECT_FALSE(state);
109 }
110
111 TEST_F(WebCompositorMutableStateTest, MutableStateMutableProperties) {
112 // In this test, there is a layer with an element id and mutable properties.
113 // In this case, we should get a valid mutable state for this element id that
114 // has a real effect on the corresponding layer.
115 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 42);
116
117 gfx::Transform identity_matrix;
118 gfx::Point3F transform_origin;
119 gfx::PointF position;
120 gfx::Size bounds(100, 100);
121 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
122 position, bounds, true, false, true);
123 root->SetDrawsContent(true);
124 root->SetElementId(42);
125 root->SetMutableProperties(
126 cc::kMutablePropertyOpacity | cc::kMutablePropertyTransform |
127 cc::kMutablePropertyScrollLeft | cc::kMutablePropertyScrollTop);
128
129 host_impl().SetViewportSize(root->bounds());
130 host_impl().active_tree()->SetRootLayer(std::move(root));
131 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
132
133 LayerTreeMutationMap mutations;
134 WebCompositorMutableStateProviderImpl provider(host_impl().active_tree(),
135 &mutations);
136
137 scoped_ptr<WebCompositorMutableState> state(provider.getMutableStateFor(42));
138 EXPECT_TRUE(state.get());
139
140 EXPECT_EQ(1.0, root_layer()->opacity());
141 EXPECT_EQ(identity_matrix.ToString(), root_layer()->transform().ToString());
142 EXPECT_EQ(0.0, root_layer()->CurrentScrollOffset().x());
143 EXPECT_EQ(0.0, root_layer()->CurrentScrollOffset().y());
144
145 gfx::Transform zero(0, 0, 0, 0, 0, 0);
146 state->setOpacity(0.5);
147 state->setTransform(zero.matrix());
148 state->setScrollLeft(1.0);
149 state->setScrollTop(1.0);
150
151 EXPECT_EQ(0.5, root_layer()->opacity());
152 EXPECT_EQ(zero.ToString(), root_layer()->transform().ToString());
153 EXPECT_EQ(1.0, root_layer()->CurrentScrollOffset().x());
154 EXPECT_EQ(1.0, root_layer()->CurrentScrollOffset().y());
155
156 // The corresponding mutation should reflect the changed values.
157 EXPECT_EQ(1ul, mutations.size());
158
159 const LayerTreeMutation& mutation = mutations[42];
160 EXPECT_TRUE(mutation.is_opacity_mutated());
161 EXPECT_TRUE(mutation.is_transform_mutated());
162 EXPECT_TRUE(mutation.is_scroll_left_mutated());
163 EXPECT_TRUE(mutation.is_scroll_top_mutated());
164
165 EXPECT_EQ(0.5, mutation.opacity());
166 EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString());
167 EXPECT_EQ(1.0, mutation.scroll_left());
168 EXPECT_EQ(1.0, mutation.scroll_top());
169 }
170
171 } // namespace
172 } // namespace cc_blink
OLDNEW
« no previous file with comments | « cc/blink/web_compositor_mutable_state_impl.cc ('k') | cc/blink/web_compositor_mutable_state_provider_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698