1 // Copyright 2011 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_host_common.h"
10 #include "cc/animation/layer_animation_controller.h"
11 #include "cc/animation/transform_operations.h"
12 #include "cc/base/math_util.h"
13 #include "cc/layers/content_layer_client.h"
14 #include "cc/layers/layer.h"
15 #include "cc/layers/layer_client.h"
16 #include "cc/layers/layer_impl.h"
17 #include "cc/layers/layer_iterator.h"
18 #include "cc/layers/render_surface.h"
19 #include "cc/layers/render_surface_impl.h"
20 #include "cc/output/copy_output_request.h"
21 #include "cc/output/copy_output_result.h"
22 #include "cc/test/animation_test_common.h"
23 #include "cc/test/fake_content_layer_client.h"
24 #include "cc/test/fake_impl_proxy.h"
25 #include "cc/test/fake_layer_tree_host.h"
26 #include "cc/test/fake_layer_tree_host_impl.h"
27 #include "cc/test/fake_picture_layer.h"
28 #include "cc/test/fake_picture_layer_impl.h"
29 #include "cc/test/geometry_test_utils.h"
30 #include "cc/test/layer_tree_host_common_test.h"
31 #include "cc/test/test_task_graph_runner.h"
32 #include "cc/trees/layer_tree_impl.h"
33 #include "cc/trees/proxy.h"
34 #include "cc/trees/single_thread_proxy.h"
35 #include "testing/gmock/include/gmock/gmock.h"
36 #include "testing/gtest/include/gtest/gtest.h"
37 #include "ui/gfx/geometry/quad_f.h"
38 #include "ui/gfx/geometry/vector2d_conversions.h"
39 #include "ui/gfx/transform.h"
44 class LayerWithForcedDrawsContent
: public Layer
{
46 explicit LayerWithForcedDrawsContent(const LayerSettings
& settings
)
49 bool DrawsContent() const override
;
52 ~LayerWithForcedDrawsContent() override
{}
55 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
57 class MockContentLayerClient
: public ContentLayerClient
{
59 MockContentLayerClient() {}
60 ~MockContentLayerClient() override
{}
61 void PaintContents(SkCanvas
* canvas
,
62 const gfx::Rect
& clip
,
63 PaintingControlSetting picture_control
) override
{}
64 scoped_refptr
<DisplayItemList
> PaintContentsToDisplayList(
65 const gfx::Rect
& clip
,
66 PaintingControlSetting picture_control
) override
{
70 bool FillsBoundsCompletely() const override
{ return false; }
73 scoped_refptr
<FakePictureLayer
> CreateDrawablePictureLayer(
74 const LayerSettings
& settings
,
75 ContentLayerClient
* delegate
) {
76 scoped_refptr
<FakePictureLayer
> to_return
=
77 FakePictureLayer::Create(settings
, delegate
);
78 to_return
->SetIsDrawable(true);
82 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
84 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
85 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
88 #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
90 EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \
93 class LayerTreeSettingsScaleContent
: public LayerTreeSettings
{
95 LayerTreeSettingsScaleContent() {
96 layer_transforms_should_scale_layer_contents
= true;
100 class LayerTreeHostCommonScalingTest
: public LayerTreeHostCommonTest
{
102 LayerTreeHostCommonScalingTest()
103 : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {}
106 TEST_F(LayerTreeHostCommonTest
, TransformsForNoOpLayer
) {
107 // Sanity check: For layers positioned at zero, with zero size,
108 // and with identity transforms, then the draw transform,
109 // screen space transform, and the hierarchy passed on to children
110 // layers should also be identity transforms.
112 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
113 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
114 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
115 parent
->AddChild(child
);
116 child
->AddChild(grand_child
);
118 host()->SetRootLayer(parent
);
120 gfx::Transform identity_matrix
;
121 SetLayerPropertiesForTesting(parent
.get(),
128 SetLayerPropertiesForTesting(child
.get(),
135 SetLayerPropertiesForTesting(grand_child
.get(),
143 ExecuteCalculateDrawProperties(parent
.get());
145 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
146 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
147 child
->screen_space_transform());
148 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
149 grand_child
->draw_transform());
150 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
151 grand_child
->screen_space_transform());
154 TEST_F(LayerTreeHostCommonTest
, DoNotSkipLayersWithHandlers
) {
155 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
156 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
157 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
158 parent
->AddChild(child
);
159 child
->AddChild(grand_child
);
161 host()->SetRootLayer(parent
);
163 gfx::Transform identity_matrix
;
164 SetLayerPropertiesForTesting(parent
.get(),
171 SetLayerPropertiesForTesting(child
.get(),
178 // This would have previously caused us to skip our subtree, but this would be
179 // wrong; we need up-to-date draw properties to do hit testing on the layers
181 child
->SetOpacity(0.f
);
182 SetLayerPropertiesForTesting(grand_child
.get(),
189 grand_child
->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
191 ExecuteCalculateDrawProperties(parent
.get());
193 // Check that we've computed draw properties for the subtree rooted at
195 EXPECT_FALSE(child
->draw_transform().IsIdentity());
196 EXPECT_FALSE(grand_child
->draw_transform().IsIdentity());
199 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleLayer
) {
200 gfx::Transform identity_matrix
;
201 scoped_refptr
<Layer
> layer
= Layer::Create(layer_settings());
203 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
204 SetLayerPropertiesForTesting(root
.get(),
211 root
->AddChild(layer
);
213 host()->SetRootLayer(root
);
215 // Case 2: Setting the bounds of the layer should not affect either the draw
216 // transform or the screenspace transform.
217 gfx::Transform translation_to_center
;
218 translation_to_center
.Translate(5.0, 6.0);
219 SetLayerPropertiesForTesting(layer
.get(),
226 ExecuteCalculateDrawProperties(root
.get());
227 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
228 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
229 layer
->screen_space_transform());
231 // Case 3: The anchor point by itself (without a layer transform) should have
232 // no effect on the transforms.
233 SetLayerPropertiesForTesting(layer
.get(),
235 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
240 ExecuteCalculateDrawProperties(root
.get());
241 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
242 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
243 layer
->screen_space_transform());
245 // Case 4: A change in actual position affects both the draw transform and
246 // screen space transform.
247 gfx::Transform position_transform
;
248 position_transform
.Translate(0.f
, 1.2f
);
249 SetLayerPropertiesForTesting(layer
.get(),
251 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
252 gfx::PointF(0.f
, 1.2f
),
256 ExecuteCalculateDrawProperties(root
.get());
257 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
, layer
->draw_transform());
258 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
,
259 layer
->screen_space_transform());
261 // Case 5: In the correct sequence of transforms, the layer transform should
262 // pre-multiply the translation_to_center. This is easily tested by using a
263 // scale transform, because scale and translation are not commutative.
264 gfx::Transform layer_transform
;
265 layer_transform
.Scale3d(2.0, 2.0, 1.0);
266 SetLayerPropertiesForTesting(layer
.get(),
273 ExecuteCalculateDrawProperties(root
.get());
274 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
, layer
->draw_transform());
275 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
,
276 layer
->screen_space_transform());
278 // Case 6: The layer transform should occur with respect to the anchor point.
279 gfx::Transform translation_to_anchor
;
280 translation_to_anchor
.Translate(5.0, 0.0);
281 gfx::Transform expected_result
=
282 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
283 SetLayerPropertiesForTesting(layer
.get(),
285 gfx::Point3F(5.0f
, 0.f
, 0.f
),
290 ExecuteCalculateDrawProperties(root
.get());
291 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
292 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
293 layer
->screen_space_transform());
295 // Case 7: Verify that position pre-multiplies the layer transform. The
296 // current implementation of CalculateDrawProperties does this implicitly, but
297 // it is still worth testing to detect accidental regressions.
298 expected_result
= position_transform
* translation_to_anchor
*
299 layer_transform
* Inverse(translation_to_anchor
);
300 SetLayerPropertiesForTesting(layer
.get(),
302 gfx::Point3F(5.0f
, 0.f
, 0.f
),
303 gfx::PointF(0.f
, 1.2f
),
307 ExecuteCalculateDrawProperties(root
.get());
308 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
309 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
310 layer
->screen_space_transform());
313 TEST_F(LayerTreeHostCommonTest
, TransformsAboutScrollOffset
) {
314 const gfx::ScrollOffset
kScrollOffset(50, 100);
315 const gfx::Vector2dF
kScrollDelta(2.34f
, 5.67f
);
316 const gfx::Vector2d
kMaxScrollOffset(200, 200);
317 const gfx::PointF
kScrollLayerPosition(-kScrollOffset
.x(),
319 const float kPageScale
= 0.888f
;
320 const float kDeviceScale
= 1.666f
;
323 TestSharedBitmapManager shared_bitmap_manager
;
324 TestTaskGraphRunner task_graph_runner
;
325 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
328 gfx::Transform identity_matrix
;
329 scoped_ptr
<LayerImpl
> sublayer_scoped_ptr(
330 LayerImpl::Create(host_impl
.active_tree(), 1));
331 LayerImpl
* sublayer
= sublayer_scoped_ptr
.get();
332 SetLayerPropertiesForTesting(sublayer
, identity_matrix
, gfx::Point3F(),
333 gfx::PointF(), gfx::Size(500, 500), true, false,
336 scoped_ptr
<LayerImpl
> scroll_layer_scoped_ptr(
337 LayerImpl::Create(host_impl
.active_tree(), 2));
338 LayerImpl
* scroll_layer
= scroll_layer_scoped_ptr
.get();
339 SetLayerPropertiesForTesting(scroll_layer
, identity_matrix
, gfx::Point3F(),
340 gfx::PointF(), gfx::Size(10, 20), true, false,
342 scoped_ptr
<LayerImpl
> clip_layer_scoped_ptr(
343 LayerImpl::Create(host_impl
.active_tree(), 4));
344 LayerImpl
* clip_layer
= clip_layer_scoped_ptr
.get();
346 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
347 clip_layer
->SetBounds(
348 gfx::Size(scroll_layer
->bounds().width() + kMaxScrollOffset
.x(),
349 scroll_layer
->bounds().height() + kMaxScrollOffset
.y()));
350 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
351 scroll_layer
->SetScrollDelta(kScrollDelta
);
352 gfx::Transform impl_transform
;
353 scroll_layer
->AddChild(sublayer_scoped_ptr
.Pass());
354 LayerImpl
* scroll_layer_raw_ptr
= scroll_layer_scoped_ptr
.get();
355 clip_layer
->AddChild(scroll_layer_scoped_ptr
.Pass());
356 scroll_layer_raw_ptr
->PushScrollOffsetFromMainThread(kScrollOffset
);
358 scoped_ptr
<LayerImpl
> root(LayerImpl::Create(host_impl
.active_tree(), 3));
359 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
360 gfx::PointF(), gfx::Size(3, 4), true, false,
362 root
->AddChild(clip_layer_scoped_ptr
.Pass());
363 root
->SetHasRenderSurface(true);
365 ExecuteCalculateDrawProperties(
366 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
367 gfx::Transform expected_transform
= identity_matrix
;
368 gfx::PointF sub_layer_screen_position
= kScrollLayerPosition
- kScrollDelta
;
369 expected_transform
.Translate(MathUtil::Round(sub_layer_screen_position
.x() *
370 kPageScale
* kDeviceScale
),
371 MathUtil::Round(sub_layer_screen_position
.y() *
372 kPageScale
* kDeviceScale
));
373 expected_transform
.Scale(kPageScale
* kDeviceScale
,
374 kPageScale
* kDeviceScale
);
375 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
376 sublayer
->draw_transform());
377 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
378 sublayer
->screen_space_transform());
380 gfx::Transform arbitrary_translate
;
381 const float kTranslateX
= 10.6f
;
382 const float kTranslateY
= 20.6f
;
383 arbitrary_translate
.Translate(kTranslateX
, kTranslateY
);
384 SetLayerPropertiesForTesting(scroll_layer
, arbitrary_translate
,
385 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
387 ExecuteCalculateDrawProperties(
388 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
389 expected_transform
.MakeIdentity();
390 expected_transform
.Translate(
391 MathUtil::Round(kTranslateX
* kPageScale
* kDeviceScale
+
392 sub_layer_screen_position
.x() * kPageScale
*
394 MathUtil::Round(kTranslateY
* kPageScale
* kDeviceScale
+
395 sub_layer_screen_position
.y() * kPageScale
*
397 expected_transform
.Scale(kPageScale
* kDeviceScale
,
398 kPageScale
* kDeviceScale
);
399 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
400 sublayer
->draw_transform());
403 TEST_F(LayerTreeHostCommonTest
, TransformsForSimpleHierarchy
) {
404 gfx::Transform identity_matrix
;
405 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
406 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
407 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
408 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
409 root
->AddChild(parent
);
410 parent
->AddChild(child
);
411 child
->AddChild(grand_child
);
413 host()->SetRootLayer(root
);
415 // One-time setup of root layer
416 SetLayerPropertiesForTesting(root
.get(),
424 // Case 1: parent's anchor point should not affect child or grand_child.
425 SetLayerPropertiesForTesting(parent
.get(),
427 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
432 SetLayerPropertiesForTesting(child
.get(),
439 SetLayerPropertiesForTesting(grand_child
.get(),
446 ExecuteCalculateDrawProperties(root
.get());
447 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
448 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
449 child
->screen_space_transform());
450 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
451 grand_child
->draw_transform());
452 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
453 grand_child
->screen_space_transform());
455 // Case 2: parent's position affects child and grand_child.
456 gfx::Transform parent_position_transform
;
457 parent_position_transform
.Translate(0.f
, 1.2f
);
458 SetLayerPropertiesForTesting(parent
.get(),
460 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
461 gfx::PointF(0.f
, 1.2f
),
465 SetLayerPropertiesForTesting(child
.get(),
472 SetLayerPropertiesForTesting(grand_child
.get(),
479 ExecuteCalculateDrawProperties(root
.get());
480 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
481 child
->draw_transform());
482 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
483 child
->screen_space_transform());
484 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
485 grand_child
->draw_transform());
486 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
487 grand_child
->screen_space_transform());
489 // Case 3: parent's local transform affects child and grandchild
490 gfx::Transform parent_layer_transform
;
491 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
492 gfx::Transform parent_translation_to_anchor
;
493 parent_translation_to_anchor
.Translate(2.5, 3.0);
494 gfx::Transform parent_composite_transform
=
495 parent_translation_to_anchor
* parent_layer_transform
*
496 Inverse(parent_translation_to_anchor
);
497 SetLayerPropertiesForTesting(parent
.get(),
498 parent_layer_transform
,
499 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
504 SetLayerPropertiesForTesting(child
.get(),
511 SetLayerPropertiesForTesting(grand_child
.get(),
518 ExecuteCalculateDrawProperties(root
.get());
519 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
520 child
->draw_transform());
521 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
522 child
->screen_space_transform());
523 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
524 grand_child
->draw_transform());
525 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
526 grand_child
->screen_space_transform());
529 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleRenderSurface
) {
530 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
531 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
532 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
533 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
534 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
535 root
->AddChild(parent
);
536 parent
->AddChild(child
);
537 child
->AddChild(grand_child
);
539 host()->SetRootLayer(root
);
541 // One-time setup of root layer
542 gfx::Transform identity_matrix
;
543 SetLayerPropertiesForTesting(root
.get(),
551 // Child is set up so that a new render surface should be created.
552 child
->SetOpacity(0.5f
);
553 child
->SetForceRenderSurface(true);
555 gfx::Transform parent_layer_transform
;
556 parent_layer_transform
.Scale3d(1.f
, 0.9f
, 1.f
);
557 gfx::Transform parent_translation_to_anchor
;
558 parent_translation_to_anchor
.Translate(25.0, 30.0);
560 gfx::Transform parent_composite_transform
=
561 parent_translation_to_anchor
* parent_layer_transform
*
562 Inverse(parent_translation_to_anchor
);
563 gfx::Vector2dF parent_composite_scale
=
564 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
566 gfx::Transform surface_sublayer_transform
;
567 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
568 parent_composite_scale
.y());
569 gfx::Transform surface_sublayer_composite_transform
=
570 parent_composite_transform
* Inverse(surface_sublayer_transform
);
572 // Child's render surface should not exist yet.
573 ASSERT_FALSE(child
->render_surface());
575 SetLayerPropertiesForTesting(parent
.get(),
576 parent_layer_transform
,
577 gfx::Point3F(25.0f
, 30.0f
, 0.f
),
582 SetLayerPropertiesForTesting(child
.get(),
589 SetLayerPropertiesForTesting(grand_child
.get(),
596 ExecuteCalculateDrawProperties(root
.get());
598 // Render surface should have been created now.
599 ASSERT_TRUE(child
->render_surface());
600 ASSERT_EQ(child
.get(), child
->render_target());
602 // The child layer's draw transform should refer to its new render surface.
603 // The screen-space transform, however, should still refer to the root.
604 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform
,
605 child
->draw_transform());
606 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
607 child
->screen_space_transform());
609 // Because the grand_child is the only drawable content, the child's render
610 // surface will tighten its bounds to the grand_child. The scale at which the
611 // surface's subtree is drawn must be removed from the composite transform.
612 EXPECT_TRANSFORMATION_MATRIX_EQ(
613 surface_sublayer_composite_transform
,
614 child
->render_target()->render_surface()->draw_transform());
616 // The screen space is the same as the target since the child surface draws
618 EXPECT_TRANSFORMATION_MATRIX_EQ(
619 surface_sublayer_composite_transform
,
620 child
->render_target()->render_surface()->screen_space_transform());
623 TEST_F(LayerTreeHostCommonTest
, TransformsForReplica
) {
624 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
625 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
626 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
627 scoped_refptr
<Layer
> child_replica
= Layer::Create(layer_settings());
628 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
629 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
630 root
->AddChild(parent
);
631 parent
->AddChild(child
);
632 child
->AddChild(grand_child
);
633 child
->SetReplicaLayer(child_replica
.get());
635 host()->SetRootLayer(root
);
637 // One-time setup of root layer
638 gfx::Transform identity_matrix
;
639 SetLayerPropertiesForTesting(root
.get(),
647 // Child is set up so that a new render surface should be created.
648 child
->SetOpacity(0.5f
);
650 gfx::Transform parent_layer_transform
;
651 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
652 gfx::Transform parent_translation_to_anchor
;
653 parent_translation_to_anchor
.Translate(2.5, 3.0);
654 gfx::Transform parent_composite_transform
=
655 parent_translation_to_anchor
* parent_layer_transform
*
656 Inverse(parent_translation_to_anchor
);
657 gfx::Transform replica_layer_transform
;
658 replica_layer_transform
.Scale3d(3.0, 3.0, 1.0);
659 gfx::Vector2dF parent_composite_scale
=
660 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
662 gfx::Transform surface_sublayer_transform
;
663 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
664 parent_composite_scale
.y());
665 gfx::Transform replica_composite_transform
=
666 parent_composite_transform
* replica_layer_transform
*
667 Inverse(surface_sublayer_transform
);
668 child_replica
->SetIsDrawable(true);
669 // Child's render surface should not exist yet.
670 ASSERT_FALSE(child
->render_surface());
672 SetLayerPropertiesForTesting(parent
.get(),
673 parent_layer_transform
,
674 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
679 SetLayerPropertiesForTesting(child
.get(),
686 SetLayerPropertiesForTesting(grand_child
.get(),
689 gfx::PointF(-0.5f
, -0.5f
),
693 SetLayerPropertiesForTesting(child_replica
.get(),
694 replica_layer_transform
,
700 ExecuteCalculateDrawProperties(root
.get());
702 // Render surface should have been created now.
703 ASSERT_TRUE(child
->render_surface());
704 ASSERT_EQ(child
.get(), child
->render_target());
706 EXPECT_TRANSFORMATION_MATRIX_EQ(
707 replica_composite_transform
,
708 child
->render_target()->render_surface()->replica_draw_transform());
709 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform
,
710 child
->render_target()
712 ->replica_screen_space_transform());
715 TEST_F(LayerTreeHostCommonTest
, TransformsForRenderSurfaceHierarchy
) {
716 // This test creates a more complex tree and verifies it all at once. This
717 // covers the following cases:
718 // - layers that are described w.r.t. a render surface: should have draw
719 // transforms described w.r.t. that surface
720 // - A render surface described w.r.t. an ancestor render surface: should
721 // have a draw transform described w.r.t. that ancestor surface
722 // - Replicas of a render surface are described w.r.t. the replica's
723 // transform around its anchor, along with the surface itself.
724 // - Sanity check on recursion: verify transforms of layers described w.r.t.
725 // a render surface that is described w.r.t. an ancestor render surface.
726 // - verifying that each layer has a reference to the correct render surface
727 // and render target values.
729 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
730 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
731 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
732 scoped_refptr
<Layer
> render_surface2
= Layer::Create(layer_settings());
733 scoped_refptr
<Layer
> child_of_root
= Layer::Create(layer_settings());
734 scoped_refptr
<Layer
> child_of_rs1
= Layer::Create(layer_settings());
735 scoped_refptr
<Layer
> child_of_rs2
= Layer::Create(layer_settings());
736 scoped_refptr
<Layer
> replica_of_rs1
= Layer::Create(layer_settings());
737 scoped_refptr
<Layer
> replica_of_rs2
= Layer::Create(layer_settings());
738 scoped_refptr
<Layer
> grand_child_of_root
= Layer::Create(layer_settings());
739 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs1
=
740 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
741 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs2
=
742 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
743 root
->AddChild(parent
);
744 parent
->AddChild(render_surface1
);
745 parent
->AddChild(child_of_root
);
746 render_surface1
->AddChild(child_of_rs1
);
747 render_surface1
->AddChild(render_surface2
);
748 render_surface2
->AddChild(child_of_rs2
);
749 child_of_root
->AddChild(grand_child_of_root
);
750 child_of_rs1
->AddChild(grand_child_of_rs1
);
751 child_of_rs2
->AddChild(grand_child_of_rs2
);
752 render_surface1
->SetReplicaLayer(replica_of_rs1
.get());
753 render_surface2
->SetReplicaLayer(replica_of_rs2
.get());
755 host()->SetRootLayer(root
);
757 // In combination with descendant draws content, opacity != 1 forces the layer
758 // to have a new render surface.
759 render_surface1
->SetOpacity(0.5f
);
760 render_surface2
->SetOpacity(0.33f
);
762 // One-time setup of root layer
763 gfx::Transform identity_matrix
;
764 SetLayerPropertiesForTesting(root
.get(),
772 // All layers in the tree are initialized with an anchor at .25 and a size of
773 // (10,10). matrix "A" is the composite layer transform used in all layers,
774 // Matrix "R" is the composite replica transform used in all replica layers.
775 gfx::Transform translation_to_anchor
;
776 translation_to_anchor
.Translate(2.5, 0.0);
777 gfx::Transform layer_transform
;
778 layer_transform
.Translate(1.0, 1.0);
779 gfx::Transform replica_layer_transform
;
780 replica_layer_transform
.Scale3d(-2.0, 5.0, 1.0);
783 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
784 gfx::Transform R
= A
* translation_to_anchor
* replica_layer_transform
*
785 Inverse(translation_to_anchor
);
787 gfx::Vector2dF surface1_parent_transform_scale
=
788 MathUtil::ComputeTransform2dScaleComponents(A
, 1.f
);
789 gfx::Transform surface1_sublayer_transform
;
790 surface1_sublayer_transform
.Scale(surface1_parent_transform_scale
.x(),
791 surface1_parent_transform_scale
.y());
793 // SS1 = transform given to the subtree of render_surface1
794 gfx::Transform SS1
= surface1_sublayer_transform
;
795 // S1 = transform to move from render_surface1 pixels to the layer space of
797 gfx::Transform S1
= Inverse(surface1_sublayer_transform
);
799 gfx::Vector2dF surface2_parent_transform_scale
=
800 MathUtil::ComputeTransform2dScaleComponents(SS1
* A
, 1.f
);
801 gfx::Transform surface2_sublayer_transform
;
802 surface2_sublayer_transform
.Scale(surface2_parent_transform_scale
.x(),
803 surface2_parent_transform_scale
.y());
805 // SS2 = transform given to the subtree of render_surface2
806 gfx::Transform SS2
= surface2_sublayer_transform
;
807 // S2 = transform to move from render_surface2 pixels to the layer space of
809 gfx::Transform S2
= Inverse(surface2_sublayer_transform
);
811 SetLayerPropertiesForTesting(parent
.get(),
813 gfx::Point3F(2.5f
, 0.f
, 0.f
),
818 SetLayerPropertiesForTesting(render_surface1
.get(),
820 gfx::Point3F(2.5f
, 0.f
, 0.f
),
825 SetLayerPropertiesForTesting(render_surface2
.get(),
827 gfx::Point3F(2.5f
, 0.f
, 0.f
),
832 SetLayerPropertiesForTesting(child_of_root
.get(),
834 gfx::Point3F(2.5f
, 0.f
, 0.f
),
839 SetLayerPropertiesForTesting(child_of_rs1
.get(),
841 gfx::Point3F(2.5f
, 0.f
, 0.f
),
846 SetLayerPropertiesForTesting(child_of_rs2
.get(),
848 gfx::Point3F(2.5f
, 0.f
, 0.f
),
853 SetLayerPropertiesForTesting(grand_child_of_root
.get(),
855 gfx::Point3F(2.5f
, 0.f
, 0.f
),
860 SetLayerPropertiesForTesting(grand_child_of_rs1
.get(),
862 gfx::Point3F(2.5f
, 0.f
, 0.f
),
867 SetLayerPropertiesForTesting(grand_child_of_rs2
.get(),
869 gfx::Point3F(2.5f
, 0.f
, 0.f
),
874 SetLayerPropertiesForTesting(replica_of_rs1
.get(),
875 replica_layer_transform
,
876 gfx::Point3F(2.5f
, 0.f
, 0.f
),
881 SetLayerPropertiesForTesting(replica_of_rs2
.get(),
882 replica_layer_transform
,
883 gfx::Point3F(2.5f
, 0.f
, 0.f
),
889 ExecuteCalculateDrawProperties(root
.get());
891 // Only layers that are associated with render surfaces should have an actual
892 // RenderSurface() value.
893 ASSERT_TRUE(root
->render_surface());
894 ASSERT_FALSE(child_of_root
->render_surface());
895 ASSERT_FALSE(grand_child_of_root
->render_surface());
897 ASSERT_TRUE(render_surface1
->render_surface());
898 ASSERT_FALSE(child_of_rs1
->render_surface());
899 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
901 ASSERT_TRUE(render_surface2
->render_surface());
902 ASSERT_FALSE(child_of_rs2
->render_surface());
903 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
905 // Verify all render target accessors
906 EXPECT_EQ(root
.get(), parent
->render_target());
907 EXPECT_EQ(root
.get(), child_of_root
->render_target());
908 EXPECT_EQ(root
.get(), grand_child_of_root
->render_target());
910 EXPECT_EQ(render_surface1
.get(), render_surface1
->render_target());
911 EXPECT_EQ(render_surface1
.get(), child_of_rs1
->render_target());
912 EXPECT_EQ(render_surface1
.get(), grand_child_of_rs1
->render_target());
914 EXPECT_EQ(render_surface2
.get(), render_surface2
->render_target());
915 EXPECT_EQ(render_surface2
.get(), child_of_rs2
->render_target());
916 EXPECT_EQ(render_surface2
.get(), grand_child_of_rs2
->render_target());
918 // Verify layer draw transforms note that draw transforms are described with
919 // respect to the nearest ancestor render surface but screen space transforms
920 // are described with respect to the root.
921 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->draw_transform());
922 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
, child_of_root
->draw_transform());
923 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
924 grand_child_of_root
->draw_transform());
926 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
, render_surface1
->draw_transform());
927 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
, child_of_rs1
->draw_transform());
928 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
* A
,
929 grand_child_of_rs1
->draw_transform());
931 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
, render_surface2
->draw_transform());
932 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
, child_of_rs2
->draw_transform());
933 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
* A
,
934 grand_child_of_rs2
->draw_transform());
936 // Verify layer screen-space transforms
938 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->screen_space_transform());
939 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
940 child_of_root
->screen_space_transform());
941 EXPECT_TRANSFORMATION_MATRIX_EQ(
942 A
* A
* A
, grand_child_of_root
->screen_space_transform());
944 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
945 render_surface1
->screen_space_transform());
946 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
947 child_of_rs1
->screen_space_transform());
948 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
949 grand_child_of_rs1
->screen_space_transform());
951 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
952 render_surface2
->screen_space_transform());
953 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
954 child_of_rs2
->screen_space_transform());
955 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
* A
,
956 grand_child_of_rs2
->screen_space_transform());
958 // Verify render surface transforms.
960 // Draw transform of render surface 1 is described with respect to root.
961 EXPECT_TRANSFORMATION_MATRIX_EQ(
962 A
* A
* S1
, render_surface1
->render_surface()->draw_transform());
963 EXPECT_TRANSFORMATION_MATRIX_EQ(
964 A
* R
* S1
, render_surface1
->render_surface()->replica_draw_transform());
965 EXPECT_TRANSFORMATION_MATRIX_EQ(
966 A
* A
* S1
, render_surface1
->render_surface()->screen_space_transform());
967 EXPECT_TRANSFORMATION_MATRIX_EQ(
969 render_surface1
->render_surface()->replica_screen_space_transform());
970 // Draw transform of render surface 2 is described with respect to render
972 EXPECT_TRANSFORMATION_MATRIX_EQ(
973 SS1
* A
* S2
, render_surface2
->render_surface()->draw_transform());
974 EXPECT_TRANSFORMATION_MATRIX_EQ(
976 render_surface2
->render_surface()->replica_draw_transform());
977 EXPECT_TRANSFORMATION_MATRIX_EQ(
979 render_surface2
->render_surface()->screen_space_transform());
980 EXPECT_TRANSFORMATION_MATRIX_EQ(
982 render_surface2
->render_surface()->replica_screen_space_transform());
984 // Sanity check. If these fail there is probably a bug in the test itself. It
985 // is expected that we correctly set up transforms so that the y-component of
986 // the screen-space transform encodes the "depth" of the layer in the tree.
987 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
989 child_of_root
->screen_space_transform().matrix().get(1, 3));
991 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
994 render_surface1
->screen_space_transform().matrix().get(1, 3));
996 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
998 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
1000 EXPECT_FLOAT_EQ(3.0,
1001 render_surface2
->screen_space_transform().matrix().get(1, 3));
1002 EXPECT_FLOAT_EQ(4.0,
1003 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
1005 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
1008 TEST_F(LayerTreeHostCommonTest
, TransformsForFlatteningLayer
) {
1009 // For layers that flatten their subtree, there should be an orthographic
1010 // projection (for x and y values) in the middle of the transform sequence.
1011 // Note that the way the code is currently implemented, it is not expected to
1012 // use a canonical orthographic projection.
1014 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1015 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
1016 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1017 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1018 scoped_refptr
<LayerWithForcedDrawsContent
> great_grand_child
=
1019 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1021 gfx::Transform rotation_about_y_axis
;
1022 rotation_about_y_axis
.RotateAboutYAxis(30.0);
1024 const gfx::Transform identity_matrix
;
1025 SetLayerPropertiesForTesting(root
.get(),
1029 gfx::Size(100, 100),
1032 SetLayerPropertiesForTesting(child
.get(),
1033 rotation_about_y_axis
,
1039 SetLayerPropertiesForTesting(grand_child
.get(),
1040 rotation_about_y_axis
,
1046 SetLayerPropertiesForTesting(great_grand_child
.get(), identity_matrix
,
1047 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1050 root
->AddChild(child
);
1051 child
->AddChild(grand_child
);
1052 grand_child
->AddChild(great_grand_child
);
1053 child
->SetForceRenderSurface(true);
1055 host()->SetRootLayer(root
);
1057 // No layers in this test should preserve 3d.
1058 ASSERT_TRUE(root
->should_flatten_transform());
1059 ASSERT_TRUE(child
->should_flatten_transform());
1060 ASSERT_TRUE(grand_child
->should_flatten_transform());
1061 ASSERT_TRUE(great_grand_child
->should_flatten_transform());
1063 gfx::Transform expected_child_draw_transform
= rotation_about_y_axis
;
1064 gfx::Transform expected_child_screen_space_transform
= rotation_about_y_axis
;
1065 gfx::Transform expected_grand_child_draw_transform
=
1066 rotation_about_y_axis
; // draws onto child's render surface
1067 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
1068 flattened_rotation_about_y
.FlattenTo2d();
1069 gfx::Transform expected_grand_child_screen_space_transform
=
1070 flattened_rotation_about_y
* rotation_about_y_axis
;
1071 gfx::Transform expected_great_grand_child_draw_transform
=
1072 flattened_rotation_about_y
;
1073 gfx::Transform expected_great_grand_child_screen_space_transform
=
1074 flattened_rotation_about_y
* flattened_rotation_about_y
;
1076 ExecuteCalculateDrawProperties(root
.get());
1078 // The child's draw transform should have been taken by its surface.
1079 ASSERT_TRUE(child
->render_surface());
1080 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform
,
1081 child
->render_surface()->draw_transform());
1082 EXPECT_TRANSFORMATION_MATRIX_EQ(
1083 expected_child_screen_space_transform
,
1084 child
->render_surface()->screen_space_transform());
1085 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1086 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform
,
1087 child
->screen_space_transform());
1088 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform
,
1089 grand_child
->draw_transform());
1090 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform
,
1091 grand_child
->screen_space_transform());
1092 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform
,
1093 great_grand_child
->draw_transform());
1094 EXPECT_TRANSFORMATION_MATRIX_EQ(
1095 expected_great_grand_child_screen_space_transform
,
1096 great_grand_child
->screen_space_transform());
1099 TEST_F(LayerTreeHostCommonTest
, TransformsForDegenerateIntermediateLayer
) {
1100 // A layer that is empty in one axis, but not the other, was accidentally
1101 // skipping a necessary translation. Without that translation, the coordinate
1102 // space of the layer's draw transform is incorrect.
1104 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1105 // but if that layer becomes a render surface, then its draw transform is
1106 // implicitly inherited by the rest of the subtree, which then is positioned
1107 // incorrectly as a result.
1109 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1110 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
1111 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1112 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1114 // The child height is zero, but has non-zero width that should be accounted
1115 // for while computing draw transforms.
1116 const gfx::Transform identity_matrix
;
1117 SetLayerPropertiesForTesting(root
.get(),
1121 gfx::Size(100, 100),
1124 SetLayerPropertiesForTesting(child
.get(),
1131 SetLayerPropertiesForTesting(grand_child
.get(),
1139 root
->AddChild(child
);
1140 child
->AddChild(grand_child
);
1141 child
->SetForceRenderSurface(true);
1143 host()->SetRootLayer(root
);
1145 ExecuteCalculateDrawProperties(root
.get());
1147 ASSERT_TRUE(child
->render_surface());
1148 // This is the real test, the rest are sanity checks.
1149 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1150 child
->render_surface()->draw_transform());
1151 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1152 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1153 grand_child
->draw_transform());
1156 TEST_F(LayerTreeHostCommonTest
, TransformAboveRootLayer
) {
1157 // Transformations applied at the root of the tree should be forwarded
1158 // to child layers instead of applied to the root RenderSurface.
1159 const gfx::Transform identity_matrix
;
1160 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
1161 new LayerWithForcedDrawsContent(layer_settings());
1162 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1163 new LayerWithForcedDrawsContent(layer_settings());
1164 child
->SetScrollClipLayerId(root
->id());
1165 root
->AddChild(child
);
1167 host()->SetRootLayer(root
);
1169 SetLayerPropertiesForTesting(root
.get(),
1176 SetLayerPropertiesForTesting(child
.get(),
1184 gfx::Transform translate
;
1185 translate
.Translate(50, 50);
1187 RenderSurfaceLayerList render_surface_layer_list
;
1188 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1189 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1190 inputs
.can_adjust_raster_scales
= true;
1191 inputs
.property_trees
->needs_rebuild
= true;
1192 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1193 EXPECT_EQ(translate
, root
->draw_properties().target_space_transform
);
1194 EXPECT_EQ(translate
, child
->draw_properties().target_space_transform
);
1195 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1198 gfx::Transform scale
;
1201 RenderSurfaceLayerList render_surface_layer_list
;
1202 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1203 root
.get(), root
->bounds(), scale
, &render_surface_layer_list
);
1204 inputs
.can_adjust_raster_scales
= true;
1205 inputs
.property_trees
->needs_rebuild
= true;
1206 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1207 EXPECT_EQ(scale
, root
->draw_properties().target_space_transform
);
1208 EXPECT_EQ(scale
, child
->draw_properties().target_space_transform
);
1209 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1212 gfx::Transform rotate
;
1215 RenderSurfaceLayerList render_surface_layer_list
;
1216 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1217 root
.get(), root
->bounds(), rotate
, &render_surface_layer_list
);
1218 inputs
.can_adjust_raster_scales
= true;
1219 inputs
.property_trees
->needs_rebuild
= true;
1220 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1221 EXPECT_EQ(rotate
, root
->draw_properties().target_space_transform
);
1222 EXPECT_EQ(rotate
, child
->draw_properties().target_space_transform
);
1223 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1226 gfx::Transform composite
;
1227 composite
.ConcatTransform(translate
);
1228 composite
.ConcatTransform(scale
);
1229 composite
.ConcatTransform(rotate
);
1231 RenderSurfaceLayerList render_surface_layer_list
;
1232 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1233 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1234 inputs
.can_adjust_raster_scales
= true;
1235 inputs
.property_trees
->needs_rebuild
= true;
1236 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1237 EXPECT_EQ(composite
, root
->draw_properties().target_space_transform
);
1238 EXPECT_EQ(composite
, child
->draw_properties().target_space_transform
);
1239 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1242 // Verify it composes correctly with device scale.
1243 float device_scale_factor
= 1.5f
;
1246 RenderSurfaceLayerList render_surface_layer_list
;
1247 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1248 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1249 inputs
.device_scale_factor
= device_scale_factor
;
1250 inputs
.can_adjust_raster_scales
= true;
1251 inputs
.property_trees
->needs_rebuild
= true;
1252 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1253 gfx::Transform device_scaled_translate
= translate
;
1254 device_scaled_translate
.Scale(device_scale_factor
, device_scale_factor
);
1255 EXPECT_EQ(device_scaled_translate
,
1256 root
->draw_properties().target_space_transform
);
1257 EXPECT_EQ(device_scaled_translate
,
1258 child
->draw_properties().target_space_transform
);
1259 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1262 // Verify it composes correctly with page scale.
1263 float page_scale_factor
= 2.f
;
1266 RenderSurfaceLayerList render_surface_layer_list
;
1267 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1268 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1269 inputs
.page_scale_factor
= page_scale_factor
;
1270 inputs
.page_scale_layer
= root
.get();
1271 inputs
.can_adjust_raster_scales
= true;
1272 inputs
.property_trees
->needs_rebuild
= true;
1273 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1274 gfx::Transform page_scaled_translate
= translate
;
1275 page_scaled_translate
.Scale(page_scale_factor
, page_scale_factor
);
1276 EXPECT_EQ(page_scaled_translate
,
1277 root
->draw_properties().target_space_transform
);
1278 EXPECT_EQ(page_scaled_translate
,
1279 child
->draw_properties().target_space_transform
);
1280 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1283 // Verify that it composes correctly with transforms directly on root layer.
1284 root
->SetTransform(composite
);
1287 RenderSurfaceLayerList render_surface_layer_list
;
1288 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1289 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1290 inputs
.can_adjust_raster_scales
= true;
1291 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1292 gfx::Transform compositeSquared
= composite
;
1293 compositeSquared
.ConcatTransform(composite
);
1294 EXPECT_TRANSFORMATION_MATRIX_EQ(
1295 compositeSquared
, root
->draw_properties().target_space_transform
);
1296 EXPECT_TRANSFORMATION_MATRIX_EQ(
1297 compositeSquared
, child
->draw_properties().target_space_transform
);
1298 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1302 TEST_F(LayerTreeHostCommonTest
,
1303 RenderSurfaceListForRenderSurfaceWithClippedLayer
) {
1304 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1305 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
1306 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1307 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1309 host()->SetRootLayer(parent
);
1311 const gfx::Transform identity_matrix
;
1312 SetLayerPropertiesForTesting(parent
.get(),
1319 SetLayerPropertiesForTesting(render_surface1
.get(),
1326 SetLayerPropertiesForTesting(child
.get(),
1329 gfx::PointF(30.f
, 30.f
),
1334 parent
->AddChild(render_surface1
);
1335 parent
->SetMasksToBounds(true);
1336 render_surface1
->AddChild(child
);
1337 render_surface1
->SetForceRenderSurface(true);
1339 RenderSurfaceLayerList render_surface_layer_list
;
1340 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1344 &render_surface_layer_list
);
1345 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1347 // The child layer's content is entirely outside the parent's clip rect, so
1348 // the intermediate render surface should not be listed here, even if it was
1349 // forced to be created. Render surfaces without children or visible content
1350 // are unexpected at draw time (e.g. we might try to create a content texture
1352 ASSERT_TRUE(parent
->render_surface());
1353 EXPECT_EQ(1U, render_surface_layer_list
.size());
1356 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceListForTransparentChild
) {
1357 LayerImpl
* parent
= root_layer();
1358 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(parent
);
1359 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface1
);
1360 child
->SetDrawsContent(true);
1362 const gfx::Transform identity_matrix
;
1363 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
1364 gfx::PointF(), gfx::Size(10, 10), true, false,
1366 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1367 gfx::PointF(), gfx::Size(10, 10), true, false,
1369 render_surface1
->SetOpacity(0.f
);
1371 LayerImplList render_surface_layer_list
;
1372 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1373 parent
, parent
->bounds(), &render_surface_layer_list
);
1374 inputs
.can_adjust_raster_scales
= true;
1375 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1377 // Since the layer is transparent, render_surface1->render_surface() should
1378 // not have gotten added anywhere. Also, the drawable content rect should not
1379 // have been extended by the children.
1380 ASSERT_TRUE(parent
->render_surface());
1381 EXPECT_EQ(0U, parent
->render_surface()->layer_list().size());
1382 EXPECT_EQ(1U, render_surface_layer_list
.size());
1383 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1384 EXPECT_EQ(gfx::Rect(), parent
->drawable_content_rect());
1387 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceForBlendMode
) {
1388 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1389 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1390 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1392 host()->SetRootLayer(parent
);
1394 const gfx::Transform identity_matrix
;
1395 const SkXfermode::Mode blend_mode
= SkXfermode::kMultiply_Mode
;
1396 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
1397 gfx::PointF(), gfx::Size(10, 10), true, false);
1399 parent
->AddChild(child
);
1400 child
->SetBlendMode(blend_mode
);
1402 RenderSurfaceLayerList render_surface_layer_list
;
1403 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1404 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1405 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1407 // Since the child layer has a blend mode other than normal, it should get
1408 // its own render surface. Also, layer's draw_properties should contain the
1409 // default blend mode, since the render surface becomes responsible for
1410 // applying the blend mode.
1411 ASSERT_TRUE(child
->render_surface());
1412 EXPECT_EQ(1U, child
->render_surface()->layer_list().size());
1413 EXPECT_EQ(SkXfermode::kSrcOver_Mode
, child
->draw_properties().blend_mode
);
1416 TEST_F(LayerTreeHostCommonTest
, ForceRenderSurface
) {
1417 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1418 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
1419 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1420 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1421 render_surface1
->SetForceRenderSurface(true);
1423 host()->SetRootLayer(parent
);
1425 const gfx::Transform identity_matrix
;
1426 SetLayerPropertiesForTesting(parent
.get(),
1433 SetLayerPropertiesForTesting(render_surface1
.get(),
1440 SetLayerPropertiesForTesting(child
.get(),
1448 parent
->AddChild(render_surface1
);
1449 render_surface1
->AddChild(child
);
1451 // Sanity check before the actual test
1452 EXPECT_FALSE(parent
->render_surface());
1453 EXPECT_FALSE(render_surface1
->render_surface());
1456 RenderSurfaceLayerList render_surface_layer_list
;
1457 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1458 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1459 inputs
.can_adjust_raster_scales
= true;
1460 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1462 // The root layer always creates a render surface
1463 EXPECT_TRUE(parent
->render_surface());
1464 EXPECT_TRUE(render_surface1
->render_surface());
1465 EXPECT_EQ(2U, render_surface_layer_list
.size());
1469 RenderSurfaceLayerList render_surface_layer_list
;
1470 render_surface1
->SetForceRenderSurface(false);
1471 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1472 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1473 inputs
.can_adjust_raster_scales
= true;
1474 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1475 EXPECT_TRUE(parent
->render_surface());
1476 EXPECT_FALSE(render_surface1
->render_surface());
1477 EXPECT_EQ(1U, render_surface_layer_list
.size());
1481 TEST_F(LayerTreeHostCommonTest
, RenderSurfacesFlattenScreenSpaceTransform
) {
1482 // Render surfaces act as a flattening point for their subtree, so should
1483 // always flatten the target-to-screen space transform seen by descendants.
1485 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1486 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1487 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1488 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1489 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1490 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1492 gfx::Transform rotation_about_y_axis
;
1493 rotation_about_y_axis
.RotateAboutYAxis(30.0);
1494 // Make |parent| have a render surface.
1495 parent
->SetOpacity(0.9f
);
1497 const gfx::Transform identity_matrix
;
1498 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
1499 gfx::PointF(), gfx::Size(100, 100), true, false);
1500 SetLayerPropertiesForTesting(parent
.get(), rotation_about_y_axis
,
1501 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1503 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
1504 gfx::PointF(), gfx::Size(10, 10), true, false);
1505 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
1506 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1509 root
->AddChild(parent
);
1510 parent
->AddChild(child
);
1511 child
->AddChild(grand_child
);
1513 grand_child
->SetShouldFlattenTransform(false);
1515 host()->SetRootLayer(root
);
1517 // Only grand_child should preserve 3d.
1518 EXPECT_TRUE(root
->should_flatten_transform());
1519 EXPECT_TRUE(parent
->should_flatten_transform());
1520 EXPECT_TRUE(child
->should_flatten_transform());
1521 EXPECT_FALSE(grand_child
->should_flatten_transform());
1523 gfx::Transform expected_child_draw_transform
= identity_matrix
;
1524 gfx::Transform expected_grand_child_draw_transform
= identity_matrix
;
1526 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
1527 flattened_rotation_about_y
.FlattenTo2d();
1529 ExecuteCalculateDrawProperties(root
.get());
1531 EXPECT_TRUE(parent
->render_surface());
1532 EXPECT_FALSE(child
->render_surface());
1533 EXPECT_FALSE(grand_child
->render_surface());
1535 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1536 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1537 grand_child
->draw_transform());
1539 // The screen-space transform inherited by |child| and |grand_child| should
1540 // have been flattened at their render target. In particular, the fact that
1541 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1542 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y
,
1543 child
->screen_space_transform());
1544 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y
,
1545 grand_child
->screen_space_transform());
1548 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsRenderSurfaces
) {
1549 // The entire subtree of layers that are outside the clip rect should be
1550 // culled away, and should not affect the render_surface_layer_list.
1552 // The test tree is set up as follows:
1553 // - all layers except the leaf_nodes are forced to be a new render surface
1554 // that have something to draw.
1555 // - parent is a large container layer.
1556 // - child has masksToBounds=true to cause clipping.
1557 // - grand_child is positioned outside of the child's bounds
1558 // - great_grand_child is also kept outside child's bounds.
1560 // In this configuration, grand_child and great_grand_child are completely
1561 // outside the clip rect, and they should never get scheduled on the list of
1565 const gfx::Transform identity_matrix
;
1566 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1567 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
1568 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
1569 scoped_refptr
<Layer
> great_grand_child
= Layer::Create(layer_settings());
1570 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1571 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1572 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1573 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1574 parent
->AddChild(child
);
1575 child
->AddChild(grand_child
);
1576 grand_child
->AddChild(great_grand_child
);
1578 host()->SetRootLayer(parent
);
1580 // leaf_node1 ensures that parent and child are kept on the
1581 // render_surface_layer_list, even though grand_child and great_grand_child
1582 // should be clipped.
1583 child
->AddChild(leaf_node1
);
1584 great_grand_child
->AddChild(leaf_node2
);
1586 SetLayerPropertiesForTesting(parent
.get(),
1590 gfx::Size(500, 500),
1593 SetLayerPropertiesForTesting(child
.get(),
1600 SetLayerPropertiesForTesting(grand_child
.get(),
1603 gfx::PointF(45.f
, 45.f
),
1607 SetLayerPropertiesForTesting(great_grand_child
.get(),
1614 SetLayerPropertiesForTesting(leaf_node1
.get(),
1618 gfx::Size(500, 500),
1621 SetLayerPropertiesForTesting(leaf_node2
.get(),
1629 child
->SetMasksToBounds(true);
1630 child
->SetOpacity(0.4f
);
1631 child
->SetForceRenderSurface(true);
1632 grand_child
->SetOpacity(0.5f
);
1633 great_grand_child
->SetOpacity(0.4f
);
1635 RenderSurfaceLayerList render_surface_layer_list
;
1636 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1637 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1638 inputs
.can_adjust_raster_scales
= true;
1639 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1641 ASSERT_EQ(2U, render_surface_layer_list
.size());
1642 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1643 EXPECT_EQ(child
->id(), render_surface_layer_list
.at(1)->id());
1646 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsSurfaceWithoutVisibleContent
) {
1647 // When a render surface has a clip rect, it is used to clip the content rect
1648 // of the surface. When the render surface is animating its transforms, then
1649 // the content rect's position in the clip rect is not defined on the main
1650 // thread, and its content rect should not be clipped.
1652 // The test tree is set up as follows:
1653 // - parent is a container layer that masksToBounds=true to cause clipping.
1654 // - child is a render surface, which has a clip rect set to the bounds of
1656 // - grand_child is a render surface, and the only visible content in child.
1657 // It is positioned outside of the clip rect from parent.
1659 // In this configuration, grand_child should be outside the clipped
1660 // content rect of the child, making grand_child not appear in the
1661 // render_surface_layer_list. However, when we place an animation on the
1662 // child, this clipping should be avoided and we should keep the grand_child
1663 // in the render_surface_layer_list.
1665 const gfx::Transform identity_matrix
;
1666 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1667 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
1668 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
1669 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node
=
1670 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1671 parent
->AddChild(child
);
1672 child
->AddChild(grand_child
);
1673 grand_child
->AddChild(leaf_node
);
1675 host()->SetRootLayer(parent
);
1677 SetLayerPropertiesForTesting(parent
.get(),
1681 gfx::Size(100, 100),
1684 SetLayerPropertiesForTesting(child
.get(),
1691 SetLayerPropertiesForTesting(grand_child
.get(),
1694 gfx::PointF(200.f
, 200.f
),
1698 SetLayerPropertiesForTesting(leaf_node
.get(),
1706 parent
->SetMasksToBounds(true);
1707 child
->SetOpacity(0.4f
);
1708 child
->SetForceRenderSurface(true);
1709 grand_child
->SetOpacity(0.4f
);
1710 grand_child
->SetForceRenderSurface(true);
1713 RenderSurfaceLayerList render_surface_layer_list
;
1714 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1715 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1716 inputs
.can_adjust_raster_scales
= true;
1717 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1719 // Without an animation, we should cull child and grand_child from the
1720 // render_surface_layer_list.
1721 ASSERT_EQ(1U, render_surface_layer_list
.size());
1722 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1725 // Now put an animating transform on child.
1726 AddAnimatedTransformToController(
1727 child
->layer_animation_controller(), 10.0, 30, 0);
1730 RenderSurfaceLayerList render_surface_layer_list
;
1731 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1732 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1733 inputs
.can_adjust_raster_scales
= true;
1734 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1736 // With an animating transform, we should keep child and grand_child in the
1737 // render_surface_layer_list.
1738 ASSERT_EQ(3U, render_surface_layer_list
.size());
1739 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1740 EXPECT_EQ(child
->id(), render_surface_layer_list
.at(1)->id());
1741 EXPECT_EQ(grand_child
->id(), render_surface_layer_list
.at(2)->id());
1745 TEST_F(LayerTreeHostCommonTest
, IsClippedIsSetCorrectly
) {
1746 // Layer's IsClipped() property is set to true when:
1747 // - the layer clips its subtree, e.g. masks to bounds,
1748 // - the layer is clipped by an ancestor that contributes to the same
1750 // - a surface is clipped by an ancestor that contributes to the same
1753 // In particular, for a layer that owns a render surface:
1754 // - the render surface inherits any clip from ancestors, and does NOT
1755 // pass that clipped status to the layer itself.
1756 // - but if the layer itself masks to bounds, it is considered clipped
1757 // and propagates the clip to the subtree.
1759 const gfx::Transform identity_matrix
;
1760 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1761 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1762 scoped_refptr
<Layer
> child1
= Layer::Create(layer_settings());
1763 scoped_refptr
<Layer
> child2
= Layer::Create(layer_settings());
1764 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
1765 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1766 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1767 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1768 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1769 root
->AddChild(parent
);
1770 parent
->AddChild(child1
);
1771 parent
->AddChild(child2
);
1772 child1
->AddChild(grand_child
);
1773 child2
->AddChild(leaf_node2
);
1774 grand_child
->AddChild(leaf_node1
);
1776 host()->SetRootLayer(root
);
1778 child2
->SetForceRenderSurface(true);
1780 SetLayerPropertiesForTesting(root
.get(),
1784 gfx::Size(100, 100),
1787 SetLayerPropertiesForTesting(parent
.get(),
1791 gfx::Size(100, 100),
1794 SetLayerPropertiesForTesting(child1
.get(),
1798 gfx::Size(100, 100),
1801 SetLayerPropertiesForTesting(child2
.get(),
1805 gfx::Size(100, 100),
1808 SetLayerPropertiesForTesting(grand_child
.get(),
1812 gfx::Size(100, 100),
1815 SetLayerPropertiesForTesting(leaf_node1
.get(),
1819 gfx::Size(100, 100),
1822 SetLayerPropertiesForTesting(leaf_node2
.get(),
1826 gfx::Size(100, 100),
1830 // Case 1: nothing is clipped except the root render surface.
1832 RenderSurfaceLayerList render_surface_layer_list
;
1833 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1834 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1835 inputs
.can_adjust_raster_scales
= true;
1836 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1838 ASSERT_TRUE(root
->render_surface());
1839 ASSERT_TRUE(child2
->render_surface());
1841 EXPECT_FALSE(root
->is_clipped());
1842 EXPECT_TRUE(root
->render_surface()->is_clipped());
1843 EXPECT_FALSE(parent
->is_clipped());
1844 EXPECT_FALSE(child1
->is_clipped());
1845 EXPECT_FALSE(child2
->is_clipped());
1846 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1847 EXPECT_FALSE(grand_child
->is_clipped());
1848 EXPECT_FALSE(leaf_node1
->is_clipped());
1849 EXPECT_FALSE(leaf_node2
->is_clipped());
1852 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1853 // surface are clipped. But layers that contribute to child2's surface are
1854 // not clipped explicitly because child2's surface already accounts for
1857 RenderSurfaceLayerList render_surface_layer_list
;
1858 parent
->SetMasksToBounds(true);
1859 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1860 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1861 inputs
.can_adjust_raster_scales
= true;
1862 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1864 ASSERT_TRUE(root
->render_surface());
1865 ASSERT_TRUE(child2
->render_surface());
1867 EXPECT_FALSE(root
->is_clipped());
1868 EXPECT_TRUE(root
->render_surface()->is_clipped());
1869 EXPECT_TRUE(parent
->is_clipped());
1870 EXPECT_TRUE(child1
->is_clipped());
1871 EXPECT_FALSE(child2
->is_clipped());
1872 EXPECT_TRUE(child2
->render_surface()->is_clipped());
1873 EXPECT_TRUE(grand_child
->is_clipped());
1874 EXPECT_TRUE(leaf_node1
->is_clipped());
1875 EXPECT_FALSE(leaf_node2
->is_clipped());
1878 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1879 // child2's render surface is not clipped.
1881 RenderSurfaceLayerList render_surface_layer_list
;
1882 parent
->SetMasksToBounds(false);
1883 child2
->SetMasksToBounds(true);
1884 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1885 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1886 inputs
.can_adjust_raster_scales
= true;
1887 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1889 ASSERT_TRUE(root
->render_surface());
1890 ASSERT_TRUE(child2
->render_surface());
1892 EXPECT_FALSE(root
->is_clipped());
1893 EXPECT_TRUE(root
->render_surface()->is_clipped());
1894 EXPECT_FALSE(parent
->is_clipped());
1895 EXPECT_FALSE(child1
->is_clipped());
1896 EXPECT_TRUE(child2
->is_clipped());
1897 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1898 EXPECT_FALSE(grand_child
->is_clipped());
1899 EXPECT_FALSE(leaf_node1
->is_clipped());
1900 EXPECT_TRUE(leaf_node2
->is_clipped());
1904 TEST_F(LayerTreeHostCommonTest
, DrawableContentRectForLayers
) {
1905 // Verify that layers get the appropriate DrawableContentRect when their
1906 // parent masksToBounds is true.
1908 // grand_child1 - completely inside the region; DrawableContentRect should
1909 // be the layer rect expressed in target space.
1910 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1911 // will be the intersection of layer bounds and the mask region.
1912 // grand_child3 - partially clipped and masksToBounds; the
1913 // DrawableContentRect will still be the intersection of layer bounds and
1915 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1919 const gfx::Transform identity_matrix
;
1920 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1921 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
1922 scoped_refptr
<Layer
> grand_child1
= Layer::Create(layer_settings());
1923 scoped_refptr
<Layer
> grand_child2
= Layer::Create(layer_settings());
1924 scoped_refptr
<Layer
> grand_child3
= Layer::Create(layer_settings());
1925 scoped_refptr
<Layer
> grand_child4
= Layer::Create(layer_settings());
1927 parent
->AddChild(child
);
1928 child
->AddChild(grand_child1
);
1929 child
->AddChild(grand_child2
);
1930 child
->AddChild(grand_child3
);
1931 child
->AddChild(grand_child4
);
1933 host()->SetRootLayer(parent
);
1935 SetLayerPropertiesForTesting(parent
.get(),
1939 gfx::Size(500, 500),
1942 SetLayerPropertiesForTesting(child
.get(),
1949 SetLayerPropertiesForTesting(grand_child1
.get(),
1952 gfx::PointF(5.f
, 5.f
),
1956 SetLayerPropertiesForTesting(grand_child2
.get(),
1959 gfx::PointF(15.f
, 15.f
),
1963 SetLayerPropertiesForTesting(grand_child3
.get(),
1966 gfx::PointF(15.f
, 15.f
),
1970 SetLayerPropertiesForTesting(grand_child4
.get(),
1973 gfx::PointF(45.f
, 45.f
),
1978 child
->SetMasksToBounds(true);
1979 grand_child3
->SetMasksToBounds(true);
1981 // Force everyone to be a render surface.
1982 child
->SetOpacity(0.4f
);
1983 grand_child1
->SetOpacity(0.5f
);
1984 grand_child2
->SetOpacity(0.5f
);
1985 grand_child3
->SetOpacity(0.5f
);
1986 grand_child4
->SetOpacity(0.5f
);
1988 RenderSurfaceLayerList render_surface_layer_list
;
1989 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1990 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1991 inputs
.can_adjust_raster_scales
= true;
1992 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1994 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1
->drawable_content_rect());
1995 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3
->drawable_content_rect());
1996 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3
->drawable_content_rect());
1997 EXPECT_TRUE(grand_child4
->drawable_content_rect().IsEmpty());
2000 TEST_F(LayerTreeHostCommonTest
, ClipRectIsPropagatedCorrectlyToSurfaces
) {
2001 // Verify that render surfaces (and their layers) get the appropriate
2002 // clip rects when their parent masksToBounds is true.
2004 // Layers that own render surfaces (at least for now) do not inherit any
2005 // clipping; instead the surface will enforce the clip for the entire subtree.
2006 // They may still have a clip rect of their own layer bounds, however, if
2007 // masksToBounds was true.
2008 const gfx::Transform identity_matrix
;
2009 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
2010 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
2011 scoped_refptr
<Layer
> grand_child1
= Layer::Create(layer_settings());
2012 scoped_refptr
<Layer
> grand_child2
= Layer::Create(layer_settings());
2013 scoped_refptr
<Layer
> grand_child3
= Layer::Create(layer_settings());
2014 scoped_refptr
<Layer
> grand_child4
= Layer::Create(layer_settings());
2015 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
2016 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2017 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
2018 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2019 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node3
=
2020 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2021 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node4
=
2022 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2024 parent
->AddChild(child
);
2025 child
->AddChild(grand_child1
);
2026 child
->AddChild(grand_child2
);
2027 child
->AddChild(grand_child3
);
2028 child
->AddChild(grand_child4
);
2030 host()->SetRootLayer(parent
);
2032 // the leaf nodes ensure that these grand_children become render surfaces for
2034 grand_child1
->AddChild(leaf_node1
);
2035 grand_child2
->AddChild(leaf_node2
);
2036 grand_child3
->AddChild(leaf_node3
);
2037 grand_child4
->AddChild(leaf_node4
);
2039 SetLayerPropertiesForTesting(parent
.get(),
2043 gfx::Size(500, 500),
2046 SetLayerPropertiesForTesting(child
.get(),
2053 SetLayerPropertiesForTesting(grand_child1
.get(),
2056 gfx::PointF(5.f
, 5.f
),
2060 SetLayerPropertiesForTesting(grand_child2
.get(),
2063 gfx::PointF(15.f
, 15.f
),
2067 SetLayerPropertiesForTesting(grand_child3
.get(),
2070 gfx::PointF(15.f
, 15.f
),
2074 SetLayerPropertiesForTesting(grand_child4
.get(),
2077 gfx::PointF(45.f
, 45.f
),
2081 SetLayerPropertiesForTesting(leaf_node1
.get(),
2088 SetLayerPropertiesForTesting(leaf_node2
.get(),
2095 SetLayerPropertiesForTesting(leaf_node3
.get(),
2102 SetLayerPropertiesForTesting(leaf_node4
.get(),
2110 child
->SetMasksToBounds(true);
2111 grand_child3
->SetMasksToBounds(true);
2112 grand_child4
->SetMasksToBounds(true);
2114 // Force everyone to be a render surface.
2115 child
->SetOpacity(0.4f
);
2116 child
->SetForceRenderSurface(true);
2117 grand_child1
->SetOpacity(0.5f
);
2118 grand_child1
->SetForceRenderSurface(true);
2119 grand_child2
->SetOpacity(0.5f
);
2120 grand_child2
->SetForceRenderSurface(true);
2121 grand_child3
->SetOpacity(0.5f
);
2122 grand_child3
->SetForceRenderSurface(true);
2123 grand_child4
->SetOpacity(0.5f
);
2124 grand_child4
->SetForceRenderSurface(true);
2126 RenderSurfaceLayerList render_surface_layer_list
;
2127 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
2128 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
2129 inputs
.can_adjust_raster_scales
= true;
2130 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
2131 ASSERT_TRUE(grand_child1
->render_surface());
2132 ASSERT_TRUE(grand_child2
->render_surface());
2133 ASSERT_TRUE(grand_child3
->render_surface());
2135 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2137 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2138 grand_child1
->render_surface()->clip_rect());
2139 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2140 grand_child2
->render_surface()->clip_rect());
2141 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2142 grand_child3
->render_surface()->clip_rect());
2145 TEST_F(LayerTreeHostCommonTest
, AnimationsForRenderSurfaceHierarchy
) {
2146 LayerImpl
* parent
= root_layer();
2147 LayerImpl
* render_surface1
= AddChildToRoot
<LayerImpl
>();
2148 LayerImpl
* child_of_rs1
= AddChild
<LayerImpl
>(render_surface1
);
2149 LayerImpl
* grand_child_of_rs1
= AddChild
<LayerImpl
>(child_of_rs1
);
2150 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(render_surface1
);
2151 LayerImpl
* child_of_rs2
= AddChild
<LayerImpl
>(render_surface2
);
2152 LayerImpl
* grand_child_of_rs2
= AddChild
<LayerImpl
>(child_of_rs2
);
2153 LayerImpl
* child_of_root
= AddChildToRoot
<LayerImpl
>();
2154 LayerImpl
* grand_child_of_root
= AddChild
<LayerImpl
>(child_of_root
);
2156 grand_child_of_rs1
->SetDrawsContent(true);
2157 grand_child_of_rs2
->SetDrawsContent(true);
2159 gfx::Transform layer_transform
;
2160 layer_transform
.Translate(1.0, 1.0);
2162 SetLayerPropertiesForTesting(
2163 parent
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2164 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, true);
2165 SetLayerPropertiesForTesting(
2166 render_surface1
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2167 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, true);
2168 SetLayerPropertiesForTesting(
2169 render_surface2
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2170 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, true);
2171 SetLayerPropertiesForTesting(
2172 child_of_root
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2173 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
2174 SetLayerPropertiesForTesting(
2175 child_of_rs1
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2176 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
2177 SetLayerPropertiesForTesting(
2178 child_of_rs2
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2179 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
2180 SetLayerPropertiesForTesting(
2181 grand_child_of_root
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2182 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
2183 SetLayerPropertiesForTesting(
2184 grand_child_of_rs1
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2185 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
2186 SetLayerPropertiesForTesting(
2187 grand_child_of_rs2
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2188 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
2190 // Put an animated opacity on the render surface.
2191 AddOpacityTransitionToController(
2192 render_surface1
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2194 // Also put an animated opacity on a layer without descendants.
2195 AddOpacityTransitionToController(
2196 grand_child_of_root
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2198 // Put a transform animation on the render surface.
2199 AddAnimatedTransformToController(
2200 render_surface2
->layer_animation_controller(), 10.0, 30, 0);
2202 // Also put transform animations on grand_child_of_root, and
2203 // grand_child_of_rs2
2204 AddAnimatedTransformToController(
2205 grand_child_of_root
->layer_animation_controller(), 10.0, 30, 0);
2206 AddAnimatedTransformToController(
2207 grand_child_of_rs2
->layer_animation_controller(), 10.0, 30, 0);
2209 ExecuteCalculateDrawProperties(parent
);
2211 // Only layers that are associated with render surfaces should have an actual
2212 // RenderSurface() value.
2213 ASSERT_TRUE(parent
->render_surface());
2214 ASSERT_FALSE(child_of_root
->render_surface());
2215 ASSERT_FALSE(grand_child_of_root
->render_surface());
2217 ASSERT_TRUE(render_surface1
->render_surface());
2218 ASSERT_FALSE(child_of_rs1
->render_surface());
2219 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
2221 ASSERT_TRUE(render_surface2
->render_surface());
2222 ASSERT_FALSE(child_of_rs2
->render_surface());
2223 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
2225 // Verify all render target accessors
2226 EXPECT_EQ(parent
, parent
->render_target());
2227 EXPECT_EQ(parent
, child_of_root
->render_target());
2228 EXPECT_EQ(parent
, grand_child_of_root
->render_target());
2230 EXPECT_EQ(render_surface1
, render_surface1
->render_target());
2231 EXPECT_EQ(render_surface1
, child_of_rs1
->render_target());
2232 EXPECT_EQ(render_surface1
, grand_child_of_rs1
->render_target());
2234 EXPECT_EQ(render_surface2
, render_surface2
->render_target());
2235 EXPECT_EQ(render_surface2
, child_of_rs2
->render_target());
2236 EXPECT_EQ(render_surface2
, grand_child_of_rs2
->render_target());
2238 // Verify draw_opacity_is_animating values
2239 EXPECT_FALSE(parent
->draw_opacity_is_animating());
2240 EXPECT_FALSE(child_of_root
->draw_opacity_is_animating());
2241 EXPECT_TRUE(grand_child_of_root
->draw_opacity_is_animating());
2242 EXPECT_FALSE(render_surface1
->draw_opacity_is_animating());
2243 EXPECT_TRUE(render_surface1
->render_surface()->draw_opacity_is_animating());
2244 EXPECT_FALSE(child_of_rs1
->draw_opacity_is_animating());
2245 EXPECT_FALSE(grand_child_of_rs1
->draw_opacity_is_animating());
2246 EXPECT_FALSE(render_surface2
->draw_opacity_is_animating());
2247 EXPECT_FALSE(render_surface2
->render_surface()->draw_opacity_is_animating());
2248 EXPECT_FALSE(child_of_rs2
->draw_opacity_is_animating());
2249 EXPECT_FALSE(grand_child_of_rs2
->draw_opacity_is_animating());
2251 // Verify draw_transform_is_animating values
2252 EXPECT_FALSE(parent
->draw_transform_is_animating());
2253 EXPECT_FALSE(child_of_root
->draw_transform_is_animating());
2254 EXPECT_TRUE(grand_child_of_root
->draw_transform_is_animating());
2255 EXPECT_FALSE(render_surface1
->draw_transform_is_animating());
2256 EXPECT_FALSE(render_surface1
->render_surface()
2257 ->target_surface_transforms_are_animating());
2258 EXPECT_FALSE(child_of_rs1
->draw_transform_is_animating());
2259 EXPECT_FALSE(grand_child_of_rs1
->draw_transform_is_animating());
2260 EXPECT_FALSE(render_surface2
->draw_transform_is_animating());
2261 EXPECT_TRUE(render_surface2
->render_surface()
2262 ->target_surface_transforms_are_animating());
2263 EXPECT_FALSE(child_of_rs2
->draw_transform_is_animating());
2264 EXPECT_TRUE(grand_child_of_rs2
->draw_transform_is_animating());
2266 // Verify screen_space_transform_is_animating values
2267 EXPECT_FALSE(parent
->screen_space_transform_is_animating());
2268 EXPECT_FALSE(child_of_root
->screen_space_transform_is_animating());
2269 EXPECT_TRUE(grand_child_of_root
->screen_space_transform_is_animating());
2270 EXPECT_FALSE(render_surface1
->screen_space_transform_is_animating());
2271 EXPECT_FALSE(render_surface1
->render_surface()
2272 ->screen_space_transforms_are_animating());
2273 EXPECT_FALSE(child_of_rs1
->screen_space_transform_is_animating());
2274 EXPECT_FALSE(grand_child_of_rs1
->screen_space_transform_is_animating());
2275 EXPECT_TRUE(render_surface2
->screen_space_transform_is_animating());
2276 EXPECT_TRUE(render_surface2
->render_surface()
2277 ->screen_space_transforms_are_animating());
2278 EXPECT_TRUE(child_of_rs2
->screen_space_transform_is_animating());
2279 EXPECT_TRUE(grand_child_of_rs2
->screen_space_transform_is_animating());
2281 // Sanity check. If these fail there is probably a bug in the test itself.
2282 // It is expected that we correctly set up transforms so that the y-component
2283 // of the screen-space transform encodes the "depth" of the layer in the tree.
2284 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
2285 EXPECT_FLOAT_EQ(2.0,
2286 child_of_root
->screen_space_transform().matrix().get(1, 3));
2288 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
2290 EXPECT_FLOAT_EQ(2.0,
2291 render_surface1
->screen_space_transform().matrix().get(1, 3));
2292 EXPECT_FLOAT_EQ(3.0,
2293 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2295 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2297 EXPECT_FLOAT_EQ(3.0,
2298 render_surface2
->screen_space_transform().matrix().get(1, 3));
2299 EXPECT_FLOAT_EQ(4.0,
2300 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2302 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2305 TEST_F(LayerTreeHostCommonTest
, VisibleRectForIdentityTransform
) {
2306 // Test the calculateVisibleRect() function works correctly for identity
2309 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2310 gfx::Transform layer_to_surface_transform
;
2312 // Case 1: Layer is contained within the surface.
2313 gfx::Rect layer_content_rect
= gfx::Rect(10, 10, 30, 30);
2314 gfx::Rect expected
= gfx::Rect(10, 10, 30, 30);
2315 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2316 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2317 EXPECT_EQ(expected
, actual
);
2319 // Case 2: Layer is outside the surface rect.
2320 layer_content_rect
= gfx::Rect(120, 120, 30, 30);
2321 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2322 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2323 EXPECT_TRUE(actual
.IsEmpty());
2325 // Case 3: Layer is partially overlapping the surface rect.
2326 layer_content_rect
= gfx::Rect(80, 80, 30, 30);
2327 expected
= gfx::Rect(80, 80, 20, 20);
2328 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2329 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2330 EXPECT_EQ(expected
, actual
);
2333 TEST_F(LayerTreeHostCommonTest
, VisibleRectForTranslations
) {
2334 // Test the calculateVisibleRect() function works correctly for scaling
2337 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2338 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2339 gfx::Transform layer_to_surface_transform
;
2341 // Case 1: Layer is contained within the surface.
2342 layer_to_surface_transform
.MakeIdentity();
2343 layer_to_surface_transform
.Translate(10.0, 10.0);
2344 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2345 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2346 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2347 EXPECT_EQ(expected
, actual
);
2349 // Case 2: Layer is outside the surface rect.
2350 layer_to_surface_transform
.MakeIdentity();
2351 layer_to_surface_transform
.Translate(120.0, 120.0);
2352 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2353 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2354 EXPECT_TRUE(actual
.IsEmpty());
2356 // Case 3: Layer is partially overlapping the surface rect.
2357 layer_to_surface_transform
.MakeIdentity();
2358 layer_to_surface_transform
.Translate(80.0, 80.0);
2359 expected
= gfx::Rect(0, 0, 20, 20);
2360 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2361 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2362 EXPECT_EQ(expected
, actual
);
2365 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor2DRotations
) {
2366 // Test the calculateVisibleRect() function works correctly for rotations
2367 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2368 // should return the g in the layer's space.
2370 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2371 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2372 gfx::Transform layer_to_surface_transform
;
2374 // Case 1: Layer is contained within the surface.
2375 layer_to_surface_transform
.MakeIdentity();
2376 layer_to_surface_transform
.Translate(50.0, 50.0);
2377 layer_to_surface_transform
.Rotate(45.0);
2378 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2379 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2380 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2381 EXPECT_EQ(expected
, actual
);
2383 // Case 2: Layer is outside the surface rect.
2384 layer_to_surface_transform
.MakeIdentity();
2385 layer_to_surface_transform
.Translate(-50.0, 0.0);
2386 layer_to_surface_transform
.Rotate(45.0);
2387 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2388 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2389 EXPECT_TRUE(actual
.IsEmpty());
2391 // Case 3: The layer is rotated about its top-left corner. In surface space,
2392 // the layer is oriented diagonally, with the left half outside of the render
2393 // surface. In this case, the g should still be the entire layer
2394 // (remember the g is computed in layer space); both the top-left
2395 // and bottom-right corners of the layer are still visible.
2396 layer_to_surface_transform
.MakeIdentity();
2397 layer_to_surface_transform
.Rotate(45.0);
2398 expected
= gfx::Rect(0, 0, 30, 30);
2399 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2400 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2401 EXPECT_EQ(expected
, actual
);
2403 // Case 4: The layer is rotated about its top-left corner, and translated
2404 // upwards. In surface space, the layer is oriented diagonally, with only the
2405 // top corner of the surface overlapping the layer. In layer space, the render
2406 // surface overlaps the right side of the layer. The g should be
2407 // the layer's right half.
2408 layer_to_surface_transform
.MakeIdentity();
2409 layer_to_surface_transform
.Translate(0.0, -sqrt(2.0) * 15.0);
2410 layer_to_surface_transform
.Rotate(45.0);
2411 expected
= gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
2412 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2413 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2414 EXPECT_EQ(expected
, actual
);
2417 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dOrthographicTransform
) {
2418 // Test that the calculateVisibleRect() function works correctly for 3d
2421 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2422 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2423 gfx::Transform layer_to_surface_transform
;
2425 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2426 // degrees, should be fully contained in the render surface.
2427 layer_to_surface_transform
.MakeIdentity();
2428 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2429 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2430 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2431 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2432 EXPECT_EQ(expected
, actual
);
2434 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2435 // degrees, but shifted to the side so only the right-half the layer would be
2436 // visible on the surface.
2437 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2438 SkMScalar half_width_of_rotated_layer
=
2439 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
2440 layer_to_surface_transform
.MakeIdentity();
2441 layer_to_surface_transform
.Translate(-half_width_of_rotated_layer
, 0.0);
2442 layer_to_surface_transform
.RotateAboutYAxis(45.0); // Rotates about the left
2443 // edge of the layer.
2444 expected
= gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
2445 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2446 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2447 EXPECT_EQ(expected
, actual
);
2450 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveTransform
) {
2451 // Test the calculateVisibleRect() function works correctly when the layer has
2452 // a perspective projection onto the target surface.
2454 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2455 gfx::Rect layer_content_rect
= gfx::Rect(-50, -50, 200, 200);
2456 gfx::Transform layer_to_surface_transform
;
2458 // Case 1: Even though the layer is twice as large as the surface, due to
2459 // perspective foreshortening, the layer will fit fully in the surface when
2460 // its translated more than the perspective amount.
2461 layer_to_surface_transform
.MakeIdentity();
2463 // The following sequence of transforms applies the perspective about the
2464 // center of the surface.
2465 layer_to_surface_transform
.Translate(50.0, 50.0);
2466 layer_to_surface_transform
.ApplyPerspectiveDepth(9.0);
2467 layer_to_surface_transform
.Translate(-50.0, -50.0);
2469 // This translate places the layer in front of the surface's projection plane.
2470 layer_to_surface_transform
.Translate3d(0.0, 0.0, -27.0);
2472 gfx::Rect expected
= gfx::Rect(-50, -50, 200, 200);
2473 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2474 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2475 EXPECT_EQ(expected
, actual
);
2477 // Case 2: same projection as before, except that the layer is also translated
2478 // to the side, so that only the right half of the layer should be visible.
2480 // Explanation of expected result: The perspective ratio is (z distance
2481 // between layer and camera origin) / (z distance between projection plane and
2482 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2483 // move a layer by translating -50 units in projected surface units (so that
2484 // only half of it is visible), then we would need to translate by (-36 / 9) *
2485 // -50 == -200 in the layer's units.
2486 layer_to_surface_transform
.Translate3d(-200.0, 0.0, 0.0);
2487 expected
= gfx::Rect(gfx::Point(50, -50),
2488 gfx::Size(100, 200)); // The right half of the layer's
2490 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2491 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2492 EXPECT_EQ(expected
, actual
);
2495 TEST_F(LayerTreeHostCommonTest
,
2496 VisibleRectFor3dOrthographicIsNotClippedBehindSurface
) {
2497 // There is currently no explicit concept of an orthographic projection plane
2498 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2499 // are technically behind the surface in an orthographic world should not be
2500 // clipped when they are flattened to the surface.
2502 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2503 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2504 gfx::Transform layer_to_surface_transform
;
2506 // This sequence of transforms effectively rotates the layer about the y-axis
2507 // at the center of the layer.
2508 layer_to_surface_transform
.MakeIdentity();
2509 layer_to_surface_transform
.Translate(50.0, 0.0);
2510 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2511 layer_to_surface_transform
.Translate(-50.0, 0.0);
2513 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2514 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2515 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2516 EXPECT_EQ(expected
, actual
);
2519 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveWhenClippedByW
) {
2520 // Test the calculateVisibleRect() function works correctly when projecting a
2521 // surface onto a layer, but the layer is partially behind the camera (not
2522 // just behind the projection plane). In this case, the cartesian coordinates
2523 // may seem to be valid, but actually they are not. The visible rect needs to
2524 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2525 // converting to cartesian coordinates.
2527 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2528 gfx::Rect layer_content_rect
= gfx::Rect(-10, -1, 20, 2);
2529 gfx::Transform layer_to_surface_transform
;
2531 // The layer is positioned so that the right half of the layer should be in
2532 // front of the camera, while the other half is behind the surface's
2533 // projection plane. The following sequence of transforms applies the
2534 // perspective and rotation about the center of the layer.
2535 layer_to_surface_transform
.MakeIdentity();
2536 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2537 layer_to_surface_transform
.Translate3d(-2.0, 0.0, 1.0);
2538 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2540 // Sanity check that this transform does indeed cause w < 0 when applying the
2541 // transform, otherwise this code is not testing the intended scenario.
2543 MathUtil::MapQuad(layer_to_surface_transform
,
2544 gfx::QuadF(gfx::RectF(layer_content_rect
)),
2546 ASSERT_TRUE(clipped
);
2548 int expected_x_position
= 0;
2549 int expected_width
= 10;
2550 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2551 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2552 EXPECT_EQ(expected_x_position
, actual
.x());
2553 EXPECT_EQ(expected_width
, actual
.width());
2556 TEST_F(LayerTreeHostCommonTest
, VisibleRectForPerspectiveUnprojection
) {
2557 // To determine visible rect in layer space, there needs to be an
2558 // un-projection from surface space to layer space. When the original
2559 // transform was a perspective projection that was clipped, it returns a rect
2560 // that encloses the clipped bounds. Un-projecting this new rect may require
2563 // This sequence of transforms causes one corner of the layer to protrude
2564 // across the w = 0 plane, and should be clipped.
2565 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2566 gfx::Rect layer_content_rect
= gfx::Rect(-10, -10, 20, 20);
2567 gfx::Transform layer_to_surface_transform
;
2568 layer_to_surface_transform
.MakeIdentity();
2569 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2570 layer_to_surface_transform
.Translate3d(0.0, 0.0, -5.0);
2571 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2572 layer_to_surface_transform
.RotateAboutXAxis(80.0);
2574 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2575 // code is not testing the intended scenario.
2577 gfx::RectF clipped_rect
=
2578 MathUtil::MapClippedRect(layer_to_surface_transform
, layer_content_rect
);
2579 MathUtil::ProjectQuad(
2580 Inverse(layer_to_surface_transform
), gfx::QuadF(clipped_rect
), &clipped
);
2581 ASSERT_TRUE(clipped
);
2583 // Only the corner of the layer is not visible on the surface because of being
2584 // clipped. But, the net result of rounding visible region to an axis-aligned
2585 // rect is that the entire layer should still be considered visible.
2586 gfx::Rect expected
= gfx::Rect(-10, -10, 20, 20);
2587 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2588 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2589 EXPECT_EQ(expected
, actual
);
2592 TEST_F(LayerTreeHostCommonTest
,
2593 VisibleRectsForPositionedRootLayerClippedByViewport
) {
2594 scoped_refptr
<Layer
> root
=
2595 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2596 host()->SetRootLayer(root
);
2598 gfx::Transform identity_matrix
;
2599 // Root layer is positioned at (60, 70). The default device viewport size
2600 // is (0, 0, 100x100) in target space. So the root layer's visible rect
2601 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space.
2602 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2603 gfx::PointF(60, 70), gfx::Size(100, 100), true,
2605 ExecuteCalculateDrawProperties(root
.get());
2607 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2608 root
->render_surface()->DrawableContentRect());
2609 // In target space, not clipped.
2610 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root
->drawable_content_rect());
2611 // In layer space, clipped.
2612 EXPECT_EQ(gfx::Rect(0, 0, 40, 30), root
->visible_layer_rect());
2615 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsForSimpleLayers
) {
2616 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2617 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2618 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2619 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2620 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2621 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2622 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2623 root
->AddChild(child1
);
2624 root
->AddChild(child2
);
2625 root
->AddChild(child3
);
2627 host()->SetRootLayer(root
);
2629 gfx::Transform identity_matrix
;
2630 SetLayerPropertiesForTesting(root
.get(),
2634 gfx::Size(100, 100),
2637 SetLayerPropertiesForTesting(child1
.get(),
2644 SetLayerPropertiesForTesting(child2
.get(),
2647 gfx::PointF(75.f
, 75.f
),
2651 SetLayerPropertiesForTesting(child3
.get(),
2654 gfx::PointF(125.f
, 125.f
),
2659 ExecuteCalculateDrawProperties(root
.get());
2661 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2662 root
->render_surface()->DrawableContentRect());
2663 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2665 // Layers that do not draw content should have empty visible_layer_rects.
2666 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2668 // layer visible_layer_rects are clipped by their target surface.
2669 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
2670 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_layer_rect());
2671 EXPECT_TRUE(child3
->visible_layer_rect().IsEmpty());
2673 // layer drawable_content_rects are not clipped.
2674 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->drawable_content_rect());
2675 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2676 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2679 TEST_F(LayerTreeHostCommonTest
,
2680 DrawableAndVisibleContentRectsForLayersClippedByLayer
) {
2681 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2682 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
2683 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child1
=
2684 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2685 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child2
=
2686 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2687 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child3
=
2688 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2689 root
->AddChild(child
);
2690 child
->AddChild(grand_child1
);
2691 child
->AddChild(grand_child2
);
2692 child
->AddChild(grand_child3
);
2694 host()->SetRootLayer(root
);
2696 gfx::Transform identity_matrix
;
2697 SetLayerPropertiesForTesting(root
.get(),
2701 gfx::Size(100, 100),
2704 SetLayerPropertiesForTesting(child
.get(),
2708 gfx::Size(100, 100),
2711 SetLayerPropertiesForTesting(grand_child1
.get(),
2714 gfx::PointF(5.f
, 5.f
),
2718 SetLayerPropertiesForTesting(grand_child2
.get(),
2721 gfx::PointF(75.f
, 75.f
),
2725 SetLayerPropertiesForTesting(grand_child3
.get(),
2728 gfx::PointF(125.f
, 125.f
),
2733 child
->SetMasksToBounds(true);
2734 ExecuteCalculateDrawProperties(root
.get());
2736 ASSERT_FALSE(child
->render_surface());
2738 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2739 root
->render_surface()->DrawableContentRect());
2740 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2742 // Layers that do not draw content should have empty visible content rects.
2743 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2744 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child
->visible_layer_rect());
2746 // All grandchild visible content rects should be clipped by child.
2747 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1
->visible_layer_rect());
2748 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2
->visible_layer_rect());
2749 EXPECT_TRUE(grand_child3
->visible_layer_rect().IsEmpty());
2751 // All grandchild DrawableContentRects should also be clipped by child.
2752 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1
->drawable_content_rect());
2753 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2
->drawable_content_rect());
2754 EXPECT_TRUE(grand_child3
->drawable_content_rect().IsEmpty());
2757 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectWithClippingAndScaling
) {
2758 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2759 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
2760 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
2761 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2762 root
->AddChild(child
);
2763 child
->AddChild(grand_child
);
2765 host()->SetRootLayer(root
);
2767 gfx::Transform identity_matrix
;
2768 gfx::Transform child_scale_matrix
;
2769 child_scale_matrix
.Scale(0.25f
, 0.25f
);
2770 gfx::Transform grand_child_scale_matrix
;
2771 grand_child_scale_matrix
.Scale(0.246f
, 0.246f
);
2772 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2773 gfx::PointF(), gfx::Size(100, 100), true, false);
2774 SetLayerPropertiesForTesting(child
.get(), child_scale_matrix
, gfx::Point3F(),
2775 gfx::PointF(), gfx::Size(10, 10), true, false);
2776 SetLayerPropertiesForTesting(grand_child
.get(), grand_child_scale_matrix
,
2777 gfx::Point3F(), gfx::PointF(),
2778 gfx::Size(100, 100), true, false);
2780 child
->SetMasksToBounds(true);
2781 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
2783 // The visible rect is expanded to integer coordinates in target space before
2784 // being projected back to layer space, where it is once again expanded to
2785 // integer coordinates.
2786 EXPECT_EQ(gfx::Rect(49, 49), grand_child
->visible_rect_from_property_trees());
2789 TEST_F(LayerTreeHostCommonTest
,
2790 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface
) {
2791 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2792 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
2793 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2794 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2795 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2796 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2797 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2798 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2799 root
->AddChild(render_surface1
);
2800 render_surface1
->AddChild(child1
);
2801 render_surface1
->AddChild(child2
);
2802 render_surface1
->AddChild(child3
);
2804 host()->SetRootLayer(root
);
2806 gfx::Transform identity_matrix
;
2807 SetLayerPropertiesForTesting(root
.get(),
2811 gfx::Size(100, 100),
2814 SetLayerPropertiesForTesting(render_surface1
.get(),
2821 SetLayerPropertiesForTesting(child1
.get(),
2824 gfx::PointF(5.f
, 5.f
),
2828 SetLayerPropertiesForTesting(child2
.get(),
2831 gfx::PointF(75.f
, 75.f
),
2835 SetLayerPropertiesForTesting(child3
.get(),
2838 gfx::PointF(125.f
, 125.f
),
2843 render_surface1
->SetForceRenderSurface(true);
2844 ExecuteCalculateDrawProperties(root
.get());
2846 ASSERT_TRUE(render_surface1
->render_surface());
2848 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2849 root
->render_surface()->DrawableContentRect());
2850 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2852 // Layers that do not draw content should have empty visible content rects.
2853 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2854 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_layer_rect());
2856 // An unclipped surface grows its DrawableContentRect to include all drawable
2857 // regions of the subtree.
2858 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2859 render_surface1
->render_surface()->DrawableContentRect());
2861 // All layers that draw content into the unclipped surface are also unclipped.
2862 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
2863 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_layer_rect());
2864 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_layer_rect());
2866 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2867 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2868 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2871 TEST_F(LayerTreeHostCommonTest
,
2872 VisibleContentRectsForClippedSurfaceWithEmptyClip
) {
2873 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2874 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2875 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2876 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2877 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2878 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2879 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2880 root
->AddChild(child1
);
2881 root
->AddChild(child2
);
2882 root
->AddChild(child3
);
2884 host()->SetRootLayer(root
);
2886 gfx::Transform identity_matrix
;
2887 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2888 gfx::PointF(), gfx::Size(100, 100), true, false);
2889 SetLayerPropertiesForTesting(child1
.get(), identity_matrix
, gfx::Point3F(),
2890 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2892 SetLayerPropertiesForTesting(child2
.get(), identity_matrix
, gfx::Point3F(),
2893 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2895 SetLayerPropertiesForTesting(child3
.get(), identity_matrix
, gfx::Point3F(),
2896 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2899 RenderSurfaceLayerList render_surface_layer_list
;
2900 // Now set the root render surface an empty clip.
2901 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
2902 root
.get(), gfx::Size(), &render_surface_layer_list
);
2904 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
2905 ASSERT_TRUE(root
->render_surface());
2906 EXPECT_FALSE(root
->is_clipped());
2909 EXPECT_EQ(empty
, root
->render_surface()->clip_rect());
2910 EXPECT_TRUE(root
->render_surface()->is_clipped());
2912 // Visible content rect calculation will check if the target surface is
2913 // clipped or not. An empty clip rect does not indicate the render surface
2915 EXPECT_EQ(empty
, child1
->visible_layer_rect());
2916 EXPECT_EQ(empty
, child2
->visible_layer_rect());
2917 EXPECT_EQ(empty
, child3
->visible_layer_rect());
2920 TEST_F(LayerTreeHostCommonTest
,
2921 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform
) {
2922 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2923 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2924 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2925 root
->AddChild(child
);
2927 host()->SetRootLayer(root
);
2929 // Case 1: a truly degenerate matrix
2930 gfx::Transform identity_matrix
;
2931 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2932 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2934 SetLayerPropertiesForTesting(root
.get(),
2938 gfx::Size(100, 100),
2941 SetLayerPropertiesForTesting(child
.get(),
2942 uninvertible_matrix
,
2944 gfx::PointF(5.f
, 5.f
),
2949 ExecuteCalculateDrawProperties(root
.get());
2951 EXPECT_TRUE(child
->visible_layer_rect().IsEmpty());
2952 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2954 // Case 2: a matrix with flattened z, uninvertible and not visible according
2956 uninvertible_matrix
.MakeIdentity();
2957 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2958 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2960 SetLayerPropertiesForTesting(child
.get(),
2961 uninvertible_matrix
,
2963 gfx::PointF(5.f
, 5.f
),
2968 ExecuteCalculateDrawProperties(root
.get());
2970 EXPECT_TRUE(child
->visible_layer_rect().IsEmpty());
2971 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2973 // Case 3: a matrix with flattened z, also uninvertible and not visible.
2974 uninvertible_matrix
.MakeIdentity();
2975 uninvertible_matrix
.Translate(500.0, 0.0);
2976 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2977 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2979 SetLayerPropertiesForTesting(child
.get(),
2980 uninvertible_matrix
,
2982 gfx::PointF(5.f
, 5.f
),
2987 ExecuteCalculateDrawProperties(root
.get());
2989 EXPECT_TRUE(child
->visible_layer_rect().IsEmpty());
2990 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2993 TEST_F(LayerTreeHostCommonTest
,
2994 SingularTransformDoesNotPreventClearingDrawProperties
) {
2995 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2996 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2997 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2998 root
->AddChild(child
);
3000 host()->SetRootLayer(root
);
3002 gfx::Transform identity_matrix
;
3003 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3004 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
3006 SetLayerPropertiesForTesting(root
.get(),
3007 uninvertible_matrix
,
3010 gfx::Size(100, 100),
3013 SetLayerPropertiesForTesting(child
.get(),
3016 gfx::PointF(5.f
, 5.f
),
3021 child
->set_sorted_for_recursion(true);
3023 TransformOperations start_transform_operations
;
3024 start_transform_operations
.AppendScale(1.f
, 0.f
, 0.f
);
3026 TransformOperations end_transform_operations
;
3027 end_transform_operations
.AppendScale(1.f
, 1.f
, 0.f
);
3029 AddAnimatedTransformToLayer(
3030 root
.get(), 10.0, start_transform_operations
, end_transform_operations
);
3032 EXPECT_TRUE(root
->TransformIsAnimating());
3034 ExecuteCalculateDrawProperties(root
.get());
3036 EXPECT_FALSE(child
->sorted_for_recursion());
3039 TEST_F(LayerTreeHostCommonTest
,
3040 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties
) {
3041 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
3043 host()->SetRootLayer(root
);
3045 gfx::Transform identity_matrix
;
3046 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3047 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
3049 SetLayerPropertiesForTesting(root
.get(),
3050 uninvertible_matrix
,
3053 gfx::Size(100, 100),
3057 root
->set_sorted_for_recursion(true);
3059 EXPECT_FALSE(root
->TransformIsAnimating());
3061 ExecuteCalculateDrawProperties(root
.get());
3063 EXPECT_FALSE(root
->sorted_for_recursion());
3066 TEST_F(LayerTreeHostCommonTest
,
3067 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface
) {
3068 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
3069 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
3070 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3071 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3072 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3073 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3074 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
3075 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3076 root
->AddChild(render_surface1
);
3077 render_surface1
->AddChild(child1
);
3078 render_surface1
->AddChild(child2
);
3079 render_surface1
->AddChild(child3
);
3081 host()->SetRootLayer(root
);
3083 gfx::Transform identity_matrix
;
3084 SetLayerPropertiesForTesting(root
.get(),
3088 gfx::Size(100, 100),
3091 SetLayerPropertiesForTesting(render_surface1
.get(),
3098 SetLayerPropertiesForTesting(child1
.get(),
3101 gfx::PointF(5.f
, 5.f
),
3105 SetLayerPropertiesForTesting(child2
.get(),
3108 gfx::PointF(75.f
, 75.f
),
3112 SetLayerPropertiesForTesting(child3
.get(),
3115 gfx::PointF(125.f
, 125.f
),
3120 root
->SetMasksToBounds(true);
3121 render_surface1
->SetForceRenderSurface(true);
3122 ExecuteCalculateDrawProperties(root
.get());
3124 ASSERT_TRUE(render_surface1
->render_surface());
3126 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3127 root
->render_surface()->DrawableContentRect());
3128 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3130 // Layers that do not draw content should have empty visible content rects.
3131 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
3132 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_layer_rect());
3134 // A clipped surface grows its DrawableContentRect to include all drawable
3135 // regions of the subtree, but also gets clamped by the ancestor's clip.
3136 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3137 render_surface1
->render_surface()->DrawableContentRect());
3139 // All layers that draw content into the surface have their visible content
3140 // rect clipped by the surface clip rect.
3141 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
3142 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_layer_rect());
3143 EXPECT_TRUE(child3
->visible_layer_rect().IsEmpty());
3145 // But the DrawableContentRects are unclipped.
3146 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
3147 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
3148 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
3151 TEST_F(LayerTreeHostCommonTest
,
3152 DrawableAndVisibleContentRectsForSurfaceHierarchy
) {
3153 // Check that clipping does not propagate down surfaces.
3154 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
3155 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
3156 scoped_refptr
<Layer
> render_surface2
= Layer::Create(layer_settings());
3157 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3158 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3159 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3160 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3161 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
3162 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3163 root
->AddChild(render_surface1
);
3164 render_surface1
->AddChild(render_surface2
);
3165 render_surface2
->AddChild(child1
);
3166 render_surface2
->AddChild(child2
);
3167 render_surface2
->AddChild(child3
);
3169 host()->SetRootLayer(root
);
3171 gfx::Transform identity_matrix
;
3172 SetLayerPropertiesForTesting(root
.get(),
3176 gfx::Size(100, 100),
3179 SetLayerPropertiesForTesting(render_surface1
.get(),
3186 SetLayerPropertiesForTesting(render_surface2
.get(),
3193 SetLayerPropertiesForTesting(child1
.get(),
3196 gfx::PointF(5.f
, 5.f
),
3200 SetLayerPropertiesForTesting(child2
.get(),
3203 gfx::PointF(75.f
, 75.f
),
3207 SetLayerPropertiesForTesting(child3
.get(),
3210 gfx::PointF(125.f
, 125.f
),
3215 root
->SetMasksToBounds(true);
3216 render_surface1
->SetForceRenderSurface(true);
3217 render_surface2
->SetForceRenderSurface(true);
3218 ExecuteCalculateDrawProperties(root
.get());
3220 ASSERT_TRUE(render_surface1
->render_surface());
3221 ASSERT_TRUE(render_surface2
->render_surface());
3223 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3224 root
->render_surface()->DrawableContentRect());
3225 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3227 // Layers that do not draw content should have empty visible content rects.
3228 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
3229 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_layer_rect());
3230 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2
->visible_layer_rect());
3232 // A clipped surface grows its DrawableContentRect to include all drawable
3233 // regions of the subtree, but also gets clamped by the ancestor's clip.
3234 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3235 render_surface1
->render_surface()->DrawableContentRect());
3237 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3238 // is only implicitly clipped by render_surface1's content rect. So,
3239 // render_surface2 grows to enclose all drawable content of its subtree.
3240 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
3241 render_surface2
->render_surface()->DrawableContentRect());
3243 // All layers that draw content into render_surface2 think they are unclipped.
3244 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
3245 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_layer_rect());
3246 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_layer_rect());
3248 // DrawableContentRects are also unclipped.
3249 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
3250 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
3251 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
3254 TEST_F(LayerTreeHostCommonTest
,
3255 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface
) {
3256 // Layers that have non-axis aligned bounds (due to transforms) have an
3257 // expanded, axis-aligned DrawableContentRect and visible content rect.
3259 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
3260 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
3261 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3262 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3263 root
->AddChild(render_surface1
);
3264 render_surface1
->AddChild(child1
);
3266 host()->SetRootLayer(root
);
3268 gfx::Transform identity_matrix
;
3269 gfx::Transform child_rotation
;
3270 child_rotation
.Rotate(45.0);
3271 SetLayerPropertiesForTesting(root
.get(),
3275 gfx::Size(100, 100),
3278 SetLayerPropertiesForTesting(render_surface1
.get(),
3285 SetLayerPropertiesForTesting(child1
.get(),
3287 gfx::Point3F(25, 25, 0.f
),
3288 gfx::PointF(25.f
, 25.f
),
3293 render_surface1
->SetForceRenderSurface(true);
3294 ExecuteCalculateDrawProperties(root
.get());
3296 ASSERT_TRUE(render_surface1
->render_surface());
3298 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3299 root
->render_surface()->DrawableContentRect());
3300 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3302 // Layers that do not draw content should have empty visible content rects.
3303 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
3304 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_layer_rect());
3306 // The unclipped surface grows its DrawableContentRect to include all drawable
3307 // regions of the subtree.
3308 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3309 gfx::Rect expected_surface_drawable_content
=
3310 gfx::Rect(50 - diagonal_radius
,
3311 50 - diagonal_radius
,
3312 diagonal_radius
* 2,
3313 diagonal_radius
* 2);
3314 EXPECT_EQ(expected_surface_drawable_content
,
3315 render_surface1
->render_surface()->DrawableContentRect());
3317 // All layers that draw content into the unclipped surface are also unclipped.
3318 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
3319 EXPECT_EQ(expected_surface_drawable_content
, child1
->drawable_content_rect());
3322 TEST_F(LayerTreeHostCommonTest
,
3323 DrawableAndVisibleContentRectsWithTransformOnClippedSurface
) {
3324 // Layers that have non-axis aligned bounds (due to transforms) have an
3325 // expanded, axis-aligned DrawableContentRect and visible content rect.
3327 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
3328 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
3329 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3330 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3331 root
->AddChild(render_surface1
);
3332 render_surface1
->AddChild(child1
);
3334 host()->SetRootLayer(root
);
3336 gfx::Transform identity_matrix
;
3337 gfx::Transform child_rotation
;
3338 child_rotation
.Rotate(45.0);
3339 SetLayerPropertiesForTesting(root
.get(),
3346 SetLayerPropertiesForTesting(render_surface1
.get(),
3354 SetLayerPropertiesForTesting(child1
.get(),
3356 gfx::Point3F(25, 25, 0.f
),
3357 gfx::PointF(25.f
, 25.f
),
3362 root
->SetMasksToBounds(true);
3363 render_surface1
->SetForceRenderSurface(true);
3364 ExecuteCalculateDrawProperties(root
.get());
3366 ASSERT_TRUE(render_surface1
->render_surface());
3368 // The clipped surface clamps the DrawableContentRect that encloses the
3370 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3371 gfx::Rect unclipped_surface_content
= gfx::Rect(50 - diagonal_radius
,
3372 50 - diagonal_radius
,
3373 diagonal_radius
* 2,
3374 diagonal_radius
* 2);
3375 gfx::Rect expected_surface_drawable_content
=
3376 gfx::IntersectRects(unclipped_surface_content
, gfx::Rect(0, 0, 50, 50));
3377 EXPECT_EQ(expected_surface_drawable_content
,
3378 render_surface1
->render_surface()->DrawableContentRect());
3380 // On the clipped surface, only a quarter of the child1 is visible, but when
3381 // rotating it back to child1's content space, the actual enclosing rect ends
3382 // up covering the full left half of child1.
3384 // Given the floating point math, this number is a little bit fuzzy.
3385 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1
->visible_layer_rect());
3387 // The child's DrawableContentRect is unclipped.
3388 EXPECT_EQ(unclipped_surface_content
, child1
->drawable_content_rect());
3391 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsInHighDPI
) {
3392 MockContentLayerClient client
;
3394 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
3395 scoped_refptr
<FakePictureLayer
> render_surface1
=
3396 CreateDrawablePictureLayer(layer_settings(), &client
);
3397 scoped_refptr
<FakePictureLayer
> render_surface2
=
3398 CreateDrawablePictureLayer(layer_settings(), &client
);
3399 scoped_refptr
<FakePictureLayer
> child1
=
3400 CreateDrawablePictureLayer(layer_settings(), &client
);
3401 scoped_refptr
<FakePictureLayer
> child2
=
3402 CreateDrawablePictureLayer(layer_settings(), &client
);
3403 scoped_refptr
<FakePictureLayer
> child3
=
3404 CreateDrawablePictureLayer(layer_settings(), &client
);
3405 root
->AddChild(render_surface1
);
3406 render_surface1
->AddChild(render_surface2
);
3407 render_surface2
->AddChild(child1
);
3408 render_surface2
->AddChild(child2
);
3409 render_surface2
->AddChild(child3
);
3411 host()->SetRootLayer(root
);
3413 gfx::Transform identity_matrix
;
3414 SetLayerPropertiesForTesting(root
.get(),
3418 gfx::Size(100, 100),
3421 SetLayerPropertiesForTesting(render_surface1
.get(),
3424 gfx::PointF(5.f
, 5.f
),
3428 SetLayerPropertiesForTesting(render_surface2
.get(),
3431 gfx::PointF(5.f
, 5.f
),
3435 SetLayerPropertiesForTesting(child1
.get(),
3438 gfx::PointF(5.f
, 5.f
),
3442 SetLayerPropertiesForTesting(child2
.get(),
3445 gfx::PointF(75.f
, 75.f
),
3449 SetLayerPropertiesForTesting(child3
.get(),
3452 gfx::PointF(125.f
, 125.f
),
3457 float device_scale_factor
= 2.f
;
3459 root
->SetMasksToBounds(true);
3460 render_surface1
->SetForceRenderSurface(true);
3461 render_surface2
->SetForceRenderSurface(true);
3462 ExecuteCalculateDrawProperties(root
.get(), device_scale_factor
);
3464 ASSERT_TRUE(render_surface1
->render_surface());
3465 ASSERT_TRUE(render_surface2
->render_surface());
3467 // drawable_content_rects for all layers and surfaces are scaled by
3468 // device_scale_factor.
3469 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
3470 root
->render_surface()->DrawableContentRect());
3471 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root
->drawable_content_rect());
3472 EXPECT_EQ(gfx::Rect(10, 10, 190, 190),
3473 render_surface1
->render_surface()->DrawableContentRect());
3475 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3476 // is only implicitly clipped by render_surface1.
3477 EXPECT_EQ(gfx::Rect(10, 10, 350, 350),
3478 render_surface2
->render_surface()->DrawableContentRect());
3480 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1
->drawable_content_rect());
3481 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2
->drawable_content_rect());
3482 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3
->drawable_content_rect());
3484 // The root layer does not actually draw content of its own.
3485 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
3487 // All layer visible content rects are not expressed in content space of each
3488 // layer, so they are not scaled by the device_scale_factor.
3489 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1
->visible_layer_rect());
3490 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2
->visible_layer_rect());
3491 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
3492 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_layer_rect());
3493 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_layer_rect());
3496 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithoutPreserves3d
) {
3497 // Verify the behavior of back-face culling when there are no preserve-3d
3498 // layers. Note that 3d transforms still apply in this case, but they are
3499 // "flattened" to each parent layer according to current W3C spec.
3501 const gfx::Transform identity_matrix
;
3502 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3503 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3504 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3505 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3506 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3507 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3508 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3509 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3510 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3511 scoped_refptr
<LayerWithForcedDrawsContent
>
3512 front_facing_child_of_front_facing_surface
=
3513 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3514 scoped_refptr
<LayerWithForcedDrawsContent
>
3515 back_facing_child_of_front_facing_surface
=
3516 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3517 scoped_refptr
<LayerWithForcedDrawsContent
>
3518 front_facing_child_of_back_facing_surface
=
3519 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3520 scoped_refptr
<LayerWithForcedDrawsContent
>
3521 back_facing_child_of_back_facing_surface
=
3522 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3524 parent
->AddChild(front_facing_child
);
3525 parent
->AddChild(back_facing_child
);
3526 parent
->AddChild(front_facing_surface
);
3527 parent
->AddChild(back_facing_surface
);
3528 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3529 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3530 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3531 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3533 host()->SetRootLayer(parent
);
3535 // Nothing is double-sided
3536 front_facing_child
->SetDoubleSided(false);
3537 back_facing_child
->SetDoubleSided(false);
3538 front_facing_surface
->SetDoubleSided(false);
3539 back_facing_surface
->SetDoubleSided(false);
3540 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3541 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3542 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3543 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3545 gfx::Transform backface_matrix
;
3546 backface_matrix
.Translate(50.0, 50.0);
3547 backface_matrix
.RotateAboutYAxis(180.0);
3548 backface_matrix
.Translate(-50.0, -50.0);
3550 // Having a descendant and opacity will force these to have render surfaces.
3551 front_facing_surface
->SetOpacity(0.5f
);
3552 back_facing_surface
->SetOpacity(0.5f
);
3554 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3555 // these layers should blindly use their own local transforms to determine
3556 // back-face culling.
3557 SetLayerPropertiesForTesting(parent
.get(),
3561 gfx::Size(100, 100),
3564 SetLayerPropertiesForTesting(front_facing_child
.get(),
3568 gfx::Size(100, 100),
3571 SetLayerPropertiesForTesting(back_facing_child
.get(),
3575 gfx::Size(100, 100),
3578 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3582 gfx::Size(100, 100),
3585 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3589 gfx::Size(100, 100),
3592 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3596 gfx::Size(100, 100),
3599 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3603 gfx::Size(100, 100),
3606 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3610 gfx::Size(100, 100),
3613 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3617 gfx::Size(100, 100),
3621 RenderSurfaceLayerList render_surface_layer_list
;
3622 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3623 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3624 inputs
.can_adjust_raster_scales
= true;
3625 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3627 // Verify which render surfaces were created.
3628 EXPECT_FALSE(front_facing_child
->render_surface());
3629 EXPECT_FALSE(back_facing_child
->render_surface());
3630 EXPECT_TRUE(front_facing_surface
->render_surface());
3631 EXPECT_TRUE(back_facing_surface
->render_surface());
3632 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3633 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3634 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3635 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3637 // Verify the render_surface_layer_list.
3638 ASSERT_EQ(3u, render_surface_layer_list
.size());
3639 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3640 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
3641 // Even though the back facing surface LAYER gets culled, the other
3642 // descendants should still be added, so the SURFACE should not be culled.
3643 EXPECT_EQ(back_facing_surface
->id(), render_surface_layer_list
.at(2)->id());
3645 // Verify root surface's layer list.
3648 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3649 EXPECT_EQ(front_facing_child
->id(),
3650 render_surface_layer_list
.at(0)
3655 EXPECT_EQ(front_facing_surface
->id(),
3656 render_surface_layer_list
.at(0)
3661 EXPECT_EQ(back_facing_surface
->id(),
3662 render_surface_layer_list
.at(0)
3668 // Verify front_facing_surface's layer list.
3671 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3672 EXPECT_EQ(front_facing_surface
->id(),
3673 render_surface_layer_list
.at(1)
3678 EXPECT_EQ(front_facing_child_of_front_facing_surface
->id(),
3679 render_surface_layer_list
.at(1)
3685 // Verify back_facing_surface's layer list; its own layer should be culled
3686 // from the surface list.
3689 render_surface_layer_list
.at(2)->render_surface()->layer_list().size());
3690 EXPECT_EQ(front_facing_child_of_back_facing_surface
->id(),
3691 render_surface_layer_list
.at(2)
3698 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithPreserves3d
) {
3699 // Verify the behavior of back-face culling when preserves-3d transform style
3702 const gfx::Transform identity_matrix
;
3703 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3704 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3705 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3706 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3707 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3708 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3709 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3710 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3711 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3712 scoped_refptr
<LayerWithForcedDrawsContent
>
3713 front_facing_child_of_front_facing_surface
=
3714 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3715 scoped_refptr
<LayerWithForcedDrawsContent
>
3716 back_facing_child_of_front_facing_surface
=
3717 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3718 scoped_refptr
<LayerWithForcedDrawsContent
>
3719 front_facing_child_of_back_facing_surface
=
3720 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3721 scoped_refptr
<LayerWithForcedDrawsContent
>
3722 back_facing_child_of_back_facing_surface
=
3723 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3724 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer1
=
3725 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3726 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer2
=
3727 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3729 parent
->AddChild(front_facing_child
);
3730 parent
->AddChild(back_facing_child
);
3731 parent
->AddChild(front_facing_surface
);
3732 parent
->AddChild(back_facing_surface
);
3733 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3734 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3735 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3736 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3738 host()->SetRootLayer(parent
);
3740 // Nothing is double-sided
3741 front_facing_child
->SetDoubleSided(false);
3742 back_facing_child
->SetDoubleSided(false);
3743 front_facing_surface
->SetDoubleSided(false);
3744 back_facing_surface
->SetDoubleSided(false);
3745 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3746 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3747 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3748 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3750 gfx::Transform backface_matrix
;
3751 backface_matrix
.Translate(50.0, 50.0);
3752 backface_matrix
.RotateAboutYAxis(180.0);
3753 backface_matrix
.Translate(-50.0, -50.0);
3755 // Opacity will not force creation of render surfaces in this case because of
3756 // the preserve-3d transform style. Instead, an example of when a surface
3757 // would be created with preserve-3d is when there is a replica layer.
3758 front_facing_surface
->SetReplicaLayer(dummy_replica_layer1
.get());
3759 back_facing_surface
->SetReplicaLayer(dummy_replica_layer2
.get());
3761 // Each surface creates its own new 3d rendering context (as defined by W3C
3762 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3763 // rendering context should use the transform with respect to that context.
3764 // This 3d rendering context occurs when (a) parent's transform style is flat
3765 // and (b) the layer's transform style is preserve-3d.
3766 SetLayerPropertiesForTesting(parent
.get(),
3770 gfx::Size(100, 100),
3772 false); // parent transform style is flat.
3773 SetLayerPropertiesForTesting(front_facing_child
.get(),
3777 gfx::Size(100, 100),
3780 SetLayerPropertiesForTesting(back_facing_child
.get(),
3784 gfx::Size(100, 100),
3787 // surface transform style is preserve-3d.
3788 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3792 gfx::Size(100, 100),
3795 // surface transform style is preserve-3d.
3796 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3800 gfx::Size(100, 100),
3803 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3807 gfx::Size(100, 100),
3810 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3814 gfx::Size(100, 100),
3817 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3821 gfx::Size(100, 100),
3824 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3828 gfx::Size(100, 100),
3832 RenderSurfaceLayerList render_surface_layer_list
;
3833 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3834 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3835 inputs
.can_adjust_raster_scales
= true;
3836 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3838 // Verify which render surfaces were created and used.
3839 EXPECT_FALSE(front_facing_child
->render_surface());
3840 EXPECT_FALSE(back_facing_child
->render_surface());
3841 EXPECT_TRUE(front_facing_surface
->render_surface());
3842 EXPECT_NE(back_facing_surface
->render_target(), back_facing_surface
);
3843 // We expect that a render_surface was created but not used.
3844 EXPECT_TRUE(back_facing_surface
->render_surface());
3845 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3846 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3847 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3848 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3850 // Verify the render_surface_layer_list. The back-facing surface should be
3852 ASSERT_EQ(2u, render_surface_layer_list
.size());
3853 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3854 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
3856 // Verify root surface's layer list.
3859 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3860 EXPECT_EQ(front_facing_child
->id(),
3861 render_surface_layer_list
.at(0)
3862 ->render_surface()->layer_list().at(0)->id());
3863 EXPECT_EQ(front_facing_surface
->id(),
3864 render_surface_layer_list
.at(0)
3865 ->render_surface()->layer_list().at(1)->id());
3867 // Verify front_facing_surface's layer list.
3870 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3871 EXPECT_EQ(front_facing_surface
->id(),
3872 render_surface_layer_list
.at(1)
3873 ->render_surface()->layer_list().at(0)->id());
3874 EXPECT_EQ(front_facing_child_of_front_facing_surface
->id(),
3875 render_surface_layer_list
.at(1)
3876 ->render_surface()->layer_list().at(1)->id());
3879 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithAnimatingTransforms
) {
3880 // Verify that layers are appropriately culled when their back face is showing
3881 // and they are not double sided, while animations are going on.
3883 // Layers that are animating do not get culled on the main thread, as their
3884 // transforms should be treated as "unknown" so we can not be sure that their
3885 // back face is really showing.
3886 const gfx::Transform identity_matrix
;
3887 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3888 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
3889 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3890 scoped_refptr
<LayerWithForcedDrawsContent
> animating_surface
=
3891 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3892 scoped_refptr
<LayerWithForcedDrawsContent
> child_of_animating_surface
=
3893 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3894 scoped_refptr
<LayerWithForcedDrawsContent
> animating_child
=
3895 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3896 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3897 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3899 parent
->AddChild(child
);
3900 parent
->AddChild(animating_surface
);
3901 animating_surface
->AddChild(child_of_animating_surface
);
3902 parent
->AddChild(animating_child
);
3903 parent
->AddChild(child2
);
3905 host()->SetRootLayer(parent
);
3907 // Nothing is double-sided
3908 child
->SetDoubleSided(false);
3909 child2
->SetDoubleSided(false);
3910 animating_surface
->SetDoubleSided(false);
3911 child_of_animating_surface
->SetDoubleSided(false);
3912 animating_child
->SetDoubleSided(false);
3914 gfx::Transform backface_matrix
;
3915 backface_matrix
.Translate(50.0, 50.0);
3916 backface_matrix
.RotateAboutYAxis(180.0);
3917 backface_matrix
.Translate(-50.0, -50.0);
3919 // Make our render surface.
3920 animating_surface
->SetForceRenderSurface(true);
3922 // Animate the transform on the render surface.
3923 AddAnimatedTransformToController(
3924 animating_surface
->layer_animation_controller(), 10.0, 30, 0);
3925 // This is just an animating layer, not a surface.
3926 AddAnimatedTransformToController(
3927 animating_child
->layer_animation_controller(), 10.0, 30, 0);
3929 SetLayerPropertiesForTesting(parent
.get(),
3933 gfx::Size(100, 100),
3936 SetLayerPropertiesForTesting(child
.get(),
3940 gfx::Size(100, 100),
3943 SetLayerPropertiesForTesting(animating_surface
.get(),
3947 gfx::Size(100, 100),
3950 SetLayerPropertiesForTesting(child_of_animating_surface
.get(),
3954 gfx::Size(100, 100),
3957 SetLayerPropertiesForTesting(animating_child
.get(),
3961 gfx::Size(100, 100),
3964 SetLayerPropertiesForTesting(child2
.get(),
3968 gfx::Size(100, 100),
3972 RenderSurfaceLayerList render_surface_layer_list
;
3973 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3974 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3975 inputs
.can_adjust_raster_scales
= true;
3976 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3978 EXPECT_FALSE(child
->render_surface());
3979 EXPECT_TRUE(animating_surface
->render_surface());
3980 EXPECT_FALSE(child_of_animating_surface
->render_surface());
3981 EXPECT_FALSE(animating_child
->render_surface());
3982 EXPECT_FALSE(child2
->render_surface());
3984 // Verify that the animating_child and child_of_animating_surface were not
3985 // culled, but that child was.
3986 ASSERT_EQ(2u, render_surface_layer_list
.size());
3987 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3988 EXPECT_EQ(animating_surface
->id(), render_surface_layer_list
.at(1)->id());
3990 // The non-animating child be culled from the layer list for the parent render
3994 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3995 EXPECT_EQ(animating_surface
->id(),
3996 render_surface_layer_list
.at(0)
3997 ->render_surface()->layer_list().at(0)->id());
3998 EXPECT_EQ(animating_child
->id(),
3999 render_surface_layer_list
.at(0)
4000 ->render_surface()->layer_list().at(1)->id());
4001 EXPECT_EQ(child2
->id(),
4002 render_surface_layer_list
.at(0)
4003 ->render_surface()->layer_list().at(2)->id());
4007 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
4008 EXPECT_EQ(animating_surface
->id(),
4009 render_surface_layer_list
.at(1)
4010 ->render_surface()->layer_list().at(0)->id());
4011 EXPECT_EQ(child_of_animating_surface
->id(),
4012 render_surface_layer_list
.at(1)
4013 ->render_surface()->layer_list().at(1)->id());
4015 EXPECT_FALSE(child2
->visible_layer_rect().IsEmpty());
4017 // The animating layers should have a visible content rect that represents the
4018 // area of the front face that is within the viewport.
4019 EXPECT_EQ(animating_child
->visible_layer_rect(),
4020 gfx::Rect(animating_child
->bounds()));
4021 EXPECT_EQ(animating_surface
->visible_layer_rect(),
4022 gfx::Rect(animating_surface
->bounds()));
4023 // And layers in the subtree of the animating layer should have valid visible
4024 // content rects also.
4025 EXPECT_EQ(child_of_animating_surface
->visible_layer_rect(),
4026 gfx::Rect(child_of_animating_surface
->bounds()));
4029 TEST_F(LayerTreeHostCommonTest
,
4030 BackFaceCullingWithPreserves3dForFlatteningSurface
) {
4031 // Verify the behavior of back-face culling for a render surface that is
4032 // created when it flattens its subtree, and its parent has preserves-3d.
4034 const gfx::Transform identity_matrix
;
4035 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
4036 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
4037 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4038 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
4039 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4040 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
4041 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4042 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
4043 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4045 parent
->AddChild(front_facing_surface
);
4046 parent
->AddChild(back_facing_surface
);
4047 front_facing_surface
->AddChild(child1
);
4048 back_facing_surface
->AddChild(child2
);
4050 host()->SetRootLayer(parent
);
4052 // RenderSurfaces are not double-sided
4053 front_facing_surface
->SetDoubleSided(false);
4054 back_facing_surface
->SetDoubleSided(false);
4056 gfx::Transform backface_matrix
;
4057 backface_matrix
.Translate(50.0, 50.0);
4058 backface_matrix
.RotateAboutYAxis(180.0);
4059 backface_matrix
.Translate(-50.0, -50.0);
4061 SetLayerPropertiesForTesting(parent
.get(),
4065 gfx::Size(100, 100),
4067 true); // parent transform style is preserve3d.
4068 SetLayerPropertiesForTesting(front_facing_surface
.get(),
4072 gfx::Size(100, 100),
4074 true); // surface transform style is flat.
4075 SetLayerPropertiesForTesting(back_facing_surface
.get(),
4079 gfx::Size(100, 100),
4081 true); // surface transform style is flat.
4082 SetLayerPropertiesForTesting(child1
.get(),
4086 gfx::Size(100, 100),
4089 SetLayerPropertiesForTesting(child2
.get(),
4093 gfx::Size(100, 100),
4097 front_facing_surface
->Set3dSortingContextId(1);
4098 back_facing_surface
->Set3dSortingContextId(1);
4100 RenderSurfaceLayerList render_surface_layer_list
;
4101 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4102 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4103 inputs
.can_adjust_raster_scales
= true;
4104 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4106 // Verify which render surfaces were created and used.
4107 EXPECT_TRUE(front_facing_surface
->render_surface());
4109 // We expect the render surface to have been created, but remain unused.
4110 EXPECT_TRUE(back_facing_surface
->render_surface());
4111 EXPECT_NE(back_facing_surface
->render_target(),
4112 back_facing_surface
); // because it should be culled
4113 EXPECT_FALSE(child1
->render_surface());
4114 EXPECT_FALSE(child2
->render_surface());
4116 // Verify the render_surface_layer_list. The back-facing surface should be
4118 ASSERT_EQ(2u, render_surface_layer_list
.size());
4119 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
4120 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
4122 // Verify root surface's layer list.
4125 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
4126 EXPECT_EQ(front_facing_surface
->id(),
4127 render_surface_layer_list
.at(0)
4128 ->render_surface()->layer_list().at(0)->id());
4130 // Verify front_facing_surface's layer list.
4133 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
4134 EXPECT_EQ(front_facing_surface
->id(),
4135 render_surface_layer_list
.at(1)
4136 ->render_surface()->layer_list().at(0)->id());
4137 EXPECT_EQ(child1
->id(),
4138 render_surface_layer_list
.at(1)
4139 ->render_surface()->layer_list().at(1)->id());
4142 TEST_F(LayerTreeHostCommonScalingTest
, LayerTransformsInHighDPI
) {
4143 // Verify draw and screen space transforms of layers not in a surface.
4144 gfx::Transform identity_matrix
;
4146 LayerImpl
* parent
= root_layer();
4147 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
4148 gfx::PointF(), gfx::Size(100, 100), false, true,
4151 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
4152 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
4153 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
4156 LayerImpl
* child_empty
= AddChildToRoot
<LayerImpl
>();
4157 SetLayerPropertiesForTesting(child_empty
, identity_matrix
, gfx::Point3F(),
4158 gfx::PointF(2.f
, 2.f
), gfx::Size(), false, true,
4161 float device_scale_factor
= 2.5f
;
4162 gfx::Size
viewport_size(100, 100);
4163 ExecuteCalculateDrawProperties(parent
, device_scale_factor
);
4165 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
, parent
);
4166 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
, child
);
4167 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
, child_empty
);
4169 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
4171 // Verify parent transforms
4172 gfx::Transform expected_parent_transform
;
4173 expected_parent_transform
.Scale(device_scale_factor
, device_scale_factor
);
4174 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4175 parent
->screen_space_transform());
4176 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4177 parent
->draw_transform());
4179 // Verify results of transformed parent rects
4180 gfx::RectF
parent_bounds(parent
->bounds());
4182 gfx::RectF parent_draw_rect
=
4183 MathUtil::MapClippedRect(parent
->draw_transform(), parent_bounds
);
4184 gfx::RectF parent_screen_space_rect
=
4185 MathUtil::MapClippedRect(parent
->screen_space_transform(), parent_bounds
);
4187 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
4188 expected_parent_draw_rect
.Scale(device_scale_factor
);
4189 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
4190 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
4192 // Verify child and child_empty transforms. They should match.
4193 gfx::Transform expected_child_transform
;
4194 expected_child_transform
.Scale(device_scale_factor
, device_scale_factor
);
4195 expected_child_transform
.Translate(child
->position().x(),
4196 child
->position().y());
4197 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4198 child
->draw_transform());
4199 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4200 child
->screen_space_transform());
4201 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4202 child_empty
->draw_transform());
4203 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4204 child_empty
->screen_space_transform());
4206 // Verify results of transformed child and child_empty rects. They should
4208 gfx::RectF
child_bounds(child
->bounds());
4210 gfx::RectF child_draw_rect
=
4211 MathUtil::MapClippedRect(child
->draw_transform(), child_bounds
);
4212 gfx::RectF child_screen_space_rect
=
4213 MathUtil::MapClippedRect(child
->screen_space_transform(), child_bounds
);
4215 gfx::RectF child_empty_draw_rect
=
4216 MathUtil::MapClippedRect(child_empty
->draw_transform(), child_bounds
);
4217 gfx::RectF child_empty_screen_space_rect
= MathUtil::MapClippedRect(
4218 child_empty
->screen_space_transform(), child_bounds
);
4220 gfx::RectF
expected_child_draw_rect(child
->position(), child
->bounds());
4221 expected_child_draw_rect
.Scale(device_scale_factor
);
4222 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
4223 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
4224 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_draw_rect
);
4225 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_screen_space_rect
);
4228 TEST_F(LayerTreeHostCommonScalingTest
, SurfaceLayerTransformsInHighDPI
) {
4229 // Verify draw and screen space transforms of layers in a surface.
4230 gfx::Transform identity_matrix
;
4231 gfx::Transform perspective_matrix
;
4232 perspective_matrix
.ApplyPerspectiveDepth(2.0);
4234 gfx::Transform scale_small_matrix
;
4235 scale_small_matrix
.Scale(SK_MScalar1
/ 10.f
, SK_MScalar1
/ 12.f
);
4237 LayerImpl
* root
= root_layer();
4238 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
4239 gfx::PointF(), gfx::Size(100, 100), false, true,
4241 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
4242 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
4243 gfx::PointF(), gfx::Size(100, 100), false, true,
4246 LayerImpl
* perspective_surface
= AddChild
<LayerImpl
>(parent
);
4247 SetLayerPropertiesForTesting(perspective_surface
,
4248 perspective_matrix
* scale_small_matrix
,
4249 gfx::Point3F(), gfx::PointF(2.f
, 2.f
),
4250 gfx::Size(10, 10), false, true, true);
4251 perspective_surface
->SetDrawsContent(true);
4253 LayerImpl
* scale_surface
= AddChild
<LayerImpl
>(parent
);
4254 SetLayerPropertiesForTesting(scale_surface
, scale_small_matrix
,
4255 gfx::Point3F(), gfx::PointF(2.f
, 2.f
),
4256 gfx::Size(10, 10), false, true, true);
4257 scale_surface
->SetDrawsContent(true);
4259 float device_scale_factor
= 2.5f
;
4260 float page_scale_factor
= 3.f
;
4261 ExecuteCalculateDrawProperties(root
, device_scale_factor
, page_scale_factor
,
4264 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4265 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4266 perspective_surface
);
4267 // Ideal scale is the max 2d scale component of the combined transform up to
4268 // the nearest render target. Here this includes the layer transform as well
4269 // as the device and page scale factors.
4270 gfx::Transform transform
= scale_small_matrix
;
4271 transform
.Scale(device_scale_factor
* page_scale_factor
,
4272 device_scale_factor
* page_scale_factor
);
4273 gfx::Vector2dF scales
=
4274 MathUtil::ComputeTransform2dScaleComponents(transform
, 0.f
);
4275 float max_2d_scale
= std::max(scales
.x(), scales
.y());
4276 EXPECT_IDEAL_SCALE_EQ(max_2d_scale
, scale_surface
);
4278 // The ideal scale will draw 1:1 with its render target space along
4279 // the larger-scale axis.
4280 gfx::Vector2dF target_space_transform_scales
=
4281 MathUtil::ComputeTransform2dScaleComponents(
4282 scale_surface
->draw_properties().target_space_transform
, 0.f
);
4283 EXPECT_FLOAT_EQ(max_2d_scale
,
4284 std::max(target_space_transform_scales
.x(),
4285 target_space_transform_scales
.y()));
4287 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
4289 gfx::Transform expected_parent_draw_transform
;
4290 expected_parent_draw_transform
.Scale(device_scale_factor
* page_scale_factor
,
4291 device_scale_factor
* page_scale_factor
);
4292 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform
,
4293 parent
->draw_transform());
4295 // The scale for the perspective surface is not known, so it is rendered 1:1
4296 // with the screen, and then scaled during drawing.
4297 gfx::Transform expected_perspective_surface_draw_transform
;
4298 expected_perspective_surface_draw_transform
.Translate(
4299 device_scale_factor
* page_scale_factor
*
4300 perspective_surface
->position().x(),
4301 device_scale_factor
* page_scale_factor
*
4302 perspective_surface
->position().y());
4303 expected_perspective_surface_draw_transform
.PreconcatTransform(
4304 perspective_matrix
);
4305 expected_perspective_surface_draw_transform
.PreconcatTransform(
4306 scale_small_matrix
);
4307 gfx::Transform expected_perspective_surface_layer_draw_transform
;
4308 expected_perspective_surface_layer_draw_transform
.Scale(
4309 device_scale_factor
* page_scale_factor
,
4310 device_scale_factor
* page_scale_factor
);
4311 EXPECT_TRANSFORMATION_MATRIX_EQ(
4312 expected_perspective_surface_draw_transform
,
4313 perspective_surface
->render_surface()->draw_transform());
4314 EXPECT_TRANSFORMATION_MATRIX_EQ(
4315 expected_perspective_surface_layer_draw_transform
,
4316 perspective_surface
->draw_transform());
4319 TEST_F(LayerTreeHostCommonScalingTest
, SmallIdealScale
) {
4320 gfx::Transform parent_scale_matrix
;
4321 SkMScalar initial_parent_scale
= 1.75;
4322 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4324 gfx::Transform child_scale_matrix
;
4325 SkMScalar initial_child_scale
= 0.25;
4326 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4328 LayerImpl
* root
= root_layer();
4329 root
->SetBounds(gfx::Size(100, 100));
4331 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
4332 SetLayerPropertiesForTesting(parent
, parent_scale_matrix
, gfx::Point3F(),
4333 gfx::PointF(), gfx::Size(100, 100), false, true,
4336 LayerImpl
* child_scale
= AddChild
<LayerImpl
>(parent
);
4337 SetLayerPropertiesForTesting(child_scale
, child_scale_matrix
, gfx::Point3F(),
4338 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
4341 float device_scale_factor
= 2.5f
;
4342 float page_scale_factor
= 0.01f
;
4345 ExecuteCalculateDrawProperties(root
, device_scale_factor
, page_scale_factor
,
4348 // The ideal scale is able to go below 1.
4349 float expected_ideal_scale
=
4350 device_scale_factor
* page_scale_factor
* initial_parent_scale
;
4351 EXPECT_LT(expected_ideal_scale
, 1.f
);
4352 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, parent
);
4354 expected_ideal_scale
= device_scale_factor
* page_scale_factor
*
4355 initial_parent_scale
* initial_child_scale
;
4356 EXPECT_LT(expected_ideal_scale
, 1.f
);
4357 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, child_scale
);
4361 TEST_F(LayerTreeHostCommonScalingTest
, IdealScaleForAnimatingLayer
) {
4362 gfx::Transform parent_scale_matrix
;
4363 SkMScalar initial_parent_scale
= 1.75;
4364 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4366 gfx::Transform child_scale_matrix
;
4367 SkMScalar initial_child_scale
= 1.25;
4368 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4370 LayerImpl
* root
= root_layer();
4371 root
->SetBounds(gfx::Size(100, 100));
4373 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
4374 SetLayerPropertiesForTesting(parent
, parent_scale_matrix
, gfx::Point3F(),
4375 gfx::PointF(), gfx::Size(100, 100), false, true,
4378 LayerImpl
* child_scale
= AddChild
<LayerImpl
>(parent
);
4379 SetLayerPropertiesForTesting(child_scale
, child_scale_matrix
, gfx::Point3F(),
4380 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
4384 ExecuteCalculateDrawProperties(root
);
4386 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale
, parent
);
4387 // Animating layers compute ideal scale in the same way as when
4389 EXPECT_IDEAL_SCALE_EQ(initial_child_scale
* initial_parent_scale
,
4394 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceTransformsInHighDPI
) {
4395 MockContentLayerClient delegate
;
4396 gfx::Transform identity_matrix
;
4398 scoped_refptr
<FakePictureLayer
> parent
=
4399 CreateDrawablePictureLayer(layer_settings(), &delegate
);
4400 SetLayerPropertiesForTesting(parent
.get(),
4408 scoped_refptr
<FakePictureLayer
> child
=
4409 CreateDrawablePictureLayer(layer_settings(), &delegate
);
4410 SetLayerPropertiesForTesting(child
.get(),
4413 gfx::PointF(2.f
, 2.f
),
4418 gfx::Transform replica_transform
;
4419 replica_transform
.Scale(1.0, -1.0);
4420 scoped_refptr
<FakePictureLayer
> replica
=
4421 CreateDrawablePictureLayer(layer_settings(), &delegate
);
4422 SetLayerPropertiesForTesting(replica
.get(),
4425 gfx::PointF(2.f
, 2.f
),
4430 // This layer should end up in the same surface as child, with the same draw
4431 // and screen space transforms.
4432 scoped_refptr
<FakePictureLayer
> duplicate_child_non_owner
=
4433 CreateDrawablePictureLayer(layer_settings(), &delegate
);
4434 SetLayerPropertiesForTesting(duplicate_child_non_owner
.get(),
4442 parent
->AddChild(child
);
4443 child
->AddChild(duplicate_child_non_owner
);
4444 child
->SetReplicaLayer(replica
.get());
4446 host()->SetRootLayer(parent
);
4448 RenderSurfaceLayerList render_surface_layer_list
;
4450 float device_scale_factor
= 1.5f
;
4451 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4452 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4453 inputs
.device_scale_factor
= device_scale_factor
;
4454 inputs
.can_adjust_raster_scales
= true;
4455 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4457 // We should have two render surfaces. The root's render surface and child's
4458 // render surface (it needs one because it has a replica layer).
4459 EXPECT_EQ(2u, render_surface_layer_list
.size());
4461 gfx::Transform expected_parent_transform
;
4462 expected_parent_transform
.Scale(device_scale_factor
, device_scale_factor
);
4463 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4464 parent
->screen_space_transform());
4465 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4466 parent
->draw_transform());
4468 gfx::Transform expected_draw_transform
;
4469 expected_draw_transform
.Scale(device_scale_factor
, device_scale_factor
);
4470 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform
,
4471 child
->draw_transform());
4473 gfx::Transform expected_screen_space_transform
;
4474 expected_screen_space_transform
.Scale(device_scale_factor
,
4475 device_scale_factor
);
4476 expected_screen_space_transform
.Translate(child
->position().x(),
4477 child
->position().y());
4478 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform
,
4479 child
->screen_space_transform());
4481 gfx::Transform expected_duplicate_child_draw_transform
=
4482 child
->draw_transform();
4483 EXPECT_TRANSFORMATION_MATRIX_EQ(child
->draw_transform(),
4484 duplicate_child_non_owner
->draw_transform());
4485 EXPECT_TRANSFORMATION_MATRIX_EQ(
4486 child
->screen_space_transform(),
4487 duplicate_child_non_owner
->screen_space_transform());
4488 EXPECT_EQ(child
->drawable_content_rect(),
4489 duplicate_child_non_owner
->drawable_content_rect());
4490 EXPECT_EQ(child
->bounds(), duplicate_child_non_owner
->bounds());
4492 gfx::Transform expected_render_surface_draw_transform
;
4493 expected_render_surface_draw_transform
.Translate(
4494 device_scale_factor
* child
->position().x(),
4495 device_scale_factor
* child
->position().y());
4496 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform
,
4497 child
->render_surface()->draw_transform());
4499 gfx::Transform expected_surface_draw_transform
;
4500 expected_surface_draw_transform
.Translate(device_scale_factor
* 2.f
,
4501 device_scale_factor
* 2.f
);
4502 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform
,
4503 child
->render_surface()->draw_transform());
4505 gfx::Transform expected_surface_screen_space_transform
;
4506 expected_surface_screen_space_transform
.Translate(device_scale_factor
* 2.f
,
4507 device_scale_factor
* 2.f
);
4508 EXPECT_TRANSFORMATION_MATRIX_EQ(
4509 expected_surface_screen_space_transform
,
4510 child
->render_surface()->screen_space_transform());
4512 gfx::Transform expected_replica_draw_transform
;
4513 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
4514 expected_replica_draw_transform
.matrix().set(0, 3, 6.0);
4515 expected_replica_draw_transform
.matrix().set(1, 3, 6.0);
4516 EXPECT_TRANSFORMATION_MATRIX_EQ(
4517 expected_replica_draw_transform
,
4518 child
->render_surface()->replica_draw_transform());
4520 gfx::Transform expected_replica_screen_space_transform
;
4521 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
4522 expected_replica_screen_space_transform
.matrix().set(0, 3, 6.0);
4523 expected_replica_screen_space_transform
.matrix().set(1, 3, 6.0);
4524 EXPECT_TRANSFORMATION_MATRIX_EQ(
4525 expected_replica_screen_space_transform
,
4526 child
->render_surface()->replica_screen_space_transform());
4527 EXPECT_TRANSFORMATION_MATRIX_EQ(
4528 expected_replica_screen_space_transform
,
4529 child
->render_surface()->replica_screen_space_transform());
4532 TEST_F(LayerTreeHostCommonTest
,
4533 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition
) {
4534 MockContentLayerClient delegate
;
4535 gfx::Transform identity_matrix
;
4537 scoped_refptr
<FakePictureLayer
> parent
=
4538 CreateDrawablePictureLayer(layer_settings(), &delegate
);
4539 SetLayerPropertiesForTesting(parent
.get(),
4547 scoped_refptr
<FakePictureLayer
> child
=
4548 CreateDrawablePictureLayer(layer_settings(), &delegate
);
4549 SetLayerPropertiesForTesting(child
.get(),
4557 gfx::Transform replica_transform
;
4558 replica_transform
.Scale(1.0, -1.0);
4559 scoped_refptr
<FakePictureLayer
> replica
=
4560 CreateDrawablePictureLayer(layer_settings(), &delegate
);
4561 SetLayerPropertiesForTesting(replica
.get(),
4569 parent
->AddChild(child
);
4570 child
->SetReplicaLayer(replica
.get());
4572 host()->SetRootLayer(parent
);
4574 float device_scale_factor
= 1.7f
;
4576 RenderSurfaceLayerList render_surface_layer_list
;
4577 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4578 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4579 inputs
.device_scale_factor
= device_scale_factor
;
4580 inputs
.can_adjust_raster_scales
= true;
4581 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4583 // We should have two render surfaces. The root's render surface and child's
4584 // render surface (it needs one because it has a replica layer).
4585 EXPECT_EQ(2u, render_surface_layer_list
.size());
4587 gfx::Transform identity_transform
;
4588 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
4589 child
->render_surface()->draw_transform());
4590 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
4591 child
->render_surface()->draw_transform());
4592 EXPECT_TRANSFORMATION_MATRIX_EQ(
4593 identity_transform
, child
->render_surface()->screen_space_transform());
4595 gfx::Transform expected_replica_draw_transform
;
4596 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
4597 EXPECT_TRANSFORMATION_MATRIX_EQ(
4598 expected_replica_draw_transform
,
4599 child
->render_surface()->replica_draw_transform());
4601 gfx::Transform expected_replica_screen_space_transform
;
4602 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
4603 EXPECT_TRANSFORMATION_MATRIX_EQ(
4604 expected_replica_screen_space_transform
,
4605 child
->render_surface()->replica_screen_space_transform());
4608 TEST_F(LayerTreeHostCommonTest
, SubtreeSearch
) {
4609 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4610 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
4611 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
4612 scoped_refptr
<Layer
> mask_layer
= Layer::Create(layer_settings());
4613 scoped_refptr
<Layer
> replica_layer
= Layer::Create(layer_settings());
4615 grand_child
->SetReplicaLayer(replica_layer
.get());
4616 child
->AddChild(grand_child
.get());
4617 child
->SetMaskLayer(mask_layer
.get());
4618 root
->AddChild(child
.get());
4620 host()->SetRootLayer(root
);
4622 int nonexistent_id
= -1;
4623 EXPECT_EQ(root
.get(),
4624 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), root
->id()));
4625 EXPECT_EQ(child
.get(),
4626 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), child
->id()));
4629 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), grand_child
->id()));
4632 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), mask_layer
->id()));
4634 replica_layer
.get(),
4635 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), replica_layer
->id()));
4637 0, LayerTreeHostCommon::FindLayerInSubtree(root
.get(), nonexistent_id
));
4640 TEST_F(LayerTreeHostCommonTest
, TransparentChildRenderSurfaceCreation
) {
4641 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4642 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
4643 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
4644 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4646 const gfx::Transform identity_matrix
;
4647 SetLayerPropertiesForTesting(root
.get(),
4651 gfx::Size(100, 100),
4654 SetLayerPropertiesForTesting(child
.get(),
4661 SetLayerPropertiesForTesting(grand_child
.get(),
4669 root
->AddChild(child
);
4670 child
->AddChild(grand_child
);
4671 child
->SetOpacity(0.5f
);
4673 host()->SetRootLayer(root
);
4675 ExecuteCalculateDrawProperties(root
.get());
4677 EXPECT_FALSE(child
->render_surface());
4680 TEST_F(LayerTreeHostCommonTest
, OpacityAnimatingOnPendingTree
) {
4681 FakeImplProxy proxy
;
4682 TestSharedBitmapManager shared_bitmap_manager
;
4683 TestTaskGraphRunner task_graph_runner
;
4684 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4685 &task_graph_runner
);
4686 host_impl
.CreatePendingTree();
4687 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4689 const gfx::Transform identity_matrix
;
4690 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4691 gfx::PointF(), gfx::Size(100, 100), true, false,
4693 root
->SetDrawsContent(true);
4695 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
4696 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
4697 gfx::PointF(), gfx::Size(50, 50), true, false,
4699 child
->SetDrawsContent(true);
4700 child
->SetOpacity(0.0f
);
4702 // Add opacity animation.
4703 AddOpacityTransitionToController(
4704 child
->layer_animation_controller(), 10.0, 0.0f
, 1.0f
, false);
4706 root
->AddChild(child
.Pass());
4707 root
->SetHasRenderSurface(true);
4709 LayerImplList render_surface_layer_list
;
4710 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4711 root
.get(), root
->bounds(), &render_surface_layer_list
);
4712 inputs
.can_adjust_raster_scales
= true;
4713 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4715 // We should have one render surface and two layers. The child
4716 // layer should be included even though it is transparent.
4717 ASSERT_EQ(1u, render_surface_layer_list
.size());
4718 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
4721 using LCDTextTestParam
= std::tr1::tuple
<bool, bool, bool>;
4722 class LCDTextTest
: public LayerTreeHostCommonTestBase
,
4723 public testing::TestWithParam
<LCDTextTestParam
> {
4726 : LayerTreeHostCommonTestBase(LayerTreeSettings()),
4727 host_impl_(&proxy_
, &shared_bitmap_manager_
, &task_graph_runner_
),
4730 grand_child_(nullptr) {}
4733 void SetUp() override
{
4734 can_use_lcd_text_
= std::tr1::get
<0>(GetParam());
4735 layers_always_allowed_lcd_text_
= std::tr1::get
<1>(GetParam());
4737 scoped_ptr
<LayerImpl
> root_ptr
=
4738 LayerImpl::Create(host_impl_
.active_tree(), 1);
4739 scoped_ptr
<LayerImpl
> child_ptr
=
4740 LayerImpl::Create(host_impl_
.active_tree(), 2);
4741 scoped_ptr
<LayerImpl
> grand_child_ptr
=
4742 LayerImpl::Create(host_impl_
.active_tree(), 3);
4744 // Stash raw pointers to look at later.
4745 root_
= root_ptr
.get();
4746 child_
= child_ptr
.get();
4747 grand_child_
= grand_child_ptr
.get();
4749 child_
->AddChild(grand_child_ptr
.Pass());
4750 root_
->AddChild(child_ptr
.Pass());
4751 host_impl_
.active_tree()->SetRootLayer(root_ptr
.Pass());
4753 root_
->SetContentsOpaque(true);
4754 child_
->SetContentsOpaque(true);
4755 grand_child_
->SetContentsOpaque(true);
4757 root_
->SetDrawsContent(true);
4758 child_
->SetDrawsContent(true);
4759 grand_child_
->SetDrawsContent(true);
4761 gfx::Transform identity_matrix
;
4762 SetLayerPropertiesForTesting(root_
, identity_matrix
, gfx::Point3F(),
4763 gfx::PointF(), gfx::Size(1, 1), true, false,
4765 SetLayerPropertiesForTesting(child_
, identity_matrix
, gfx::Point3F(),
4766 gfx::PointF(), gfx::Size(1, 1), true, false,
4767 std::tr1::get
<2>(GetParam()));
4768 SetLayerPropertiesForTesting(grand_child_
, identity_matrix
, gfx::Point3F(),
4769 gfx::PointF(), gfx::Size(1, 1), true, false,
4773 bool can_use_lcd_text_
;
4774 bool layers_always_allowed_lcd_text_
;
4776 FakeImplProxy proxy_
;
4777 TestSharedBitmapManager shared_bitmap_manager_
;
4778 TestTaskGraphRunner task_graph_runner_
;
4779 FakeLayerTreeHostImpl host_impl_
;
4783 LayerImpl
* grand_child_
;
4786 TEST_P(LCDTextTest
, CanUseLCDText
) {
4787 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
4788 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
4790 // Case 1: Identity transform.
4791 gfx::Transform identity_matrix
;
4792 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4793 layers_always_allowed_lcd_text_
);
4794 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4795 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4796 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4798 // Case 2: Integral translation.
4799 gfx::Transform integral_translation
;
4800 integral_translation
.Translate(1.0, 2.0);
4801 child_
->SetTransform(integral_translation
);
4802 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4803 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4804 layers_always_allowed_lcd_text_
);
4805 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4806 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4807 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4809 // Case 3: Non-integral translation.
4810 gfx::Transform non_integral_translation
;
4811 non_integral_translation
.Translate(1.5, 2.5);
4812 child_
->SetTransform(non_integral_translation
);
4813 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4814 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4815 layers_always_allowed_lcd_text_
);
4816 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4817 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4818 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4820 // Case 4: Rotation.
4821 gfx::Transform rotation
;
4822 rotation
.Rotate(10.0);
4823 child_
->SetTransform(rotation
);
4824 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4825 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4826 layers_always_allowed_lcd_text_
);
4827 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4828 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4829 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4832 gfx::Transform scale
;
4833 scale
.Scale(2.0, 2.0);
4834 child_
->SetTransform(scale
);
4835 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4836 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4837 layers_always_allowed_lcd_text_
);
4838 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4839 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4840 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4843 gfx::Transform skew
;
4845 child_
->SetTransform(skew
);
4846 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4847 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4848 layers_always_allowed_lcd_text_
);
4849 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4850 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4851 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4853 // Case 7: Translucent.
4854 child_
->SetTransform(identity_matrix
);
4855 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4856 child_
->SetOpacity(0.5f
);
4857 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4858 layers_always_allowed_lcd_text_
);
4859 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4860 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4861 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4863 // Case 8: Sanity check: restore transform and opacity.
4864 child_
->SetTransform(identity_matrix
);
4865 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4866 child_
->SetOpacity(1.f
);
4867 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4868 layers_always_allowed_lcd_text_
);
4869 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4870 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4871 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4873 // Case 9: Non-opaque content.
4874 child_
->SetContentsOpaque(false);
4875 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4876 layers_always_allowed_lcd_text_
);
4877 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4878 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4879 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4881 // Case 10: Sanity check: restore content opaqueness.
4882 child_
->SetContentsOpaque(true);
4883 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4884 layers_always_allowed_lcd_text_
);
4885 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4886 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4887 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4890 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimation
) {
4891 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
4892 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
4894 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
4895 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4896 layers_always_allowed_lcd_text_
);
4897 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4898 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4899 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4901 // Add opacity animation.
4902 child_
->SetOpacity(0.9f
);
4903 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4904 AddOpacityTransitionToController(
4905 child_
->layer_animation_controller(), 10.0, 0.9f
, 0.1f
, false);
4907 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4908 layers_always_allowed_lcd_text_
);
4909 // Text LCD should be adjusted while animation is active.
4910 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4911 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4912 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4915 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimationContentsOpaque
) {
4916 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
4917 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
4919 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
4920 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4921 layers_always_allowed_lcd_text_
);
4922 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4923 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4924 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4926 // Mark contents non-opaque within the first animation frame.
4927 child_
->SetContentsOpaque(false);
4928 AddOpacityTransitionToController(child_
->layer_animation_controller(), 10.0,
4931 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4932 layers_always_allowed_lcd_text_
);
4933 // LCD text should be disabled for non-opaque layers even during animations.
4934 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4935 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4936 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4939 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest
,
4941 testing::Combine(testing::Bool(),
4945 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayer
) {
4946 FakeImplProxy proxy
;
4947 TestSharedBitmapManager shared_bitmap_manager
;
4948 TestTaskGraphRunner task_graph_runner
;
4949 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4950 &task_graph_runner
);
4951 host_impl
.CreatePendingTree();
4952 const gfx::Transform identity_matrix
;
4954 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4955 SetLayerPropertiesForTesting(root
.get(),
4962 root
->SetIsDrawable(true);
4964 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
4965 SetLayerPropertiesForTesting(child
.get(),
4972 child
->SetIsDrawable(true);
4974 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
4975 SetLayerPropertiesForTesting(grand_child
.get(),
4982 grand_child
->SetIsDrawable(true);
4983 grand_child
->SetHideLayerAndSubtree(true);
4985 child
->AddChild(grand_child
);
4986 root
->AddChild(child
);
4988 host()->SetRootLayer(root
);
4990 RenderSurfaceLayerList render_surface_layer_list
;
4991 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4992 root
.get(), root
->bounds(), &render_surface_layer_list
);
4993 inputs
.can_adjust_raster_scales
= true;
4994 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4996 // We should have one render surface and two layers. The grand child has
4998 ASSERT_EQ(1u, render_surface_layer_list
.size());
4999 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5000 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
5001 EXPECT_EQ(child
->id(), root
->render_surface()->layer_list().at(1)->id());
5004 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayerImpl
) {
5005 FakeImplProxy proxy
;
5006 TestSharedBitmapManager shared_bitmap_manager
;
5007 TestTaskGraphRunner task_graph_runner
;
5008 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5009 &task_graph_runner
);
5010 host_impl
.CreatePendingTree();
5011 const gfx::Transform identity_matrix
;
5013 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
5014 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
5015 gfx::PointF(), gfx::Size(50, 50), true, false,
5017 root
->SetDrawsContent(true);
5019 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
5020 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
5021 gfx::PointF(), gfx::Size(40, 40), true, false,
5023 child
->SetDrawsContent(true);
5025 scoped_ptr
<LayerImpl
> grand_child
=
5026 LayerImpl::Create(host_impl
.pending_tree(), 3);
5027 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
5028 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5029 true, false, false);
5030 grand_child
->SetDrawsContent(true);
5031 grand_child
->SetHideLayerAndSubtree(true);
5033 child
->AddChild(grand_child
.Pass());
5034 root
->AddChild(child
.Pass());
5035 root
->SetHasRenderSurface(true);
5037 LayerImplList render_surface_layer_list
;
5038 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5039 root
.get(), root
->bounds(), &render_surface_layer_list
);
5040 inputs
.can_adjust_raster_scales
= true;
5041 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5043 // We should have one render surface and two layers. The grand child has
5045 ASSERT_EQ(1u, render_surface_layer_list
.size());
5046 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5047 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
5048 EXPECT_EQ(2, root
->render_surface()->layer_list().at(1)->id());
5051 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayers
) {
5052 FakeImplProxy proxy
;
5053 TestSharedBitmapManager shared_bitmap_manager
;
5054 TestTaskGraphRunner task_graph_runner
;
5055 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5056 &task_graph_runner
);
5057 host_impl
.CreatePendingTree();
5058 const gfx::Transform identity_matrix
;
5060 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5061 SetLayerPropertiesForTesting(root
.get(),
5068 root
->SetIsDrawable(true);
5070 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
5071 SetLayerPropertiesForTesting(child
.get(),
5078 child
->SetIsDrawable(true);
5079 child
->SetHideLayerAndSubtree(true);
5081 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
5082 SetLayerPropertiesForTesting(grand_child
.get(),
5089 grand_child
->SetIsDrawable(true);
5091 child
->AddChild(grand_child
);
5092 root
->AddChild(child
);
5094 host()->SetRootLayer(root
);
5096 RenderSurfaceLayerList render_surface_layer_list
;
5097 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5098 root
.get(), root
->bounds(), &render_surface_layer_list
);
5099 inputs
.can_adjust_raster_scales
= true;
5100 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5102 // We should have one render surface and one layers. The child has
5103 // hidden itself and the grand child.
5104 ASSERT_EQ(1u, render_surface_layer_list
.size());
5105 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
5106 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
5109 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayersImpl
) {
5110 FakeImplProxy proxy
;
5111 TestSharedBitmapManager shared_bitmap_manager
;
5112 TestTaskGraphRunner task_graph_runner
;
5113 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5114 &task_graph_runner
);
5115 host_impl
.CreatePendingTree();
5116 const gfx::Transform identity_matrix
;
5118 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
5119 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
5120 gfx::PointF(), gfx::Size(50, 50), true, false,
5122 root
->SetDrawsContent(true);
5124 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
5125 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
5126 gfx::PointF(), gfx::Size(40, 40), true, false,
5128 child
->SetDrawsContent(true);
5129 child
->SetHideLayerAndSubtree(true);
5131 scoped_ptr
<LayerImpl
> grand_child
=
5132 LayerImpl::Create(host_impl
.pending_tree(), 3);
5133 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
5134 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5135 true, false, false);
5136 grand_child
->SetDrawsContent(true);
5138 child
->AddChild(grand_child
.Pass());
5139 root
->AddChild(child
.Pass());
5141 LayerImplList render_surface_layer_list
;
5142 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5143 root
.get(), root
->bounds(), &render_surface_layer_list
);
5144 inputs
.can_adjust_raster_scales
= true;
5145 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5147 // We should have one render surface and one layers. The child has
5148 // hidden itself and the grand child.
5149 ASSERT_EQ(1u, render_surface_layer_list
.size());
5150 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
5151 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
5154 void EmptyCopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {}
5156 TEST_F(LayerTreeHostCommonTest
, SubtreeHiddenWithCopyRequest
) {
5157 FakeImplProxy proxy
;
5158 TestSharedBitmapManager shared_bitmap_manager
;
5159 TestTaskGraphRunner task_graph_runner
;
5160 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5161 &task_graph_runner
);
5162 host_impl
.CreatePendingTree();
5163 const gfx::Transform identity_matrix
;
5165 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5166 SetLayerPropertiesForTesting(root
.get(),
5173 root
->SetIsDrawable(true);
5175 scoped_refptr
<Layer
> copy_grand_parent
= Layer::Create(layer_settings());
5176 SetLayerPropertiesForTesting(copy_grand_parent
.get(),
5183 copy_grand_parent
->SetIsDrawable(true);
5185 scoped_refptr
<Layer
> copy_parent
= Layer::Create(layer_settings());
5186 SetLayerPropertiesForTesting(copy_parent
.get(),
5193 copy_parent
->SetIsDrawable(true);
5194 copy_parent
->SetForceRenderSurface(true);
5196 scoped_refptr
<Layer
> copy_layer
= Layer::Create(layer_settings());
5197 SetLayerPropertiesForTesting(copy_layer
.get(),
5204 copy_layer
->SetIsDrawable(true);
5206 scoped_refptr
<Layer
> copy_child
= Layer::Create(layer_settings());
5207 SetLayerPropertiesForTesting(copy_child
.get(),
5214 copy_child
->SetIsDrawable(true);
5216 scoped_refptr
<Layer
> copy_grand_parent_sibling_before
=
5217 Layer::Create(layer_settings());
5218 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before
.get(),
5225 copy_grand_parent_sibling_before
->SetIsDrawable(true);
5227 scoped_refptr
<Layer
> copy_grand_parent_sibling_after
=
5228 Layer::Create(layer_settings());
5229 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after
.get(),
5236 copy_grand_parent_sibling_after
->SetIsDrawable(true);
5238 copy_layer
->AddChild(copy_child
);
5239 copy_parent
->AddChild(copy_layer
);
5240 copy_grand_parent
->AddChild(copy_parent
);
5241 root
->AddChild(copy_grand_parent_sibling_before
);
5242 root
->AddChild(copy_grand_parent
);
5243 root
->AddChild(copy_grand_parent_sibling_after
);
5245 host()->SetRootLayer(root
);
5247 // Hide the copy_grand_parent and its subtree. But make a copy request in that
5248 // hidden subtree on copy_layer.
5249 copy_grand_parent
->SetHideLayerAndSubtree(true);
5250 copy_grand_parent_sibling_before
->SetHideLayerAndSubtree(true);
5251 copy_grand_parent_sibling_after
->SetHideLayerAndSubtree(true);
5252 copy_layer
->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
5253 base::Bind(&EmptyCopyOutputCallback
)));
5254 EXPECT_TRUE(copy_layer
->HasCopyRequest());
5256 RenderSurfaceLayerList render_surface_layer_list
;
5257 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5258 root
.get(), root
->bounds(), &render_surface_layer_list
);
5259 inputs
.can_adjust_raster_scales
= true;
5260 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5262 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
5263 EXPECT_TRUE(copy_grand_parent
->draw_properties().
5264 layer_or_descendant_has_copy_request
);
5265 EXPECT_TRUE(copy_parent
->draw_properties().
5266 layer_or_descendant_has_copy_request
);
5267 EXPECT_TRUE(copy_layer
->draw_properties().
5268 layer_or_descendant_has_copy_request
);
5269 EXPECT_FALSE(copy_child
->draw_properties().
5270 layer_or_descendant_has_copy_request
);
5271 EXPECT_FALSE(copy_grand_parent_sibling_before
->draw_properties().
5272 layer_or_descendant_has_copy_request
);
5273 EXPECT_FALSE(copy_grand_parent_sibling_after
->draw_properties().
5274 layer_or_descendant_has_copy_request
);
5276 // We should have three render surfaces, one for the root, one for the parent
5277 // since it owns a surface, and one for the copy_layer.
5278 ASSERT_EQ(3u, render_surface_layer_list
.size());
5279 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
5280 EXPECT_EQ(copy_parent
->id(), render_surface_layer_list
.at(1)->id());
5281 EXPECT_EQ(copy_layer
->id(), render_surface_layer_list
.at(2)->id());
5283 // The root render surface should have 2 contributing layers. The
5284 // copy_grand_parent is hidden along with its siblings, but the copy_parent
5285 // will appear since something in its subtree needs to be drawn for a copy
5287 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5288 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
5289 EXPECT_EQ(copy_parent
->id(),
5290 root
->render_surface()->layer_list().at(1)->id());
5292 // Nothing actually draws into the copy parent, so only the copy_layer will
5293 // appear in its list, since it needs to be drawn for the copy request.
5294 ASSERT_EQ(1u, copy_parent
->render_surface()->layer_list().size());
5295 EXPECT_EQ(copy_layer
->id(),
5296 copy_parent
->render_surface()->layer_list().at(0)->id());
5298 // The copy_layer's render surface should have two contributing layers.
5299 ASSERT_EQ(2u, copy_layer
->render_surface()->layer_list().size());
5300 EXPECT_EQ(copy_layer
->id(),
5301 copy_layer
->render_surface()->layer_list().at(0)->id());
5302 EXPECT_EQ(copy_child
->id(),
5303 copy_layer
->render_surface()->layer_list().at(1)->id());
5306 TEST_F(LayerTreeHostCommonTest
, ClippedOutCopyRequest
) {
5307 FakeImplProxy proxy
;
5308 TestSharedBitmapManager shared_bitmap_manager
;
5309 TestTaskGraphRunner task_graph_runner
;
5310 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5311 &task_graph_runner
);
5312 host_impl
.CreatePendingTree();
5313 const gfx::Transform identity_matrix
;
5315 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5316 SetLayerPropertiesForTesting(root
.get(),
5323 root
->SetIsDrawable(true);
5325 scoped_refptr
<Layer
> copy_parent
= Layer::Create(layer_settings());
5326 SetLayerPropertiesForTesting(copy_parent
.get(),
5333 copy_parent
->SetIsDrawable(true);
5334 copy_parent
->SetMasksToBounds(true);
5336 scoped_refptr
<Layer
> copy_layer
= Layer::Create(layer_settings());
5337 SetLayerPropertiesForTesting(copy_layer
.get(),
5344 copy_layer
->SetIsDrawable(true);
5346 scoped_refptr
<Layer
> copy_child
= Layer::Create(layer_settings());
5347 SetLayerPropertiesForTesting(copy_child
.get(),
5354 copy_child
->SetIsDrawable(true);
5356 copy_layer
->AddChild(copy_child
);
5357 copy_parent
->AddChild(copy_layer
);
5358 root
->AddChild(copy_parent
);
5360 host()->SetRootLayer(root
);
5362 copy_layer
->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
5363 base::Bind(&EmptyCopyOutputCallback
)));
5364 EXPECT_TRUE(copy_layer
->HasCopyRequest());
5366 RenderSurfaceLayerList render_surface_layer_list
;
5367 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5368 root
.get(), root
->bounds(), &render_surface_layer_list
);
5369 inputs
.can_adjust_raster_scales
= true;
5370 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5372 // We should have one render surface, as the others are clipped out.
5373 ASSERT_EQ(1u, render_surface_layer_list
.size());
5374 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
5376 // The root render surface should only have 1 contributing layer, since the
5377 // other layers are empty/clipped away.
5378 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
5379 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
5382 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInsideSurface
) {
5383 FakeImplProxy proxy
;
5384 TestSharedBitmapManager shared_bitmap_manager
;
5385 TestTaskGraphRunner task_graph_runner
;
5386 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5387 &task_graph_runner
);
5388 host_impl
.CreatePendingTree();
5389 const gfx::Transform identity_matrix
;
5391 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5392 SetLayerPropertiesForTesting(root
.get(),
5399 root
->SetIsDrawable(true);
5401 // The surface is moved slightly outside of the viewport.
5402 scoped_refptr
<Layer
> surface
= Layer::Create(layer_settings());
5403 SetLayerPropertiesForTesting(surface
.get(),
5406 gfx::PointF(-10, -20),
5410 surface
->SetForceRenderSurface(true);
5412 scoped_refptr
<Layer
> surface_child
= Layer::Create(layer_settings());
5413 SetLayerPropertiesForTesting(surface_child
.get(),
5420 surface_child
->SetIsDrawable(true);
5422 surface
->AddChild(surface_child
);
5423 root
->AddChild(surface
);
5425 host()->SetRootLayer(root
);
5427 RenderSurfaceLayerList render_surface_layer_list
;
5428 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5429 root
.get(), root
->bounds(), &render_surface_layer_list
);
5430 inputs
.can_adjust_raster_scales
= true;
5431 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5433 // The visible_layer_rect for the |surface_child| should not be clipped by
5435 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
5436 surface_child
->visible_layer_rect().ToString());
5439 TEST_F(LayerTreeHostCommonTest
, TransformedClipParent
) {
5440 // Ensure that a transform between the layer and its render surface is not a
5441 // problem. Constructs the following layer tree.
5443 // root (a render surface)
5445 // + clip_parent (scaled)
5446 // + intervening_clipping_layer
5449 // The render surface should be resized correctly and the clip child should
5450 // inherit the right clip rect.
5451 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5452 scoped_refptr
<Layer
> render_surface
= Layer::Create(layer_settings());
5453 scoped_refptr
<Layer
> clip_parent
= Layer::Create(layer_settings());
5454 scoped_refptr
<Layer
> intervening
= Layer::Create(layer_settings());
5455 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
5456 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5458 root
->AddChild(render_surface
);
5459 render_surface
->AddChild(clip_parent
);
5460 clip_parent
->AddChild(intervening
);
5461 intervening
->AddChild(clip_child
);
5463 clip_child
->SetClipParent(clip_parent
.get());
5465 intervening
->SetMasksToBounds(true);
5466 clip_parent
->SetMasksToBounds(true);
5468 render_surface
->SetForceRenderSurface(true);
5470 gfx::Transform scale_transform
;
5471 scale_transform
.Scale(2, 2);
5473 gfx::Transform identity_transform
;
5475 SetLayerPropertiesForTesting(root
.get(),
5482 SetLayerPropertiesForTesting(render_surface
.get(),
5489 SetLayerPropertiesForTesting(clip_parent
.get(),
5492 gfx::PointF(1.f
, 1.f
),
5496 SetLayerPropertiesForTesting(intervening
.get(),
5499 gfx::PointF(1.f
, 1.f
),
5503 SetLayerPropertiesForTesting(clip_child
.get(),
5506 gfx::PointF(1.f
, 1.f
),
5511 host()->SetRootLayer(root
);
5513 ExecuteCalculateDrawProperties(root
.get());
5515 ASSERT_TRUE(root
->render_surface());
5516 ASSERT_TRUE(render_surface
->render_surface());
5518 // Ensure that we've inherited our clip parent's clip and weren't affected
5519 // by the intervening clip layer.
5520 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
5521 clip_parent
->clip_rect().ToString());
5522 ASSERT_EQ(clip_parent
->clip_rect().ToString(),
5523 clip_child
->clip_rect().ToString());
5524 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
5525 intervening
->clip_rect().ToString());
5527 // Ensure that the render surface reports a content rect that has been grown
5528 // to accomodate for the clip child.
5529 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
5530 render_surface
->render_surface()->content_rect().ToString());
5532 // The above check implies the two below, but they nicely demonstrate that
5533 // we've grown, despite the intervening layer's clip.
5534 ASSERT_TRUE(clip_parent
->clip_rect().Contains(
5535 render_surface
->render_surface()->content_rect()));
5536 ASSERT_FALSE(intervening
->clip_rect().Contains(
5537 render_surface
->render_surface()->content_rect()));
5540 TEST_F(LayerTreeHostCommonTest
, ClipParentWithInterveningRenderSurface
) {
5541 // Ensure that intervening render surfaces are not a problem in the basic
5542 // case. In the following tree, both render surfaces should be resized to
5543 // accomodate for the clip child, despite an intervening clip.
5545 // root (a render surface)
5546 // + clip_parent (masks to bounds)
5547 // + render_surface1 (sets opacity)
5548 // + intervening (masks to bounds)
5549 // + render_surface2 (also sets opacity)
5552 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5553 scoped_refptr
<Layer
> clip_parent
= Layer::Create(layer_settings());
5554 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
5555 scoped_refptr
<Layer
> intervening
= Layer::Create(layer_settings());
5556 scoped_refptr
<Layer
> render_surface2
= Layer::Create(layer_settings());
5557 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
5558 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5560 root
->AddChild(clip_parent
);
5561 clip_parent
->AddChild(render_surface1
);
5562 render_surface1
->AddChild(intervening
);
5563 intervening
->AddChild(render_surface2
);
5564 render_surface2
->AddChild(clip_child
);
5566 clip_child
->SetClipParent(clip_parent
.get());
5568 intervening
->SetMasksToBounds(true);
5569 clip_parent
->SetMasksToBounds(true);
5571 render_surface1
->SetForceRenderSurface(true);
5572 render_surface2
->SetForceRenderSurface(true);
5574 gfx::Transform translation_transform
;
5575 translation_transform
.Translate(2, 2);
5577 gfx::Transform identity_transform
;
5578 SetLayerPropertiesForTesting(root
.get(),
5585 SetLayerPropertiesForTesting(clip_parent
.get(),
5586 translation_transform
,
5588 gfx::PointF(1.f
, 1.f
),
5592 SetLayerPropertiesForTesting(render_surface1
.get(),
5599 SetLayerPropertiesForTesting(intervening
.get(),
5602 gfx::PointF(1.f
, 1.f
),
5606 SetLayerPropertiesForTesting(render_surface2
.get(),
5613 SetLayerPropertiesForTesting(clip_child
.get(),
5616 gfx::PointF(-10.f
, -10.f
),
5621 host()->SetRootLayer(root
);
5623 ExecuteCalculateDrawProperties(root
.get());
5625 EXPECT_TRUE(root
->render_surface());
5626 EXPECT_TRUE(render_surface1
->render_surface());
5627 EXPECT_TRUE(render_surface2
->render_surface());
5629 // Since the render surfaces could have expanded, they should not clip (their
5630 // bounds would no longer be reliable). We should resort to layer clipping
5632 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5633 render_surface1
->render_surface()->clip_rect().ToString());
5634 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
5635 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5636 render_surface2
->render_surface()->clip_rect().ToString());
5637 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
5639 // NB: clip rects are in target space.
5640 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5641 render_surface1
->clip_rect().ToString());
5642 EXPECT_TRUE(render_surface1
->is_clipped());
5644 // This value is inherited from the clipping ancestor layer, 'intervening'.
5645 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5646 render_surface2
->clip_rect().ToString());
5647 EXPECT_TRUE(render_surface2
->is_clipped());
5649 // The content rects of both render surfaces should both have expanded to
5650 // contain the clip child.
5651 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5652 render_surface1
->render_surface()->content_rect().ToString());
5653 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
5654 render_surface2
->render_surface()->content_rect().ToString());
5656 // The clip child should have inherited the clip parent's clip (projected to
5657 // the right space, of course), and should have the correctly sized visible
5659 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
5660 clip_child
->clip_rect().ToString());
5661 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
5662 clip_child
->visible_layer_rect().ToString());
5663 EXPECT_TRUE(clip_child
->is_clipped());
5666 TEST_F(LayerTreeHostCommonTest
, ClipParentScrolledInterveningLayer
) {
5667 // Ensure that intervening render surfaces are not a problem, even if there
5668 // is a scroll involved. Note, we do _not_ have to consider any other sort
5671 // root (a render surface)
5672 // + clip_parent (masks to bounds)
5673 // + render_surface1 (sets opacity)
5674 // + intervening (masks to bounds AND scrolls)
5675 // + render_surface2 (also sets opacity)
5678 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5679 scoped_refptr
<Layer
> clip_parent
= Layer::Create(layer_settings());
5680 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
5681 scoped_refptr
<Layer
> intervening
= Layer::Create(layer_settings());
5682 scoped_refptr
<Layer
> render_surface2
= Layer::Create(layer_settings());
5683 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
5684 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5686 root
->AddChild(clip_parent
);
5687 clip_parent
->AddChild(render_surface1
);
5688 render_surface1
->AddChild(intervening
);
5689 intervening
->AddChild(render_surface2
);
5690 render_surface2
->AddChild(clip_child
);
5692 clip_child
->SetClipParent(clip_parent
.get());
5694 intervening
->SetMasksToBounds(true);
5695 clip_parent
->SetMasksToBounds(true);
5696 intervening
->SetScrollClipLayerId(clip_parent
->id());
5697 intervening
->SetScrollOffset(gfx::ScrollOffset(3, 3));
5699 render_surface1
->SetForceRenderSurface(true);
5700 render_surface2
->SetForceRenderSurface(true);
5702 gfx::Transform translation_transform
;
5703 translation_transform
.Translate(2, 2);
5705 gfx::Transform identity_transform
;
5706 SetLayerPropertiesForTesting(root
.get(),
5713 SetLayerPropertiesForTesting(clip_parent
.get(),
5714 translation_transform
,
5716 gfx::PointF(1.f
, 1.f
),
5720 SetLayerPropertiesForTesting(render_surface1
.get(),
5727 SetLayerPropertiesForTesting(intervening
.get(),
5730 gfx::PointF(1.f
, 1.f
),
5734 SetLayerPropertiesForTesting(render_surface2
.get(),
5741 SetLayerPropertiesForTesting(clip_child
.get(),
5744 gfx::PointF(-10.f
, -10.f
),
5749 host()->SetRootLayer(root
);
5751 ExecuteCalculateDrawProperties(root
.get());
5753 EXPECT_TRUE(root
->render_surface());
5754 EXPECT_TRUE(render_surface1
->render_surface());
5755 EXPECT_TRUE(render_surface2
->render_surface());
5757 // Since the render surfaces could have expanded, they should not clip (their
5758 // bounds would no longer be reliable). We should resort to layer clipping
5760 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5761 render_surface1
->render_surface()->clip_rect().ToString());
5762 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
5763 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5764 render_surface2
->render_surface()->clip_rect().ToString());
5765 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
5767 // NB: clip rects are in target space.
5768 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5769 render_surface1
->clip_rect().ToString());
5770 EXPECT_TRUE(render_surface1
->is_clipped());
5772 // This value is inherited from the clipping ancestor layer, 'intervening'.
5773 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
5774 render_surface2
->clip_rect().ToString());
5775 EXPECT_TRUE(render_surface2
->is_clipped());
5777 // The content rects of both render surfaces should both have expanded to
5778 // contain the clip child.
5779 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5780 render_surface1
->render_surface()->content_rect().ToString());
5781 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
5782 render_surface2
->render_surface()->content_rect().ToString());
5784 // The clip child should have inherited the clip parent's clip (projected to
5785 // the right space, of course), and should have the correctly sized visible
5787 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
5788 clip_child
->clip_rect().ToString());
5789 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
5790 clip_child
->visible_layer_rect().ToString());
5791 EXPECT_TRUE(clip_child
->is_clipped());
5794 TEST_F(LayerTreeHostCommonTest
, DescendantsOfClipChildren
) {
5795 // Ensures that descendants of the clip child inherit the correct clip.
5797 // root (a render surface)
5798 // + clip_parent (masks to bounds)
5799 // + intervening (masks to bounds)
5803 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5804 scoped_refptr
<Layer
> clip_parent
= Layer::Create(layer_settings());
5805 scoped_refptr
<Layer
> intervening
= Layer::Create(layer_settings());
5806 scoped_refptr
<Layer
> clip_child
= Layer::Create(layer_settings());
5807 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
5808 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5810 root
->AddChild(clip_parent
);
5811 clip_parent
->AddChild(intervening
);
5812 intervening
->AddChild(clip_child
);
5813 clip_child
->AddChild(child
);
5815 clip_child
->SetClipParent(clip_parent
.get());
5817 intervening
->SetMasksToBounds(true);
5818 clip_parent
->SetMasksToBounds(true);
5820 gfx::Transform identity_transform
;
5821 SetLayerPropertiesForTesting(root
.get(),
5828 SetLayerPropertiesForTesting(clip_parent
.get(),
5835 SetLayerPropertiesForTesting(intervening
.get(),
5842 SetLayerPropertiesForTesting(clip_child
.get(),
5849 SetLayerPropertiesForTesting(child
.get(),
5857 host()->SetRootLayer(root
);
5859 ExecuteCalculateDrawProperties(root
.get());
5861 EXPECT_TRUE(root
->render_surface());
5863 // Neither the clip child nor its descendant should have inherited the clip
5864 // from |intervening|.
5865 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5866 clip_child
->clip_rect().ToString());
5867 EXPECT_TRUE(clip_child
->is_clipped());
5868 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5869 child
->visible_layer_rect().ToString());
5870 EXPECT_TRUE(child
->is_clipped());
5873 TEST_F(LayerTreeHostCommonTest
,
5874 SurfacesShouldBeUnaffectedByNonDescendantClipChildren
) {
5875 // Ensures that non-descendant clip children in the tree do not affect
5878 // root (a render surface)
5879 // + clip_parent (masks to bounds)
5880 // + render_surface1
5882 // + render_surface2
5885 // In this example render_surface2 should be unaffected by clip_child.
5886 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5887 scoped_refptr
<Layer
> clip_parent
= Layer::Create(layer_settings());
5888 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
5889 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
5890 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5891 scoped_refptr
<Layer
> render_surface2
= Layer::Create(layer_settings());
5892 scoped_refptr
<LayerWithForcedDrawsContent
> non_clip_child
=
5893 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5895 root
->AddChild(clip_parent
);
5896 clip_parent
->AddChild(render_surface1
);
5897 render_surface1
->AddChild(clip_child
);
5898 clip_parent
->AddChild(render_surface2
);
5899 render_surface2
->AddChild(non_clip_child
);
5901 clip_child
->SetClipParent(clip_parent
.get());
5903 clip_parent
->SetMasksToBounds(true);
5904 render_surface1
->SetMasksToBounds(true);
5906 gfx::Transform identity_transform
;
5907 SetLayerPropertiesForTesting(root
.get(),
5914 SetLayerPropertiesForTesting(clip_parent
.get(),
5921 SetLayerPropertiesForTesting(render_surface1
.get(),
5928 SetLayerPropertiesForTesting(render_surface2
.get(),
5935 SetLayerPropertiesForTesting(clip_child
.get(),
5942 SetLayerPropertiesForTesting(non_clip_child
.get(),
5950 render_surface1
->SetForceRenderSurface(true);
5951 render_surface2
->SetForceRenderSurface(true);
5953 host()->SetRootLayer(root
);
5955 ExecuteCalculateDrawProperties(root
.get());
5957 EXPECT_TRUE(root
->render_surface());
5958 EXPECT_TRUE(render_surface1
->render_surface());
5959 EXPECT_TRUE(render_surface2
->render_surface());
5961 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5962 render_surface1
->clip_rect().ToString());
5963 EXPECT_TRUE(render_surface1
->is_clipped());
5965 // The render surface should not clip (it has unclipped descendants), instead
5966 // it should rely on layer clipping.
5967 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5968 render_surface1
->render_surface()->clip_rect().ToString());
5969 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
5971 // That said, it should have grown to accomodate the unclipped descendant.
5972 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
5973 render_surface1
->render_surface()->content_rect().ToString());
5975 // This render surface should clip. It has no unclipped descendants.
5976 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5977 render_surface2
->clip_rect().ToString());
5978 EXPECT_TRUE(render_surface2
->render_surface()->is_clipped());
5980 // It also shouldn't have grown to accomodate the clip child.
5981 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5982 render_surface2
->render_surface()->content_rect().ToString());
5984 // Sanity check our num_unclipped_descendants values.
5985 EXPECT_EQ(1u, render_surface1
->num_unclipped_descendants());
5986 EXPECT_EQ(0u, render_surface2
->num_unclipped_descendants());
5989 TEST_F(LayerTreeHostCommonTest
, CanRenderToSeparateSurface
) {
5990 FakeImplProxy proxy
;
5991 TestSharedBitmapManager shared_bitmap_manager
;
5992 TestTaskGraphRunner task_graph_runner
;
5993 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5994 &task_graph_runner
);
5995 scoped_ptr
<LayerImpl
> root
=
5996 LayerImpl::Create(host_impl
.active_tree(), 12345);
5997 scoped_ptr
<LayerImpl
> child1
=
5998 LayerImpl::Create(host_impl
.active_tree(), 123456);
5999 scoped_ptr
<LayerImpl
> child2
=
6000 LayerImpl::Create(host_impl
.active_tree(), 1234567);
6001 scoped_ptr
<LayerImpl
> child3
=
6002 LayerImpl::Create(host_impl
.active_tree(), 12345678);
6004 gfx::Transform identity_matrix
;
6005 gfx::Point3F transform_origin
;
6006 gfx::PointF position
;
6007 gfx::Size
bounds(100, 100);
6008 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
6009 position
, bounds
, true, false, true);
6010 root
->SetDrawsContent(true);
6012 // This layer structure normally forces render surface due to preserves3d
6014 SetLayerPropertiesForTesting(child1
.get(), identity_matrix
, transform_origin
,
6015 position
, bounds
, false, true, true);
6016 child1
->SetDrawsContent(true);
6017 SetLayerPropertiesForTesting(child2
.get(), identity_matrix
, transform_origin
,
6018 position
, bounds
, true, false, false);
6019 child2
->SetDrawsContent(true);
6020 SetLayerPropertiesForTesting(child3
.get(), identity_matrix
, transform_origin
,
6021 position
, bounds
, true, false, false);
6022 child3
->SetDrawsContent(true);
6024 child2
->Set3dSortingContextId(1);
6025 child3
->Set3dSortingContextId(1);
6027 child2
->AddChild(child3
.Pass());
6028 child1
->AddChild(child2
.Pass());
6029 root
->AddChild(child1
.Pass());
6032 LayerImplList render_surface_layer_list
;
6033 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root
.get());
6034 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6035 root
.get(), root
->bounds(), &render_surface_layer_list
);
6036 inputs
.can_render_to_separate_surface
= true;
6037 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6039 EXPECT_EQ(2u, render_surface_layer_list
.size());
6041 int count_represents_target_render_surface
= 0;
6042 int count_represents_contributing_render_surface
= 0;
6043 int count_represents_itself
= 0;
6044 LayerIterator end
= LayerIterator::End(&render_surface_layer_list
);
6045 for (LayerIterator it
= LayerIterator::Begin(&render_surface_layer_list
);
6047 if (it
.represents_target_render_surface())
6048 count_represents_target_render_surface
++;
6049 if (it
.represents_contributing_render_surface())
6050 count_represents_contributing_render_surface
++;
6051 if (it
.represents_itself())
6052 count_represents_itself
++;
6055 // Two render surfaces.
6056 EXPECT_EQ(2, count_represents_target_render_surface
);
6057 // Second render surface contributes to root render surface.
6058 EXPECT_EQ(1, count_represents_contributing_render_surface
);
6059 // All 4 layers represent itself.
6060 EXPECT_EQ(4, count_represents_itself
);
6064 LayerImplList render_surface_layer_list
;
6065 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6066 root
.get(), root
->bounds(), &render_surface_layer_list
);
6067 inputs
.can_render_to_separate_surface
= false;
6068 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6070 EXPECT_EQ(1u, render_surface_layer_list
.size());
6072 int count_represents_target_render_surface
= 0;
6073 int count_represents_contributing_render_surface
= 0;
6074 int count_represents_itself
= 0;
6075 LayerIterator end
= LayerIterator::End(&render_surface_layer_list
);
6076 for (LayerIterator it
= LayerIterator::Begin(&render_surface_layer_list
);
6078 if (it
.represents_target_render_surface())
6079 count_represents_target_render_surface
++;
6080 if (it
.represents_contributing_render_surface())
6081 count_represents_contributing_render_surface
++;
6082 if (it
.represents_itself())
6083 count_represents_itself
++;
6086 // Only root layer has a render surface.
6087 EXPECT_EQ(1, count_represents_target_render_surface
);
6088 // No layer contributes a render surface to root render surface.
6089 EXPECT_EQ(0, count_represents_contributing_render_surface
);
6090 // All 4 layers represent itself.
6091 EXPECT_EQ(4, count_represents_itself
);
6095 TEST_F(LayerTreeHostCommonTest
, DoNotIncludeBackfaceInvisibleSurfaces
) {
6096 LayerImpl
* root
= root_layer();
6097 LayerImpl
* render_surface
= AddChild
<LayerImpl
>(root
);
6098 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface
);
6099 child
->SetDrawsContent(true);
6101 gfx::Transform identity_transform
;
6102 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
6103 gfx::PointF(), gfx::Size(50, 50), true, false,
6105 SetLayerPropertiesForTesting(render_surface
, identity_transform
,
6106 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6108 SetLayerPropertiesForTesting(child
, identity_transform
, gfx::Point3F(),
6109 gfx::PointF(), gfx::Size(20, 20), true, false,
6112 root
->SetShouldFlattenTransform(false);
6113 root
->Set3dSortingContextId(1);
6114 render_surface
->SetDoubleSided(false);
6116 ExecuteCalculateDrawProperties(root
);
6118 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
6119 EXPECT_EQ(1u, render_surface_layer_list_impl()
6124 EXPECT_EQ(1u, render_surface_layer_list_impl()
6130 gfx::Transform rotation_transform
= identity_transform
;
6131 rotation_transform
.RotateAboutXAxis(180.0);
6133 render_surface
->SetTransform(rotation_transform
);
6135 ExecuteCalculateDrawProperties(root
);
6137 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6138 EXPECT_EQ(0u, render_surface_layer_list_impl()
6145 TEST_F(LayerTreeHostCommonTest
, ClippedByScrollParent
) {
6146 // Checks that the simple case (being clipped by a scroll parent that would
6147 // have been processed before you anyhow) results in the right clips.
6150 // + scroll_parent_border
6151 // | + scroll_parent_clip
6152 // | + scroll_parent
6155 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6156 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create(layer_settings());
6157 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create(layer_settings());
6158 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
6159 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6160 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
6161 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6163 root
->AddChild(scroll_child
);
6165 root
->AddChild(scroll_parent_border
);
6166 scroll_parent_border
->AddChild(scroll_parent_clip
);
6167 scroll_parent_clip
->AddChild(scroll_parent
);
6169 scroll_parent_clip
->SetMasksToBounds(true);
6171 scroll_child
->SetScrollParent(scroll_parent
.get());
6173 gfx::Transform identity_transform
;
6174 SetLayerPropertiesForTesting(root
.get(),
6181 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
6188 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
6195 SetLayerPropertiesForTesting(scroll_parent
.get(),
6202 SetLayerPropertiesForTesting(scroll_child
.get(),
6210 host()->SetRootLayer(root
);
6212 ExecuteCalculateDrawProperties(root
.get());
6214 EXPECT_TRUE(root
->render_surface());
6216 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
6217 scroll_child
->clip_rect().ToString());
6218 EXPECT_TRUE(scroll_child
->is_clipped());
6221 TEST_F(LayerTreeHostCommonTest
, SingularTransformSubtreesDoNotDraw
) {
6222 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
6223 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6224 scoped_refptr
<LayerWithForcedDrawsContent
> parent
=
6225 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6226 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
6227 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6229 root
->AddChild(parent
);
6230 parent
->AddChild(child
);
6232 gfx::Transform identity_transform
;
6233 SetLayerPropertiesForTesting(root
.get(),
6240 root
->SetForceRenderSurface(true);
6241 SetLayerPropertiesForTesting(parent
.get(),
6248 parent
->SetForceRenderSurface(true);
6249 SetLayerPropertiesForTesting(child
.get(),
6256 child
->SetForceRenderSurface(true);
6258 host()->SetRootLayer(root
);
6260 ExecuteCalculateDrawProperties(root
.get());
6262 EXPECT_EQ(3u, render_surface_layer_list()->size());
6264 gfx::Transform singular_transform
;
6265 singular_transform
.Scale3d(
6266 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
6268 child
->SetTransform(singular_transform
);
6270 ExecuteCalculateDrawProperties(root
.get());
6272 EXPECT_EQ(2u, render_surface_layer_list()->size());
6274 // Ensure that the entire subtree under a layer with singular transform does
6275 // not get rendered.
6276 parent
->SetTransform(singular_transform
);
6277 child
->SetTransform(identity_transform
);
6279 ExecuteCalculateDrawProperties(root
.get());
6281 EXPECT_EQ(1u, render_surface_layer_list()->size());
6284 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollParent
) {
6285 // Checks that clipping by a scroll parent that follows you in paint order
6286 // still results in correct clipping.
6289 // + scroll_parent_border
6290 // + scroll_parent_clip
6294 LayerImpl
* root
= root_layer();
6295 LayerImpl
* scroll_parent_border
= AddChild
<LayerImpl
>(root
);
6296 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
6297 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
6298 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
6300 scroll_parent
->SetDrawsContent(true);
6301 scroll_child
->SetDrawsContent(true);
6303 scroll_parent_clip
->SetMasksToBounds(true);
6305 scroll_child
->SetScrollParent(scroll_parent
);
6306 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
6307 scroll_children
->insert(scroll_child
);
6308 scroll_parent
->SetScrollChildren(scroll_children
.release());
6310 gfx::Transform identity_transform
;
6311 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
6312 gfx::PointF(), gfx::Size(50, 50), true, false,
6314 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
6315 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6316 true, false, false);
6317 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
6318 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6319 true, false, false);
6320 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
6321 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6322 true, false, false);
6323 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
6324 gfx::PointF(), gfx::Size(50, 50), true, false,
6327 ExecuteCalculateDrawProperties(root
);
6329 EXPECT_TRUE(root
->render_surface());
6331 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
6332 scroll_child
->clip_rect().ToString());
6333 EXPECT_TRUE(scroll_child
->is_clipped());
6336 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollGrandparent
) {
6337 // Checks that clipping by a scroll parent and scroll grandparent that follow
6338 // you in paint order still results in correct clipping.
6342 // + scroll_parent_border
6343 // | + scroll_parent_clip
6344 // | + scroll_parent
6345 // + scroll_grandparent_border
6346 // + scroll_grandparent_clip
6347 // + scroll_grandparent
6349 LayerImpl
* root
= root_layer();
6350 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
6351 LayerImpl
* scroll_parent_border
= AddChild
<LayerImpl
>(root
);
6352 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
6353 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
6354 LayerImpl
* scroll_grandparent_border
= AddChild
<LayerImpl
>(root
);
6355 LayerImpl
* scroll_grandparent_clip
=
6356 AddChild
<LayerImpl
>(scroll_grandparent_border
);
6357 LayerImpl
* scroll_grandparent
= AddChild
<LayerImpl
>(scroll_grandparent_clip
);
6359 scroll_parent
->SetDrawsContent(true);
6360 scroll_grandparent
->SetDrawsContent(true);
6361 scroll_child
->SetDrawsContent(true);
6363 scroll_parent_clip
->SetMasksToBounds(true);
6364 scroll_grandparent_clip
->SetMasksToBounds(true);
6366 scroll_child
->SetScrollParent(scroll_parent
);
6367 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
6368 scroll_children
->insert(scroll_child
);
6369 scroll_parent
->SetScrollChildren(scroll_children
.release());
6371 scroll_parent_border
->SetScrollParent(scroll_grandparent
);
6372 scroll_children
.reset(new std::set
<LayerImpl
*>);
6373 scroll_children
->insert(scroll_parent_border
);
6374 scroll_grandparent
->SetScrollChildren(scroll_children
.release());
6376 gfx::Transform identity_transform
;
6377 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
6378 gfx::PointF(), gfx::Size(50, 50), true, false,
6380 SetLayerPropertiesForTesting(scroll_grandparent_border
, identity_transform
,
6381 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6382 true, false, false);
6383 SetLayerPropertiesForTesting(scroll_grandparent_clip
, identity_transform
,
6384 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6385 true, false, false);
6386 SetLayerPropertiesForTesting(scroll_grandparent
, identity_transform
,
6387 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6388 true, false, false);
6389 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
6390 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6391 true, false, false);
6392 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
6393 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6394 true, false, false);
6395 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
6396 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6397 true, false, false);
6398 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
6399 gfx::PointF(), gfx::Size(50, 50), true, false,
6402 ExecuteCalculateDrawProperties(root
);
6404 EXPECT_TRUE(root
->render_surface());
6406 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
6407 scroll_child
->clip_rect().ToString());
6408 EXPECT_TRUE(scroll_child
->is_clipped());
6410 // Despite the fact that we visited the above layers out of order to get the
6411 // correct clip, the layer lists should be unaffected.
6412 EXPECT_EQ(3u, root
->render_surface()->layer_list().size());
6413 EXPECT_EQ(scroll_child
, root
->render_surface()->layer_list().at(0));
6414 EXPECT_EQ(scroll_parent
, root
->render_surface()->layer_list().at(1));
6415 EXPECT_EQ(scroll_grandparent
, root
->render_surface()->layer_list().at(2));
6418 TEST_F(LayerTreeHostCommonTest
, OutOfOrderClippingRequiresRSLLSorting
) {
6419 // Ensures that even if we visit layers out of order, we still produce a
6420 // correctly ordered render surface layer list.
6423 // + scroll_parent_border
6424 // + scroll_parent_clip
6426 // + render_surface2
6427 // + scroll_grandparent_border
6428 // + scroll_grandparent_clip
6429 // + scroll_grandparent
6430 // + render_surface1
6432 LayerImpl
* root
= root_layer();
6433 root
->SetDrawsContent(true);
6435 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
6436 scroll_child
->SetDrawsContent(true);
6438 LayerImpl
* scroll_parent_border
= AddChild
<LayerImpl
>(root
);
6439 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
6440 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
6441 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(scroll_parent
);
6442 LayerImpl
* scroll_grandparent_border
= AddChild
<LayerImpl
>(root
);
6443 LayerImpl
* scroll_grandparent_clip
=
6444 AddChild
<LayerImpl
>(scroll_grandparent_border
);
6445 LayerImpl
* scroll_grandparent
= AddChild
<LayerImpl
>(scroll_grandparent_clip
);
6446 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(scroll_grandparent
);
6448 scroll_parent
->SetDrawsContent(true);
6449 render_surface1
->SetDrawsContent(true);
6450 scroll_grandparent
->SetDrawsContent(true);
6451 render_surface2
->SetDrawsContent(true);
6453 scroll_parent_clip
->SetMasksToBounds(true);
6454 scroll_grandparent_clip
->SetMasksToBounds(true);
6456 scroll_child
->SetScrollParent(scroll_parent
);
6457 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
6458 scroll_children
->insert(scroll_child
);
6459 scroll_parent
->SetScrollChildren(scroll_children
.release());
6461 scroll_parent_border
->SetScrollParent(scroll_grandparent
);
6462 scroll_children
.reset(new std::set
<LayerImpl
*>);
6463 scroll_children
->insert(scroll_parent_border
);
6464 scroll_grandparent
->SetScrollChildren(scroll_children
.release());
6466 gfx::Transform identity_transform
;
6467 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
6468 gfx::PointF(), gfx::Size(50, 50), true, false,
6470 SetLayerPropertiesForTesting(scroll_grandparent_border
, identity_transform
,
6471 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6472 true, false, false);
6473 SetLayerPropertiesForTesting(scroll_grandparent_clip
, identity_transform
,
6474 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6475 true, false, false);
6476 SetLayerPropertiesForTesting(scroll_grandparent
, identity_transform
,
6477 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6478 true, false, false);
6479 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
6480 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6482 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
6483 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6484 true, false, false);
6485 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
6486 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6487 true, false, false);
6488 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
6489 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6490 true, false, false);
6491 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
6492 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6494 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
6495 gfx::PointF(), gfx::Size(50, 50), true, false,
6498 ExecuteCalculateDrawProperties(root
);
6500 EXPECT_TRUE(root
->render_surface());
6502 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
6503 scroll_child
->clip_rect().ToString());
6504 EXPECT_TRUE(scroll_child
->is_clipped());
6506 // Despite the fact that we had to process the layers out of order to get the
6507 // right clip, our render_surface_layer_list's order should be unaffected.
6508 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6509 EXPECT_EQ(root
, render_surface_layer_list_impl()->at(0));
6510 EXPECT_EQ(render_surface2
, render_surface_layer_list_impl()->at(1));
6511 EXPECT_EQ(render_surface1
, render_surface_layer_list_impl()->at(2));
6512 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
6513 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
6514 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
6517 TEST_F(LayerTreeHostCommonTest
, FixedPositionWithInterveningRenderSurface
) {
6518 // Ensures that when we have a render surface between a fixed position layer
6519 // and its container, we compute the fixed position layer's draw transform
6520 // with respect to that intervening render surface, not with respect to its
6521 // container's render target.
6528 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6529 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface
=
6530 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6531 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
6532 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6533 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
6534 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6536 root
->AddChild(render_surface
);
6537 render_surface
->AddChild(fixed
);
6538 fixed
->AddChild(child
);
6540 root
->SetIsContainerForFixedPositionLayers(true);
6541 render_surface
->SetForceRenderSurface(true);
6543 LayerPositionConstraint constraint
;
6544 constraint
.set_is_fixed_position(true);
6545 fixed
->SetPositionConstraint(constraint
);
6547 SetLayerPropertiesForTesting(root
.get(), gfx::Transform(), gfx::Point3F(),
6548 gfx::PointF(), gfx::Size(50, 50), true, false);
6549 SetLayerPropertiesForTesting(render_surface
.get(), gfx::Transform(),
6550 gfx::Point3F(), gfx::PointF(7.f
, 9.f
),
6551 gfx::Size(50, 50), true, false);
6552 SetLayerPropertiesForTesting(fixed
.get(), gfx::Transform(), gfx::Point3F(),
6553 gfx::PointF(10.f
, 15.f
), gfx::Size(50, 50), true,
6555 SetLayerPropertiesForTesting(child
.get(), gfx::Transform(), gfx::Point3F(),
6556 gfx::PointF(1.f
, 2.f
), gfx::Size(50, 50), true,
6559 host()->SetRootLayer(root
);
6561 ExecuteCalculateDrawProperties(root
.get());
6563 gfx::Transform expected_fixed_draw_transform
;
6564 expected_fixed_draw_transform
.Translate(10.f
, 15.f
);
6565 EXPECT_EQ(expected_fixed_draw_transform
, fixed
->draw_transform());
6567 gfx::Transform expected_fixed_screen_space_transform
;
6568 expected_fixed_screen_space_transform
.Translate(17.f
, 24.f
);
6569 EXPECT_EQ(expected_fixed_screen_space_transform
,
6570 fixed
->screen_space_transform());
6572 gfx::Transform expected_child_draw_transform
;
6573 expected_child_draw_transform
.Translate(11.f
, 17.f
);
6574 EXPECT_EQ(expected_child_draw_transform
, child
->draw_transform());
6576 gfx::Transform expected_child_screen_space_transform
;
6577 expected_child_screen_space_transform
.Translate(18.f
, 26.f
);
6578 EXPECT_EQ(expected_child_screen_space_transform
,
6579 child
->screen_space_transform());
6582 TEST_F(LayerTreeHostCommonTest
, ScrollCompensationWithRounding
) {
6583 // This test verifies that a scrolling layer that gets snapped to
6584 // integer coordinates doesn't move a fixed position child.
6591 FakeImplProxy proxy
;
6592 TestSharedBitmapManager shared_bitmap_manager
;
6593 TestTaskGraphRunner task_graph_runner
;
6594 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
6595 &task_graph_runner
);
6596 host_impl
.CreatePendingTree();
6597 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
6598 scoped_ptr
<LayerImpl
> container
=
6599 LayerImpl::Create(host_impl
.active_tree(), 2);
6600 LayerImpl
* container_layer
= container
.get();
6601 scoped_ptr
<LayerImpl
> scroller
=
6602 LayerImpl::Create(host_impl
.active_tree(), 3);
6603 LayerImpl
* scroll_layer
= scroller
.get();
6604 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
6605 LayerImpl
* fixed_layer
= fixed
.get();
6607 container
->SetIsContainerForFixedPositionLayers(true);
6609 LayerPositionConstraint constraint
;
6610 constraint
.set_is_fixed_position(true);
6611 fixed
->SetPositionConstraint(constraint
);
6613 scroller
->SetScrollClipLayer(container
->id());
6615 gfx::Transform identity_transform
;
6616 gfx::Transform container_transform
;
6617 container_transform
.Translate3d(10.0, 20.0, 0.0);
6618 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
6620 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
6621 gfx::PointF(), gfx::Size(50, 50), true, false,
6623 SetLayerPropertiesForTesting(container
.get(), container_transform
,
6624 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6625 true, false, false);
6626 SetLayerPropertiesForTesting(scroller
.get(), identity_transform
,
6627 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6628 true, false, false);
6629 SetLayerPropertiesForTesting(fixed
.get(), identity_transform
, gfx::Point3F(),
6630 gfx::PointF(), gfx::Size(50, 50), true, false,
6633 scroller
->AddChild(fixed
.Pass());
6634 container
->AddChild(scroller
.Pass());
6635 root
->AddChild(container
.Pass());
6637 // Rounded to integers already.
6639 gfx::Vector2dF
scroll_delta(3.0, 5.0);
6640 scroll_layer
->SetScrollDelta(scroll_delta
);
6642 LayerImplList render_surface_layer_list
;
6643 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6644 root
.get(), root
->bounds(), &render_surface_layer_list
);
6645 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6647 EXPECT_TRANSFORMATION_MATRIX_EQ(
6648 container_layer
->draw_properties().screen_space_transform
,
6649 fixed_layer
->draw_properties().screen_space_transform
);
6651 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
6653 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
6654 .screen_space_transform
.To2dTranslation(),
6655 container_offset
- scroll_delta
);
6658 // Scroll delta requiring rounding.
6660 gfx::Vector2dF
scroll_delta(4.1f
, 8.1f
);
6661 scroll_layer
->SetScrollDelta(scroll_delta
);
6663 gfx::Vector2dF
rounded_scroll_delta(4.f
, 8.f
);
6665 LayerImplList render_surface_layer_list
;
6666 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6667 root
.get(), root
->bounds(), &render_surface_layer_list
);
6668 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6670 EXPECT_TRANSFORMATION_MATRIX_EQ(
6671 container_layer
->draw_properties().screen_space_transform
,
6672 fixed_layer
->draw_properties().screen_space_transform
);
6674 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
6676 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
6677 .screen_space_transform
.To2dTranslation(),
6678 container_offset
- rounded_scroll_delta
);
6681 // Scale is applied earlier in the tree.
6683 gfx::Transform scaled_container_transform
= container_transform
;
6684 scaled_container_transform
.Scale3d(3.0, 3.0, 1.0);
6685 container_layer
->SetTransform(scaled_container_transform
);
6687 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
6688 scroll_layer
->SetScrollDelta(scroll_delta
);
6690 LayerImplList render_surface_layer_list
;
6691 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6692 root
.get(), root
->bounds(), &render_surface_layer_list
);
6693 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6695 EXPECT_TRANSFORMATION_MATRIX_EQ(
6696 container_layer
->draw_properties().screen_space_transform
,
6697 fixed_layer
->draw_properties().screen_space_transform
);
6699 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
6702 container_layer
->SetTransform(container_transform
);
6705 // Scale is applied on the scroll layer itself.
6707 gfx::Transform scale_transform
;
6708 scale_transform
.Scale3d(3.0, 3.0, 1.0);
6709 scroll_layer
->SetTransform(scale_transform
);
6711 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
6712 scroll_layer
->SetScrollDelta(scroll_delta
);
6714 LayerImplList render_surface_layer_list
;
6715 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6716 root
.get(), root
->bounds(), &render_surface_layer_list
);
6717 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6720 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
6723 scroll_layer
->SetTransform(identity_transform
);
6727 TEST_F(LayerTreeHostCommonTest
,
6728 ScrollCompensationMainScrollOffsetFractionalPart
) {
6729 // This test verifies that a scrolling layer that has fractional scroll offset
6730 // from main doesn't move a fixed position child.
6737 FakeImplProxy proxy
;
6738 TestSharedBitmapManager shared_bitmap_manager
;
6739 TestTaskGraphRunner task_graph_runner
;
6740 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
6741 &task_graph_runner
);
6742 host_impl
.CreatePendingTree();
6743 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
6744 scoped_ptr
<LayerImpl
> container
=
6745 LayerImpl::Create(host_impl
.active_tree(), 2);
6746 LayerImpl
* container_layer
= container
.get();
6747 scoped_ptr
<LayerImpl
> scroller
=
6748 LayerImpl::Create(host_impl
.active_tree(), 3);
6749 LayerImpl
* scroll_layer
= scroller
.get();
6750 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
6751 LayerImpl
* fixed_layer
= fixed
.get();
6753 container
->SetIsContainerForFixedPositionLayers(true);
6755 LayerPositionConstraint constraint
;
6756 constraint
.set_is_fixed_position(true);
6757 fixed
->SetPositionConstraint(constraint
);
6759 scroller
->SetScrollClipLayer(container
->id());
6761 gfx::Transform identity_transform
;
6762 gfx::Transform container_transform
;
6763 container_transform
.Translate3d(10.0, 20.0, 0.0);
6764 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
6766 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
6767 gfx::PointF(), gfx::Size(50, 50), true, false,
6769 SetLayerPropertiesForTesting(container
.get(), container_transform
,
6770 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6771 true, false, false);
6772 SetLayerPropertiesForTesting(scroller
.get(), identity_transform
,
6773 gfx::Point3F(), gfx::PointF(0.0, 0.0),
6774 gfx::Size(30, 30), true, false, false);
6776 gfx::ScrollOffset
scroll_offset(3.3, 4.2);
6777 gfx::Vector2dF
main_scroll_fractional_part(0.3f
, 0.2f
);
6778 gfx::Vector2dF
scroll_delta(0.1f
, 0.4f
);
6779 // Blink only uses the integer part of the scroll_offset for fixed
6781 SetLayerPropertiesForTesting(fixed
.get(), identity_transform
, gfx::Point3F(),
6782 gfx::PointF(3.0f
, 4.0f
), gfx::Size(50, 50), true,
6784 scroll_layer
->PushScrollOffsetFromMainThread(scroll_offset
);
6785 scroll_layer
->SetScrollDelta(scroll_delta
);
6786 scroll_layer
->SetScrollCompensationAdjustment(main_scroll_fractional_part
);
6788 scroller
->AddChild(fixed
.Pass());
6789 container
->AddChild(scroller
.Pass());
6790 root
->AddChild(container
.Pass());
6792 LayerImplList render_surface_layer_list
;
6793 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6794 root
.get(), root
->bounds(), &render_surface_layer_list
);
6795 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6797 EXPECT_TRANSFORMATION_MATRIX_EQ(
6798 container_layer
->draw_properties().screen_space_transform
,
6799 fixed_layer
->draw_properties().screen_space_transform
);
6801 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
6804 gfx::ScrollOffset effective_scroll_offset
=
6805 ScrollOffsetWithDelta(scroll_offset
, scroll_delta
);
6806 gfx::Vector2d rounded_effective_scroll_offset
=
6807 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset
));
6809 scroll_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
6810 container_offset
- rounded_effective_scroll_offset
);
6813 class AnimationScaleFactorTrackingLayerImpl
: public LayerImpl
{
6815 static scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> Create(
6816 LayerTreeImpl
* tree_impl
,
6818 return make_scoped_ptr(
6819 new AnimationScaleFactorTrackingLayerImpl(tree_impl
, id
));
6822 ~AnimationScaleFactorTrackingLayerImpl() override
{}
6825 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl
* tree_impl
,
6827 : LayerImpl(tree_impl
, id
) {
6828 SetDrawsContent(true);
6832 TEST_F(LayerTreeHostCommonTest
, MaximumAnimationScaleFactor
) {
6833 FakeImplProxy proxy
;
6834 TestSharedBitmapManager shared_bitmap_manager
;
6835 TestTaskGraphRunner task_graph_runner
;
6836 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
6837 &task_graph_runner
);
6838 gfx::Transform identity_matrix
;
6839 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_parent
=
6840 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 1);
6841 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> parent
=
6842 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 2);
6843 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> child
=
6844 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 3);
6845 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_child
=
6846 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 4);
6848 AnimationScaleFactorTrackingLayerImpl
* parent_raw
= parent
.get();
6849 AnimationScaleFactorTrackingLayerImpl
* child_raw
= child
.get();
6850 AnimationScaleFactorTrackingLayerImpl
* grand_child_raw
= grand_child
.get();
6852 child
->AddChild(grand_child
.Pass());
6853 parent
->AddChild(child
.Pass());
6854 grand_parent
->AddChild(parent
.Pass());
6856 SetLayerPropertiesForTesting(grand_parent
.get(), identity_matrix
,
6857 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6859 SetLayerPropertiesForTesting(parent_raw
, identity_matrix
, gfx::Point3F(),
6860 gfx::PointF(), gfx::Size(1, 2), true, false,
6862 SetLayerPropertiesForTesting(child_raw
, identity_matrix
, gfx::Point3F(),
6863 gfx::PointF(), gfx::Size(1, 2), true, false,
6866 SetLayerPropertiesForTesting(grand_child_raw
, identity_matrix
, gfx::Point3F(),
6867 gfx::PointF(), gfx::Size(1, 2), true, false,
6870 ExecuteCalculateDrawProperties(grand_parent
.get());
6872 // No layers have animations.
6874 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6876 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6877 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6879 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6881 TransformOperations translation
;
6882 translation
.AppendTranslate(1.f
, 2.f
, 3.f
);
6884 AddAnimatedTransformToLayer(
6885 parent_raw
, 1.0, TransformOperations(), translation
);
6887 // No layers have scale-affecting animations.
6889 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6891 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6892 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6894 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6896 TransformOperations scale
;
6897 scale
.AppendScale(5.f
, 4.f
, 3.f
);
6899 AddAnimatedTransformToLayer(child_raw
, 1.0, TransformOperations(), scale
);
6900 ExecuteCalculateDrawProperties(grand_parent
.get());
6902 // Only |child| has a scale-affecting animation.
6904 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6906 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6907 EXPECT_EQ(5.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6909 5.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6911 AddAnimatedTransformToLayer(
6912 grand_parent
.get(), 1.0, TransformOperations(), scale
);
6913 ExecuteCalculateDrawProperties(grand_parent
.get());
6915 // |grand_parent| and |child| have scale-affecting animations.
6917 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6919 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6920 // We don't support combining animated scales from two nodes; 0.f means
6921 // that the maximum scale could not be computed.
6922 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6924 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6926 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
6927 ExecuteCalculateDrawProperties(grand_parent
.get());
6929 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
6931 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6933 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6934 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6936 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6938 grand_parent
->layer_animation_controller()->AbortAnimations(
6939 Animation::TRANSFORM
);
6940 parent_raw
->layer_animation_controller()->AbortAnimations(
6941 Animation::TRANSFORM
);
6942 child_raw
->layer_animation_controller()->AbortAnimations(
6943 Animation::TRANSFORM
);
6945 TransformOperations perspective
;
6946 perspective
.AppendPerspective(10.f
);
6948 AddAnimatedTransformToLayer(
6949 child_raw
, 1.0, TransformOperations(), perspective
);
6950 ExecuteCalculateDrawProperties(grand_parent
.get());
6952 // |child| has a scale-affecting animation but computing the maximum of this
6953 // animation is not supported.
6955 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6957 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6958 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6960 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6962 child_raw
->layer_animation_controller()->AbortAnimations(
6963 Animation::TRANSFORM
);
6965 gfx::Transform scale_matrix
;
6966 scale_matrix
.Scale(1.f
, 2.f
);
6967 grand_parent
->SetTransform(scale_matrix
);
6968 parent_raw
->SetTransform(scale_matrix
);
6969 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6970 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
6971 ExecuteCalculateDrawProperties(grand_parent
.get());
6973 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
6974 // animation with maximum scale 5.f.
6976 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6978 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6980 child_raw
->draw_properties().maximum_animation_contents_scale
);
6983 grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6985 gfx::Transform perspective_matrix
;
6986 perspective_matrix
.ApplyPerspectiveDepth(2.f
);
6987 child_raw
->SetTransform(perspective_matrix
);
6988 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6989 ExecuteCalculateDrawProperties(grand_parent
.get());
6991 // |child| has a transform that's neither a translation nor a scale.
6993 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6995 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6996 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6998 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7000 parent_raw
->SetTransform(perspective_matrix
);
7001 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
7002 ExecuteCalculateDrawProperties(grand_parent
.get());
7004 // |parent| and |child| have transforms that are neither translations nor
7007 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7009 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7010 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7012 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7014 parent_raw
->SetTransform(identity_matrix
);
7015 child_raw
->SetTransform(identity_matrix
);
7016 grand_parent
->SetTransform(perspective_matrix
);
7017 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
7019 ExecuteCalculateDrawProperties(grand_parent
.get());
7021 // |grand_parent| has a transform that's neither a translation nor a scale.
7023 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7025 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7026 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7028 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7031 static int membership_id(LayerImpl
* layer
) {
7032 return layer
->draw_properties().last_drawn_render_surface_layer_list_id
;
7035 static void GatherDrawnLayers(LayerImplList
* rsll
,
7036 std::set
<LayerImpl
*>* drawn_layers
) {
7037 for (LayerIterator it
= LayerIterator::Begin(rsll
),
7038 end
= LayerIterator::End(rsll
);
7040 LayerImpl
* layer
= *it
;
7041 if (it
.represents_itself())
7042 drawn_layers
->insert(layer
);
7044 if (!it
.represents_contributing_render_surface())
7047 if (layer
->mask_layer())
7048 drawn_layers
->insert(layer
->mask_layer());
7049 if (layer
->replica_layer() && layer
->replica_layer()->mask_layer())
7050 drawn_layers
->insert(layer
->replica_layer()->mask_layer());
7054 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceLayerListMembership
) {
7055 FakeImplProxy proxy
;
7056 TestSharedBitmapManager shared_bitmap_manager
;
7057 TestTaskGraphRunner task_graph_runner
;
7058 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
7059 &task_graph_runner
);
7060 gfx::Transform identity_matrix
;
7062 scoped_ptr
<LayerImpl
> grand_parent
=
7063 LayerImpl::Create(host_impl
.active_tree(), 1);
7064 scoped_ptr
<LayerImpl
> parent
= LayerImpl::Create(host_impl
.active_tree(), 3);
7065 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 5);
7066 scoped_ptr
<LayerImpl
> grand_child1
=
7067 LayerImpl::Create(host_impl
.active_tree(), 7);
7068 scoped_ptr
<LayerImpl
> grand_child2
=
7069 LayerImpl::Create(host_impl
.active_tree(), 9);
7071 LayerImpl
* grand_parent_raw
= grand_parent
.get();
7072 LayerImpl
* parent_raw
= parent
.get();
7073 LayerImpl
* child_raw
= child
.get();
7074 LayerImpl
* grand_child1_raw
= grand_child1
.get();
7075 LayerImpl
* grand_child2_raw
= grand_child2
.get();
7077 child
->AddChild(grand_child1
.Pass());
7078 child
->AddChild(grand_child2
.Pass());
7079 parent
->AddChild(child
.Pass());
7080 grand_parent
->AddChild(parent
.Pass());
7082 SetLayerPropertiesForTesting(grand_parent_raw
, identity_matrix
,
7083 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7085 SetLayerPropertiesForTesting(parent_raw
, identity_matrix
, gfx::Point3F(),
7086 gfx::PointF(), gfx::Size(1, 2), true, false,
7089 SetLayerPropertiesForTesting(child_raw
, identity_matrix
, gfx::Point3F(),
7090 gfx::PointF(), gfx::Size(1, 2), true, false,
7093 SetLayerPropertiesForTesting(grand_child1_raw
, identity_matrix
,
7094 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7095 true, false, false);
7097 SetLayerPropertiesForTesting(grand_child2_raw
, identity_matrix
,
7098 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7099 true, false, false);
7101 // Start with nothing being drawn.
7102 ExecuteCalculateDrawProperties(grand_parent_raw
);
7103 int member_id
= render_surface_layer_list_count();
7105 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
7106 EXPECT_NE(member_id
, membership_id(parent_raw
));
7107 EXPECT_NE(member_id
, membership_id(child_raw
));
7108 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
7109 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
7111 std::set
<LayerImpl
*> expected
;
7112 std::set
<LayerImpl
*> actual
;
7113 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
7114 EXPECT_EQ(expected
, actual
);
7116 // If we force render surface, but none of the layers are in the layer list,
7117 // then this layer should not appear in RSLL.
7118 grand_child1_raw
->SetHasRenderSurface(true);
7120 ExecuteCalculateDrawProperties(grand_parent_raw
);
7121 member_id
= render_surface_layer_list_count();
7123 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
7124 EXPECT_NE(member_id
, membership_id(parent_raw
));
7125 EXPECT_NE(member_id
, membership_id(child_raw
));
7126 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
7127 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
7131 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
7132 EXPECT_EQ(expected
, actual
);
7134 // However, if we say that this layer also draws content, it will appear in
7136 grand_child1_raw
->SetDrawsContent(true);
7138 ExecuteCalculateDrawProperties(grand_parent_raw
);
7139 member_id
= render_surface_layer_list_count();
7141 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
7142 EXPECT_NE(member_id
, membership_id(parent_raw
));
7143 EXPECT_NE(member_id
, membership_id(child_raw
));
7144 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
7145 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
7148 expected
.insert(grand_child1_raw
);
7151 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
7152 EXPECT_EQ(expected
, actual
);
7154 // Now child is forced to have a render surface, and one if its children draws
7156 grand_child1_raw
->SetDrawsContent(false);
7157 grand_child1_raw
->SetHasRenderSurface(false);
7158 child_raw
->SetHasRenderSurface(true);
7159 grand_child2_raw
->SetDrawsContent(true);
7161 ExecuteCalculateDrawProperties(grand_parent_raw
);
7162 member_id
= render_surface_layer_list_count();
7164 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
7165 EXPECT_NE(member_id
, membership_id(parent_raw
));
7166 EXPECT_NE(member_id
, membership_id(child_raw
));
7167 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
7168 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
7171 expected
.insert(grand_child2_raw
);
7174 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
7175 EXPECT_EQ(expected
, actual
);
7177 // Add a mask layer to child.
7178 child_raw
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6).Pass());
7180 ExecuteCalculateDrawProperties(grand_parent_raw
);
7181 member_id
= render_surface_layer_list_count();
7183 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
7184 EXPECT_NE(member_id
, membership_id(parent_raw
));
7185 EXPECT_NE(member_id
, membership_id(child_raw
));
7186 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
7187 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
7188 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
7191 expected
.insert(grand_child2_raw
);
7192 expected
.insert(child_raw
->mask_layer());
7195 expected
.insert(grand_child2_raw
);
7196 expected
.insert(child_raw
->mask_layer());
7199 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
7200 EXPECT_EQ(expected
, actual
);
7202 // Add replica mask layer.
7203 scoped_ptr
<LayerImpl
> replica_layer
=
7204 LayerImpl::Create(host_impl
.active_tree(), 20);
7205 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 21));
7206 child_raw
->SetReplicaLayer(replica_layer
.Pass());
7208 ExecuteCalculateDrawProperties(grand_parent_raw
);
7209 member_id
= render_surface_layer_list_count();
7211 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
7212 EXPECT_NE(member_id
, membership_id(parent_raw
));
7213 EXPECT_NE(member_id
, membership_id(child_raw
));
7214 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
7215 EXPECT_EQ(member_id
, membership_id(child_raw
->replica_layer()->mask_layer()));
7216 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
7217 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
7220 expected
.insert(grand_child2_raw
);
7221 expected
.insert(child_raw
->mask_layer());
7222 expected
.insert(child_raw
->replica_layer()->mask_layer());
7225 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
7226 EXPECT_EQ(expected
, actual
);
7228 child_raw
->TakeReplicaLayer();
7230 // With nothing drawing, we should have no layers.
7231 grand_child2_raw
->SetDrawsContent(false);
7233 ExecuteCalculateDrawProperties(grand_parent_raw
);
7234 member_id
= render_surface_layer_list_count();
7236 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
7237 EXPECT_NE(member_id
, membership_id(parent_raw
));
7238 EXPECT_NE(member_id
, membership_id(child_raw
));
7239 EXPECT_NE(member_id
, membership_id(child_raw
->mask_layer()));
7240 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
7241 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
7245 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
7246 EXPECT_EQ(expected
, actual
);
7248 // Child itself draws means that we should have the child and the mask in the
7250 child_raw
->SetDrawsContent(true);
7252 ExecuteCalculateDrawProperties(grand_parent_raw
);
7253 member_id
= render_surface_layer_list_count();
7255 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
7256 EXPECT_NE(member_id
, membership_id(parent_raw
));
7257 EXPECT_EQ(member_id
, membership_id(child_raw
));
7258 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
7259 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
7260 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
7263 expected
.insert(child_raw
);
7264 expected
.insert(child_raw
->mask_layer());
7266 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
7267 EXPECT_EQ(expected
, actual
);
7269 child_raw
->TakeMaskLayer();
7271 // Now everyone's a member!
7272 grand_parent_raw
->SetDrawsContent(true);
7273 parent_raw
->SetDrawsContent(true);
7274 child_raw
->SetDrawsContent(true);
7275 grand_child1_raw
->SetDrawsContent(true);
7276 grand_child2_raw
->SetDrawsContent(true);
7278 ExecuteCalculateDrawProperties(grand_parent_raw
);
7279 member_id
= render_surface_layer_list_count();
7281 EXPECT_EQ(member_id
, membership_id(grand_parent_raw
));
7282 EXPECT_EQ(member_id
, membership_id(parent_raw
));
7283 EXPECT_EQ(member_id
, membership_id(child_raw
));
7284 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
7285 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
7288 expected
.insert(grand_parent_raw
);
7289 expected
.insert(parent_raw
);
7290 expected
.insert(child_raw
);
7291 expected
.insert(grand_child1_raw
);
7292 expected
.insert(grand_child2_raw
);
7295 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
7296 EXPECT_EQ(expected
, actual
);
7299 TEST_F(LayerTreeHostCommonTest
, DrawPropertyScales
) {
7300 FakeImplProxy proxy
;
7301 TestSharedBitmapManager shared_bitmap_manager
;
7302 TestTaskGraphRunner task_graph_runner
;
7303 LayerTreeSettings settings
;
7304 settings
.layer_transforms_should_scale_layer_contents
= true;
7305 FakeLayerTreeHostImpl
host_impl(settings
, &proxy
, &shared_bitmap_manager
,
7306 &task_graph_runner
);
7308 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7309 LayerImpl
* root_layer
= root
.get();
7310 scoped_ptr
<LayerImpl
> child1
= LayerImpl::Create(host_impl
.active_tree(), 2);
7311 LayerImpl
* child1_layer
= child1
.get();
7312 scoped_ptr
<LayerImpl
> child2
= LayerImpl::Create(host_impl
.active_tree(), 3);
7313 LayerImpl
* child2_layer
= child2
.get();
7315 root
->AddChild(child1
.Pass());
7316 root
->AddChild(child2
.Pass());
7317 root
->SetHasRenderSurface(true);
7319 gfx::Transform identity_matrix
, scale_transform_child1
,
7320 scale_transform_child2
;
7321 scale_transform_child1
.Scale(2, 3);
7322 scale_transform_child2
.Scale(4, 5);
7324 SetLayerPropertiesForTesting(root_layer
, identity_matrix
, gfx::Point3F(),
7325 gfx::PointF(), gfx::Size(1, 1), true, false,
7327 SetLayerPropertiesForTesting(child1_layer
, scale_transform_child1
,
7328 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
7331 child1_layer
->SetMaskLayer(
7332 LayerImpl::Create(host_impl
.active_tree(), 4).Pass());
7334 scoped_ptr
<LayerImpl
> replica_layer
=
7335 LayerImpl::Create(host_impl
.active_tree(), 5);
7336 replica_layer
->SetHasRenderSurface(true);
7337 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6));
7338 child1_layer
->SetReplicaLayer(replica_layer
.Pass());
7339 child1_layer
->SetHasRenderSurface(true);
7341 ExecuteCalculateDrawProperties(root_layer
);
7343 TransformOperations scale
;
7344 scale
.AppendScale(5.f
, 8.f
, 3.f
);
7346 AddAnimatedTransformToLayer(child2_layer
, 1.0, TransformOperations(), scale
);
7347 SetLayerPropertiesForTesting(child2_layer
, scale_transform_child2
,
7348 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
7351 ExecuteCalculateDrawProperties(root_layer
);
7353 EXPECT_FLOAT_EQ(1.f
, root_layer
->GetIdealContentsScale());
7354 EXPECT_FLOAT_EQ(3.f
, child1_layer
->GetIdealContentsScale());
7355 EXPECT_FLOAT_EQ(3.f
, child1_layer
->mask_layer()->GetIdealContentsScale());
7356 EXPECT_FLOAT_EQ(5.f
, child2_layer
->GetIdealContentsScale());
7359 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
7361 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
7362 EXPECT_FLOAT_EQ(0.f
,
7363 child1_layer
->mask_layer()
7365 .maximum_animation_contents_scale
);
7366 EXPECT_FLOAT_EQ(0.f
,
7367 child1_layer
->replica_layer()
7370 .maximum_animation_contents_scale
);
7372 8.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
7374 // Changing page-scale would affect ideal_contents_scale and
7375 // maximum_animation_contents_scale.
7377 float page_scale_factor
= 3.f
;
7378 float device_scale_factor
= 1.0f
;
7379 std::vector
<LayerImpl
*> render_surface_layer_list
;
7380 gfx::Size device_viewport_size
=
7381 gfx::Size(root_layer
->bounds().width() * device_scale_factor
,
7382 root_layer
->bounds().height() * device_scale_factor
);
7383 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7384 root_layer
, device_viewport_size
, &render_surface_layer_list
);
7386 inputs
.page_scale_factor
= page_scale_factor
;
7387 inputs
.can_adjust_raster_scales
= true;
7388 inputs
.page_scale_layer
= root_layer
;
7389 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7391 EXPECT_FLOAT_EQ(3.f
, root_layer
->GetIdealContentsScale());
7392 EXPECT_FLOAT_EQ(9.f
, child1_layer
->GetIdealContentsScale());
7393 EXPECT_FLOAT_EQ(9.f
, child1_layer
->mask_layer()->GetIdealContentsScale());
7396 child1_layer
->replica_layer()->mask_layer()->GetIdealContentsScale());
7397 EXPECT_FLOAT_EQ(15.f
, child2_layer
->GetIdealContentsScale());
7400 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
7402 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
7403 EXPECT_FLOAT_EQ(0.f
,
7404 child1_layer
->mask_layer()
7406 .maximum_animation_contents_scale
);
7407 EXPECT_FLOAT_EQ(0.f
,
7408 child1_layer
->replica_layer()
7411 .maximum_animation_contents_scale
);
7413 24.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
7415 // Changing device-scale would affect ideal_contents_scale and
7416 // maximum_animation_contents_scale.
7418 device_scale_factor
= 4.0f
;
7419 inputs
.device_scale_factor
= device_scale_factor
;
7420 inputs
.can_adjust_raster_scales
= true;
7421 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7423 EXPECT_FLOAT_EQ(12.f
, root_layer
->GetIdealContentsScale());
7424 EXPECT_FLOAT_EQ(36.f
, child1_layer
->GetIdealContentsScale());
7425 EXPECT_FLOAT_EQ(36.f
, child1_layer
->mask_layer()->GetIdealContentsScale());
7428 child1_layer
->replica_layer()->mask_layer()->GetIdealContentsScale());
7429 EXPECT_FLOAT_EQ(60.f
, child2_layer
->GetIdealContentsScale());
7432 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
7434 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
7435 EXPECT_FLOAT_EQ(0.f
,
7436 child1_layer
->mask_layer()
7438 .maximum_animation_contents_scale
);
7439 EXPECT_FLOAT_EQ(0.f
,
7440 child1_layer
->replica_layer()
7443 .maximum_animation_contents_scale
);
7445 96.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
7448 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInChildRenderSurface
) {
7449 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7450 SetLayerPropertiesForTesting(root
.get(),
7454 gfx::Size(768 / 2, 3000),
7457 root
->SetIsDrawable(true);
7459 scoped_refptr
<Layer
> clip
= Layer::Create(layer_settings());
7460 SetLayerPropertiesForTesting(clip
.get(),
7464 gfx::Size(768 / 2, 10000),
7467 clip
->SetMasksToBounds(true);
7469 scoped_refptr
<Layer
> content
= Layer::Create(layer_settings());
7470 SetLayerPropertiesForTesting(content
.get(),
7474 gfx::Size(768 / 2, 10000),
7477 content
->SetIsDrawable(true);
7478 content
->SetForceRenderSurface(true);
7480 root
->AddChild(clip
);
7481 clip
->AddChild(content
);
7483 host()->SetRootLayer(root
);
7485 gfx::Size
device_viewport_size(768, 582);
7486 RenderSurfaceLayerList render_surface_layer_list
;
7487 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
7488 host()->root_layer(), device_viewport_size
, &render_surface_layer_list
);
7489 inputs
.device_scale_factor
= 2.f
;
7490 inputs
.page_scale_factor
= 1.f
;
7491 inputs
.page_scale_layer
= NULL
;
7492 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7494 // Layers in the root render surface have their visible content rect clipped
7496 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root
->visible_layer_rect());
7498 // Layers drawing to a child render surface should still have their visible
7499 // content rect clipped by the viewport.
7500 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content
->visible_layer_rect());
7503 TEST_F(LayerTreeHostCommonTest
, BoundsDeltaAffectVisibleContentRect
) {
7504 FakeImplProxy proxy
;
7505 TestSharedBitmapManager shared_bitmap_manager
;
7506 TestTaskGraphRunner task_graph_runner
;
7507 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
7508 &task_graph_runner
);
7510 // Set two layers: the root layer clips it's child,
7511 // the child draws its content.
7513 gfx::Size root_size
= gfx::Size(300, 500);
7515 // Sublayer should be bigger than the root enlarged by bounds_delta.
7516 gfx::Size sublayer_size
= gfx::Size(300, 1000);
7518 // Device viewport accomidated the root and the top controls.
7519 gfx::Size device_viewport_size
= gfx::Size(300, 600);
7520 gfx::Transform identity_matrix
;
7522 host_impl
.SetViewportSize(device_viewport_size
);
7523 host_impl
.active_tree()->SetRootLayer(
7524 LayerImpl::Create(host_impl
.active_tree(), 1));
7526 LayerImpl
* root
= host_impl
.active_tree()->root_layer();
7527 SetLayerPropertiesForTesting(root
,
7535 root
->SetMasksToBounds(true);
7537 root
->AddChild(LayerImpl::Create(host_impl
.active_tree(), 2));
7539 LayerImpl
* sublayer
= root
->child_at(0);
7540 SetLayerPropertiesForTesting(sublayer
,
7548 sublayer
->SetDrawsContent(true);
7550 LayerImplList layer_impl_list
;
7551 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7552 root
, device_viewport_size
, &layer_impl_list
);
7554 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7556 EXPECT_EQ(gfx::Rect(root_size
), sublayer
->visible_layer_rect());
7558 root
->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
7560 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7562 gfx::Rect
affected_by_delta(0, 0, root_size
.width(),
7563 root_size
.height() + 50);
7564 EXPECT_EQ(affected_by_delta
, sublayer
->visible_layer_rect());
7567 TEST_F(LayerTreeHostCommonTest
, NodesAffectedByBoundsDeltaGetUpdated
) {
7568 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7569 scoped_refptr
<Layer
> inner_viewport_container_layer
=
7570 Layer::Create(layer_settings());
7571 scoped_refptr
<Layer
> inner_viewport_scroll_layer
=
7572 Layer::Create(layer_settings());
7573 scoped_refptr
<Layer
> outer_viewport_container_layer
=
7574 Layer::Create(layer_settings());
7575 scoped_refptr
<Layer
> outer_viewport_scroll_layer
=
7576 Layer::Create(layer_settings());
7578 root
->AddChild(inner_viewport_container_layer
);
7579 inner_viewport_container_layer
->AddChild(inner_viewport_scroll_layer
);
7580 inner_viewport_scroll_layer
->AddChild(outer_viewport_container_layer
);
7581 outer_viewport_container_layer
->AddChild(outer_viewport_scroll_layer
);
7583 inner_viewport_scroll_layer
->SetScrollClipLayerId(
7584 inner_viewport_container_layer
->id());
7585 outer_viewport_scroll_layer
->SetScrollClipLayerId(
7586 outer_viewport_container_layer
->id());
7588 inner_viewport_scroll_layer
->SetIsContainerForFixedPositionLayers(true);
7589 outer_viewport_scroll_layer
->SetIsContainerForFixedPositionLayers(true);
7591 host()->SetRootLayer(root
);
7592 host()->RegisterViewportLayers(nullptr, root
, inner_viewport_scroll_layer
,
7593 outer_viewport_scroll_layer
);
7595 scoped_refptr
<Layer
> fixed_to_inner
= Layer::Create(layer_settings());
7596 scoped_refptr
<Layer
> fixed_to_outer
= Layer::Create(layer_settings());
7598 inner_viewport_scroll_layer
->AddChild(fixed_to_inner
);
7599 outer_viewport_scroll_layer
->AddChild(fixed_to_outer
);
7601 LayerPositionConstraint fixed_to_right
;
7602 fixed_to_right
.set_is_fixed_position(true);
7603 fixed_to_right
.set_is_fixed_to_right_edge(true);
7605 fixed_to_inner
->SetPositionConstraint(fixed_to_right
);
7606 fixed_to_outer
->SetPositionConstraint(fixed_to_right
);
7608 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7610 TransformTree
& transform_tree
= host()->property_trees()->transform_tree
;
7611 EXPECT_TRUE(transform_tree
.HasNodesAffectedByInnerViewportBoundsDelta());
7612 EXPECT_TRUE(transform_tree
.HasNodesAffectedByOuterViewportBoundsDelta());
7614 LayerPositionConstraint fixed_to_left
;
7615 fixed_to_left
.set_is_fixed_position(true);
7616 fixed_to_inner
->SetPositionConstraint(fixed_to_left
);
7618 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7619 EXPECT_FALSE(transform_tree
.HasNodesAffectedByInnerViewportBoundsDelta());
7620 EXPECT_TRUE(transform_tree
.HasNodesAffectedByOuterViewportBoundsDelta());
7622 fixed_to_outer
->SetPositionConstraint(fixed_to_left
);
7624 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7625 EXPECT_FALSE(transform_tree
.HasNodesAffectedByInnerViewportBoundsDelta());
7626 EXPECT_FALSE(transform_tree
.HasNodesAffectedByOuterViewportBoundsDelta());
7629 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectForAnimatedLayer
) {
7630 const gfx::Transform identity_matrix
;
7631 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7632 scoped_refptr
<LayerWithForcedDrawsContent
> animated
=
7633 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7635 root
->AddChild(animated
);
7637 host()->SetRootLayer(root
);
7639 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
7640 gfx::PointF(), gfx::Size(100, 100), true, false);
7641 SetLayerPropertiesForTesting(animated
.get(), identity_matrix
, gfx::Point3F(),
7642 gfx::PointF(), gfx::Size(20, 20), true, false);
7644 root
->SetMasksToBounds(true);
7645 root
->SetForceRenderSurface(true);
7646 animated
->SetOpacity(0.f
);
7648 AddOpacityTransitionToController(animated
->layer_animation_controller(), 10.0,
7651 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7653 EXPECT_FALSE(animated
->visible_rect_from_property_trees().IsEmpty());
7656 TEST_F(LayerTreeHostCommonTest
,
7657 VisibleContentRectForAnimatedLayerWithSingularTransform
) {
7658 const gfx::Transform identity_matrix
;
7659 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7660 scoped_refptr
<Layer
> clip
= Layer::Create(layer_settings());
7661 scoped_refptr
<LayerWithForcedDrawsContent
> animated
=
7662 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7663 scoped_refptr
<LayerWithForcedDrawsContent
> surface
=
7664 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7665 scoped_refptr
<LayerWithForcedDrawsContent
> descendant_of_animation
=
7666 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7668 root
->AddChild(clip
);
7669 clip
->AddChild(animated
);
7670 animated
->AddChild(surface
);
7671 surface
->AddChild(descendant_of_animation
);
7673 clip
->SetMasksToBounds(true);
7674 surface
->SetForceRenderSurface(true);
7676 host()->SetRootLayer(root
);
7678 gfx::Transform uninvertible_matrix
;
7679 uninvertible_matrix
.Scale3d(6.f
, 6.f
, 0.f
);
7681 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
7682 gfx::PointF(), gfx::Size(100, 100), true, false);
7683 SetLayerPropertiesForTesting(clip
.get(), identity_matrix
, gfx::Point3F(),
7684 gfx::PointF(), gfx::Size(10, 10), true, false);
7685 SetLayerPropertiesForTesting(animated
.get(), uninvertible_matrix
,
7686 gfx::Point3F(), gfx::PointF(),
7687 gfx::Size(120, 120), true, false);
7688 SetLayerPropertiesForTesting(surface
.get(), identity_matrix
, gfx::Point3F(),
7689 gfx::PointF(), gfx::Size(100, 100), true, false);
7690 SetLayerPropertiesForTesting(descendant_of_animation
.get(), identity_matrix
,
7691 gfx::Point3F(), gfx::PointF(),
7692 gfx::Size(200, 200), true, false);
7694 TransformOperations start_transform_operations
;
7695 start_transform_operations
.AppendMatrix(uninvertible_matrix
);
7696 TransformOperations end_transform_operations
;
7698 AddAnimatedTransformToLayer(animated
.get(), 10.0, start_transform_operations
,
7699 end_transform_operations
);
7701 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7703 // The animated layer has a singular transform and maps to a non-empty rect in
7704 // clipped target space, so is treated as fully visible.
7705 EXPECT_EQ(gfx::Rect(120, 120), animated
->visible_rect_from_property_trees());
7707 // The singular transform on |animated| is flattened when inherited by
7708 // |surface|, and this happens to make it invertible.
7709 EXPECT_EQ(gfx::Rect(2, 2), surface
->visible_rect_from_property_trees());
7710 EXPECT_EQ(gfx::Rect(2, 2),
7711 descendant_of_animation
->visible_rect_from_property_trees());
7713 gfx::Transform zero_matrix
;
7714 zero_matrix
.Scale3d(0.f
, 0.f
, 0.f
);
7715 SetLayerPropertiesForTesting(animated
.get(), zero_matrix
, gfx::Point3F(),
7716 gfx::PointF(), gfx::Size(120, 120), true, false);
7718 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7720 // The animated layer maps to the empty rect in clipped target space, so is
7721 // treated as having an empty visible rect.
7722 EXPECT_EQ(gfx::Rect(), animated
->visible_rect_from_property_trees());
7724 // This time, flattening does not make |animated|'s transform invertible. This
7725 // means the clip cannot be projected into |surface|'s space, so we treat
7726 // |surface| and layers that draw into it as fully visible.
7727 EXPECT_EQ(gfx::Rect(100, 100), surface
->visible_rect_from_property_trees());
7728 EXPECT_EQ(gfx::Rect(200, 200),
7729 descendant_of_animation
->visible_rect_from_property_trees());
7732 // Verify that having an animated filter (but no current filter, as these
7733 // are mutually exclusive) correctly creates a render surface.
7734 TEST_F(LayerTreeHostCommonTest
, AnimatedFilterCreatesRenderSurface
) {
7735 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7736 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7737 scoped_refptr
<Layer
> grandchild
= Layer::Create(layer_settings());
7738 root
->AddChild(child
);
7739 child
->AddChild(grandchild
);
7741 gfx::Transform identity_transform
;
7742 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7743 gfx::PointF(), gfx::Size(50, 50), true, false);
7744 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7745 gfx::PointF(), gfx::Size(50, 50), true, false);
7746 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7747 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7749 host()->SetRootLayer(root
);
7751 AddAnimatedFilterToLayer(child
.get(), 10.0, 0.1f
, 0.2f
);
7753 ExecuteCalculateDrawProperties(root
.get());
7755 EXPECT_TRUE(root
->render_surface());
7756 EXPECT_TRUE(child
->render_surface());
7757 EXPECT_FALSE(grandchild
->render_surface());
7759 EXPECT_TRUE(root
->filters().IsEmpty());
7760 EXPECT_TRUE(child
->filters().IsEmpty());
7761 EXPECT_TRUE(grandchild
->filters().IsEmpty());
7763 EXPECT_FALSE(root
->FilterIsAnimating());
7764 EXPECT_TRUE(child
->FilterIsAnimating());
7765 EXPECT_FALSE(grandchild
->FilterIsAnimating());
7768 // Ensures that the property tree code accounts for offsets between fixed
7769 // position layers and their respective containers.
7770 TEST_F(LayerTreeHostCommonTest
, PropertyTreesAccountForFixedParentOffset
) {
7771 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7772 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7773 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
7774 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7776 root
->AddChild(child
);
7777 child
->AddChild(grandchild
);
7779 gfx::Transform identity_transform
;
7780 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7781 gfx::PointF(), gfx::Size(50, 50), true, false);
7782 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7783 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7785 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7786 gfx::Point3F(), gfx::PointF(-1000, -1000),
7787 gfx::Size(50, 50), true, false);
7789 root
->SetMasksToBounds(true);
7790 root
->SetIsContainerForFixedPositionLayers(true);
7791 LayerPositionConstraint constraint
;
7792 constraint
.set_is_fixed_position(true);
7793 grandchild
->SetPositionConstraint(constraint
);
7795 root
->SetIsContainerForFixedPositionLayers(true);
7797 host()->SetRootLayer(root
);
7799 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7801 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7802 grandchild
->visible_rect_from_property_trees());
7805 // Ensures that the property tree code accounts for offsets between fixed
7806 // position containers and their transform tree parents, when a fixed position
7807 // layer's container is its layer tree parent, but this parent doesn't have its
7808 // own transform tree node.
7809 TEST_F(LayerTreeHostCommonTest
,
7810 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent
) {
7811 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7812 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7813 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
7814 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7816 root
->AddChild(child
);
7817 child
->AddChild(grandchild
);
7819 gfx::Transform identity_transform
;
7820 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7821 gfx::PointF(), gfx::Size(50, 50), true, false);
7822 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7823 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7825 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7826 gfx::Point3F(), gfx::PointF(-1000, -1000),
7827 gfx::Size(50, 50), true, false);
7829 root
->SetMasksToBounds(true);
7830 child
->SetIsContainerForFixedPositionLayers(true);
7831 LayerPositionConstraint constraint
;
7832 constraint
.set_is_fixed_position(true);
7833 grandchild
->SetPositionConstraint(constraint
);
7835 root
->SetIsContainerForFixedPositionLayers(true);
7837 host()->SetRootLayer(root
);
7839 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7841 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7842 grandchild
->visible_rect_from_property_trees());
7845 TEST_F(LayerTreeHostCommonTest
, CombineClipsUsingContentTarget
) {
7846 // In the following layer tree, the layer |box|'s render target is |surface|.
7847 // |surface| also creates a transform node. We want to combine clips for |box|
7848 // in the space of its target (i.e., |surface|), not its target's target. This
7849 // test ensures that happens.
7851 gfx::Transform rotate
;
7853 gfx::Transform identity
;
7855 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7856 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7857 gfx::PointF(), gfx::Size(2500, 1500), true,
7860 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7861 SetLayerPropertiesForTesting(frame_clip
.get(), identity
, gfx::Point3F(),
7862 gfx::PointF(), gfx::Size(2500, 1500), true,
7864 frame_clip
->SetMasksToBounds(true);
7866 scoped_refptr
<Layer
> rotated
= Layer::Create(layer_settings());
7867 SetLayerPropertiesForTesting(rotated
.get(), rotate
,
7868 gfx::Point3F(1250, 250, 0), gfx::PointF(),
7869 gfx::Size(2500, 500), true, false);
7871 scoped_refptr
<Layer
> surface
= Layer::Create(layer_settings());
7872 SetLayerPropertiesForTesting(surface
.get(), rotate
, gfx::Point3F(),
7873 gfx::PointF(), gfx::Size(2500, 500), true,
7875 surface
->SetOpacity(0.5);
7877 scoped_refptr
<LayerWithForcedDrawsContent
> container
=
7878 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7879 SetLayerPropertiesForTesting(container
.get(), identity
, gfx::Point3F(),
7880 gfx::PointF(), gfx::Size(300, 300), true, false);
7882 scoped_refptr
<LayerWithForcedDrawsContent
> box
=
7883 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7884 SetLayerPropertiesForTesting(box
.get(), identity
, gfx::Point3F(),
7885 gfx::PointF(), gfx::Size(100, 100), true, false);
7887 root
->AddChild(frame_clip
);
7888 frame_clip
->AddChild(rotated
);
7889 rotated
->AddChild(surface
);
7890 surface
->AddChild(container
);
7891 surface
->AddChild(box
);
7893 host()->SetRootLayer(root
);
7895 ExecuteCalculateDrawProperties(root
.get());
7898 TEST_F(LayerTreeHostCommonTest
, OnlyApplyFixedPositioningOnce
) {
7899 gfx::Transform identity
;
7900 gfx::Transform translate_z
;
7901 translate_z
.Translate3d(0, 0, 10);
7903 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7904 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7905 gfx::PointF(), gfx::Size(800, 800), true, false);
7906 root
->SetIsContainerForFixedPositionLayers(true);
7908 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7909 SetLayerPropertiesForTesting(frame_clip
.get(), translate_z
, gfx::Point3F(),
7910 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7912 frame_clip
->SetMasksToBounds(true);
7914 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
7915 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7916 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
7917 gfx::PointF(), gfx::Size(1000, 1000), true,
7920 LayerPositionConstraint constraint
;
7921 constraint
.set_is_fixed_position(true);
7922 fixed
->SetPositionConstraint(constraint
);
7924 root
->AddChild(frame_clip
);
7925 frame_clip
->AddChild(fixed
);
7927 host()->SetRootLayer(root
);
7929 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7931 gfx::Rect
expected(0, 0, 100, 100);
7932 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
7935 TEST_F(LayerTreeHostCommonTest
,
7936 PropertyTreesAccountForScrollCompensationAdjustment
) {
7937 gfx::Transform identity
;
7938 gfx::Transform translate_z
;
7939 translate_z
.Translate3d(0, 0, 10);
7941 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7942 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7943 gfx::PointF(), gfx::Size(800, 800), true, false);
7944 root
->SetIsContainerForFixedPositionLayers(true);
7946 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7947 SetLayerPropertiesForTesting(frame_clip
.get(), translate_z
, gfx::Point3F(),
7948 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7950 frame_clip
->SetMasksToBounds(true);
7952 scoped_refptr
<LayerWithForcedDrawsContent
> scroller
=
7953 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7954 SetLayerPropertiesForTesting(scroller
.get(), identity
, gfx::Point3F(),
7955 gfx::PointF(), gfx::Size(1000, 1000), true,
7958 scroller
->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f
, 0.7f
));
7959 scroller
->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7));
7960 scroller
->SetScrollClipLayerId(frame_clip
->id());
7962 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
7963 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7964 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
7965 gfx::PointF(), gfx::Size(50, 50), true, false);
7967 LayerPositionConstraint constraint
;
7968 constraint
.set_is_fixed_position(true);
7969 fixed
->SetPositionConstraint(constraint
);
7971 scoped_refptr
<LayerWithForcedDrawsContent
> fixed_child
=
7972 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7973 SetLayerPropertiesForTesting(fixed_child
.get(), identity
, gfx::Point3F(),
7974 gfx::PointF(), gfx::Size(10, 10), true, false);
7976 fixed_child
->SetPositionConstraint(constraint
);
7978 root
->AddChild(frame_clip
);
7979 frame_clip
->AddChild(scroller
);
7980 scroller
->AddChild(fixed
);
7981 fixed
->AddChild(fixed_child
);
7983 host()->SetRootLayer(root
);
7985 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7987 gfx::Rect
expected(0, 0, 50, 50);
7988 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
7990 expected
= gfx::Rect(0, 0, 10, 10);
7991 EXPECT_EQ(expected
, fixed_child
->visible_rect_from_property_trees());
7994 TEST_F(LayerTreeHostCommonTest
, FixedClipsShouldBeAssociatedWithTheRightNode
) {
7995 gfx::Transform identity
;
7997 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7998 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7999 gfx::PointF(), gfx::Size(800, 800), true, false);
8000 root
->SetIsContainerForFixedPositionLayers(true);
8002 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
8003 SetLayerPropertiesForTesting(frame_clip
.get(), identity
, gfx::Point3F(),
8004 gfx::PointF(500, 100), gfx::Size(100, 100), true,
8006 frame_clip
->SetMasksToBounds(true);
8008 scoped_refptr
<LayerWithForcedDrawsContent
> scroller
=
8009 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8010 SetLayerPropertiesForTesting(scroller
.get(), identity
, gfx::Point3F(),
8011 gfx::PointF(), gfx::Size(1000, 1000), true,
8014 scroller
->SetScrollOffset(gfx::ScrollOffset(100, 100));
8015 scroller
->SetScrollClipLayerId(frame_clip
->id());
8017 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
8018 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8019 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
8020 gfx::PointF(100, 100), gfx::Size(50, 50), true,
8023 LayerPositionConstraint constraint
;
8024 constraint
.set_is_fixed_position(true);
8025 fixed
->SetPositionConstraint(constraint
);
8026 fixed
->SetForceRenderSurface(true);
8027 fixed
->SetMasksToBounds(true);
8029 root
->AddChild(frame_clip
);
8030 frame_clip
->AddChild(scroller
);
8031 scroller
->AddChild(fixed
);
8033 host()->SetRootLayer(root
);
8035 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8037 gfx::Rect
expected(0, 0, 50, 50);
8038 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
8041 TEST_F(LayerTreeHostCommonTest
, ChangingAxisAlignmentTriggersRebuild
) {
8042 gfx::Transform identity
;
8043 gfx::Transform translate
;
8044 gfx::Transform rotate
;
8046 translate
.Translate(10, 10);
8049 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
8050 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
8051 gfx::PointF(), gfx::Size(800, 800), true, false);
8052 root
->SetIsContainerForFixedPositionLayers(true);
8054 host()->SetRootLayer(root
);
8056 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8057 EXPECT_FALSE(host()->property_trees()->needs_rebuild
);
8059 root
->SetTransform(translate
);
8060 EXPECT_FALSE(host()->property_trees()->needs_rebuild
);
8062 root
->SetTransform(rotate
);
8063 EXPECT_TRUE(host()->property_trees()->needs_rebuild
);
8066 TEST_F(LayerTreeHostCommonTest
, ChangeTransformOrigin
) {
8067 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
8068 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
8069 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8070 root
->AddChild(child
);
8072 host()->SetRootLayer(root
);
8074 gfx::Transform identity_matrix
;
8075 gfx::Transform scale_matrix
;
8076 scale_matrix
.Scale(2.f
, 2.f
);
8077 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
8078 gfx::PointF(), gfx::Size(100, 100), true, false);
8079 SetLayerPropertiesForTesting(child
.get(), scale_matrix
, gfx::Point3F(),
8080 gfx::PointF(), gfx::Size(10, 10), true, false);
8082 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8083 EXPECT_EQ(gfx::Rect(10, 10), child
->visible_rect_from_property_trees());
8085 child
->SetTransformOrigin(gfx::Point3F(10.f
, 10.f
, 10.f
));
8087 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8088 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child
->visible_rect_from_property_trees());
8091 TEST_F(LayerTreeHostCommonTest
, UpdateScrollChildPosition
) {
8092 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
8093 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
8094 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8095 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
8096 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8098 root
->AddChild(scroll_child
);
8099 root
->AddChild(scroll_parent
);
8100 scroll_child
->SetScrollParent(scroll_parent
.get());
8101 scroll_parent
->SetScrollClipLayerId(root
->id());
8103 host()->SetRootLayer(root
);
8105 gfx::Transform identity_transform
;
8106 gfx::Transform scale
;
8107 scale
.Scale(2.f
, 2.f
);
8108 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
8109 gfx::PointF(), gfx::Size(50, 50), true, false);
8110 SetLayerPropertiesForTesting(scroll_child
.get(), scale
, gfx::Point3F(),
8111 gfx::PointF(), gfx::Size(40, 40), true, false);
8112 SetLayerPropertiesForTesting(scroll_parent
.get(), identity_transform
,
8113 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
8116 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8117 EXPECT_EQ(gfx::Rect(25, 25),
8118 scroll_child
->visible_rect_from_property_trees());
8120 scroll_child
->SetPosition(gfx::PointF(0, -10.f
));
8121 scroll_parent
->SetScrollOffset(gfx::ScrollOffset(0.f
, 10.f
));
8122 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8123 EXPECT_EQ(gfx::Rect(0, 5, 25, 25),
8124 scroll_child
->visible_rect_from_property_trees());
8127 static void CopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {
8130 TEST_F(LayerTreeHostCommonTest
, SkippingSubtreeMain
) {
8131 gfx::Transform identity
;
8132 FakeContentLayerClient client
;
8133 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
8134 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
8135 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8136 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
8137 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8138 scoped_refptr
<FakePictureLayer
> greatgrandchild(
8139 FakePictureLayer::Create(layer_settings(), &client
));
8140 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
8141 gfx::PointF(), gfx::Size(100, 100), true, false);
8142 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
8143 gfx::PointF(), gfx::Size(10, 10), true, false);
8144 SetLayerPropertiesForTesting(grandchild
.get(), identity
, gfx::Point3F(),
8145 gfx::PointF(), gfx::Size(10, 10), true, false);
8146 SetLayerPropertiesForTesting(greatgrandchild
.get(), identity
, gfx::Point3F(),
8147 gfx::PointF(), gfx::Size(10, 10), true, false);
8149 root
->AddChild(child
);
8150 child
->AddChild(grandchild
);
8151 grandchild
->AddChild(greatgrandchild
);
8153 host()->SetRootLayer(root
);
8155 // Check the non-skipped case.
8156 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8157 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
8159 // Now we will reset the visible rect from property trees for the grandchild,
8160 // and we will configure |child| in several ways that should force the subtree
8161 // to be skipped. The visible content rect for |grandchild| should, therefore,
8163 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
8164 gfx::Transform singular
;
8165 singular
.matrix().set(0, 0, 0);
8167 child
->SetTransform(singular
);
8168 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8169 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
8170 child
->SetTransform(identity
);
8172 child
->SetHideLayerAndSubtree(true);
8173 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8174 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
8175 child
->SetHideLayerAndSubtree(false);
8177 child
->SetOpacity(0.f
);
8178 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8179 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
8181 // Now, even though child has zero opacity, we will configure |grandchild| and
8182 // |greatgrandchild| in several ways that should force the subtree to be
8183 // processed anyhow.
8184 grandchild
->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10)));
8185 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8186 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
8187 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
8188 grandchild
->SetTouchEventHandlerRegion(Region());
8189 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8190 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
8191 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
8193 greatgrandchild
->RequestCopyOfOutput(
8194 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback
)));
8195 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8196 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
8199 TEST_F(LayerTreeHostCommonTest
, SkippingSubtreeImpl
) {
8200 FakeImplProxy proxy
;
8201 TestSharedBitmapManager shared_bitmap_manager
;
8202 TestTaskGraphRunner task_graph_runner
;
8203 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
8204 &task_graph_runner
);
8206 gfx::Transform identity
;
8207 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
8208 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 2);
8209 scoped_ptr
<LayerImpl
> grandchild
=
8210 LayerImpl::Create(host_impl
.active_tree(), 3);
8212 scoped_ptr
<FakePictureLayerImpl
> greatgrandchild(
8213 FakePictureLayerImpl::Create(host_impl
.active_tree(), 4));
8215 child
->SetDrawsContent(true);
8216 grandchild
->SetDrawsContent(true);
8217 greatgrandchild
->SetDrawsContent(true);
8219 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
8220 gfx::PointF(), gfx::Size(100, 100), true, false,
8222 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
8223 gfx::PointF(), gfx::Size(10, 10), true, false,
8225 SetLayerPropertiesForTesting(grandchild
.get(), identity
, gfx::Point3F(),
8226 gfx::PointF(), gfx::Size(10, 10), true, false,
8228 SetLayerPropertiesForTesting(greatgrandchild
.get(), identity
, gfx::Point3F(),
8229 gfx::PointF(), gfx::Size(10, 10), true, false,
8232 LayerImpl
* child_ptr
= child
.get();
8233 LayerImpl
* grandchild_ptr
= grandchild
.get();
8234 LayerImpl
* greatgrandchild_ptr
= greatgrandchild
.get();
8236 grandchild
->AddChild(greatgrandchild
.Pass());
8237 child
->AddChild(grandchild
.Pass());
8238 root
->AddChild(child
.Pass());
8240 // Check the non-skipped case.
8241 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8242 EXPECT_EQ(gfx::Rect(10, 10),
8243 grandchild_ptr
->visible_rect_from_property_trees());
8245 // Now we will reset the visible rect from property trees for the grandchild,
8246 // and we will configure |child| in several ways that should force the subtree
8247 // to be skipped. The visible content rect for |grandchild| should, therefore,
8249 grandchild_ptr
->set_visible_rect_from_property_trees(gfx::Rect());
8250 gfx::Transform singular
;
8251 singular
.matrix().set(0, 0, 0);
8253 child_ptr
->SetTransform(singular
);
8254 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8255 EXPECT_EQ(gfx::Rect(0, 0),
8256 grandchild_ptr
->visible_rect_from_property_trees());
8257 child_ptr
->SetTransform(identity
);
8259 child_ptr
->SetHideLayerAndSubtree(true);
8260 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8261 EXPECT_EQ(gfx::Rect(0, 0),
8262 grandchild_ptr
->visible_rect_from_property_trees());
8263 child_ptr
->SetHideLayerAndSubtree(false);
8265 child_ptr
->SetOpacity(0.f
);
8266 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8267 EXPECT_EQ(gfx::Rect(0, 0),
8268 grandchild_ptr
->visible_rect_from_property_trees());
8270 // Now, even though child has zero opacity, we will configure |grandchild| and
8271 // |greatgrandchild| in several ways that should force the subtree to be
8272 // processed anyhow.
8273 grandchild_ptr
->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10)));
8274 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8275 EXPECT_EQ(gfx::Rect(10, 10),
8276 grandchild_ptr
->visible_rect_from_property_trees());
8277 grandchild_ptr
->set_visible_rect_from_property_trees(gfx::Rect());
8278 grandchild_ptr
->SetTouchEventHandlerRegion(Region());
8279 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8280 EXPECT_EQ(gfx::Rect(0, 0),
8281 grandchild_ptr
->visible_rect_from_property_trees());
8282 grandchild_ptr
->set_visible_rect_from_property_trees(gfx::Rect());
8284 ScopedPtrVector
<CopyOutputRequest
> requests
;
8285 requests
.push_back(CopyOutputRequest::CreateEmptyRequest());
8287 greatgrandchild_ptr
->PassCopyRequests(&requests
);
8288 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8289 EXPECT_EQ(gfx::Rect(10, 10),
8290 grandchild_ptr
->visible_rect_from_property_trees());
8293 TEST_F(LayerTreeHostCommonTest
, SkippingLayer
) {
8294 gfx::Transform identity
;
8295 FakeContentLayerClient client
;
8296 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
8297 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
8298 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8299 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
8300 gfx::PointF(), gfx::Size(100, 100), true, false);
8301 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
8302 gfx::PointF(), gfx::Size(10, 10), true, false);
8303 root
->AddChild(child
);
8305 host()->SetRootLayer(root
);
8307 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8308 EXPECT_EQ(gfx::Rect(10, 10), child
->visible_rect_from_property_trees());
8309 child
->set_visible_rect_from_property_trees(gfx::Rect());
8311 child
->SetHideLayerAndSubtree(true);
8312 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8313 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
8314 child
->SetHideLayerAndSubtree(false);
8316 child
->SetBounds(gfx::Size());
8317 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8318 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
8319 child
->SetBounds(gfx::Size(10, 10));
8321 gfx::Transform rotate
;
8322 child
->SetDoubleSided(false);
8323 rotate
.RotateAboutXAxis(180.f
);
8324 child
->SetTransform(rotate
);
8325 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8326 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
8327 child
->SetDoubleSided(true);
8328 child
->SetTransform(identity
);
8330 child
->SetOpacity(0.f
);
8331 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8332 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
8335 TEST_F(LayerTreeHostCommonTest
, LayerTreeRebuildTest
) {
8336 // Ensure that the treewalk in LayerTreeHostCommom::
8337 // PreCalculateMetaInformation happens when its required.
8338 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
8339 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
8340 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
8342 root
->AddChild(parent
);
8343 parent
->AddChild(child
);
8345 child
->SetClipParent(root
.get());
8347 gfx::Transform identity
;
8349 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
8350 gfx::PointF(), gfx::Size(100, 100), true, false);
8351 SetLayerPropertiesForTesting(parent
.get(), identity
, gfx::Point3F(),
8352 gfx::PointF(), gfx::Size(100, 100), true, false);
8353 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
8354 gfx::PointF(), gfx::Size(100, 100), true, false);
8356 host()->SetRootLayer(root
);
8358 ExecuteCalculateDrawProperties(root
.get());
8359 EXPECT_EQ(parent
->draw_properties().num_unclipped_descendants
, 1u);
8361 // Ensure the dynamic update to input handlers happens.
8362 child
->SetHaveWheelEventHandlers(true);
8363 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_input_handler
);
8364 ExecuteCalculateDrawProperties(root
.get());
8365 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_input_handler
);
8367 child
->SetHaveWheelEventHandlers(false);
8368 EXPECT_FALSE(root
->draw_properties().layer_or_descendant_has_input_handler
);
8369 ExecuteCalculateDrawProperties(root
.get());
8370 EXPECT_FALSE(root
->draw_properties().layer_or_descendant_has_input_handler
);
8372 child
->RequestCopyOfOutput(
8373 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback
)));
8374 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
8375 ExecuteCalculateDrawProperties(root
.get());
8376 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
8379 TEST_F(LayerTreeHostCommonTest
, InputHandlersRecursiveUpdateTest
) {
8380 // Ensure that the treewalk in LayertreeHostCommon::
8381 // PreCalculateMetaInformation updates input handlers correctly.
8382 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
8383 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
8385 root
->AddChild(child
);
8387 child
->SetHaveWheelEventHandlers(true);
8389 gfx::Transform identity
;
8391 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
8392 gfx::PointF(), gfx::Size(100, 100), true, false);
8393 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
8394 gfx::PointF(), gfx::Size(100, 100), true, false);
8396 host()->SetRootLayer(root
);
8398 EXPECT_EQ(root
->num_layer_or_descendants_with_input_handler(), 0);
8399 ExecuteCalculateDrawProperties(root
.get());
8400 EXPECT_EQ(root
->num_layer_or_descendants_with_input_handler(), 1);
8401 child
->SetHaveWheelEventHandlers(false);
8402 EXPECT_EQ(root
->num_layer_or_descendants_with_input_handler(), 0);
8405 TEST_F(LayerTreeHostCommonTest
, ResetPropertyTreeIndices
) {
8406 gfx::Transform identity
;
8407 gfx::Transform translate_z
;
8408 translate_z
.Translate3d(0, 0, 10);
8410 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
8411 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
8412 gfx::PointF(), gfx::Size(800, 800), true, false);
8414 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
8415 SetLayerPropertiesForTesting(child
.get(), translate_z
, gfx::Point3F(),
8416 gfx::PointF(), gfx::Size(100, 100), true, false);
8418 root
->AddChild(child
);
8420 host()->SetRootLayer(root
);
8422 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8423 EXPECT_NE(-1, child
->transform_tree_index());
8425 child
->RemoveFromParent();
8427 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8428 EXPECT_EQ(-1, child
->transform_tree_index());
8431 TEST_F(LayerTreeHostCommonTest
, ResetLayerDrawPropertiestest
) {
8432 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
8433 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
8435 root
->AddChild(child
);
8436 gfx::Transform identity
;
8438 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
8439 gfx::PointF(), gfx::Size(100, 100), true, false);
8440 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
8441 gfx::PointF(), gfx::Size(100, 100), true, false);
8443 host()->SetRootLayer(root
);
8445 EXPECT_FALSE(root
->layer_or_descendant_is_drawn());
8446 EXPECT_FALSE(root
->visited());
8447 EXPECT_FALSE(root
->sorted_for_recursion());
8448 EXPECT_FALSE(child
->layer_or_descendant_is_drawn());
8449 EXPECT_FALSE(child
->visited());
8450 EXPECT_FALSE(child
->sorted_for_recursion());
8452 root
->set_layer_or_descendant_is_drawn(true);
8453 root
->set_visited(true);
8454 root
->set_sorted_for_recursion(true);
8455 child
->set_layer_or_descendant_is_drawn(true);
8456 child
->set_visited(true);
8457 child
->set_sorted_for_recursion(true);
8459 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root
.get());
8461 EXPECT_FALSE(root
->layer_or_descendant_is_drawn());
8462 EXPECT_FALSE(root
->visited());
8463 EXPECT_FALSE(root
->sorted_for_recursion());
8464 EXPECT_FALSE(child
->layer_or_descendant_is_drawn());
8465 EXPECT_FALSE(child
->visited());
8466 EXPECT_FALSE(child
->sorted_for_recursion());