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

Side by Side Diff: cc/trees/layer_tree_impl_unittest.cc

Issue 2181763005: cc: Make LayerTreeImpl tests stop subclassing LayerImplTest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lthcommontest-harness3
Patch Set: Created 4 years, 4 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
« no previous file with comments | « cc/test/layer_test_common.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_impl.h" 5 #include "cc/trees/layer_tree_impl.h"
6 6
7 #include "cc/layers/heads_up_display_layer_impl.h" 7 #include "cc/layers/heads_up_display_layer_impl.h"
8 #include "cc/layers/layer.h"
9 #include "cc/layers/solid_color_scrollbar_layer_impl.h"
10 #include "cc/test/fake_impl_task_runner_provider.h"
11 #include "cc/test/fake_layer_tree_host_impl.h" 8 #include "cc/test/fake_layer_tree_host_impl.h"
12 #include "cc/test/fake_output_surface.h"
13 #include "cc/test/geometry_test_utils.h" 9 #include "cc/test/geometry_test_utils.h"
14 #include "cc/test/layer_test_common.h" 10 #include "cc/test/layer_test_common.h"
15 #include "cc/test/test_shared_bitmap_manager.h" 11 #include "cc/test/layer_tree_settings_for_testing.h"
16 #include "cc/test/test_task_graph_runner.h"
17 #include "cc/trees/clip_node.h" 12 #include "cc/trees/clip_node.h"
18 #include "cc/trees/draw_property_utils.h" 13 #include "cc/trees/draw_property_utils.h"
19 #include "cc/trees/layer_tree_host_common.h" 14 #include "cc/trees/layer_tree_host_common.h"
20 #include "cc/trees/layer_tree_host_impl.h" 15 #include "cc/trees/layer_tree_host_impl.h"
21 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/gfx/geometry/size_conversions.h"
23 17
24 namespace cc { 18 namespace cc {
25 namespace { 19 namespace {
26 20
27 class LayerTreeImplTest : public LayerTestCommon::LayerImplTest, 21 class LayerTreeImplTestSettings : public LayerTreeSettingsForTesting {
28 public testing::Test {
29 public: 22 public:
30 LayerTreeImplTest() 23 LayerTreeImplTestSettings() {
31 : output_surface_(FakeOutputSurface::CreateDelegating3d()) { 24 layer_transforms_should_scale_layer_contents = true;
32 LayerTreeSettings settings;
33 settings.layer_transforms_should_scale_layer_contents = true;
34 settings.verify_clip_tree_calculations = true;
35 settings.verify_transform_tree_calculations = true;
36 host_impl_.reset(new FakeLayerTreeHostImpl(settings, &task_runner_provider_,
37 &shared_bitmap_manager_,
38 &task_graph_runner_));
39 host_impl_->SetVisible(true);
40 EXPECT_TRUE(host_impl_->InitializeRenderer(output_surface_.get()));
41 } 25 }
26 };
42 27
43 FakeLayerTreeHostImpl& host_impl() { return *host_impl_; } 28 class LayerTreeImplTest : public testing::Test {
29 public:
30 LayerTreeImplTest() : impl_test_(LayerTreeImplTestSettings()) {}
44 31
45 LayerImpl* root_layer() { 32 FakeLayerTreeHostImpl& host_impl() const { return *impl_test_.host_impl(); }
46 return host_impl_->active_tree()->root_layer_for_testing(); 33
47 } 34 LayerImpl* root_layer() { return impl_test_.root_layer_for_testing(); }
48 35
49 const LayerImplList& RenderSurfaceLayerList() const { 36 const LayerImplList& RenderSurfaceLayerList() const {
50 return host_impl_->active_tree()->RenderSurfaceLayerList(); 37 return host_impl().active_tree()->RenderSurfaceLayerList();
51 } 38 }
52 39
53 void ExecuteCalculateDrawProperties(LayerImpl* root_layer) { 40 void ExecuteCalculateDrawProperties(LayerImpl* root_layer) {
54 // We are probably not testing what is intended if the root_layer bounds are 41 // We are probably not testing what is intended if the root_layer bounds are
55 // empty. 42 // empty.
56 DCHECK(!root_layer->bounds().IsEmpty()); 43 DCHECK(!root_layer->bounds().IsEmpty());
57 44
58 render_surface_layer_list_impl_.clear(); 45 render_surface_layer_list_impl_.clear();
59 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( 46 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
60 root_layer, root_layer->bounds(), &render_surface_layer_list_impl_); 47 root_layer, root_layer->bounds(), &render_surface_layer_list_impl_);
61 inputs.can_adjust_raster_scales = true; 48 inputs.can_adjust_raster_scales = true;
62 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); 49 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
63 } 50 }
64 51
65 int HitTestSimpleTree(int root_id, 52 int HitTestSimpleTree(int root_id,
66 int left_child_id, 53 int left_child_id,
67 int right_child_id, 54 int right_child_id,
68 int root_sorting_context, 55 int root_sorting_context,
69 int left_child_sorting_context, 56 int left_child_sorting_context,
70 int right_child_sorting_context, 57 int right_child_sorting_context,
71 float root_depth, 58 float root_depth,
72 float left_child_depth, 59 float left_child_depth,
73 float right_child_depth) { 60 float right_child_depth) {
61 host_impl().active_tree()->SetRootLayerForTesting(nullptr);
62
74 std::unique_ptr<LayerImpl> root = 63 std::unique_ptr<LayerImpl> root =
75 LayerImpl::Create(host_impl().active_tree(), root_id); 64 LayerImpl::Create(host_impl().active_tree(), root_id);
76 std::unique_ptr<LayerImpl> left_child = 65 std::unique_ptr<LayerImpl> left_child =
77 LayerImpl::Create(host_impl().active_tree(), left_child_id); 66 LayerImpl::Create(host_impl().active_tree(), left_child_id);
78 std::unique_ptr<LayerImpl> right_child = 67 std::unique_ptr<LayerImpl> right_child =
79 LayerImpl::Create(host_impl().active_tree(), right_child_id); 68 LayerImpl::Create(host_impl().active_tree(), right_child_id);
80 69
81 gfx::Size bounds(100, 100); 70 gfx::Size bounds(100, 100);
82 { 71 {
83 gfx::Transform translate_z; 72 gfx::Transform translate_z;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 104
116 gfx::PointF test_point = gfx::PointF(1.f, 1.f); 105 gfx::PointF test_point = gfx::PointF(1.f, 1.f);
117 LayerImpl* result_layer = 106 LayerImpl* result_layer =
118 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 107 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
119 108
120 CHECK(result_layer); 109 CHECK(result_layer);
121 return result_layer->id(); 110 return result_layer->id();
122 } 111 }
123 112
124 private: 113 private:
125 TestSharedBitmapManager shared_bitmap_manager_; 114 LayerTestCommon::LayerImplTest impl_test_;
126 TestTaskGraphRunner task_graph_runner_;
127 FakeImplTaskRunnerProvider task_runner_provider_;
128 std::unique_ptr<OutputSurface> output_surface_;
129 std::unique_ptr<FakeLayerTreeHostImpl> host_impl_;
130 std::vector<LayerImpl*> render_surface_layer_list_impl_; 115 std::vector<LayerImpl*> render_surface_layer_list_impl_;
131 }; 116 };
132 117
133 TEST_F(LayerTreeImplTest, HitTestingForSingleLayer) { 118 TEST_F(LayerTreeImplTest, HitTestingForSingleLayer) {
134 std::unique_ptr<LayerImpl> root =
135 LayerImpl::Create(host_impl().active_tree(), 12345);
136
137 gfx::Size bounds(100, 100); 119 gfx::Size bounds(100, 100);
120 LayerImpl* root = root_layer();
138 root->SetBounds(bounds); 121 root->SetBounds(bounds);
139 root->SetDrawsContent(true); 122 root->SetDrawsContent(true);
140 123
141 host_impl().SetViewportSize(root->bounds()); 124 host_impl().SetViewportSize(root->bounds());
142 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
143 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 125 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
144 126
145 // Sanity check the scenario we just created. 127 // Sanity check the scenario we just created.
146 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 128 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
147 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); 129 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
148 130
149 // Hit testing for a point outside the layer should return a null pointer. 131 // Hit testing for a point outside the layer should return a null pointer.
150 gfx::PointF test_point(101.f, 101.f); 132 gfx::PointF test_point(101.f, 101.f);
151 LayerImpl* result_layer = 133 LayerImpl* result_layer =
152 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 134 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
153 EXPECT_FALSE(result_layer); 135 EXPECT_FALSE(result_layer);
154 136
155 test_point = gfx::PointF(-1.f, -1.f); 137 test_point = gfx::PointF(-1.f, -1.f);
156 result_layer = 138 result_layer =
157 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 139 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
158 EXPECT_FALSE(result_layer); 140 EXPECT_FALSE(result_layer);
159 141
160 // Hit testing for a point inside should return the root layer. 142 // Hit testing for a point inside should return the root layer.
161 test_point = gfx::PointF(1.f, 1.f); 143 test_point = gfx::PointF(1.f, 1.f);
162 result_layer = 144 result_layer =
163 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 145 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
164 ASSERT_TRUE(result_layer); 146 ASSERT_TRUE(result_layer);
165 EXPECT_EQ(12345, result_layer->id()); 147 EXPECT_EQ(root->id(), result_layer->id());
166 148
167 test_point = gfx::PointF(99.f, 99.f); 149 test_point = gfx::PointF(99.f, 99.f);
168 result_layer = 150 result_layer =
169 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 151 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
170 ASSERT_TRUE(result_layer); 152 ASSERT_TRUE(result_layer);
171 EXPECT_EQ(12345, result_layer->id()); 153 EXPECT_EQ(root->id(), result_layer->id());
172 } 154 }
173 155
174 TEST_F(LayerTreeImplTest, UpdateViewportAndHitTest) { 156 TEST_F(LayerTreeImplTest, UpdateViewportAndHitTest) {
175 // Ensures that the viewport rect is correctly updated by the clip tree. 157 // Ensures that the viewport rect is correctly updated by the clip tree.
176 TestSharedBitmapManager shared_bitmap_manager;
177 TestTaskGraphRunner task_graph_runner;
178 FakeImplTaskRunnerProvider task_runner_provider;
179 LayerTreeSettings settings;
180 settings.verify_clip_tree_calculations = true;
181 settings.verify_transform_tree_calculations = true;
182 std::unique_ptr<OutputSurface> output_surface =
183 FakeOutputSurface::CreateDelegating3d();
184 std::unique_ptr<FakeLayerTreeHostImpl> host_impl;
185 host_impl.reset(new FakeLayerTreeHostImpl(settings, &task_runner_provider,
186 &shared_bitmap_manager,
187 &task_graph_runner));
188 host_impl->SetVisible(true);
189 EXPECT_TRUE(host_impl->InitializeRenderer(output_surface.get()));
190 std::unique_ptr<LayerImpl> root =
191 LayerImpl::Create(host_impl->active_tree(), 12345);
192
193 gfx::Size bounds(100, 100); 158 gfx::Size bounds(100, 100);
159 LayerImpl* root = root_layer();
194 root->SetBounds(bounds); 160 root->SetBounds(bounds);
195 root->SetDrawsContent(true); 161 root->SetDrawsContent(true);
196 162
197 host_impl->SetViewportSize(root->bounds()); 163 host_impl().SetViewportSize(root->bounds());
198 host_impl->active_tree()->SetRootLayerForTesting(std::move(root)); 164 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
199 host_impl->UpdateNumChildrenAndDrawPropertiesForActiveTree();
200 EXPECT_EQ( 165 EXPECT_EQ(
201 gfx::RectF(gfx::SizeF(bounds)), 166 gfx::RectF(gfx::SizeF(bounds)),
202 host_impl->active_tree()->property_trees()->clip_tree.ViewportClip()); 167 host_impl().active_tree()->property_trees()->clip_tree.ViewportClip());
203 EXPECT_EQ( 168 EXPECT_EQ(gfx::Rect(bounds), root->visible_layer_rect());
204 gfx::Rect(bounds),
205 host_impl->active_tree()->root_layer_for_testing()->visible_layer_rect());
206 169
207 gfx::Size new_bounds(50, 50); 170 gfx::Size new_bounds(50, 50);
208 host_impl->SetViewportSize(new_bounds); 171 host_impl().SetViewportSize(new_bounds);
209 gfx::PointF test_point(51.f, 51.f); 172 gfx::PointF test_point(51.f, 51.f);
210 host_impl->active_tree()->FindLayerThatIsHitByPoint(test_point); 173 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
211 EXPECT_EQ( 174 EXPECT_EQ(
212 gfx::RectF(gfx::SizeF(new_bounds)), 175 gfx::RectF(gfx::SizeF(new_bounds)),
213 host_impl->active_tree()->property_trees()->clip_tree.ViewportClip()); 176 host_impl().active_tree()->property_trees()->clip_tree.ViewportClip());
214 EXPECT_EQ( 177 EXPECT_EQ(gfx::Rect(new_bounds), root->visible_layer_rect());
215 gfx::Rect(new_bounds),
216 host_impl->active_tree()->root_layer_for_testing()->visible_layer_rect());
217 } 178 }
218 179
219 TEST_F(LayerTreeImplTest, HitTestingForSingleLayerAndHud) { 180 TEST_F(LayerTreeImplTest, HitTestingForSingleLayerAndHud) {
220 std::unique_ptr<LayerImpl> root = 181 LayerImpl* root = root_layer();
221 LayerImpl::Create(host_impl().active_tree(), 12345);
222 std::unique_ptr<HeadsUpDisplayLayerImpl> hud =
223 HeadsUpDisplayLayerImpl::Create(host_impl().active_tree(), 11111);
224
225 root->SetBounds(gfx::Size(100, 100)); 182 root->SetBounds(gfx::Size(100, 100));
226 root->SetDrawsContent(true); 183 root->SetDrawsContent(true);
227 184
228 // Create hud and add it as a child of root. 185 // Create hud and add it as a child of root.
186 std::unique_ptr<HeadsUpDisplayLayerImpl> hud =
187 HeadsUpDisplayLayerImpl::Create(host_impl().active_tree(), 11111);
229 hud->SetBounds(gfx::Size(200, 200)); 188 hud->SetBounds(gfx::Size(200, 200));
230 hud->SetDrawsContent(true); 189 hud->SetDrawsContent(true);
231 190
232 host_impl().SetViewportSize(hud->bounds()); 191 host_impl().SetViewportSize(hud->bounds());
233 host_impl().active_tree()->set_hud_layer(hud.get()); 192 host_impl().active_tree()->set_hud_layer(hud.get());
234 root->test_properties()->AddChild(std::move(hud)); 193 root->test_properties()->AddChild(std::move(hud));
235 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
236 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 194 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
237 195
238 // Sanity check the scenario we just created. 196 // Sanity check the scenario we just created.
239 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 197 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
240 ASSERT_EQ(2u, root_layer()->render_surface()->layer_list().size()); 198 ASSERT_EQ(2u, root_layer()->render_surface()->layer_list().size());
241 199
242 // Hit testing for a point inside HUD, but outside root should return null 200 // Hit testing for a point inside HUD, but outside root should return null
243 gfx::PointF test_point(101.f, 101.f); 201 gfx::PointF test_point(101.f, 101.f);
244 LayerImpl* result_layer = 202 LayerImpl* result_layer =
245 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 203 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
246 EXPECT_FALSE(result_layer); 204 EXPECT_FALSE(result_layer);
247 205
248 test_point = gfx::PointF(-1.f, -1.f); 206 test_point = gfx::PointF(-1.f, -1.f);
249 result_layer = 207 result_layer =
250 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 208 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
251 EXPECT_FALSE(result_layer); 209 EXPECT_FALSE(result_layer);
252 210
253 // Hit testing for a point inside should return the root layer, never the HUD 211 // Hit testing for a point inside should return the root layer, never the HUD
254 // layer. 212 // layer.
255 test_point = gfx::PointF(1.f, 1.f); 213 test_point = gfx::PointF(1.f, 1.f);
256 result_layer = 214 result_layer =
257 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 215 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
258 ASSERT_TRUE(result_layer); 216 ASSERT_TRUE(result_layer);
259 EXPECT_EQ(12345, result_layer->id()); 217 EXPECT_EQ(root->id(), result_layer->id());
260 218
261 test_point = gfx::PointF(99.f, 99.f); 219 test_point = gfx::PointF(99.f, 99.f);
262 result_layer = 220 result_layer =
263 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 221 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
264 ASSERT_TRUE(result_layer); 222 ASSERT_TRUE(result_layer);
265 EXPECT_EQ(12345, result_layer->id()); 223 EXPECT_EQ(root->id(), result_layer->id());
266 } 224 }
267 225
268 TEST_F(LayerTreeImplTest, HitTestingForUninvertibleTransform) { 226 TEST_F(LayerTreeImplTest, HitTestingForUninvertibleTransform) {
269 std::unique_ptr<LayerImpl> root =
270 LayerImpl::Create(host_impl().active_tree(), 12345);
271
272 gfx::Transform uninvertible_transform; 227 gfx::Transform uninvertible_transform;
273 uninvertible_transform.matrix().set(0, 0, 0.0); 228 uninvertible_transform.matrix().set(0, 0, 0.0);
274 uninvertible_transform.matrix().set(1, 1, 0.0); 229 uninvertible_transform.matrix().set(1, 1, 0.0);
275 uninvertible_transform.matrix().set(2, 2, 0.0); 230 uninvertible_transform.matrix().set(2, 2, 0.0);
276 uninvertible_transform.matrix().set(3, 3, 0.0); 231 uninvertible_transform.matrix().set(3, 3, 0.0);
277 ASSERT_FALSE(uninvertible_transform.IsInvertible()); 232 ASSERT_FALSE(uninvertible_transform.IsInvertible());
278 233
234 LayerImpl* root = root_layer();
279 root->SetTransform(uninvertible_transform); 235 root->SetTransform(uninvertible_transform);
280 root->SetBounds(gfx::Size(100, 100)); 236 root->SetBounds(gfx::Size(100, 100));
281 root->SetDrawsContent(true); 237 root->SetDrawsContent(true);
282 238
283 host_impl().SetViewportSize(root->bounds()); 239 host_impl().SetViewportSize(root->bounds());
284 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
285 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 240 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
286 // Sanity check the scenario we just created. 241 // Sanity check the scenario we just created.
287 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 242 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
288 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); 243 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
289 ASSERT_FALSE(root_layer()->ScreenSpaceTransform().IsInvertible()); 244 ASSERT_FALSE(root_layer()->ScreenSpaceTransform().IsInvertible());
290 245
291 // Hit testing any point should not hit the layer. If the invertible matrix is 246 // Hit testing any point should not hit the layer. If the invertible matrix is
292 // accidentally ignored and treated like an identity, then the hit testing 247 // accidentally ignored and treated like an identity, then the hit testing
293 // will incorrectly hit the layer when it shouldn't. 248 // will incorrectly hit the layer when it shouldn't.
294 gfx::PointF test_point(1.f, 1.f); 249 gfx::PointF test_point(1.f, 1.f);
(...skipping 26 matching lines...) Expand all
321 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 276 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
322 EXPECT_FALSE(result_layer); 277 EXPECT_FALSE(result_layer);
323 278
324 test_point = gfx::PointF(-1.f, -1.f); 279 test_point = gfx::PointF(-1.f, -1.f);
325 result_layer = 280 result_layer =
326 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 281 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
327 EXPECT_FALSE(result_layer); 282 EXPECT_FALSE(result_layer);
328 } 283 }
329 284
330 TEST_F(LayerTreeImplTest, HitTestingForSinglePositionedLayer) { 285 TEST_F(LayerTreeImplTest, HitTestingForSinglePositionedLayer) {
331 std::unique_ptr<LayerImpl> root =
332 LayerImpl::Create(host_impl().active_tree(), 12345);
333
334 // This layer is positioned, and hit testing should correctly know where the 286 // This layer is positioned, and hit testing should correctly know where the
335 // layer is located. 287 // layer is located.
288 LayerImpl* root = root_layer();
336 root->SetPosition(gfx::PointF(50.f, 50.f)); 289 root->SetPosition(gfx::PointF(50.f, 50.f));
337 root->SetBounds(gfx::Size(100, 100)); 290 root->SetBounds(gfx::Size(100, 100));
338 root->SetDrawsContent(true); 291 root->SetDrawsContent(true);
339 292
340 host_impl().SetViewportSize(root->bounds()); 293 host_impl().SetViewportSize(root->bounds());
341 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
342 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 294 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
343 295
344 // Sanity check the scenario we just created. 296 // Sanity check the scenario we just created.
345 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 297 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
346 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); 298 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
347 299
348 // Hit testing for a point outside the layer should return a null pointer. 300 // Hit testing for a point outside the layer should return a null pointer.
349 gfx::PointF test_point(49.f, 49.f); 301 gfx::PointF test_point(49.f, 49.f);
350 LayerImpl* result_layer = 302 LayerImpl* result_layer =
351 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 303 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
352 EXPECT_FALSE(result_layer); 304 EXPECT_FALSE(result_layer);
353 305
354 // Even though the layer exists at (101, 101), it should not be visible there 306 // Even though the layer exists at (101, 101), it should not be visible there
355 // since the root render surface would clamp it. 307 // since the root render surface would clamp it.
356 test_point = gfx::PointF(101.f, 101.f); 308 test_point = gfx::PointF(101.f, 101.f);
357 result_layer = 309 result_layer =
358 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 310 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
359 EXPECT_FALSE(result_layer); 311 EXPECT_FALSE(result_layer);
360 312
361 // Hit testing for a point inside should return the root layer. 313 // Hit testing for a point inside should return the root layer.
362 test_point = gfx::PointF(51.f, 51.f); 314 test_point = gfx::PointF(51.f, 51.f);
363 result_layer = 315 result_layer =
364 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 316 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
365 ASSERT_TRUE(result_layer); 317 ASSERT_TRUE(result_layer);
366 EXPECT_EQ(12345, result_layer->id()); 318 EXPECT_EQ(root->id(), result_layer->id());
367 319
368 test_point = gfx::PointF(99.f, 99.f); 320 test_point = gfx::PointF(99.f, 99.f);
369 result_layer = 321 result_layer =
370 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 322 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
371 ASSERT_TRUE(result_layer); 323 ASSERT_TRUE(result_layer);
372 EXPECT_EQ(12345, result_layer->id()); 324 EXPECT_EQ(root->id(), result_layer->id());
373 } 325 }
374 326
375 TEST_F(LayerTreeImplTest, HitTestingForSingleRotatedLayer) { 327 TEST_F(LayerTreeImplTest, HitTestingForSingleRotatedLayer) {
376 std::unique_ptr<LayerImpl> root =
377 LayerImpl::Create(host_impl().active_tree(), 12345);
378
379 gfx::Transform rotation45_degrees_about_center; 328 gfx::Transform rotation45_degrees_about_center;
380 rotation45_degrees_about_center.Translate(50.0, 50.0); 329 rotation45_degrees_about_center.Translate(50.0, 50.0);
381 rotation45_degrees_about_center.RotateAboutZAxis(45.0); 330 rotation45_degrees_about_center.RotateAboutZAxis(45.0);
382 rotation45_degrees_about_center.Translate(-50.0, -50.0); 331 rotation45_degrees_about_center.Translate(-50.0, -50.0);
383 332
333 LayerImpl* root = root_layer();
384 root->SetTransform(rotation45_degrees_about_center); 334 root->SetTransform(rotation45_degrees_about_center);
385 root->SetBounds(gfx::Size(100, 100)); 335 root->SetBounds(gfx::Size(100, 100));
386 root->SetDrawsContent(true); 336 root->SetDrawsContent(true);
387 337
388 host_impl().SetViewportSize(root->bounds()); 338 host_impl().SetViewportSize(root->bounds());
389 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
390 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 339 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
391 340
392 // Sanity check the scenario we just created. 341 // Sanity check the scenario we just created.
393 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 342 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
394 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); 343 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
395 344
396 // Hit testing for points outside the layer. 345 // Hit testing for points outside the layer.
397 // These corners would have been inside the un-transformed layer, but they 346 // These corners would have been inside the un-transformed layer, but they
398 // should not hit the correctly transformed layer. 347 // should not hit the correctly transformed layer.
399 gfx::PointF test_point(99.f, 99.f); 348 gfx::PointF test_point(99.f, 99.f);
400 LayerImpl* result_layer = 349 LayerImpl* result_layer =
401 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 350 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
402 EXPECT_FALSE(result_layer); 351 EXPECT_FALSE(result_layer);
403 352
404 test_point = gfx::PointF(1.f, 1.f); 353 test_point = gfx::PointF(1.f, 1.f);
405 result_layer = 354 result_layer =
406 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 355 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
407 EXPECT_FALSE(result_layer); 356 EXPECT_FALSE(result_layer);
408 357
409 // Hit testing for a point inside should return the root layer. 358 // Hit testing for a point inside should return the root layer.
410 test_point = gfx::PointF(1.f, 50.f); 359 test_point = gfx::PointF(1.f, 50.f);
411 result_layer = 360 result_layer =
412 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 361 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
413 ASSERT_TRUE(result_layer); 362 ASSERT_TRUE(result_layer);
414 EXPECT_EQ(12345, result_layer->id()); 363 EXPECT_EQ(root->id(), result_layer->id());
415 364
416 // Hit testing the corners that would overlap the unclipped layer, but are 365 // Hit testing the corners that would overlap the unclipped layer, but are
417 // outside the clipped region. 366 // outside the clipped region.
418 test_point = gfx::PointF(50.f, -1.f); 367 test_point = gfx::PointF(50.f, -1.f);
419 result_layer = 368 result_layer =
420 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 369 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
421 ASSERT_FALSE(result_layer); 370 ASSERT_FALSE(result_layer);
422 371
423 test_point = gfx::PointF(-1.f, 50.f); 372 test_point = gfx::PointF(-1.f, 50.f);
424 result_layer = 373 result_layer =
425 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 374 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
426 ASSERT_FALSE(result_layer); 375 ASSERT_FALSE(result_layer);
427 } 376 }
428 377
429 TEST_F(LayerTreeImplTest, HitTestingClipNodeDifferentTransformAndTargetIds) { 378 TEST_F(LayerTreeImplTest, HitTestingClipNodeDifferentTransformAndTargetIds) {
430 // Tests hit testing on a layer whose clip node has different transform and 379 // Tests hit testing on a layer whose clip node has different transform and
431 // target id. 380 // target id.
432 std::unique_ptr<LayerImpl> root = 381 LayerImpl* root = root_layer();
433 LayerImpl::Create(host_impl().active_tree(), 1);
434 root->SetBounds(gfx::Size(500, 500)); 382 root->SetBounds(gfx::Size(500, 500));
435 383
436 gfx::Transform translation; 384 gfx::Transform translation;
437 translation.Translate(100, 100); 385 translation.Translate(100, 100);
438 std::unique_ptr<LayerImpl> render_surface = 386 std::unique_ptr<LayerImpl> render_surface =
439 LayerImpl::Create(host_impl().active_tree(), 2); 387 LayerImpl::Create(host_impl().active_tree(), 2);
440 render_surface->SetTransform(translation); 388 render_surface->SetTransform(translation);
441 render_surface->SetBounds(gfx::Size(100, 100)); 389 render_surface->SetBounds(gfx::Size(100, 100));
442 render_surface->test_properties()->force_render_surface = true; 390 render_surface->test_properties()->force_render_surface = true;
443 391
(...skipping 13 matching lines...) Expand all
457 LayerImpl::Create(host_impl().active_tree(), 5); 405 LayerImpl::Create(host_impl().active_tree(), 5);
458 test->SetBounds(gfx::Size(100, 100)); 406 test->SetBounds(gfx::Size(100, 100));
459 test->SetDrawsContent(true); 407 test->SetDrawsContent(true);
460 408
461 clip->test_properties()->AddChild(std::move(test)); 409 clip->test_properties()->AddChild(std::move(test));
462 scale->test_properties()->AddChild(std::move(clip)); 410 scale->test_properties()->AddChild(std::move(clip));
463 render_surface->test_properties()->AddChild(std::move(scale)); 411 render_surface->test_properties()->AddChild(std::move(scale));
464 root->test_properties()->AddChild(std::move(render_surface)); 412 root->test_properties()->AddChild(std::move(render_surface));
465 413
466 host_impl().SetViewportSize(root->bounds()); 414 host_impl().SetViewportSize(root->bounds());
467 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
468 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 415 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
469 416
470 gfx::PointF test_point(160.f, 160.f); 417 gfx::PointF test_point(160.f, 160.f);
471 LayerImpl* result_layer = 418 LayerImpl* result_layer =
472 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 419 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
473 EXPECT_FALSE(result_layer); 420 EXPECT_FALSE(result_layer);
474 421
475 test_point = gfx::PointF(140.f, 140.f); 422 test_point = gfx::PointF(140.f, 140.f);
476 result_layer = 423 result_layer =
477 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 424 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
478 ASSERT_TRUE(result_layer); 425 ASSERT_TRUE(result_layer);
479 EXPECT_EQ(5, result_layer->id()); 426 EXPECT_EQ(5, result_layer->id());
480 427
481 ClipTree& clip_tree = host_impl().active_tree()->property_trees()->clip_tree; 428 ClipTree& clip_tree = host_impl().active_tree()->property_trees()->clip_tree;
482 ClipNode* clip_node = clip_tree.Node(result_layer->clip_tree_index()); 429 ClipNode* clip_node = clip_tree.Node(result_layer->clip_tree_index());
483 EXPECT_NE(clip_node->transform_id, clip_node->target_transform_id); 430 EXPECT_NE(clip_node->transform_id, clip_node->target_transform_id);
484 } 431 }
485 432
486 TEST_F(LayerTreeImplTest, HitTestingSiblings) { 433 TEST_F(LayerTreeImplTest, HitTestingSiblings) {
487 // This tests hit testing when the test point hits only one of the siblings. 434 // This tests hit testing when the test point hits only one of the siblings.
488 gfx::Transform identity_matrix; 435 LayerImpl* root = root_layer();
489 std::unique_ptr<LayerImpl> root =
490 LayerImpl::Create(host_impl().active_tree(), 1);
491 root->SetBounds(gfx::Size(100, 100)); 436 root->SetBounds(gfx::Size(100, 100));
437
492 std::unique_ptr<LayerImpl> child1 = 438 std::unique_ptr<LayerImpl> child1 =
493 LayerImpl::Create(host_impl().active_tree(), 2); 439 LayerImpl::Create(host_impl().active_tree(), 2);
494 child1->SetBounds(gfx::Size(25, 25)); 440 child1->SetBounds(gfx::Size(25, 25));
495 child1->SetMasksToBounds(true); 441 child1->SetMasksToBounds(true);
496 child1->SetDrawsContent(true); 442 child1->SetDrawsContent(true);
443
497 std::unique_ptr<LayerImpl> child2 = 444 std::unique_ptr<LayerImpl> child2 =
498 LayerImpl::Create(host_impl().active_tree(), 3); 445 LayerImpl::Create(host_impl().active_tree(), 3);
499 child2->SetBounds(gfx::Size(75, 75)); 446 child2->SetBounds(gfx::Size(75, 75));
500 child2->SetMasksToBounds(true); 447 child2->SetMasksToBounds(true);
501 child2->SetDrawsContent(true); 448 child2->SetDrawsContent(true);
449
502 root->test_properties()->AddChild(std::move(child1)); 450 root->test_properties()->AddChild(std::move(child1));
503 root->test_properties()->AddChild(std::move(child2)); 451 root->test_properties()->AddChild(std::move(child2));
504 452
505 host_impl().SetViewportSize(root->bounds()); 453 host_impl().SetViewportSize(root->bounds());
506 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
507 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 454 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
508 455
509 gfx::PointF test_point(50.f, 50.f); 456 gfx::PointF test_point(50.f, 50.f);
510 LayerImpl* result_layer = 457 LayerImpl* result_layer =
511 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 458 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
512 ASSERT_TRUE(result_layer); 459 ASSERT_TRUE(result_layer);
513 EXPECT_EQ(3, result_layer->id()); 460 EXPECT_EQ(3, result_layer->id());
514 } 461 }
515 462
516 TEST_F(LayerTreeImplTest, HitTestingPointOutsideMaxTextureSize) { 463 TEST_F(LayerTreeImplTest, HitTestingPointOutsideMaxTextureSize) {
517 gfx::Transform identity_matrix; 464 gfx::Transform identity_matrix;
518 int max_texture_size = 465 int max_texture_size =
519 host_impl().active_tree()->resource_provider()->max_texture_size(); 466 host_impl().active_tree()->resource_provider()->max_texture_size();
520 gfx::Size bounds(max_texture_size + 100, max_texture_size + 100); 467 gfx::Size bounds(max_texture_size + 100, max_texture_size + 100);
521 468
522 std::unique_ptr<LayerImpl> root = 469 LayerImpl* root = root_layer();
523 LayerImpl::Create(host_impl().active_tree(), 1);
524 root->SetBounds(bounds); 470 root->SetBounds(bounds);
525 471
526 std::unique_ptr<LayerImpl> surface = 472 std::unique_ptr<LayerImpl> surface =
527 LayerImpl::Create(host_impl().active_tree(), 2); 473 LayerImpl::Create(host_impl().active_tree(), 2);
528 surface->SetBounds(bounds); 474 surface->SetBounds(bounds);
529 surface->SetMasksToBounds(true); 475 surface->SetMasksToBounds(true);
530 surface->SetDrawsContent(true); 476 surface->SetDrawsContent(true);
531 surface->test_properties()->force_render_surface = true; 477 surface->test_properties()->force_render_surface = true;
532 478
533 root->test_properties()->AddChild(std::move(surface)); 479 root->test_properties()->AddChild(std::move(surface));
534 host_impl().SetViewportSize(root->bounds()); 480 host_impl().SetViewportSize(root->bounds());
535 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
536 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 481 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
537 482
538 gfx::PointF test_point(max_texture_size - 50, max_texture_size - 50); 483 gfx::PointF test_point(max_texture_size - 50, max_texture_size - 50);
539 LayerImpl* result_layer = 484 LayerImpl* result_layer =
540 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 485 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
541 EXPECT_TRUE(result_layer); 486 EXPECT_TRUE(result_layer);
542 487
543 test_point = gfx::PointF(max_texture_size + 50, max_texture_size + 50); 488 test_point = gfx::PointF(max_texture_size + 50, max_texture_size + 50);
544 result_layer = 489 result_layer =
545 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 490 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
546 EXPECT_FALSE(result_layer); 491 EXPECT_FALSE(result_layer);
547 } 492 }
548 493
549 TEST_F(LayerTreeImplTest, HitTestingForSinglePerspectiveLayer) { 494 TEST_F(LayerTreeImplTest, HitTestingForSinglePerspectiveLayer) {
550 std::unique_ptr<LayerImpl> root =
551 LayerImpl::Create(host_impl().active_tree(), 12345);
552
553 // perspective_projection_about_center * translation_by_z is designed so that 495 // perspective_projection_about_center * translation_by_z is designed so that
554 // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50). 496 // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50).
555 gfx::Transform perspective_projection_about_center; 497 gfx::Transform perspective_projection_about_center;
556 perspective_projection_about_center.Translate(50.0, 50.0); 498 perspective_projection_about_center.Translate(50.0, 50.0);
557 perspective_projection_about_center.ApplyPerspectiveDepth(1.0); 499 perspective_projection_about_center.ApplyPerspectiveDepth(1.0);
558 perspective_projection_about_center.Translate(-50.0, -50.0); 500 perspective_projection_about_center.Translate(-50.0, -50.0);
559 gfx::Transform translation_by_z; 501 gfx::Transform translation_by_z;
560 translation_by_z.Translate3d(0.0, 0.0, -1.0); 502 translation_by_z.Translate3d(0.0, 0.0, -1.0);
561 503
504 LayerImpl* root = root_layer();
562 root->SetTransform(perspective_projection_about_center * translation_by_z); 505 root->SetTransform(perspective_projection_about_center * translation_by_z);
563 root->SetBounds(gfx::Size(100, 100)); 506 root->SetBounds(gfx::Size(100, 100));
564 root->SetDrawsContent(true); 507 root->SetDrawsContent(true);
565 508
566 host_impl().SetViewportSize(root->bounds()); 509 host_impl().SetViewportSize(root->bounds());
567 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
568 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 510 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
569 511
570 // Sanity check the scenario we just created. 512 // Sanity check the scenario we just created.
571 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 513 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
572 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); 514 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
573 515
574 // Hit testing for points outside the layer. 516 // Hit testing for points outside the layer.
575 // These corners would have been inside the un-transformed layer, but they 517 // These corners would have been inside the un-transformed layer, but they
576 // should not hit the correctly transformed layer. 518 // should not hit the correctly transformed layer.
577 gfx::PointF test_point(24.f, 24.f); 519 gfx::PointF test_point(24.f, 24.f);
578 LayerImpl* result_layer = 520 LayerImpl* result_layer =
579 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 521 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
580 EXPECT_FALSE(result_layer); 522 EXPECT_FALSE(result_layer);
581 523
582 test_point = gfx::PointF(76.f, 76.f); 524 test_point = gfx::PointF(76.f, 76.f);
583 result_layer = 525 result_layer =
584 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 526 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
585 EXPECT_FALSE(result_layer); 527 EXPECT_FALSE(result_layer);
586 528
587 // Hit testing for a point inside should return the root layer. 529 // Hit testing for a point inside should return the root layer.
588 test_point = gfx::PointF(26.f, 26.f); 530 test_point = gfx::PointF(26.f, 26.f);
589 result_layer = 531 result_layer =
590 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 532 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
591 ASSERT_TRUE(result_layer); 533 ASSERT_TRUE(result_layer);
592 EXPECT_EQ(12345, result_layer->id()); 534 EXPECT_EQ(root->id(), result_layer->id());
593 535
594 test_point = gfx::PointF(74.f, 74.f); 536 test_point = gfx::PointF(74.f, 74.f);
595 result_layer = 537 result_layer =
596 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 538 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
597 ASSERT_TRUE(result_layer); 539 ASSERT_TRUE(result_layer);
598 EXPECT_EQ(12345, result_layer->id()); 540 EXPECT_EQ(root->id(), result_layer->id());
599 } 541 }
600 542
601 TEST_F(LayerTreeImplTest, HitTestingForSimpleClippedLayer) { 543 TEST_F(LayerTreeImplTest, HitTestingForSimpleClippedLayer) {
602 // Test that hit-testing will only work for the visible portion of a layer, 544 // Test that hit-testing will only work for the visible portion of a layer,
603 // and not the entire layer bounds. Here we just test the simple axis-aligned 545 // and not the entire layer bounds. Here we just test the simple axis-aligned
604 // case. 546 // case.
605 std::unique_ptr<LayerImpl> root = 547 LayerImpl* root = root_layer();
606 LayerImpl::Create(host_impl().active_tree(), 1);
607 root->SetBounds(gfx::Size(100, 100)); 548 root->SetBounds(gfx::Size(100, 100));
608 { 549 {
609 std::unique_ptr<LayerImpl> clipping_layer = 550 std::unique_ptr<LayerImpl> clipping_layer =
610 LayerImpl::Create(host_impl().active_tree(), 123); 551 LayerImpl::Create(host_impl().active_tree(), 123);
611 // this layer is positioned, and hit testing should correctly know where the 552 // this layer is positioned, and hit testing should correctly know where the
612 // layer is located. 553 // layer is located.
613 clipping_layer->SetPosition(gfx::PointF(25.f, 25.f)); 554 clipping_layer->SetPosition(gfx::PointF(25.f, 25.f));
614 clipping_layer->SetBounds(gfx::Size(50, 50)); 555 clipping_layer->SetBounds(gfx::Size(50, 50));
615 clipping_layer->SetMasksToBounds(true); 556 clipping_layer->SetMasksToBounds(true);
616 557
617 std::unique_ptr<LayerImpl> child = 558 std::unique_ptr<LayerImpl> child =
618 LayerImpl::Create(host_impl().active_tree(), 456); 559 LayerImpl::Create(host_impl().active_tree(), 456);
619 child->SetPosition(gfx::PointF(-50.f, -50.f)); 560 child->SetPosition(gfx::PointF(-50.f, -50.f));
620 child->SetBounds(gfx::Size(300, 300)); 561 child->SetBounds(gfx::Size(300, 300));
621 child->SetDrawsContent(true); 562 child->SetDrawsContent(true);
622 clipping_layer->test_properties()->AddChild(std::move(child)); 563 clipping_layer->test_properties()->AddChild(std::move(child));
623 root->test_properties()->AddChild(std::move(clipping_layer)); 564 root->test_properties()->AddChild(std::move(clipping_layer));
624 } 565 }
625 566
626 host_impl().SetViewportSize(root->bounds()); 567 host_impl().SetViewportSize(root->bounds());
627 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
628 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 568 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
629 569
630 // Sanity check the scenario we just created. 570 // Sanity check the scenario we just created.
631 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 571 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
632 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); 572 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
633 ASSERT_EQ(456, root_layer()->render_surface()->layer_list().at(0)->id()); 573 ASSERT_EQ(456, root_layer()->render_surface()->layer_list().at(0)->id());
634 574
635 // Hit testing for a point outside the layer should return a null pointer. 575 // Hit testing for a point outside the layer should return a null pointer.
636 // Despite the child layer being very large, it should be clipped to the root 576 // Despite the child layer being very large, it should be clipped to the root
637 // layer's bounds. 577 // layer's bounds.
(...skipping 27 matching lines...) Expand all
665 // This test checks whether hit testing correctly avoids hit testing with 605 // This test checks whether hit testing correctly avoids hit testing with
666 // multiple ancestors that clip in non axis-aligned ways. To pass this test, 606 // multiple ancestors that clip in non axis-aligned ways. To pass this test,
667 // the hit testing algorithm needs to recognize that multiple parent layers 607 // the hit testing algorithm needs to recognize that multiple parent layers
668 // may clip the layer, and should not actually hit those clipped areas. 608 // may clip the layer, and should not actually hit those clipped areas.
669 // 609 //
670 // The child and grand_child layers are both initialized to clip the 610 // The child and grand_child layers are both initialized to clip the
671 // rotated_leaf. The child layer is rotated about the top-left corner, so that 611 // rotated_leaf. The child layer is rotated about the top-left corner, so that
672 // the root + child clips combined create a triangle. The rotated_leaf will 612 // the root + child clips combined create a triangle. The rotated_leaf will
673 // only be visible where it overlaps this triangle. 613 // only be visible where it overlaps this triangle.
674 // 614 //
675 std::unique_ptr<LayerImpl> root = 615 LayerImpl* root = root_layer();
676 LayerImpl::Create(host_impl().active_tree(), 123);
677 LayerImpl* root_layer = root.get();
678 616
679 root->SetBounds(gfx::Size(100, 100)); 617 root->SetBounds(gfx::Size(100, 100));
680 root->SetMasksToBounds(true); 618 root->SetMasksToBounds(true);
681 { 619 {
682 std::unique_ptr<LayerImpl> child = 620 std::unique_ptr<LayerImpl> child =
683 LayerImpl::Create(host_impl().active_tree(), 456); 621 LayerImpl::Create(host_impl().active_tree(), 456);
684 std::unique_ptr<LayerImpl> grand_child = 622 std::unique_ptr<LayerImpl> grand_child =
685 LayerImpl::Create(host_impl().active_tree(), 789); 623 LayerImpl::Create(host_impl().active_tree(), 789);
686 std::unique_ptr<LayerImpl> rotated_leaf = 624 std::unique_ptr<LayerImpl> rotated_leaf =
687 LayerImpl::Create(host_impl().active_tree(), 2468); 625 LayerImpl::Create(host_impl().active_tree(), 2468);
(...skipping 21 matching lines...) Expand all
709 rotated_leaf_transform.Translate(50.0, 50.0); 647 rotated_leaf_transform.Translate(50.0, 50.0);
710 rotated_leaf_transform.RotateAboutZAxis(45.0); 648 rotated_leaf_transform.RotateAboutZAxis(45.0);
711 rotated_leaf_transform.Translate(-50.0, -50.0); 649 rotated_leaf_transform.Translate(-50.0, -50.0);
712 rotated_leaf->SetBounds(gfx::Size(100, 100)); 650 rotated_leaf->SetBounds(gfx::Size(100, 100));
713 rotated_leaf->SetTransform(rotated_leaf_transform); 651 rotated_leaf->SetTransform(rotated_leaf_transform);
714 rotated_leaf->SetDrawsContent(true); 652 rotated_leaf->SetDrawsContent(true);
715 653
716 grand_child->test_properties()->AddChild(std::move(rotated_leaf)); 654 grand_child->test_properties()->AddChild(std::move(rotated_leaf));
717 child->test_properties()->AddChild(std::move(grand_child)); 655 child->test_properties()->AddChild(std::move(grand_child));
718 root->test_properties()->AddChild(std::move(child)); 656 root->test_properties()->AddChild(std::move(child));
719 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
720 657
721 ExecuteCalculateDrawProperties(root_layer); 658 ExecuteCalculateDrawProperties(root);
722 } 659 }
723 660
724 host_impl().SetViewportSize(root_layer->bounds()); 661 host_impl().SetViewportSize(root->bounds());
725 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 662 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
726 // (11, 89) is close to the the bottom left corner within the clip, but it is 663 // (11, 89) is close to the the bottom left corner within the clip, but it is
727 // not inside the layer. 664 // not inside the layer.
728 gfx::PointF test_point(11.f, 89.f); 665 gfx::PointF test_point(11.f, 89.f);
729 LayerImpl* result_layer = 666 LayerImpl* result_layer =
730 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 667 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
731 EXPECT_FALSE(result_layer); 668 EXPECT_FALSE(result_layer);
732 669
733 // Closer inwards from the bottom left will overlap the layer. 670 // Closer inwards from the bottom left will overlap the layer.
734 test_point = gfx::PointF(25.f, 75.f); 671 test_point = gfx::PointF(25.f, 75.f);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 ASSERT_TRUE(result_layer); 706 ASSERT_TRUE(result_layer);
770 EXPECT_EQ(2468, result_layer->id()); 707 EXPECT_EQ(2468, result_layer->id());
771 } 708 }
772 709
773 TEST_F(LayerTreeImplTest, HitTestingForNonClippingIntermediateLayer) { 710 TEST_F(LayerTreeImplTest, HitTestingForNonClippingIntermediateLayer) {
774 // This test checks that hit testing code does not accidentally clip to layer 711 // This test checks that hit testing code does not accidentally clip to layer
775 // bounds for a layer that actually does not clip. 712 // bounds for a layer that actually does not clip.
776 gfx::Transform identity_matrix; 713 gfx::Transform identity_matrix;
777 gfx::Point3F transform_origin; 714 gfx::Point3F transform_origin;
778 715
779 std::unique_ptr<LayerImpl> root = 716 LayerImpl* root = root_layer();
780 LayerImpl::Create(host_impl().active_tree(), 1);
781 root->SetBounds(gfx::Size(100, 100)); 717 root->SetBounds(gfx::Size(100, 100));
782 { 718 {
783 std::unique_ptr<LayerImpl> intermediate_layer = 719 std::unique_ptr<LayerImpl> intermediate_layer =
784 LayerImpl::Create(host_impl().active_tree(), 123); 720 LayerImpl::Create(host_impl().active_tree(), 123);
785 // this layer is positioned, and hit testing should correctly know where the 721 // this layer is positioned, and hit testing should correctly know where the
786 // layer is located. 722 // layer is located.
787 intermediate_layer->SetPosition(gfx::PointF(10.f, 10.f)); 723 intermediate_layer->SetPosition(gfx::PointF(10.f, 10.f));
788 intermediate_layer->SetBounds(gfx::Size(50, 50)); 724 intermediate_layer->SetBounds(gfx::Size(50, 50));
789 // Sanity check the intermediate layer should not clip. 725 // Sanity check the intermediate layer should not clip.
790 ASSERT_FALSE(intermediate_layer->masks_to_bounds()); 726 ASSERT_FALSE(intermediate_layer->masks_to_bounds());
791 ASSERT_FALSE(intermediate_layer->test_properties()->mask_layer); 727 ASSERT_FALSE(intermediate_layer->test_properties()->mask_layer);
792 728
793 // The child of the intermediate_layer is translated so that it does not 729 // The child of the intermediate_layer is translated so that it does not
794 // overlap intermediate_layer at all. If child is incorrectly clipped, we 730 // overlap intermediate_layer at all. If child is incorrectly clipped, we
795 // would not be able to hit it successfully. 731 // would not be able to hit it successfully.
796 std::unique_ptr<LayerImpl> child = 732 std::unique_ptr<LayerImpl> child =
797 LayerImpl::Create(host_impl().active_tree(), 456); 733 LayerImpl::Create(host_impl().active_tree(), 456);
798 child->SetPosition(gfx::PointF(60.f, 60.f)); // 70, 70 in screen space 734 child->SetPosition(gfx::PointF(60.f, 60.f)); // 70, 70 in screen space
799 child->SetBounds(gfx::Size(20, 20)); 735 child->SetBounds(gfx::Size(20, 20));
800 child->SetDrawsContent(true); 736 child->SetDrawsContent(true);
801 intermediate_layer->test_properties()->AddChild(std::move(child)); 737 intermediate_layer->test_properties()->AddChild(std::move(child));
802 root->test_properties()->AddChild(std::move(intermediate_layer)); 738 root->test_properties()->AddChild(std::move(intermediate_layer));
803 } 739 }
804 740
805 host_impl().SetViewportSize(root->bounds()); 741 host_impl().SetViewportSize(root->bounds());
806 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
807 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 742 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
808 743
809 // Sanity check the scenario we just created. 744 // Sanity check the scenario we just created.
810 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 745 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
811 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); 746 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
812 ASSERT_EQ(456, root_layer()->render_surface()->layer_list().at(0)->id()); 747 ASSERT_EQ(456, root_layer()->render_surface()->layer_list().at(0)->id());
813 748
814 // Hit testing for a point outside the layer should return a null pointer. 749 // Hit testing for a point outside the layer should return a null pointer.
815 gfx::PointF test_point(69.f, 69.f); 750 gfx::PointF test_point(69.f, 69.f);
816 LayerImpl* result_layer = 751 LayerImpl* result_layer =
(...skipping 13 matching lines...) Expand all
830 EXPECT_EQ(456, result_layer->id()); 765 EXPECT_EQ(456, result_layer->id());
831 766
832 test_point = gfx::PointF(89.f, 89.f); 767 test_point = gfx::PointF(89.f, 89.f);
833 result_layer = 768 result_layer =
834 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 769 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
835 ASSERT_TRUE(result_layer); 770 ASSERT_TRUE(result_layer);
836 EXPECT_EQ(456, result_layer->id()); 771 EXPECT_EQ(456, result_layer->id());
837 } 772 }
838 773
839 TEST_F(LayerTreeImplTest, HitTestingForMultipleLayers) { 774 TEST_F(LayerTreeImplTest, HitTestingForMultipleLayers) {
840 std::unique_ptr<LayerImpl> root = 775 LayerImpl* root = root_layer();
841 LayerImpl::Create(host_impl().active_tree(), 1);
842 LayerImpl* root_layer = root.get();
843
844 root->SetBounds(gfx::Size(100, 100)); 776 root->SetBounds(gfx::Size(100, 100));
845 root->SetDrawsContent(true); 777 root->SetDrawsContent(true);
846 { 778 {
847 // child 1 and child2 are initialized to overlap between x=50 and x=60. 779 // child 1 and child2 are initialized to overlap between x=50 and x=60.
848 // grand_child is set to overlap both child1 and child2 between y=50 and 780 // grand_child is set to overlap both child1 and child2 between y=50 and
849 // y=60. The expected stacking order is: (front) child2, (second) 781 // y=60. The expected stacking order is: (front) child2, (second)
850 // grand_child, (third) child1, and (back) the root layer behind all other 782 // grand_child, (third) child1, and (back) the root layer behind all other
851 // layers. 783 // layers.
852 784
853 std::unique_ptr<LayerImpl> child1 = 785 std::unique_ptr<LayerImpl> child1 =
(...skipping 14 matching lines...) Expand all
868 // Remember that grand_child is positioned with respect to its parent (i.e. 800 // Remember that grand_child is positioned with respect to its parent (i.e.
869 // child1). In screen space, the intended position is (10, 50), with size 801 // child1). In screen space, the intended position is (10, 50), with size
870 // 100 x 50. 802 // 100 x 50.
871 grand_child1->SetPosition(gfx::PointF(0.f, 40.f)); 803 grand_child1->SetPosition(gfx::PointF(0.f, 40.f));
872 grand_child1->SetBounds(gfx::Size(100, 50)); 804 grand_child1->SetBounds(gfx::Size(100, 50));
873 grand_child1->SetDrawsContent(true); 805 grand_child1->SetDrawsContent(true);
874 806
875 child1->test_properties()->AddChild(std::move(grand_child1)); 807 child1->test_properties()->AddChild(std::move(grand_child1));
876 root->test_properties()->AddChild(std::move(child1)); 808 root->test_properties()->AddChild(std::move(child1));
877 root->test_properties()->AddChild(std::move(child2)); 809 root->test_properties()->AddChild(std::move(child2));
878 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
879 810
880 ExecuteCalculateDrawProperties(root_layer); 811 ExecuteCalculateDrawProperties(root);
881 } 812 }
882 813
883 LayerImpl* child1 = root_layer->test_properties()->children[0]; 814 LayerImpl* child1 = root->test_properties()->children[0];
884 LayerImpl* child2 = root_layer->test_properties()->children[1]; 815 LayerImpl* child2 = root->test_properties()->children[1];
885 LayerImpl* grand_child1 = child1->test_properties()->children[0]; 816 LayerImpl* grand_child1 = child1->test_properties()->children[0];
886 817
887 host_impl().SetViewportSize(root_layer->bounds()); 818 host_impl().SetViewportSize(root->bounds());
888 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 819 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
889 820
890 // Sanity check the scenario we just created. 821 // Sanity check the scenario we just created.
891 ASSERT_TRUE(child1); 822 ASSERT_TRUE(child1);
892 ASSERT_TRUE(child2); 823 ASSERT_TRUE(child2);
893 ASSERT_TRUE(grand_child1); 824 ASSERT_TRUE(grand_child1);
894 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 825 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
895 826
896 RenderSurfaceImpl* root_render_surface = root_layer->render_surface(); 827 RenderSurfaceImpl* root_render_surface = root->render_surface();
897 ASSERT_EQ(4u, root_render_surface->layer_list().size()); 828 ASSERT_EQ(4u, root_render_surface->layer_list().size());
898 ASSERT_EQ(1, root_render_surface->layer_list().at(0)->id()); // root layer 829 ASSERT_EQ(1, root_render_surface->layer_list().at(0)->id()); // root layer
899 ASSERT_EQ(2, root_render_surface->layer_list().at(1)->id()); // child1 830 ASSERT_EQ(2, root_render_surface->layer_list().at(1)->id()); // child1
900 ASSERT_EQ(4, root_render_surface->layer_list().at(2)->id()); // grand_child1 831 ASSERT_EQ(4, root_render_surface->layer_list().at(2)->id()); // grand_child1
901 ASSERT_EQ(3, root_render_surface->layer_list().at(3)->id()); // child2 832 ASSERT_EQ(3, root_render_surface->layer_list().at(3)->id()); // child2
902 833
903 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find 834 // Nothing overlaps the root at (1, 1), so hit testing there should find
904 // the root layer. 835 // the root layer.
905 gfx::PointF test_point = gfx::PointF(1.f, 1.f); 836 gfx::PointF test_point = gfx::PointF(1.f, 1.f);
906 LayerImpl* result_layer = 837 LayerImpl* result_layer =
907 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 838 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
908 ASSERT_TRUE(result_layer); 839 ASSERT_TRUE(result_layer);
909 EXPECT_EQ(1, result_layer->id()); 840 EXPECT_EQ(1, result_layer->id());
910 841
911 // At (15, 15), child1 and root are the only layers. child1 is expected to be 842 // At (15, 15), child1 and root are the only layers. child1 is expected to be
912 // on top. 843 // on top.
913 test_point = gfx::PointF(15.f, 15.f); 844 test_point = gfx::PointF(15.f, 15.f);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 } 909 }
979 910
980 TEST_F(LayerTreeImplTest, HitTestingSameSortingContextParentWins) { 911 TEST_F(LayerTreeImplTest, HitTestingSameSortingContextParentWins) {
981 int hit_layer_id = HitTestSimpleTree(/* ids */ 1, 2, 3, 912 int hit_layer_id = HitTestSimpleTree(/* ids */ 1, 2, 3,
982 /* sorting_contexts */ 10, 10, 10, 913 /* sorting_contexts */ 10, 10, 10,
983 /* depths */ 0, -1, -1); 914 /* depths */ 0, -1, -1);
984 EXPECT_EQ(1, hit_layer_id); 915 EXPECT_EQ(1, hit_layer_id);
985 } 916 }
986 917
987 TEST_F(LayerTreeImplTest, HitTestingForMultipleLayersAtVaryingDepths) { 918 TEST_F(LayerTreeImplTest, HitTestingForMultipleLayersAtVaryingDepths) {
988 std::unique_ptr<LayerImpl> root = 919 LayerImpl* root = root_layer();
989 LayerImpl::Create(host_impl().active_tree(), 1);
990
991 root->SetBounds(gfx::Size(100, 100)); 920 root->SetBounds(gfx::Size(100, 100));
992 root->SetDrawsContent(true); 921 root->SetDrawsContent(true);
993 root->test_properties()->should_flatten_transform = false; 922 root->test_properties()->should_flatten_transform = false;
994 root->Set3dSortingContextId(1); 923 root->Set3dSortingContextId(1);
995 { 924 {
996 // child 1 and child2 are initialized to overlap between x=50 and x=60. 925 // child 1 and child2 are initialized to overlap between x=50 and x=60.
997 // grand_child is set to overlap both child1 and child2 between y=50 and 926 // grand_child is set to overlap both child1 and child2 between y=50 and
998 // y=60. The expected stacking order is: (front) child2, (second) 927 // y=60. The expected stacking order is: (front) child2, (second)
999 // grand_child, (third) child1, and (back) the root layer behind all other 928 // grand_child, (third) child1, and (back) the root layer behind all other
1000 // layers. 929 // layers.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 child1->test_properties()->AddChild(std::move(grand_child1)); 961 child1->test_properties()->AddChild(std::move(grand_child1));
1033 root->test_properties()->AddChild(std::move(child1)); 962 root->test_properties()->AddChild(std::move(child1));
1034 root->test_properties()->AddChild(std::move(child2)); 963 root->test_properties()->AddChild(std::move(child2));
1035 } 964 }
1036 965
1037 LayerImpl* child1 = root->test_properties()->children[0]; 966 LayerImpl* child1 = root->test_properties()->children[0];
1038 LayerImpl* child2 = root->test_properties()->children[1]; 967 LayerImpl* child2 = root->test_properties()->children[1];
1039 LayerImpl* grand_child1 = child1->test_properties()->children[0]; 968 LayerImpl* grand_child1 = child1->test_properties()->children[0];
1040 969
1041 host_impl().SetViewportSize(root->bounds()); 970 host_impl().SetViewportSize(root->bounds());
1042 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
1043 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 971 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1044 972
1045 // Sanity check the scenario we just created. 973 // Sanity check the scenario we just created.
1046 ASSERT_TRUE(child1); 974 ASSERT_TRUE(child1);
1047 ASSERT_TRUE(child2); 975 ASSERT_TRUE(child2);
1048 ASSERT_TRUE(grand_child1); 976 ASSERT_TRUE(grand_child1);
1049 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 977 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1050 978
1051 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find 979 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
1052 // the root layer. 980 // the root layer.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to 1019 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
1092 // be on top, as it descends from child1. 1020 // be on top, as it descends from child1.
1093 test_point = gfx::PointF(20.f, 51.f); 1021 test_point = gfx::PointF(20.f, 51.f);
1094 result_layer = 1022 result_layer =
1095 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 1023 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
1096 ASSERT_TRUE(result_layer); 1024 ASSERT_TRUE(result_layer);
1097 EXPECT_EQ(4, result_layer->id()); 1025 EXPECT_EQ(4, result_layer->id());
1098 } 1026 }
1099 1027
1100 TEST_F(LayerTreeImplTest, HitTestingRespectsClipParents) { 1028 TEST_F(LayerTreeImplTest, HitTestingRespectsClipParents) {
1101 std::unique_ptr<LayerImpl> root = 1029 LayerImpl* root = root_layer();
1102 LayerImpl::Create(host_impl().active_tree(), 1);
1103
1104 root->SetBounds(gfx::Size(100, 100)); 1030 root->SetBounds(gfx::Size(100, 100));
1105 root->SetDrawsContent(true); 1031 root->SetDrawsContent(true);
1106 { 1032 {
1107 std::unique_ptr<LayerImpl> child = 1033 std::unique_ptr<LayerImpl> child =
1108 LayerImpl::Create(host_impl().active_tree(), 2); 1034 LayerImpl::Create(host_impl().active_tree(), 2);
1109 std::unique_ptr<LayerImpl> grand_child = 1035 std::unique_ptr<LayerImpl> grand_child =
1110 LayerImpl::Create(host_impl().active_tree(), 4); 1036 LayerImpl::Create(host_impl().active_tree(), 4);
1111 1037
1112 child->SetPosition(gfx::PointF(10.f, 10.f)); 1038 child->SetPosition(gfx::PointF(10.f, 10.f));
1113 child->SetBounds(gfx::Size(1, 1)); 1039 child->SetBounds(gfx::Size(1, 1));
1114 child->SetDrawsContent(true); 1040 child->SetDrawsContent(true);
1115 child->SetMasksToBounds(true); 1041 child->SetMasksToBounds(true);
1116 1042
1117 grand_child->SetPosition(gfx::PointF(0.f, 40.f)); 1043 grand_child->SetPosition(gfx::PointF(0.f, 40.f));
1118 grand_child->SetBounds(gfx::Size(100, 50)); 1044 grand_child->SetBounds(gfx::Size(100, 50));
1119 grand_child->SetDrawsContent(true); 1045 grand_child->SetDrawsContent(true);
1120 grand_child->SetHasRenderSurface(true); 1046 grand_child->SetHasRenderSurface(true);
1121 1047
1122 // This should let |grand_child| "escape" |child|'s clip. 1048 // This should let |grand_child| "escape" |child|'s clip.
1123 grand_child->test_properties()->clip_parent = root.get(); 1049 grand_child->test_properties()->clip_parent = root;
1124 std::unique_ptr<std::set<LayerImpl*>> clip_children( 1050 std::unique_ptr<std::set<LayerImpl*>> clip_children(
1125 new std::set<LayerImpl*>); 1051 new std::set<LayerImpl*>);
1126 clip_children->insert(grand_child.get()); 1052 clip_children->insert(grand_child.get());
1127 root->test_properties()->clip_children.reset(clip_children.release()); 1053 root->test_properties()->clip_children.reset(clip_children.release());
1128 1054
1129 child->test_properties()->AddChild(std::move(grand_child)); 1055 child->test_properties()->AddChild(std::move(grand_child));
1130 root->test_properties()->AddChild(std::move(child)); 1056 root->test_properties()->AddChild(std::move(child));
1131 } 1057 }
1132 1058
1133 host_impl().SetViewportSize(root->bounds()); 1059 host_impl().SetViewportSize(root->bounds());
1134 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
1135 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 1060 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1136 1061
1137 gfx::PointF test_point(12.f, 52.f); 1062 gfx::PointF test_point(12.f, 52.f);
1138 LayerImpl* result_layer = 1063 LayerImpl* result_layer =
1139 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 1064 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
1140 ASSERT_TRUE(result_layer); 1065 ASSERT_TRUE(result_layer);
1141 EXPECT_EQ(4, result_layer->id()); 1066 EXPECT_EQ(4, result_layer->id());
1142 } 1067 }
1143 1068
1144 TEST_F(LayerTreeImplTest, HitTestingRespectsScrollParents) { 1069 TEST_F(LayerTreeImplTest, HitTestingRespectsScrollParents) {
1145 std::unique_ptr<LayerImpl> root = 1070 LayerImpl* root = root_layer();
1146 LayerImpl::Create(host_impl().active_tree(), 1);
1147 root->SetBounds(gfx::Size(100, 100)); 1071 root->SetBounds(gfx::Size(100, 100));
1148 root->SetDrawsContent(true); 1072 root->SetDrawsContent(true);
1149 { 1073 {
1150 std::unique_ptr<LayerImpl> child = 1074 std::unique_ptr<LayerImpl> child =
1151 LayerImpl::Create(host_impl().active_tree(), 2); 1075 LayerImpl::Create(host_impl().active_tree(), 2);
1152 std::unique_ptr<LayerImpl> scroll_child = 1076 std::unique_ptr<LayerImpl> scroll_child =
1153 LayerImpl::Create(host_impl().active_tree(), 3); 1077 LayerImpl::Create(host_impl().active_tree(), 3);
1154 std::unique_ptr<LayerImpl> grand_child = 1078 std::unique_ptr<LayerImpl> grand_child =
1155 LayerImpl::Create(host_impl().active_tree(), 4); 1079 LayerImpl::Create(host_impl().active_tree(), 4);
1156 1080
(...skipping 15 matching lines...) Expand all
1172 grand_child->SetBounds(gfx::Size(200, 200)); 1096 grand_child->SetBounds(gfx::Size(200, 200));
1173 grand_child->SetDrawsContent(true); 1097 grand_child->SetDrawsContent(true);
1174 grand_child->SetHasRenderSurface(true); 1098 grand_child->SetHasRenderSurface(true);
1175 1099
1176 scroll_child->test_properties()->AddChild(std::move(grand_child)); 1100 scroll_child->test_properties()->AddChild(std::move(grand_child));
1177 root->test_properties()->AddChild(std::move(scroll_child)); 1101 root->test_properties()->AddChild(std::move(scroll_child));
1178 root->test_properties()->AddChild(std::move(child)); 1102 root->test_properties()->AddChild(std::move(child));
1179 } 1103 }
1180 1104
1181 host_impl().SetViewportSize(root->bounds()); 1105 host_impl().SetViewportSize(root->bounds());
1182 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
1183 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 1106 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1184 1107
1185 gfx::PointF test_point(12.f, 52.f); 1108 gfx::PointF test_point(12.f, 52.f);
1186 LayerImpl* result_layer = 1109 LayerImpl* result_layer =
1187 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 1110 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
1188 // The |test_point| should have been clipped away by |child|, the scroll 1111 // The |test_point| should have been clipped away by |child|, the scroll
1189 // parent, so the only thing that should be hit is |root|. 1112 // parent, so the only thing that should be hit is |root|.
1190 ASSERT_TRUE(result_layer); 1113 ASSERT_TRUE(result_layer);
1191 ASSERT_EQ(1, result_layer->id()); 1114 ASSERT_EQ(1, result_layer->id());
1192 } 1115 }
1193 TEST_F(LayerTreeImplTest, HitTestingForMultipleLayerLists) { 1116 TEST_F(LayerTreeImplTest, HitTestingForMultipleLayerLists) {
1194 // 1117 //
1195 // The geometry is set up similarly to the previous case, but 1118 // The geometry is set up similarly to the previous case, but
1196 // all layers are forced to be render surfaces now. 1119 // all layers are forced to be render surfaces now.
1197 // 1120 //
1198 std::unique_ptr<LayerImpl> root = 1121 LayerImpl* root = root_layer();
1199 LayerImpl::Create(host_impl().active_tree(), 1);
1200 LayerImpl* root_layer = root.get();
1201
1202 root->SetBounds(gfx::Size(100, 100)); 1122 root->SetBounds(gfx::Size(100, 100));
1203 root->SetDrawsContent(true); 1123 root->SetDrawsContent(true);
1204 { 1124 {
1205 // child 1 and child2 are initialized to overlap between x=50 and x=60. 1125 // child 1 and child2 are initialized to overlap between x=50 and x=60.
1206 // grand_child is set to overlap both child1 and child2 between y=50 and 1126 // grand_child is set to overlap both child1 and child2 between y=50 and
1207 // y=60. The expected stacking order is: (front) child2, (second) 1127 // y=60. The expected stacking order is: (front) child2, (second)
1208 // grand_child, (third) child1, and (back) the root layer behind all other 1128 // grand_child, (third) child1, and (back) the root layer behind all other
1209 // layers. 1129 // layers.
1210 1130
1211 std::unique_ptr<LayerImpl> child1 = 1131 std::unique_ptr<LayerImpl> child1 =
(...skipping 17 matching lines...) Expand all
1229 // child1). In screen space, the intended position is (10, 50), with size 1149 // child1). In screen space, the intended position is (10, 50), with size
1230 // 100 x 50. 1150 // 100 x 50.
1231 grand_child1->SetPosition(gfx::PointF(0.f, 40.f)); 1151 grand_child1->SetPosition(gfx::PointF(0.f, 40.f));
1232 grand_child1->SetBounds(gfx::Size(100, 50)); 1152 grand_child1->SetBounds(gfx::Size(100, 50));
1233 grand_child1->SetDrawsContent(true); 1153 grand_child1->SetDrawsContent(true);
1234 grand_child1->test_properties()->force_render_surface = true; 1154 grand_child1->test_properties()->force_render_surface = true;
1235 1155
1236 child1->test_properties()->AddChild(std::move(grand_child1)); 1156 child1->test_properties()->AddChild(std::move(grand_child1));
1237 root->test_properties()->AddChild(std::move(child1)); 1157 root->test_properties()->AddChild(std::move(child1));
1238 root->test_properties()->AddChild(std::move(child2)); 1158 root->test_properties()->AddChild(std::move(child2));
1239 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
1240 1159
1241 ExecuteCalculateDrawProperties(root_layer); 1160 ExecuteCalculateDrawProperties(root);
1242 } 1161 }
1243 1162
1244 LayerImpl* child1 = root_layer->test_properties()->children[0]; 1163 LayerImpl* child1 = root->test_properties()->children[0];
1245 LayerImpl* child2 = root_layer->test_properties()->children[1]; 1164 LayerImpl* child2 = root->test_properties()->children[1];
1246 LayerImpl* grand_child1 = child1->test_properties()->children[0]; 1165 LayerImpl* grand_child1 = child1->test_properties()->children[0];
1247 1166
1248 host_impl().SetViewportSize(root_layer->bounds()); 1167 host_impl().SetViewportSize(root->bounds());
1249 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 1168 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1250 1169
1251 // Sanity check the scenario we just created. 1170 // Sanity check the scenario we just created.
1252 ASSERT_TRUE(child1); 1171 ASSERT_TRUE(child1);
1253 ASSERT_TRUE(child2); 1172 ASSERT_TRUE(child2);
1254 ASSERT_TRUE(grand_child1); 1173 ASSERT_TRUE(grand_child1);
1255 ASSERT_TRUE(child1->render_surface()); 1174 ASSERT_TRUE(child1->render_surface());
1256 ASSERT_TRUE(child2->render_surface()); 1175 ASSERT_TRUE(child2->render_surface());
1257 ASSERT_TRUE(grand_child1->render_surface()); 1176 ASSERT_TRUE(grand_child1->render_surface());
1258 ASSERT_EQ(4u, RenderSurfaceLayerList().size()); 1177 ASSERT_EQ(4u, RenderSurfaceLayerList().size());
1259 // The root surface has the root layer, and child1's and child2's render 1178 // The root surface has the root layer, and child1's and child2's render
1260 // surfaces. 1179 // surfaces.
1261 ASSERT_EQ(3u, root_layer->render_surface()->layer_list().size()); 1180 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
1262 // The child1 surface has the child1 layer and grand_child1's render surface. 1181 // The child1 surface has the child1 layer and grand_child1's render surface.
1263 ASSERT_EQ(2u, child1->render_surface()->layer_list().size()); 1182 ASSERT_EQ(2u, child1->render_surface()->layer_list().size());
1264 ASSERT_EQ(1u, child2->render_surface()->layer_list().size()); 1183 ASSERT_EQ(1u, child2->render_surface()->layer_list().size());
1265 ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size()); 1184 ASSERT_EQ(1u, grand_child1->render_surface()->layer_list().size());
1266 ASSERT_EQ(1, RenderSurfaceLayerList().at(0)->id()); // root layer 1185 ASSERT_EQ(1, RenderSurfaceLayerList().at(0)->id()); // root layer
1267 ASSERT_EQ(2, RenderSurfaceLayerList()[1]->id()); // child1 1186 ASSERT_EQ(2, RenderSurfaceLayerList()[1]->id()); // child1
1268 ASSERT_EQ(4, RenderSurfaceLayerList().at(2)->id()); // grand_child1 1187 ASSERT_EQ(4, RenderSurfaceLayerList().at(2)->id()); // grand_child1
1269 ASSERT_EQ(3, RenderSurfaceLayerList()[3]->id()); // child2 1188 ASSERT_EQ(3, RenderSurfaceLayerList()[3]->id()); // child2
1270 1189
1271 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find 1190 // Nothing overlaps the root at (1, 1), so hit testing there should find
1272 // the root layer. 1191 // the root layer.
1273 gfx::PointF test_point(1.f, 1.f); 1192 gfx::PointF test_point(1.f, 1.f);
1274 LayerImpl* result_layer = 1193 LayerImpl* result_layer =
1275 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 1194 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
1276 ASSERT_TRUE(result_layer); 1195 ASSERT_TRUE(result_layer);
1277 EXPECT_EQ(1, result_layer->id()); 1196 EXPECT_EQ(1, result_layer->id());
1278 1197
1279 // At (15, 15), child1 and root are the only layers. child1 is expected to be 1198 // At (15, 15), child1 and root are the only layers. child1 is expected to be
1280 // on top. 1199 // on top.
1281 test_point = gfx::PointF(15.f, 15.f); 1200 test_point = gfx::PointF(15.f, 15.f);
(...skipping 28 matching lines...) Expand all
1310 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to 1229 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
1311 // be on top. 1230 // be on top.
1312 test_point = gfx::PointF(20.f, 51.f); 1231 test_point = gfx::PointF(20.f, 51.f);
1313 result_layer = 1232 result_layer =
1314 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 1233 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
1315 ASSERT_TRUE(result_layer); 1234 ASSERT_TRUE(result_layer);
1316 EXPECT_EQ(4, result_layer->id()); 1235 EXPECT_EQ(4, result_layer->id());
1317 } 1236 }
1318 1237
1319 TEST_F(LayerTreeImplTest, HitCheckingTouchHandlerRegionsForSingleLayer) { 1238 TEST_F(LayerTreeImplTest, HitCheckingTouchHandlerRegionsForSingleLayer) {
1320 std::unique_ptr<LayerImpl> root =
1321 LayerImpl::Create(host_impl().active_tree(), 12345);
1322
1323 Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); 1239 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
1324 1240
1241 LayerImpl* root = root_layer();
1325 root->SetBounds(gfx::Size(100, 100)); 1242 root->SetBounds(gfx::Size(100, 100));
1326 root->SetDrawsContent(true); 1243 root->SetDrawsContent(true);
1327 1244
1328 host_impl().SetViewportSize(root->bounds()); 1245 host_impl().SetViewportSize(root->bounds());
1329 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
1330 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 1246 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1331 1247
1332 // Sanity check the scenario we just created. 1248 // Sanity check the scenario we just created.
1333 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 1249 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1334 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); 1250 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
1335 1251
1336 // Hit checking for any point should return a null pointer for a layer without 1252 // Hit checking for any point should return a null pointer for a layer without
1337 // any touch event handler regions. 1253 // any touch event handler regions.
1338 gfx::PointF test_point(11.f, 11.f); 1254 gfx::PointF test_point(11.f, 11.f);
1339 LayerImpl* result_layer = 1255 LayerImpl* result_layer =
1340 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1256 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1341 test_point); 1257 test_point);
1342 EXPECT_FALSE(result_layer); 1258 EXPECT_FALSE(result_layer);
1343 1259
1344 host_impl() 1260 root->SetTouchEventHandlerRegion(touch_handler_region);
1345 .active_tree()
1346 ->root_layer_for_testing()
1347 ->SetTouchEventHandlerRegion(touch_handler_region);
1348 // Hit checking for a point outside the layer should return a null pointer. 1261 // Hit checking for a point outside the layer should return a null pointer.
1349 test_point = gfx::PointF(101.f, 101.f); 1262 test_point = gfx::PointF(101.f, 101.f);
1350 result_layer = 1263 result_layer =
1351 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1264 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1352 test_point); 1265 test_point);
1353 EXPECT_FALSE(result_layer); 1266 EXPECT_FALSE(result_layer);
1354 1267
1355 test_point = gfx::PointF(-1.f, -1.f); 1268 test_point = gfx::PointF(-1.f, -1.f);
1356 result_layer = 1269 result_layer =
1357 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1270 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
(...skipping 14 matching lines...) Expand all
1372 test_point); 1285 test_point);
1373 EXPECT_FALSE(result_layer); 1286 EXPECT_FALSE(result_layer);
1374 1287
1375 // Hit checking for a point inside the touch event handler region should 1288 // Hit checking for a point inside the touch event handler region should
1376 // return the root layer. 1289 // return the root layer.
1377 test_point = gfx::PointF(11.f, 11.f); 1290 test_point = gfx::PointF(11.f, 11.f);
1378 result_layer = 1291 result_layer =
1379 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1292 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1380 test_point); 1293 test_point);
1381 ASSERT_TRUE(result_layer); 1294 ASSERT_TRUE(result_layer);
1382 EXPECT_EQ(12345, result_layer->id()); 1295 EXPECT_EQ(root->id(), result_layer->id());
1383 1296
1384 test_point = gfx::PointF(59.f, 59.f); 1297 test_point = gfx::PointF(59.f, 59.f);
1385 result_layer = 1298 result_layer =
1386 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1299 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1387 test_point); 1300 test_point);
1388 ASSERT_TRUE(result_layer); 1301 ASSERT_TRUE(result_layer);
1389 EXPECT_EQ(12345, result_layer->id()); 1302 EXPECT_EQ(root->id(), result_layer->id());
1390 } 1303 }
1391 1304
1392 TEST_F(LayerTreeImplTest, 1305 TEST_F(LayerTreeImplTest,
1393 HitCheckingTouchHandlerRegionsForUninvertibleTransform) { 1306 HitCheckingTouchHandlerRegionsForUninvertibleTransform) {
1394 std::unique_ptr<LayerImpl> root =
1395 LayerImpl::Create(host_impl().active_tree(), 12345);
1396
1397 gfx::Transform uninvertible_transform; 1307 gfx::Transform uninvertible_transform;
1398 uninvertible_transform.matrix().set(0, 0, 0.0); 1308 uninvertible_transform.matrix().set(0, 0, 0.0);
1399 uninvertible_transform.matrix().set(1, 1, 0.0); 1309 uninvertible_transform.matrix().set(1, 1, 0.0);
1400 uninvertible_transform.matrix().set(2, 2, 0.0); 1310 uninvertible_transform.matrix().set(2, 2, 0.0);
1401 uninvertible_transform.matrix().set(3, 3, 0.0); 1311 uninvertible_transform.matrix().set(3, 3, 0.0);
1402 ASSERT_FALSE(uninvertible_transform.IsInvertible()); 1312 ASSERT_FALSE(uninvertible_transform.IsInvertible());
1403 1313
1404 Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); 1314 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
1405 1315
1316 LayerImpl* root = root_layer();
1406 root->SetTransform(uninvertible_transform); 1317 root->SetTransform(uninvertible_transform);
1407 root->SetBounds(gfx::Size(100, 100)); 1318 root->SetBounds(gfx::Size(100, 100));
1408 root->SetDrawsContent(true); 1319 root->SetDrawsContent(true);
1409 root->SetTouchEventHandlerRegion(touch_handler_region); 1320 root->SetTouchEventHandlerRegion(touch_handler_region);
1410 1321
1411 host_impl().SetViewportSize(root->bounds()); 1322 host_impl().SetViewportSize(root->bounds());
1412 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
1413 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 1323 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1414 1324
1415 // Sanity check the scenario we just created. 1325 // Sanity check the scenario we just created.
1416 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 1326 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1417 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); 1327 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
1418 ASSERT_FALSE(root_layer()->ScreenSpaceTransform().IsInvertible()); 1328 ASSERT_FALSE(root->ScreenSpaceTransform().IsInvertible());
1419 1329
1420 // Hit checking any point should not hit the touch handler region on the 1330 // Hit checking any point should not hit the touch handler region on the
1421 // layer. If the invertible matrix is accidentally ignored and treated like an 1331 // layer. If the invertible matrix is accidentally ignored and treated like an
1422 // identity, then the hit testing will incorrectly hit the layer when it 1332 // identity, then the hit testing will incorrectly hit the layer when it
1423 // shouldn't. 1333 // shouldn't.
1424 gfx::PointF test_point(1.f, 1.f); 1334 gfx::PointF test_point(1.f, 1.f);
1425 LayerImpl* result_layer = 1335 LayerImpl* result_layer =
1426 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1336 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1427 test_point); 1337 test_point);
1428 EXPECT_FALSE(result_layer); 1338 EXPECT_FALSE(result_layer);
(...skipping 30 matching lines...) Expand all
1459 1369
1460 test_point = gfx::PointF(-1.f, -1.f); 1370 test_point = gfx::PointF(-1.f, -1.f);
1461 result_layer = 1371 result_layer =
1462 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1372 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1463 test_point); 1373 test_point);
1464 EXPECT_FALSE(result_layer); 1374 EXPECT_FALSE(result_layer);
1465 } 1375 }
1466 1376
1467 TEST_F(LayerTreeImplTest, 1377 TEST_F(LayerTreeImplTest,
1468 HitCheckingTouchHandlerRegionsForSinglePositionedLayer) { 1378 HitCheckingTouchHandlerRegionsForSinglePositionedLayer) {
1469 std::unique_ptr<LayerImpl> root = 1379 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
1470 LayerImpl::Create(host_impl().active_tree(), 12345);
1471 1380
1472 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
1473 // This layer is positioned, and hit testing should correctly know where the 1381 // This layer is positioned, and hit testing should correctly know where the
1474 // layer is located. 1382 // layer is located.
1383 LayerImpl* root = root_layer();
1475 root->SetPosition(gfx::PointF(50.f, 50.f)); 1384 root->SetPosition(gfx::PointF(50.f, 50.f));
1476 root->SetBounds(gfx::Size(100, 100)); 1385 root->SetBounds(gfx::Size(100, 100));
1477 root->SetDrawsContent(true); 1386 root->SetDrawsContent(true);
1478 root->SetTouchEventHandlerRegion(touch_handler_region); 1387 root->SetTouchEventHandlerRegion(touch_handler_region);
1479 1388
1480 host_impl().SetViewportSize(root->bounds()); 1389 host_impl().SetViewportSize(root->bounds());
1481 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
1482 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 1390 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1483 1391
1484 // Sanity check the scenario we just created. 1392 // Sanity check the scenario we just created.
1485 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 1393 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1486 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); 1394 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
1487 1395
1488 // Hit checking for a point outside the layer should return a null pointer. 1396 // Hit checking for a point outside the layer should return a null pointer.
1489 gfx::PointF test_point(49.f, 49.f); 1397 gfx::PointF test_point(49.f, 49.f);
1490 LayerImpl* result_layer = 1398 LayerImpl* result_layer =
1491 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1399 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1492 test_point); 1400 test_point);
1493 EXPECT_FALSE(result_layer); 1401 EXPECT_FALSE(result_layer);
1494 1402
1495 // Even though the layer has a touch handler region containing (101, 101), it 1403 // Even though the layer has a touch handler region containing (101, 101), it
1496 // should not be visible there since the root render surface would clamp it. 1404 // should not be visible there since the root render surface would clamp it.
(...skipping 11 matching lines...) Expand all
1508 test_point); 1416 test_point);
1509 EXPECT_FALSE(result_layer); 1417 EXPECT_FALSE(result_layer);
1510 1418
1511 // Hit checking for a point inside the touch event handler region should 1419 // Hit checking for a point inside the touch event handler region should
1512 // return the root layer. 1420 // return the root layer.
1513 test_point = gfx::PointF(61.f, 61.f); 1421 test_point = gfx::PointF(61.f, 61.f);
1514 result_layer = 1422 result_layer =
1515 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1423 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1516 test_point); 1424 test_point);
1517 ASSERT_TRUE(result_layer); 1425 ASSERT_TRUE(result_layer);
1518 EXPECT_EQ(12345, result_layer->id()); 1426 EXPECT_EQ(root->id(), result_layer->id());
1519 1427
1520 test_point = gfx::PointF(99.f, 99.f); 1428 test_point = gfx::PointF(99.f, 99.f);
1521 result_layer = 1429 result_layer =
1522 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1430 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1523 test_point); 1431 test_point);
1524 ASSERT_TRUE(result_layer); 1432 ASSERT_TRUE(result_layer);
1525 EXPECT_EQ(12345, result_layer->id()); 1433 EXPECT_EQ(root->id(), result_layer->id());
1526 } 1434 }
1527 1435
1528 TEST_F(LayerTreeImplTest, 1436 TEST_F(LayerTreeImplTest,
1529 HitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale) { 1437 HitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale) {
1530 // The layer's device_scale_factor and page_scale_factor should scale the 1438 // The layer's device_scale_factor and page_scale_factor should scale the
1531 // content rect and we should be able to hit the touch handler region by 1439 // content rect and we should be able to hit the touch handler region by
1532 // scaling the points accordingly. 1440 // scaling the points accordingly.
1533 std::unique_ptr<LayerImpl> root =
1534 LayerImpl::Create(host_impl().active_tree(), 1);
1535 1441
1536 // Set the bounds of the root layer big enough to fit the child when scaled. 1442 // Set the bounds of the root layer big enough to fit the child when scaled.
1443 LayerImpl* root = root_layer();
1537 root->SetBounds(gfx::Size(100, 100)); 1444 root->SetBounds(gfx::Size(100, 100));
1538 { 1445 {
1539 Region touch_handler_region(gfx::Rect(10, 10, 30, 30)); 1446 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
1540 gfx::PointF position(25.f, 25.f); 1447 gfx::PointF position(25.f, 25.f);
1541 gfx::Size bounds(50, 50); 1448 gfx::Size bounds(50, 50);
1542 std::unique_ptr<LayerImpl> test_layer = 1449 std::unique_ptr<LayerImpl> test_layer =
1543 LayerImpl::Create(host_impl().active_tree(), 12345); 1450 LayerImpl::Create(host_impl().active_tree(), 12345);
1544 test_layer->SetPosition(gfx::PointF(25.f, 25.f)); 1451 test_layer->SetPosition(gfx::PointF(25.f, 25.f));
1545 test_layer->SetBounds(gfx::Size(50, 50)); 1452 test_layer->SetBounds(gfx::Size(50, 50));
1546 test_layer->SetDrawsContent(true); 1453 test_layer->SetDrawsContent(true);
1547 test_layer->SetTouchEventHandlerRegion(touch_handler_region); 1454 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
1548 root->test_properties()->AddChild(std::move(test_layer)); 1455 root->test_properties()->AddChild(std::move(test_layer));
1549 } 1456 }
1550 1457
1551 float device_scale_factor = 3.f; 1458 float device_scale_factor = 3.f;
1552 float page_scale_factor = 5.f; 1459 float page_scale_factor = 5.f;
1553 float max_page_scale_factor = 10.f; 1460 float max_page_scale_factor = 10.f;
1554 gfx::Size scaled_bounds_for_root = gfx::ScaleToCeiledSize( 1461 gfx::Size scaled_bounds_for_root = gfx::ScaleToCeiledSize(
1555 root->bounds(), device_scale_factor * page_scale_factor); 1462 root->bounds(), device_scale_factor * page_scale_factor);
1556 host_impl().SetViewportSize(scaled_bounds_for_root); 1463 host_impl().SetViewportSize(scaled_bounds_for_root);
1557 1464
1558 host_impl().active_tree()->SetDeviceScaleFactor(device_scale_factor); 1465 host_impl().active_tree()->SetDeviceScaleFactor(device_scale_factor);
1559 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
1560 host_impl().active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 1, 1466 host_impl().active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 1,
1561 Layer::INVALID_ID); 1467 Layer::INVALID_ID);
1562 host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting(); 1468 host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
1563 host_impl().active_tree()->PushPageScaleFromMainThread( 1469 host_impl().active_tree()->PushPageScaleFromMainThread(
1564 page_scale_factor, page_scale_factor, max_page_scale_factor); 1470 page_scale_factor, page_scale_factor, max_page_scale_factor);
1565 host_impl().active_tree()->SetPageScaleOnActiveTree(page_scale_factor); 1471 host_impl().active_tree()->SetPageScaleOnActiveTree(page_scale_factor);
1566 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 1472 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1567 1473
1568 // Sanity check the scenario we just created. 1474 // Sanity check the scenario we just created.
1569 // The visible content rect for test_layer is actually 100x100, even though 1475 // The visible content rect for test_layer is actually 100x100, even though
1570 // its layout size is 50x50, positioned at 25x25. 1476 // its layout size is 50x50, positioned at 25x25.
1571 LayerImpl* test_layer = host_impl() 1477 LayerImpl* test_layer = root->test_properties()->children[0];
1572 .active_tree()
1573 ->root_layer_for_testing()
1574 ->test_properties()
1575 ->children[0];
1576 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 1478 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1577 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); 1479 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
1578 1480
1579 // Check whether the child layer fits into the root after scaled. 1481 // Check whether the child layer fits into the root after scaled.
1580 EXPECT_EQ(gfx::Rect(test_layer->bounds()), test_layer->visible_layer_rect()); 1482 EXPECT_EQ(gfx::Rect(test_layer->bounds()), test_layer->visible_layer_rect());
1581 1483
1582 // Hit checking for a point outside the layer should return a null pointer 1484 // Hit checking for a point outside the layer should return a null pointer
1583 // (the root layer does not have a touch event handler, so it will not be 1485 // (the root layer does not have a touch event handler, so it will not be
1584 // tested either). 1486 // tested either).
1585 gfx::PointF test_point(76.f, 76.f); 1487 gfx::PointF test_point(76.f, 76.f);
1586 test_point = 1488 test_point =
1587 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); 1489 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 result_layer = 1543 result_layer =
1642 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1544 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1643 test_point); 1545 test_point);
1644 ASSERT_TRUE(result_layer); 1546 ASSERT_TRUE(result_layer);
1645 EXPECT_EQ(12345, result_layer->id()); 1547 EXPECT_EQ(12345, result_layer->id());
1646 1548
1647 // Check update of page scale factor on the active tree when page scale layer 1549 // Check update of page scale factor on the active tree when page scale layer
1648 // is also the root layer. 1550 // is also the root layer.
1649 page_scale_factor *= 1.5f; 1551 page_scale_factor *= 1.5f;
1650 host_impl().active_tree()->SetPageScaleOnActiveTree(page_scale_factor); 1552 host_impl().active_tree()->SetPageScaleOnActiveTree(page_scale_factor);
1651 EXPECT_EQ(host_impl().active_tree()->root_layer_for_testing(), 1553 EXPECT_EQ(root, host_impl().active_tree()->PageScaleLayer());
1652 host_impl().active_tree()->PageScaleLayer());
1653 1554
1654 test_point = gfx::PointF(35.f, 35.f); 1555 test_point = gfx::PointF(35.f, 35.f);
1655 test_point = 1556 test_point =
1656 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); 1557 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
1657 result_layer = 1558 result_layer =
1658 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1559 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1659 test_point); 1560 test_point);
1660 ASSERT_TRUE(result_layer); 1561 ASSERT_TRUE(result_layer);
1661 EXPECT_EQ(12345, result_layer->id()); 1562 EXPECT_EQ(12345, result_layer->id());
1662 1563
1663 test_point = gfx::PointF(64.f, 64.f); 1564 test_point = gfx::PointF(64.f, 64.f);
1664 test_point = 1565 test_point =
1665 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor); 1566 gfx::ScalePoint(test_point, device_scale_factor * page_scale_factor);
1666 result_layer = 1567 result_layer =
1667 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1568 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1668 test_point); 1569 test_point);
1669 ASSERT_TRUE(result_layer); 1570 ASSERT_TRUE(result_layer);
1670 EXPECT_EQ(12345, result_layer->id()); 1571 EXPECT_EQ(12345, result_layer->id());
1671 } 1572 }
1672 1573
1673 TEST_F(LayerTreeImplTest, HitCheckingTouchHandlerRegionsForSimpleClippedLayer) { 1574 TEST_F(LayerTreeImplTest, HitCheckingTouchHandlerRegionsForSimpleClippedLayer) {
1674 // Test that hit-checking will only work for the visible portion of a layer, 1575 // Test that hit-checking will only work for the visible portion of a layer,
1675 // and not the entire layer bounds. Here we just test the simple axis-aligned 1576 // and not the entire layer bounds. Here we just test the simple axis-aligned
1676 // case. 1577 // case.
1677 std::unique_ptr<LayerImpl> root = 1578 LayerImpl* root = root_layer();
1678 LayerImpl::Create(host_impl().active_tree(), 1);
1679 root->SetBounds(gfx::Size(100, 100)); 1579 root->SetBounds(gfx::Size(100, 100));
1680 { 1580 {
1681 std::unique_ptr<LayerImpl> clipping_layer = 1581 std::unique_ptr<LayerImpl> clipping_layer =
1682 LayerImpl::Create(host_impl().active_tree(), 123); 1582 LayerImpl::Create(host_impl().active_tree(), 123);
1683 // this layer is positioned, and hit testing should correctly know where the 1583 // this layer is positioned, and hit testing should correctly know where the
1684 // layer is located. 1584 // layer is located.
1685 clipping_layer->SetPosition(gfx::PointF(25.f, 25.f)); 1585 clipping_layer->SetPosition(gfx::PointF(25.f, 25.f));
1686 clipping_layer->SetBounds(gfx::Size(50, 50)); 1586 clipping_layer->SetBounds(gfx::Size(50, 50));
1687 clipping_layer->SetMasksToBounds(true); 1587 clipping_layer->SetMasksToBounds(true);
1688 1588
1689 Region touch_handler_region(gfx::Rect(10, 10, 50, 50)); 1589 Region touch_handler_region(gfx::Rect(10, 10, 50, 50));
1690 1590
1691 std::unique_ptr<LayerImpl> child = 1591 std::unique_ptr<LayerImpl> child =
1692 LayerImpl::Create(host_impl().active_tree(), 456); 1592 LayerImpl::Create(host_impl().active_tree(), 456);
1693 child->SetPosition(gfx::PointF(-50.f, -50.f)); 1593 child->SetPosition(gfx::PointF(-50.f, -50.f));
1694 child->SetBounds(gfx::Size(300, 300)); 1594 child->SetBounds(gfx::Size(300, 300));
1695 child->SetDrawsContent(true); 1595 child->SetDrawsContent(true);
1696 child->SetTouchEventHandlerRegion(touch_handler_region); 1596 child->SetTouchEventHandlerRegion(touch_handler_region);
1697 clipping_layer->test_properties()->AddChild(std::move(child)); 1597 clipping_layer->test_properties()->AddChild(std::move(child));
1698 root->test_properties()->AddChild(std::move(clipping_layer)); 1598 root->test_properties()->AddChild(std::move(clipping_layer));
1699 } 1599 }
1700 1600
1701 host_impl().SetViewportSize(root->bounds()); 1601 host_impl().SetViewportSize(root->bounds());
1702 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
1703 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 1602 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1704 1603
1705 // Sanity check the scenario we just created. 1604 // Sanity check the scenario we just created.
1706 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 1605 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1707 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); 1606 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
1708 ASSERT_EQ(456, root_layer()->render_surface()->layer_list().at(0)->id()); 1607 ASSERT_EQ(456, root->render_surface()->layer_list().at(0)->id());
1709 1608
1710 // Hit checking for a point outside the layer should return a null pointer. 1609 // Hit checking for a point outside the layer should return a null pointer.
1711 // Despite the child layer being very large, it should be clipped to the root 1610 // Despite the child layer being very large, it should be clipped to the root
1712 // layer's bounds. 1611 // layer's bounds.
1713 gfx::PointF test_point(24.f, 24.f); 1612 gfx::PointF test_point(24.f, 24.f);
1714 LayerImpl* result_layer = 1613 LayerImpl* result_layer =
1715 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1614 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1716 test_point); 1615 test_point);
1717 EXPECT_FALSE(result_layer); 1616 EXPECT_FALSE(result_layer);
1718 1617
(...skipping 26 matching lines...) Expand all
1745 test_point); 1644 test_point);
1746 ASSERT_TRUE(result_layer); 1645 ASSERT_TRUE(result_layer);
1747 EXPECT_EQ(456, result_layer->id()); 1646 EXPECT_EQ(456, result_layer->id());
1748 } 1647 }
1749 1648
1750 TEST_F(LayerTreeImplTest, 1649 TEST_F(LayerTreeImplTest,
1751 HitCheckingTouchHandlerRegionsForClippedLayerWithDeviceScale) { 1650 HitCheckingTouchHandlerRegionsForClippedLayerWithDeviceScale) {
1752 // The layer's device_scale_factor and page_scale_factor should scale the 1651 // The layer's device_scale_factor and page_scale_factor should scale the
1753 // content rect and we should be able to hit the touch handler region by 1652 // content rect and we should be able to hit the touch handler region by
1754 // scaling the points accordingly. 1653 // scaling the points accordingly.
1755 std::unique_ptr<LayerImpl> root = 1654
1756 LayerImpl::Create(host_impl().active_tree(), 1);
1757 // Set the bounds of the root layer big enough to fit the child when scaled. 1655 // Set the bounds of the root layer big enough to fit the child when scaled.
1656 LayerImpl* root = root_layer();
1758 root->SetBounds(gfx::Size(100, 100)); 1657 root->SetBounds(gfx::Size(100, 100));
1759 std::unique_ptr<LayerImpl> surface = 1658 std::unique_ptr<LayerImpl> surface =
1760 LayerImpl::Create(host_impl().active_tree(), 2); 1659 LayerImpl::Create(host_impl().active_tree(), 2);
1761 surface->SetBounds(gfx::Size(100, 100)); 1660 surface->SetBounds(gfx::Size(100, 100));
1762 surface->test_properties()->force_render_surface = true; 1661 surface->test_properties()->force_render_surface = true;
1763 { 1662 {
1764 std::unique_ptr<LayerImpl> clipping_layer = 1663 std::unique_ptr<LayerImpl> clipping_layer =
1765 LayerImpl::Create(host_impl().active_tree(), 123); 1664 LayerImpl::Create(host_impl().active_tree(), 123);
1766 // This layer is positioned, and hit testing should correctly know where the 1665 // This layer is positioned, and hit testing should correctly know where the
1767 // layer is located. 1666 // layer is located.
(...skipping 15 matching lines...) Expand all
1783 } 1682 }
1784 1683
1785 float device_scale_factor = 3.f; 1684 float device_scale_factor = 3.f;
1786 float page_scale_factor = 1.f; 1685 float page_scale_factor = 1.f;
1787 float max_page_scale_factor = 1.f; 1686 float max_page_scale_factor = 1.f;
1788 gfx::Size scaled_bounds_for_root = gfx::ScaleToCeiledSize( 1687 gfx::Size scaled_bounds_for_root = gfx::ScaleToCeiledSize(
1789 root->bounds(), device_scale_factor * page_scale_factor); 1688 root->bounds(), device_scale_factor * page_scale_factor);
1790 host_impl().SetViewportSize(scaled_bounds_for_root); 1689 host_impl().SetViewportSize(scaled_bounds_for_root);
1791 1690
1792 host_impl().active_tree()->SetDeviceScaleFactor(device_scale_factor); 1691 host_impl().active_tree()->SetDeviceScaleFactor(device_scale_factor);
1793 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
1794 host_impl().active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 1, 1692 host_impl().active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 1,
1795 Layer::INVALID_ID); 1693 Layer::INVALID_ID);
1796 host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting(); 1694 host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
1797 host_impl().active_tree()->PushPageScaleFromMainThread( 1695 host_impl().active_tree()->PushPageScaleFromMainThread(
1798 page_scale_factor, page_scale_factor, max_page_scale_factor); 1696 page_scale_factor, page_scale_factor, max_page_scale_factor);
1799 host_impl().active_tree()->SetPageScaleOnActiveTree(page_scale_factor); 1697 host_impl().active_tree()->SetPageScaleOnActiveTree(page_scale_factor);
1800 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 1698 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1801 1699
1802 // Sanity check the scenario we just created. 1700 // Sanity check the scenario we just created.
1803 ASSERT_EQ(2u, RenderSurfaceLayerList().size()); 1701 ASSERT_EQ(2u, RenderSurfaceLayerList().size());
(...skipping 18 matching lines...) Expand all
1822 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1720 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1823 test_point); 1721 test_point);
1824 ASSERT_TRUE(result_layer); 1722 ASSERT_TRUE(result_layer);
1825 EXPECT_EQ(456, result_layer->id()); 1723 EXPECT_EQ(456, result_layer->id());
1826 } 1724 }
1827 1725
1828 TEST_F(LayerTreeImplTest, HitCheckingTouchHandlerOverlappingRegions) { 1726 TEST_F(LayerTreeImplTest, HitCheckingTouchHandlerOverlappingRegions) {
1829 gfx::Transform identity_matrix; 1727 gfx::Transform identity_matrix;
1830 gfx::Point3F transform_origin; 1728 gfx::Point3F transform_origin;
1831 1729
1832 std::unique_ptr<LayerImpl> root = 1730 LayerImpl* root = root_layer();
1833 LayerImpl::Create(host_impl().active_tree(), 1);
1834 root->SetBounds(gfx::Size(100, 100)); 1731 root->SetBounds(gfx::Size(100, 100));
1835 { 1732 {
1836 std::unique_ptr<LayerImpl> touch_layer = 1733 std::unique_ptr<LayerImpl> touch_layer =
1837 LayerImpl::Create(host_impl().active_tree(), 123); 1734 LayerImpl::Create(host_impl().active_tree(), 123);
1838 // this layer is positioned, and hit testing should correctly know where the 1735 // this layer is positioned, and hit testing should correctly know where the
1839 // layer is located. 1736 // layer is located.
1840 touch_layer->SetBounds(gfx::Size(50, 50)); 1737 touch_layer->SetBounds(gfx::Size(50, 50));
1841 touch_layer->SetDrawsContent(true); 1738 touch_layer->SetDrawsContent(true);
1842 touch_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50)); 1739 touch_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50));
1843 root->test_properties()->AddChild(std::move(touch_layer)); 1740 root->test_properties()->AddChild(std::move(touch_layer));
1844 } 1741 }
1845 1742
1846 { 1743 {
1847 std::unique_ptr<LayerImpl> notouch_layer = 1744 std::unique_ptr<LayerImpl> notouch_layer =
1848 LayerImpl::Create(host_impl().active_tree(), 1234); 1745 LayerImpl::Create(host_impl().active_tree(), 1234);
1849 // this layer is positioned, and hit testing should correctly know where the 1746 // this layer is positioned, and hit testing should correctly know where the
1850 // layer is located. 1747 // layer is located.
1851 notouch_layer->SetPosition(gfx::PointF(0, 25)); 1748 notouch_layer->SetPosition(gfx::PointF(0, 25));
1852 notouch_layer->SetBounds(gfx::Size(50, 50)); 1749 notouch_layer->SetBounds(gfx::Size(50, 50));
1853 notouch_layer->SetDrawsContent(true); 1750 notouch_layer->SetDrawsContent(true);
1854 root->test_properties()->AddChild(std::move(notouch_layer)); 1751 root->test_properties()->AddChild(std::move(notouch_layer));
1855 } 1752 }
1856 1753
1857 host_impl().SetViewportSize(root->bounds()); 1754 host_impl().SetViewportSize(root->bounds());
1858 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
1859 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 1755 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1860 1756
1861 // Sanity check the scenario we just created. 1757 // Sanity check the scenario we just created.
1862 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 1758 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1863 ASSERT_EQ(2u, root_layer()->render_surface()->layer_list().size()); 1759 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
1864 ASSERT_EQ(123, root_layer()->render_surface()->layer_list().at(0)->id()); 1760 ASSERT_EQ(123, root->render_surface()->layer_list().at(0)->id());
1865 ASSERT_EQ(1234, root_layer()->render_surface()->layer_list().at(1)->id()); 1761 ASSERT_EQ(1234, root->render_surface()->layer_list().at(1)->id());
1866 1762
1867 gfx::PointF test_point(35.f, 35.f); 1763 gfx::PointF test_point(35.f, 35.f);
1868 LayerImpl* result_layer = 1764 LayerImpl* result_layer =
1869 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1765 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1870 test_point); 1766 test_point);
1871 1767
1872 // We should have passed through the no-touch layer and found the layer 1768 // We should have passed through the no-touch layer and found the layer
1873 // behind it. 1769 // behind it.
1874 EXPECT_TRUE(result_layer); 1770 EXPECT_TRUE(result_layer);
1875 1771
(...skipping 16 matching lines...) Expand all
1892 EXPECT_EQ(123, result_layer->id()); 1788 EXPECT_EQ(123, result_layer->id());
1893 1789
1894 test_point = gfx::PointF(35.f, 65.f); 1790 test_point = gfx::PointF(35.f, 65.f);
1895 result_layer = 1791 result_layer =
1896 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1792 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1897 test_point); 1793 test_point);
1898 EXPECT_FALSE(result_layer); 1794 EXPECT_FALSE(result_layer);
1899 } 1795 }
1900 1796
1901 TEST_F(LayerTreeImplTest, HitTestingTouchHandlerRegionsForLayerThatIsNotDrawn) { 1797 TEST_F(LayerTreeImplTest, HitTestingTouchHandlerRegionsForLayerThatIsNotDrawn) {
1902 std::unique_ptr<LayerImpl> root = 1798 LayerImpl* root = root_layer();
1903 LayerImpl::Create(host_impl().active_tree(), 1);
1904 root->SetBounds(gfx::Size(100, 100)); 1799 root->SetBounds(gfx::Size(100, 100));
1905 root->SetDrawsContent(true); 1800 root->SetDrawsContent(true);
1906 { 1801 {
1907 Region touch_handler_region(gfx::Rect(10, 10, 30, 30)); 1802 Region touch_handler_region(gfx::Rect(10, 10, 30, 30));
1908 std::unique_ptr<LayerImpl> test_layer = 1803 std::unique_ptr<LayerImpl> test_layer =
1909 LayerImpl::Create(host_impl().active_tree(), 12345); 1804 LayerImpl::Create(host_impl().active_tree(), 12345);
1910 test_layer->SetBounds(gfx::Size(50, 50)); 1805 test_layer->SetBounds(gfx::Size(50, 50));
1911 test_layer->SetDrawsContent(false); 1806 test_layer->SetDrawsContent(false);
1912 test_layer->SetTouchEventHandlerRegion(touch_handler_region); 1807 test_layer->SetTouchEventHandlerRegion(touch_handler_region);
1913 root->test_properties()->AddChild(std::move(test_layer)); 1808 root->test_properties()->AddChild(std::move(test_layer));
1914 } 1809 }
1915 host_impl().SetViewportSize(root->bounds()); 1810 host_impl().SetViewportSize(root->bounds());
1916 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
1917 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 1811 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1918 1812
1919 LayerImpl* test_layer = host_impl() 1813 LayerImpl* test_layer = root->test_properties()->children[0];
1920 .active_tree()
1921 ->root_layer_for_testing()
1922 ->test_properties()
1923 ->children[0];
1924 // As test_layer doesn't draw content, the layer list of root's render surface 1814 // As test_layer doesn't draw content, the layer list of root's render surface
1925 // should contain only the root layer. 1815 // should contain only the root layer.
1926 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 1816 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1927 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); 1817 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
1928 1818
1929 // Hit testing for a point outside the test layer should return null pointer. 1819 // Hit testing for a point outside the test layer should return null pointer.
1930 // We also implicitly check that the updated screen space transform of a layer 1820 // We also implicitly check that the updated screen space transform of a layer
1931 // that is not in drawn render surface layer list (test_layer) is used during 1821 // that is not in drawn render surface layer list (test_layer) is used during
1932 // hit testing (becuase the point is inside test_layer with respect to the old 1822 // hit testing (becuase the point is inside test_layer with respect to the old
1933 // screen space transform). 1823 // screen space transform).
1934 gfx::PointF test_point(24.f, 24.f); 1824 gfx::PointF test_point(24.f, 24.f);
1935 test_layer->SetPosition(gfx::PointF(25.f, 25.f)); 1825 test_layer->SetPosition(gfx::PointF(25.f, 25.f));
1936 gfx::Transform expected_screen_space_transform; 1826 gfx::Transform expected_screen_space_transform;
1937 expected_screen_space_transform.Translate(25.f, 25.f); 1827 expected_screen_space_transform.Translate(25.f, 25.f);
1938 1828
1939 host_impl().active_tree()->property_trees()->needs_rebuild = true; 1829 host_impl().active_tree()->property_trees()->needs_rebuild = true;
1940 host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting(); 1830 host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
1941 LayerImpl* result_layer = 1831 LayerImpl* result_layer =
1942 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1832 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1943 test_point); 1833 test_point);
1944 EXPECT_FALSE(result_layer); 1834 EXPECT_FALSE(result_layer);
1945 EXPECT_FALSE(test_layer->is_drawn_render_surface_layer_list_member()); 1835 EXPECT_FALSE(test_layer->is_drawn_render_surface_layer_list_member());
1946 EXPECT_TRANSFORMATION_MATRIX_EQ( 1836 EXPECT_TRANSFORMATION_MATRIX_EQ(
1947 expected_screen_space_transform, 1837 expected_screen_space_transform,
1948 draw_property_utils::ScreenSpaceTransform( 1838 draw_property_utils::ScreenSpaceTransform(
1949 test_layer, 1839 test_layer,
1950 host_impl().active_tree()->property_trees()->transform_tree)); 1840 host_impl().active_tree()->property_trees()->transform_tree));
1951 1841
1952 // We change the position of the test layer such that the test point is now 1842 // We change the position of the test layer such that the test point is now
1953 // inside the test_layer. 1843 // inside the test_layer.
1954 test_layer = host_impl() 1844 test_layer = root->test_properties()->children[0];
1955 .active_tree()
1956 ->root_layer_for_testing()
1957 ->test_properties()
1958 ->children[0];
1959 test_layer->SetPosition(gfx::PointF(10.f, 10.f)); 1845 test_layer->SetPosition(gfx::PointF(10.f, 10.f));
1960 test_layer->NoteLayerPropertyChanged(); 1846 test_layer->NoteLayerPropertyChanged();
1961 expected_screen_space_transform.MakeIdentity(); 1847 expected_screen_space_transform.MakeIdentity();
1962 expected_screen_space_transform.Translate(10.f, 10.f); 1848 expected_screen_space_transform.Translate(10.f, 10.f);
1963 1849
1964 host_impl().active_tree()->property_trees()->needs_rebuild = true; 1850 host_impl().active_tree()->property_trees()->needs_rebuild = true;
1965 host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting(); 1851 host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
1966 result_layer = 1852 result_layer =
1967 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion( 1853 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1968 test_point); 1854 test_point);
1969 ASSERT_TRUE(result_layer); 1855 ASSERT_TRUE(result_layer);
1970 ASSERT_EQ(test_layer, result_layer); 1856 ASSERT_EQ(test_layer, result_layer);
1971 EXPECT_FALSE(result_layer->is_drawn_render_surface_layer_list_member()); 1857 EXPECT_FALSE(result_layer->is_drawn_render_surface_layer_list_member());
1972 EXPECT_TRANSFORMATION_MATRIX_EQ( 1858 EXPECT_TRANSFORMATION_MATRIX_EQ(
1973 expected_screen_space_transform, 1859 expected_screen_space_transform,
1974 draw_property_utils::ScreenSpaceTransform( 1860 draw_property_utils::ScreenSpaceTransform(
1975 test_layer, 1861 test_layer,
1976 host_impl().active_tree()->property_trees()->transform_tree)); 1862 host_impl().active_tree()->property_trees()->transform_tree));
1977 } 1863 }
1978 1864
1979 TEST_F(LayerTreeImplTest, SelectionBoundsForSingleLayer) { 1865 TEST_F(LayerTreeImplTest, SelectionBoundsForSingleLayer) {
1980 int root_layer_id = 12345; 1866 LayerImpl* root = root_layer();
1981 std::unique_ptr<LayerImpl> root =
1982 LayerImpl::Create(host_impl().active_tree(), root_layer_id);
1983 root->SetBounds(gfx::Size(100, 100)); 1867 root->SetBounds(gfx::Size(100, 100));
1984 root->SetDrawsContent(true); 1868 root->SetDrawsContent(true);
1985 1869
1986 host_impl().SetViewportSize(root->bounds()); 1870 host_impl().SetViewportSize(root->bounds());
1987 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
1988 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 1871 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1989 1872
1990 // Sanity check the scenario we just created. 1873 // Sanity check the scenario we just created.
1991 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 1874 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1992 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size()); 1875 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
1993 1876
1994 LayerSelection input; 1877 LayerSelection input;
1995 1878
1996 input.start.type = gfx::SelectionBound::LEFT; 1879 input.start.type = gfx::SelectionBound::LEFT;
1997 input.start.edge_top = gfx::Point(10, 10); 1880 input.start.edge_top = gfx::Point(10, 10);
1998 input.start.edge_bottom = gfx::Point(10, 20); 1881 input.start.edge_bottom = gfx::Point(10, 20);
1999 input.start.layer_id = root_layer_id; 1882 input.start.layer_id = root->id();
2000 1883
2001 input.end.type = gfx::SelectionBound::RIGHT; 1884 input.end.type = gfx::SelectionBound::RIGHT;
2002 input.end.edge_top = gfx::Point(50, 10); 1885 input.end.edge_top = gfx::Point(50, 10);
2003 input.end.edge_bottom = gfx::Point(50, 30); 1886 input.end.edge_bottom = gfx::Point(50, 30);
2004 input.end.layer_id = root_layer_id; 1887 input.end.layer_id = root->id();
2005 1888
2006 Selection<gfx::SelectionBound> output; 1889 Selection<gfx::SelectionBound> output;
2007 1890
2008 // Empty input bounds should produce empty output bounds. 1891 // Empty input bounds should produce empty output bounds.
2009 host_impl().active_tree()->GetViewportSelection(&output); 1892 host_impl().active_tree()->GetViewportSelection(&output);
2010 EXPECT_EQ(gfx::SelectionBound(), output.start); 1893 EXPECT_EQ(gfx::SelectionBound(), output.start);
2011 EXPECT_EQ(gfx::SelectionBound(), output.end); 1894 EXPECT_EQ(gfx::SelectionBound(), output.end);
2012 1895
2013 // Selection bounds should produce distinct left and right bounds. 1896 // Selection bounds should produce distinct left and right bounds.
2014 host_impl().active_tree()->RegisterSelection(input); 1897 host_impl().active_tree()->RegisterSelection(input);
2015 host_impl().active_tree()->GetViewportSelection(&output); 1898 host_impl().active_tree()->GetViewportSelection(&output);
2016 EXPECT_EQ(input.start.type, output.start.type()); 1899 EXPECT_EQ(input.start.type, output.start.type());
2017 EXPECT_EQ(gfx::PointF(input.start.edge_bottom), output.start.edge_bottom()); 1900 EXPECT_EQ(gfx::PointF(input.start.edge_bottom), output.start.edge_bottom());
2018 EXPECT_EQ(gfx::PointF(input.start.edge_top), output.start.edge_top()); 1901 EXPECT_EQ(gfx::PointF(input.start.edge_top), output.start.edge_top());
2019 EXPECT_TRUE(output.start.visible()); 1902 EXPECT_TRUE(output.start.visible());
2020 EXPECT_EQ(input.end.type, output.end.type()); 1903 EXPECT_EQ(input.end.type, output.end.type());
2021 EXPECT_EQ(gfx::PointF(input.end.edge_bottom), output.end.edge_bottom()); 1904 EXPECT_EQ(gfx::PointF(input.end.edge_bottom), output.end.edge_bottom());
2022 EXPECT_EQ(gfx::PointF(input.end.edge_top), output.end.edge_top()); 1905 EXPECT_EQ(gfx::PointF(input.end.edge_top), output.end.edge_top());
2023 EXPECT_TRUE(output.end.visible()); 1906 EXPECT_TRUE(output.end.visible());
2024 EXPECT_EQ(input.is_editable, output.is_editable); 1907 EXPECT_EQ(input.is_editable, output.is_editable);
2025 EXPECT_EQ(input.is_empty_text_form_control, 1908 EXPECT_EQ(input.is_empty_text_form_control,
2026 output.is_empty_text_form_control); 1909 output.is_empty_text_form_control);
2027 1910
2028 // Insertion bounds should produce identical left and right bounds. 1911 // Insertion bounds should produce identical left and right bounds.
2029 LayerSelection insertion_input; 1912 LayerSelection insertion_input;
2030 insertion_input.start.type = gfx::SelectionBound::CENTER; 1913 insertion_input.start.type = gfx::SelectionBound::CENTER;
2031 insertion_input.start.edge_top = gfx::Point(15, 10); 1914 insertion_input.start.edge_top = gfx::Point(15, 10);
2032 insertion_input.start.edge_bottom = gfx::Point(15, 30); 1915 insertion_input.start.edge_bottom = gfx::Point(15, 30);
2033 insertion_input.start.layer_id = root_layer_id; 1916 insertion_input.start.layer_id = root->id();
2034 insertion_input.is_editable = true; 1917 insertion_input.is_editable = true;
2035 insertion_input.is_empty_text_form_control = true; 1918 insertion_input.is_empty_text_form_control = true;
2036 insertion_input.end = insertion_input.start; 1919 insertion_input.end = insertion_input.start;
2037 host_impl().active_tree()->RegisterSelection(insertion_input); 1920 host_impl().active_tree()->RegisterSelection(insertion_input);
2038 host_impl().active_tree()->GetViewportSelection(&output); 1921 host_impl().active_tree()->GetViewportSelection(&output);
2039 EXPECT_EQ(insertion_input.start.type, output.start.type()); 1922 EXPECT_EQ(insertion_input.start.type, output.start.type());
2040 EXPECT_EQ(gfx::PointF(insertion_input.start.edge_bottom), 1923 EXPECT_EQ(gfx::PointF(insertion_input.start.edge_bottom),
2041 output.start.edge_bottom()); 1924 output.start.edge_bottom());
2042 EXPECT_EQ(gfx::PointF(insertion_input.start.edge_top), 1925 EXPECT_EQ(gfx::PointF(insertion_input.start.edge_top),
2043 output.start.edge_top()); 1926 output.start.edge_top());
2044 EXPECT_EQ(insertion_input.is_editable, output.is_editable); 1927 EXPECT_EQ(insertion_input.is_editable, output.is_editable);
2045 EXPECT_EQ(insertion_input.is_empty_text_form_control, 1928 EXPECT_EQ(insertion_input.is_empty_text_form_control,
2046 output.is_empty_text_form_control); 1929 output.is_empty_text_form_control);
2047 EXPECT_TRUE(output.start.visible()); 1930 EXPECT_TRUE(output.start.visible());
2048 EXPECT_EQ(output.start, output.end); 1931 EXPECT_EQ(output.start, output.end);
2049 } 1932 }
2050 1933
2051 TEST_F(LayerTreeImplTest, SelectionBoundsForPartialOccludedLayers) { 1934 TEST_F(LayerTreeImplTest, SelectionBoundsForPartialOccludedLayers) {
2052 int root_layer_id = 12345; 1935 LayerImpl* root = root_layer();
1936 root->SetDrawsContent(true);
1937 root->SetBounds(gfx::Size(100, 100));
1938
2053 int clip_layer_id = 1234; 1939 int clip_layer_id = 1234;
2054 int clipped_layer_id = 123; 1940 int clipped_layer_id = 123;
2055 std::unique_ptr<LayerImpl> root =
2056 LayerImpl::Create(host_impl().active_tree(), root_layer_id);
2057 root->SetDrawsContent(true);
2058 root->SetBounds(gfx::Size(100, 100));
2059 1941
2060 gfx::Vector2dF clipping_offset(10, 10); 1942 gfx::Vector2dF clipping_offset(10, 10);
2061 { 1943 {
2062 std::unique_ptr<LayerImpl> clipping_layer = 1944 std::unique_ptr<LayerImpl> clipping_layer =
2063 LayerImpl::Create(host_impl().active_tree(), clip_layer_id); 1945 LayerImpl::Create(host_impl().active_tree(), clip_layer_id);
2064 // The clipping layer should occlude the right selection bound. 1946 // The clipping layer should occlude the right selection bound.
2065 clipping_layer->SetPosition(gfx::PointF() + clipping_offset); 1947 clipping_layer->SetPosition(gfx::PointF() + clipping_offset);
2066 clipping_layer->SetBounds(gfx::Size(50, 50)); 1948 clipping_layer->SetBounds(gfx::Size(50, 50));
2067 clipping_layer->SetMasksToBounds(true); 1949 clipping_layer->SetMasksToBounds(true);
2068 1950
2069 std::unique_ptr<LayerImpl> clipped_layer = 1951 std::unique_ptr<LayerImpl> clipped_layer =
2070 LayerImpl::Create(host_impl().active_tree(), clipped_layer_id); 1952 LayerImpl::Create(host_impl().active_tree(), clipped_layer_id);
2071 clipped_layer->SetBounds(gfx::Size(100, 100)); 1953 clipped_layer->SetBounds(gfx::Size(100, 100));
2072 clipped_layer->SetDrawsContent(true); 1954 clipped_layer->SetDrawsContent(true);
2073 clipping_layer->test_properties()->AddChild(std::move(clipped_layer)); 1955 clipping_layer->test_properties()->AddChild(std::move(clipped_layer));
2074 root->test_properties()->AddChild(std::move(clipping_layer)); 1956 root->test_properties()->AddChild(std::move(clipping_layer));
2075 } 1957 }
2076 1958
2077 host_impl().SetViewportSize(root->bounds()); 1959 host_impl().SetViewportSize(root->bounds());
2078 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
2079 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 1960 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
2080 1961
2081 // Sanity check the scenario we just created. 1962 // Sanity check the scenario we just created.
2082 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 1963 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
2083 1964
2084 LayerSelection input; 1965 LayerSelection input;
2085 input.start.type = gfx::SelectionBound::LEFT; 1966 input.start.type = gfx::SelectionBound::LEFT;
2086 input.start.edge_top = gfx::Point(25, 10); 1967 input.start.edge_top = gfx::Point(25, 10);
2087 input.start.edge_bottom = gfx::Point(25, 30); 1968 input.start.edge_bottom = gfx::Point(25, 30);
2088 input.start.layer_id = clipped_layer_id; 1969 input.start.layer_id = clipped_layer_id;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 2009
2129 // If the handle bottom is partially visible, the handle is marked visible. 2010 // If the handle bottom is partially visible, the handle is marked visible.
2130 input.start.edge_top = gfx::Point(0, -20); 2011 input.start.edge_top = gfx::Point(0, -20);
2131 input.start.edge_bottom = gfx::Point(0, 1); 2012 input.start.edge_bottom = gfx::Point(0, 1);
2132 host_impl().active_tree()->RegisterSelection(input); 2013 host_impl().active_tree()->RegisterSelection(input);
2133 host_impl().active_tree()->GetViewportSelection(&output); 2014 host_impl().active_tree()->GetViewportSelection(&output);
2134 EXPECT_TRUE(output.start.visible()); 2015 EXPECT_TRUE(output.start.visible());
2135 } 2016 }
2136 2017
2137 TEST_F(LayerTreeImplTest, SelectionBoundsForScaledLayers) { 2018 TEST_F(LayerTreeImplTest, SelectionBoundsForScaledLayers) {
2138 int root_layer_id = 1; 2019 LayerImpl* root = root_layer();
2139 int sub_layer_id = 2;
2140 std::unique_ptr<LayerImpl> root =
2141 LayerImpl::Create(host_impl().active_tree(), root_layer_id);
2142 root->SetDrawsContent(true); 2020 root->SetDrawsContent(true);
2143 root->SetBounds(gfx::Size(100, 100)); 2021 root->SetBounds(gfx::Size(100, 100));
2144 2022
2023 int root_layer_id = root->id();
2024 int sub_layer_id = 2;
2025
2145 gfx::Vector2dF sub_layer_offset(10, 0); 2026 gfx::Vector2dF sub_layer_offset(10, 0);
2146 { 2027 {
2147 std::unique_ptr<LayerImpl> sub_layer = 2028 std::unique_ptr<LayerImpl> sub_layer =
2148 LayerImpl::Create(host_impl().active_tree(), sub_layer_id); 2029 LayerImpl::Create(host_impl().active_tree(), sub_layer_id);
2149 sub_layer->SetPosition(gfx::PointF() + sub_layer_offset); 2030 sub_layer->SetPosition(gfx::PointF() + sub_layer_offset);
2150 sub_layer->SetBounds(gfx::Size(50, 50)); 2031 sub_layer->SetBounds(gfx::Size(50, 50));
2151 sub_layer->SetDrawsContent(true); 2032 sub_layer->SetDrawsContent(true);
2152 root->test_properties()->AddChild(std::move(sub_layer)); 2033 root->test_properties()->AddChild(std::move(sub_layer));
2153 } 2034 }
2154 2035
2036 host_impl().active_tree()->BuildPropertyTreesForTesting();
2037
2155 float device_scale_factor = 3.f; 2038 float device_scale_factor = 3.f;
2156 float page_scale_factor = 5.f; 2039 float page_scale_factor = 5.f;
2157 gfx::Size scaled_bounds_for_root = gfx::ScaleToCeiledSize( 2040 gfx::Size scaled_bounds_for_root = gfx::ScaleToCeiledSize(
2158 root->bounds(), device_scale_factor * page_scale_factor); 2041 root->bounds(), device_scale_factor * page_scale_factor);
2159 host_impl().SetViewportSize(scaled_bounds_for_root); 2042 host_impl().SetViewportSize(scaled_bounds_for_root);
2160 2043
2044 host_impl().active_tree()->SetViewportLayersFromIds(0, root->id(), 0, 0);
2161 host_impl().active_tree()->SetDeviceScaleFactor(device_scale_factor); 2045 host_impl().active_tree()->SetDeviceScaleFactor(device_scale_factor);
2162 host_impl().active_tree()->SetPageScaleOnActiveTree(page_scale_factor); 2046 host_impl().active_tree()->SetPageScaleOnActiveTree(page_scale_factor);
2163 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
2164 host_impl().active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 1, 2047 host_impl().active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 1,
2165 Layer::INVALID_ID); 2048 Layer::INVALID_ID);
2166 host_impl().active_tree()->BuildLayerListAndPropertyTreesForTesting();
2167 host_impl().active_tree()->PushPageScaleFromMainThread( 2049 host_impl().active_tree()->PushPageScaleFromMainThread(
2168 page_scale_factor, page_scale_factor, page_scale_factor); 2050 page_scale_factor, page_scale_factor, page_scale_factor);
2169 host_impl().active_tree()->SetPageScaleOnActiveTree(page_scale_factor); 2051 host_impl().active_tree()->SetPageScaleOnActiveTree(page_scale_factor);
2170 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 2052 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
2171 2053
2172 // Sanity check the scenario we just created. 2054 // Sanity check the scenario we just created.
2173 ASSERT_EQ(1u, RenderSurfaceLayerList().size()); 2055 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
2174 2056
2175 LayerSelection input; 2057 LayerSelection input;
2176 input.start.type = gfx::SelectionBound::LEFT; 2058 input.start.type = gfx::SelectionBound::LEFT;
(...skipping 26 matching lines...) Expand all
2203 expected_output_end_top.Offset(sub_layer_offset.x(), sub_layer_offset.y()); 2085 expected_output_end_top.Offset(sub_layer_offset.x(), sub_layer_offset.y());
2204 expected_output_end_bottom.Offset(sub_layer_offset.x(), sub_layer_offset.y()); 2086 expected_output_end_bottom.Offset(sub_layer_offset.x(), sub_layer_offset.y());
2205 expected_output_end_top.Scale(page_scale_factor); 2087 expected_output_end_top.Scale(page_scale_factor);
2206 expected_output_end_bottom.Scale(page_scale_factor); 2088 expected_output_end_bottom.Scale(page_scale_factor);
2207 EXPECT_EQ(expected_output_end_top, output.end.edge_top()); 2089 EXPECT_EQ(expected_output_end_top, output.end.edge_top());
2208 EXPECT_EQ(expected_output_end_bottom, output.end.edge_bottom()); 2090 EXPECT_EQ(expected_output_end_bottom, output.end.edge_bottom());
2209 EXPECT_TRUE(output.end.visible()); 2091 EXPECT_TRUE(output.end.visible());
2210 } 2092 }
2211 2093
2212 TEST_F(LayerTreeImplTest, SelectionBoundsWithLargeTransforms) { 2094 TEST_F(LayerTreeImplTest, SelectionBoundsWithLargeTransforms) {
2213 int root_id = 1; 2095 LayerImpl* root = root_layer();
2096 root->SetBounds(gfx::Size(100, 100));
2097
2214 int child_id = 2; 2098 int child_id = 2;
2215 int grand_child_id = 3; 2099 int grand_child_id = 3;
2216 2100
2217 std::unique_ptr<LayerImpl> root =
2218 LayerImpl::Create(host_impl().active_tree(), root_id);
2219 root->SetBounds(gfx::Size(100, 100));
2220
2221 gfx::Transform large_transform; 2101 gfx::Transform large_transform;
2222 large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37)); 2102 large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37));
2223 large_transform.RotateAboutYAxis(30); 2103 large_transform.RotateAboutYAxis(30);
2224 2104
2225 { 2105 {
2226 std::unique_ptr<LayerImpl> child = 2106 std::unique_ptr<LayerImpl> child =
2227 LayerImpl::Create(host_impl().active_tree(), child_id); 2107 LayerImpl::Create(host_impl().active_tree(), child_id);
2228 child->SetTransform(large_transform); 2108 child->SetTransform(large_transform);
2229 child->SetBounds(gfx::Size(100, 100)); 2109 child->SetBounds(gfx::Size(100, 100));
2230 2110
2231 std::unique_ptr<LayerImpl> grand_child = 2111 std::unique_ptr<LayerImpl> grand_child =
2232 LayerImpl::Create(host_impl().active_tree(), grand_child_id); 2112 LayerImpl::Create(host_impl().active_tree(), grand_child_id);
2233 grand_child->SetTransform(large_transform); 2113 grand_child->SetTransform(large_transform);
2234 grand_child->SetBounds(gfx::Size(100, 100)); 2114 grand_child->SetBounds(gfx::Size(100, 100));
2235 grand_child->SetDrawsContent(true); 2115 grand_child->SetDrawsContent(true);
2236 2116
2237 child->test_properties()->AddChild(std::move(grand_child)); 2117 child->test_properties()->AddChild(std::move(grand_child));
2238 root->test_properties()->AddChild(std::move(child)); 2118 root->test_properties()->AddChild(std::move(child));
2239 } 2119 }
2240 2120
2241 host_impl().SetViewportSize(root->bounds()); 2121 host_impl().SetViewportSize(root->bounds());
2242 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
2243 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 2122 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
2244 2123
2245 LayerSelection input; 2124 LayerSelection input;
2246 2125
2247 input.start.type = gfx::SelectionBound::LEFT; 2126 input.start.type = gfx::SelectionBound::LEFT;
2248 input.start.edge_top = gfx::Point(10, 10); 2127 input.start.edge_top = gfx::Point(10, 10);
2249 input.start.edge_bottom = gfx::Point(10, 20); 2128 input.start.edge_bottom = gfx::Point(10, 20);
2250 input.start.layer_id = grand_child_id; 2129 input.start.layer_id = grand_child_id;
2251 2130
2252 input.end.type = gfx::SelectionBound::RIGHT; 2131 input.end.type = gfx::SelectionBound::RIGHT;
2253 input.end.edge_top = gfx::Point(50, 10); 2132 input.end.edge_top = gfx::Point(50, 10);
2254 input.end.edge_bottom = gfx::Point(50, 30); 2133 input.end.edge_bottom = gfx::Point(50, 30);
2255 input.end.layer_id = grand_child_id; 2134 input.end.layer_id = grand_child_id;
2256 2135
2257 host_impl().active_tree()->RegisterSelection(input); 2136 host_impl().active_tree()->RegisterSelection(input);
2258 2137
2259 Selection<gfx::SelectionBound> output; 2138 Selection<gfx::SelectionBound> output;
2260 host_impl().active_tree()->GetViewportSelection(&output); 2139 host_impl().active_tree()->GetViewportSelection(&output);
2261 2140
2262 // edge_bottom and edge_top aren't allowed to have NaNs, so the selection 2141 // edge_bottom and edge_top aren't allowed to have NaNs, so the selection
2263 // should be empty. 2142 // should be empty.
2264 EXPECT_EQ(gfx::SelectionBound(), output.start); 2143 EXPECT_EQ(gfx::SelectionBound(), output.start);
2265 EXPECT_EQ(gfx::SelectionBound(), output.end); 2144 EXPECT_EQ(gfx::SelectionBound(), output.end);
2266 } 2145 }
2267 2146
2268 TEST_F(LayerTreeImplTest, NumLayersTestOne) { 2147 TEST_F(LayerTreeImplTest, NumLayersTestOne) {
2269 EXPECT_EQ(0u, host_impl().active_tree()->NumLayers()); 2148 // Root is created by the test harness.
2270 std::unique_ptr<LayerImpl> root =
2271 LayerImpl::Create(host_impl().active_tree(), 1);
2272 EXPECT_EQ(1u, host_impl().active_tree()->NumLayers()); 2149 EXPECT_EQ(1u, host_impl().active_tree()->NumLayers());
2150 EXPECT_TRUE(root_layer());
2151 // Create another layer, should increment.
2152 auto layer = LayerImpl::Create(host_impl().active_tree(), 2);
2153 EXPECT_EQ(2u, host_impl().active_tree()->NumLayers());
2273 } 2154 }
2274 2155
2275 TEST_F(LayerTreeImplTest, NumLayersSmallTree) { 2156 TEST_F(LayerTreeImplTest, NumLayersSmallTree) {
2276 EXPECT_EQ(0u, host_impl().active_tree()->NumLayers()); 2157 EXPECT_EQ(1u, host_impl().active_tree()->NumLayers());
2277 std::unique_ptr<LayerImpl> root = 2158 LayerImpl* root = root_layer();
2278 LayerImpl::Create(host_impl().active_tree(), 1);
2279 root->test_properties()->AddChild( 2159 root->test_properties()->AddChild(
2280 LayerImpl::Create(host_impl().active_tree(), 2)); 2160 LayerImpl::Create(host_impl().active_tree(), 2));
2281 root->test_properties()->AddChild( 2161 root->test_properties()->AddChild(
2282 LayerImpl::Create(host_impl().active_tree(), 3)); 2162 LayerImpl::Create(host_impl().active_tree(), 3));
2283 root->test_properties()->children[1]->test_properties()->AddChild( 2163 root->test_properties()->children[1]->test_properties()->AddChild(
2284 LayerImpl::Create(host_impl().active_tree(), 4)); 2164 LayerImpl::Create(host_impl().active_tree(), 4));
2285 EXPECT_EQ(4u, host_impl().active_tree()->NumLayers()); 2165 EXPECT_EQ(4u, host_impl().active_tree()->NumLayers());
2286 } 2166 }
2287 2167
2288 TEST_F(LayerTreeImplTest, DeviceScaleFactorNeedsDrawPropertiesUpdate) { 2168 TEST_F(LayerTreeImplTest, DeviceScaleFactorNeedsDrawPropertiesUpdate) {
2169 host_impl().active_tree()->BuildPropertyTreesForTesting();
2289 host_impl().active_tree()->SetDeviceScaleFactor(1.f); 2170 host_impl().active_tree()->SetDeviceScaleFactor(1.f);
2290 host_impl().active_tree()->UpdateDrawProperties(false); 2171 host_impl().active_tree()->UpdateDrawProperties(false);
2291 EXPECT_FALSE(host_impl().active_tree()->needs_update_draw_properties()); 2172 EXPECT_FALSE(host_impl().active_tree()->needs_update_draw_properties());
2292 host_impl().active_tree()->SetDeviceScaleFactor(2.f); 2173 host_impl().active_tree()->SetDeviceScaleFactor(2.f);
2293 EXPECT_TRUE(host_impl().active_tree()->needs_update_draw_properties()); 2174 EXPECT_TRUE(host_impl().active_tree()->needs_update_draw_properties());
2294 } 2175 }
2295 2176
2296 TEST_F(LayerTreeImplTest, HitTestingCorrectLayerWheelListener) { 2177 TEST_F(LayerTreeImplTest, HitTestingCorrectLayerWheelListener) {
2297 host_impl().active_tree()->set_event_listener_properties( 2178 host_impl().active_tree()->set_event_listener_properties(
2298 EventListenerClass::kMouseWheel, EventListenerProperties::kBlocking); 2179 EventListenerClass::kMouseWheel, EventListenerProperties::kBlocking);
2299 std::unique_ptr<LayerImpl> root = 2180
2300 LayerImpl::Create(host_impl().active_tree(), 1); 2181 LayerImpl* root = root_layer();
2301 std::unique_ptr<LayerImpl> left_child = 2182 std::unique_ptr<LayerImpl> left_child =
2302 LayerImpl::Create(host_impl().active_tree(), 2); 2183 LayerImpl::Create(host_impl().active_tree(), 2);
2303 std::unique_ptr<LayerImpl> right_child = 2184 std::unique_ptr<LayerImpl> right_child =
2304 LayerImpl::Create(host_impl().active_tree(), 3); 2185 LayerImpl::Create(host_impl().active_tree(), 3);
2305 2186
2306 { 2187 {
2307 gfx::Transform translate_z; 2188 gfx::Transform translate_z;
2308 translate_z.Translate3d(0, 0, 10); 2189 translate_z.Translate3d(0, 0, 10);
2309 root->SetTransform(translate_z); 2190 root->SetTransform(translate_z);
2310 root->SetBounds(gfx::Size(100, 100)); 2191 root->SetBounds(gfx::Size(100, 100));
(...skipping 10 matching lines...) Expand all
2321 gfx::Transform translate_z; 2202 gfx::Transform translate_z;
2322 translate_z.Translate3d(0, 0, 10); 2203 translate_z.Translate3d(0, 0, 10);
2323 right_child->SetTransform(translate_z); 2204 right_child->SetTransform(translate_z);
2324 right_child->SetBounds(gfx::Size(100, 100)); 2205 right_child->SetBounds(gfx::Size(100, 100));
2325 } 2206 }
2326 2207
2327 root->test_properties()->AddChild(std::move(left_child)); 2208 root->test_properties()->AddChild(std::move(left_child));
2328 root->test_properties()->AddChild(std::move(right_child)); 2209 root->test_properties()->AddChild(std::move(right_child));
2329 2210
2330 host_impl().SetViewportSize(root->bounds()); 2211 host_impl().SetViewportSize(root->bounds());
2331 host_impl().active_tree()->SetRootLayerForTesting(std::move(root));
2332 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); 2212 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
2333 CHECK_EQ(1u, RenderSurfaceLayerList().size()); 2213 CHECK_EQ(1u, RenderSurfaceLayerList().size());
2334 2214
2335 gfx::PointF test_point = gfx::PointF(1.f, 1.f); 2215 gfx::PointF test_point = gfx::PointF(1.f, 1.f);
2336 LayerImpl* result_layer = 2216 LayerImpl* result_layer =
2337 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 2217 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
2338 2218
2339 CHECK(result_layer); 2219 CHECK(result_layer);
2340 EXPECT_EQ(2, result_layer->id()); 2220 EXPECT_EQ(2, result_layer->id());
2341 } 2221 }
2342 2222
2343 } // namespace 2223 } // namespace
2344 } // namespace cc 2224 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/layer_test_common.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698