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
3 // found in the LICENSE file.
5 #include "cc/trees/layer_tree_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_proxy.h"
11 #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"
14 #include "cc/test/layer_tree_host_common_test.h"
15 #include "cc/test/test_shared_bitmap_manager.h"
16 #include "cc/test/test_task_graph_runner.h"
17 #include "cc/trees/layer_tree_host_impl.h"
18 #include "ui/gfx/geometry/size_conversions.h"
23 class LayerTreeImplTest
: public LayerTreeHostCommonTest
{
26 LayerTreeSettings settings
;
27 settings
.layer_transforms_should_scale_layer_contents
= true;
28 settings
.scrollbar_show_scale_threshold
= 1.1f
;
29 host_impl_
.reset(new FakeLayerTreeHostImpl(
30 settings
, &proxy_
, &shared_bitmap_manager_
, &task_graph_runner_
));
31 EXPECT_TRUE(host_impl_
->InitializeRenderer(FakeOutputSurface::Create3d()));
34 FakeLayerTreeHostImpl
& host_impl() { return *host_impl_
; }
36 LayerImpl
* root_layer() { return host_impl_
->active_tree()->root_layer(); }
38 const LayerImplList
& RenderSurfaceLayerList() const {
39 return host_impl_
->active_tree()->RenderSurfaceLayerList();
43 TestSharedBitmapManager shared_bitmap_manager_
;
44 TestTaskGraphRunner task_graph_runner_
;
46 scoped_ptr
<FakeLayerTreeHostImpl
> host_impl_
;
49 TEST_F(LayerTreeImplTest
, HitTestingForSingleLayer
) {
50 scoped_ptr
<LayerImpl
> root
=
51 LayerImpl::Create(host_impl().active_tree(), 12345);
53 gfx::Transform identity_matrix
;
54 gfx::Point3F transform_origin
;
56 gfx::Size
bounds(100, 100);
57 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
58 position
, bounds
, true, false, true);
59 root
->SetDrawsContent(true);
61 host_impl().SetViewportSize(root
->bounds());
62 host_impl().active_tree()->SetRootLayer(root
.Pass());
63 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
65 // Sanity check the scenario we just created.
66 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
67 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
69 // Hit testing for a point outside the layer should return a null pointer.
70 gfx::Point
test_point(101, 101);
71 LayerImpl
* result_layer
=
72 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
73 EXPECT_FALSE(result_layer
);
75 test_point
= gfx::Point(-1, -1);
77 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
78 EXPECT_FALSE(result_layer
);
80 // Hit testing for a point inside should return the root layer.
81 test_point
= gfx::Point(1, 1);
83 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
84 ASSERT_TRUE(result_layer
);
85 EXPECT_EQ(12345, result_layer
->id());
87 test_point
= gfx::Point(99, 99);
89 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
90 ASSERT_TRUE(result_layer
);
91 EXPECT_EQ(12345, result_layer
->id());
94 TEST_F(LayerTreeImplTest
, HitTestingForSingleLayerAndHud
) {
95 scoped_ptr
<LayerImpl
> root
=
96 LayerImpl::Create(host_impl().active_tree(), 12345);
97 scoped_ptr
<HeadsUpDisplayLayerImpl
> hud
=
98 HeadsUpDisplayLayerImpl::Create(host_impl().active_tree(), 11111);
100 gfx::Transform identity_matrix
;
101 gfx::Point3F transform_origin
;
102 gfx::PointF position
;
103 gfx::Size
bounds(100, 100);
104 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
105 position
, bounds
, true, false, true);
106 root
->SetDrawsContent(true);
108 // Create hud and add it as a child of root.
109 gfx::Size
hud_bounds(200, 200);
110 SetLayerPropertiesForTesting(hud
.get(), identity_matrix
, transform_origin
,
111 position
, hud_bounds
, true, false, false);
112 hud
->SetDrawsContent(true);
114 host_impl().active_tree()->set_hud_layer(hud
.get());
115 root
->AddChild(hud
.Pass());
117 host_impl().SetViewportSize(hud_bounds
);
118 host_impl().active_tree()->SetRootLayer(root
.Pass());
119 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
121 // Sanity check the scenario we just created.
122 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
123 ASSERT_EQ(2u, root_layer()->render_surface()->layer_list().size());
125 // Hit testing for a point inside HUD, but outside root should return null
126 gfx::Point
test_point(101, 101);
127 LayerImpl
* result_layer
=
128 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
129 EXPECT_FALSE(result_layer
);
131 test_point
= gfx::Point(-1, -1);
133 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
134 EXPECT_FALSE(result_layer
);
136 // Hit testing for a point inside should return the root layer, never the HUD
138 test_point
= gfx::Point(1, 1);
140 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
141 ASSERT_TRUE(result_layer
);
142 EXPECT_EQ(12345, result_layer
->id());
144 test_point
= gfx::Point(99, 99);
146 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
147 ASSERT_TRUE(result_layer
);
148 EXPECT_EQ(12345, result_layer
->id());
151 TEST_F(LayerTreeImplTest
, HitTestingForUninvertibleTransform
) {
152 scoped_ptr
<LayerImpl
> root
=
153 LayerImpl::Create(host_impl().active_tree(), 12345);
155 gfx::Transform uninvertible_transform
;
156 uninvertible_transform
.matrix().set(0, 0, 0.0);
157 uninvertible_transform
.matrix().set(1, 1, 0.0);
158 uninvertible_transform
.matrix().set(2, 2, 0.0);
159 uninvertible_transform
.matrix().set(3, 3, 0.0);
160 ASSERT_FALSE(uninvertible_transform
.IsInvertible());
162 gfx::Transform identity_matrix
;
163 gfx::Point3F transform_origin
;
164 gfx::PointF position
;
165 gfx::Size
bounds(100, 100);
166 SetLayerPropertiesForTesting(root
.get(), uninvertible_transform
,
167 transform_origin
, position
, bounds
, true, false,
169 root
->SetDrawsContent(true);
171 host_impl().SetViewportSize(root
->bounds());
172 host_impl().active_tree()->SetRootLayer(root
.Pass());
173 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
174 // Sanity check the scenario we just created.
175 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
176 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
177 ASSERT_FALSE(root_layer()->screen_space_transform().IsInvertible());
179 // Hit testing any point should not hit the layer. If the invertible matrix is
180 // accidentally ignored and treated like an identity, then the hit testing
181 // will incorrectly hit the layer when it shouldn't.
182 gfx::Point
test_point(1, 1);
183 LayerImpl
* result_layer
=
184 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
185 EXPECT_FALSE(result_layer
);
187 test_point
= gfx::Point(10, 10);
189 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
190 EXPECT_FALSE(result_layer
);
192 test_point
= gfx::Point(10, 30);
194 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
195 EXPECT_FALSE(result_layer
);
197 test_point
= gfx::Point(50, 50);
199 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
200 EXPECT_FALSE(result_layer
);
202 test_point
= gfx::Point(67, 48);
204 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
205 EXPECT_FALSE(result_layer
);
207 test_point
= gfx::Point(99, 99);
209 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
210 EXPECT_FALSE(result_layer
);
212 test_point
= gfx::Point(-1, -1);
214 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
215 EXPECT_FALSE(result_layer
);
218 TEST_F(LayerTreeImplTest
, HitTestingForSinglePositionedLayer
) {
219 scoped_ptr
<LayerImpl
> root
=
220 LayerImpl::Create(host_impl().active_tree(), 12345);
222 gfx::Transform identity_matrix
;
223 gfx::Point3F transform_origin
;
224 // this layer is positioned, and hit testing should correctly know where the
226 gfx::PointF
position(50.f
, 50.f
);
227 gfx::Size
bounds(100, 100);
228 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
229 position
, bounds
, true, false, true);
230 root
->SetDrawsContent(true);
232 host_impl().SetViewportSize(root
->bounds());
233 host_impl().active_tree()->SetRootLayer(root
.Pass());
234 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
236 // Sanity check the scenario we just created.
237 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
238 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
240 // Hit testing for a point outside the layer should return a null pointer.
241 gfx::Point
test_point(49, 49);
242 LayerImpl
* result_layer
=
243 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
244 EXPECT_FALSE(result_layer
);
246 // Even though the layer exists at (101, 101), it should not be visible there
247 // since the root render surface would clamp it.
248 test_point
= gfx::Point(101, 101);
250 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
251 EXPECT_FALSE(result_layer
);
253 // Hit testing for a point inside should return the root layer.
254 test_point
= gfx::Point(51, 51);
256 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
257 ASSERT_TRUE(result_layer
);
258 EXPECT_EQ(12345, result_layer
->id());
260 test_point
= gfx::Point(99, 99);
262 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
263 ASSERT_TRUE(result_layer
);
264 EXPECT_EQ(12345, result_layer
->id());
267 TEST_F(LayerTreeImplTest
, HitTestingForSingleRotatedLayer
) {
268 scoped_ptr
<LayerImpl
> root
=
269 LayerImpl::Create(host_impl().active_tree(), 12345);
271 gfx::Transform identity_matrix
;
272 gfx::Transform rotation45_degrees_about_center
;
273 rotation45_degrees_about_center
.Translate(50.0, 50.0);
274 rotation45_degrees_about_center
.RotateAboutZAxis(45.0);
275 rotation45_degrees_about_center
.Translate(-50.0, -50.0);
276 gfx::Point3F transform_origin
;
277 gfx::PointF position
;
278 gfx::Size
bounds(100, 100);
279 SetLayerPropertiesForTesting(root
.get(), rotation45_degrees_about_center
,
280 transform_origin
, position
, bounds
, true, false,
282 root
->SetDrawsContent(true);
284 host_impl().SetViewportSize(root
->bounds());
285 host_impl().active_tree()->SetRootLayer(root
.Pass());
286 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
288 // Sanity check the scenario we just created.
289 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
290 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
292 // Hit testing for points outside the layer.
293 // These corners would have been inside the un-transformed layer, but they
294 // should not hit the correctly transformed layer.
295 gfx::Point
test_point(99, 99);
296 LayerImpl
* result_layer
=
297 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
298 EXPECT_FALSE(result_layer
);
300 test_point
= gfx::Point(1, 1);
302 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
303 EXPECT_FALSE(result_layer
);
305 // Hit testing for a point inside should return the root layer.
306 test_point
= gfx::Point(1, 50);
308 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
309 ASSERT_TRUE(result_layer
);
310 EXPECT_EQ(12345, result_layer
->id());
312 // Hit testing the corners that would overlap the unclipped layer, but are
313 // outside the clipped region.
314 test_point
= gfx::Point(50, -1);
316 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
317 ASSERT_FALSE(result_layer
);
319 test_point
= gfx::Point(-1, 50);
321 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
322 ASSERT_FALSE(result_layer
);
325 TEST_F(LayerTreeImplTest
, HitTestingForSinglePerspectiveLayer
) {
326 scoped_ptr
<LayerImpl
> root
=
327 LayerImpl::Create(host_impl().active_tree(), 12345);
329 gfx::Transform identity_matrix
;
331 // perspective_projection_about_center * translation_by_z is designed so that
332 // the 100 x 100 layer becomes 50 x 50, and remains centered at (50, 50).
333 gfx::Transform perspective_projection_about_center
;
334 perspective_projection_about_center
.Translate(50.0, 50.0);
335 perspective_projection_about_center
.ApplyPerspectiveDepth(1.0);
336 perspective_projection_about_center
.Translate(-50.0, -50.0);
337 gfx::Transform translation_by_z
;
338 translation_by_z
.Translate3d(0.0, 0.0, -1.0);
340 gfx::Point3F transform_origin
;
341 gfx::PointF position
;
342 gfx::Size
bounds(100, 100);
343 SetLayerPropertiesForTesting(
344 root
.get(), perspective_projection_about_center
* translation_by_z
,
345 transform_origin
, position
, bounds
, true, false, true);
346 root
->SetDrawsContent(true);
348 host_impl().SetViewportSize(root
->bounds());
349 host_impl().active_tree()->SetRootLayer(root
.Pass());
350 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
352 // Sanity check the scenario we just created.
353 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
354 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
356 // Hit testing for points outside the layer.
357 // These corners would have been inside the un-transformed layer, but they
358 // should not hit the correctly transformed layer.
359 gfx::Point
test_point(24, 24);
360 LayerImpl
* result_layer
=
361 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
362 EXPECT_FALSE(result_layer
);
364 test_point
= gfx::Point(76, 76);
366 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
367 EXPECT_FALSE(result_layer
);
369 // Hit testing for a point inside should return the root layer.
370 test_point
= gfx::Point(26, 26);
372 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
373 ASSERT_TRUE(result_layer
);
374 EXPECT_EQ(12345, result_layer
->id());
376 test_point
= gfx::Point(74, 74);
378 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
379 ASSERT_TRUE(result_layer
);
380 EXPECT_EQ(12345, result_layer
->id());
383 TEST_F(LayerTreeImplTest
, HitTestingForSingleLayerWithScaledContents
) {
384 // A layer's visible content rect is actually in the layer's content space.
385 // The screen space transform converts from the layer's origin space to screen
386 // space. This test makes sure that hit testing works correctly accounts for
387 // the contents scale. A contents scale that is not 1 effectively forces a
388 // non-identity transform between layer's content space and layer's origin
389 // space. The hit testing code must take this into account.
391 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
392 // contents scale is ignored, then hit testing will mis-interpret the visible
393 // content rect as being larger than the actual bounds of the layer.
395 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl().active_tree(), 1);
397 gfx::Transform identity_matrix
;
398 gfx::Point3F transform_origin
;
400 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
401 gfx::PointF(), gfx::Size(100, 100), true, false,
404 gfx::PointF
position(25.f
, 25.f
);
405 gfx::Size
bounds(50, 50);
406 scoped_ptr
<LayerImpl
> test_layer
=
407 LayerImpl::Create(host_impl().active_tree(), 12345);
408 SetLayerPropertiesForTesting(test_layer
.get(), identity_matrix
,
409 transform_origin
, position
, bounds
, true,
412 // override content bounds and contents scale
413 test_layer
->SetContentBounds(gfx::Size(100, 100));
414 test_layer
->SetContentsScale(2, 2);
416 test_layer
->SetDrawsContent(true);
417 root
->AddChild(test_layer
.Pass());
420 host_impl().SetViewportSize(root
->bounds());
421 host_impl().active_tree()->SetRootLayer(root
.Pass());
422 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
424 // Sanity check the scenario we just created.
425 // The visible content rect for test_layer is actually 100x100, even though
426 // its layout size is 50x50, positioned at 25x25.
427 LayerImpl
* test_layer
=
428 host_impl().active_tree()->root_layer()->children()[0];
429 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), test_layer
->visible_content_rect());
430 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
431 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
433 // Hit testing for a point outside the layer should return a null pointer (the
434 // root layer does not draw content, so it will not be hit tested either).
435 gfx::Point
test_point(101, 101);
436 LayerImpl
* result_layer
=
437 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
438 EXPECT_FALSE(result_layer
);
440 test_point
= gfx::Point(24, 24);
442 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
443 EXPECT_FALSE(result_layer
);
445 test_point
= gfx::Point(76, 76);
447 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
448 EXPECT_FALSE(result_layer
);
450 // Hit testing for a point inside should return the test layer.
451 test_point
= gfx::Point(26, 26);
453 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
454 ASSERT_TRUE(result_layer
);
455 EXPECT_EQ(12345, result_layer
->id());
457 test_point
= gfx::Point(74, 74);
459 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
460 ASSERT_TRUE(result_layer
);
461 EXPECT_EQ(12345, result_layer
->id());
464 TEST_F(LayerTreeImplTest
, HitTestingForSimpleClippedLayer
) {
465 // Test that hit-testing will only work for the visible portion of a layer,
466 // and not the entire layer bounds. Here we just test the simple axis-aligned
468 gfx::Transform identity_matrix
;
469 gfx::Point3F transform_origin
;
471 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl().active_tree(), 1);
472 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
473 gfx::PointF(), gfx::Size(100, 100), true, false,
476 scoped_ptr
<LayerImpl
> clipping_layer
=
477 LayerImpl::Create(host_impl().active_tree(), 123);
478 // this layer is positioned, and hit testing should correctly know where the
480 gfx::PointF
position(25.f
, 25.f
);
481 gfx::Size
bounds(50, 50);
482 SetLayerPropertiesForTesting(clipping_layer
.get(), identity_matrix
,
483 transform_origin
, position
, bounds
, true,
485 clipping_layer
->SetMasksToBounds(true);
487 scoped_ptr
<LayerImpl
> child
=
488 LayerImpl::Create(host_impl().active_tree(), 456);
489 position
= gfx::PointF(-50.f
, -50.f
);
490 bounds
= gfx::Size(300, 300);
491 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, transform_origin
,
492 position
, bounds
, true, false, false);
493 child
->SetDrawsContent(true);
494 clipping_layer
->AddChild(child
.Pass());
495 root
->AddChild(clipping_layer
.Pass());
498 host_impl().SetViewportSize(root
->bounds());
499 host_impl().active_tree()->SetRootLayer(root
.Pass());
500 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
502 // Sanity check the scenario we just created.
503 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
504 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
505 ASSERT_EQ(456, root_layer()->render_surface()->layer_list().at(0)->id());
507 // Hit testing for a point outside the layer should return a null pointer.
508 // Despite the child layer being very large, it should be clipped to the root
510 gfx::Point
test_point(24, 24);
511 LayerImpl
* result_layer
=
512 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
513 EXPECT_FALSE(result_layer
);
515 // Even though the layer exists at (101, 101), it should not be visible there
516 // since the clipping_layer would clamp it.
517 test_point
= gfx::Point(76, 76);
519 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
520 EXPECT_FALSE(result_layer
);
522 // Hit testing for a point inside should return the child layer.
523 test_point
= gfx::Point(26, 26);
525 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
526 ASSERT_TRUE(result_layer
);
527 EXPECT_EQ(456, result_layer
->id());
529 test_point
= gfx::Point(74, 74);
531 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
532 ASSERT_TRUE(result_layer
);
533 EXPECT_EQ(456, result_layer
->id());
536 TEST_F(LayerTreeImplTest
, HitTestingForMultiClippedRotatedLayer
) {
537 // This test checks whether hit testing correctly avoids hit testing with
538 // multiple ancestors that clip in non axis-aligned ways. To pass this test,
539 // the hit testing algorithm needs to recognize that multiple parent layers
540 // may clip the layer, and should not actually hit those clipped areas.
542 // The child and grand_child layers are both initialized to clip the
543 // rotated_leaf. The child layer is rotated about the top-left corner, so that
544 // the root + child clips combined create a triangle. The rotated_leaf will
545 // only be visible where it overlaps this triangle.
547 scoped_ptr
<LayerImpl
> root
=
548 LayerImpl::Create(host_impl().active_tree(), 123);
550 gfx::Transform identity_matrix
;
551 gfx::Point3F transform_origin
;
552 gfx::PointF position
;
553 gfx::Size
bounds(100, 100);
554 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
555 position
, bounds
, true, false, true);
556 root
->SetMasksToBounds(true);
558 scoped_ptr
<LayerImpl
> child
=
559 LayerImpl::Create(host_impl().active_tree(), 456);
560 scoped_ptr
<LayerImpl
> grand_child
=
561 LayerImpl::Create(host_impl().active_tree(), 789);
562 scoped_ptr
<LayerImpl
> rotated_leaf
=
563 LayerImpl::Create(host_impl().active_tree(), 2468);
565 position
= gfx::PointF(10.f
, 10.f
);
566 bounds
= gfx::Size(80, 80);
567 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, transform_origin
,
568 position
, bounds
, true, false, false);
569 child
->SetMasksToBounds(true);
571 gfx::Transform rotation45_degrees_about_corner
;
572 rotation45_degrees_about_corner
.RotateAboutZAxis(45.0);
574 // remember, positioned with respect to its parent which is already at 10,
576 position
= gfx::PointF();
578 gfx::Size(200, 200); // to ensure it covers at least sqrt(2) * 100.
579 SetLayerPropertiesForTesting(
580 grand_child
.get(), rotation45_degrees_about_corner
, transform_origin
,
581 position
, bounds
, true, false, false);
582 grand_child
->SetMasksToBounds(true);
584 // Rotates about the center of the layer
585 gfx::Transform rotated_leaf_transform
;
586 rotated_leaf_transform
.Translate(
587 -10.0, -10.0); // cancel out the grand_parent's position
588 rotated_leaf_transform
.RotateAboutZAxis(
589 -45.0); // cancel out the corner 45-degree rotation of the parent.
590 rotated_leaf_transform
.Translate(50.0, 50.0);
591 rotated_leaf_transform
.RotateAboutZAxis(45.0);
592 rotated_leaf_transform
.Translate(-50.0, -50.0);
593 position
= gfx::PointF();
594 bounds
= gfx::Size(100, 100);
595 SetLayerPropertiesForTesting(rotated_leaf
.get(), rotated_leaf_transform
,
596 transform_origin
, position
, bounds
, true,
598 rotated_leaf
->SetDrawsContent(true);
600 grand_child
->AddChild(rotated_leaf
.Pass());
601 child
->AddChild(grand_child
.Pass());
602 root
->AddChild(child
.Pass());
605 host_impl().SetViewportSize(root
->bounds());
606 host_impl().active_tree()->SetRootLayer(root
.Pass());
607 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
609 // (11, 89) is close to the the bottom left corner within the clip, but it is
610 // not inside the layer.
611 gfx::Point
test_point(11, 89);
612 LayerImpl
* result_layer
=
613 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
614 EXPECT_FALSE(result_layer
);
616 // Closer inwards from the bottom left will overlap the layer.
617 test_point
= gfx::Point(25, 75);
619 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
620 ASSERT_TRUE(result_layer
);
621 EXPECT_EQ(2468, result_layer
->id());
623 // (4, 50) is inside the unclipped layer, but that corner of the layer should
624 // be clipped away by the grandparent and should not get hit. If hit testing
625 // blindly uses visible content rect without considering how parent may clip
626 // the layer, then hit testing would accidentally think that the point
627 // successfully hits the layer.
628 test_point
= gfx::Point(4, 50);
630 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
631 EXPECT_FALSE(result_layer
);
633 // (11, 50) is inside the layer and within the clipped area.
634 test_point
= gfx::Point(11, 50);
636 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
637 ASSERT_TRUE(result_layer
);
638 EXPECT_EQ(2468, result_layer
->id());
640 // Around the middle, just to the right and up, would have hit the layer
641 // except that that area should be clipped away by the parent.
642 test_point
= gfx::Point(51, 49);
644 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
645 EXPECT_FALSE(result_layer
);
647 // Around the middle, just to the left and down, should successfully hit the
649 test_point
= gfx::Point(49, 51);
651 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
652 ASSERT_TRUE(result_layer
);
653 EXPECT_EQ(2468, result_layer
->id());
656 TEST_F(LayerTreeImplTest
, HitTestingForNonClippingIntermediateLayer
) {
657 // This test checks that hit testing code does not accidentally clip to layer
658 // bounds for a layer that actually does not clip.
659 gfx::Transform identity_matrix
;
660 gfx::Point3F transform_origin
;
662 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl().active_tree(), 1);
663 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
664 gfx::PointF(), gfx::Size(100, 100), true, false,
667 scoped_ptr
<LayerImpl
> intermediate_layer
=
668 LayerImpl::Create(host_impl().active_tree(), 123);
669 // this layer is positioned, and hit testing should correctly know where the
671 gfx::PointF
position(10.f
, 10.f
);
672 gfx::Size
bounds(50, 50);
673 SetLayerPropertiesForTesting(intermediate_layer
.get(), identity_matrix
,
674 transform_origin
, position
, bounds
, true,
676 // Sanity check the intermediate layer should not clip.
677 ASSERT_FALSE(intermediate_layer
->masks_to_bounds());
678 ASSERT_FALSE(intermediate_layer
->mask_layer());
680 // The child of the intermediate_layer is translated so that it does not
681 // overlap intermediate_layer at all. If child is incorrectly clipped, we
682 // would not be able to hit it successfully.
683 scoped_ptr
<LayerImpl
> child
=
684 LayerImpl::Create(host_impl().active_tree(), 456);
685 position
= gfx::PointF(60.f
, 60.f
); // 70, 70 in screen space
686 bounds
= gfx::Size(20, 20);
687 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, transform_origin
,
688 position
, bounds
, true, false, false);
689 child
->SetDrawsContent(true);
690 intermediate_layer
->AddChild(child
.Pass());
691 root
->AddChild(intermediate_layer
.Pass());
694 host_impl().SetViewportSize(root
->bounds());
695 host_impl().active_tree()->SetRootLayer(root
.Pass());
696 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
698 // Sanity check the scenario we just created.
699 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
700 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
701 ASSERT_EQ(456, root_layer()->render_surface()->layer_list().at(0)->id());
703 // Hit testing for a point outside the layer should return a null pointer.
704 gfx::Point
test_point(69, 69);
705 LayerImpl
* result_layer
=
706 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
707 EXPECT_FALSE(result_layer
);
709 test_point
= gfx::Point(91, 91);
711 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
712 EXPECT_FALSE(result_layer
);
714 // Hit testing for a point inside should return the child layer.
715 test_point
= gfx::Point(71, 71);
717 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
718 ASSERT_TRUE(result_layer
);
719 EXPECT_EQ(456, result_layer
->id());
721 test_point
= gfx::Point(89, 89);
723 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
724 ASSERT_TRUE(result_layer
);
725 EXPECT_EQ(456, result_layer
->id());
728 TEST_F(LayerTreeImplTest
, HitTestingForMultipleLayers
) {
729 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl().active_tree(), 1);
731 gfx::Transform identity_matrix
;
732 gfx::Point3F transform_origin
;
733 gfx::PointF position
;
734 gfx::Size
bounds(100, 100);
735 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
736 position
, bounds
, true, false, true);
737 root
->SetDrawsContent(true);
739 // child 1 and child2 are initialized to overlap between x=50 and x=60.
740 // grand_child is set to overlap both child1 and child2 between y=50 and
741 // y=60. The expected stacking order is: (front) child2, (second)
742 // grand_child, (third) child1, and (back) the root layer behind all other
745 scoped_ptr
<LayerImpl
> child1
=
746 LayerImpl::Create(host_impl().active_tree(), 2);
747 scoped_ptr
<LayerImpl
> child2
=
748 LayerImpl::Create(host_impl().active_tree(), 3);
749 scoped_ptr
<LayerImpl
> grand_child1
=
750 LayerImpl::Create(host_impl().active_tree(), 4);
752 position
= gfx::PointF(10.f
, 10.f
);
753 bounds
= gfx::Size(50, 50);
754 SetLayerPropertiesForTesting(child1
.get(), identity_matrix
,
755 transform_origin
, position
, bounds
, true,
757 child1
->SetDrawsContent(true);
759 position
= gfx::PointF(50.f
, 10.f
);
760 bounds
= gfx::Size(50, 50);
761 SetLayerPropertiesForTesting(child2
.get(), identity_matrix
,
762 transform_origin
, position
, bounds
, true,
764 child2
->SetDrawsContent(true);
766 // Remember that grand_child is positioned with respect to its parent (i.e.
767 // child1). In screen space, the intended position is (10, 50), with size
769 position
= gfx::PointF(0.f
, 40.f
);
770 bounds
= gfx::Size(100, 50);
771 SetLayerPropertiesForTesting(grand_child1
.get(), identity_matrix
,
772 transform_origin
, position
, bounds
, true,
774 grand_child1
->SetDrawsContent(true);
776 child1
->AddChild(grand_child1
.Pass());
777 root
->AddChild(child1
.Pass());
778 root
->AddChild(child2
.Pass());
781 LayerImpl
* child1
= root
->children()[0];
782 LayerImpl
* child2
= root
->children()[1];
783 LayerImpl
* grand_child1
= child1
->children()[0];
785 host_impl().SetViewportSize(root
->bounds());
786 host_impl().active_tree()->SetRootLayer(root
.Pass());
787 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
789 // Sanity check the scenario we just created.
792 ASSERT_TRUE(grand_child1
);
793 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
795 RenderSurfaceImpl
* root_render_surface
= root_layer()->render_surface();
796 ASSERT_EQ(4u, root_render_surface
->layer_list().size());
797 ASSERT_EQ(1, root_render_surface
->layer_list().at(0)->id()); // root layer
798 ASSERT_EQ(2, root_render_surface
->layer_list().at(1)->id()); // child1
799 ASSERT_EQ(4, root_render_surface
->layer_list().at(2)->id()); // grand_child1
800 ASSERT_EQ(3, root_render_surface
->layer_list().at(3)->id()); // child2
802 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
804 gfx::Point test_point
= gfx::Point(1, 1);
805 LayerImpl
* result_layer
=
806 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
807 ASSERT_TRUE(result_layer
);
808 EXPECT_EQ(1, result_layer
->id());
810 // At (15, 15), child1 and root are the only layers. child1 is expected to be
812 test_point
= gfx::Point(15, 15);
814 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
815 ASSERT_TRUE(result_layer
);
816 EXPECT_EQ(2, result_layer
->id());
818 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
819 test_point
= gfx::Point(51, 20);
821 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
822 ASSERT_TRUE(result_layer
);
823 EXPECT_EQ(3, result_layer
->id());
825 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
827 test_point
= gfx::Point(80, 51);
829 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
830 ASSERT_TRUE(result_layer
);
831 EXPECT_EQ(3, result_layer
->id());
833 // At (51, 51), all layers overlap each other. child2 is expected to be on top
834 // of all other layers.
835 test_point
= gfx::Point(51, 51);
837 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
838 ASSERT_TRUE(result_layer
);
839 EXPECT_EQ(3, result_layer
->id());
841 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
843 test_point
= gfx::Point(20, 51);
845 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
846 ASSERT_TRUE(result_layer
);
847 EXPECT_EQ(4, result_layer
->id());
850 TEST_F(LayerTreeImplTest
, HitTestingForMultipleLayersAtVaryingDepths
) {
851 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl().active_tree(), 1);
853 gfx::Transform identity_matrix
;
854 gfx::Point3F transform_origin
;
855 gfx::PointF position
;
856 gfx::Size
bounds(100, 100);
857 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
858 position
, bounds
, true, false, true);
859 root
->SetDrawsContent(true);
860 root
->SetShouldFlattenTransform(false);
861 root
->Set3dSortingContextId(1);
863 // child 1 and child2 are initialized to overlap between x=50 and x=60.
864 // grand_child is set to overlap both child1 and child2 between y=50 and
865 // y=60. The expected stacking order is: (front) child2, (second)
866 // grand_child, (third) child1, and (back) the root layer behind all other
869 scoped_ptr
<LayerImpl
> child1
=
870 LayerImpl::Create(host_impl().active_tree(), 2);
871 scoped_ptr
<LayerImpl
> child2
=
872 LayerImpl::Create(host_impl().active_tree(), 3);
873 scoped_ptr
<LayerImpl
> grand_child1
=
874 LayerImpl::Create(host_impl().active_tree(), 4);
876 position
= gfx::PointF(10.f
, 10.f
);
877 bounds
= gfx::Size(50, 50);
878 SetLayerPropertiesForTesting(child1
.get(), identity_matrix
,
879 transform_origin
, position
, bounds
, true,
881 child1
->SetDrawsContent(true);
882 child1
->SetShouldFlattenTransform(false);
883 child1
->Set3dSortingContextId(1);
885 position
= gfx::PointF(50.f
, 10.f
);
886 bounds
= gfx::Size(50, 50);
887 gfx::Transform translate_z
;
888 translate_z
.Translate3d(0, 0, -10.f
);
889 SetLayerPropertiesForTesting(child2
.get(), translate_z
, transform_origin
,
890 position
, bounds
, true, false, false);
891 child2
->SetDrawsContent(true);
892 child2
->SetShouldFlattenTransform(false);
893 child2
->Set3dSortingContextId(1);
895 // Remember that grand_child is positioned with respect to its parent (i.e.
896 // child1). In screen space, the intended position is (10, 50), with size
898 position
= gfx::PointF(0.f
, 40.f
);
899 bounds
= gfx::Size(100, 50);
900 SetLayerPropertiesForTesting(grand_child1
.get(), identity_matrix
,
901 transform_origin
, position
, bounds
, true,
903 grand_child1
->SetDrawsContent(true);
904 grand_child1
->SetShouldFlattenTransform(false);
906 child1
->AddChild(grand_child1
.Pass());
907 root
->AddChild(child1
.Pass());
908 root
->AddChild(child2
.Pass());
911 LayerImpl
* child1
= root
->children()[0];
912 LayerImpl
* child2
= root
->children()[1];
913 LayerImpl
* grand_child1
= child1
->children()[0];
915 host_impl().SetViewportSize(root
->bounds());
916 host_impl().active_tree()->SetRootLayer(root
.Pass());
917 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
919 // Sanity check the scenario we just created.
922 ASSERT_TRUE(grand_child1
);
923 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
925 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
927 gfx::Point test_point
= gfx::Point(1, 1);
928 LayerImpl
* result_layer
=
929 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
930 ASSERT_TRUE(result_layer
);
931 EXPECT_EQ(1, result_layer
->id());
933 // At (15, 15), child1 and root are the only layers. child1 is expected to be
935 test_point
= gfx::Point(15, 15);
937 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
938 ASSERT_TRUE(result_layer
);
939 EXPECT_EQ(2, result_layer
->id());
941 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
942 // (because 3 is transformed to the back).
943 test_point
= gfx::Point(51, 20);
945 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
946 ASSERT_TRUE(result_layer
);
947 EXPECT_EQ(2, result_layer
->id());
949 // 3 Would have been on top if it hadn't been transformed to the background.
950 // Make sure that it isn't hit.
951 test_point
= gfx::Point(80, 51);
953 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
954 ASSERT_TRUE(result_layer
);
955 EXPECT_EQ(4, result_layer
->id());
957 // 3 Would have been on top if it hadn't been transformed to the background.
958 // Make sure that it isn't hit.
959 test_point
= gfx::Point(51, 51);
961 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
962 ASSERT_TRUE(result_layer
);
963 EXPECT_EQ(4, result_layer
->id());
965 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
967 test_point
= gfx::Point(20, 51);
969 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
970 ASSERT_TRUE(result_layer
);
971 EXPECT_EQ(4, result_layer
->id());
974 TEST_F(LayerTreeImplTest
, HitTestingRespectsClipParents
) {
975 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl().active_tree(), 1);
976 gfx::Transform identity_matrix
;
977 gfx::Point3F transform_origin
;
978 gfx::PointF position
;
979 gfx::Size
bounds(100, 100);
980 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
981 position
, bounds
, true, false, true);
982 root
->SetDrawsContent(true);
984 scoped_ptr
<LayerImpl
> child
=
985 LayerImpl::Create(host_impl().active_tree(), 2);
986 scoped_ptr
<LayerImpl
> grand_child
=
987 LayerImpl::Create(host_impl().active_tree(), 4);
989 position
= gfx::PointF(10.f
, 10.f
);
990 bounds
= gfx::Size(1, 1);
991 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, transform_origin
,
992 position
, bounds
, true, false, false);
993 child
->SetDrawsContent(true);
994 child
->SetMasksToBounds(true);
996 position
= gfx::PointF(0.f
, 40.f
);
997 bounds
= gfx::Size(100, 50);
998 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
999 transform_origin
, position
, bounds
, true,
1001 grand_child
->SetDrawsContent(true);
1002 grand_child
->SetHasRenderSurface(true);
1004 // This should let |grand_child| "escape" |child|'s clip.
1005 grand_child
->SetClipParent(root
.get());
1007 child
->AddChild(grand_child
.Pass());
1008 root
->AddChild(child
.Pass());
1011 host_impl().SetViewportSize(root
->bounds());
1012 host_impl().active_tree()->SetRootLayer(root
.Pass());
1013 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1015 gfx::Point test_point
= gfx::Point(12, 52);
1016 LayerImpl
* result_layer
=
1017 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
1018 ASSERT_TRUE(result_layer
);
1019 EXPECT_EQ(4, result_layer
->id());
1022 TEST_F(LayerTreeImplTest
, HitTestingRespectsScrollParents
) {
1023 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl().active_tree(), 1);
1024 gfx::Transform identity_matrix
;
1025 gfx::Point3F transform_origin
;
1026 gfx::PointF position
;
1027 gfx::Size
bounds(100, 100);
1028 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
1029 position
, bounds
, true, false, true);
1030 root
->SetDrawsContent(true);
1032 scoped_ptr
<LayerImpl
> child
=
1033 LayerImpl::Create(host_impl().active_tree(), 2);
1034 scoped_ptr
<LayerImpl
> scroll_child
=
1035 LayerImpl::Create(host_impl().active_tree(), 3);
1036 scoped_ptr
<LayerImpl
> grand_child
=
1037 LayerImpl::Create(host_impl().active_tree(), 4);
1039 position
= gfx::PointF(10.f
, 10.f
);
1040 bounds
= gfx::Size(1, 1);
1041 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, transform_origin
,
1042 position
, bounds
, true, false, false);
1043 child
->SetDrawsContent(true);
1044 child
->SetMasksToBounds(true);
1046 position
= gfx::PointF();
1047 bounds
= gfx::Size(200, 200);
1048 SetLayerPropertiesForTesting(scroll_child
.get(), identity_matrix
,
1049 transform_origin
, position
, bounds
, true,
1051 scroll_child
->SetDrawsContent(true);
1053 // This should cause scroll child and its descendants to be affected by
1055 scroll_child
->SetScrollParent(child
.get());
1057 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
1058 transform_origin
, position
, bounds
, true,
1060 grand_child
->SetDrawsContent(true);
1061 grand_child
->SetHasRenderSurface(true);
1063 scroll_child
->AddChild(grand_child
.Pass());
1064 root
->AddChild(scroll_child
.Pass());
1065 root
->AddChild(child
.Pass());
1068 host_impl().SetViewportSize(root
->bounds());
1069 host_impl().active_tree()->SetRootLayer(root
.Pass());
1070 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1072 gfx::Point test_point
= gfx::Point(12, 52);
1073 LayerImpl
* result_layer
=
1074 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
1075 // The |test_point| should have been clipped away by |child|, the scroll
1076 // parent, so the only thing that should be hit is |root|.
1077 ASSERT_TRUE(result_layer
);
1078 ASSERT_EQ(1, result_layer
->id());
1080 TEST_F(LayerTreeImplTest
, HitTestingForMultipleLayerLists
) {
1082 // The geometry is set up similarly to the previous case, but
1083 // all layers are forced to be render surfaces now.
1085 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl().active_tree(), 1);
1087 gfx::Transform identity_matrix
;
1088 gfx::Point3F transform_origin
;
1089 gfx::PointF position
;
1090 gfx::Size
bounds(100, 100);
1091 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
1092 position
, bounds
, true, false, true);
1093 root
->SetDrawsContent(true);
1095 // child 1 and child2 are initialized to overlap between x=50 and x=60.
1096 // grand_child is set to overlap both child1 and child2 between y=50 and
1097 // y=60. The expected stacking order is: (front) child2, (second)
1098 // grand_child, (third) child1, and (back) the root layer behind all other
1101 scoped_ptr
<LayerImpl
> child1
=
1102 LayerImpl::Create(host_impl().active_tree(), 2);
1103 scoped_ptr
<LayerImpl
> child2
=
1104 LayerImpl::Create(host_impl().active_tree(), 3);
1105 scoped_ptr
<LayerImpl
> grand_child1
=
1106 LayerImpl::Create(host_impl().active_tree(), 4);
1108 position
= gfx::PointF(10.f
, 10.f
);
1109 bounds
= gfx::Size(50, 50);
1110 SetLayerPropertiesForTesting(child1
.get(), identity_matrix
,
1111 transform_origin
, position
, bounds
, true,
1113 child1
->SetDrawsContent(true);
1114 child1
->SetHasRenderSurface(true);
1116 position
= gfx::PointF(50.f
, 10.f
);
1117 bounds
= gfx::Size(50, 50);
1118 SetLayerPropertiesForTesting(child2
.get(), identity_matrix
,
1119 transform_origin
, position
, bounds
, true,
1121 child2
->SetDrawsContent(true);
1122 child2
->SetHasRenderSurface(true);
1124 // Remember that grand_child is positioned with respect to its parent (i.e.
1125 // child1). In screen space, the intended position is (10, 50), with size
1127 position
= gfx::PointF(0.f
, 40.f
);
1128 bounds
= gfx::Size(100, 50);
1129 SetLayerPropertiesForTesting(grand_child1
.get(), identity_matrix
,
1130 transform_origin
, position
, bounds
, true,
1132 grand_child1
->SetDrawsContent(true);
1133 grand_child1
->SetHasRenderSurface(true);
1135 child1
->AddChild(grand_child1
.Pass());
1136 root
->AddChild(child1
.Pass());
1137 root
->AddChild(child2
.Pass());
1140 LayerImpl
* child1
= root
->children()[0];
1141 LayerImpl
* child2
= root
->children()[1];
1142 LayerImpl
* grand_child1
= child1
->children()[0];
1144 host_impl().SetViewportSize(root
->bounds());
1145 host_impl().active_tree()->SetRootLayer(root
.Pass());
1146 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1148 // Sanity check the scenario we just created.
1149 ASSERT_TRUE(child1
);
1150 ASSERT_TRUE(child2
);
1151 ASSERT_TRUE(grand_child1
);
1152 ASSERT_TRUE(child1
->render_surface());
1153 ASSERT_TRUE(child2
->render_surface());
1154 ASSERT_TRUE(grand_child1
->render_surface());
1155 ASSERT_EQ(4u, RenderSurfaceLayerList().size());
1156 // The root surface has the root layer, and child1's and child2's render
1158 ASSERT_EQ(3u, root_layer()->render_surface()->layer_list().size());
1159 // The child1 surface has the child1 layer and grand_child1's render surface.
1160 ASSERT_EQ(2u, child1
->render_surface()->layer_list().size());
1161 ASSERT_EQ(1u, child2
->render_surface()->layer_list().size());
1162 ASSERT_EQ(1u, grand_child1
->render_surface()->layer_list().size());
1163 ASSERT_EQ(1, RenderSurfaceLayerList().at(0)->id()); // root layer
1164 ASSERT_EQ(2, RenderSurfaceLayerList()[1]->id()); // child1
1165 ASSERT_EQ(4, RenderSurfaceLayerList().at(2)->id()); // grand_child1
1166 ASSERT_EQ(3, RenderSurfaceLayerList()[3]->id()); // child2
1168 // Nothing overlaps the root_layer at (1, 1), so hit testing there should find
1170 gfx::Point test_point
= gfx::Point(1, 1);
1171 LayerImpl
* result_layer
=
1172 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
1173 ASSERT_TRUE(result_layer
);
1174 EXPECT_EQ(1, result_layer
->id());
1176 // At (15, 15), child1 and root are the only layers. child1 is expected to be
1178 test_point
= gfx::Point(15, 15);
1180 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
1181 ASSERT_TRUE(result_layer
);
1182 EXPECT_EQ(2, result_layer
->id());
1184 // At (51, 20), child1 and child2 overlap. child2 is expected to be on top.
1185 test_point
= gfx::Point(51, 20);
1187 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
1188 ASSERT_TRUE(result_layer
);
1189 EXPECT_EQ(3, result_layer
->id());
1191 // At (80, 51), child2 and grand_child1 overlap. child2 is expected to be on
1193 test_point
= gfx::Point(80, 51);
1195 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
1196 ASSERT_TRUE(result_layer
);
1197 EXPECT_EQ(3, result_layer
->id());
1199 // At (51, 51), all layers overlap each other. child2 is expected to be on top
1200 // of all other layers.
1201 test_point
= gfx::Point(51, 51);
1203 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
1204 ASSERT_TRUE(result_layer
);
1205 EXPECT_EQ(3, result_layer
->id());
1207 // At (20, 51), child1 and grand_child1 overlap. grand_child1 is expected to
1209 test_point
= gfx::Point(20, 51);
1211 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point
);
1212 ASSERT_TRUE(result_layer
);
1213 EXPECT_EQ(4, result_layer
->id());
1216 TEST_F(LayerTreeImplTest
, HitCheckingTouchHandlerRegionsForSingleLayer
) {
1217 scoped_ptr
<LayerImpl
> root
=
1218 LayerImpl::Create(host_impl().active_tree(), 12345);
1220 gfx::Transform identity_matrix
;
1221 Region
touch_handler_region(gfx::Rect(10, 10, 50, 50));
1222 gfx::Point3F transform_origin
;
1223 gfx::PointF position
;
1224 gfx::Size
bounds(100, 100);
1225 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
1226 position
, bounds
, true, false, true);
1227 root
->SetDrawsContent(true);
1229 host_impl().SetViewportSize(root
->bounds());
1230 host_impl().active_tree()->SetRootLayer(root
.Pass());
1231 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1233 // Sanity check the scenario we just created.
1234 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1235 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
1237 // Hit checking for any point should return a null pointer for a layer without
1238 // any touch event handler regions.
1239 gfx::Point
test_point(11, 11);
1240 LayerImpl
* result_layer
=
1241 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1243 EXPECT_FALSE(result_layer
);
1245 host_impl().active_tree()->root_layer()->SetTouchEventHandlerRegion(
1246 touch_handler_region
);
1247 // Hit checking for a point outside the layer should return a null pointer.
1248 test_point
= gfx::Point(101, 101);
1250 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1252 EXPECT_FALSE(result_layer
);
1254 test_point
= gfx::Point(-1, -1);
1256 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1258 EXPECT_FALSE(result_layer
);
1260 // Hit checking for a point inside the layer, but outside the touch handler
1261 // region should return a null pointer.
1262 test_point
= gfx::Point(1, 1);
1264 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1266 EXPECT_FALSE(result_layer
);
1268 test_point
= gfx::Point(99, 99);
1270 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1272 EXPECT_FALSE(result_layer
);
1274 // Hit checking for a point inside the touch event handler region should
1275 // return the root layer.
1276 test_point
= gfx::Point(11, 11);
1278 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1280 ASSERT_TRUE(result_layer
);
1281 EXPECT_EQ(12345, result_layer
->id());
1283 test_point
= gfx::Point(59, 59);
1285 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1287 ASSERT_TRUE(result_layer
);
1288 EXPECT_EQ(12345, result_layer
->id());
1291 TEST_F(LayerTreeImplTest
,
1292 HitCheckingTouchHandlerRegionsForUninvertibleTransform
) {
1293 scoped_ptr
<LayerImpl
> root
=
1294 LayerImpl::Create(host_impl().active_tree(), 12345);
1296 gfx::Transform uninvertible_transform
;
1297 uninvertible_transform
.matrix().set(0, 0, 0.0);
1298 uninvertible_transform
.matrix().set(1, 1, 0.0);
1299 uninvertible_transform
.matrix().set(2, 2, 0.0);
1300 uninvertible_transform
.matrix().set(3, 3, 0.0);
1301 ASSERT_FALSE(uninvertible_transform
.IsInvertible());
1303 gfx::Transform identity_matrix
;
1304 Region
touch_handler_region(gfx::Rect(10, 10, 50, 50));
1305 gfx::Point3F transform_origin
;
1306 gfx::PointF position
;
1307 gfx::Size
bounds(100, 100);
1308 SetLayerPropertiesForTesting(root
.get(), uninvertible_transform
,
1309 transform_origin
, position
, bounds
, true, false,
1311 root
->SetDrawsContent(true);
1312 root
->SetTouchEventHandlerRegion(touch_handler_region
);
1314 host_impl().SetViewportSize(root
->bounds());
1315 host_impl().active_tree()->SetRootLayer(root
.Pass());
1316 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1318 // Sanity check the scenario we just created.
1319 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1320 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
1321 ASSERT_FALSE(root_layer()->screen_space_transform().IsInvertible());
1323 // Hit checking any point should not hit the touch handler region on the
1324 // layer. If the invertible matrix is accidentally ignored and treated like an
1325 // identity, then the hit testing will incorrectly hit the layer when it
1327 gfx::Point
test_point(1, 1);
1328 LayerImpl
* result_layer
=
1329 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1331 EXPECT_FALSE(result_layer
);
1333 test_point
= gfx::Point(10, 10);
1335 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1337 EXPECT_FALSE(result_layer
);
1339 test_point
= gfx::Point(10, 30);
1341 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1343 EXPECT_FALSE(result_layer
);
1345 test_point
= gfx::Point(50, 50);
1347 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1349 EXPECT_FALSE(result_layer
);
1351 test_point
= gfx::Point(67, 48);
1353 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1355 EXPECT_FALSE(result_layer
);
1357 test_point
= gfx::Point(99, 99);
1359 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1361 EXPECT_FALSE(result_layer
);
1363 test_point
= gfx::Point(-1, -1);
1365 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1367 EXPECT_FALSE(result_layer
);
1370 TEST_F(LayerTreeImplTest
, MakeScrollbarsInvisibleNearMinPageScale
) {
1371 const int kThumbThickness
= 10;
1372 const int kTrackStart
= 0;
1373 const bool kIsLeftSideVerticalScrollbar
= false;
1374 const bool kIsOverlayScrollbar
= true;
1376 LayerTreeImpl
* active_tree
= host_impl().active_tree();
1378 scoped_ptr
<LayerImpl
> scroll_layer
= LayerImpl::Create(active_tree
, 1);
1379 scoped_ptr
<SolidColorScrollbarLayerImpl
> vertical_scrollbar_layer
=
1380 SolidColorScrollbarLayerImpl::Create(active_tree
,
1385 kIsLeftSideVerticalScrollbar
,
1386 kIsOverlayScrollbar
);
1387 scoped_ptr
<SolidColorScrollbarLayerImpl
> horizontal_scrollbar_layer
=
1388 SolidColorScrollbarLayerImpl::Create(active_tree
,
1393 kIsLeftSideVerticalScrollbar
,
1394 kIsOverlayScrollbar
);
1396 scoped_ptr
<LayerImpl
> clip_layer
= LayerImpl::Create(active_tree
, 4);
1397 scoped_ptr
<LayerImpl
> page_scale_layer
= LayerImpl::Create(active_tree
, 5);
1399 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
1401 LayerImpl
* scroll_layer_ptr
= scroll_layer
.get();
1402 LayerImpl
* page_scale_layer_ptr
= page_scale_layer
.get();
1404 clip_layer
->AddChild(page_scale_layer
.Pass());
1405 page_scale_layer_ptr
->AddChild(scroll_layer
.Pass());
1407 vertical_scrollbar_layer
->SetScrollLayerAndClipLayerByIds(
1408 scroll_layer_ptr
->id(),
1410 horizontal_scrollbar_layer
->SetScrollLayerAndClipLayerByIds(
1411 scroll_layer_ptr
->id(),
1414 active_tree
->PushPageScaleFromMainThread(1.0f
, 1.0f
, 4.0f
);
1415 active_tree
->SetViewportLayersFromIds(
1416 Layer::INVALID_ID
, // Overscroll
1417 page_scale_layer_ptr
->id(),
1418 scroll_layer_ptr
->id(),
1419 Layer::INVALID_ID
); // Outer Scroll
1421 EXPECT_TRUE(vertical_scrollbar_layer
->hide_layer_and_subtree());
1422 EXPECT_TRUE(horizontal_scrollbar_layer
->hide_layer_and_subtree());
1424 active_tree
->PushPageScaleFromMainThread(1.05f
, 1.0f
, 4.0f
);
1425 EXPECT_TRUE(vertical_scrollbar_layer
->hide_layer_and_subtree());
1426 EXPECT_TRUE(horizontal_scrollbar_layer
->hide_layer_and_subtree());
1428 active_tree
->PushPageScaleFromMainThread(1.1f
, 1.0f
, 4.0f
);
1429 EXPECT_FALSE(vertical_scrollbar_layer
->hide_layer_and_subtree());
1430 EXPECT_FALSE(horizontal_scrollbar_layer
->hide_layer_and_subtree());
1432 active_tree
->PushPageScaleFromMainThread(1.5f
, 1.0f
, 4.0f
);
1433 EXPECT_FALSE(vertical_scrollbar_layer
->hide_layer_and_subtree());
1434 EXPECT_FALSE(horizontal_scrollbar_layer
->hide_layer_and_subtree());
1437 TEST_F(LayerTreeImplTest
,
1438 HitCheckingTouchHandlerRegionsForSinglePositionedLayer
) {
1439 scoped_ptr
<LayerImpl
> root
=
1440 LayerImpl::Create(host_impl().active_tree(), 12345);
1442 gfx::Transform identity_matrix
;
1443 Region
touch_handler_region(gfx::Rect(10, 10, 50, 50));
1444 gfx::Point3F transform_origin
;
1445 // this layer is positioned, and hit testing should correctly know where the
1446 // layer is located.
1447 gfx::PointF
position(50.f
, 50.f
);
1448 gfx::Size
bounds(100, 100);
1449 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
1450 position
, bounds
, true, false, true);
1451 root
->SetDrawsContent(true);
1452 root
->SetTouchEventHandlerRegion(touch_handler_region
);
1454 host_impl().SetViewportSize(root
->bounds());
1455 host_impl().active_tree()->SetRootLayer(root
.Pass());
1456 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1458 // Sanity check the scenario we just created.
1459 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1460 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
1462 // Hit checking for a point outside the layer should return a null pointer.
1463 gfx::Point
test_point(49, 49);
1464 LayerImpl
* result_layer
=
1465 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1467 EXPECT_FALSE(result_layer
);
1469 // Even though the layer has a touch handler region containing (101, 101), it
1470 // should not be visible there since the root render surface would clamp it.
1471 test_point
= gfx::Point(101, 101);
1473 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1475 EXPECT_FALSE(result_layer
);
1477 // Hit checking for a point inside the layer, but outside the touch handler
1478 // region should return a null pointer.
1479 test_point
= gfx::Point(51, 51);
1481 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1483 EXPECT_FALSE(result_layer
);
1485 // Hit checking for a point inside the touch event handler region should
1486 // return the root layer.
1487 test_point
= gfx::Point(61, 61);
1489 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1491 ASSERT_TRUE(result_layer
);
1492 EXPECT_EQ(12345, result_layer
->id());
1494 test_point
= gfx::Point(99, 99);
1496 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1498 ASSERT_TRUE(result_layer
);
1499 EXPECT_EQ(12345, result_layer
->id());
1502 TEST_F(LayerTreeImplTest
,
1503 HitCheckingTouchHandlerRegionsForSingleLayerWithScaledContents
) {
1504 // A layer's visible content rect is actually in the layer's content space.
1505 // The screen space transform converts from the layer's origin space to screen
1506 // space. This test makes sure that hit testing works correctly accounts for
1507 // the contents scale. A contents scale that is not 1 effectively forces a
1508 // non-identity transform between layer's content space and layer's origin
1509 // space. The hit testing code must take this into account.
1511 // To test this, the layer is positioned at (25, 25), and is size (50, 50). If
1512 // contents scale is ignored, then hit checking will mis-interpret the visible
1513 // content rect as being larger than the actual bounds of the layer.
1515 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl().active_tree(), 1);
1517 gfx::Transform identity_matrix
;
1518 gfx::Point3F transform_origin
;
1520 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
1521 gfx::PointF(), gfx::Size(100, 100), true, false,
1524 Region
touch_handler_region(gfx::Rect(10, 10, 30, 30));
1525 gfx::PointF
position(25.f
, 25.f
);
1526 gfx::Size
bounds(50, 50);
1527 scoped_ptr
<LayerImpl
> test_layer
=
1528 LayerImpl::Create(host_impl().active_tree(), 12345);
1529 SetLayerPropertiesForTesting(test_layer
.get(), identity_matrix
,
1530 transform_origin
, position
, bounds
, true,
1533 // override content bounds and contents scale
1534 test_layer
->SetContentBounds(gfx::Size(100, 100));
1535 test_layer
->SetContentsScale(2, 2);
1537 test_layer
->SetDrawsContent(true);
1538 test_layer
->SetTouchEventHandlerRegion(touch_handler_region
);
1539 root
->AddChild(test_layer
.Pass());
1542 host_impl().SetViewportSize(root
->bounds());
1543 host_impl().active_tree()->SetRootLayer(root
.Pass());
1544 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1546 // Sanity check the scenario we just created.
1547 // The visible content rect for test_layer is actually 100x100, even though
1548 // its layout size is 50x50, positioned at 25x25.
1549 LayerImpl
* test_layer
=
1550 host_impl().active_tree()->root_layer()->children()[0];
1551 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), test_layer
->visible_content_rect());
1552 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1553 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
1555 // Hit checking for a point outside the layer should return a null pointer
1556 // (the root layer does not draw content, so it will not be tested either).
1557 gfx::Point
test_point(76, 76);
1558 LayerImpl
* result_layer
=
1559 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1561 EXPECT_FALSE(result_layer
);
1563 // Hit checking for a point inside the layer, but outside the touch handler
1564 // region should return a null pointer.
1565 test_point
= gfx::Point(26, 26);
1567 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1569 EXPECT_FALSE(result_layer
);
1571 test_point
= gfx::Point(34, 34);
1573 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1575 EXPECT_FALSE(result_layer
);
1577 test_point
= gfx::Point(65, 65);
1579 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1581 EXPECT_FALSE(result_layer
);
1583 test_point
= gfx::Point(74, 74);
1585 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1587 EXPECT_FALSE(result_layer
);
1589 // Hit checking for a point inside the touch event handler region should
1590 // return the root layer.
1591 test_point
= gfx::Point(35, 35);
1593 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1595 ASSERT_TRUE(result_layer
);
1596 EXPECT_EQ(12345, result_layer
->id());
1598 test_point
= gfx::Point(64, 64);
1600 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1602 ASSERT_TRUE(result_layer
);
1603 EXPECT_EQ(12345, result_layer
->id());
1606 TEST_F(LayerTreeImplTest
,
1607 HitCheckingTouchHandlerRegionsForSingleLayerWithDeviceScale
) {
1608 // The layer's device_scale_factor and page_scale_factor should scale the
1609 // content rect and we should be able to hit the touch handler region by
1610 // scaling the points accordingly.
1611 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl().active_tree(), 1);
1613 gfx::Transform identity_matrix
;
1614 gfx::Point3F transform_origin
;
1615 // Set the bounds of the root layer big enough to fit the child when scaled.
1616 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
1617 gfx::PointF(), gfx::Size(100, 100), true, false,
1620 Region
touch_handler_region(gfx::Rect(10, 10, 30, 30));
1621 gfx::PointF
position(25.f
, 25.f
);
1622 gfx::Size
bounds(50, 50);
1623 scoped_ptr
<LayerImpl
> test_layer
=
1624 LayerImpl::Create(host_impl().active_tree(), 12345);
1625 SetLayerPropertiesForTesting(test_layer
.get(), identity_matrix
,
1626 transform_origin
, position
, bounds
, true,
1629 test_layer
->SetDrawsContent(true);
1630 test_layer
->SetTouchEventHandlerRegion(touch_handler_region
);
1631 root
->AddChild(test_layer
.Pass());
1634 float device_scale_factor
= 3.f
;
1635 float page_scale_factor
= 5.f
;
1636 gfx::Size scaled_bounds_for_root
= gfx::ToCeiledSize(
1637 gfx::ScaleSize(root
->bounds(), device_scale_factor
* page_scale_factor
));
1638 host_impl().SetViewportSize(scaled_bounds_for_root
);
1640 host_impl().SetDeviceScaleFactor(device_scale_factor
);
1641 host_impl().active_tree()->PushPageScaleFromMainThread(
1642 page_scale_factor
, page_scale_factor
, page_scale_factor
);
1643 host_impl().SetPageScaleOnActiveTree(page_scale_factor
);
1644 host_impl().active_tree()->SetRootLayer(root
.Pass());
1645 host_impl().active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID
, 1, 1,
1647 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1649 // Sanity check the scenario we just created.
1650 // The visible content rect for test_layer is actually 100x100, even though
1651 // its layout size is 50x50, positioned at 25x25.
1652 LayerImpl
* test_layer
=
1653 host_impl().active_tree()->root_layer()->children()[0];
1654 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1655 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
1657 // Check whether the child layer fits into the root after scaled.
1658 EXPECT_EQ(gfx::Rect(test_layer
->content_bounds()),
1659 test_layer
->visible_content_rect());
1661 // Hit checking for a point outside the layer should return a null pointer
1662 // (the root layer does not draw content, so it will not be tested either).
1663 gfx::PointF
test_point(76.f
, 76.f
);
1665 gfx::ScalePoint(test_point
, device_scale_factor
* page_scale_factor
);
1666 LayerImpl
* result_layer
=
1667 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1669 EXPECT_FALSE(result_layer
);
1671 // Hit checking for a point inside the layer, but outside the touch handler
1672 // region should return a null pointer.
1673 test_point
= gfx::Point(26, 26);
1675 gfx::ScalePoint(test_point
, device_scale_factor
* page_scale_factor
);
1677 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1679 EXPECT_FALSE(result_layer
);
1681 test_point
= gfx::Point(34, 34);
1683 gfx::ScalePoint(test_point
, device_scale_factor
* page_scale_factor
);
1685 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1687 EXPECT_FALSE(result_layer
);
1689 test_point
= gfx::Point(65, 65);
1691 gfx::ScalePoint(test_point
, device_scale_factor
* page_scale_factor
);
1693 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1695 EXPECT_FALSE(result_layer
);
1697 test_point
= gfx::Point(74, 74);
1699 gfx::ScalePoint(test_point
, device_scale_factor
* page_scale_factor
);
1701 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1703 EXPECT_FALSE(result_layer
);
1705 // Hit checking for a point inside the touch event handler region should
1706 // return the root layer.
1707 test_point
= gfx::Point(35, 35);
1709 gfx::ScalePoint(test_point
, device_scale_factor
* page_scale_factor
);
1711 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1713 ASSERT_TRUE(result_layer
);
1714 EXPECT_EQ(12345, result_layer
->id());
1716 test_point
= gfx::Point(64, 64);
1718 gfx::ScalePoint(test_point
, device_scale_factor
* page_scale_factor
);
1720 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1722 ASSERT_TRUE(result_layer
);
1723 EXPECT_EQ(12345, result_layer
->id());
1726 TEST_F(LayerTreeImplTest
, HitCheckingTouchHandlerRegionsForSimpleClippedLayer
) {
1727 // Test that hit-checking will only work for the visible portion of a layer,
1728 // and not the entire layer bounds. Here we just test the simple axis-aligned
1730 gfx::Transform identity_matrix
;
1731 gfx::Point3F transform_origin
;
1733 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl().active_tree(), 1);
1734 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
1735 gfx::PointF(), gfx::Size(100, 100), true, false,
1738 scoped_ptr
<LayerImpl
> clipping_layer
=
1739 LayerImpl::Create(host_impl().active_tree(), 123);
1740 // this layer is positioned, and hit testing should correctly know where the
1741 // layer is located.
1742 gfx::PointF
position(25.f
, 25.f
);
1743 gfx::Size
bounds(50, 50);
1744 SetLayerPropertiesForTesting(clipping_layer
.get(), identity_matrix
,
1745 transform_origin
, position
, bounds
, true,
1747 clipping_layer
->SetMasksToBounds(true);
1749 scoped_ptr
<LayerImpl
> child
=
1750 LayerImpl::Create(host_impl().active_tree(), 456);
1751 Region
touch_handler_region(gfx::Rect(10, 10, 50, 50));
1752 position
= gfx::PointF(-50.f
, -50.f
);
1753 bounds
= gfx::Size(300, 300);
1754 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, transform_origin
,
1755 position
, bounds
, true, false, false);
1756 child
->SetDrawsContent(true);
1757 child
->SetTouchEventHandlerRegion(touch_handler_region
);
1758 clipping_layer
->AddChild(child
.Pass());
1759 root
->AddChild(clipping_layer
.Pass());
1762 host_impl().SetViewportSize(root
->bounds());
1763 host_impl().active_tree()->SetRootLayer(root
.Pass());
1764 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1766 // Sanity check the scenario we just created.
1767 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1768 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
1769 ASSERT_EQ(456, root_layer()->render_surface()->layer_list().at(0)->id());
1771 // Hit checking for a point outside the layer should return a null pointer.
1772 // Despite the child layer being very large, it should be clipped to the root
1774 gfx::Point
test_point(24, 24);
1775 LayerImpl
* result_layer
=
1776 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1778 EXPECT_FALSE(result_layer
);
1780 // Hit checking for a point inside the layer, but outside the touch handler
1781 // region should return a null pointer.
1782 test_point
= gfx::Point(35, 35);
1784 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1786 EXPECT_FALSE(result_layer
);
1788 test_point
= gfx::Point(74, 74);
1790 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1792 EXPECT_FALSE(result_layer
);
1794 // Hit checking for a point inside the touch event handler region should
1795 // return the root layer.
1796 test_point
= gfx::Point(25, 25);
1798 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1800 ASSERT_TRUE(result_layer
);
1801 EXPECT_EQ(456, result_layer
->id());
1803 test_point
= gfx::Point(34, 34);
1805 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1807 ASSERT_TRUE(result_layer
);
1808 EXPECT_EQ(456, result_layer
->id());
1811 TEST_F(LayerTreeImplTest
, HitCheckingTouchHandlerOverlappingRegions
) {
1812 gfx::Transform identity_matrix
;
1813 gfx::Point3F transform_origin
;
1815 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl().active_tree(), 1);
1816 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
1817 gfx::PointF(), gfx::Size(100, 100), true, false,
1820 scoped_ptr
<LayerImpl
> touch_layer
=
1821 LayerImpl::Create(host_impl().active_tree(), 123);
1822 // this layer is positioned, and hit testing should correctly know where the
1823 // layer is located.
1824 gfx::PointF position
;
1825 gfx::Size
bounds(50, 50);
1826 SetLayerPropertiesForTesting(touch_layer
.get(), identity_matrix
,
1827 transform_origin
, position
, bounds
, true,
1829 touch_layer
->SetDrawsContent(true);
1830 touch_layer
->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 50, 50));
1831 root
->AddChild(touch_layer
.Pass());
1835 scoped_ptr
<LayerImpl
> notouch_layer
=
1836 LayerImpl::Create(host_impl().active_tree(), 1234);
1837 // this layer is positioned, and hit testing should correctly know where the
1838 // layer is located.
1839 gfx::PointF
position(0, 25);
1840 gfx::Size
bounds(50, 50);
1841 SetLayerPropertiesForTesting(notouch_layer
.get(), identity_matrix
,
1842 transform_origin
, position
, bounds
, true,
1844 notouch_layer
->SetDrawsContent(true);
1845 root
->AddChild(notouch_layer
.Pass());
1848 host_impl().SetViewportSize(root
->bounds());
1849 host_impl().active_tree()->SetRootLayer(root
.Pass());
1850 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1852 // Sanity check the scenario we just created.
1853 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1854 ASSERT_EQ(2u, root_layer()->render_surface()->layer_list().size());
1855 ASSERT_EQ(123, root_layer()->render_surface()->layer_list().at(0)->id());
1856 ASSERT_EQ(1234, root_layer()->render_surface()->layer_list().at(1)->id());
1858 gfx::Point
test_point(35, 35);
1859 LayerImpl
* result_layer
=
1860 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1863 // We should have passed through the no-touch layer and found the layer
1865 EXPECT_TRUE(result_layer
);
1867 host_impl().active_tree()->LayerById(1234)->SetContentsOpaque(true);
1869 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1872 // Even with an opaque layer in the middle, we should still find the layer
1874 // the touch handler behind it (since we can't assume that opaque layers are
1875 // opaque to hit testing).
1876 EXPECT_TRUE(result_layer
);
1878 test_point
= gfx::Point(35, 15);
1880 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1882 ASSERT_TRUE(result_layer
);
1883 EXPECT_EQ(123, result_layer
->id());
1885 test_point
= gfx::Point(35, 65);
1887 host_impl().active_tree()->FindLayerThatIsHitByPointInTouchHandlerRegion(
1889 EXPECT_FALSE(result_layer
);
1892 TEST_F(LayerTreeImplTest
, SelectionBoundsForSingleLayer
) {
1893 int root_layer_id
= 12345;
1894 scoped_ptr
<LayerImpl
> root
=
1895 LayerImpl::Create(host_impl().active_tree(), root_layer_id
);
1897 gfx::Transform identity_matrix
;
1898 gfx::Point3F transform_origin
;
1899 gfx::PointF position
;
1900 gfx::Size
bounds(100, 100);
1901 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
1902 position
, bounds
, true, false, true);
1903 root
->SetDrawsContent(true);
1905 host_impl().SetViewportSize(root
->bounds());
1906 host_impl().active_tree()->SetRootLayer(root
.Pass());
1907 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
1909 // Sanity check the scenario we just created.
1910 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
1911 ASSERT_EQ(1u, root_layer()->render_surface()->layer_list().size());
1913 LayerSelectionBound left_input
;
1914 left_input
.type
= SELECTION_BOUND_LEFT
;
1915 left_input
.edge_top
= gfx::PointF(10, 10);
1916 left_input
.edge_bottom
= gfx::PointF(10, 20);
1917 left_input
.layer_id
= root_layer_id
;
1919 LayerSelectionBound right_input
;
1920 right_input
.type
= SELECTION_BOUND_RIGHT
;
1921 right_input
.edge_top
= gfx::PointF(50, 10);
1922 right_input
.edge_bottom
= gfx::PointF(50, 30);
1923 right_input
.layer_id
= root_layer_id
;
1925 ViewportSelectionBound left_output
, right_output
;
1927 // Empty input bounds should produce empty output bounds.
1928 host_impl().active_tree()->GetViewportSelection(&left_output
, &right_output
);
1929 EXPECT_EQ(ViewportSelectionBound(), left_output
);
1930 EXPECT_EQ(ViewportSelectionBound(), right_output
);
1932 // Selection bounds should produce distinct left and right bounds.
1933 host_impl().active_tree()->RegisterSelection(left_input
, right_input
);
1934 host_impl().active_tree()->GetViewportSelection(&left_output
, &right_output
);
1935 EXPECT_EQ(left_input
.type
, left_output
.type
);
1936 EXPECT_EQ(left_input
.edge_bottom
, left_output
.edge_bottom
);
1937 EXPECT_EQ(left_input
.edge_top
, left_output
.edge_top
);
1938 EXPECT_TRUE(left_output
.visible
);
1939 EXPECT_EQ(right_input
.type
, right_output
.type
);
1940 EXPECT_EQ(right_input
.edge_bottom
, right_output
.edge_bottom
);
1941 EXPECT_EQ(right_input
.edge_top
, right_output
.edge_top
);
1942 EXPECT_TRUE(right_output
.visible
);
1944 // Insertion bounds should produce identical left and right bounds.
1945 LayerSelectionBound insertion_input
;
1946 insertion_input
.type
= SELECTION_BOUND_CENTER
;
1947 insertion_input
.edge_top
= gfx::PointF(15, 10);
1948 insertion_input
.edge_bottom
= gfx::PointF(15, 30);
1949 insertion_input
.layer_id
= root_layer_id
;
1950 host_impl().active_tree()->RegisterSelection(insertion_input
,
1951 LayerSelectionBound());
1952 host_impl().active_tree()->GetViewportSelection(&left_output
, &right_output
);
1953 EXPECT_EQ(insertion_input
.type
, left_output
.type
);
1954 EXPECT_EQ(insertion_input
.edge_bottom
, left_output
.edge_bottom
);
1955 EXPECT_EQ(insertion_input
.edge_top
, left_output
.edge_top
);
1956 EXPECT_TRUE(left_output
.visible
);
1957 EXPECT_EQ(left_output
, right_output
);
1960 TEST_F(LayerTreeImplTest
, SelectionBoundsForPartialOccludedLayers
) {
1961 int root_layer_id
= 12345;
1962 int clip_layer_id
= 1234;
1963 int clipped_layer_id
= 123;
1964 scoped_ptr
<LayerImpl
> root
=
1965 LayerImpl::Create(host_impl().active_tree(), root_layer_id
);
1966 root
->SetDrawsContent(true);
1968 gfx::Transform identity_matrix
;
1969 gfx::Point3F transform_origin
;
1970 gfx::PointF position
;
1971 gfx::Size
bounds(100, 100);
1972 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
1973 position
, bounds
, true, false, true);
1975 gfx::Vector2dF
clipping_offset(10, 10);
1977 scoped_ptr
<LayerImpl
> clipping_layer
=
1978 LayerImpl::Create(host_impl().active_tree(), clip_layer_id
);
1979 // The clipping layer should occlude the right selection bound.
1980 gfx::PointF position
= gfx::PointF() + clipping_offset
;
1981 gfx::Size
bounds(50, 50);
1982 SetLayerPropertiesForTesting(clipping_layer
.get(), identity_matrix
,
1983 transform_origin
, position
, bounds
, true,
1985 clipping_layer
->SetMasksToBounds(true);
1987 scoped_ptr
<LayerImpl
> clipped_layer
=
1988 LayerImpl::Create(host_impl().active_tree(), clipped_layer_id
);
1989 position
= gfx::PointF();
1990 bounds
= gfx::Size(100, 100);
1991 SetLayerPropertiesForTesting(clipped_layer
.get(), identity_matrix
,
1992 transform_origin
, position
, bounds
, true,
1994 clipped_layer
->SetDrawsContent(true);
1995 clipping_layer
->AddChild(clipped_layer
.Pass());
1996 root
->AddChild(clipping_layer
.Pass());
1999 host_impl().SetViewportSize(root
->bounds());
2000 host_impl().active_tree()->SetRootLayer(root
.Pass());
2001 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
2003 // Sanity check the scenario we just created.
2004 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
2006 LayerSelectionBound left_input
;
2007 left_input
.type
= SELECTION_BOUND_LEFT
;
2008 left_input
.edge_top
= gfx::PointF(25, 10);
2009 left_input
.edge_bottom
= gfx::PointF(25, 30);
2010 left_input
.layer_id
= clipped_layer_id
;
2012 LayerSelectionBound right_input
;
2013 right_input
.type
= SELECTION_BOUND_RIGHT
;
2014 right_input
.edge_top
= gfx::PointF(75, 10);
2015 right_input
.edge_bottom
= gfx::PointF(75, 30);
2016 right_input
.layer_id
= clipped_layer_id
;
2017 host_impl().active_tree()->RegisterSelection(left_input
, right_input
);
2019 // The left bound should be occluded by the clip layer.
2020 ViewportSelectionBound left_output
, right_output
;
2021 host_impl().active_tree()->GetViewportSelection(&left_output
, &right_output
);
2022 EXPECT_EQ(left_input
.type
, left_output
.type
);
2023 gfx::PointF expected_left_output_top
= left_input
.edge_top
;
2024 gfx::PointF expected_left_output_bottom
= left_input
.edge_bottom
;
2025 expected_left_output_top
.Offset(clipping_offset
.x(), clipping_offset
.y());
2026 expected_left_output_bottom
.Offset(clipping_offset
.x(), clipping_offset
.y());
2027 EXPECT_EQ(expected_left_output_top
, left_output
.edge_top
);
2028 EXPECT_EQ(expected_left_output_bottom
, left_output
.edge_bottom
);
2029 EXPECT_TRUE(left_output
.visible
);
2030 EXPECT_EQ(right_input
.type
, right_output
.type
);
2031 gfx::PointF expected_right_output_top
= right_input
.edge_top
;
2032 gfx::PointF expected_right_output_bottom
= right_input
.edge_bottom
;
2033 expected_right_output_bottom
.Offset(clipping_offset
.x(), clipping_offset
.y());
2034 expected_right_output_top
.Offset(clipping_offset
.x(), clipping_offset
.y());
2035 EXPECT_EQ(expected_right_output_top
, right_output
.edge_top
);
2036 EXPECT_EQ(expected_right_output_bottom
, right_output
.edge_bottom
);
2037 EXPECT_FALSE(right_output
.visible
);
2039 // Handles outside the viewport bounds should be marked invisible.
2040 left_input
.edge_top
= gfx::PointF(-25, 0);
2041 left_input
.edge_bottom
= gfx::PointF(-25, 20);
2042 host_impl().active_tree()->RegisterSelection(left_input
, right_input
);
2043 host_impl().active_tree()->GetViewportSelection(&left_output
, &right_output
);
2044 EXPECT_FALSE(left_output
.visible
);
2046 left_input
.edge_top
= gfx::PointF(0, -25);
2047 left_input
.edge_bottom
= gfx::PointF(0, -5);
2048 host_impl().active_tree()->RegisterSelection(left_input
, right_input
);
2049 host_impl().active_tree()->GetViewportSelection(&left_output
, &right_output
);
2050 EXPECT_FALSE(left_output
.visible
);
2052 // If the handle bottom is partially visible, the handle is marked visible.
2053 left_input
.edge_top
= gfx::PointF(0, -20);
2054 left_input
.edge_bottom
= gfx::PointF(0, 1);
2055 host_impl().active_tree()->RegisterSelection(left_input
, right_input
);
2056 host_impl().active_tree()->GetViewportSelection(&left_output
, &right_output
);
2057 EXPECT_TRUE(left_output
.visible
);
2060 TEST_F(LayerTreeImplTest
, SelectionBoundsForScaledLayers
) {
2061 int root_layer_id
= 1;
2062 int sub_layer_id
= 2;
2063 scoped_ptr
<LayerImpl
> root
=
2064 LayerImpl::Create(host_impl().active_tree(), root_layer_id
);
2065 root
->SetDrawsContent(true);
2067 gfx::Transform identity_matrix
;
2068 gfx::Point3F transform_origin
;
2069 gfx::PointF position
;
2070 gfx::Size
bounds(100, 100);
2071 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
2072 position
, bounds
, true, false, true);
2074 gfx::Vector2dF
sub_layer_offset(10, 0);
2076 scoped_ptr
<LayerImpl
> sub_layer
=
2077 LayerImpl::Create(host_impl().active_tree(), sub_layer_id
);
2078 gfx::PointF position
= gfx::PointF() + sub_layer_offset
;
2079 gfx::Size
bounds(50, 50);
2080 SetLayerPropertiesForTesting(sub_layer
.get(), identity_matrix
,
2081 transform_origin
, position
, bounds
, true,
2083 sub_layer
->SetDrawsContent(true);
2084 root
->AddChild(sub_layer
.Pass());
2087 float device_scale_factor
= 3.f
;
2088 float page_scale_factor
= 5.f
;
2089 gfx::Size scaled_bounds_for_root
= gfx::ToCeiledSize(
2090 gfx::ScaleSize(root
->bounds(), device_scale_factor
* page_scale_factor
));
2091 host_impl().SetViewportSize(scaled_bounds_for_root
);
2093 host_impl().SetDeviceScaleFactor(device_scale_factor
);
2094 host_impl().active_tree()->PushPageScaleFromMainThread(
2095 page_scale_factor
, page_scale_factor
, page_scale_factor
);
2096 host_impl().SetPageScaleOnActiveTree(page_scale_factor
);
2097 host_impl().active_tree()->SetRootLayer(root
.Pass());
2098 host_impl().active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID
, 1, 1,
2100 host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
2102 // Sanity check the scenario we just created.
2103 ASSERT_EQ(1u, RenderSurfaceLayerList().size());
2105 LayerSelectionBound left_input
;
2106 left_input
.type
= SELECTION_BOUND_LEFT
;
2107 left_input
.edge_top
= gfx::PointF(10, 10);
2108 left_input
.edge_bottom
= gfx::PointF(10, 30);
2109 left_input
.layer_id
= root_layer_id
;
2111 LayerSelectionBound right_input
;
2112 right_input
.type
= SELECTION_BOUND_RIGHT
;
2113 right_input
.edge_top
= gfx::PointF(0, 0);
2114 right_input
.edge_bottom
= gfx::PointF(0, 20);
2115 right_input
.layer_id
= sub_layer_id
;
2116 host_impl().active_tree()->RegisterSelection(left_input
, right_input
);
2118 // The viewport bounds should be properly scaled by the page scale, but should
2119 // remain in DIP coordinates.
2120 ViewportSelectionBound left_output
, right_output
;
2121 host_impl().active_tree()->GetViewportSelection(&left_output
, &right_output
);
2122 EXPECT_EQ(left_input
.type
, left_output
.type
);
2123 gfx::PointF expected_left_output_top
= left_input
.edge_top
;
2124 gfx::PointF expected_left_output_bottom
= left_input
.edge_bottom
;
2125 expected_left_output_top
.Scale(page_scale_factor
);
2126 expected_left_output_bottom
.Scale(page_scale_factor
);
2127 EXPECT_EQ(left_input
.edge_top
, left_output
.edge_top
);
2128 EXPECT_EQ(left_input
.edge_bottom
, left_output
.edge_bottom
);
2129 EXPECT_TRUE(left_output
.visible
);
2130 EXPECT_EQ(right_input
.type
, right_output
.type
);
2132 gfx::PointF expected_right_output_top
= right_input
.edge_top
;
2133 gfx::PointF expected_right_output_bottom
= right_input
.edge_bottom
;
2134 expected_right_output_top
.Offset(sub_layer_offset
.x(), sub_layer_offset
.y());
2135 expected_right_output_bottom
.Offset(sub_layer_offset
.x(),
2136 sub_layer_offset
.y());
2137 expected_right_output_top
.Scale(page_scale_factor
);
2138 expected_right_output_bottom
.Scale(page_scale_factor
);
2139 EXPECT_EQ(expected_right_output_top
, right_output
.edge_top
);
2140 EXPECT_EQ(expected_right_output_bottom
, right_output
.edge_bottom
);
2141 EXPECT_TRUE(right_output
.visible
);
2144 TEST_F(LayerTreeImplTest
, NumLayersTestOne
) {
2145 EXPECT_EQ(0u, host_impl().active_tree()->NumLayers());
2146 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl().active_tree(), 1);
2147 EXPECT_EQ(1u, host_impl().active_tree()->NumLayers());
2150 TEST_F(LayerTreeImplTest
, NumLayersSmallTree
) {
2151 EXPECT_EQ(0u, host_impl().active_tree()->NumLayers());
2152 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl().active_tree(), 1);
2153 root
->AddChild(LayerImpl::Create(host_impl().active_tree(), 2));
2154 root
->AddChild(LayerImpl::Create(host_impl().active_tree(), 3));
2155 root
->child_at(1)->AddChild(LayerImpl::Create(host_impl().active_tree(), 4));
2156 EXPECT_EQ(4u, host_impl().active_tree()->NumLayers());