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.h"
14 #include "cc/layers/content_layer_client.h"
15 #include "cc/layers/layer.h"
16 #include "cc/layers/layer_client.h"
17 #include "cc/layers/layer_impl.h"
18 #include "cc/layers/layer_iterator.h"
19 #include "cc/layers/render_surface.h"
20 #include "cc/layers/render_surface_impl.h"
21 #include "cc/output/copy_output_request.h"
22 #include "cc/output/copy_output_result.h"
23 #include "cc/test/animation_test_common.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/trees/layer_tree_impl.h"
32 #include "cc/trees/proxy.h"
33 #include "cc/trees/single_thread_proxy.h"
34 #include "testing/gmock/include/gmock/gmock.h"
35 #include "testing/gtest/include/gtest/gtest.h"
36 #include "ui/gfx/geometry/quad_f.h"
37 #include "ui/gfx/transform.h"
42 class LayerWithForcedDrawsContent
: public Layer
{
44 LayerWithForcedDrawsContent() {}
46 bool DrawsContent() const override
;
49 ~LayerWithForcedDrawsContent() override
{}
52 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
54 class MockContentLayerClient
: public ContentLayerClient
{
56 MockContentLayerClient() {}
57 ~MockContentLayerClient() override
{}
60 const gfx::Rect
& clip
,
61 ContentLayerClient::GraphicsContextStatus gc_status
) override
{}
62 void DidChangeLayerCanUseLCDText() override
{}
63 bool FillsBoundsCompletely() const override
{ return false; }
66 scoped_refptr
<FakePictureLayer
> CreateDrawablePictureLayer(
67 ContentLayerClient
* delegate
) {
68 scoped_refptr
<FakePictureLayer
> to_return
=
69 FakePictureLayer::Create(delegate
);
70 to_return
->SetIsDrawable(true);
74 scoped_refptr
<ContentLayer
> CreateDrawableContentLayer(
75 ContentLayerClient
* delegate
) {
76 scoped_refptr
<ContentLayer
> to_return
= ContentLayer::Create(delegate
);
77 to_return
->SetIsDrawable(true);
81 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
83 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
84 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
87 #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
89 EXPECT_FLOAT_EQ(expected, layer->draw_properties().ideal_contents_scale); \
92 TEST_F(LayerTreeHostCommonTest
, TransformsForNoOpLayer
) {
93 // Sanity check: For layers positioned at zero, with zero size,
94 // and with identity transforms, then the draw transform,
95 // screen space transform, and the hierarchy passed on to children
96 // layers should also be identity transforms.
98 scoped_refptr
<Layer
> parent
= Layer::Create();
99 scoped_refptr
<Layer
> child
= Layer::Create();
100 scoped_refptr
<Layer
> grand_child
= Layer::Create();
101 parent
->AddChild(child
);
102 child
->AddChild(grand_child
);
104 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
105 host
->SetRootLayer(parent
);
107 gfx::Transform identity_matrix
;
108 SetLayerPropertiesForTesting(parent
.get(),
115 SetLayerPropertiesForTesting(child
.get(),
122 SetLayerPropertiesForTesting(grand_child
.get(),
130 ExecuteCalculateDrawProperties(parent
.get());
132 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
133 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
134 child
->screen_space_transform());
135 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
136 grand_child
->draw_transform());
137 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
138 grand_child
->screen_space_transform());
141 TEST_F(LayerTreeHostCommonTest
, DoNotSkipLayersWithHandlers
) {
142 scoped_refptr
<Layer
> parent
= Layer::Create();
143 scoped_refptr
<Layer
> child
= Layer::Create();
144 scoped_refptr
<Layer
> grand_child
= Layer::Create();
145 parent
->AddChild(child
);
146 child
->AddChild(grand_child
);
148 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
149 host
->SetRootLayer(parent
);
151 gfx::Transform identity_matrix
;
152 SetLayerPropertiesForTesting(parent
.get(),
159 SetLayerPropertiesForTesting(child
.get(),
166 // This would have previously caused us to skip our subtree, but this would be
167 // wrong; we need up-to-date draw properties to do hit testing on the layers
169 child
->SetOpacity(0.f
);
170 SetLayerPropertiesForTesting(grand_child
.get(),
177 grand_child
->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
179 ExecuteCalculateDrawProperties(parent
.get());
181 // Check that we've computed draw properties for the subtree rooted at
183 EXPECT_FALSE(child
->draw_transform().IsIdentity());
184 EXPECT_FALSE(grand_child
->draw_transform().IsIdentity());
187 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleLayer
) {
188 gfx::Transform identity_matrix
;
189 scoped_refptr
<Layer
> layer
= Layer::Create();
191 scoped_refptr
<Layer
> root
= Layer::Create();
192 SetLayerPropertiesForTesting(root
.get(),
199 root
->AddChild(layer
);
201 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
202 host
->SetRootLayer(root
);
204 // Case 2: Setting the bounds of the layer should not affect either the draw
205 // transform or the screenspace transform.
206 gfx::Transform translation_to_center
;
207 translation_to_center
.Translate(5.0, 6.0);
208 SetLayerPropertiesForTesting(layer
.get(),
215 ExecuteCalculateDrawProperties(root
.get());
216 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
217 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
218 layer
->screen_space_transform());
220 // Case 3: The anchor point by itself (without a layer transform) should have
221 // no effect on the transforms.
222 SetLayerPropertiesForTesting(layer
.get(),
224 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
229 ExecuteCalculateDrawProperties(root
.get());
230 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
231 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
232 layer
->screen_space_transform());
234 // Case 4: A change in actual position affects both the draw transform and
235 // screen space transform.
236 gfx::Transform position_transform
;
237 position_transform
.Translate(0.f
, 1.2f
);
238 SetLayerPropertiesForTesting(layer
.get(),
240 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
241 gfx::PointF(0.f
, 1.2f
),
245 ExecuteCalculateDrawProperties(root
.get());
246 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
, layer
->draw_transform());
247 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
,
248 layer
->screen_space_transform());
250 // Case 5: In the correct sequence of transforms, the layer transform should
251 // pre-multiply the translation_to_center. This is easily tested by using a
252 // scale transform, because scale and translation are not commutative.
253 gfx::Transform layer_transform
;
254 layer_transform
.Scale3d(2.0, 2.0, 1.0);
255 SetLayerPropertiesForTesting(layer
.get(),
262 ExecuteCalculateDrawProperties(root
.get());
263 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
, layer
->draw_transform());
264 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
,
265 layer
->screen_space_transform());
267 // Case 6: The layer transform should occur with respect to the anchor point.
268 gfx::Transform translation_to_anchor
;
269 translation_to_anchor
.Translate(5.0, 0.0);
270 gfx::Transform expected_result
=
271 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
272 SetLayerPropertiesForTesting(layer
.get(),
274 gfx::Point3F(5.0f
, 0.f
, 0.f
),
279 ExecuteCalculateDrawProperties(root
.get());
280 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
281 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
282 layer
->screen_space_transform());
284 // Case 7: Verify that position pre-multiplies the layer transform. The
285 // current implementation of CalculateDrawProperties does this implicitly, but
286 // it is still worth testing to detect accidental regressions.
287 expected_result
= position_transform
* translation_to_anchor
*
288 layer_transform
* Inverse(translation_to_anchor
);
289 SetLayerPropertiesForTesting(layer
.get(),
291 gfx::Point3F(5.0f
, 0.f
, 0.f
),
292 gfx::PointF(0.f
, 1.2f
),
296 ExecuteCalculateDrawProperties(root
.get());
297 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
298 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
299 layer
->screen_space_transform());
302 TEST_F(LayerTreeHostCommonTest
, TransformsAboutScrollOffset
) {
303 const gfx::ScrollOffset
kScrollOffset(50, 100);
304 const gfx::Vector2dF
kScrollDelta(2.34f
, 5.67f
);
305 const gfx::Vector2d
kMaxScrollOffset(200, 200);
306 const gfx::PointF
kScrollLayerPosition(-kScrollOffset
.x(),
308 const float kPageScale
= 0.888f
;
309 const float kDeviceScale
= 1.666f
;
312 TestSharedBitmapManager shared_bitmap_manager
;
313 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
315 gfx::Transform identity_matrix
;
316 scoped_ptr
<LayerImpl
> sublayer_scoped_ptr(
317 LayerImpl::Create(host_impl
.active_tree(), 1));
318 LayerImpl
* sublayer
= sublayer_scoped_ptr
.get();
319 sublayer
->SetContentsScale(kPageScale
* kDeviceScale
,
320 kPageScale
* kDeviceScale
);
321 SetLayerPropertiesForTesting(sublayer
,
329 scoped_ptr
<LayerImpl
> scroll_layer_scoped_ptr(
330 LayerImpl::Create(host_impl
.active_tree(), 2));
331 LayerImpl
* scroll_layer
= scroll_layer_scoped_ptr
.get();
332 SetLayerPropertiesForTesting(scroll_layer
,
339 scoped_ptr
<LayerImpl
> clip_layer_scoped_ptr(
340 LayerImpl::Create(host_impl
.active_tree(), 4));
341 LayerImpl
* clip_layer
= clip_layer_scoped_ptr
.get();
343 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
344 clip_layer
->SetBounds(
345 gfx::Size(scroll_layer
->bounds().width() + kMaxScrollOffset
.x(),
346 scroll_layer
->bounds().height() + kMaxScrollOffset
.y()));
347 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
348 scroll_layer
->SetScrollDelta(kScrollDelta
);
349 gfx::Transform impl_transform
;
350 scroll_layer
->AddChild(sublayer_scoped_ptr
.Pass());
351 LayerImpl
* scroll_layer_raw_ptr
= scroll_layer_scoped_ptr
.get();
352 clip_layer
->AddChild(scroll_layer_scoped_ptr
.Pass());
353 scroll_layer_raw_ptr
->SetScrollOffset(kScrollOffset
);
355 scoped_ptr
<LayerImpl
> root(LayerImpl::Create(host_impl
.active_tree(), 3));
356 SetLayerPropertiesForTesting(root
.get(),
363 root
->AddChild(clip_layer_scoped_ptr
.Pass());
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 sub_layer_screen_position
.Scale(kPageScale
* kDeviceScale
);
370 expected_transform
.Translate(MathUtil::Round(sub_layer_screen_position
.x()),
371 MathUtil::Round(sub_layer_screen_position
.y()));
372 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
373 sublayer
->draw_transform());
374 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
375 sublayer
->screen_space_transform());
377 gfx::Transform arbitrary_translate
;
378 const float kTranslateX
= 10.6f
;
379 const float kTranslateY
= 20.6f
;
380 arbitrary_translate
.Translate(kTranslateX
, kTranslateY
);
381 SetLayerPropertiesForTesting(scroll_layer
,
388 ExecuteCalculateDrawProperties(
389 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
390 expected_transform
.MakeIdentity();
391 expected_transform
.Translate(
392 MathUtil::Round(kTranslateX
* kPageScale
* kDeviceScale
+
393 sub_layer_screen_position
.x()),
394 MathUtil::Round(kTranslateY
* kPageScale
* kDeviceScale
+
395 sub_layer_screen_position
.y()));
396 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
397 sublayer
->draw_transform());
400 TEST_F(LayerTreeHostCommonTest
, TransformsForSimpleHierarchy
) {
401 gfx::Transform identity_matrix
;
402 scoped_refptr
<Layer
> root
= Layer::Create();
403 scoped_refptr
<Layer
> parent
= Layer::Create();
404 scoped_refptr
<Layer
> child
= Layer::Create();
405 scoped_refptr
<Layer
> grand_child
= Layer::Create();
406 root
->AddChild(parent
);
407 parent
->AddChild(child
);
408 child
->AddChild(grand_child
);
410 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
411 host
->SetRootLayer(root
);
413 // One-time setup of root layer
414 SetLayerPropertiesForTesting(root
.get(),
422 // Case 1: parent's anchor point should not affect child or grand_child.
423 SetLayerPropertiesForTesting(parent
.get(),
425 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
430 SetLayerPropertiesForTesting(child
.get(),
437 SetLayerPropertiesForTesting(grand_child
.get(),
444 ExecuteCalculateDrawProperties(root
.get());
445 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
446 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
447 child
->screen_space_transform());
448 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
449 grand_child
->draw_transform());
450 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
451 grand_child
->screen_space_transform());
453 // Case 2: parent's position affects child and grand_child.
454 gfx::Transform parent_position_transform
;
455 parent_position_transform
.Translate(0.f
, 1.2f
);
456 SetLayerPropertiesForTesting(parent
.get(),
458 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
459 gfx::PointF(0.f
, 1.2f
),
463 SetLayerPropertiesForTesting(child
.get(),
470 SetLayerPropertiesForTesting(grand_child
.get(),
477 ExecuteCalculateDrawProperties(root
.get());
478 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
479 child
->draw_transform());
480 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
481 child
->screen_space_transform());
482 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
483 grand_child
->draw_transform());
484 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
485 grand_child
->screen_space_transform());
487 // Case 3: parent's local transform affects child and grandchild
488 gfx::Transform parent_layer_transform
;
489 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
490 gfx::Transform parent_translation_to_anchor
;
491 parent_translation_to_anchor
.Translate(2.5, 3.0);
492 gfx::Transform parent_composite_transform
=
493 parent_translation_to_anchor
* parent_layer_transform
*
494 Inverse(parent_translation_to_anchor
);
495 SetLayerPropertiesForTesting(parent
.get(),
496 parent_layer_transform
,
497 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
502 SetLayerPropertiesForTesting(child
.get(),
509 SetLayerPropertiesForTesting(grand_child
.get(),
516 ExecuteCalculateDrawProperties(root
.get());
517 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
518 child
->draw_transform());
519 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
520 child
->screen_space_transform());
521 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
522 grand_child
->draw_transform());
523 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
524 grand_child
->screen_space_transform());
527 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleRenderSurface
) {
528 scoped_refptr
<Layer
> root
= Layer::Create();
529 scoped_refptr
<Layer
> parent
= Layer::Create();
530 scoped_refptr
<Layer
> child
= Layer::Create();
531 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
532 make_scoped_refptr(new LayerWithForcedDrawsContent());
533 root
->AddChild(parent
);
534 parent
->AddChild(child
);
535 child
->AddChild(grand_child
);
537 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
538 host
->SetRootLayer(root
);
540 // One-time setup of root layer
541 gfx::Transform identity_matrix
;
542 SetLayerPropertiesForTesting(root
.get(),
550 // Child is set up so that a new render surface should be created.
551 child
->SetOpacity(0.5f
);
552 child
->SetForceRenderSurface(true);
554 gfx::Transform parent_layer_transform
;
555 parent_layer_transform
.Scale3d(1.f
, 0.9f
, 1.f
);
556 gfx::Transform parent_translation_to_anchor
;
557 parent_translation_to_anchor
.Translate(25.0, 30.0);
559 gfx::Transform parent_composite_transform
=
560 parent_translation_to_anchor
* parent_layer_transform
*
561 Inverse(parent_translation_to_anchor
);
562 gfx::Vector2dF parent_composite_scale
=
563 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
565 gfx::Transform surface_sublayer_transform
;
566 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
567 parent_composite_scale
.y());
568 gfx::Transform surface_sublayer_composite_transform
=
569 parent_composite_transform
* Inverse(surface_sublayer_transform
);
571 // Child's render surface should not exist yet.
572 ASSERT_FALSE(child
->render_surface());
574 SetLayerPropertiesForTesting(parent
.get(),
575 parent_layer_transform
,
576 gfx::Point3F(25.0f
, 30.0f
, 0.f
),
581 SetLayerPropertiesForTesting(child
.get(),
588 SetLayerPropertiesForTesting(grand_child
.get(),
595 ExecuteCalculateDrawProperties(root
.get());
597 // Render surface should have been created now.
598 ASSERT_TRUE(child
->render_surface());
599 ASSERT_EQ(child
.get(), child
->render_target());
601 // The child layer's draw transform should refer to its new render surface.
602 // The screen-space transform, however, should still refer to the root.
603 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform
,
604 child
->draw_transform());
605 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
606 child
->screen_space_transform());
608 // Because the grand_child is the only drawable content, the child's render
609 // surface will tighten its bounds to the grand_child. The scale at which the
610 // surface's subtree is drawn must be removed from the composite transform.
611 EXPECT_TRANSFORMATION_MATRIX_EQ(
612 surface_sublayer_composite_transform
,
613 child
->render_target()->render_surface()->draw_transform());
615 // The screen space is the same as the target since the child surface draws
617 EXPECT_TRANSFORMATION_MATRIX_EQ(
618 surface_sublayer_composite_transform
,
619 child
->render_target()->render_surface()->screen_space_transform());
622 TEST_F(LayerTreeHostCommonTest
, TransformsForReplica
) {
623 scoped_refptr
<Layer
> root
= Layer::Create();
624 scoped_refptr
<Layer
> parent
= Layer::Create();
625 scoped_refptr
<Layer
> child
= Layer::Create();
626 scoped_refptr
<Layer
> child_replica
= Layer::Create();
627 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
628 make_scoped_refptr(new LayerWithForcedDrawsContent());
629 root
->AddChild(parent
);
630 parent
->AddChild(child
);
631 child
->AddChild(grand_child
);
632 child
->SetReplicaLayer(child_replica
.get());
634 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
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
);
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();
730 scoped_refptr
<Layer
> parent
= Layer::Create();
731 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
732 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
733 scoped_refptr
<Layer
> child_of_root
= Layer::Create();
734 scoped_refptr
<Layer
> child_of_rs1
= Layer::Create();
735 scoped_refptr
<Layer
> child_of_rs2
= Layer::Create();
736 scoped_refptr
<Layer
> replica_of_rs1
= Layer::Create();
737 scoped_refptr
<Layer
> replica_of_rs2
= Layer::Create();
738 scoped_refptr
<Layer
> grand_child_of_root
= Layer::Create();
739 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs1
=
740 make_scoped_refptr(new LayerWithForcedDrawsContent());
741 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs2
=
742 make_scoped_refptr(new LayerWithForcedDrawsContent());
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 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
756 host
->SetRootLayer(root
);
758 // In combination with descendant draws content, opacity != 1 forces the layer
759 // to have a new render surface.
760 render_surface1
->SetOpacity(0.5f
);
761 render_surface2
->SetOpacity(0.33f
);
763 // One-time setup of root layer
764 gfx::Transform identity_matrix
;
765 SetLayerPropertiesForTesting(root
.get(),
773 // All layers in the tree are initialized with an anchor at .25 and a size of
774 // (10,10). matrix "A" is the composite layer transform used in all layers,
775 // Matrix "R" is the composite replica transform used in all replica layers.
776 gfx::Transform translation_to_anchor
;
777 translation_to_anchor
.Translate(2.5, 0.0);
778 gfx::Transform layer_transform
;
779 layer_transform
.Translate(1.0, 1.0);
780 gfx::Transform replica_layer_transform
;
781 replica_layer_transform
.Scale3d(-2.0, 5.0, 1.0);
784 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
785 gfx::Transform R
= A
* translation_to_anchor
* replica_layer_transform
*
786 Inverse(translation_to_anchor
);
788 gfx::Vector2dF surface1_parent_transform_scale
=
789 MathUtil::ComputeTransform2dScaleComponents(A
, 1.f
);
790 gfx::Transform surface1_sublayer_transform
;
791 surface1_sublayer_transform
.Scale(surface1_parent_transform_scale
.x(),
792 surface1_parent_transform_scale
.y());
794 // SS1 = transform given to the subtree of render_surface1
795 gfx::Transform SS1
= surface1_sublayer_transform
;
796 // S1 = transform to move from render_surface1 pixels to the layer space of
798 gfx::Transform S1
= Inverse(surface1_sublayer_transform
);
800 gfx::Vector2dF surface2_parent_transform_scale
=
801 MathUtil::ComputeTransform2dScaleComponents(SS1
* A
, 1.f
);
802 gfx::Transform surface2_sublayer_transform
;
803 surface2_sublayer_transform
.Scale(surface2_parent_transform_scale
.x(),
804 surface2_parent_transform_scale
.y());
806 // SS2 = transform given to the subtree of render_surface2
807 gfx::Transform SS2
= surface2_sublayer_transform
;
808 // S2 = transform to move from render_surface2 pixels to the layer space of
810 gfx::Transform S2
= Inverse(surface2_sublayer_transform
);
812 SetLayerPropertiesForTesting(parent
.get(),
814 gfx::Point3F(2.5f
, 0.f
, 0.f
),
819 SetLayerPropertiesForTesting(render_surface1
.get(),
821 gfx::Point3F(2.5f
, 0.f
, 0.f
),
826 SetLayerPropertiesForTesting(render_surface2
.get(),
828 gfx::Point3F(2.5f
, 0.f
, 0.f
),
833 SetLayerPropertiesForTesting(child_of_root
.get(),
835 gfx::Point3F(2.5f
, 0.f
, 0.f
),
840 SetLayerPropertiesForTesting(child_of_rs1
.get(),
842 gfx::Point3F(2.5f
, 0.f
, 0.f
),
847 SetLayerPropertiesForTesting(child_of_rs2
.get(),
849 gfx::Point3F(2.5f
, 0.f
, 0.f
),
854 SetLayerPropertiesForTesting(grand_child_of_root
.get(),
856 gfx::Point3F(2.5f
, 0.f
, 0.f
),
861 SetLayerPropertiesForTesting(grand_child_of_rs1
.get(),
863 gfx::Point3F(2.5f
, 0.f
, 0.f
),
868 SetLayerPropertiesForTesting(grand_child_of_rs2
.get(),
870 gfx::Point3F(2.5f
, 0.f
, 0.f
),
875 SetLayerPropertiesForTesting(replica_of_rs1
.get(),
876 replica_layer_transform
,
877 gfx::Point3F(2.5f
, 0.f
, 0.f
),
882 SetLayerPropertiesForTesting(replica_of_rs2
.get(),
883 replica_layer_transform
,
884 gfx::Point3F(2.5f
, 0.f
, 0.f
),
890 ExecuteCalculateDrawProperties(root
.get());
892 // Only layers that are associated with render surfaces should have an actual
893 // RenderSurface() value.
894 ASSERT_TRUE(root
->render_surface());
895 ASSERT_FALSE(child_of_root
->render_surface());
896 ASSERT_FALSE(grand_child_of_root
->render_surface());
898 ASSERT_TRUE(render_surface1
->render_surface());
899 ASSERT_FALSE(child_of_rs1
->render_surface());
900 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
902 ASSERT_TRUE(render_surface2
->render_surface());
903 ASSERT_FALSE(child_of_rs2
->render_surface());
904 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
906 // Verify all render target accessors
907 EXPECT_EQ(root
.get(), parent
->render_target());
908 EXPECT_EQ(root
.get(), child_of_root
->render_target());
909 EXPECT_EQ(root
.get(), grand_child_of_root
->render_target());
911 EXPECT_EQ(render_surface1
.get(), render_surface1
->render_target());
912 EXPECT_EQ(render_surface1
.get(), child_of_rs1
->render_target());
913 EXPECT_EQ(render_surface1
.get(), grand_child_of_rs1
->render_target());
915 EXPECT_EQ(render_surface2
.get(), render_surface2
->render_target());
916 EXPECT_EQ(render_surface2
.get(), child_of_rs2
->render_target());
917 EXPECT_EQ(render_surface2
.get(), grand_child_of_rs2
->render_target());
919 // Verify layer draw transforms note that draw transforms are described with
920 // respect to the nearest ancestor render surface but screen space transforms
921 // are described with respect to the root.
922 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->draw_transform());
923 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
, child_of_root
->draw_transform());
924 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
925 grand_child_of_root
->draw_transform());
927 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
, render_surface1
->draw_transform());
928 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
, child_of_rs1
->draw_transform());
929 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
* A
,
930 grand_child_of_rs1
->draw_transform());
932 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
, render_surface2
->draw_transform());
933 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
, child_of_rs2
->draw_transform());
934 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
* A
,
935 grand_child_of_rs2
->draw_transform());
937 // Verify layer screen-space transforms
939 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->screen_space_transform());
940 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
941 child_of_root
->screen_space_transform());
942 EXPECT_TRANSFORMATION_MATRIX_EQ(
943 A
* A
* A
, grand_child_of_root
->screen_space_transform());
945 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
946 render_surface1
->screen_space_transform());
947 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
948 child_of_rs1
->screen_space_transform());
949 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
950 grand_child_of_rs1
->screen_space_transform());
952 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
953 render_surface2
->screen_space_transform());
954 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
955 child_of_rs2
->screen_space_transform());
956 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
* A
,
957 grand_child_of_rs2
->screen_space_transform());
959 // Verify render surface transforms.
961 // Draw transform of render surface 1 is described with respect to root.
962 EXPECT_TRANSFORMATION_MATRIX_EQ(
963 A
* A
* S1
, render_surface1
->render_surface()->draw_transform());
964 EXPECT_TRANSFORMATION_MATRIX_EQ(
965 A
* R
* S1
, render_surface1
->render_surface()->replica_draw_transform());
966 EXPECT_TRANSFORMATION_MATRIX_EQ(
967 A
* A
* S1
, render_surface1
->render_surface()->screen_space_transform());
968 EXPECT_TRANSFORMATION_MATRIX_EQ(
970 render_surface1
->render_surface()->replica_screen_space_transform());
971 // Draw transform of render surface 2 is described with respect to render
973 EXPECT_TRANSFORMATION_MATRIX_EQ(
974 SS1
* A
* S2
, render_surface2
->render_surface()->draw_transform());
975 EXPECT_TRANSFORMATION_MATRIX_EQ(
977 render_surface2
->render_surface()->replica_draw_transform());
978 EXPECT_TRANSFORMATION_MATRIX_EQ(
980 render_surface2
->render_surface()->screen_space_transform());
981 EXPECT_TRANSFORMATION_MATRIX_EQ(
983 render_surface2
->render_surface()->replica_screen_space_transform());
985 // Sanity check. If these fail there is probably a bug in the test itself. It
986 // is expected that we correctly set up transforms so that the y-component of
987 // the screen-space transform encodes the "depth" of the layer in the tree.
988 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
990 child_of_root
->screen_space_transform().matrix().get(1, 3));
992 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
995 render_surface1
->screen_space_transform().matrix().get(1, 3));
997 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
999 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
1001 EXPECT_FLOAT_EQ(3.0,
1002 render_surface2
->screen_space_transform().matrix().get(1, 3));
1003 EXPECT_FLOAT_EQ(4.0,
1004 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
1006 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
1009 TEST_F(LayerTreeHostCommonTest
, TransformsForFlatteningLayer
) {
1010 // For layers that flatten their subtree, there should be an orthographic
1011 // projection (for x and y values) in the middle of the transform sequence.
1012 // Note that the way the code is currently implemented, it is not expected to
1013 // use a canonical orthographic projection.
1015 scoped_refptr
<Layer
> root
= Layer::Create();
1016 scoped_refptr
<Layer
> child
= Layer::Create();
1017 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1018 make_scoped_refptr(new LayerWithForcedDrawsContent());
1020 gfx::Transform rotation_about_y_axis
;
1021 rotation_about_y_axis
.RotateAboutYAxis(30.0);
1023 const gfx::Transform identity_matrix
;
1024 SetLayerPropertiesForTesting(root
.get(),
1028 gfx::Size(100, 100),
1031 SetLayerPropertiesForTesting(child
.get(),
1032 rotation_about_y_axis
,
1038 SetLayerPropertiesForTesting(grand_child
.get(),
1039 rotation_about_y_axis
,
1046 root
->AddChild(child
);
1047 child
->AddChild(grand_child
);
1048 child
->SetForceRenderSurface(true);
1050 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1051 host
->SetRootLayer(root
);
1053 // No layers in this test should preserve 3d.
1054 ASSERT_TRUE(root
->should_flatten_transform());
1055 ASSERT_TRUE(child
->should_flatten_transform());
1056 ASSERT_TRUE(grand_child
->should_flatten_transform());
1058 gfx::Transform expected_child_draw_transform
= rotation_about_y_axis
;
1059 gfx::Transform expected_child_screen_space_transform
= rotation_about_y_axis
;
1060 gfx::Transform expected_grand_child_draw_transform
=
1061 rotation_about_y_axis
; // draws onto child's render surface
1062 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
1063 flattened_rotation_about_y
.FlattenTo2d();
1064 gfx::Transform expected_grand_child_screen_space_transform
=
1065 flattened_rotation_about_y
* rotation_about_y_axis
;
1067 ExecuteCalculateDrawProperties(root
.get());
1069 // The child's draw transform should have been taken by its surface.
1070 ASSERT_TRUE(child
->render_surface());
1071 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform
,
1072 child
->render_surface()->draw_transform());
1073 EXPECT_TRANSFORMATION_MATRIX_EQ(
1074 expected_child_screen_space_transform
,
1075 child
->render_surface()->screen_space_transform());
1076 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1077 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform
,
1078 child
->screen_space_transform());
1079 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform
,
1080 grand_child
->draw_transform());
1081 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform
,
1082 grand_child
->screen_space_transform());
1085 TEST_F(LayerTreeHostCommonTest
, TransformsForDegenerateIntermediateLayer
) {
1086 // A layer that is empty in one axis, but not the other, was accidentally
1087 // skipping a necessary translation. Without that translation, the coordinate
1088 // space of the layer's draw transform is incorrect.
1090 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1091 // but if that layer becomes a render surface, then its draw transform is
1092 // implicitly inherited by the rest of the subtree, which then is positioned
1093 // incorrectly as a result.
1095 scoped_refptr
<Layer
> root
= Layer::Create();
1096 scoped_refptr
<Layer
> child
= Layer::Create();
1097 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1098 make_scoped_refptr(new LayerWithForcedDrawsContent());
1100 // The child height is zero, but has non-zero width that should be accounted
1101 // for while computing draw transforms.
1102 const gfx::Transform identity_matrix
;
1103 SetLayerPropertiesForTesting(root
.get(),
1107 gfx::Size(100, 100),
1110 SetLayerPropertiesForTesting(child
.get(),
1117 SetLayerPropertiesForTesting(grand_child
.get(),
1125 root
->AddChild(child
);
1126 child
->AddChild(grand_child
);
1127 child
->SetForceRenderSurface(true);
1129 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1130 host
->SetRootLayer(root
);
1132 ExecuteCalculateDrawProperties(root
.get());
1134 ASSERT_TRUE(child
->render_surface());
1135 // This is the real test, the rest are sanity checks.
1136 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1137 child
->render_surface()->draw_transform());
1138 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1139 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1140 grand_child
->draw_transform());
1143 TEST_F(LayerTreeHostCommonTest
, TransformAboveRootLayer
) {
1144 // Transformations applied at the root of the tree should be forwarded
1145 // to child layers instead of applied to the root RenderSurface.
1146 const gfx::Transform identity_matrix
;
1147 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
1148 new LayerWithForcedDrawsContent
;
1149 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1150 new LayerWithForcedDrawsContent
;
1151 child
->SetScrollClipLayerId(root
->id());
1152 root
->AddChild(child
);
1154 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1155 host
->SetRootLayer(root
);
1157 SetLayerPropertiesForTesting(root
.get(),
1164 SetLayerPropertiesForTesting(child
.get(),
1172 gfx::Transform translate
;
1173 translate
.Translate(50, 50);
1175 RenderSurfaceLayerList render_surface_layer_list
;
1176 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1177 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1178 inputs
.can_adjust_raster_scales
= true;
1179 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1180 EXPECT_EQ(translate
, root
->draw_properties().target_space_transform
);
1181 EXPECT_EQ(translate
, child
->draw_properties().target_space_transform
);
1182 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1183 EXPECT_EQ(1.f
, root
->draw_properties().device_scale_factor
);
1184 EXPECT_EQ(1.f
, child
->draw_properties().device_scale_factor
);
1187 gfx::Transform scale
;
1190 RenderSurfaceLayerList render_surface_layer_list
;
1191 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1192 root
.get(), root
->bounds(), scale
, &render_surface_layer_list
);
1193 inputs
.can_adjust_raster_scales
= true;
1194 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1195 EXPECT_EQ(scale
, root
->draw_properties().target_space_transform
);
1196 EXPECT_EQ(scale
, child
->draw_properties().target_space_transform
);
1197 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1198 EXPECT_EQ(2.f
, root
->draw_properties().device_scale_factor
);
1199 EXPECT_EQ(2.f
, child
->draw_properties().device_scale_factor
);
1202 gfx::Transform rotate
;
1205 RenderSurfaceLayerList render_surface_layer_list
;
1206 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1207 root
.get(), root
->bounds(), rotate
, &render_surface_layer_list
);
1208 inputs
.can_adjust_raster_scales
= true;
1209 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1210 EXPECT_EQ(rotate
, root
->draw_properties().target_space_transform
);
1211 EXPECT_EQ(rotate
, child
->draw_properties().target_space_transform
);
1212 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1213 EXPECT_EQ(1.f
, root
->draw_properties().device_scale_factor
);
1214 EXPECT_EQ(1.f
, child
->draw_properties().device_scale_factor
);
1217 gfx::Transform composite
;
1218 composite
.ConcatTransform(translate
);
1219 composite
.ConcatTransform(scale
);
1220 composite
.ConcatTransform(rotate
);
1222 RenderSurfaceLayerList render_surface_layer_list
;
1223 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1224 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1225 inputs
.can_adjust_raster_scales
= true;
1226 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1227 EXPECT_EQ(composite
, root
->draw_properties().target_space_transform
);
1228 EXPECT_EQ(composite
, child
->draw_properties().target_space_transform
);
1229 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1232 // Verify it composes correctly with device scale.
1233 float device_scale_factor
= 1.5f
;
1236 RenderSurfaceLayerList render_surface_layer_list
;
1237 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1238 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1239 inputs
.device_scale_factor
= device_scale_factor
;
1240 inputs
.can_adjust_raster_scales
= true;
1241 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1242 gfx::Transform device_scaled_translate
= translate
;
1243 device_scaled_translate
.Scale(device_scale_factor
, device_scale_factor
);
1244 EXPECT_EQ(device_scaled_translate
,
1245 root
->draw_properties().target_space_transform
);
1246 EXPECT_EQ(device_scaled_translate
,
1247 child
->draw_properties().target_space_transform
);
1248 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1249 EXPECT_EQ(device_scale_factor
, root
->draw_properties().device_scale_factor
);
1250 EXPECT_EQ(device_scale_factor
,
1251 child
->draw_properties().device_scale_factor
);
1254 // Verify it composes correctly with page scale.
1255 float page_scale_factor
= 2.f
;
1258 RenderSurfaceLayerList render_surface_layer_list
;
1259 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1260 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1261 inputs
.page_scale_factor
= page_scale_factor
;
1262 inputs
.page_scale_application_layer
= root
.get();
1263 inputs
.can_adjust_raster_scales
= true;
1264 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1265 gfx::Transform page_scaled_translate
= translate
;
1266 page_scaled_translate
.Scale(page_scale_factor
, page_scale_factor
);
1267 EXPECT_EQ(translate
, root
->draw_properties().target_space_transform
);
1268 EXPECT_EQ(page_scaled_translate
,
1269 child
->draw_properties().target_space_transform
);
1270 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1271 EXPECT_EQ(1.f
, root
->draw_properties().device_scale_factor
);
1272 EXPECT_EQ(1.f
, child
->draw_properties().device_scale_factor
);
1275 // Verify that it composes correctly with transforms directly on root layer.
1276 root
->SetTransform(composite
);
1279 RenderSurfaceLayerList render_surface_layer_list
;
1280 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1281 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1282 inputs
.can_adjust_raster_scales
= true;
1283 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1284 gfx::Transform compositeSquared
= composite
;
1285 compositeSquared
.ConcatTransform(composite
);
1286 EXPECT_TRANSFORMATION_MATRIX_EQ(
1287 compositeSquared
, root
->draw_properties().target_space_transform
);
1288 EXPECT_TRANSFORMATION_MATRIX_EQ(
1289 compositeSquared
, child
->draw_properties().target_space_transform
);
1290 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1294 TEST_F(LayerTreeHostCommonTest
,
1295 RenderSurfaceListForRenderSurfaceWithClippedLayer
) {
1296 scoped_refptr
<Layer
> parent
= Layer::Create();
1297 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
1298 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1299 make_scoped_refptr(new LayerWithForcedDrawsContent());
1301 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1302 host
->SetRootLayer(parent
);
1304 const gfx::Transform identity_matrix
;
1305 SetLayerPropertiesForTesting(parent
.get(),
1312 SetLayerPropertiesForTesting(render_surface1
.get(),
1319 SetLayerPropertiesForTesting(child
.get(),
1322 gfx::PointF(30.f
, 30.f
),
1327 parent
->AddChild(render_surface1
);
1328 parent
->SetMasksToBounds(true);
1329 render_surface1
->AddChild(child
);
1330 render_surface1
->SetForceRenderSurface(true);
1332 RenderSurfaceLayerList render_surface_layer_list
;
1333 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1337 &render_surface_layer_list
);
1338 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1340 // The child layer's content is entirely outside the parent's clip rect, so
1341 // the intermediate render surface should not be listed here, even if it was
1342 // forced to be created. Render surfaces without children or visible content
1343 // are unexpected at draw time (e.g. we might try to create a content texture
1345 ASSERT_TRUE(parent
->render_surface());
1346 EXPECT_EQ(1U, render_surface_layer_list
.size());
1349 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceListForTransparentChild
) {
1350 scoped_refptr
<Layer
> parent
= Layer::Create();
1351 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
1352 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1353 make_scoped_refptr(new LayerWithForcedDrawsContent());
1355 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1356 host
->SetRootLayer(parent
);
1358 const gfx::Transform identity_matrix
;
1359 SetLayerPropertiesForTesting(render_surface1
.get(),
1366 SetLayerPropertiesForTesting(child
.get(),
1374 parent
->AddChild(render_surface1
);
1375 render_surface1
->AddChild(child
);
1376 render_surface1
->SetForceRenderSurface(true);
1377 render_surface1
->SetOpacity(0.f
);
1379 RenderSurfaceLayerList render_surface_layer_list
;
1380 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1381 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1382 inputs
.can_adjust_raster_scales
= true;
1383 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1385 // Since the layer is transparent, render_surface1->render_surface() should
1386 // not have gotten added anywhere. Also, the drawable content rect should not
1387 // have been extended by the children.
1388 ASSERT_TRUE(parent
->render_surface());
1389 EXPECT_EQ(0U, parent
->render_surface()->layer_list().size());
1390 EXPECT_EQ(1U, render_surface_layer_list
.size());
1391 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1392 EXPECT_EQ(gfx::Rect(), parent
->drawable_content_rect());
1395 TEST_F(LayerTreeHostCommonTest
, ForceRenderSurface
) {
1396 scoped_refptr
<Layer
> parent
= Layer::Create();
1397 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
1398 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1399 make_scoped_refptr(new LayerWithForcedDrawsContent());
1400 render_surface1
->SetForceRenderSurface(true);
1402 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1403 host
->SetRootLayer(parent
);
1405 const gfx::Transform identity_matrix
;
1406 SetLayerPropertiesForTesting(parent
.get(),
1413 SetLayerPropertiesForTesting(render_surface1
.get(),
1420 SetLayerPropertiesForTesting(child
.get(),
1428 parent
->AddChild(render_surface1
);
1429 render_surface1
->AddChild(child
);
1431 // Sanity check before the actual test
1432 EXPECT_FALSE(parent
->render_surface());
1433 EXPECT_FALSE(render_surface1
->render_surface());
1436 RenderSurfaceLayerList render_surface_layer_list
;
1437 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1438 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1439 inputs
.can_adjust_raster_scales
= true;
1440 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1442 // The root layer always creates a render surface
1443 EXPECT_TRUE(parent
->render_surface());
1444 EXPECT_TRUE(render_surface1
->render_surface());
1445 EXPECT_EQ(2U, render_surface_layer_list
.size());
1449 RenderSurfaceLayerList render_surface_layer_list
;
1450 render_surface1
->SetForceRenderSurface(false);
1451 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1452 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1453 inputs
.can_adjust_raster_scales
= true;
1454 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1455 EXPECT_TRUE(parent
->render_surface());
1456 EXPECT_FALSE(render_surface1
->render_surface());
1457 EXPECT_EQ(1U, render_surface_layer_list
.size());
1461 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsRenderSurfaces
) {
1462 // The entire subtree of layers that are outside the clip rect should be
1463 // culled away, and should not affect the render_surface_layer_list.
1465 // The test tree is set up as follows:
1466 // - all layers except the leaf_nodes are forced to be a new render surface
1467 // that have something to draw.
1468 // - parent is a large container layer.
1469 // - child has masksToBounds=true to cause clipping.
1470 // - grand_child is positioned outside of the child's bounds
1471 // - great_grand_child is also kept outside child's bounds.
1473 // In this configuration, grand_child and great_grand_child are completely
1474 // outside the clip rect, and they should never get scheduled on the list of
1478 const gfx::Transform identity_matrix
;
1479 scoped_refptr
<Layer
> parent
= Layer::Create();
1480 scoped_refptr
<Layer
> child
= Layer::Create();
1481 scoped_refptr
<Layer
> grand_child
= Layer::Create();
1482 scoped_refptr
<Layer
> great_grand_child
= Layer::Create();
1483 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1484 make_scoped_refptr(new LayerWithForcedDrawsContent());
1485 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1486 make_scoped_refptr(new LayerWithForcedDrawsContent());
1487 parent
->AddChild(child
);
1488 child
->AddChild(grand_child
);
1489 grand_child
->AddChild(great_grand_child
);
1491 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1492 host
->SetRootLayer(parent
);
1494 // leaf_node1 ensures that parent and child are kept on the
1495 // render_surface_layer_list, even though grand_child and great_grand_child
1496 // should be clipped.
1497 child
->AddChild(leaf_node1
);
1498 great_grand_child
->AddChild(leaf_node2
);
1500 SetLayerPropertiesForTesting(parent
.get(),
1504 gfx::Size(500, 500),
1507 SetLayerPropertiesForTesting(child
.get(),
1514 SetLayerPropertiesForTesting(grand_child
.get(),
1517 gfx::PointF(45.f
, 45.f
),
1521 SetLayerPropertiesForTesting(great_grand_child
.get(),
1528 SetLayerPropertiesForTesting(leaf_node1
.get(),
1532 gfx::Size(500, 500),
1535 SetLayerPropertiesForTesting(leaf_node2
.get(),
1543 child
->SetMasksToBounds(true);
1544 child
->SetOpacity(0.4f
);
1545 child
->SetForceRenderSurface(true);
1546 grand_child
->SetOpacity(0.5f
);
1547 great_grand_child
->SetOpacity(0.4f
);
1549 RenderSurfaceLayerList render_surface_layer_list
;
1550 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1551 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1552 inputs
.can_adjust_raster_scales
= true;
1553 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1555 ASSERT_EQ(2U, render_surface_layer_list
.size());
1556 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1557 EXPECT_EQ(child
->id(), render_surface_layer_list
.at(1)->id());
1560 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsSurfaceWithoutVisibleContent
) {
1561 // When a render surface has a clip rect, it is used to clip the content rect
1562 // of the surface. When the render surface is animating its transforms, then
1563 // the content rect's position in the clip rect is not defined on the main
1564 // thread, and its content rect should not be clipped.
1566 // The test tree is set up as follows:
1567 // - parent is a container layer that masksToBounds=true to cause clipping.
1568 // - child is a render surface, which has a clip rect set to the bounds of
1570 // - grand_child is a render surface, and the only visible content in child.
1571 // It is positioned outside of the clip rect from parent.
1573 // In this configuration, grand_child should be outside the clipped
1574 // content rect of the child, making grand_child not appear in the
1575 // render_surface_layer_list. However, when we place an animation on the
1576 // child, this clipping should be avoided and we should keep the grand_child
1577 // in the render_surface_layer_list.
1579 const gfx::Transform identity_matrix
;
1580 scoped_refptr
<Layer
> parent
= Layer::Create();
1581 scoped_refptr
<Layer
> child
= Layer::Create();
1582 scoped_refptr
<Layer
> grand_child
= Layer::Create();
1583 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node
=
1584 make_scoped_refptr(new LayerWithForcedDrawsContent());
1585 parent
->AddChild(child
);
1586 child
->AddChild(grand_child
);
1587 grand_child
->AddChild(leaf_node
);
1589 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1590 host
->SetRootLayer(parent
);
1592 SetLayerPropertiesForTesting(parent
.get(),
1596 gfx::Size(100, 100),
1599 SetLayerPropertiesForTesting(child
.get(),
1606 SetLayerPropertiesForTesting(grand_child
.get(),
1609 gfx::PointF(200.f
, 200.f
),
1613 SetLayerPropertiesForTesting(leaf_node
.get(),
1621 parent
->SetMasksToBounds(true);
1622 child
->SetOpacity(0.4f
);
1623 child
->SetForceRenderSurface(true);
1624 grand_child
->SetOpacity(0.4f
);
1625 grand_child
->SetForceRenderSurface(true);
1628 RenderSurfaceLayerList render_surface_layer_list
;
1629 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1630 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1631 inputs
.can_adjust_raster_scales
= true;
1632 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1634 // Without an animation, we should cull child and grand_child from the
1635 // render_surface_layer_list.
1636 ASSERT_EQ(1U, render_surface_layer_list
.size());
1637 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1640 // Now put an animating transform on child.
1641 AddAnimatedTransformToController(
1642 child
->layer_animation_controller(), 10.0, 30, 0);
1645 RenderSurfaceLayerList render_surface_layer_list
;
1646 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1647 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1648 inputs
.can_adjust_raster_scales
= true;
1649 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1651 // With an animating transform, we should keep child and grand_child in the
1652 // render_surface_layer_list.
1653 ASSERT_EQ(3U, render_surface_layer_list
.size());
1654 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1655 EXPECT_EQ(child
->id(), render_surface_layer_list
.at(1)->id());
1656 EXPECT_EQ(grand_child
->id(), render_surface_layer_list
.at(2)->id());
1660 TEST_F(LayerTreeHostCommonTest
, IsClippedIsSetCorrectly
) {
1661 // Layer's IsClipped() property is set to true when:
1662 // - the layer clips its subtree, e.g. masks to bounds,
1663 // - the layer is clipped by an ancestor that contributes to the same
1665 // - a surface is clipped by an ancestor that contributes to the same
1668 // In particular, for a layer that owns a render surface:
1669 // - the render surface inherits any clip from ancestors, and does NOT
1670 // pass that clipped status to the layer itself.
1671 // - but if the layer itself masks to bounds, it is considered clipped
1672 // and propagates the clip to the subtree.
1674 const gfx::Transform identity_matrix
;
1675 scoped_refptr
<Layer
> root
= Layer::Create();
1676 scoped_refptr
<Layer
> parent
= Layer::Create();
1677 scoped_refptr
<Layer
> child1
= Layer::Create();
1678 scoped_refptr
<Layer
> child2
= Layer::Create();
1679 scoped_refptr
<Layer
> grand_child
= Layer::Create();
1680 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1681 make_scoped_refptr(new LayerWithForcedDrawsContent());
1682 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1683 make_scoped_refptr(new LayerWithForcedDrawsContent());
1684 root
->AddChild(parent
);
1685 parent
->AddChild(child1
);
1686 parent
->AddChild(child2
);
1687 child1
->AddChild(grand_child
);
1688 child2
->AddChild(leaf_node2
);
1689 grand_child
->AddChild(leaf_node1
);
1691 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1692 host
->SetRootLayer(root
);
1694 child2
->SetForceRenderSurface(true);
1696 SetLayerPropertiesForTesting(root
.get(),
1700 gfx::Size(100, 100),
1703 SetLayerPropertiesForTesting(parent
.get(),
1707 gfx::Size(100, 100),
1710 SetLayerPropertiesForTesting(child1
.get(),
1714 gfx::Size(100, 100),
1717 SetLayerPropertiesForTesting(child2
.get(),
1721 gfx::Size(100, 100),
1724 SetLayerPropertiesForTesting(grand_child
.get(),
1728 gfx::Size(100, 100),
1731 SetLayerPropertiesForTesting(leaf_node1
.get(),
1735 gfx::Size(100, 100),
1738 SetLayerPropertiesForTesting(leaf_node2
.get(),
1742 gfx::Size(100, 100),
1746 // Case 1: nothing is clipped except the root render surface.
1748 RenderSurfaceLayerList render_surface_layer_list
;
1749 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1750 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1751 inputs
.can_adjust_raster_scales
= true;
1752 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1754 ASSERT_TRUE(root
->render_surface());
1755 ASSERT_TRUE(child2
->render_surface());
1757 EXPECT_FALSE(root
->is_clipped());
1758 EXPECT_TRUE(root
->render_surface()->is_clipped());
1759 EXPECT_FALSE(parent
->is_clipped());
1760 EXPECT_FALSE(child1
->is_clipped());
1761 EXPECT_FALSE(child2
->is_clipped());
1762 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1763 EXPECT_FALSE(grand_child
->is_clipped());
1764 EXPECT_FALSE(leaf_node1
->is_clipped());
1765 EXPECT_FALSE(leaf_node2
->is_clipped());
1768 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1769 // surface are clipped. But layers that contribute to child2's surface are
1770 // not clipped explicitly because child2's surface already accounts for
1773 RenderSurfaceLayerList render_surface_layer_list
;
1774 parent
->SetMasksToBounds(true);
1775 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1776 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1777 inputs
.can_adjust_raster_scales
= true;
1778 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1780 ASSERT_TRUE(root
->render_surface());
1781 ASSERT_TRUE(child2
->render_surface());
1783 EXPECT_FALSE(root
->is_clipped());
1784 EXPECT_TRUE(root
->render_surface()->is_clipped());
1785 EXPECT_TRUE(parent
->is_clipped());
1786 EXPECT_TRUE(child1
->is_clipped());
1787 EXPECT_FALSE(child2
->is_clipped());
1788 EXPECT_TRUE(child2
->render_surface()->is_clipped());
1789 EXPECT_TRUE(grand_child
->is_clipped());
1790 EXPECT_TRUE(leaf_node1
->is_clipped());
1791 EXPECT_FALSE(leaf_node2
->is_clipped());
1794 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1795 // child2's render surface is not clipped.
1797 RenderSurfaceLayerList render_surface_layer_list
;
1798 parent
->SetMasksToBounds(false);
1799 child2
->SetMasksToBounds(true);
1800 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1801 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1802 inputs
.can_adjust_raster_scales
= true;
1803 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1805 ASSERT_TRUE(root
->render_surface());
1806 ASSERT_TRUE(child2
->render_surface());
1808 EXPECT_FALSE(root
->is_clipped());
1809 EXPECT_TRUE(root
->render_surface()->is_clipped());
1810 EXPECT_FALSE(parent
->is_clipped());
1811 EXPECT_FALSE(child1
->is_clipped());
1812 EXPECT_TRUE(child2
->is_clipped());
1813 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1814 EXPECT_FALSE(grand_child
->is_clipped());
1815 EXPECT_FALSE(leaf_node1
->is_clipped());
1816 EXPECT_TRUE(leaf_node2
->is_clipped());
1820 TEST_F(LayerTreeHostCommonTest
, DrawableContentRectForLayers
) {
1821 // Verify that layers get the appropriate DrawableContentRect when their
1822 // parent masksToBounds is true.
1824 // grand_child1 - completely inside the region; DrawableContentRect should
1825 // be the layer rect expressed in target space.
1826 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1827 // will be the intersection of layer bounds and the mask region.
1828 // grand_child3 - partially clipped and masksToBounds; the
1829 // DrawableContentRect will still be the intersection of layer bounds and
1831 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1835 const gfx::Transform identity_matrix
;
1836 scoped_refptr
<Layer
> parent
= Layer::Create();
1837 scoped_refptr
<Layer
> child
= Layer::Create();
1838 scoped_refptr
<Layer
> grand_child1
= Layer::Create();
1839 scoped_refptr
<Layer
> grand_child2
= Layer::Create();
1840 scoped_refptr
<Layer
> grand_child3
= Layer::Create();
1841 scoped_refptr
<Layer
> grand_child4
= Layer::Create();
1843 parent
->AddChild(child
);
1844 child
->AddChild(grand_child1
);
1845 child
->AddChild(grand_child2
);
1846 child
->AddChild(grand_child3
);
1847 child
->AddChild(grand_child4
);
1849 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1850 host
->SetRootLayer(parent
);
1852 SetLayerPropertiesForTesting(parent
.get(),
1856 gfx::Size(500, 500),
1859 SetLayerPropertiesForTesting(child
.get(),
1866 SetLayerPropertiesForTesting(grand_child1
.get(),
1869 gfx::PointF(5.f
, 5.f
),
1873 SetLayerPropertiesForTesting(grand_child2
.get(),
1876 gfx::PointF(15.f
, 15.f
),
1880 SetLayerPropertiesForTesting(grand_child3
.get(),
1883 gfx::PointF(15.f
, 15.f
),
1887 SetLayerPropertiesForTesting(grand_child4
.get(),
1890 gfx::PointF(45.f
, 45.f
),
1895 child
->SetMasksToBounds(true);
1896 grand_child3
->SetMasksToBounds(true);
1898 // Force everyone to be a render surface.
1899 child
->SetOpacity(0.4f
);
1900 grand_child1
->SetOpacity(0.5f
);
1901 grand_child2
->SetOpacity(0.5f
);
1902 grand_child3
->SetOpacity(0.5f
);
1903 grand_child4
->SetOpacity(0.5f
);
1905 RenderSurfaceLayerList render_surface_layer_list
;
1906 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1907 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1908 inputs
.can_adjust_raster_scales
= true;
1909 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1911 EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10),
1912 grand_child1
->drawable_content_rect());
1913 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
1914 grand_child3
->drawable_content_rect());
1915 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
1916 grand_child3
->drawable_content_rect());
1917 EXPECT_TRUE(grand_child4
->drawable_content_rect().IsEmpty());
1920 TEST_F(LayerTreeHostCommonTest
, ClipRectIsPropagatedCorrectlyToSurfaces
) {
1921 // Verify that render surfaces (and their layers) get the appropriate
1922 // clip rects when their parent masksToBounds is true.
1924 // Layers that own render surfaces (at least for now) do not inherit any
1925 // clipping; instead the surface will enforce the clip for the entire subtree.
1926 // They may still have a clip rect of their own layer bounds, however, if
1927 // masksToBounds was true.
1928 const gfx::Transform identity_matrix
;
1929 scoped_refptr
<Layer
> parent
= Layer::Create();
1930 scoped_refptr
<Layer
> child
= Layer::Create();
1931 scoped_refptr
<Layer
> grand_child1
= Layer::Create();
1932 scoped_refptr
<Layer
> grand_child2
= Layer::Create();
1933 scoped_refptr
<Layer
> grand_child3
= Layer::Create();
1934 scoped_refptr
<Layer
> grand_child4
= Layer::Create();
1935 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1936 make_scoped_refptr(new LayerWithForcedDrawsContent());
1937 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1938 make_scoped_refptr(new LayerWithForcedDrawsContent());
1939 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node3
=
1940 make_scoped_refptr(new LayerWithForcedDrawsContent());
1941 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node4
=
1942 make_scoped_refptr(new LayerWithForcedDrawsContent());
1944 parent
->AddChild(child
);
1945 child
->AddChild(grand_child1
);
1946 child
->AddChild(grand_child2
);
1947 child
->AddChild(grand_child3
);
1948 child
->AddChild(grand_child4
);
1950 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1951 host
->SetRootLayer(parent
);
1953 // the leaf nodes ensure that these grand_children become render surfaces for
1955 grand_child1
->AddChild(leaf_node1
);
1956 grand_child2
->AddChild(leaf_node2
);
1957 grand_child3
->AddChild(leaf_node3
);
1958 grand_child4
->AddChild(leaf_node4
);
1960 SetLayerPropertiesForTesting(parent
.get(),
1964 gfx::Size(500, 500),
1967 SetLayerPropertiesForTesting(child
.get(),
1974 SetLayerPropertiesForTesting(grand_child1
.get(),
1977 gfx::PointF(5.f
, 5.f
),
1981 SetLayerPropertiesForTesting(grand_child2
.get(),
1984 gfx::PointF(15.f
, 15.f
),
1988 SetLayerPropertiesForTesting(grand_child3
.get(),
1991 gfx::PointF(15.f
, 15.f
),
1995 SetLayerPropertiesForTesting(grand_child4
.get(),
1998 gfx::PointF(45.f
, 45.f
),
2002 SetLayerPropertiesForTesting(leaf_node1
.get(),
2009 SetLayerPropertiesForTesting(leaf_node2
.get(),
2016 SetLayerPropertiesForTesting(leaf_node3
.get(),
2023 SetLayerPropertiesForTesting(leaf_node4
.get(),
2031 child
->SetMasksToBounds(true);
2032 grand_child3
->SetMasksToBounds(true);
2033 grand_child4
->SetMasksToBounds(true);
2035 // Force everyone to be a render surface.
2036 child
->SetOpacity(0.4f
);
2037 child
->SetForceRenderSurface(true);
2038 grand_child1
->SetOpacity(0.5f
);
2039 grand_child1
->SetForceRenderSurface(true);
2040 grand_child2
->SetOpacity(0.5f
);
2041 grand_child2
->SetForceRenderSurface(true);
2042 grand_child3
->SetOpacity(0.5f
);
2043 grand_child3
->SetForceRenderSurface(true);
2044 grand_child4
->SetOpacity(0.5f
);
2045 grand_child4
->SetForceRenderSurface(true);
2047 RenderSurfaceLayerList render_surface_layer_list
;
2048 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
2049 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
2050 inputs
.can_adjust_raster_scales
= true;
2051 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
2052 ASSERT_TRUE(grand_child1
->render_surface());
2053 ASSERT_TRUE(grand_child2
->render_surface());
2054 ASSERT_TRUE(grand_child3
->render_surface());
2056 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2058 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
2059 grand_child1
->render_surface()->clip_rect());
2060 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
2061 grand_child2
->render_surface()->clip_rect());
2062 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
2063 grand_child3
->render_surface()->clip_rect());
2066 TEST_F(LayerTreeHostCommonTest
, AnimationsForRenderSurfaceHierarchy
) {
2067 scoped_refptr
<Layer
> parent
= Layer::Create();
2068 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
2069 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
2070 scoped_refptr
<Layer
> child_of_root
= Layer::Create();
2071 scoped_refptr
<Layer
> child_of_rs1
= Layer::Create();
2072 scoped_refptr
<Layer
> child_of_rs2
= Layer::Create();
2073 scoped_refptr
<Layer
> grand_child_of_root
= Layer::Create();
2074 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs1
=
2075 make_scoped_refptr(new LayerWithForcedDrawsContent());
2076 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs2
=
2077 make_scoped_refptr(new LayerWithForcedDrawsContent());
2078 parent
->AddChild(render_surface1
);
2079 parent
->AddChild(child_of_root
);
2080 render_surface1
->AddChild(child_of_rs1
);
2081 render_surface1
->AddChild(render_surface2
);
2082 render_surface2
->AddChild(child_of_rs2
);
2083 child_of_root
->AddChild(grand_child_of_root
);
2084 child_of_rs1
->AddChild(grand_child_of_rs1
);
2085 child_of_rs2
->AddChild(grand_child_of_rs2
);
2087 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2088 host
->SetRootLayer(parent
);
2090 // Make our render surfaces.
2091 render_surface1
->SetForceRenderSurface(true);
2092 render_surface2
->SetForceRenderSurface(true);
2094 gfx::Transform layer_transform
;
2095 layer_transform
.Translate(1.0, 1.0);
2097 SetLayerPropertiesForTesting(parent
.get(),
2099 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2100 gfx::PointF(2.5f
, 0.f
),
2104 SetLayerPropertiesForTesting(render_surface1
.get(),
2106 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2107 gfx::PointF(2.5f
, 0.f
),
2111 SetLayerPropertiesForTesting(render_surface2
.get(),
2113 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2114 gfx::PointF(2.5f
, 0.f
),
2118 SetLayerPropertiesForTesting(child_of_root
.get(),
2120 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2121 gfx::PointF(2.5f
, 0.f
),
2125 SetLayerPropertiesForTesting(child_of_rs1
.get(),
2127 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2128 gfx::PointF(2.5f
, 0.f
),
2132 SetLayerPropertiesForTesting(child_of_rs2
.get(),
2134 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2135 gfx::PointF(2.5f
, 0.f
),
2139 SetLayerPropertiesForTesting(grand_child_of_root
.get(),
2141 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2142 gfx::PointF(2.5f
, 0.f
),
2146 SetLayerPropertiesForTesting(grand_child_of_rs1
.get(),
2148 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2149 gfx::PointF(2.5f
, 0.f
),
2153 SetLayerPropertiesForTesting(grand_child_of_rs2
.get(),
2155 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2156 gfx::PointF(2.5f
, 0.f
),
2161 // Put an animated opacity on the render surface.
2162 AddOpacityTransitionToController(
2163 render_surface1
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2165 // Also put an animated opacity on a layer without descendants.
2166 AddOpacityTransitionToController(
2167 grand_child_of_root
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2169 // Put a transform animation on the render surface.
2170 AddAnimatedTransformToController(
2171 render_surface2
->layer_animation_controller(), 10.0, 30, 0);
2173 // Also put transform animations on grand_child_of_root, and
2174 // grand_child_of_rs2
2175 AddAnimatedTransformToController(
2176 grand_child_of_root
->layer_animation_controller(), 10.0, 30, 0);
2177 AddAnimatedTransformToController(
2178 grand_child_of_rs2
->layer_animation_controller(), 10.0, 30, 0);
2180 ExecuteCalculateDrawProperties(parent
.get());
2182 // Only layers that are associated with render surfaces should have an actual
2183 // RenderSurface() value.
2184 ASSERT_TRUE(parent
->render_surface());
2185 ASSERT_FALSE(child_of_root
->render_surface());
2186 ASSERT_FALSE(grand_child_of_root
->render_surface());
2188 ASSERT_TRUE(render_surface1
->render_surface());
2189 ASSERT_FALSE(child_of_rs1
->render_surface());
2190 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
2192 ASSERT_TRUE(render_surface2
->render_surface());
2193 ASSERT_FALSE(child_of_rs2
->render_surface());
2194 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
2196 // Verify all render target accessors
2197 EXPECT_EQ(parent
.get(), parent
->render_target());
2198 EXPECT_EQ(parent
.get(), child_of_root
->render_target());
2199 EXPECT_EQ(parent
.get(), grand_child_of_root
->render_target());
2201 EXPECT_EQ(render_surface1
.get(), render_surface1
->render_target());
2202 EXPECT_EQ(render_surface1
.get(), child_of_rs1
->render_target());
2203 EXPECT_EQ(render_surface1
.get(), grand_child_of_rs1
->render_target());
2205 EXPECT_EQ(render_surface2
.get(), render_surface2
->render_target());
2206 EXPECT_EQ(render_surface2
.get(), child_of_rs2
->render_target());
2207 EXPECT_EQ(render_surface2
.get(), grand_child_of_rs2
->render_target());
2209 // Verify draw_opacity_is_animating values
2210 EXPECT_FALSE(parent
->draw_opacity_is_animating());
2211 EXPECT_FALSE(child_of_root
->draw_opacity_is_animating());
2212 EXPECT_TRUE(grand_child_of_root
->draw_opacity_is_animating());
2213 EXPECT_FALSE(render_surface1
->draw_opacity_is_animating());
2214 EXPECT_TRUE(render_surface1
->render_surface()->draw_opacity_is_animating());
2215 EXPECT_FALSE(child_of_rs1
->draw_opacity_is_animating());
2216 EXPECT_FALSE(grand_child_of_rs1
->draw_opacity_is_animating());
2217 EXPECT_FALSE(render_surface2
->draw_opacity_is_animating());
2218 EXPECT_FALSE(render_surface2
->render_surface()->draw_opacity_is_animating());
2219 EXPECT_FALSE(child_of_rs2
->draw_opacity_is_animating());
2220 EXPECT_FALSE(grand_child_of_rs2
->draw_opacity_is_animating());
2222 // Verify draw_transform_is_animating values
2223 EXPECT_FALSE(parent
->draw_transform_is_animating());
2224 EXPECT_FALSE(child_of_root
->draw_transform_is_animating());
2225 EXPECT_TRUE(grand_child_of_root
->draw_transform_is_animating());
2226 EXPECT_FALSE(render_surface1
->draw_transform_is_animating());
2227 EXPECT_FALSE(render_surface1
->render_surface()
2228 ->target_surface_transforms_are_animating());
2229 EXPECT_FALSE(child_of_rs1
->draw_transform_is_animating());
2230 EXPECT_FALSE(grand_child_of_rs1
->draw_transform_is_animating());
2231 EXPECT_FALSE(render_surface2
->draw_transform_is_animating());
2232 EXPECT_TRUE(render_surface2
->render_surface()
2233 ->target_surface_transforms_are_animating());
2234 EXPECT_FALSE(child_of_rs2
->draw_transform_is_animating());
2235 EXPECT_TRUE(grand_child_of_rs2
->draw_transform_is_animating());
2237 // Verify screen_space_transform_is_animating values
2238 EXPECT_FALSE(parent
->screen_space_transform_is_animating());
2239 EXPECT_FALSE(child_of_root
->screen_space_transform_is_animating());
2240 EXPECT_TRUE(grand_child_of_root
->screen_space_transform_is_animating());
2241 EXPECT_FALSE(render_surface1
->screen_space_transform_is_animating());
2242 EXPECT_FALSE(render_surface1
->render_surface()
2243 ->screen_space_transforms_are_animating());
2244 EXPECT_FALSE(child_of_rs1
->screen_space_transform_is_animating());
2245 EXPECT_FALSE(grand_child_of_rs1
->screen_space_transform_is_animating());
2246 EXPECT_TRUE(render_surface2
->screen_space_transform_is_animating());
2247 EXPECT_TRUE(render_surface2
->render_surface()
2248 ->screen_space_transforms_are_animating());
2249 EXPECT_TRUE(child_of_rs2
->screen_space_transform_is_animating());
2250 EXPECT_TRUE(grand_child_of_rs2
->screen_space_transform_is_animating());
2252 // Sanity check. If these fail there is probably a bug in the test itself.
2253 // It is expected that we correctly set up transforms so that the y-component
2254 // of the screen-space transform encodes the "depth" of the layer in the tree.
2255 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
2256 EXPECT_FLOAT_EQ(2.0,
2257 child_of_root
->screen_space_transform().matrix().get(1, 3));
2259 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
2261 EXPECT_FLOAT_EQ(2.0,
2262 render_surface1
->screen_space_transform().matrix().get(1, 3));
2263 EXPECT_FLOAT_EQ(3.0,
2264 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2266 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2268 EXPECT_FLOAT_EQ(3.0,
2269 render_surface2
->screen_space_transform().matrix().get(1, 3));
2270 EXPECT_FLOAT_EQ(4.0,
2271 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2273 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2276 TEST_F(LayerTreeHostCommonTest
, VisibleRectForIdentityTransform
) {
2277 // Test the calculateVisibleRect() function works correctly for identity
2280 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2281 gfx::Transform layer_to_surface_transform
;
2283 // Case 1: Layer is contained within the surface.
2284 gfx::Rect layer_content_rect
= gfx::Rect(10, 10, 30, 30);
2285 gfx::Rect expected
= gfx::Rect(10, 10, 30, 30);
2286 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2287 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2288 EXPECT_RECT_EQ(expected
, actual
);
2290 // Case 2: Layer is outside the surface rect.
2291 layer_content_rect
= gfx::Rect(120, 120, 30, 30);
2292 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2293 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2294 EXPECT_TRUE(actual
.IsEmpty());
2296 // Case 3: Layer is partially overlapping the surface rect.
2297 layer_content_rect
= gfx::Rect(80, 80, 30, 30);
2298 expected
= gfx::Rect(80, 80, 20, 20);
2299 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2300 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2301 EXPECT_RECT_EQ(expected
, actual
);
2304 TEST_F(LayerTreeHostCommonTest
, VisibleRectForTranslations
) {
2305 // Test the calculateVisibleRect() function works correctly for scaling
2308 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2309 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2310 gfx::Transform layer_to_surface_transform
;
2312 // Case 1: Layer is contained within the surface.
2313 layer_to_surface_transform
.MakeIdentity();
2314 layer_to_surface_transform
.Translate(10.0, 10.0);
2315 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2316 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2317 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2318 EXPECT_RECT_EQ(expected
, actual
);
2320 // Case 2: Layer is outside the surface rect.
2321 layer_to_surface_transform
.MakeIdentity();
2322 layer_to_surface_transform
.Translate(120.0, 120.0);
2323 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2324 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2325 EXPECT_TRUE(actual
.IsEmpty());
2327 // Case 3: Layer is partially overlapping the surface rect.
2328 layer_to_surface_transform
.MakeIdentity();
2329 layer_to_surface_transform
.Translate(80.0, 80.0);
2330 expected
= gfx::Rect(0, 0, 20, 20);
2331 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2332 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2333 EXPECT_RECT_EQ(expected
, actual
);
2336 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor2DRotations
) {
2337 // Test the calculateVisibleRect() function works correctly for rotations
2338 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2339 // should return the g in the layer's space.
2341 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2342 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2343 gfx::Transform layer_to_surface_transform
;
2345 // Case 1: Layer is contained within the surface.
2346 layer_to_surface_transform
.MakeIdentity();
2347 layer_to_surface_transform
.Translate(50.0, 50.0);
2348 layer_to_surface_transform
.Rotate(45.0);
2349 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2350 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2351 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2352 EXPECT_RECT_EQ(expected
, actual
);
2354 // Case 2: Layer is outside the surface rect.
2355 layer_to_surface_transform
.MakeIdentity();
2356 layer_to_surface_transform
.Translate(-50.0, 0.0);
2357 layer_to_surface_transform
.Rotate(45.0);
2358 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2359 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2360 EXPECT_TRUE(actual
.IsEmpty());
2362 // Case 3: The layer is rotated about its top-left corner. In surface space,
2363 // the layer is oriented diagonally, with the left half outside of the render
2364 // surface. In this case, the g should still be the entire layer
2365 // (remember the g is computed in layer space); both the top-left
2366 // and bottom-right corners of the layer are still visible.
2367 layer_to_surface_transform
.MakeIdentity();
2368 layer_to_surface_transform
.Rotate(45.0);
2369 expected
= gfx::Rect(0, 0, 30, 30);
2370 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2371 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2372 EXPECT_RECT_EQ(expected
, actual
);
2374 // Case 4: The layer is rotated about its top-left corner, and translated
2375 // upwards. In surface space, the layer is oriented diagonally, with only the
2376 // top corner of the surface overlapping the layer. In layer space, the render
2377 // surface overlaps the right side of the layer. The g should be
2378 // the layer's right half.
2379 layer_to_surface_transform
.MakeIdentity();
2380 layer_to_surface_transform
.Translate(0.0, -sqrt(2.0) * 15.0);
2381 layer_to_surface_transform
.Rotate(45.0);
2382 expected
= gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
2383 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2384 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2385 EXPECT_RECT_EQ(expected
, actual
);
2388 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dOrthographicTransform
) {
2389 // Test that the calculateVisibleRect() function works correctly for 3d
2392 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2393 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2394 gfx::Transform layer_to_surface_transform
;
2396 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2397 // degrees, should be fully contained in the render surface.
2398 layer_to_surface_transform
.MakeIdentity();
2399 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2400 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2401 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2402 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2403 EXPECT_RECT_EQ(expected
, actual
);
2405 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2406 // degrees, but shifted to the side so only the right-half the layer would be
2407 // visible on the surface.
2408 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2409 SkMScalar half_width_of_rotated_layer
=
2410 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
2411 layer_to_surface_transform
.MakeIdentity();
2412 layer_to_surface_transform
.Translate(-half_width_of_rotated_layer
, 0.0);
2413 layer_to_surface_transform
.RotateAboutYAxis(45.0); // Rotates about the left
2414 // edge of the layer.
2415 expected
= gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
2416 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2417 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2418 EXPECT_RECT_EQ(expected
, actual
);
2421 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveTransform
) {
2422 // Test the calculateVisibleRect() function works correctly when the layer has
2423 // a perspective projection onto the target surface.
2425 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2426 gfx::Rect layer_content_rect
= gfx::Rect(-50, -50, 200, 200);
2427 gfx::Transform layer_to_surface_transform
;
2429 // Case 1: Even though the layer is twice as large as the surface, due to
2430 // perspective foreshortening, the layer will fit fully in the surface when
2431 // its translated more than the perspective amount.
2432 layer_to_surface_transform
.MakeIdentity();
2434 // The following sequence of transforms applies the perspective about the
2435 // center of the surface.
2436 layer_to_surface_transform
.Translate(50.0, 50.0);
2437 layer_to_surface_transform
.ApplyPerspectiveDepth(9.0);
2438 layer_to_surface_transform
.Translate(-50.0, -50.0);
2440 // This translate places the layer in front of the surface's projection plane.
2441 layer_to_surface_transform
.Translate3d(0.0, 0.0, -27.0);
2443 gfx::Rect expected
= gfx::Rect(-50, -50, 200, 200);
2444 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2445 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2446 EXPECT_RECT_EQ(expected
, actual
);
2448 // Case 2: same projection as before, except that the layer is also translated
2449 // to the side, so that only the right half of the layer should be visible.
2451 // Explanation of expected result: The perspective ratio is (z distance
2452 // between layer and camera origin) / (z distance between projection plane and
2453 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2454 // move a layer by translating -50 units in projected surface units (so that
2455 // only half of it is visible), then we would need to translate by (-36 / 9) *
2456 // -50 == -200 in the layer's units.
2457 layer_to_surface_transform
.Translate3d(-200.0, 0.0, 0.0);
2458 expected
= gfx::Rect(gfx::Point(50, -50),
2459 gfx::Size(100, 200)); // The right half of the layer's
2461 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2462 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2463 EXPECT_RECT_EQ(expected
, actual
);
2466 TEST_F(LayerTreeHostCommonTest
,
2467 VisibleRectFor3dOrthographicIsNotClippedBehindSurface
) {
2468 // There is currently no explicit concept of an orthographic projection plane
2469 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2470 // are technically behind the surface in an orthographic world should not be
2471 // clipped when they are flattened to the surface.
2473 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2474 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2475 gfx::Transform layer_to_surface_transform
;
2477 // This sequence of transforms effectively rotates the layer about the y-axis
2478 // at the center of the layer.
2479 layer_to_surface_transform
.MakeIdentity();
2480 layer_to_surface_transform
.Translate(50.0, 0.0);
2481 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2482 layer_to_surface_transform
.Translate(-50.0, 0.0);
2484 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2485 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2486 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2487 EXPECT_RECT_EQ(expected
, actual
);
2490 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveWhenClippedByW
) {
2491 // Test the calculateVisibleRect() function works correctly when projecting a
2492 // surface onto a layer, but the layer is partially behind the camera (not
2493 // just behind the projection plane). In this case, the cartesian coordinates
2494 // may seem to be valid, but actually they are not. The visible rect needs to
2495 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2496 // converting to cartesian coordinates.
2498 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2499 gfx::Rect layer_content_rect
= gfx::Rect(-10, -1, 20, 2);
2500 gfx::Transform layer_to_surface_transform
;
2502 // The layer is positioned so that the right half of the layer should be in
2503 // front of the camera, while the other half is behind the surface's
2504 // projection plane. The following sequence of transforms applies the
2505 // perspective and rotation about the center of the layer.
2506 layer_to_surface_transform
.MakeIdentity();
2507 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2508 layer_to_surface_transform
.Translate3d(-2.0, 0.0, 1.0);
2509 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2511 // Sanity check that this transform does indeed cause w < 0 when applying the
2512 // transform, otherwise this code is not testing the intended scenario.
2514 MathUtil::MapQuad(layer_to_surface_transform
,
2515 gfx::QuadF(gfx::RectF(layer_content_rect
)),
2517 ASSERT_TRUE(clipped
);
2519 int expected_x_position
= 0;
2520 int expected_width
= 10;
2521 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2522 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2523 EXPECT_EQ(expected_x_position
, actual
.x());
2524 EXPECT_EQ(expected_width
, actual
.width());
2527 TEST_F(LayerTreeHostCommonTest
, VisibleRectForPerspectiveUnprojection
) {
2528 // To determine visible rect in layer space, there needs to be an
2529 // un-projection from surface space to layer space. When the original
2530 // transform was a perspective projection that was clipped, it returns a rect
2531 // that encloses the clipped bounds. Un-projecting this new rect may require
2534 // This sequence of transforms causes one corner of the layer to protrude
2535 // across the w = 0 plane, and should be clipped.
2536 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2537 gfx::Rect layer_content_rect
= gfx::Rect(-10, -10, 20, 20);
2538 gfx::Transform layer_to_surface_transform
;
2539 layer_to_surface_transform
.MakeIdentity();
2540 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2541 layer_to_surface_transform
.Translate3d(0.0, 0.0, -5.0);
2542 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2543 layer_to_surface_transform
.RotateAboutXAxis(80.0);
2545 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2546 // code is not testing the intended scenario.
2548 gfx::RectF clipped_rect
=
2549 MathUtil::MapClippedRect(layer_to_surface_transform
, layer_content_rect
);
2550 MathUtil::ProjectQuad(
2551 Inverse(layer_to_surface_transform
), gfx::QuadF(clipped_rect
), &clipped
);
2552 ASSERT_TRUE(clipped
);
2554 // Only the corner of the layer is not visible on the surface because of being
2555 // clipped. But, the net result of rounding visible region to an axis-aligned
2556 // rect is that the entire layer should still be considered visible.
2557 gfx::Rect expected
= gfx::Rect(-10, -10, 20, 20);
2558 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2559 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2560 EXPECT_RECT_EQ(expected
, actual
);
2563 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsForSimpleLayers
) {
2564 scoped_refptr
<Layer
> root
= Layer::Create();
2565 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2566 make_scoped_refptr(new LayerWithForcedDrawsContent());
2567 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2568 make_scoped_refptr(new LayerWithForcedDrawsContent());
2569 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2570 make_scoped_refptr(new LayerWithForcedDrawsContent());
2571 root
->AddChild(child1
);
2572 root
->AddChild(child2
);
2573 root
->AddChild(child3
);
2575 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2576 host
->SetRootLayer(root
);
2578 gfx::Transform identity_matrix
;
2579 SetLayerPropertiesForTesting(root
.get(),
2583 gfx::Size(100, 100),
2586 SetLayerPropertiesForTesting(child1
.get(),
2593 SetLayerPropertiesForTesting(child2
.get(),
2596 gfx::PointF(75.f
, 75.f
),
2600 SetLayerPropertiesForTesting(child3
.get(),
2603 gfx::PointF(125.f
, 125.f
),
2608 ExecuteCalculateDrawProperties(root
.get());
2610 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2611 root
->render_surface()->DrawableContentRect());
2612 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2614 // Layers that do not draw content should have empty visible_content_rects.
2615 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2617 // layer visible_content_rects are clipped by their target surface.
2618 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
2619 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_content_rect());
2620 EXPECT_TRUE(child3
->visible_content_rect().IsEmpty());
2622 // layer drawable_content_rects are not clipped.
2623 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->drawable_content_rect());
2624 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2625 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2628 TEST_F(LayerTreeHostCommonTest
,
2629 DrawableAndVisibleContentRectsForLayersClippedByLayer
) {
2630 scoped_refptr
<Layer
> root
= Layer::Create();
2631 scoped_refptr
<Layer
> child
= Layer::Create();
2632 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child1
=
2633 make_scoped_refptr(new LayerWithForcedDrawsContent());
2634 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child2
=
2635 make_scoped_refptr(new LayerWithForcedDrawsContent());
2636 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child3
=
2637 make_scoped_refptr(new LayerWithForcedDrawsContent());
2638 root
->AddChild(child
);
2639 child
->AddChild(grand_child1
);
2640 child
->AddChild(grand_child2
);
2641 child
->AddChild(grand_child3
);
2643 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2644 host
->SetRootLayer(root
);
2646 gfx::Transform identity_matrix
;
2647 SetLayerPropertiesForTesting(root
.get(),
2651 gfx::Size(100, 100),
2654 SetLayerPropertiesForTesting(child
.get(),
2658 gfx::Size(100, 100),
2661 SetLayerPropertiesForTesting(grand_child1
.get(),
2664 gfx::PointF(5.f
, 5.f
),
2668 SetLayerPropertiesForTesting(grand_child2
.get(),
2671 gfx::PointF(75.f
, 75.f
),
2675 SetLayerPropertiesForTesting(grand_child3
.get(),
2678 gfx::PointF(125.f
, 125.f
),
2683 child
->SetMasksToBounds(true);
2684 ExecuteCalculateDrawProperties(root
.get());
2686 ASSERT_FALSE(child
->render_surface());
2688 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2689 root
->render_surface()->DrawableContentRect());
2690 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2692 // Layers that do not draw content should have empty visible content rects.
2693 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2694 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child
->visible_content_rect());
2696 // All grandchild visible content rects should be clipped by child.
2697 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1
->visible_content_rect());
2698 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2
->visible_content_rect());
2699 EXPECT_TRUE(grand_child3
->visible_content_rect().IsEmpty());
2701 // All grandchild DrawableContentRects should also be clipped by child.
2702 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50),
2703 grand_child1
->drawable_content_rect());
2704 EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25),
2705 grand_child2
->drawable_content_rect());
2706 EXPECT_TRUE(grand_child3
->drawable_content_rect().IsEmpty());
2709 TEST_F(LayerTreeHostCommonTest
,
2710 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface
) {
2711 scoped_refptr
<Layer
> root
= Layer::Create();
2712 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
2713 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2714 make_scoped_refptr(new LayerWithForcedDrawsContent());
2715 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2716 make_scoped_refptr(new LayerWithForcedDrawsContent());
2717 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2718 make_scoped_refptr(new LayerWithForcedDrawsContent());
2719 root
->AddChild(render_surface1
);
2720 render_surface1
->AddChild(child1
);
2721 render_surface1
->AddChild(child2
);
2722 render_surface1
->AddChild(child3
);
2724 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2725 host
->SetRootLayer(root
);
2727 gfx::Transform identity_matrix
;
2728 SetLayerPropertiesForTesting(root
.get(),
2732 gfx::Size(100, 100),
2735 SetLayerPropertiesForTesting(render_surface1
.get(),
2742 SetLayerPropertiesForTesting(child1
.get(),
2745 gfx::PointF(5.f
, 5.f
),
2749 SetLayerPropertiesForTesting(child2
.get(),
2752 gfx::PointF(75.f
, 75.f
),
2756 SetLayerPropertiesForTesting(child3
.get(),
2759 gfx::PointF(125.f
, 125.f
),
2764 render_surface1
->SetForceRenderSurface(true);
2765 ExecuteCalculateDrawProperties(root
.get());
2767 ASSERT_TRUE(render_surface1
->render_surface());
2769 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2770 root
->render_surface()->DrawableContentRect());
2771 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2773 // Layers that do not draw content should have empty visible content rects.
2774 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2775 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
2776 render_surface1
->visible_content_rect());
2778 // An unclipped surface grows its DrawableContentRect to include all drawable
2779 // regions of the subtree.
2780 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
2781 render_surface1
->render_surface()->DrawableContentRect());
2783 // All layers that draw content into the unclipped surface are also unclipped.
2784 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
2785 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
2786 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
2788 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2789 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2790 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2793 TEST_F(LayerTreeHostCommonTest
,
2794 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform
) {
2795 scoped_refptr
<Layer
> root
= Layer::Create();
2796 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2797 make_scoped_refptr(new LayerWithForcedDrawsContent());
2798 root
->AddChild(child
);
2800 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2801 host
->SetRootLayer(root
);
2803 // Case 1: a truly degenerate matrix
2804 gfx::Transform identity_matrix
;
2805 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2806 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2808 SetLayerPropertiesForTesting(root
.get(),
2812 gfx::Size(100, 100),
2815 SetLayerPropertiesForTesting(child
.get(),
2816 uninvertible_matrix
,
2818 gfx::PointF(5.f
, 5.f
),
2823 ExecuteCalculateDrawProperties(root
.get());
2825 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
2826 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2828 // Case 2: a matrix with flattened z, uninvertible and not visible according
2830 uninvertible_matrix
.MakeIdentity();
2831 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2832 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2834 SetLayerPropertiesForTesting(child
.get(),
2835 uninvertible_matrix
,
2837 gfx::PointF(5.f
, 5.f
),
2842 ExecuteCalculateDrawProperties(root
.get());
2844 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
2845 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2847 // Case 3: a matrix with flattened z, also uninvertible and not visible.
2848 uninvertible_matrix
.MakeIdentity();
2849 uninvertible_matrix
.Translate(500.0, 0.0);
2850 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2851 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2853 SetLayerPropertiesForTesting(child
.get(),
2854 uninvertible_matrix
,
2856 gfx::PointF(5.f
, 5.f
),
2861 ExecuteCalculateDrawProperties(root
.get());
2863 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
2864 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2867 TEST_F(LayerTreeHostCommonTest
,
2868 SingularTransformDoesNotPreventClearingDrawProperties
) {
2869 scoped_refptr
<Layer
> root
= Layer::Create();
2870 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2871 make_scoped_refptr(new LayerWithForcedDrawsContent());
2872 root
->AddChild(child
);
2874 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2875 host
->SetRootLayer(root
);
2877 gfx::Transform identity_matrix
;
2878 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2879 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2881 SetLayerPropertiesForTesting(root
.get(),
2882 uninvertible_matrix
,
2885 gfx::Size(100, 100),
2888 SetLayerPropertiesForTesting(child
.get(),
2891 gfx::PointF(5.f
, 5.f
),
2896 child
->draw_properties().sorted_for_recursion
= true;
2898 TransformOperations start_transform_operations
;
2899 start_transform_operations
.AppendScale(1.f
, 0.f
, 0.f
);
2901 TransformOperations end_transform_operations
;
2902 end_transform_operations
.AppendScale(1.f
, 1.f
, 0.f
);
2904 AddAnimatedTransformToLayer(
2905 root
.get(), 10.0, start_transform_operations
, end_transform_operations
);
2907 EXPECT_TRUE(root
->TransformIsAnimating());
2909 ExecuteCalculateDrawProperties(root
.get());
2911 EXPECT_FALSE(child
->draw_properties().sorted_for_recursion
);
2914 TEST_F(LayerTreeHostCommonTest
,
2915 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties
) {
2916 scoped_refptr
<Layer
> root
= Layer::Create();
2918 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2919 host
->SetRootLayer(root
);
2921 gfx::Transform identity_matrix
;
2922 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2923 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2925 SetLayerPropertiesForTesting(root
.get(),
2926 uninvertible_matrix
,
2929 gfx::Size(100, 100),
2933 root
->draw_properties().sorted_for_recursion
= true;
2935 EXPECT_FALSE(root
->TransformIsAnimating());
2937 ExecuteCalculateDrawProperties(root
.get());
2939 EXPECT_FALSE(root
->draw_properties().sorted_for_recursion
);
2942 TEST_F(LayerTreeHostCommonTest
,
2943 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface
) {
2944 scoped_refptr
<Layer
> root
= Layer::Create();
2945 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
2946 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2947 make_scoped_refptr(new LayerWithForcedDrawsContent());
2948 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2949 make_scoped_refptr(new LayerWithForcedDrawsContent());
2950 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2951 make_scoped_refptr(new LayerWithForcedDrawsContent());
2952 root
->AddChild(render_surface1
);
2953 render_surface1
->AddChild(child1
);
2954 render_surface1
->AddChild(child2
);
2955 render_surface1
->AddChild(child3
);
2957 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2958 host
->SetRootLayer(root
);
2960 gfx::Transform identity_matrix
;
2961 SetLayerPropertiesForTesting(root
.get(),
2965 gfx::Size(100, 100),
2968 SetLayerPropertiesForTesting(render_surface1
.get(),
2975 SetLayerPropertiesForTesting(child1
.get(),
2978 gfx::PointF(5.f
, 5.f
),
2982 SetLayerPropertiesForTesting(child2
.get(),
2985 gfx::PointF(75.f
, 75.f
),
2989 SetLayerPropertiesForTesting(child3
.get(),
2992 gfx::PointF(125.f
, 125.f
),
2997 root
->SetMasksToBounds(true);
2998 render_surface1
->SetForceRenderSurface(true);
2999 ExecuteCalculateDrawProperties(root
.get());
3001 ASSERT_TRUE(render_surface1
->render_surface());
3003 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3004 root
->render_surface()->DrawableContentRect());
3005 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3007 // Layers that do not draw content should have empty visible content rects.
3008 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3009 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3010 render_surface1
->visible_content_rect());
3012 // A clipped surface grows its DrawableContentRect to include all drawable
3013 // regions of the subtree, but also gets clamped by the ancestor's clip.
3014 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3015 render_surface1
->render_surface()->DrawableContentRect());
3017 // All layers that draw content into the surface have their visible content
3018 // rect clipped by the surface clip rect.
3019 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3020 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_content_rect());
3021 EXPECT_TRUE(child3
->visible_content_rect().IsEmpty());
3023 // But the DrawableContentRects are unclipped.
3024 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
3025 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
3026 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
3029 TEST_F(LayerTreeHostCommonTest
,
3030 DrawableAndVisibleContentRectsForSurfaceHierarchy
) {
3031 // Check that clipping does not propagate down surfaces.
3032 scoped_refptr
<Layer
> root
= Layer::Create();
3033 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3034 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
3035 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3036 make_scoped_refptr(new LayerWithForcedDrawsContent());
3037 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3038 make_scoped_refptr(new LayerWithForcedDrawsContent());
3039 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
3040 make_scoped_refptr(new LayerWithForcedDrawsContent());
3041 root
->AddChild(render_surface1
);
3042 render_surface1
->AddChild(render_surface2
);
3043 render_surface2
->AddChild(child1
);
3044 render_surface2
->AddChild(child2
);
3045 render_surface2
->AddChild(child3
);
3047 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3048 host
->SetRootLayer(root
);
3050 gfx::Transform identity_matrix
;
3051 SetLayerPropertiesForTesting(root
.get(),
3055 gfx::Size(100, 100),
3058 SetLayerPropertiesForTesting(render_surface1
.get(),
3065 SetLayerPropertiesForTesting(render_surface2
.get(),
3072 SetLayerPropertiesForTesting(child1
.get(),
3075 gfx::PointF(5.f
, 5.f
),
3079 SetLayerPropertiesForTesting(child2
.get(),
3082 gfx::PointF(75.f
, 75.f
),
3086 SetLayerPropertiesForTesting(child3
.get(),
3089 gfx::PointF(125.f
, 125.f
),
3094 root
->SetMasksToBounds(true);
3095 render_surface1
->SetForceRenderSurface(true);
3096 render_surface2
->SetForceRenderSurface(true);
3097 ExecuteCalculateDrawProperties(root
.get());
3099 ASSERT_TRUE(render_surface1
->render_surface());
3100 ASSERT_TRUE(render_surface2
->render_surface());
3102 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3103 root
->render_surface()->DrawableContentRect());
3104 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3106 // Layers that do not draw content should have empty visible content rects.
3107 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3108 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3109 render_surface1
->visible_content_rect());
3110 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3111 render_surface2
->visible_content_rect());
3113 // A clipped surface grows its DrawableContentRect to include all drawable
3114 // regions of the subtree, but also gets clamped by the ancestor's clip.
3115 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3116 render_surface1
->render_surface()->DrawableContentRect());
3118 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3119 // is only implicitly clipped by render_surface1's content rect. So,
3120 // render_surface2 grows to enclose all drawable content of its subtree.
3121 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
3122 render_surface2
->render_surface()->DrawableContentRect());
3124 // All layers that draw content into render_surface2 think they are unclipped.
3125 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3126 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
3127 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
3129 // DrawableContentRects are also unclipped.
3130 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
3131 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
3132 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
3135 TEST_F(LayerTreeHostCommonTest
,
3136 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface
) {
3137 // Layers that have non-axis aligned bounds (due to transforms) have an
3138 // expanded, axis-aligned DrawableContentRect and visible content rect.
3140 scoped_refptr
<Layer
> root
= Layer::Create();
3141 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3142 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3143 make_scoped_refptr(new LayerWithForcedDrawsContent());
3144 root
->AddChild(render_surface1
);
3145 render_surface1
->AddChild(child1
);
3147 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3148 host
->SetRootLayer(root
);
3150 gfx::Transform identity_matrix
;
3151 gfx::Transform child_rotation
;
3152 child_rotation
.Rotate(45.0);
3153 SetLayerPropertiesForTesting(root
.get(),
3157 gfx::Size(100, 100),
3160 SetLayerPropertiesForTesting(render_surface1
.get(),
3167 SetLayerPropertiesForTesting(child1
.get(),
3169 gfx::Point3F(25, 25, 0.f
),
3170 gfx::PointF(25.f
, 25.f
),
3175 render_surface1
->SetForceRenderSurface(true);
3176 ExecuteCalculateDrawProperties(root
.get());
3178 ASSERT_TRUE(render_surface1
->render_surface());
3180 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3181 root
->render_surface()->DrawableContentRect());
3182 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3184 // Layers that do not draw content should have empty visible content rects.
3185 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3186 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3187 render_surface1
->visible_content_rect());
3189 // The unclipped surface grows its DrawableContentRect to include all drawable
3190 // regions of the subtree.
3191 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3192 gfx::Rect expected_surface_drawable_content
=
3193 gfx::Rect(50 - diagonal_radius
,
3194 50 - diagonal_radius
,
3195 diagonal_radius
* 2,
3196 diagonal_radius
* 2);
3197 EXPECT_RECT_EQ(expected_surface_drawable_content
,
3198 render_surface1
->render_surface()->DrawableContentRect());
3200 // All layers that draw content into the unclipped surface are also unclipped.
3201 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3202 EXPECT_RECT_EQ(expected_surface_drawable_content
,
3203 child1
->drawable_content_rect());
3206 TEST_F(LayerTreeHostCommonTest
,
3207 DrawableAndVisibleContentRectsWithTransformOnClippedSurface
) {
3208 // Layers that have non-axis aligned bounds (due to transforms) have an
3209 // expanded, axis-aligned DrawableContentRect and visible content rect.
3211 scoped_refptr
<Layer
> root
= Layer::Create();
3212 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3213 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3214 make_scoped_refptr(new LayerWithForcedDrawsContent());
3215 root
->AddChild(render_surface1
);
3216 render_surface1
->AddChild(child1
);
3218 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3219 host
->SetRootLayer(root
);
3221 gfx::Transform identity_matrix
;
3222 gfx::Transform child_rotation
;
3223 child_rotation
.Rotate(45.0);
3224 SetLayerPropertiesForTesting(root
.get(),
3231 SetLayerPropertiesForTesting(render_surface1
.get(),
3239 SetLayerPropertiesForTesting(child1
.get(),
3241 gfx::Point3F(25, 25, 0.f
),
3242 gfx::PointF(25.f
, 25.f
),
3247 root
->SetMasksToBounds(true);
3248 render_surface1
->SetForceRenderSurface(true);
3249 ExecuteCalculateDrawProperties(root
.get());
3251 ASSERT_TRUE(render_surface1
->render_surface());
3253 // The clipped surface clamps the DrawableContentRect that encloses the
3255 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3256 gfx::Rect unclipped_surface_content
= gfx::Rect(50 - diagonal_radius
,
3257 50 - diagonal_radius
,
3258 diagonal_radius
* 2,
3259 diagonal_radius
* 2);
3260 gfx::Rect expected_surface_drawable_content
=
3261 gfx::IntersectRects(unclipped_surface_content
, gfx::Rect(0, 0, 50, 50));
3262 EXPECT_RECT_EQ(expected_surface_drawable_content
,
3263 render_surface1
->render_surface()->DrawableContentRect());
3265 // On the clipped surface, only a quarter of the child1 is visible, but when
3266 // rotating it back to child1's content space, the actual enclosing rect ends
3267 // up covering the full left half of child1.
3269 // Given the floating point math, this number is a little bit fuzzy.
3270 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1
->visible_content_rect());
3272 // The child's DrawableContentRect is unclipped.
3273 EXPECT_RECT_EQ(unclipped_surface_content
, child1
->drawable_content_rect());
3276 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsInHighDPI
) {
3277 MockContentLayerClient client
;
3279 scoped_refptr
<Layer
> root
= Layer::Create();
3280 scoped_refptr
<FakePictureLayer
> render_surface1
=
3281 CreateDrawablePictureLayer(&client
);
3282 scoped_refptr
<FakePictureLayer
> render_surface2
=
3283 CreateDrawablePictureLayer(&client
);
3284 scoped_refptr
<FakePictureLayer
> child1
= CreateDrawablePictureLayer(&client
);
3285 scoped_refptr
<FakePictureLayer
> child2
= CreateDrawablePictureLayer(&client
);
3286 scoped_refptr
<FakePictureLayer
> child3
= CreateDrawablePictureLayer(&client
);
3287 root
->AddChild(render_surface1
);
3288 render_surface1
->AddChild(render_surface2
);
3289 render_surface2
->AddChild(child1
);
3290 render_surface2
->AddChild(child2
);
3291 render_surface2
->AddChild(child3
);
3293 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3294 host
->SetRootLayer(root
);
3296 gfx::Transform identity_matrix
;
3297 SetLayerPropertiesForTesting(root
.get(),
3301 gfx::Size(100, 100),
3304 SetLayerPropertiesForTesting(render_surface1
.get(),
3307 gfx::PointF(5.f
, 5.f
),
3311 SetLayerPropertiesForTesting(render_surface2
.get(),
3314 gfx::PointF(5.f
, 5.f
),
3318 SetLayerPropertiesForTesting(child1
.get(),
3321 gfx::PointF(5.f
, 5.f
),
3325 SetLayerPropertiesForTesting(child2
.get(),
3328 gfx::PointF(75.f
, 75.f
),
3332 SetLayerPropertiesForTesting(child3
.get(),
3335 gfx::PointF(125.f
, 125.f
),
3340 float device_scale_factor
= 2.f
;
3342 root
->SetMasksToBounds(true);
3343 render_surface1
->SetForceRenderSurface(true);
3344 render_surface2
->SetForceRenderSurface(true);
3345 ExecuteCalculateDrawProperties(root
.get(), device_scale_factor
);
3347 ASSERT_TRUE(render_surface1
->render_surface());
3348 ASSERT_TRUE(render_surface2
->render_surface());
3350 // drawable_content_rects for all layers and surfaces are scaled by
3351 // device_scale_factor.
3352 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200),
3353 root
->render_surface()->DrawableContentRect());
3354 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root
->drawable_content_rect());
3355 EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190),
3356 render_surface1
->render_surface()->DrawableContentRect());
3358 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3359 // is only implicitly clipped by render_surface1.
3360 EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350),
3361 render_surface2
->render_surface()->DrawableContentRect());
3363 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1
->drawable_content_rect());
3364 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100),
3365 child2
->drawable_content_rect());
3366 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100),
3367 child3
->drawable_content_rect());
3369 // The root layer does not actually draw content of its own.
3370 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3372 // All layer visible content rects are not expressed in content space of each
3373 // layer, so they are not scaled by the device_scale_factor.
3374 EXPECT_RECT_EQ(gfx::Rect(0, 0, 3, 4),
3375 render_surface1
->visible_content_rect());
3376 EXPECT_RECT_EQ(gfx::Rect(0, 0, 7, 13),
3377 render_surface2
->visible_content_rect());
3378 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3379 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
3380 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
3383 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithoutPreserves3d
) {
3384 // Verify the behavior of back-face culling when there are no preserve-3d
3385 // layers. Note that 3d transforms still apply in this case, but they are
3386 // "flattened" to each parent layer according to current W3C spec.
3388 const gfx::Transform identity_matrix
;
3389 scoped_refptr
<Layer
> parent
= Layer::Create();
3390 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3391 make_scoped_refptr(new LayerWithForcedDrawsContent());
3392 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3393 make_scoped_refptr(new LayerWithForcedDrawsContent());
3394 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3395 make_scoped_refptr(new LayerWithForcedDrawsContent());
3396 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3397 make_scoped_refptr(new LayerWithForcedDrawsContent());
3398 scoped_refptr
<LayerWithForcedDrawsContent
>
3399 front_facing_child_of_front_facing_surface
=
3400 make_scoped_refptr(new LayerWithForcedDrawsContent());
3401 scoped_refptr
<LayerWithForcedDrawsContent
>
3402 back_facing_child_of_front_facing_surface
=
3403 make_scoped_refptr(new LayerWithForcedDrawsContent());
3404 scoped_refptr
<LayerWithForcedDrawsContent
>
3405 front_facing_child_of_back_facing_surface
=
3406 make_scoped_refptr(new LayerWithForcedDrawsContent());
3407 scoped_refptr
<LayerWithForcedDrawsContent
>
3408 back_facing_child_of_back_facing_surface
=
3409 make_scoped_refptr(new LayerWithForcedDrawsContent());
3411 parent
->AddChild(front_facing_child
);
3412 parent
->AddChild(back_facing_child
);
3413 parent
->AddChild(front_facing_surface
);
3414 parent
->AddChild(back_facing_surface
);
3415 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3416 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3417 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3418 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3420 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3421 host
->SetRootLayer(parent
);
3423 // Nothing is double-sided
3424 front_facing_child
->SetDoubleSided(false);
3425 back_facing_child
->SetDoubleSided(false);
3426 front_facing_surface
->SetDoubleSided(false);
3427 back_facing_surface
->SetDoubleSided(false);
3428 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3429 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3430 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3431 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3433 gfx::Transform backface_matrix
;
3434 backface_matrix
.Translate(50.0, 50.0);
3435 backface_matrix
.RotateAboutYAxis(180.0);
3436 backface_matrix
.Translate(-50.0, -50.0);
3438 // Having a descendant and opacity will force these to have render surfaces.
3439 front_facing_surface
->SetOpacity(0.5f
);
3440 back_facing_surface
->SetOpacity(0.5f
);
3442 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3443 // these layers should blindly use their own local transforms to determine
3444 // back-face culling.
3445 SetLayerPropertiesForTesting(parent
.get(),
3449 gfx::Size(100, 100),
3452 SetLayerPropertiesForTesting(front_facing_child
.get(),
3456 gfx::Size(100, 100),
3459 SetLayerPropertiesForTesting(back_facing_child
.get(),
3463 gfx::Size(100, 100),
3466 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3470 gfx::Size(100, 100),
3473 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3477 gfx::Size(100, 100),
3480 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3484 gfx::Size(100, 100),
3487 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3491 gfx::Size(100, 100),
3494 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3498 gfx::Size(100, 100),
3501 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3505 gfx::Size(100, 100),
3509 RenderSurfaceLayerList render_surface_layer_list
;
3510 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3511 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3512 inputs
.can_adjust_raster_scales
= true;
3513 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3515 // Verify which render surfaces were created.
3516 EXPECT_FALSE(front_facing_child
->render_surface());
3517 EXPECT_FALSE(back_facing_child
->render_surface());
3518 EXPECT_TRUE(front_facing_surface
->render_surface());
3519 EXPECT_TRUE(back_facing_surface
->render_surface());
3520 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3521 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3522 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3523 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3525 // Verify the render_surface_layer_list.
3526 ASSERT_EQ(3u, render_surface_layer_list
.size());
3527 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3528 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
3529 // Even though the back facing surface LAYER gets culled, the other
3530 // descendants should still be added, so the SURFACE should not be culled.
3531 EXPECT_EQ(back_facing_surface
->id(), render_surface_layer_list
.at(2)->id());
3533 // Verify root surface's layer list.
3536 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3537 EXPECT_EQ(front_facing_child
->id(),
3538 render_surface_layer_list
.at(0)
3543 EXPECT_EQ(front_facing_surface
->id(),
3544 render_surface_layer_list
.at(0)
3549 EXPECT_EQ(back_facing_surface
->id(),
3550 render_surface_layer_list
.at(0)
3556 // Verify front_facing_surface's layer list.
3559 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3560 EXPECT_EQ(front_facing_surface
->id(),
3561 render_surface_layer_list
.at(1)
3566 EXPECT_EQ(front_facing_child_of_front_facing_surface
->id(),
3567 render_surface_layer_list
.at(1)
3573 // Verify back_facing_surface's layer list; its own layer should be culled
3574 // from the surface list.
3577 render_surface_layer_list
.at(2)->render_surface()->layer_list().size());
3578 EXPECT_EQ(front_facing_child_of_back_facing_surface
->id(),
3579 render_surface_layer_list
.at(2)
3586 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithPreserves3d
) {
3587 // Verify the behavior of back-face culling when preserves-3d transform style
3590 const gfx::Transform identity_matrix
;
3591 scoped_refptr
<Layer
> parent
= Layer::Create();
3592 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3593 make_scoped_refptr(new LayerWithForcedDrawsContent());
3594 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3595 make_scoped_refptr(new LayerWithForcedDrawsContent());
3596 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3597 make_scoped_refptr(new LayerWithForcedDrawsContent());
3598 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3599 make_scoped_refptr(new LayerWithForcedDrawsContent());
3600 scoped_refptr
<LayerWithForcedDrawsContent
>
3601 front_facing_child_of_front_facing_surface
=
3602 make_scoped_refptr(new LayerWithForcedDrawsContent());
3603 scoped_refptr
<LayerWithForcedDrawsContent
>
3604 back_facing_child_of_front_facing_surface
=
3605 make_scoped_refptr(new LayerWithForcedDrawsContent());
3606 scoped_refptr
<LayerWithForcedDrawsContent
>
3607 front_facing_child_of_back_facing_surface
=
3608 make_scoped_refptr(new LayerWithForcedDrawsContent());
3609 scoped_refptr
<LayerWithForcedDrawsContent
>
3610 back_facing_child_of_back_facing_surface
=
3611 make_scoped_refptr(new LayerWithForcedDrawsContent());
3612 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer1
=
3613 make_scoped_refptr(new LayerWithForcedDrawsContent());
3614 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer2
=
3615 make_scoped_refptr(new LayerWithForcedDrawsContent());
3617 parent
->AddChild(front_facing_child
);
3618 parent
->AddChild(back_facing_child
);
3619 parent
->AddChild(front_facing_surface
);
3620 parent
->AddChild(back_facing_surface
);
3621 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3622 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3623 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3624 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3626 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3627 host
->SetRootLayer(parent
);
3629 // Nothing is double-sided
3630 front_facing_child
->SetDoubleSided(false);
3631 back_facing_child
->SetDoubleSided(false);
3632 front_facing_surface
->SetDoubleSided(false);
3633 back_facing_surface
->SetDoubleSided(false);
3634 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3635 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3636 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3637 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3639 gfx::Transform backface_matrix
;
3640 backface_matrix
.Translate(50.0, 50.0);
3641 backface_matrix
.RotateAboutYAxis(180.0);
3642 backface_matrix
.Translate(-50.0, -50.0);
3644 // Opacity will not force creation of render surfaces in this case because of
3645 // the preserve-3d transform style. Instead, an example of when a surface
3646 // would be created with preserve-3d is when there is a replica layer.
3647 front_facing_surface
->SetReplicaLayer(dummy_replica_layer1
.get());
3648 back_facing_surface
->SetReplicaLayer(dummy_replica_layer2
.get());
3650 // Each surface creates its own new 3d rendering context (as defined by W3C
3651 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3652 // rendering context should use the transform with respect to that context.
3653 // This 3d rendering context occurs when (a) parent's transform style is flat
3654 // and (b) the layer's transform style is preserve-3d.
3655 SetLayerPropertiesForTesting(parent
.get(),
3659 gfx::Size(100, 100),
3661 false); // parent transform style is flat.
3662 SetLayerPropertiesForTesting(front_facing_child
.get(),
3666 gfx::Size(100, 100),
3669 SetLayerPropertiesForTesting(back_facing_child
.get(),
3673 gfx::Size(100, 100),
3676 // surface transform style is preserve-3d.
3677 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3681 gfx::Size(100, 100),
3684 // surface transform style is preserve-3d.
3685 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3689 gfx::Size(100, 100),
3692 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3696 gfx::Size(100, 100),
3699 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3703 gfx::Size(100, 100),
3706 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3710 gfx::Size(100, 100),
3713 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3717 gfx::Size(100, 100),
3721 RenderSurfaceLayerList render_surface_layer_list
;
3722 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3723 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3724 inputs
.can_adjust_raster_scales
= true;
3725 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3727 // Verify which render surfaces were created.
3728 EXPECT_FALSE(front_facing_child
->render_surface());
3729 EXPECT_FALSE(back_facing_child
->render_surface());
3730 EXPECT_TRUE(front_facing_surface
->render_surface());
3731 EXPECT_FALSE(back_facing_surface
->render_surface());
3732 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3733 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3734 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3735 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3737 // Verify the render_surface_layer_list. The back-facing surface should be
3739 ASSERT_EQ(2u, render_surface_layer_list
.size());
3740 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3741 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
3743 // Verify root surface's layer list.
3746 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3747 EXPECT_EQ(front_facing_child
->id(),
3748 render_surface_layer_list
.at(0)
3749 ->render_surface()->layer_list().at(0)->id());
3750 EXPECT_EQ(front_facing_surface
->id(),
3751 render_surface_layer_list
.at(0)
3752 ->render_surface()->layer_list().at(1)->id());
3754 // Verify front_facing_surface's layer list.
3757 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3758 EXPECT_EQ(front_facing_surface
->id(),
3759 render_surface_layer_list
.at(1)
3760 ->render_surface()->layer_list().at(0)->id());
3761 EXPECT_EQ(front_facing_child_of_front_facing_surface
->id(),
3762 render_surface_layer_list
.at(1)
3763 ->render_surface()->layer_list().at(1)->id());
3766 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithAnimatingTransforms
) {
3767 // Verify that layers are appropriately culled when their back face is showing
3768 // and they are not double sided, while animations are going on.
3770 // Layers that are animating do not get culled on the main thread, as their
3771 // transforms should be treated as "unknown" so we can not be sure that their
3772 // back face is really showing.
3773 const gfx::Transform identity_matrix
;
3774 scoped_refptr
<Layer
> parent
= Layer::Create();
3775 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
3776 make_scoped_refptr(new LayerWithForcedDrawsContent());
3777 scoped_refptr
<LayerWithForcedDrawsContent
> animating_surface
=
3778 make_scoped_refptr(new LayerWithForcedDrawsContent());
3779 scoped_refptr
<LayerWithForcedDrawsContent
> child_of_animating_surface
=
3780 make_scoped_refptr(new LayerWithForcedDrawsContent());
3781 scoped_refptr
<LayerWithForcedDrawsContent
> animating_child
=
3782 make_scoped_refptr(new LayerWithForcedDrawsContent());
3783 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3784 make_scoped_refptr(new LayerWithForcedDrawsContent());
3786 parent
->AddChild(child
);
3787 parent
->AddChild(animating_surface
);
3788 animating_surface
->AddChild(child_of_animating_surface
);
3789 parent
->AddChild(animating_child
);
3790 parent
->AddChild(child2
);
3792 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3793 host
->SetRootLayer(parent
);
3795 // Nothing is double-sided
3796 child
->SetDoubleSided(false);
3797 child2
->SetDoubleSided(false);
3798 animating_surface
->SetDoubleSided(false);
3799 child_of_animating_surface
->SetDoubleSided(false);
3800 animating_child
->SetDoubleSided(false);
3802 gfx::Transform backface_matrix
;
3803 backface_matrix
.Translate(50.0, 50.0);
3804 backface_matrix
.RotateAboutYAxis(180.0);
3805 backface_matrix
.Translate(-50.0, -50.0);
3807 // Make our render surface.
3808 animating_surface
->SetForceRenderSurface(true);
3810 // Animate the transform on the render surface.
3811 AddAnimatedTransformToController(
3812 animating_surface
->layer_animation_controller(), 10.0, 30, 0);
3813 // This is just an animating layer, not a surface.
3814 AddAnimatedTransformToController(
3815 animating_child
->layer_animation_controller(), 10.0, 30, 0);
3817 SetLayerPropertiesForTesting(parent
.get(),
3821 gfx::Size(100, 100),
3824 SetLayerPropertiesForTesting(child
.get(),
3828 gfx::Size(100, 100),
3831 SetLayerPropertiesForTesting(animating_surface
.get(),
3835 gfx::Size(100, 100),
3838 SetLayerPropertiesForTesting(child_of_animating_surface
.get(),
3842 gfx::Size(100, 100),
3845 SetLayerPropertiesForTesting(animating_child
.get(),
3849 gfx::Size(100, 100),
3852 SetLayerPropertiesForTesting(child2
.get(),
3856 gfx::Size(100, 100),
3860 RenderSurfaceLayerList render_surface_layer_list
;
3861 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3862 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3863 inputs
.can_adjust_raster_scales
= true;
3864 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3866 EXPECT_FALSE(child
->render_surface());
3867 EXPECT_TRUE(animating_surface
->render_surface());
3868 EXPECT_FALSE(child_of_animating_surface
->render_surface());
3869 EXPECT_FALSE(animating_child
->render_surface());
3870 EXPECT_FALSE(child2
->render_surface());
3872 // Verify that the animating_child and child_of_animating_surface were not
3873 // culled, but that child was.
3874 ASSERT_EQ(2u, render_surface_layer_list
.size());
3875 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3876 EXPECT_EQ(animating_surface
->id(), render_surface_layer_list
.at(1)->id());
3878 // The non-animating child be culled from the layer list for the parent render
3882 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3883 EXPECT_EQ(animating_surface
->id(),
3884 render_surface_layer_list
.at(0)
3885 ->render_surface()->layer_list().at(0)->id());
3886 EXPECT_EQ(animating_child
->id(),
3887 render_surface_layer_list
.at(0)
3888 ->render_surface()->layer_list().at(1)->id());
3889 EXPECT_EQ(child2
->id(),
3890 render_surface_layer_list
.at(0)
3891 ->render_surface()->layer_list().at(2)->id());
3895 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3896 EXPECT_EQ(animating_surface
->id(),
3897 render_surface_layer_list
.at(1)
3898 ->render_surface()->layer_list().at(0)->id());
3899 EXPECT_EQ(child_of_animating_surface
->id(),
3900 render_surface_layer_list
.at(1)
3901 ->render_surface()->layer_list().at(1)->id());
3903 EXPECT_FALSE(child2
->visible_content_rect().IsEmpty());
3905 // The animating layers should have a visible content rect that represents the
3906 // area of the front face that is within the viewport.
3907 EXPECT_EQ(animating_child
->visible_content_rect(),
3908 gfx::Rect(animating_child
->content_bounds()));
3909 EXPECT_EQ(animating_surface
->visible_content_rect(),
3910 gfx::Rect(animating_surface
->content_bounds()));
3911 // And layers in the subtree of the animating layer should have valid visible
3912 // content rects also.
3913 EXPECT_EQ(child_of_animating_surface
->visible_content_rect(),
3914 gfx::Rect(child_of_animating_surface
->content_bounds()));
3917 TEST_F(LayerTreeHostCommonTest
,
3918 BackFaceCullingWithPreserves3dForFlatteningSurface
) {
3919 // Verify the behavior of back-face culling for a render surface that is
3920 // created when it flattens its subtree, and its parent has preserves-3d.
3922 const gfx::Transform identity_matrix
;
3923 scoped_refptr
<Layer
> parent
= Layer::Create();
3924 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3925 make_scoped_refptr(new LayerWithForcedDrawsContent());
3926 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3927 make_scoped_refptr(new LayerWithForcedDrawsContent());
3928 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3929 make_scoped_refptr(new LayerWithForcedDrawsContent());
3930 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3931 make_scoped_refptr(new LayerWithForcedDrawsContent());
3933 parent
->AddChild(front_facing_surface
);
3934 parent
->AddChild(back_facing_surface
);
3935 front_facing_surface
->AddChild(child1
);
3936 back_facing_surface
->AddChild(child2
);
3938 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3939 host
->SetRootLayer(parent
);
3941 // RenderSurfaces are not double-sided
3942 front_facing_surface
->SetDoubleSided(false);
3943 back_facing_surface
->SetDoubleSided(false);
3945 gfx::Transform backface_matrix
;
3946 backface_matrix
.Translate(50.0, 50.0);
3947 backface_matrix
.RotateAboutYAxis(180.0);
3948 backface_matrix
.Translate(-50.0, -50.0);
3950 SetLayerPropertiesForTesting(parent
.get(),
3954 gfx::Size(100, 100),
3956 true); // parent transform style is preserve3d.
3957 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3961 gfx::Size(100, 100),
3963 true); // surface transform style is flat.
3964 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3968 gfx::Size(100, 100),
3970 true); // surface transform style is flat.
3971 SetLayerPropertiesForTesting(child1
.get(),
3975 gfx::Size(100, 100),
3978 SetLayerPropertiesForTesting(child2
.get(),
3982 gfx::Size(100, 100),
3986 front_facing_surface
->Set3dSortingContextId(1);
3987 back_facing_surface
->Set3dSortingContextId(1);
3989 RenderSurfaceLayerList render_surface_layer_list
;
3990 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3991 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3992 inputs
.can_adjust_raster_scales
= true;
3993 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3995 // Verify which render surfaces were created.
3996 EXPECT_TRUE(front_facing_surface
->render_surface());
3998 back_facing_surface
->render_surface()); // because it should be culled
3999 EXPECT_FALSE(child1
->render_surface());
4000 EXPECT_FALSE(child2
->render_surface());
4002 // Verify the render_surface_layer_list. The back-facing surface should be
4004 ASSERT_EQ(2u, render_surface_layer_list
.size());
4005 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
4006 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
4008 // Verify root surface's layer list.
4011 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
4012 EXPECT_EQ(front_facing_surface
->id(),
4013 render_surface_layer_list
.at(0)
4014 ->render_surface()->layer_list().at(0)->id());
4016 // Verify front_facing_surface's layer list.
4019 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
4020 EXPECT_EQ(front_facing_surface
->id(),
4021 render_surface_layer_list
.at(1)
4022 ->render_surface()->layer_list().at(0)->id());
4023 EXPECT_EQ(child1
->id(),
4024 render_surface_layer_list
.at(1)
4025 ->render_surface()->layer_list().at(1)->id());
4028 class NoScaleContentLayer
: public ContentLayer
{
4030 static scoped_refptr
<NoScaleContentLayer
> Create(ContentLayerClient
* client
) {
4031 return make_scoped_refptr(new NoScaleContentLayer(client
));
4034 void CalculateContentsScale(float ideal_contents_scale
,
4035 float* contents_scale_x
,
4036 float* contents_scale_y
,
4037 gfx::Size
* content_bounds
) override
{
4038 // Skip over the ContentLayer to the base Layer class.
4039 Layer::CalculateContentsScale(ideal_contents_scale
,
4046 explicit NoScaleContentLayer(ContentLayerClient
* client
)
4047 : ContentLayer(client
) {}
4048 ~NoScaleContentLayer() override
{}
4051 scoped_refptr
<NoScaleContentLayer
> CreateNoScaleDrawableContentLayer(
4052 ContentLayerClient
* delegate
) {
4053 scoped_refptr
<NoScaleContentLayer
> to_return
=
4054 NoScaleContentLayer::Create(delegate
);
4055 to_return
->SetIsDrawable(true);
4059 TEST_F(LayerTreeHostCommonTest
, LayerTransformsInHighDPI
) {
4060 // Verify draw and screen space transforms of layers not in a surface.
4061 MockContentLayerClient delegate
;
4062 gfx::Transform identity_matrix
;
4064 scoped_refptr
<FakePictureLayer
> parent
=
4065 CreateDrawablePictureLayer(&delegate
);
4066 SetLayerPropertiesForTesting(parent
.get(),
4070 gfx::Size(100, 100),
4074 scoped_refptr
<FakePictureLayer
> child
= CreateDrawablePictureLayer(&delegate
);
4075 SetLayerPropertiesForTesting(child
.get(),
4078 gfx::PointF(2.f
, 2.f
),
4083 scoped_refptr
<FakePictureLayer
> child_empty
=
4084 CreateDrawablePictureLayer(&delegate
);
4085 SetLayerPropertiesForTesting(child_empty
.get(),
4088 gfx::PointF(2.f
, 2.f
),
4093 parent
->AddChild(child
);
4094 parent
->AddChild(child_empty
);
4096 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4097 host
->SetRootLayer(parent
);
4099 float device_scale_factor
= 2.5f
;
4100 float page_scale_factor
= 1.f
;
4102 RenderSurfaceLayerList render_surface_layer_list
;
4103 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4104 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4105 inputs
.device_scale_factor
= device_scale_factor
;
4106 inputs
.page_scale_factor
= page_scale_factor
;
4107 inputs
.can_adjust_raster_scales
= true;
4108 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4110 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4111 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, child
);
4112 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, child_empty
);
4114 EXPECT_EQ(1u, render_surface_layer_list
.size());
4116 // Verify parent transforms
4117 gfx::Transform expected_parent_transform
;
4118 expected_parent_transform
.Scale(device_scale_factor
* page_scale_factor
,
4119 device_scale_factor
* page_scale_factor
);
4120 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4121 parent
->screen_space_transform());
4122 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4123 parent
->draw_transform());
4125 // Verify results of transformed parent rects
4126 gfx::RectF
parent_content_bounds(parent
->content_bounds());
4128 gfx::RectF parent_draw_rect
=
4129 MathUtil::MapClippedRect(parent
->draw_transform(), parent_content_bounds
);
4130 gfx::RectF parent_screen_space_rect
= MathUtil::MapClippedRect(
4131 parent
->screen_space_transform(), parent_content_bounds
);
4133 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
4134 expected_parent_draw_rect
.Scale(device_scale_factor
);
4135 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
4136 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
4138 // Verify child and child_empty transforms. They should match.
4139 gfx::Transform expected_child_transform
;
4140 expected_child_transform
.Scale(device_scale_factor
, device_scale_factor
);
4141 expected_child_transform
.Translate(child
->position().x(),
4142 child
->position().y());
4143 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4144 child
->draw_transform());
4145 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4146 child
->screen_space_transform());
4147 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4148 child_empty
->draw_transform());
4149 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4150 child_empty
->screen_space_transform());
4152 // Verify results of transformed child and child_empty rects. They should
4154 gfx::RectF
child_content_bounds(child
->content_bounds());
4156 gfx::RectF child_draw_rect
=
4157 MathUtil::MapClippedRect(child
->draw_transform(), child_content_bounds
);
4158 gfx::RectF child_screen_space_rect
= MathUtil::MapClippedRect(
4159 child
->screen_space_transform(), child_content_bounds
);
4161 gfx::RectF child_empty_draw_rect
= MathUtil::MapClippedRect(
4162 child_empty
->draw_transform(), child_content_bounds
);
4163 gfx::RectF child_empty_screen_space_rect
= MathUtil::MapClippedRect(
4164 child_empty
->screen_space_transform(), child_content_bounds
);
4166 gfx::RectF
expected_child_draw_rect(child
->position(), child
->bounds());
4167 expected_child_draw_rect
.Scale(device_scale_factor
);
4168 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
4169 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
4170 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_draw_rect
);
4171 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_screen_space_rect
);
4174 TEST_F(LayerTreeHostCommonTest
, SurfaceLayerTransformsInHighDPI
) {
4175 // Verify draw and screen space transforms of layers in a surface.
4176 MockContentLayerClient delegate
;
4177 gfx::Transform identity_matrix
;
4179 gfx::Transform perspective_matrix
;
4180 perspective_matrix
.ApplyPerspectiveDepth(2.0);
4182 gfx::Transform scale_small_matrix
;
4183 scale_small_matrix
.Scale(SK_MScalar1
/ 10.f
, SK_MScalar1
/ 12.f
);
4185 scoped_refptr
<Layer
> root
= Layer::Create();
4187 scoped_refptr
<FakePictureLayer
> parent
=
4188 CreateDrawablePictureLayer(&delegate
);
4189 SetLayerPropertiesForTesting(parent
.get(),
4193 gfx::Size(100, 100),
4197 scoped_refptr
<FakePictureLayer
> perspective_surface
=
4198 CreateDrawablePictureLayer(&delegate
);
4199 SetLayerPropertiesForTesting(perspective_surface
.get(),
4200 perspective_matrix
* scale_small_matrix
,
4202 gfx::PointF(2.f
, 2.f
),
4207 scoped_refptr
<FakePictureLayer
> scale_surface
=
4208 CreateDrawablePictureLayer(&delegate
);
4209 SetLayerPropertiesForTesting(scale_surface
.get(),
4212 gfx::PointF(2.f
, 2.f
),
4217 perspective_surface
->SetForceRenderSurface(true);
4218 scale_surface
->SetForceRenderSurface(true);
4220 parent
->AddChild(perspective_surface
);
4221 parent
->AddChild(scale_surface
);
4222 root
->AddChild(parent
);
4224 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4225 host
->SetRootLayer(root
);
4227 float device_scale_factor
= 2.5f
;
4228 float page_scale_factor
= 3.f
;
4230 RenderSurfaceLayerList render_surface_layer_list
;
4231 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4232 root
.get(), parent
->bounds(), &render_surface_layer_list
);
4233 inputs
.device_scale_factor
= device_scale_factor
;
4234 inputs
.page_scale_factor
= page_scale_factor
;
4235 inputs
.page_scale_application_layer
= root
.get();
4236 inputs
.can_adjust_raster_scales
= true;
4237 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4239 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4240 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4241 perspective_surface
);
4242 // Ideal scale is the max 2d scale component of the combined transform up to
4243 // the nearest render target. Here this includes the layer transform as well
4244 // as the device and page scale factors.
4245 gfx::Transform transform
= scale_small_matrix
;
4246 transform
.Scale(device_scale_factor
* page_scale_factor
,
4247 device_scale_factor
* page_scale_factor
);
4248 gfx::Vector2dF scales
=
4249 MathUtil::ComputeTransform2dScaleComponents(transform
, 0.f
);
4250 float max_2d_scale
= std::max(scales
.x(), scales
.y());
4251 EXPECT_IDEAL_SCALE_EQ(max_2d_scale
, scale_surface
);
4253 // The ideal scale will draw 1:1 with its render target space along
4254 // the larger-scale axis.
4255 gfx::Vector2dF target_space_transform_scales
=
4256 MathUtil::ComputeTransform2dScaleComponents(
4257 scale_surface
->draw_properties().target_space_transform
, 0.f
);
4258 EXPECT_FLOAT_EQ(max_2d_scale
,
4259 std::max(target_space_transform_scales
.x(),
4260 target_space_transform_scales
.y()));
4262 EXPECT_EQ(3u, render_surface_layer_list
.size());
4264 gfx::Transform expected_parent_draw_transform
;
4265 expected_parent_draw_transform
.Scale(device_scale_factor
* page_scale_factor
,
4266 device_scale_factor
* page_scale_factor
);
4267 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform
,
4268 parent
->draw_transform());
4270 // The scale for the perspective surface is not known, so it is rendered 1:1
4271 // with the screen, and then scaled during drawing.
4272 gfx::Transform expected_perspective_surface_draw_transform
;
4273 expected_perspective_surface_draw_transform
.Translate(
4274 device_scale_factor
* page_scale_factor
*
4275 perspective_surface
->position().x(),
4276 device_scale_factor
* page_scale_factor
*
4277 perspective_surface
->position().y());
4278 expected_perspective_surface_draw_transform
.PreconcatTransform(
4279 perspective_matrix
);
4280 expected_perspective_surface_draw_transform
.PreconcatTransform(
4281 scale_small_matrix
);
4282 gfx::Transform expected_perspective_surface_layer_draw_transform
;
4283 expected_perspective_surface_layer_draw_transform
.Scale(
4284 device_scale_factor
* page_scale_factor
,
4285 device_scale_factor
* page_scale_factor
);
4286 EXPECT_TRANSFORMATION_MATRIX_EQ(
4287 expected_perspective_surface_draw_transform
,
4288 perspective_surface
->render_surface()->draw_transform());
4289 EXPECT_TRANSFORMATION_MATRIX_EQ(
4290 expected_perspective_surface_layer_draw_transform
,
4291 perspective_surface
->draw_transform());
4294 // TODO(sohanjg): Remove this test when ContentLayer is removed.
4295 TEST_F(LayerTreeHostCommonTest
,
4296 LayerTransformsInHighDPIAccurateScaleZeroChildPosition
) {
4297 // Verify draw and screen space transforms of layers not in a surface.
4298 MockContentLayerClient delegate
;
4299 gfx::Transform identity_matrix
;
4301 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4302 SetLayerPropertiesForTesting(parent
.get(),
4306 gfx::Size(133, 133),
4310 scoped_refptr
<ContentLayer
> child
= CreateDrawableContentLayer(&delegate
);
4311 SetLayerPropertiesForTesting(child
.get(),
4319 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4320 CreateNoScaleDrawableContentLayer(&delegate
);
4321 SetLayerPropertiesForTesting(child_no_scale
.get(),
4329 parent
->AddChild(child
);
4330 parent
->AddChild(child_no_scale
);
4332 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4333 host
->SetRootLayer(parent
);
4335 float device_scale_factor
= 1.7f
;
4336 float page_scale_factor
= 1.f
;
4338 RenderSurfaceLayerList render_surface_layer_list
;
4339 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4340 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4341 inputs
.device_scale_factor
= device_scale_factor
;
4342 inputs
.page_scale_factor
= page_scale_factor
;
4343 inputs
.page_scale_application_layer
= parent
.get();
4344 inputs
.can_adjust_raster_scales
= true;
4345 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4347 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4348 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, child
);
4349 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4351 EXPECT_EQ(1u, render_surface_layer_list
.size());
4353 // Verify parent transforms
4354 gfx::Transform expected_parent_transform
;
4355 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4356 parent
->screen_space_transform());
4357 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4358 parent
->draw_transform());
4360 // Verify results of transformed parent rects
4361 gfx::RectF
parent_content_bounds(parent
->content_bounds());
4363 gfx::RectF parent_draw_rect
=
4364 MathUtil::MapClippedRect(parent
->draw_transform(), parent_content_bounds
);
4365 gfx::RectF parent_screen_space_rect
= MathUtil::MapClippedRect(
4366 parent
->screen_space_transform(), parent_content_bounds
);
4368 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
4369 expected_parent_draw_rect
.Scale(device_scale_factor
);
4370 expected_parent_draw_rect
.set_width(ceil(expected_parent_draw_rect
.width()));
4371 expected_parent_draw_rect
.set_height(
4372 ceil(expected_parent_draw_rect
.height()));
4373 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
4374 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
4376 // Verify child transforms
4377 gfx::Transform expected_child_transform
;
4378 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4379 child
->draw_transform());
4380 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4381 child
->screen_space_transform());
4383 // Verify results of transformed child rects
4384 gfx::RectF
child_content_bounds(child
->content_bounds());
4386 gfx::RectF child_draw_rect
=
4387 MathUtil::MapClippedRect(child
->draw_transform(), child_content_bounds
);
4388 gfx::RectF child_screen_space_rect
= MathUtil::MapClippedRect(
4389 child
->screen_space_transform(), child_content_bounds
);
4391 gfx::RectF
expected_child_draw_rect(child
->bounds());
4392 expected_child_draw_rect
.Scale(device_scale_factor
);
4393 expected_child_draw_rect
.set_width(ceil(expected_child_draw_rect
.width()));
4394 expected_child_draw_rect
.set_height(ceil(expected_child_draw_rect
.height()));
4395 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
4396 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
4398 // Verify child_no_scale transforms
4399 gfx::Transform expected_child_no_scale_transform
= child
->draw_transform();
4400 // All transforms operate on content rects. The child's content rect
4401 // incorporates device scale, but the child_no_scale does not; add it here.
4402 expected_child_no_scale_transform
.Scale(device_scale_factor
,
4403 device_scale_factor
);
4404 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4405 child_no_scale
->draw_transform());
4406 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4407 child_no_scale
->screen_space_transform());
4410 // TODO(sohanjg): Remove this test when ContentLayer is removed.
4411 TEST_F(LayerTreeHostCommonTest
, ContentsScale
) {
4412 MockContentLayerClient delegate
;
4413 gfx::Transform identity_matrix
;
4415 gfx::Transform parent_scale_matrix
;
4416 SkMScalar initial_parent_scale
= 1.75;
4417 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4419 gfx::Transform child_scale_matrix
;
4420 SkMScalar initial_child_scale
= 1.25;
4421 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4423 scoped_refptr
<Layer
> root
= Layer::Create();
4424 root
->SetBounds(gfx::Size(100, 100));
4426 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4427 SetLayerPropertiesForTesting(parent
.get(),
4428 parent_scale_matrix
,
4431 gfx::Size(100, 100),
4435 scoped_refptr
<ContentLayer
> child_scale
=
4436 CreateDrawableContentLayer(&delegate
);
4437 SetLayerPropertiesForTesting(child_scale
.get(),
4440 gfx::PointF(2.f
, 2.f
),
4445 scoped_refptr
<ContentLayer
> child_empty
=
4446 CreateDrawableContentLayer(&delegate
);
4447 SetLayerPropertiesForTesting(child_empty
.get(),
4450 gfx::PointF(2.f
, 2.f
),
4455 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4456 CreateNoScaleDrawableContentLayer(&delegate
);
4457 SetLayerPropertiesForTesting(child_no_scale
.get(),
4460 gfx::PointF(12.f
, 12.f
),
4465 root
->AddChild(parent
);
4467 parent
->AddChild(child_scale
);
4468 parent
->AddChild(child_empty
);
4469 parent
->AddChild(child_no_scale
);
4471 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4472 host
->SetRootLayer(root
);
4474 float device_scale_factor
= 2.5f
;
4475 float page_scale_factor
= 1.f
;
4478 RenderSurfaceLayerList render_surface_layer_list
;
4479 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4480 root
.get(), root
->bounds(), &render_surface_layer_list
);
4481 inputs
.device_scale_factor
= device_scale_factor
;
4482 inputs
.page_scale_factor
= page_scale_factor
;
4483 inputs
.page_scale_application_layer
= root
.get();
4484 inputs
.can_adjust_raster_scales
= true;
4485 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4487 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4488 initial_parent_scale
, parent
);
4489 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4490 initial_parent_scale
* initial_child_scale
,
4492 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4493 initial_parent_scale
* initial_child_scale
,
4495 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4497 // The parent is scaled up and shouldn't need to scale during draw. The
4498 // child that can scale its contents should also not need to scale during
4499 // draw. This shouldn't change if the child has empty bounds. The other
4501 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(0, 0));
4502 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(1, 1));
4503 EXPECT_FLOAT_EQ(1.0, child_scale
->draw_transform().matrix().get(0, 0));
4504 EXPECT_FLOAT_EQ(1.0, child_scale
->draw_transform().matrix().get(1, 1));
4505 EXPECT_FLOAT_EQ(1.0, child_empty
->draw_transform().matrix().get(0, 0));
4506 EXPECT_FLOAT_EQ(1.0, child_empty
->draw_transform().matrix().get(1, 1));
4507 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4508 initial_parent_scale
* initial_child_scale
,
4509 child_no_scale
->draw_transform().matrix().get(0, 0));
4510 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4511 initial_parent_scale
* initial_child_scale
,
4512 child_no_scale
->draw_transform().matrix().get(1, 1));
4515 // If the device_scale_factor or page_scale_factor changes, then it should be
4516 // updated using the initial transform as the raster scale.
4517 device_scale_factor
= 2.25f
;
4518 page_scale_factor
= 1.25f
;
4521 RenderSurfaceLayerList render_surface_layer_list
;
4522 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4523 root
.get(), root
->bounds(), &render_surface_layer_list
);
4524 inputs
.device_scale_factor
= device_scale_factor
;
4525 inputs
.page_scale_factor
= page_scale_factor
;
4526 inputs
.page_scale_application_layer
= root
.get();
4527 inputs
.can_adjust_raster_scales
= true;
4528 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4530 EXPECT_CONTENTS_SCALE_EQ(
4531 device_scale_factor
* page_scale_factor
* initial_parent_scale
, parent
);
4532 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4533 initial_parent_scale
* initial_child_scale
,
4535 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4536 initial_parent_scale
* initial_child_scale
,
4538 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4541 // If the transform changes, we expect the raster scale to be reset to 1.0.
4542 SkMScalar second_child_scale
= 1.75;
4543 child_scale_matrix
.Scale(second_child_scale
/ initial_child_scale
,
4544 second_child_scale
/ initial_child_scale
);
4545 child_scale
->SetTransform(child_scale_matrix
);
4546 child_empty
->SetTransform(child_scale_matrix
);
4549 RenderSurfaceLayerList render_surface_layer_list
;
4550 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4551 root
.get(), root
->bounds(), &render_surface_layer_list
);
4552 inputs
.device_scale_factor
= device_scale_factor
;
4553 inputs
.page_scale_factor
= page_scale_factor
;
4554 inputs
.page_scale_application_layer
= root
.get();
4555 inputs
.can_adjust_raster_scales
= true;
4556 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4558 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4559 initial_parent_scale
,
4561 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4563 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4565 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4568 // If the device_scale_factor or page_scale_factor changes, then it should be
4569 // updated, but still using 1.0 as the raster scale.
4570 device_scale_factor
= 2.75f
;
4571 page_scale_factor
= 1.75f
;
4574 RenderSurfaceLayerList render_surface_layer_list
;
4575 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4576 root
.get(), root
->bounds(), &render_surface_layer_list
);
4577 inputs
.device_scale_factor
= device_scale_factor
;
4578 inputs
.page_scale_factor
= page_scale_factor
;
4579 inputs
.page_scale_application_layer
= root
.get();
4580 inputs
.can_adjust_raster_scales
= true;
4581 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4583 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4584 initial_parent_scale
,
4586 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4588 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4590 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4594 // TODO(sohanjg): Remove this test when ContentLayer is removed.
4595 TEST_F(LayerTreeHostCommonTest
,
4596 ContentsScale_LayerTransformsDontAffectContentsScale
) {
4597 MockContentLayerClient delegate
;
4598 gfx::Transform identity_matrix
;
4600 gfx::Transform parent_scale_matrix
;
4601 SkMScalar initial_parent_scale
= 1.75;
4602 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4604 gfx::Transform child_scale_matrix
;
4605 SkMScalar initial_child_scale
= 1.25;
4606 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4608 scoped_refptr
<Layer
> root
= Layer::Create();
4609 root
->SetBounds(gfx::Size(100, 100));
4611 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4612 SetLayerPropertiesForTesting(parent
.get(),
4613 parent_scale_matrix
,
4616 gfx::Size(100, 100),
4620 scoped_refptr
<ContentLayer
> child_scale
=
4621 CreateDrawableContentLayer(&delegate
);
4622 SetLayerPropertiesForTesting(child_scale
.get(),
4625 gfx::PointF(2.f
, 2.f
),
4630 scoped_refptr
<ContentLayer
> child_empty
=
4631 CreateDrawableContentLayer(&delegate
);
4632 SetLayerPropertiesForTesting(child_empty
.get(),
4635 gfx::PointF(2.f
, 2.f
),
4640 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4641 CreateNoScaleDrawableContentLayer(&delegate
);
4642 SetLayerPropertiesForTesting(child_no_scale
.get(),
4645 gfx::PointF(12.f
, 12.f
),
4650 root
->AddChild(parent
);
4652 parent
->AddChild(child_scale
);
4653 parent
->AddChild(child_empty
);
4654 parent
->AddChild(child_no_scale
);
4656 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4657 host
->SetRootLayer(root
);
4659 RenderSurfaceLayerList render_surface_layer_list
;
4661 float device_scale_factor
= 2.5f
;
4662 float page_scale_factor
= 1.f
;
4664 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4665 root
.get(), root
->bounds(), &render_surface_layer_list
);
4666 inputs
.device_scale_factor
= device_scale_factor
;
4667 inputs
.page_scale_factor
= page_scale_factor
;
4668 inputs
.page_scale_application_layer
= root
.get(),
4669 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4671 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4672 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4674 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4676 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4678 // Since the transform scale does not affect contents scale, it should affect
4679 // the draw transform instead.
4680 EXPECT_FLOAT_EQ(initial_parent_scale
,
4681 parent
->draw_transform().matrix().get(0, 0));
4682 EXPECT_FLOAT_EQ(initial_parent_scale
,
4683 parent
->draw_transform().matrix().get(1, 1));
4684 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4685 child_scale
->draw_transform().matrix().get(0, 0));
4686 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4687 child_scale
->draw_transform().matrix().get(1, 1));
4688 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4689 child_empty
->draw_transform().matrix().get(0, 0));
4690 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4691 child_empty
->draw_transform().matrix().get(1, 1));
4692 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4693 initial_parent_scale
* initial_child_scale
,
4694 child_no_scale
->draw_transform().matrix().get(0, 0));
4695 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4696 initial_parent_scale
* initial_child_scale
,
4697 child_no_scale
->draw_transform().matrix().get(1, 1));
4700 TEST_F(LayerTreeHostCommonTest
, SmallIdealScale
) {
4701 MockContentLayerClient delegate
;
4702 gfx::Transform identity_matrix
;
4704 gfx::Transform parent_scale_matrix
;
4705 SkMScalar initial_parent_scale
= 1.75;
4706 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4708 gfx::Transform child_scale_matrix
;
4709 SkMScalar initial_child_scale
= 0.25;
4710 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4712 scoped_refptr
<Layer
> root
= Layer::Create();
4713 root
->SetBounds(gfx::Size(100, 100));
4715 scoped_refptr
<FakePictureLayer
> parent
=
4716 CreateDrawablePictureLayer(&delegate
);
4717 SetLayerPropertiesForTesting(parent
.get(),
4718 parent_scale_matrix
,
4721 gfx::Size(100, 100),
4725 scoped_refptr
<FakePictureLayer
> child_scale
=
4726 CreateDrawablePictureLayer(&delegate
);
4727 SetLayerPropertiesForTesting(child_scale
.get(),
4730 gfx::PointF(2.f
, 2.f
),
4735 root
->AddChild(parent
);
4737 parent
->AddChild(child_scale
);
4739 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4740 host
->SetRootLayer(root
);
4742 float device_scale_factor
= 2.5f
;
4743 float page_scale_factor
= 0.01f
;
4746 RenderSurfaceLayerList render_surface_layer_list
;
4747 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4748 root
.get(), root
->bounds(), &render_surface_layer_list
);
4749 inputs
.device_scale_factor
= device_scale_factor
;
4750 inputs
.page_scale_factor
= page_scale_factor
;
4751 inputs
.page_scale_application_layer
= root
.get();
4752 inputs
.can_adjust_raster_scales
= true;
4753 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4755 // The ideal scale is able to go below 1.
4756 float expected_ideal_scale
=
4757 device_scale_factor
* page_scale_factor
* initial_parent_scale
;
4758 EXPECT_LT(expected_ideal_scale
, 1.f
);
4759 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, parent
);
4761 expected_ideal_scale
= device_scale_factor
* page_scale_factor
*
4762 initial_parent_scale
* initial_child_scale
;
4763 EXPECT_LT(expected_ideal_scale
, 1.f
);
4764 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, child_scale
);
4768 TEST_F(LayerTreeHostCommonTest
, ContentsScaleForSurfaces
) {
4769 MockContentLayerClient delegate
;
4770 gfx::Transform identity_matrix
;
4772 gfx::Transform parent_scale_matrix
;
4773 SkMScalar initial_parent_scale
= 2.0;
4774 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4776 gfx::Transform child_scale_matrix
;
4777 SkMScalar initial_child_scale
= 3.0;
4778 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4780 scoped_refptr
<Layer
> root
= Layer::Create();
4781 root
->SetBounds(gfx::Size(100, 100));
4783 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4784 SetLayerPropertiesForTesting(parent
.get(),
4785 parent_scale_matrix
,
4788 gfx::Size(100, 100),
4792 scoped_refptr
<ContentLayer
> surface_scale
=
4793 CreateDrawableContentLayer(&delegate
);
4794 SetLayerPropertiesForTesting(surface_scale
.get(),
4797 gfx::PointF(2.f
, 2.f
),
4802 scoped_refptr
<ContentLayer
> surface_scale_child_scale
=
4803 CreateDrawableContentLayer(&delegate
);
4804 SetLayerPropertiesForTesting(surface_scale_child_scale
.get(),
4812 scoped_refptr
<NoScaleContentLayer
> surface_scale_child_no_scale
=
4813 CreateNoScaleDrawableContentLayer(&delegate
);
4814 SetLayerPropertiesForTesting(surface_scale_child_no_scale
.get(),
4822 scoped_refptr
<NoScaleContentLayer
> surface_no_scale
=
4823 CreateNoScaleDrawableContentLayer(&delegate
);
4824 SetLayerPropertiesForTesting(surface_no_scale
.get(),
4827 gfx::PointF(12.f
, 12.f
),
4832 scoped_refptr
<ContentLayer
> surface_no_scale_child_scale
=
4833 CreateDrawableContentLayer(&delegate
);
4834 SetLayerPropertiesForTesting(surface_no_scale_child_scale
.get(),
4842 scoped_refptr
<NoScaleContentLayer
> surface_no_scale_child_no_scale
=
4843 CreateNoScaleDrawableContentLayer(&delegate
);
4844 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale
.get(),
4852 root
->AddChild(parent
);
4854 parent
->AddChild(surface_scale
);
4855 parent
->AddChild(surface_no_scale
);
4857 surface_scale
->SetForceRenderSurface(true);
4858 surface_scale
->AddChild(surface_scale_child_scale
);
4859 surface_scale
->AddChild(surface_scale_child_no_scale
);
4861 surface_no_scale
->SetForceRenderSurface(true);
4862 surface_no_scale
->AddChild(surface_no_scale_child_scale
);
4863 surface_no_scale
->AddChild(surface_no_scale_child_no_scale
);
4865 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4866 host
->SetRootLayer(root
);
4868 SkMScalar device_scale_factor
= 5;
4869 SkMScalar page_scale_factor
= 7;
4871 RenderSurfaceLayerList render_surface_layer_list
;
4872 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4873 root
.get(), root
->bounds(), &render_surface_layer_list
);
4874 inputs
.device_scale_factor
= device_scale_factor
;
4875 inputs
.page_scale_factor
= page_scale_factor
;
4876 inputs
.page_scale_application_layer
= root
.get();
4877 inputs
.can_adjust_raster_scales
= true;
4878 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4880 EXPECT_CONTENTS_SCALE_EQ(
4881 device_scale_factor
* page_scale_factor
* initial_parent_scale
, parent
);
4882 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4883 initial_parent_scale
* initial_child_scale
,
4885 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale
);
4886 EXPECT_CONTENTS_SCALE_EQ(
4887 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4888 initial_child_scale
* initial_child_scale
,
4889 surface_scale_child_scale
);
4890 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale
);
4891 EXPECT_CONTENTS_SCALE_EQ(
4892 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4893 initial_child_scale
* initial_child_scale
,
4894 surface_no_scale_child_scale
);
4895 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale
);
4897 // The parent is scaled up and shouldn't need to scale during draw.
4898 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(0, 0));
4899 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(1, 1));
4901 // RenderSurfaces should always be 1:1 with their target.
4904 surface_scale
->render_surface()->draw_transform().matrix().get(0, 0));
4907 surface_scale
->render_surface()->draw_transform().matrix().get(1, 1));
4909 // The surface_scale can apply contents scale so the layer shouldn't need to
4910 // scale during draw.
4911 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(0, 0));
4912 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(1, 1));
4914 // The surface_scale_child_scale can apply contents scale so it shouldn't need
4915 // to scale during draw.
4917 1.0, surface_scale_child_scale
->draw_transform().matrix().get(0, 0));
4919 1.0, surface_scale_child_scale
->draw_transform().matrix().get(1, 1));
4921 // The surface_scale_child_no_scale can not apply contents scale, so it needs
4922 // to be scaled during draw.
4924 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4925 initial_child_scale
* initial_child_scale
,
4926 surface_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
4928 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4929 initial_child_scale
* initial_child_scale
,
4930 surface_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
4932 // RenderSurfaces should always be 1:1 with their target.
4935 surface_no_scale
->render_surface()->draw_transform().matrix().get(0, 0));
4938 surface_no_scale
->render_surface()->draw_transform().matrix().get(1, 1));
4940 // The surface_no_scale layer can not apply contents scale, so it needs to be
4941 // scaled during draw.
4942 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4943 initial_parent_scale
* initial_child_scale
,
4944 surface_no_scale
->draw_transform().matrix().get(0, 0));
4945 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4946 initial_parent_scale
* initial_child_scale
,
4947 surface_no_scale
->draw_transform().matrix().get(1, 1));
4949 // The surface_scale_child_scale can apply contents scale so it shouldn't need
4950 // to scale during draw.
4952 1.0, surface_no_scale_child_scale
->draw_transform().matrix().get(0, 0));
4954 1.0, surface_no_scale_child_scale
->draw_transform().matrix().get(1, 1));
4956 // The surface_scale_child_no_scale can not apply contents scale, so it needs
4957 // to be scaled during draw.
4959 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4960 initial_child_scale
* initial_child_scale
,
4961 surface_no_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
4963 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4964 initial_child_scale
* initial_child_scale
,
4965 surface_no_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
4968 // TODO(sohanjg): Remove this test when ContentLayer is removed.
4969 TEST_F(LayerTreeHostCommonTest
,
4970 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale
) {
4971 MockContentLayerClient delegate
;
4972 gfx::Transform identity_matrix
;
4974 gfx::Transform parent_scale_matrix
;
4975 SkMScalar initial_parent_scale
= 2.0;
4976 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4978 gfx::Transform child_scale_matrix
;
4979 SkMScalar initial_child_scale
= 3.0;
4980 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4982 scoped_refptr
<Layer
> root
= Layer::Create();
4983 root
->SetBounds(gfx::Size(100, 100));
4985 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4986 SetLayerPropertiesForTesting(parent
.get(),
4987 parent_scale_matrix
,
4990 gfx::Size(100, 100),
4994 scoped_refptr
<ContentLayer
> surface_scale
=
4995 CreateDrawableContentLayer(&delegate
);
4996 SetLayerPropertiesForTesting(surface_scale
.get(),
4999 gfx::PointF(2.f
, 2.f
),
5004 scoped_refptr
<ContentLayer
> surface_scale_child_scale
=
5005 CreateDrawableContentLayer(&delegate
);
5006 SetLayerPropertiesForTesting(surface_scale_child_scale
.get(),
5014 scoped_refptr
<NoScaleContentLayer
> surface_scale_child_no_scale
=
5015 CreateNoScaleDrawableContentLayer(&delegate
);
5016 SetLayerPropertiesForTesting(surface_scale_child_no_scale
.get(),
5024 scoped_refptr
<NoScaleContentLayer
> surface_no_scale
=
5025 CreateNoScaleDrawableContentLayer(&delegate
);
5026 SetLayerPropertiesForTesting(surface_no_scale
.get(),
5029 gfx::PointF(12.f
, 12.f
),
5034 scoped_refptr
<ContentLayer
> surface_no_scale_child_scale
=
5035 CreateDrawableContentLayer(&delegate
);
5036 SetLayerPropertiesForTesting(surface_no_scale_child_scale
.get(),
5044 scoped_refptr
<NoScaleContentLayer
> surface_no_scale_child_no_scale
=
5045 CreateNoScaleDrawableContentLayer(&delegate
);
5046 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale
.get(),
5054 root
->AddChild(parent
);
5056 parent
->AddChild(surface_scale
);
5057 parent
->AddChild(surface_no_scale
);
5059 surface_scale
->SetForceRenderSurface(true);
5060 surface_scale
->AddChild(surface_scale_child_scale
);
5061 surface_scale
->AddChild(surface_scale_child_no_scale
);
5063 surface_no_scale
->SetForceRenderSurface(true);
5064 surface_no_scale
->AddChild(surface_no_scale_child_scale
);
5065 surface_no_scale
->AddChild(surface_no_scale_child_no_scale
);
5067 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5068 host
->SetRootLayer(root
);
5070 RenderSurfaceLayerList render_surface_layer_list
;
5072 SkMScalar device_scale_factor
= 5.0;
5073 SkMScalar page_scale_factor
= 7.0;
5074 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5075 root
.get(), root
->bounds(), &render_surface_layer_list
);
5076 inputs
.device_scale_factor
= device_scale_factor
;
5077 inputs
.page_scale_factor
= page_scale_factor
;
5078 inputs
.page_scale_application_layer
= root
.get();
5079 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5081 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5083 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5085 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_no_scale
);
5086 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5087 surface_scale_child_scale
);
5088 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_scale_child_no_scale
);
5089 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5090 surface_no_scale_child_scale
);
5091 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_no_scale_child_no_scale
);
5093 // The parent is scaled up during draw, since its contents are not scaled by
5094 // the transform hierarchy.
5095 EXPECT_FLOAT_EQ(initial_parent_scale
,
5096 parent
->draw_transform().matrix().get(0, 0));
5097 EXPECT_FLOAT_EQ(initial_parent_scale
,
5098 parent
->draw_transform().matrix().get(1, 1));
5100 // The child surface is scaled up during draw since its subtree is not scaled
5101 // by the transform hierarchy.
5103 initial_parent_scale
* initial_child_scale
,
5104 surface_scale
->render_surface()->draw_transform().matrix().get(0, 0));
5106 initial_parent_scale
* initial_child_scale
,
5107 surface_scale
->render_surface()->draw_transform().matrix().get(1, 1));
5109 // The surface_scale's RenderSurface is scaled during draw, so the layer does
5110 // not need to be scaled when drawing into its surface.
5111 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(0, 0));
5112 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(1, 1));
5114 // The surface_scale_child_scale is scaled when drawing into its surface,
5115 // since its content bounds are not scaled by the transform hierarchy.
5117 initial_child_scale
,
5118 surface_scale_child_scale
->draw_transform().matrix().get(0, 0));
5120 initial_child_scale
,
5121 surface_scale_child_scale
->draw_transform().matrix().get(1, 1));
5123 // The surface_scale_child_no_scale has a fixed contents scale of 1, so it
5124 // needs to be scaled by the device and page scale factors, along with the
5125 // transform hierarchy.
5127 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5128 surface_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5130 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5131 surface_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5133 // The child surface is scaled up during draw since its subtree is not scaled
5134 // by the transform hierarchy.
5136 initial_parent_scale
* initial_child_scale
,
5137 surface_no_scale
->render_surface()->draw_transform().matrix().get(0, 0));
5139 initial_parent_scale
* initial_child_scale
,
5140 surface_no_scale
->render_surface()->draw_transform().matrix().get(1, 1));
5142 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
5143 // be scaled by the device and page scale factors. Its surface is already
5144 // scaled by the transform hierarchy so those don't need to scale the layer's
5146 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
,
5147 surface_no_scale
->draw_transform().matrix().get(0, 0));
5148 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
,
5149 surface_no_scale
->draw_transform().matrix().get(1, 1));
5151 // The surface_no_scale_child_scale has its contents scaled by the page and
5152 // device scale factors, but needs to be scaled by the transform hierarchy
5155 initial_child_scale
,
5156 surface_no_scale_child_scale
->draw_transform().matrix().get(0, 0));
5158 initial_child_scale
,
5159 surface_no_scale_child_scale
->draw_transform().matrix().get(1, 1));
5161 // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it
5162 // needs to be scaled by the device and page scale factors. It also needs to
5163 // be scaled by any transform heirarchy below its target surface.
5165 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5166 surface_no_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5168 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5169 surface_no_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5172 TEST_F(LayerTreeHostCommonTest
, IdealScaleForAnimatingLayer
) {
5173 MockContentLayerClient delegate
;
5174 gfx::Transform identity_matrix
;
5176 gfx::Transform parent_scale_matrix
;
5177 SkMScalar initial_parent_scale
= 1.75;
5178 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
5180 gfx::Transform child_scale_matrix
;
5181 SkMScalar initial_child_scale
= 1.25;
5182 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
5184 scoped_refptr
<Layer
> root
= Layer::Create();
5185 root
->SetBounds(gfx::Size(100, 100));
5187 scoped_refptr
<FakePictureLayer
> parent
=
5188 CreateDrawablePictureLayer(&delegate
);
5189 SetLayerPropertiesForTesting(parent
.get(),
5190 parent_scale_matrix
,
5193 gfx::Size(100, 100),
5197 scoped_refptr
<FakePictureLayer
> child_scale
=
5198 CreateDrawablePictureLayer(&delegate
);
5199 SetLayerPropertiesForTesting(child_scale
.get(),
5202 gfx::PointF(2.f
, 2.f
),
5207 root
->AddChild(parent
);
5209 parent
->AddChild(child_scale
);
5211 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5212 host
->SetRootLayer(root
);
5215 RenderSurfaceLayerList render_surface_layer_list
;
5216 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5217 root
.get(), root
->bounds(), &render_surface_layer_list
);
5218 inputs
.can_adjust_raster_scales
= true;
5219 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5221 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale
, parent
);
5222 // Animating layers compute ideal scale in the same way as when
5224 EXPECT_IDEAL_SCALE_EQ(initial_child_scale
* initial_parent_scale
,
5229 // TODO(sohanjg): Remove this test when ContentLayer is removed.
5230 TEST_F(LayerTreeHostCommonTest
,
5231 ChangeInContentBoundsOrScaleTriggersPushProperties
) {
5232 MockContentLayerClient delegate
;
5233 scoped_refptr
<Layer
> root
= Layer::Create();
5234 scoped_refptr
<Layer
> child
= CreateDrawableContentLayer(&delegate
);
5235 root
->AddChild(child
);
5237 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5238 host
->SetRootLayer(root
);
5240 gfx::Transform identity_matrix
;
5241 SetLayerPropertiesForTesting(root
.get(),
5245 gfx::Size(100, 100),
5248 SetLayerPropertiesForTesting(child
.get(),
5252 gfx::Size(100, 100),
5256 root
->reset_needs_push_properties_for_testing();
5257 child
->reset_needs_push_properties_for_testing();
5259 // This will change both layers' content bounds.
5260 ExecuteCalculateDrawProperties(root
.get());
5261 EXPECT_TRUE(root
->needs_push_properties());
5262 EXPECT_TRUE(child
->needs_push_properties());
5264 root
->reset_needs_push_properties_for_testing();
5265 child
->reset_needs_push_properties_for_testing();
5267 // This will change only the child layer's contents scale and content bounds,
5268 // since the root layer is not a ContentsScalingLayer.
5269 ExecuteCalculateDrawProperties(root
.get(), 2.f
);
5270 EXPECT_FALSE(root
->needs_push_properties());
5271 EXPECT_TRUE(child
->needs_push_properties());
5273 root
->reset_needs_push_properties_for_testing();
5274 child
->reset_needs_push_properties_for_testing();
5276 // This will not change either layer's contents scale or content bounds.
5277 ExecuteCalculateDrawProperties(root
.get(), 2.f
);
5278 EXPECT_FALSE(root
->needs_push_properties());
5279 EXPECT_FALSE(child
->needs_push_properties());
5282 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceTransformsInHighDPI
) {
5283 MockContentLayerClient delegate
;
5284 gfx::Transform identity_matrix
;
5286 scoped_refptr
<FakePictureLayer
> parent
=
5287 CreateDrawablePictureLayer(&delegate
);
5288 SetLayerPropertiesForTesting(parent
.get(),
5296 scoped_refptr
<FakePictureLayer
> child
= CreateDrawablePictureLayer(&delegate
);
5297 SetLayerPropertiesForTesting(child
.get(),
5300 gfx::PointF(2.f
, 2.f
),
5305 gfx::Transform replica_transform
;
5306 replica_transform
.Scale(1.0, -1.0);
5307 scoped_refptr
<FakePictureLayer
> replica
=
5308 CreateDrawablePictureLayer(&delegate
);
5309 SetLayerPropertiesForTesting(replica
.get(),
5312 gfx::PointF(2.f
, 2.f
),
5317 // This layer should end up in the same surface as child, with the same draw
5318 // and screen space transforms.
5319 scoped_refptr
<FakePictureLayer
> duplicate_child_non_owner
=
5320 CreateDrawablePictureLayer(&delegate
);
5321 SetLayerPropertiesForTesting(duplicate_child_non_owner
.get(),
5329 parent
->AddChild(child
);
5330 child
->AddChild(duplicate_child_non_owner
);
5331 child
->SetReplicaLayer(replica
.get());
5333 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5334 host
->SetRootLayer(parent
);
5336 RenderSurfaceLayerList render_surface_layer_list
;
5338 float device_scale_factor
= 1.5f
;
5339 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5340 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
5341 inputs
.device_scale_factor
= device_scale_factor
;
5342 inputs
.can_adjust_raster_scales
= true;
5343 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5345 // We should have two render surfaces. The root's render surface and child's
5346 // render surface (it needs one because it has a replica layer).
5347 EXPECT_EQ(2u, render_surface_layer_list
.size());
5349 gfx::Transform expected_parent_transform
;
5350 expected_parent_transform
.Scale(device_scale_factor
, device_scale_factor
);
5351 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
5352 parent
->screen_space_transform());
5353 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
5354 parent
->draw_transform());
5356 gfx::Transform expected_draw_transform
;
5357 expected_draw_transform
.Scale(device_scale_factor
, device_scale_factor
);
5358 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform
,
5359 child
->draw_transform());
5361 gfx::Transform expected_screen_space_transform
;
5362 expected_screen_space_transform
.Scale(device_scale_factor
,
5363 device_scale_factor
);
5364 expected_screen_space_transform
.Translate(child
->position().x(),
5365 child
->position().y());
5366 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform
,
5367 child
->screen_space_transform());
5369 gfx::Transform expected_duplicate_child_draw_transform
=
5370 child
->draw_transform();
5371 EXPECT_TRANSFORMATION_MATRIX_EQ(child
->draw_transform(),
5372 duplicate_child_non_owner
->draw_transform());
5373 EXPECT_TRANSFORMATION_MATRIX_EQ(
5374 child
->screen_space_transform(),
5375 duplicate_child_non_owner
->screen_space_transform());
5376 EXPECT_RECT_EQ(child
->drawable_content_rect(),
5377 duplicate_child_non_owner
->drawable_content_rect());
5378 EXPECT_EQ(child
->content_bounds(),
5379 duplicate_child_non_owner
->content_bounds());
5381 gfx::Transform expected_render_surface_draw_transform
;
5382 expected_render_surface_draw_transform
.Translate(
5383 device_scale_factor
* child
->position().x(),
5384 device_scale_factor
* child
->position().y());
5385 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform
,
5386 child
->render_surface()->draw_transform());
5388 gfx::Transform expected_surface_draw_transform
;
5389 expected_surface_draw_transform
.Translate(device_scale_factor
* 2.f
,
5390 device_scale_factor
* 2.f
);
5391 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform
,
5392 child
->render_surface()->draw_transform());
5394 gfx::Transform expected_surface_screen_space_transform
;
5395 expected_surface_screen_space_transform
.Translate(device_scale_factor
* 2.f
,
5396 device_scale_factor
* 2.f
);
5397 EXPECT_TRANSFORMATION_MATRIX_EQ(
5398 expected_surface_screen_space_transform
,
5399 child
->render_surface()->screen_space_transform());
5401 gfx::Transform expected_replica_draw_transform
;
5402 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
5403 expected_replica_draw_transform
.matrix().set(0, 3, 6.0);
5404 expected_replica_draw_transform
.matrix().set(1, 3, 6.0);
5405 EXPECT_TRANSFORMATION_MATRIX_EQ(
5406 expected_replica_draw_transform
,
5407 child
->render_surface()->replica_draw_transform());
5409 gfx::Transform expected_replica_screen_space_transform
;
5410 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
5411 expected_replica_screen_space_transform
.matrix().set(0, 3, 6.0);
5412 expected_replica_screen_space_transform
.matrix().set(1, 3, 6.0);
5413 EXPECT_TRANSFORMATION_MATRIX_EQ(
5414 expected_replica_screen_space_transform
,
5415 child
->render_surface()->replica_screen_space_transform());
5416 EXPECT_TRANSFORMATION_MATRIX_EQ(
5417 expected_replica_screen_space_transform
,
5418 child
->render_surface()->replica_screen_space_transform());
5421 TEST_F(LayerTreeHostCommonTest
,
5422 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition
) {
5423 MockContentLayerClient delegate
;
5424 gfx::Transform identity_matrix
;
5426 scoped_refptr
<FakePictureLayer
> parent
=
5427 CreateDrawablePictureLayer(&delegate
);
5428 SetLayerPropertiesForTesting(parent
.get(),
5436 scoped_refptr
<FakePictureLayer
> child
= CreateDrawablePictureLayer(&delegate
);
5437 SetLayerPropertiesForTesting(child
.get(),
5445 gfx::Transform replica_transform
;
5446 replica_transform
.Scale(1.0, -1.0);
5447 scoped_refptr
<FakePictureLayer
> replica
=
5448 CreateDrawablePictureLayer(&delegate
);
5449 SetLayerPropertiesForTesting(replica
.get(),
5457 parent
->AddChild(child
);
5458 child
->SetReplicaLayer(replica
.get());
5460 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5461 host
->SetRootLayer(parent
);
5463 float device_scale_factor
= 1.7f
;
5465 RenderSurfaceLayerList render_surface_layer_list
;
5466 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5467 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
5468 inputs
.device_scale_factor
= device_scale_factor
;
5469 inputs
.can_adjust_raster_scales
= true;
5470 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5472 // We should have two render surfaces. The root's render surface and child's
5473 // render surface (it needs one because it has a replica layer).
5474 EXPECT_EQ(2u, render_surface_layer_list
.size());
5476 gfx::Transform identity_transform
;
5477 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5478 child
->render_surface()->draw_transform());
5479 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5480 child
->render_surface()->draw_transform());
5481 EXPECT_TRANSFORMATION_MATRIX_EQ(
5482 identity_transform
, child
->render_surface()->screen_space_transform());
5484 gfx::Transform expected_replica_draw_transform
;
5485 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
5486 EXPECT_TRANSFORMATION_MATRIX_EQ(
5487 expected_replica_draw_transform
,
5488 child
->render_surface()->replica_draw_transform());
5490 gfx::Transform expected_replica_screen_space_transform
;
5491 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
5492 EXPECT_TRANSFORMATION_MATRIX_EQ(
5493 expected_replica_screen_space_transform
,
5494 child
->render_surface()->replica_screen_space_transform());
5497 TEST_F(LayerTreeHostCommonTest
, SubtreeSearch
) {
5498 scoped_refptr
<Layer
> root
= Layer::Create();
5499 scoped_refptr
<Layer
> child
= Layer::Create();
5500 scoped_refptr
<Layer
> grand_child
= Layer::Create();
5501 scoped_refptr
<Layer
> mask_layer
= Layer::Create();
5502 scoped_refptr
<Layer
> replica_layer
= Layer::Create();
5504 grand_child
->SetReplicaLayer(replica_layer
.get());
5505 child
->AddChild(grand_child
.get());
5506 child
->SetMaskLayer(mask_layer
.get());
5507 root
->AddChild(child
.get());
5509 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5510 host
->SetRootLayer(root
);
5512 int nonexistent_id
= -1;
5513 EXPECT_EQ(root
.get(),
5514 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), root
->id()));
5515 EXPECT_EQ(child
.get(),
5516 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), child
->id()));
5519 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), grand_child
->id()));
5522 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), mask_layer
->id()));
5524 replica_layer
.get(),
5525 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), replica_layer
->id()));
5527 0, LayerTreeHostCommon::FindLayerInSubtree(root
.get(), nonexistent_id
));
5530 TEST_F(LayerTreeHostCommonTest
, TransparentChildRenderSurfaceCreation
) {
5531 scoped_refptr
<Layer
> root
= Layer::Create();
5532 scoped_refptr
<Layer
> child
= Layer::Create();
5533 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
5534 make_scoped_refptr(new LayerWithForcedDrawsContent());
5536 const gfx::Transform identity_matrix
;
5537 SetLayerPropertiesForTesting(root
.get(),
5541 gfx::Size(100, 100),
5544 SetLayerPropertiesForTesting(child
.get(),
5551 SetLayerPropertiesForTesting(grand_child
.get(),
5559 root
->AddChild(child
);
5560 child
->AddChild(grand_child
);
5561 child
->SetOpacity(0.5f
);
5563 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5564 host
->SetRootLayer(root
);
5566 ExecuteCalculateDrawProperties(root
.get());
5568 EXPECT_FALSE(child
->render_surface());
5571 TEST_F(LayerTreeHostCommonTest
, OpacityAnimatingOnPendingTree
) {
5572 FakeImplProxy proxy
;
5573 TestSharedBitmapManager shared_bitmap_manager
;
5574 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5575 host_impl
.CreatePendingTree();
5576 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
5578 const gfx::Transform identity_matrix
;
5579 SetLayerPropertiesForTesting(root
.get(),
5583 gfx::Size(100, 100),
5586 root
->SetDrawsContent(true);
5588 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
5589 SetLayerPropertiesForTesting(child
.get(),
5596 child
->SetDrawsContent(true);
5597 child
->SetOpacity(0.0f
);
5599 // Add opacity animation.
5600 AddOpacityTransitionToController(
5601 child
->layer_animation_controller(), 10.0, 0.0f
, 1.0f
, false);
5603 root
->AddChild(child
.Pass());
5605 LayerImplList render_surface_layer_list
;
5606 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5607 root
.get(), root
->bounds(), &render_surface_layer_list
);
5608 inputs
.can_adjust_raster_scales
= true;
5609 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5611 // We should have one render surface and two layers. The child
5612 // layer should be included even though it is transparent.
5613 ASSERT_EQ(1u, render_surface_layer_list
.size());
5614 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5617 typedef std::tr1::tuple
<bool, bool> LCDTextTestParam
;
5619 : public LayerTreeHostCommonTestBase
,
5620 public testing::TestWithParam
<LCDTextTestParam
> {
5622 virtual void SetUp() {
5623 can_use_lcd_text_
= std::tr1::get
<0>(GetParam());
5625 root_
= Layer::Create();
5626 child_
= Layer::Create();
5627 grand_child_
= Layer::Create();
5628 child_
->AddChild(grand_child_
.get());
5629 root_
->AddChild(child_
.get());
5631 gfx::Transform identity_matrix
;
5632 SetLayerPropertiesForTesting(root_
.get(),
5639 SetLayerPropertiesForTesting(child_
.get(),
5646 SetLayerPropertiesForTesting(grand_child_
.get(),
5654 child_
->SetForceRenderSurface(std::tr1::get
<1>(GetParam()));
5656 host_
= CreateFakeLayerTreeHost();
5657 host_
->SetRootLayer(root_
);
5660 bool can_use_lcd_text_
;
5661 scoped_ptr
<FakeLayerTreeHost
> host_
;
5662 scoped_refptr
<Layer
> root_
;
5663 scoped_refptr
<Layer
> child_
;
5664 scoped_refptr
<Layer
> grand_child_
;
5667 TEST_P(LCDTextTest
, CanUseLCDText
) {
5668 // Case 1: Identity transform.
5669 gfx::Transform identity_matrix
;
5670 ExecuteCalculateDrawProperties(
5671 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5672 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5673 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5674 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5676 // Case 2: Integral translation.
5677 gfx::Transform integral_translation
;
5678 integral_translation
.Translate(1.0, 2.0);
5679 child_
->SetTransform(integral_translation
);
5680 ExecuteCalculateDrawProperties(
5681 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5682 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5683 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5684 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5686 // Case 3: Non-integral translation.
5687 gfx::Transform non_integral_translation
;
5688 non_integral_translation
.Translate(1.5, 2.5);
5689 child_
->SetTransform(non_integral_translation
);
5690 ExecuteCalculateDrawProperties(
5691 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5692 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5693 EXPECT_FALSE(child_
->can_use_lcd_text());
5694 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5696 // Case 4: Rotation.
5697 gfx::Transform rotation
;
5698 rotation
.Rotate(10.0);
5699 child_
->SetTransform(rotation
);
5700 ExecuteCalculateDrawProperties(
5701 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5702 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5703 EXPECT_FALSE(child_
->can_use_lcd_text());
5704 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5707 gfx::Transform scale
;
5708 scale
.Scale(2.0, 2.0);
5709 child_
->SetTransform(scale
);
5710 ExecuteCalculateDrawProperties(
5711 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5712 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5713 EXPECT_FALSE(child_
->can_use_lcd_text());
5714 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5717 gfx::Transform skew
;
5719 child_
->SetTransform(skew
);
5720 ExecuteCalculateDrawProperties(
5721 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5722 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5723 EXPECT_FALSE(child_
->can_use_lcd_text());
5724 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5726 // Case 7: Translucent.
5727 child_
->SetTransform(identity_matrix
);
5728 child_
->SetOpacity(0.5f
);
5729 ExecuteCalculateDrawProperties(
5730 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5731 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5732 EXPECT_FALSE(child_
->can_use_lcd_text());
5733 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5735 // Case 8: Sanity check: restore transform and opacity.
5736 child_
->SetTransform(identity_matrix
);
5737 child_
->SetOpacity(1.f
);
5738 ExecuteCalculateDrawProperties(
5739 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5740 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5741 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5742 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5745 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimation
) {
5746 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
5747 ExecuteCalculateDrawProperties(
5748 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5749 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5750 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5751 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5753 // Add opacity animation.
5754 child_
->SetOpacity(0.9f
);
5755 AddOpacityTransitionToController(
5756 child_
->layer_animation_controller(), 10.0, 0.9f
, 0.1f
, false);
5758 ExecuteCalculateDrawProperties(
5759 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5760 // Text AA should not be adjusted while animation is active.
5761 // Make sure LCD text AA setting remains unchanged.
5762 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5763 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5764 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5767 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest
,
5769 testing::Combine(testing::Bool(), testing::Bool()));
5771 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayer
) {
5772 FakeImplProxy proxy
;
5773 TestSharedBitmapManager shared_bitmap_manager
;
5774 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5775 host_impl
.CreatePendingTree();
5776 const gfx::Transform identity_matrix
;
5778 scoped_refptr
<Layer
> root
= Layer::Create();
5779 SetLayerPropertiesForTesting(root
.get(),
5786 root
->SetIsDrawable(true);
5788 scoped_refptr
<Layer
> child
= Layer::Create();
5789 SetLayerPropertiesForTesting(child
.get(),
5796 child
->SetIsDrawable(true);
5798 scoped_refptr
<Layer
> grand_child
= Layer::Create();
5799 SetLayerPropertiesForTesting(grand_child
.get(),
5806 grand_child
->SetIsDrawable(true);
5807 grand_child
->SetHideLayerAndSubtree(true);
5809 child
->AddChild(grand_child
);
5810 root
->AddChild(child
);
5812 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5813 host
->SetRootLayer(root
);
5815 RenderSurfaceLayerList render_surface_layer_list
;
5816 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5817 root
.get(), root
->bounds(), &render_surface_layer_list
);
5818 inputs
.can_adjust_raster_scales
= true;
5819 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5821 // We should have one render surface and two layers. The grand child has
5823 ASSERT_EQ(1u, render_surface_layer_list
.size());
5824 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5825 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
5826 EXPECT_EQ(child
->id(), root
->render_surface()->layer_list().at(1)->id());
5829 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayerImpl
) {
5830 FakeImplProxy proxy
;
5831 TestSharedBitmapManager shared_bitmap_manager
;
5832 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5833 host_impl
.CreatePendingTree();
5834 const gfx::Transform identity_matrix
;
5836 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
5837 SetLayerPropertiesForTesting(root
.get(),
5844 root
->SetDrawsContent(true);
5846 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
5847 SetLayerPropertiesForTesting(child
.get(),
5854 child
->SetDrawsContent(true);
5856 scoped_ptr
<LayerImpl
> grand_child
=
5857 LayerImpl::Create(host_impl
.pending_tree(), 3);
5858 SetLayerPropertiesForTesting(grand_child
.get(),
5865 grand_child
->SetDrawsContent(true);
5866 grand_child
->SetHideLayerAndSubtree(true);
5868 child
->AddChild(grand_child
.Pass());
5869 root
->AddChild(child
.Pass());
5871 LayerImplList render_surface_layer_list
;
5872 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5873 root
.get(), root
->bounds(), &render_surface_layer_list
);
5874 inputs
.can_adjust_raster_scales
= true;
5875 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5877 // We should have one render surface and two layers. The grand child has
5879 ASSERT_EQ(1u, render_surface_layer_list
.size());
5880 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5881 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
5882 EXPECT_EQ(2, root
->render_surface()->layer_list().at(1)->id());
5885 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayers
) {
5886 FakeImplProxy proxy
;
5887 TestSharedBitmapManager shared_bitmap_manager
;
5888 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5889 host_impl
.CreatePendingTree();
5890 const gfx::Transform identity_matrix
;
5892 scoped_refptr
<Layer
> root
= Layer::Create();
5893 SetLayerPropertiesForTesting(root
.get(),
5900 root
->SetIsDrawable(true);
5902 scoped_refptr
<Layer
> child
= Layer::Create();
5903 SetLayerPropertiesForTesting(child
.get(),
5910 child
->SetIsDrawable(true);
5911 child
->SetHideLayerAndSubtree(true);
5913 scoped_refptr
<Layer
> grand_child
= Layer::Create();
5914 SetLayerPropertiesForTesting(grand_child
.get(),
5921 grand_child
->SetIsDrawable(true);
5923 child
->AddChild(grand_child
);
5924 root
->AddChild(child
);
5926 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5927 host
->SetRootLayer(root
);
5929 RenderSurfaceLayerList render_surface_layer_list
;
5930 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5931 root
.get(), root
->bounds(), &render_surface_layer_list
);
5932 inputs
.can_adjust_raster_scales
= true;
5933 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5935 // We should have one render surface and one layers. The child has
5936 // hidden itself and the grand child.
5937 ASSERT_EQ(1u, render_surface_layer_list
.size());
5938 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
5939 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
5942 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayersImpl
) {
5943 FakeImplProxy proxy
;
5944 TestSharedBitmapManager shared_bitmap_manager
;
5945 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5946 host_impl
.CreatePendingTree();
5947 const gfx::Transform identity_matrix
;
5949 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
5950 SetLayerPropertiesForTesting(root
.get(),
5957 root
->SetDrawsContent(true);
5959 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
5960 SetLayerPropertiesForTesting(child
.get(),
5967 child
->SetDrawsContent(true);
5968 child
->SetHideLayerAndSubtree(true);
5970 scoped_ptr
<LayerImpl
> grand_child
=
5971 LayerImpl::Create(host_impl
.pending_tree(), 3);
5972 SetLayerPropertiesForTesting(grand_child
.get(),
5979 grand_child
->SetDrawsContent(true);
5981 child
->AddChild(grand_child
.Pass());
5982 root
->AddChild(child
.Pass());
5984 LayerImplList render_surface_layer_list
;
5985 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5986 root
.get(), root
->bounds(), &render_surface_layer_list
);
5987 inputs
.can_adjust_raster_scales
= true;
5988 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5990 // We should have one render surface and one layers. The child has
5991 // hidden itself and the grand child.
5992 ASSERT_EQ(1u, render_surface_layer_list
.size());
5993 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
5994 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
5997 void EmptyCopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {}
5999 TEST_F(LayerTreeHostCommonTest
, SubtreeHiddenWithCopyRequest
) {
6000 FakeImplProxy proxy
;
6001 TestSharedBitmapManager shared_bitmap_manager
;
6002 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6003 host_impl
.CreatePendingTree();
6004 const gfx::Transform identity_matrix
;
6006 scoped_refptr
<Layer
> root
= Layer::Create();
6007 SetLayerPropertiesForTesting(root
.get(),
6014 root
->SetIsDrawable(true);
6016 scoped_refptr
<Layer
> copy_grand_parent
= Layer::Create();
6017 SetLayerPropertiesForTesting(copy_grand_parent
.get(),
6024 copy_grand_parent
->SetIsDrawable(true);
6026 scoped_refptr
<Layer
> copy_parent
= Layer::Create();
6027 SetLayerPropertiesForTesting(copy_parent
.get(),
6034 copy_parent
->SetIsDrawable(true);
6035 copy_parent
->SetForceRenderSurface(true);
6037 scoped_refptr
<Layer
> copy_layer
= Layer::Create();
6038 SetLayerPropertiesForTesting(copy_layer
.get(),
6045 copy_layer
->SetIsDrawable(true);
6047 scoped_refptr
<Layer
> copy_child
= Layer::Create();
6048 SetLayerPropertiesForTesting(copy_child
.get(),
6055 copy_child
->SetIsDrawable(true);
6057 scoped_refptr
<Layer
> copy_grand_parent_sibling_before
= Layer::Create();
6058 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before
.get(),
6065 copy_grand_parent_sibling_before
->SetIsDrawable(true);
6067 scoped_refptr
<Layer
> copy_grand_parent_sibling_after
= Layer::Create();
6068 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after
.get(),
6075 copy_grand_parent_sibling_after
->SetIsDrawable(true);
6077 copy_layer
->AddChild(copy_child
);
6078 copy_parent
->AddChild(copy_layer
);
6079 copy_grand_parent
->AddChild(copy_parent
);
6080 root
->AddChild(copy_grand_parent_sibling_before
);
6081 root
->AddChild(copy_grand_parent
);
6082 root
->AddChild(copy_grand_parent_sibling_after
);
6084 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6085 host
->SetRootLayer(root
);
6087 // Hide the copy_grand_parent and its subtree. But make a copy request in that
6088 // hidden subtree on copy_layer.
6089 copy_grand_parent
->SetHideLayerAndSubtree(true);
6090 copy_grand_parent_sibling_before
->SetHideLayerAndSubtree(true);
6091 copy_grand_parent_sibling_after
->SetHideLayerAndSubtree(true);
6092 copy_layer
->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6093 base::Bind(&EmptyCopyOutputCallback
)));
6094 EXPECT_TRUE(copy_layer
->HasCopyRequest());
6096 RenderSurfaceLayerList render_surface_layer_list
;
6097 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6098 root
.get(), root
->bounds(), &render_surface_layer_list
);
6099 inputs
.can_adjust_raster_scales
= true;
6100 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6102 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
6103 EXPECT_TRUE(copy_grand_parent
->draw_properties().
6104 layer_or_descendant_has_copy_request
);
6105 EXPECT_TRUE(copy_parent
->draw_properties().
6106 layer_or_descendant_has_copy_request
);
6107 EXPECT_TRUE(copy_layer
->draw_properties().
6108 layer_or_descendant_has_copy_request
);
6109 EXPECT_FALSE(copy_child
->draw_properties().
6110 layer_or_descendant_has_copy_request
);
6111 EXPECT_FALSE(copy_grand_parent_sibling_before
->draw_properties().
6112 layer_or_descendant_has_copy_request
);
6113 EXPECT_FALSE(copy_grand_parent_sibling_after
->draw_properties().
6114 layer_or_descendant_has_copy_request
);
6116 // We should have three render surfaces, one for the root, one for the parent
6117 // since it owns a surface, and one for the copy_layer.
6118 ASSERT_EQ(3u, render_surface_layer_list
.size());
6119 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
6120 EXPECT_EQ(copy_parent
->id(), render_surface_layer_list
.at(1)->id());
6121 EXPECT_EQ(copy_layer
->id(), render_surface_layer_list
.at(2)->id());
6123 // The root render surface should have 2 contributing layers. The
6124 // copy_grand_parent is hidden along with its siblings, but the copy_parent
6125 // will appear since something in its subtree needs to be drawn for a copy
6127 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
6128 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6129 EXPECT_EQ(copy_parent
->id(),
6130 root
->render_surface()->layer_list().at(1)->id());
6132 // Nothing actually draws into the copy parent, so only the copy_layer will
6133 // appear in its list, since it needs to be drawn for the copy request.
6134 ASSERT_EQ(1u, copy_parent
->render_surface()->layer_list().size());
6135 EXPECT_EQ(copy_layer
->id(),
6136 copy_parent
->render_surface()->layer_list().at(0)->id());
6138 // The copy_layer's render surface should have two contributing layers.
6139 ASSERT_EQ(2u, copy_layer
->render_surface()->layer_list().size());
6140 EXPECT_EQ(copy_layer
->id(),
6141 copy_layer
->render_surface()->layer_list().at(0)->id());
6142 EXPECT_EQ(copy_child
->id(),
6143 copy_layer
->render_surface()->layer_list().at(1)->id());
6146 TEST_F(LayerTreeHostCommonTest
, ClippedOutCopyRequest
) {
6147 FakeImplProxy proxy
;
6148 TestSharedBitmapManager shared_bitmap_manager
;
6149 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6150 host_impl
.CreatePendingTree();
6151 const gfx::Transform identity_matrix
;
6153 scoped_refptr
<Layer
> root
= Layer::Create();
6154 SetLayerPropertiesForTesting(root
.get(),
6161 root
->SetIsDrawable(true);
6163 scoped_refptr
<Layer
> copy_parent
= Layer::Create();
6164 SetLayerPropertiesForTesting(copy_parent
.get(),
6171 copy_parent
->SetIsDrawable(true);
6172 copy_parent
->SetMasksToBounds(true);
6174 scoped_refptr
<Layer
> copy_layer
= Layer::Create();
6175 SetLayerPropertiesForTesting(copy_layer
.get(),
6182 copy_layer
->SetIsDrawable(true);
6184 scoped_refptr
<Layer
> copy_child
= Layer::Create();
6185 SetLayerPropertiesForTesting(copy_child
.get(),
6192 copy_child
->SetIsDrawable(true);
6194 copy_layer
->AddChild(copy_child
);
6195 copy_parent
->AddChild(copy_layer
);
6196 root
->AddChild(copy_parent
);
6198 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6199 host
->SetRootLayer(root
);
6201 copy_layer
->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6202 base::Bind(&EmptyCopyOutputCallback
)));
6203 EXPECT_TRUE(copy_layer
->HasCopyRequest());
6205 RenderSurfaceLayerList render_surface_layer_list
;
6206 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6207 root
.get(), root
->bounds(), &render_surface_layer_list
);
6208 inputs
.can_adjust_raster_scales
= true;
6209 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6211 // We should have one render surface, as the others are clipped out.
6212 ASSERT_EQ(1u, render_surface_layer_list
.size());
6213 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
6215 // The root render surface should only have 1 contributing layer, since the
6216 // other layers are empty/clipped away.
6217 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
6218 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6221 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInsideSurface
) {
6222 FakeImplProxy proxy
;
6223 TestSharedBitmapManager shared_bitmap_manager
;
6224 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6225 host_impl
.CreatePendingTree();
6226 const gfx::Transform identity_matrix
;
6228 scoped_refptr
<Layer
> root
= Layer::Create();
6229 SetLayerPropertiesForTesting(root
.get(),
6236 root
->SetIsDrawable(true);
6238 // The surface is moved slightly outside of the viewport.
6239 scoped_refptr
<Layer
> surface
= Layer::Create();
6240 SetLayerPropertiesForTesting(surface
.get(),
6243 gfx::PointF(-10, -20),
6247 surface
->SetForceRenderSurface(true);
6249 scoped_refptr
<Layer
> surface_child
= Layer::Create();
6250 SetLayerPropertiesForTesting(surface_child
.get(),
6257 surface_child
->SetIsDrawable(true);
6259 surface
->AddChild(surface_child
);
6260 root
->AddChild(surface
);
6262 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6263 host
->SetRootLayer(root
);
6265 RenderSurfaceLayerList render_surface_layer_list
;
6266 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6267 root
.get(), root
->bounds(), &render_surface_layer_list
);
6268 inputs
.can_adjust_raster_scales
= true;
6269 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6271 // The visible_content_rect for the |surface_child| should not be clipped by
6273 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
6274 surface_child
->visible_content_rect().ToString());
6277 TEST_F(LayerTreeHostCommonTest
, TransformedClipParent
) {
6278 // Ensure that a transform between the layer and its render surface is not a
6279 // problem. Constructs the following layer tree.
6281 // root (a render surface)
6283 // + clip_parent (scaled)
6284 // + intervening_clipping_layer
6287 // The render surface should be resized correctly and the clip child should
6288 // inherit the right clip rect.
6289 scoped_refptr
<Layer
> root
= Layer::Create();
6290 scoped_refptr
<Layer
> render_surface
= Layer::Create();
6291 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6292 scoped_refptr
<Layer
> intervening
= Layer::Create();
6293 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6294 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6296 root
->AddChild(render_surface
);
6297 render_surface
->AddChild(clip_parent
);
6298 clip_parent
->AddChild(intervening
);
6299 intervening
->AddChild(clip_child
);
6301 clip_child
->SetClipParent(clip_parent
.get());
6303 intervening
->SetMasksToBounds(true);
6304 clip_parent
->SetMasksToBounds(true);
6306 render_surface
->SetForceRenderSurface(true);
6308 gfx::Transform scale_transform
;
6309 scale_transform
.Scale(2, 2);
6311 gfx::Transform identity_transform
;
6313 SetLayerPropertiesForTesting(root
.get(),
6320 SetLayerPropertiesForTesting(render_surface
.get(),
6327 SetLayerPropertiesForTesting(clip_parent
.get(),
6330 gfx::PointF(1.f
, 1.f
),
6334 SetLayerPropertiesForTesting(intervening
.get(),
6337 gfx::PointF(1.f
, 1.f
),
6341 SetLayerPropertiesForTesting(clip_child
.get(),
6344 gfx::PointF(1.f
, 1.f
),
6349 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6350 host
->SetRootLayer(root
);
6352 ExecuteCalculateDrawProperties(root
.get());
6354 ASSERT_TRUE(root
->render_surface());
6355 ASSERT_TRUE(render_surface
->render_surface());
6357 // Ensure that we've inherited our clip parent's clip and weren't affected
6358 // by the intervening clip layer.
6359 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
6360 clip_parent
->clip_rect().ToString());
6361 ASSERT_EQ(clip_parent
->clip_rect().ToString(),
6362 clip_child
->clip_rect().ToString());
6363 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
6364 intervening
->clip_rect().ToString());
6366 // Ensure that the render surface reports a content rect that has been grown
6367 // to accomodate for the clip child.
6368 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
6369 render_surface
->render_surface()->content_rect().ToString());
6371 // The above check implies the two below, but they nicely demonstrate that
6372 // we've grown, despite the intervening layer's clip.
6373 ASSERT_TRUE(clip_parent
->clip_rect().Contains(
6374 render_surface
->render_surface()->content_rect()));
6375 ASSERT_FALSE(intervening
->clip_rect().Contains(
6376 render_surface
->render_surface()->content_rect()));
6379 TEST_F(LayerTreeHostCommonTest
, ClipParentWithInterveningRenderSurface
) {
6380 // Ensure that intervening render surfaces are not a problem in the basic
6381 // case. In the following tree, both render surfaces should be resized to
6382 // accomodate for the clip child, despite an intervening clip.
6384 // root (a render surface)
6385 // + clip_parent (masks to bounds)
6386 // + render_surface1 (sets opacity)
6387 // + intervening (masks to bounds)
6388 // + render_surface2 (also sets opacity)
6391 scoped_refptr
<Layer
> root
= Layer::Create();
6392 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6393 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
6394 scoped_refptr
<Layer
> intervening
= Layer::Create();
6395 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
6396 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6397 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6399 root
->AddChild(clip_parent
);
6400 clip_parent
->AddChild(render_surface1
);
6401 render_surface1
->AddChild(intervening
);
6402 intervening
->AddChild(render_surface2
);
6403 render_surface2
->AddChild(clip_child
);
6405 clip_child
->SetClipParent(clip_parent
.get());
6407 intervening
->SetMasksToBounds(true);
6408 clip_parent
->SetMasksToBounds(true);
6410 render_surface1
->SetForceRenderSurface(true);
6411 render_surface2
->SetForceRenderSurface(true);
6413 gfx::Transform translation_transform
;
6414 translation_transform
.Translate(2, 2);
6416 gfx::Transform identity_transform
;
6417 SetLayerPropertiesForTesting(root
.get(),
6424 SetLayerPropertiesForTesting(clip_parent
.get(),
6425 translation_transform
,
6427 gfx::PointF(1.f
, 1.f
),
6431 SetLayerPropertiesForTesting(render_surface1
.get(),
6438 SetLayerPropertiesForTesting(intervening
.get(),
6441 gfx::PointF(1.f
, 1.f
),
6445 SetLayerPropertiesForTesting(render_surface2
.get(),
6452 SetLayerPropertiesForTesting(clip_child
.get(),
6455 gfx::PointF(-10.f
, -10.f
),
6460 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6461 host
->SetRootLayer(root
);
6463 ExecuteCalculateDrawProperties(root
.get());
6465 EXPECT_TRUE(root
->render_surface());
6466 EXPECT_TRUE(render_surface1
->render_surface());
6467 EXPECT_TRUE(render_surface2
->render_surface());
6469 // Since the render surfaces could have expanded, they should not clip (their
6470 // bounds would no longer be reliable). We should resort to layer clipping
6472 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6473 render_surface1
->render_surface()->clip_rect().ToString());
6474 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6475 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6476 render_surface2
->render_surface()->clip_rect().ToString());
6477 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
6479 // NB: clip rects are in target space.
6480 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6481 render_surface1
->clip_rect().ToString());
6482 EXPECT_TRUE(render_surface1
->is_clipped());
6484 // This value is inherited from the clipping ancestor layer, 'intervening'.
6485 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6486 render_surface2
->clip_rect().ToString());
6487 EXPECT_TRUE(render_surface2
->is_clipped());
6489 // The content rects of both render surfaces should both have expanded to
6490 // contain the clip child.
6491 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6492 render_surface1
->render_surface()->content_rect().ToString());
6493 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6494 render_surface2
->render_surface()->content_rect().ToString());
6496 // The clip child should have inherited the clip parent's clip (projected to
6497 // the right space, of course), and should have the correctly sized visible
6499 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6500 clip_child
->clip_rect().ToString());
6501 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
6502 clip_child
->visible_content_rect().ToString());
6503 EXPECT_TRUE(clip_child
->is_clipped());
6506 TEST_F(LayerTreeHostCommonTest
, ClipParentScrolledInterveningLayer
) {
6507 // Ensure that intervening render surfaces are not a problem, even if there
6508 // is a scroll involved. Note, we do _not_ have to consider any other sort
6511 // root (a render surface)
6512 // + clip_parent (masks to bounds)
6513 // + render_surface1 (sets opacity)
6514 // + intervening (masks to bounds AND scrolls)
6515 // + render_surface2 (also sets opacity)
6518 scoped_refptr
<Layer
> root
= Layer::Create();
6519 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6520 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
6521 scoped_refptr
<Layer
> intervening
= Layer::Create();
6522 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
6523 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6524 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6526 root
->AddChild(clip_parent
);
6527 clip_parent
->AddChild(render_surface1
);
6528 render_surface1
->AddChild(intervening
);
6529 intervening
->AddChild(render_surface2
);
6530 render_surface2
->AddChild(clip_child
);
6532 clip_child
->SetClipParent(clip_parent
.get());
6534 intervening
->SetMasksToBounds(true);
6535 clip_parent
->SetMasksToBounds(true);
6536 intervening
->SetScrollClipLayerId(clip_parent
->id());
6537 intervening
->SetScrollOffset(gfx::ScrollOffset(3, 3));
6539 render_surface1
->SetForceRenderSurface(true);
6540 render_surface2
->SetForceRenderSurface(true);
6542 gfx::Transform translation_transform
;
6543 translation_transform
.Translate(2, 2);
6545 gfx::Transform identity_transform
;
6546 SetLayerPropertiesForTesting(root
.get(),
6553 SetLayerPropertiesForTesting(clip_parent
.get(),
6554 translation_transform
,
6556 gfx::PointF(1.f
, 1.f
),
6560 SetLayerPropertiesForTesting(render_surface1
.get(),
6567 SetLayerPropertiesForTesting(intervening
.get(),
6570 gfx::PointF(1.f
, 1.f
),
6574 SetLayerPropertiesForTesting(render_surface2
.get(),
6581 SetLayerPropertiesForTesting(clip_child
.get(),
6584 gfx::PointF(-10.f
, -10.f
),
6589 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6590 host
->SetRootLayer(root
);
6592 ExecuteCalculateDrawProperties(root
.get());
6594 EXPECT_TRUE(root
->render_surface());
6595 EXPECT_TRUE(render_surface1
->render_surface());
6596 EXPECT_TRUE(render_surface2
->render_surface());
6598 // Since the render surfaces could have expanded, they should not clip (their
6599 // bounds would no longer be reliable). We should resort to layer clipping
6601 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6602 render_surface1
->render_surface()->clip_rect().ToString());
6603 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6604 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6605 render_surface2
->render_surface()->clip_rect().ToString());
6606 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
6608 // NB: clip rects are in target space.
6609 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6610 render_surface1
->clip_rect().ToString());
6611 EXPECT_TRUE(render_surface1
->is_clipped());
6613 // This value is inherited from the clipping ancestor layer, 'intervening'.
6614 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
6615 render_surface2
->clip_rect().ToString());
6616 EXPECT_TRUE(render_surface2
->is_clipped());
6618 // The content rects of both render surfaces should both have expanded to
6619 // contain the clip child.
6620 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6621 render_surface1
->render_surface()->content_rect().ToString());
6622 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6623 render_surface2
->render_surface()->content_rect().ToString());
6625 // The clip child should have inherited the clip parent's clip (projected to
6626 // the right space, of course), and should have the correctly sized visible
6628 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6629 clip_child
->clip_rect().ToString());
6630 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
6631 clip_child
->visible_content_rect().ToString());
6632 EXPECT_TRUE(clip_child
->is_clipped());
6635 TEST_F(LayerTreeHostCommonTest
, DescendantsOfClipChildren
) {
6636 // Ensures that descendants of the clip child inherit the correct clip.
6638 // root (a render surface)
6639 // + clip_parent (masks to bounds)
6640 // + intervening (masks to bounds)
6644 scoped_refptr
<Layer
> root
= Layer::Create();
6645 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6646 scoped_refptr
<Layer
> intervening
= Layer::Create();
6647 scoped_refptr
<Layer
> clip_child
= Layer::Create();
6648 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
6649 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6651 root
->AddChild(clip_parent
);
6652 clip_parent
->AddChild(intervening
);
6653 intervening
->AddChild(clip_child
);
6654 clip_child
->AddChild(child
);
6656 clip_child
->SetClipParent(clip_parent
.get());
6658 intervening
->SetMasksToBounds(true);
6659 clip_parent
->SetMasksToBounds(true);
6661 gfx::Transform identity_transform
;
6662 SetLayerPropertiesForTesting(root
.get(),
6669 SetLayerPropertiesForTesting(clip_parent
.get(),
6676 SetLayerPropertiesForTesting(intervening
.get(),
6683 SetLayerPropertiesForTesting(clip_child
.get(),
6690 SetLayerPropertiesForTesting(child
.get(),
6698 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6699 host
->SetRootLayer(root
);
6701 ExecuteCalculateDrawProperties(root
.get());
6703 EXPECT_TRUE(root
->render_surface());
6705 // Neither the clip child nor its descendant should have inherited the clip
6706 // from |intervening|.
6707 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6708 clip_child
->clip_rect().ToString());
6709 EXPECT_TRUE(clip_child
->is_clipped());
6710 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6711 child
->visible_content_rect().ToString());
6712 EXPECT_TRUE(child
->is_clipped());
6715 TEST_F(LayerTreeHostCommonTest
,
6716 SurfacesShouldBeUnaffectedByNonDescendantClipChildren
) {
6717 // Ensures that non-descendant clip children in the tree do not affect
6720 // root (a render surface)
6721 // + clip_parent (masks to bounds)
6722 // + render_surface1
6724 // + render_surface2
6727 // In this example render_surface2 should be unaffected by clip_child.
6728 scoped_refptr
<Layer
> root
= Layer::Create();
6729 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6730 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
6731 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6732 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6733 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
6734 scoped_refptr
<LayerWithForcedDrawsContent
> non_clip_child
=
6735 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6737 root
->AddChild(clip_parent
);
6738 clip_parent
->AddChild(render_surface1
);
6739 render_surface1
->AddChild(clip_child
);
6740 clip_parent
->AddChild(render_surface2
);
6741 render_surface2
->AddChild(non_clip_child
);
6743 clip_child
->SetClipParent(clip_parent
.get());
6745 clip_parent
->SetMasksToBounds(true);
6746 render_surface1
->SetMasksToBounds(true);
6748 gfx::Transform identity_transform
;
6749 SetLayerPropertiesForTesting(root
.get(),
6756 SetLayerPropertiesForTesting(clip_parent
.get(),
6763 SetLayerPropertiesForTesting(render_surface1
.get(),
6770 SetLayerPropertiesForTesting(render_surface2
.get(),
6777 SetLayerPropertiesForTesting(clip_child
.get(),
6784 SetLayerPropertiesForTesting(non_clip_child
.get(),
6792 render_surface1
->SetForceRenderSurface(true);
6793 render_surface2
->SetForceRenderSurface(true);
6795 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6796 host
->SetRootLayer(root
);
6798 ExecuteCalculateDrawProperties(root
.get());
6800 EXPECT_TRUE(root
->render_surface());
6801 EXPECT_TRUE(render_surface1
->render_surface());
6802 EXPECT_TRUE(render_surface2
->render_surface());
6804 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6805 render_surface1
->clip_rect().ToString());
6806 EXPECT_TRUE(render_surface1
->is_clipped());
6808 // The render surface should not clip (it has unclipped descendants), instead
6809 // it should rely on layer clipping.
6810 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6811 render_surface1
->render_surface()->clip_rect().ToString());
6812 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6814 // That said, it should have grown to accomodate the unclipped descendant.
6815 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
6816 render_surface1
->render_surface()->content_rect().ToString());
6818 // This render surface should clip. It has no unclipped descendants.
6819 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6820 render_surface2
->clip_rect().ToString());
6821 EXPECT_TRUE(render_surface2
->render_surface()->is_clipped());
6823 // It also shouldn't have grown to accomodate the clip child.
6824 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6825 render_surface2
->render_surface()->content_rect().ToString());
6827 // Sanity check our num_unclipped_descendants values.
6828 EXPECT_EQ(1, render_surface1
->num_unclipped_descendants());
6829 EXPECT_EQ(0, render_surface2
->num_unclipped_descendants());
6832 TEST_F(LayerTreeHostCommonTest
, CanRenderToSeparateSurface
) {
6833 FakeImplProxy proxy
;
6834 TestSharedBitmapManager shared_bitmap_manager
;
6835 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6836 scoped_ptr
<LayerImpl
> root
=
6837 LayerImpl::Create(host_impl
.active_tree(), 12345);
6838 scoped_ptr
<LayerImpl
> child1
=
6839 LayerImpl::Create(host_impl
.active_tree(), 123456);
6840 scoped_ptr
<LayerImpl
> child2
=
6841 LayerImpl::Create(host_impl
.active_tree(), 1234567);
6842 scoped_ptr
<LayerImpl
> child3
=
6843 LayerImpl::Create(host_impl
.active_tree(), 12345678);
6845 gfx::Transform identity_matrix
;
6846 gfx::Point3F transform_origin
;
6847 gfx::PointF position
;
6848 gfx::Size
bounds(100, 100);
6849 SetLayerPropertiesForTesting(root
.get(),
6856 root
->SetDrawsContent(true);
6858 // This layer structure normally forces render surface due to preserves3d
6860 SetLayerPropertiesForTesting(child1
.get(),
6867 child1
->SetDrawsContent(true);
6868 SetLayerPropertiesForTesting(child2
.get(),
6875 child2
->SetDrawsContent(true);
6876 SetLayerPropertiesForTesting(child3
.get(),
6883 child3
->SetDrawsContent(true);
6885 child2
->Set3dSortingContextId(1);
6886 child3
->Set3dSortingContextId(1);
6888 child2
->AddChild(child3
.Pass());
6889 child1
->AddChild(child2
.Pass());
6890 root
->AddChild(child1
.Pass());
6893 LayerImplList render_surface_layer_list
;
6894 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root
.get());
6895 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6896 root
.get(), root
->bounds(), &render_surface_layer_list
);
6897 inputs
.can_render_to_separate_surface
= true;
6898 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6900 EXPECT_EQ(2u, render_surface_layer_list
.size());
6904 LayerImplList render_surface_layer_list
;
6905 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6906 root
.get(), root
->bounds(), &render_surface_layer_list
);
6907 inputs
.can_render_to_separate_surface
= false;
6908 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6910 EXPECT_EQ(1u, render_surface_layer_list
.size());
6914 TEST_F(LayerTreeHostCommonTest
, DoNotIncludeBackfaceInvisibleSurfaces
) {
6915 scoped_refptr
<Layer
> root
= Layer::Create();
6916 scoped_refptr
<Layer
> render_surface
= Layer::Create();
6917 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
6918 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6920 root
->AddChild(render_surface
);
6921 render_surface
->AddChild(child
);
6923 gfx::Transform identity_transform
;
6924 SetLayerPropertiesForTesting(root
.get(),
6931 SetLayerPropertiesForTesting(render_surface
.get(),
6938 SetLayerPropertiesForTesting(child
.get(),
6946 root
->SetShouldFlattenTransform(false);
6947 root
->Set3dSortingContextId(1);
6948 render_surface
->SetDoubleSided(false);
6949 render_surface
->SetForceRenderSurface(true);
6951 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6952 host
->SetRootLayer(root
);
6954 ExecuteCalculateDrawProperties(root
.get());
6956 EXPECT_EQ(2u, render_surface_layer_list()->size());
6958 render_surface_layer_list()->at(0)
6959 ->render_surface()->layer_list().size());
6961 render_surface_layer_list()->at(1)
6962 ->render_surface()->layer_list().size());
6964 gfx::Transform rotation_transform
= identity_transform
;
6965 rotation_transform
.RotateAboutXAxis(180.0);
6967 render_surface
->SetTransform(rotation_transform
);
6969 ExecuteCalculateDrawProperties(root
.get());
6971 EXPECT_EQ(1u, render_surface_layer_list()->size());
6973 render_surface_layer_list()->at(0)
6974 ->render_surface()->layer_list().size());
6977 TEST_F(LayerTreeHostCommonTest
, ClippedByScrollParent
) {
6978 // Checks that the simple case (being clipped by a scroll parent that would
6979 // have been processed before you anyhow) results in the right clips.
6982 // + scroll_parent_border
6983 // | + scroll_parent_clip
6984 // | + scroll_parent
6987 scoped_refptr
<Layer
> root
= Layer::Create();
6988 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
6989 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
6990 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
6991 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6992 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
6993 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6995 root
->AddChild(scroll_child
);
6997 root
->AddChild(scroll_parent_border
);
6998 scroll_parent_border
->AddChild(scroll_parent_clip
);
6999 scroll_parent_clip
->AddChild(scroll_parent
);
7001 scroll_parent_clip
->SetMasksToBounds(true);
7003 scroll_child
->SetScrollParent(scroll_parent
.get());
7005 gfx::Transform identity_transform
;
7006 SetLayerPropertiesForTesting(root
.get(),
7013 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7020 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7027 SetLayerPropertiesForTesting(scroll_parent
.get(),
7034 SetLayerPropertiesForTesting(scroll_child
.get(),
7042 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7043 host
->SetRootLayer(root
);
7045 ExecuteCalculateDrawProperties(root
.get());
7047 EXPECT_TRUE(root
->render_surface());
7049 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7050 scroll_child
->clip_rect().ToString());
7051 EXPECT_TRUE(scroll_child
->is_clipped());
7054 TEST_F(LayerTreeHostCommonTest
, SingularTransformSubtreesDoNotDraw
) {
7055 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
7056 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7057 scoped_refptr
<LayerWithForcedDrawsContent
> parent
=
7058 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7059 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7060 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7062 root
->AddChild(parent
);
7063 parent
->AddChild(child
);
7065 gfx::Transform identity_transform
;
7066 SetLayerPropertiesForTesting(root
.get(),
7073 root
->SetForceRenderSurface(true);
7074 SetLayerPropertiesForTesting(parent
.get(),
7081 parent
->SetForceRenderSurface(true);
7082 SetLayerPropertiesForTesting(child
.get(),
7089 child
->SetForceRenderSurface(true);
7091 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7092 host
->SetRootLayer(root
);
7094 ExecuteCalculateDrawProperties(root
.get());
7096 EXPECT_EQ(3u, render_surface_layer_list()->size());
7098 gfx::Transform singular_transform
;
7099 singular_transform
.Scale3d(
7100 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
7102 child
->SetTransform(singular_transform
);
7104 ExecuteCalculateDrawProperties(root
.get());
7106 EXPECT_EQ(2u, render_surface_layer_list()->size());
7108 // Ensure that the entire subtree under a layer with singular transform does
7109 // not get rendered.
7110 parent
->SetTransform(singular_transform
);
7111 child
->SetTransform(identity_transform
);
7113 ExecuteCalculateDrawProperties(root
.get());
7115 EXPECT_EQ(1u, render_surface_layer_list()->size());
7118 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollParent
) {
7119 // Checks that clipping by a scroll parent that follows you in paint order
7120 // still results in correct clipping.
7124 // + scroll_parent_border
7125 // + scroll_parent_clip
7128 scoped_refptr
<Layer
> root
= Layer::Create();
7129 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7130 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7131 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7132 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7133 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7134 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7136 root
->AddChild(scroll_parent_border
);
7137 scroll_parent_border
->AddChild(scroll_parent_clip
);
7138 scroll_parent_clip
->AddChild(scroll_parent
);
7140 root
->AddChild(scroll_child
);
7142 scroll_parent_clip
->SetMasksToBounds(true);
7144 scroll_child
->SetScrollParent(scroll_parent
.get());
7146 gfx::Transform identity_transform
;
7147 SetLayerPropertiesForTesting(root
.get(),
7154 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7161 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7168 SetLayerPropertiesForTesting(scroll_parent
.get(),
7175 SetLayerPropertiesForTesting(scroll_child
.get(),
7183 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7184 host
->SetRootLayer(root
);
7186 ExecuteCalculateDrawProperties(root
.get());
7188 EXPECT_TRUE(root
->render_surface());
7190 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7191 scroll_child
->clip_rect().ToString());
7192 EXPECT_TRUE(scroll_child
->is_clipped());
7195 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollGrandparent
) {
7196 // Checks that clipping by a scroll parent and scroll grandparent that follow
7197 // you in paint order still results in correct clipping.
7201 // + scroll_parent_border
7202 // | + scroll_parent_clip
7203 // | + scroll_parent
7204 // + scroll_grandparent_border
7205 // + scroll_grandparent_clip
7206 // + scroll_grandparent
7208 scoped_refptr
<Layer
> root
= Layer::Create();
7209 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7210 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7211 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7212 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7214 scoped_refptr
<Layer
> scroll_grandparent_border
= Layer::Create();
7215 scoped_refptr
<Layer
> scroll_grandparent_clip
= Layer::Create();
7216 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_grandparent
=
7217 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7219 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7220 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7222 root
->AddChild(scroll_child
);
7224 root
->AddChild(scroll_parent_border
);
7225 scroll_parent_border
->AddChild(scroll_parent_clip
);
7226 scroll_parent_clip
->AddChild(scroll_parent
);
7228 root
->AddChild(scroll_grandparent_border
);
7229 scroll_grandparent_border
->AddChild(scroll_grandparent_clip
);
7230 scroll_grandparent_clip
->AddChild(scroll_grandparent
);
7232 scroll_parent_clip
->SetMasksToBounds(true);
7233 scroll_grandparent_clip
->SetMasksToBounds(true);
7235 scroll_child
->SetScrollParent(scroll_parent
.get());
7236 scroll_parent_border
->SetScrollParent(scroll_grandparent
.get());
7238 gfx::Transform identity_transform
;
7239 SetLayerPropertiesForTesting(root
.get(),
7246 SetLayerPropertiesForTesting(scroll_grandparent_border
.get(),
7253 SetLayerPropertiesForTesting(scroll_grandparent_clip
.get(),
7260 SetLayerPropertiesForTesting(scroll_grandparent
.get(),
7267 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7274 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7281 SetLayerPropertiesForTesting(scroll_parent
.get(),
7288 SetLayerPropertiesForTesting(scroll_child
.get(),
7296 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7297 host
->SetRootLayer(root
);
7299 ExecuteCalculateDrawProperties(root
.get());
7301 EXPECT_TRUE(root
->render_surface());
7303 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7304 scroll_child
->clip_rect().ToString());
7305 EXPECT_TRUE(scroll_child
->is_clipped());
7307 // Despite the fact that we visited the above layers out of order to get the
7308 // correct clip, the layer lists should be unaffected.
7309 EXPECT_EQ(3u, root
->render_surface()->layer_list().size());
7310 EXPECT_EQ(scroll_child
.get(),
7311 root
->render_surface()->layer_list().at(0).get());
7312 EXPECT_EQ(scroll_parent
.get(),
7313 root
->render_surface()->layer_list().at(1).get());
7314 EXPECT_EQ(scroll_grandparent
.get(),
7315 root
->render_surface()->layer_list().at(2).get());
7318 TEST_F(LayerTreeHostCommonTest
, OutOfOrderClippingRequiresRSLLSorting
) {
7319 // Ensures that even if we visit layers out of order, we still produce a
7320 // correctly ordered render surface layer list.
7323 // + scroll_parent_border
7324 // + scroll_parent_clip
7326 // + render_surface1
7327 // + scroll_grandparent_border
7328 // + scroll_grandparent_clip
7329 // + scroll_grandparent
7330 // + render_surface2
7332 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
7333 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7335 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7336 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7337 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7338 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7339 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface1
=
7340 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7342 scoped_refptr
<Layer
> scroll_grandparent_border
= Layer::Create();
7343 scoped_refptr
<Layer
> scroll_grandparent_clip
= Layer::Create();
7344 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_grandparent
=
7345 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7346 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface2
=
7347 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7349 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7350 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7352 root
->AddChild(scroll_child
);
7354 root
->AddChild(scroll_parent_border
);
7355 scroll_parent_border
->AddChild(scroll_parent_clip
);
7356 scroll_parent_clip
->AddChild(scroll_parent
);
7357 scroll_parent
->AddChild(render_surface2
);
7359 root
->AddChild(scroll_grandparent_border
);
7360 scroll_grandparent_border
->AddChild(scroll_grandparent_clip
);
7361 scroll_grandparent_clip
->AddChild(scroll_grandparent
);
7362 scroll_grandparent
->AddChild(render_surface1
);
7364 scroll_parent_clip
->SetMasksToBounds(true);
7365 scroll_grandparent_clip
->SetMasksToBounds(true);
7367 scroll_child
->SetScrollParent(scroll_parent
.get());
7368 scroll_parent_border
->SetScrollParent(scroll_grandparent
.get());
7370 render_surface1
->SetForceRenderSurface(true);
7371 render_surface2
->SetForceRenderSurface(true);
7373 gfx::Transform identity_transform
;
7374 SetLayerPropertiesForTesting(root
.get(),
7381 SetLayerPropertiesForTesting(scroll_grandparent_border
.get(),
7388 SetLayerPropertiesForTesting(scroll_grandparent_clip
.get(),
7395 SetLayerPropertiesForTesting(scroll_grandparent
.get(),
7402 SetLayerPropertiesForTesting(render_surface1
.get(),
7409 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7416 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7423 SetLayerPropertiesForTesting(scroll_parent
.get(),
7430 SetLayerPropertiesForTesting(render_surface2
.get(),
7437 SetLayerPropertiesForTesting(scroll_child
.get(),
7445 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7446 host
->SetRootLayer(root
);
7448 RenderSurfaceLayerList render_surface_layer_list
;
7449 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
7453 &render_surface_layer_list
);
7455 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7457 EXPECT_TRUE(root
->render_surface());
7459 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7460 scroll_child
->clip_rect().ToString());
7461 EXPECT_TRUE(scroll_child
->is_clipped());
7463 // Despite the fact that we had to process the layers out of order to get the
7464 // right clip, our render_surface_layer_list's order should be unaffected.
7465 EXPECT_EQ(3u, render_surface_layer_list
.size());
7466 EXPECT_EQ(root
.get(), render_surface_layer_list
.at(0));
7467 EXPECT_EQ(render_surface2
.get(), render_surface_layer_list
.at(1));
7468 EXPECT_EQ(render_surface1
.get(), render_surface_layer_list
.at(2));
7469 EXPECT_TRUE(render_surface_layer_list
.at(0)->render_surface());
7470 EXPECT_TRUE(render_surface_layer_list
.at(1)->render_surface());
7471 EXPECT_TRUE(render_surface_layer_list
.at(2)->render_surface());
7474 TEST_F(LayerTreeHostCommonTest
, DoNotClobberSorting
) {
7475 // We rearrange layer list contributions if we have to visit children out of
7476 // order, but it should be a 'stable' rearrangement. That is, the layer list
7477 // additions for a single layer should not be reordered, though their position
7478 // wrt to the contributions due to a sibling may vary.
7484 // + scroll_parent_border
7485 // + scroll_parent_clip
7488 FakeImplProxy proxy
;
7489 TestSharedBitmapManager shared_bitmap_manager
;
7490 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7491 host_impl
.CreatePendingTree();
7492 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7493 scoped_ptr
<LayerImpl
> scroll_parent_border
=
7494 LayerImpl::Create(host_impl
.active_tree(), 2);
7495 scoped_ptr
<LayerImpl
> scroll_parent_clip
=
7496 LayerImpl::Create(host_impl
.active_tree(), 3);
7497 scoped_ptr
<LayerImpl
> scroll_parent
=
7498 LayerImpl::Create(host_impl
.active_tree(), 4);
7499 scoped_ptr
<LayerImpl
> scroll_child
=
7500 LayerImpl::Create(host_impl
.active_tree(), 5);
7501 scoped_ptr
<LayerImpl
> bottom_content
=
7502 LayerImpl::Create(host_impl
.active_tree(), 6);
7503 scoped_ptr
<LayerImpl
> top_content
=
7504 LayerImpl::Create(host_impl
.active_tree(), 7);
7506 scroll_parent_clip
->SetMasksToBounds(true);
7508 scroll_child
->SetScrollParent(scroll_parent
.get());
7509 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
7510 scroll_children
->insert(scroll_child
.get());
7511 scroll_parent
->SetScrollChildren(scroll_children
.release());
7513 scroll_child
->SetDrawsContent(true);
7514 scroll_parent
->SetDrawsContent(true);
7515 top_content
->SetDrawsContent(true);
7516 bottom_content
->SetDrawsContent(true);
7518 gfx::Transform identity_transform
;
7519 gfx::Transform top_transform
;
7520 top_transform
.Translate3d(0.0, 0.0, 5.0);
7521 gfx::Transform bottom_transform
;
7522 bottom_transform
.Translate3d(0.0, 0.0, 3.0);
7524 SetLayerPropertiesForTesting(root
.get(),
7531 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7538 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7545 SetLayerPropertiesForTesting(scroll_parent
.get(),
7552 SetLayerPropertiesForTesting(scroll_child
.get(),
7559 SetLayerPropertiesForTesting(top_content
.get(),
7566 SetLayerPropertiesForTesting(bottom_content
.get(),
7574 scroll_child
->SetShouldFlattenTransform(false);
7575 scroll_child
->Set3dSortingContextId(1);
7577 scroll_child
->AddChild(top_content
.Pass());
7578 scroll_child
->AddChild(bottom_content
.Pass());
7579 root
->AddChild(scroll_child
.Pass());
7581 scroll_parent_clip
->AddChild(scroll_parent
.Pass());
7582 scroll_parent_border
->AddChild(scroll_parent_clip
.Pass());
7583 root
->AddChild(scroll_parent_border
.Pass());
7585 LayerImplList render_surface_layer_list
;
7586 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7587 root
.get(), root
->bounds(), &render_surface_layer_list
);
7589 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7591 EXPECT_TRUE(root
->render_surface());
7593 // If we don't sort by depth and let the layers get added in the order they
7594 // would normally be visited in, then layers 6 and 7 will be out of order. In
7595 // other words, although we've had to shift 5, 6, and 7 to appear before 4
7596 // in the list (because of the scroll parent relationship), this should not
7597 // have an effect on the the order of 5, 6, and 7 (which had been reordered
7598 // due to layer sorting).
7599 EXPECT_EQ(4u, root
->render_surface()->layer_list().size());
7600 EXPECT_EQ(5, root
->render_surface()->layer_list().at(0)->id());
7601 EXPECT_EQ(6, root
->render_surface()->layer_list().at(1)->id());
7602 EXPECT_EQ(7, root
->render_surface()->layer_list().at(2)->id());
7603 EXPECT_EQ(4, root
->render_surface()->layer_list().at(3)->id());
7606 TEST_F(LayerTreeHostCommonTest
, ScrollCompensationWithRounding
) {
7607 // This test verifies that a scrolling layer that gets snapped to
7608 // integer coordinates doesn't move a fixed position child.
7615 FakeImplProxy proxy
;
7616 TestSharedBitmapManager shared_bitmap_manager
;
7617 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7618 host_impl
.CreatePendingTree();
7619 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7620 scoped_ptr
<LayerImpl
> container
=
7621 LayerImpl::Create(host_impl
.active_tree(), 2);
7622 LayerImpl
* container_layer
= container
.get();
7623 scoped_ptr
<LayerImpl
> scroller
=
7624 LayerImpl::Create(host_impl
.active_tree(), 3);
7625 LayerImpl
* scroll_layer
= scroller
.get();
7626 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
7627 LayerImpl
* fixed_layer
= fixed
.get();
7629 container
->SetIsContainerForFixedPositionLayers(true);
7631 LayerPositionConstraint constraint
;
7632 constraint
.set_is_fixed_position(true);
7633 fixed
->SetPositionConstraint(constraint
);
7635 scroller
->SetScrollClipLayer(container
->id());
7637 gfx::Transform identity_transform
;
7638 gfx::Transform container_transform
;
7639 container_transform
.Translate3d(10.0, 20.0, 0.0);
7640 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
7642 SetLayerPropertiesForTesting(root
.get(),
7649 SetLayerPropertiesForTesting(container
.get(),
7650 container_transform
,
7656 SetLayerPropertiesForTesting(scroller
.get(),
7663 SetLayerPropertiesForTesting(fixed
.get(),
7671 scroller
->AddChild(fixed
.Pass());
7672 container
->AddChild(scroller
.Pass());
7673 root
->AddChild(container
.Pass());
7675 // Rounded to integers already.
7677 gfx::Vector2dF
scroll_delta(3.0, 5.0);
7678 scroll_layer
->SetScrollDelta(scroll_delta
);
7680 LayerImplList render_surface_layer_list
;
7681 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7682 root
.get(), root
->bounds(), &render_surface_layer_list
);
7683 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7685 EXPECT_TRANSFORMATION_MATRIX_EQ(
7686 container_layer
->draw_properties().screen_space_transform
,
7687 fixed_layer
->draw_properties().screen_space_transform
);
7689 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7691 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
7692 .screen_space_transform
.To2dTranslation(),
7693 container_offset
- scroll_delta
);
7696 // Scroll delta requiring rounding.
7698 gfx::Vector2dF
scroll_delta(4.1f
, 8.1f
);
7699 scroll_layer
->SetScrollDelta(scroll_delta
);
7701 gfx::Vector2dF
rounded_scroll_delta(4.f
, 8.f
);
7703 LayerImplList render_surface_layer_list
;
7704 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7705 root
.get(), root
->bounds(), &render_surface_layer_list
);
7706 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7708 EXPECT_TRANSFORMATION_MATRIX_EQ(
7709 container_layer
->draw_properties().screen_space_transform
,
7710 fixed_layer
->draw_properties().screen_space_transform
);
7712 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7714 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
7715 .screen_space_transform
.To2dTranslation(),
7716 container_offset
- rounded_scroll_delta
);
7719 // Scale is applied earlier in the tree.
7721 gfx::Transform scaled_container_transform
= container_transform
;
7722 scaled_container_transform
.Scale3d(3.0, 3.0, 1.0);
7723 container_layer
->SetTransform(scaled_container_transform
);
7725 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
7726 scroll_layer
->SetScrollDelta(scroll_delta
);
7728 LayerImplList render_surface_layer_list
;
7729 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7730 root
.get(), root
->bounds(), &render_surface_layer_list
);
7731 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7733 EXPECT_TRANSFORMATION_MATRIX_EQ(
7734 container_layer
->draw_properties().screen_space_transform
,
7735 fixed_layer
->draw_properties().screen_space_transform
);
7737 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7740 container_layer
->SetTransform(container_transform
);
7743 // Scale is applied on the scroll layer itself.
7745 gfx::Transform scale_transform
;
7746 scale_transform
.Scale3d(3.0, 3.0, 1.0);
7747 scroll_layer
->SetTransform(scale_transform
);
7749 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
7750 scroll_layer
->SetScrollDelta(scroll_delta
);
7752 LayerImplList render_surface_layer_list
;
7753 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7754 root
.get(), root
->bounds(), &render_surface_layer_list
);
7755 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7758 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7761 scroll_layer
->SetTransform(identity_transform
);
7765 class AnimationScaleFactorTrackingLayerImpl
: public LayerImpl
{
7767 static scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> Create(
7768 LayerTreeImpl
* tree_impl
,
7770 return make_scoped_ptr(
7771 new AnimationScaleFactorTrackingLayerImpl(tree_impl
, id
));
7774 ~AnimationScaleFactorTrackingLayerImpl() override
{}
7777 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl
* tree_impl
,
7779 : LayerImpl(tree_impl
, id
) {
7780 SetDrawsContent(true);
7784 TEST_F(LayerTreeHostCommonTest
, MaximumAnimationScaleFactor
) {
7785 FakeImplProxy proxy
;
7786 TestSharedBitmapManager shared_bitmap_manager
;
7787 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7788 gfx::Transform identity_matrix
;
7789 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_parent
=
7790 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 1);
7791 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> parent
=
7792 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 2);
7793 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> child
=
7794 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 3);
7795 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_child
=
7796 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 4);
7798 AnimationScaleFactorTrackingLayerImpl
* parent_raw
= parent
.get();
7799 AnimationScaleFactorTrackingLayerImpl
* child_raw
= child
.get();
7800 AnimationScaleFactorTrackingLayerImpl
* grand_child_raw
= grand_child
.get();
7802 child
->AddChild(grand_child
.Pass());
7803 parent
->AddChild(child
.Pass());
7804 grand_parent
->AddChild(parent
.Pass());
7806 SetLayerPropertiesForTesting(grand_parent
.get(),
7813 SetLayerPropertiesForTesting(parent_raw
,
7820 SetLayerPropertiesForTesting(child_raw
,
7827 SetLayerPropertiesForTesting(grand_child_raw
,
7835 ExecuteCalculateDrawProperties(grand_parent
.get());
7837 // No layers have animations.
7839 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7841 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7842 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7844 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7846 TransformOperations translation
;
7847 translation
.AppendTranslate(1.f
, 2.f
, 3.f
);
7849 AddAnimatedTransformToLayer(
7850 parent_raw
, 1.0, TransformOperations(), translation
);
7852 // No layers have scale-affecting animations.
7854 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7856 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7857 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7859 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7861 TransformOperations scale
;
7862 scale
.AppendScale(5.f
, 4.f
, 3.f
);
7864 AddAnimatedTransformToLayer(child_raw
, 1.0, TransformOperations(), scale
);
7865 ExecuteCalculateDrawProperties(grand_parent
.get());
7867 // Only |child| has a scale-affecting animation.
7869 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7871 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7872 EXPECT_EQ(5.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7874 5.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7876 AddAnimatedTransformToLayer(
7877 grand_parent
.get(), 1.0, TransformOperations(), scale
);
7878 ExecuteCalculateDrawProperties(grand_parent
.get());
7880 // |grand_parent| and |child| have scale-affecting animations.
7882 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7884 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7885 // We don't support combining animated scales from two nodes; 0.f means
7886 // that the maximum scale could not be computed.
7887 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7889 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7891 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
7892 ExecuteCalculateDrawProperties(grand_parent
.get());
7894 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
7896 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7898 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7899 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7901 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7903 grand_parent
->layer_animation_controller()->AbortAnimations(
7904 Animation::Transform
);
7905 parent_raw
->layer_animation_controller()->AbortAnimations(
7906 Animation::Transform
);
7907 child_raw
->layer_animation_controller()->AbortAnimations(
7908 Animation::Transform
);
7910 TransformOperations perspective
;
7911 perspective
.AppendPerspective(10.f
);
7913 AddAnimatedTransformToLayer(
7914 child_raw
, 1.0, TransformOperations(), perspective
);
7915 ExecuteCalculateDrawProperties(grand_parent
.get());
7917 // |child| has a scale-affecting animation but computing the maximum of this
7918 // animation is not supported.
7920 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7922 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7923 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7925 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7927 child_raw
->layer_animation_controller()->AbortAnimations(
7928 Animation::Transform
);
7930 gfx::Transform scale_matrix
;
7931 scale_matrix
.Scale(1.f
, 2.f
);
7932 grand_parent
->SetTransform(scale_matrix
);
7933 parent_raw
->SetTransform(scale_matrix
);
7934 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
7935 ExecuteCalculateDrawProperties(grand_parent
.get());
7937 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
7938 // animation with maximum scale 5.f.
7940 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7942 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7944 child_raw
->draw_properties().maximum_animation_contents_scale
);
7947 grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7949 gfx::Transform perspective_matrix
;
7950 perspective_matrix
.ApplyPerspectiveDepth(2.f
);
7951 child_raw
->SetTransform(perspective_matrix
);
7952 ExecuteCalculateDrawProperties(grand_parent
.get());
7954 // |child| has a transform that's neither a translation nor a scale.
7956 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7958 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7959 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7961 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7963 parent_raw
->SetTransform(perspective_matrix
);
7964 ExecuteCalculateDrawProperties(grand_parent
.get());
7966 // |parent| and |child| have transforms that are neither translations nor
7969 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7971 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7972 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7974 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7976 parent_raw
->SetTransform(identity_matrix
);
7977 child_raw
->SetTransform(identity_matrix
);
7978 grand_parent
->SetTransform(perspective_matrix
);
7980 ExecuteCalculateDrawProperties(grand_parent
.get());
7982 // |grand_parent| has a transform that's neither a translation nor a scale.
7984 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7986 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7987 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7989 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7992 static int membership_id(LayerImpl
* layer
) {
7993 return layer
->draw_properties().last_drawn_render_surface_layer_list_id
;
7996 static void GatherDrawnLayers(LayerImplList
* rsll
,
7997 std::set
<LayerImpl
*>* drawn_layers
) {
7998 for (LayerIterator
<LayerImpl
> it
= LayerIterator
<LayerImpl
>::Begin(rsll
),
7999 end
= LayerIterator
<LayerImpl
>::End(rsll
);
8002 LayerImpl
* layer
= *it
;
8003 if (it
.represents_itself())
8004 drawn_layers
->insert(layer
);
8006 if (!it
.represents_contributing_render_surface())
8009 if (layer
->mask_layer())
8010 drawn_layers
->insert(layer
->mask_layer());
8011 if (layer
->replica_layer() && layer
->replica_layer()->mask_layer())
8012 drawn_layers
->insert(layer
->replica_layer()->mask_layer());
8016 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceLayerListMembership
) {
8017 FakeImplProxy proxy
;
8018 TestSharedBitmapManager shared_bitmap_manager
;
8019 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
8020 gfx::Transform identity_matrix
;
8022 scoped_ptr
<LayerImpl
> grand_parent
=
8023 LayerImpl::Create(host_impl
.active_tree(), 1);
8024 scoped_ptr
<LayerImpl
> parent
= LayerImpl::Create(host_impl
.active_tree(), 3);
8025 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 5);
8026 scoped_ptr
<LayerImpl
> grand_child1
=
8027 LayerImpl::Create(host_impl
.active_tree(), 7);
8028 scoped_ptr
<LayerImpl
> grand_child2
=
8029 LayerImpl::Create(host_impl
.active_tree(), 9);
8031 LayerImpl
* grand_parent_raw
= grand_parent
.get();
8032 LayerImpl
* parent_raw
= parent
.get();
8033 LayerImpl
* child_raw
= child
.get();
8034 LayerImpl
* grand_child1_raw
= grand_child1
.get();
8035 LayerImpl
* grand_child2_raw
= grand_child2
.get();
8037 child
->AddChild(grand_child1
.Pass());
8038 child
->AddChild(grand_child2
.Pass());
8039 parent
->AddChild(child
.Pass());
8040 grand_parent
->AddChild(parent
.Pass());
8042 SetLayerPropertiesForTesting(grand_parent_raw
,
8049 SetLayerPropertiesForTesting(parent_raw
,
8056 SetLayerPropertiesForTesting(child_raw
,
8063 SetLayerPropertiesForTesting(grand_child1_raw
,
8070 SetLayerPropertiesForTesting(grand_child2_raw
,
8078 // Start with nothing being drawn.
8079 ExecuteCalculateDrawProperties(grand_parent_raw
);
8080 int member_id
= render_surface_layer_list_count();
8082 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8083 EXPECT_NE(member_id
, membership_id(parent_raw
));
8084 EXPECT_NE(member_id
, membership_id(child_raw
));
8085 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8086 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8088 std::set
<LayerImpl
*> expected
;
8089 std::set
<LayerImpl
*> actual
;
8090 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8091 EXPECT_EQ(expected
, actual
);
8093 // If we force render surface, but none of the layers are in the layer list,
8094 // then this layer should not appear in RSLL.
8095 grand_child1_raw
->SetForceRenderSurface(true);
8097 ExecuteCalculateDrawProperties(grand_parent_raw
);
8098 member_id
= render_surface_layer_list_count();
8100 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8101 EXPECT_NE(member_id
, membership_id(parent_raw
));
8102 EXPECT_NE(member_id
, membership_id(child_raw
));
8103 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8104 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8108 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8109 EXPECT_EQ(expected
, actual
);
8111 // However, if we say that this layer also draws content, it will appear in
8113 grand_child1_raw
->SetDrawsContent(true);
8115 ExecuteCalculateDrawProperties(grand_parent_raw
);
8116 member_id
= render_surface_layer_list_count();
8118 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8119 EXPECT_NE(member_id
, membership_id(parent_raw
));
8120 EXPECT_NE(member_id
, membership_id(child_raw
));
8121 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
8122 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8125 expected
.insert(grand_child1_raw
);
8128 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8129 EXPECT_EQ(expected
, actual
);
8131 // Now child is forced to have a render surface, and one if its children draws
8133 grand_child1_raw
->SetDrawsContent(false);
8134 grand_child1_raw
->SetForceRenderSurface(false);
8135 child_raw
->SetForceRenderSurface(true);
8136 grand_child2_raw
->SetDrawsContent(true);
8138 ExecuteCalculateDrawProperties(grand_parent_raw
);
8139 member_id
= render_surface_layer_list_count();
8141 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8142 EXPECT_NE(member_id
, membership_id(parent_raw
));
8143 EXPECT_NE(member_id
, membership_id(child_raw
));
8144 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8145 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8148 expected
.insert(grand_child2_raw
);
8151 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8152 EXPECT_EQ(expected
, actual
);
8154 // Add a mask layer to child.
8155 child_raw
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6).Pass());
8157 ExecuteCalculateDrawProperties(grand_parent_raw
);
8158 member_id
= render_surface_layer_list_count();
8160 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8161 EXPECT_NE(member_id
, membership_id(parent_raw
));
8162 EXPECT_NE(member_id
, membership_id(child_raw
));
8163 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8164 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8165 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8168 expected
.insert(grand_child2_raw
);
8169 expected
.insert(child_raw
->mask_layer());
8172 expected
.insert(grand_child2_raw
);
8173 expected
.insert(child_raw
->mask_layer());
8176 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8177 EXPECT_EQ(expected
, actual
);
8179 // Add replica mask layer.
8180 scoped_ptr
<LayerImpl
> replica_layer
=
8181 LayerImpl::Create(host_impl
.active_tree(), 20);
8182 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 21));
8183 child_raw
->SetReplicaLayer(replica_layer
.Pass());
8185 ExecuteCalculateDrawProperties(grand_parent_raw
);
8186 member_id
= render_surface_layer_list_count();
8188 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8189 EXPECT_NE(member_id
, membership_id(parent_raw
));
8190 EXPECT_NE(member_id
, membership_id(child_raw
));
8191 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8192 EXPECT_EQ(member_id
, membership_id(child_raw
->replica_layer()->mask_layer()));
8193 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8194 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8197 expected
.insert(grand_child2_raw
);
8198 expected
.insert(child_raw
->mask_layer());
8199 expected
.insert(child_raw
->replica_layer()->mask_layer());
8202 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8203 EXPECT_EQ(expected
, actual
);
8205 child_raw
->TakeReplicaLayer();
8207 // With nothing drawing, we should have no layers.
8208 grand_child2_raw
->SetDrawsContent(false);
8210 ExecuteCalculateDrawProperties(grand_parent_raw
);
8211 member_id
= render_surface_layer_list_count();
8213 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8214 EXPECT_NE(member_id
, membership_id(parent_raw
));
8215 EXPECT_NE(member_id
, membership_id(child_raw
));
8216 EXPECT_NE(member_id
, membership_id(child_raw
->mask_layer()));
8217 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8218 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8222 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8223 EXPECT_EQ(expected
, actual
);
8225 // Child itself draws means that we should have the child and the mask in the
8227 child_raw
->SetDrawsContent(true);
8229 ExecuteCalculateDrawProperties(grand_parent_raw
);
8230 member_id
= render_surface_layer_list_count();
8232 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8233 EXPECT_NE(member_id
, membership_id(parent_raw
));
8234 EXPECT_EQ(member_id
, membership_id(child_raw
));
8235 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8236 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8237 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8240 expected
.insert(child_raw
);
8241 expected
.insert(child_raw
->mask_layer());
8243 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8244 EXPECT_EQ(expected
, actual
);
8246 child_raw
->TakeMaskLayer();
8248 // Now everyone's a member!
8249 grand_parent_raw
->SetDrawsContent(true);
8250 parent_raw
->SetDrawsContent(true);
8251 child_raw
->SetDrawsContent(true);
8252 grand_child1_raw
->SetDrawsContent(true);
8253 grand_child2_raw
->SetDrawsContent(true);
8255 ExecuteCalculateDrawProperties(grand_parent_raw
);
8256 member_id
= render_surface_layer_list_count();
8258 EXPECT_EQ(member_id
, membership_id(grand_parent_raw
));
8259 EXPECT_EQ(member_id
, membership_id(parent_raw
));
8260 EXPECT_EQ(member_id
, membership_id(child_raw
));
8261 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
8262 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8265 expected
.insert(grand_parent_raw
);
8266 expected
.insert(parent_raw
);
8267 expected
.insert(child_raw
);
8268 expected
.insert(grand_child1_raw
);
8269 expected
.insert(grand_child2_raw
);
8272 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8273 EXPECT_EQ(expected
, actual
);
8276 TEST_F(LayerTreeHostCommonTest
, DrawPropertyScales
) {
8277 FakeImplProxy proxy
;
8278 TestSharedBitmapManager shared_bitmap_manager
;
8279 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
8281 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
8282 LayerImpl
* root_layer
= root
.get();
8283 scoped_ptr
<LayerImpl
> child1
= LayerImpl::Create(host_impl
.active_tree(), 2);
8284 LayerImpl
* child1_layer
= child1
.get();
8285 scoped_ptr
<LayerImpl
> child2
= LayerImpl::Create(host_impl
.active_tree(), 3);
8286 LayerImpl
* child2_layer
= child2
.get();
8288 root
->AddChild(child1
.Pass());
8289 root
->AddChild(child2
.Pass());
8291 gfx::Transform identity_matrix
, scale_transform_child1
,
8292 scale_transform_child2
;
8293 scale_transform_child1
.Scale(2, 3);
8294 scale_transform_child2
.Scale(4, 5);
8296 SetLayerPropertiesForTesting(root_layer
,
8303 SetLayerPropertiesForTesting(child1_layer
,
8304 scale_transform_child1
,
8311 child1_layer
->SetMaskLayer(
8312 LayerImpl::Create(host_impl
.active_tree(), 4).Pass());
8314 scoped_ptr
<LayerImpl
> replica_layer
=
8315 LayerImpl::Create(host_impl
.active_tree(), 5);
8316 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6));
8317 child1_layer
->SetReplicaLayer(replica_layer
.Pass());
8319 ExecuteCalculateDrawProperties(root_layer
);
8321 TransformOperations scale
;
8322 scale
.AppendScale(5.f
, 8.f
, 3.f
);
8324 AddAnimatedTransformToLayer(child2_layer
, 1.0, TransformOperations(), scale
);
8325 SetLayerPropertiesForTesting(child2_layer
,
8326 scale_transform_child2
,
8333 ExecuteCalculateDrawProperties(root_layer
);
8335 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().ideal_contents_scale
);
8336 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8338 3.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8339 EXPECT_FLOAT_EQ(3.f
,
8340 child1_layer
->replica_layer()
8343 .ideal_contents_scale
);
8344 EXPECT_FLOAT_EQ(5.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8347 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8349 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8350 EXPECT_FLOAT_EQ(0.f
,
8351 child1_layer
->mask_layer()
8353 .maximum_animation_contents_scale
);
8354 EXPECT_FLOAT_EQ(0.f
,
8355 child1_layer
->replica_layer()
8358 .maximum_animation_contents_scale
);
8360 8.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8362 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8363 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().page_scale_factor
);
8365 1.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8366 EXPECT_FLOAT_EQ(1.f
,
8367 child1_layer
->replica_layer()
8370 .page_scale_factor
);
8371 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().page_scale_factor
);
8373 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().device_scale_factor
);
8374 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().device_scale_factor
);
8376 1.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8377 EXPECT_FLOAT_EQ(1.f
,
8378 child1_layer
->replica_layer()
8381 .device_scale_factor
);
8382 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().device_scale_factor
);
8384 // Changing page-scale would affect ideal_contents_scale and
8385 // maximum_animation_contents_scale.
8387 float page_scale_factor
= 3.f
;
8388 float device_scale_factor
= 1.0f
;
8389 std::vector
<LayerImpl
*> render_surface_layer_list
;
8390 gfx::Size device_viewport_size
=
8391 gfx::Size(root_layer
->bounds().width() * device_scale_factor
,
8392 root_layer
->bounds().height() * device_scale_factor
);
8393 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
8394 root_layer
, device_viewport_size
, &render_surface_layer_list
);
8396 inputs
.page_scale_factor
= page_scale_factor
;
8397 inputs
.can_adjust_raster_scales
= true;
8398 inputs
.page_scale_application_layer
= root_layer
;
8399 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8401 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().ideal_contents_scale
);
8402 EXPECT_FLOAT_EQ(9.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8404 9.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8405 EXPECT_FLOAT_EQ(9.f
,
8406 child1_layer
->replica_layer()
8409 .ideal_contents_scale
);
8410 EXPECT_FLOAT_EQ(15.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8413 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8415 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8416 EXPECT_FLOAT_EQ(0.f
,
8417 child1_layer
->mask_layer()
8419 .maximum_animation_contents_scale
);
8420 EXPECT_FLOAT_EQ(0.f
,
8421 child1_layer
->replica_layer()
8424 .maximum_animation_contents_scale
);
8426 24.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8428 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8429 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().page_scale_factor
);
8431 3.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8432 EXPECT_FLOAT_EQ(3.f
,
8433 child1_layer
->replica_layer()
8436 .page_scale_factor
);
8437 EXPECT_FLOAT_EQ(3.f
, child2_layer
->draw_properties().page_scale_factor
);
8439 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().device_scale_factor
);
8440 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().device_scale_factor
);
8442 1.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8443 EXPECT_FLOAT_EQ(1.f
,
8444 child1_layer
->replica_layer()
8447 .device_scale_factor
);
8448 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().device_scale_factor
);
8450 // Changing device-scale would affect ideal_contents_scale and
8451 // maximum_animation_contents_scale.
8453 device_scale_factor
= 4.0f
;
8454 inputs
.device_scale_factor
= device_scale_factor
;
8455 inputs
.can_adjust_raster_scales
= true;
8456 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8458 EXPECT_FLOAT_EQ(4.f
, root_layer
->draw_properties().ideal_contents_scale
);
8459 EXPECT_FLOAT_EQ(36.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8461 36.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8462 EXPECT_FLOAT_EQ(36.f
,
8463 child1_layer
->replica_layer()
8466 .ideal_contents_scale
);
8467 EXPECT_FLOAT_EQ(60.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8470 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8472 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8473 EXPECT_FLOAT_EQ(0.f
,
8474 child1_layer
->mask_layer()
8476 .maximum_animation_contents_scale
);
8477 EXPECT_FLOAT_EQ(0.f
,
8478 child1_layer
->replica_layer()
8481 .maximum_animation_contents_scale
);
8483 96.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8485 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8486 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().page_scale_factor
);
8488 3.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8489 EXPECT_FLOAT_EQ(3.f
,
8490 child1_layer
->replica_layer()
8493 .page_scale_factor
);
8494 EXPECT_FLOAT_EQ(3.f
, child2_layer
->draw_properties().page_scale_factor
);
8496 EXPECT_FLOAT_EQ(4.f
, root_layer
->draw_properties().device_scale_factor
);
8497 EXPECT_FLOAT_EQ(4.f
, child1_layer
->draw_properties().device_scale_factor
);
8499 4.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8500 EXPECT_FLOAT_EQ(4.f
,
8501 child1_layer
->replica_layer()
8504 .device_scale_factor
);
8505 EXPECT_FLOAT_EQ(4.f
, child2_layer
->draw_properties().device_scale_factor
);
8508 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInChildRenderSurface
) {
8509 scoped_refptr
<Layer
> root
= Layer::Create();
8510 SetLayerPropertiesForTesting(root
.get(),
8514 gfx::Size(768 / 2, 3000),
8517 root
->SetIsDrawable(true);
8519 scoped_refptr
<Layer
> clip
= Layer::Create();
8520 SetLayerPropertiesForTesting(clip
.get(),
8524 gfx::Size(768 / 2, 10000),
8527 clip
->SetMasksToBounds(true);
8529 scoped_refptr
<Layer
> content
= Layer::Create();
8530 SetLayerPropertiesForTesting(content
.get(),
8534 gfx::Size(768 / 2, 10000),
8537 content
->SetIsDrawable(true);
8538 content
->SetForceRenderSurface(true);
8540 root
->AddChild(clip
);
8541 clip
->AddChild(content
);
8543 FakeLayerTreeHostClient
client(FakeLayerTreeHostClient::DIRECT_3D
);
8544 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(&client
);
8545 host
->SetRootLayer(root
);
8547 gfx::Size
device_viewport_size(768, 582);
8548 RenderSurfaceLayerList render_surface_layer_list
;
8549 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
8550 host
->root_layer(), device_viewport_size
, &render_surface_layer_list
);
8551 inputs
.device_scale_factor
= 2.f
;
8552 inputs
.page_scale_factor
= 1.f
;
8553 inputs
.page_scale_application_layer
= NULL
;
8554 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8556 // Layers in the root render surface have their visible content rect clipped
8558 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root
->visible_content_rect());
8560 // Layers drawing to a child render surface should still have their visible
8561 // content rect clipped by the viewport.
8562 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content
->visible_content_rect());