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
, RenderSurfaceForBlendMode
) {
1396 scoped_refptr
<Layer
> parent
= Layer::Create();
1397 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1398 make_scoped_refptr(new LayerWithForcedDrawsContent());
1400 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1401 host
->SetRootLayer(parent
);
1403 const gfx::Transform identity_matrix
;
1404 const SkXfermode::Mode blend_mode
= SkXfermode::kMultiply_Mode
;
1405 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
1406 gfx::PointF(), gfx::Size(10, 10), true, false);
1408 parent
->AddChild(child
);
1409 child
->SetBlendMode(blend_mode
);
1411 RenderSurfaceLayerList render_surface_layer_list
;
1412 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1413 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1414 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1416 // Since the child layer has a blend mode other than normal, it should get
1417 // its own render surface. Also, layer's draw_properties should contain the
1418 // default blend mode, since the render surface becomes responsible for
1419 // applying the blend mode.
1420 ASSERT_TRUE(child
->render_surface());
1421 EXPECT_EQ(1U, child
->render_surface()->layer_list().size());
1422 EXPECT_EQ(SkXfermode::kSrcOver_Mode
, child
->draw_properties().blend_mode
);
1425 TEST_F(LayerTreeHostCommonTest
, ForceRenderSurface
) {
1426 scoped_refptr
<Layer
> parent
= Layer::Create();
1427 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
1428 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1429 make_scoped_refptr(new LayerWithForcedDrawsContent());
1430 render_surface1
->SetForceRenderSurface(true);
1432 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1433 host
->SetRootLayer(parent
);
1435 const gfx::Transform identity_matrix
;
1436 SetLayerPropertiesForTesting(parent
.get(),
1443 SetLayerPropertiesForTesting(render_surface1
.get(),
1450 SetLayerPropertiesForTesting(child
.get(),
1458 parent
->AddChild(render_surface1
);
1459 render_surface1
->AddChild(child
);
1461 // Sanity check before the actual test
1462 EXPECT_FALSE(parent
->render_surface());
1463 EXPECT_FALSE(render_surface1
->render_surface());
1466 RenderSurfaceLayerList render_surface_layer_list
;
1467 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1468 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1469 inputs
.can_adjust_raster_scales
= true;
1470 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1472 // The root layer always creates a render surface
1473 EXPECT_TRUE(parent
->render_surface());
1474 EXPECT_TRUE(render_surface1
->render_surface());
1475 EXPECT_EQ(2U, render_surface_layer_list
.size());
1479 RenderSurfaceLayerList render_surface_layer_list
;
1480 render_surface1
->SetForceRenderSurface(false);
1481 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1482 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1483 inputs
.can_adjust_raster_scales
= true;
1484 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1485 EXPECT_TRUE(parent
->render_surface());
1486 EXPECT_FALSE(render_surface1
->render_surface());
1487 EXPECT_EQ(1U, render_surface_layer_list
.size());
1491 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsRenderSurfaces
) {
1492 // The entire subtree of layers that are outside the clip rect should be
1493 // culled away, and should not affect the render_surface_layer_list.
1495 // The test tree is set up as follows:
1496 // - all layers except the leaf_nodes are forced to be a new render surface
1497 // that have something to draw.
1498 // - parent is a large container layer.
1499 // - child has masksToBounds=true to cause clipping.
1500 // - grand_child is positioned outside of the child's bounds
1501 // - great_grand_child is also kept outside child's bounds.
1503 // In this configuration, grand_child and great_grand_child are completely
1504 // outside the clip rect, and they should never get scheduled on the list of
1508 const gfx::Transform identity_matrix
;
1509 scoped_refptr
<Layer
> parent
= Layer::Create();
1510 scoped_refptr
<Layer
> child
= Layer::Create();
1511 scoped_refptr
<Layer
> grand_child
= Layer::Create();
1512 scoped_refptr
<Layer
> great_grand_child
= Layer::Create();
1513 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1514 make_scoped_refptr(new LayerWithForcedDrawsContent());
1515 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1516 make_scoped_refptr(new LayerWithForcedDrawsContent());
1517 parent
->AddChild(child
);
1518 child
->AddChild(grand_child
);
1519 grand_child
->AddChild(great_grand_child
);
1521 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1522 host
->SetRootLayer(parent
);
1524 // leaf_node1 ensures that parent and child are kept on the
1525 // render_surface_layer_list, even though grand_child and great_grand_child
1526 // should be clipped.
1527 child
->AddChild(leaf_node1
);
1528 great_grand_child
->AddChild(leaf_node2
);
1530 SetLayerPropertiesForTesting(parent
.get(),
1534 gfx::Size(500, 500),
1537 SetLayerPropertiesForTesting(child
.get(),
1544 SetLayerPropertiesForTesting(grand_child
.get(),
1547 gfx::PointF(45.f
, 45.f
),
1551 SetLayerPropertiesForTesting(great_grand_child
.get(),
1558 SetLayerPropertiesForTesting(leaf_node1
.get(),
1562 gfx::Size(500, 500),
1565 SetLayerPropertiesForTesting(leaf_node2
.get(),
1573 child
->SetMasksToBounds(true);
1574 child
->SetOpacity(0.4f
);
1575 child
->SetForceRenderSurface(true);
1576 grand_child
->SetOpacity(0.5f
);
1577 great_grand_child
->SetOpacity(0.4f
);
1579 RenderSurfaceLayerList render_surface_layer_list
;
1580 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1581 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1582 inputs
.can_adjust_raster_scales
= true;
1583 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1585 ASSERT_EQ(2U, render_surface_layer_list
.size());
1586 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1587 EXPECT_EQ(child
->id(), render_surface_layer_list
.at(1)->id());
1590 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsSurfaceWithoutVisibleContent
) {
1591 // When a render surface has a clip rect, it is used to clip the content rect
1592 // of the surface. When the render surface is animating its transforms, then
1593 // the content rect's position in the clip rect is not defined on the main
1594 // thread, and its content rect should not be clipped.
1596 // The test tree is set up as follows:
1597 // - parent is a container layer that masksToBounds=true to cause clipping.
1598 // - child is a render surface, which has a clip rect set to the bounds of
1600 // - grand_child is a render surface, and the only visible content in child.
1601 // It is positioned outside of the clip rect from parent.
1603 // In this configuration, grand_child should be outside the clipped
1604 // content rect of the child, making grand_child not appear in the
1605 // render_surface_layer_list. However, when we place an animation on the
1606 // child, this clipping should be avoided and we should keep the grand_child
1607 // in the render_surface_layer_list.
1609 const gfx::Transform identity_matrix
;
1610 scoped_refptr
<Layer
> parent
= Layer::Create();
1611 scoped_refptr
<Layer
> child
= Layer::Create();
1612 scoped_refptr
<Layer
> grand_child
= Layer::Create();
1613 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node
=
1614 make_scoped_refptr(new LayerWithForcedDrawsContent());
1615 parent
->AddChild(child
);
1616 child
->AddChild(grand_child
);
1617 grand_child
->AddChild(leaf_node
);
1619 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1620 host
->SetRootLayer(parent
);
1622 SetLayerPropertiesForTesting(parent
.get(),
1626 gfx::Size(100, 100),
1629 SetLayerPropertiesForTesting(child
.get(),
1636 SetLayerPropertiesForTesting(grand_child
.get(),
1639 gfx::PointF(200.f
, 200.f
),
1643 SetLayerPropertiesForTesting(leaf_node
.get(),
1651 parent
->SetMasksToBounds(true);
1652 child
->SetOpacity(0.4f
);
1653 child
->SetForceRenderSurface(true);
1654 grand_child
->SetOpacity(0.4f
);
1655 grand_child
->SetForceRenderSurface(true);
1658 RenderSurfaceLayerList render_surface_layer_list
;
1659 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1660 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1661 inputs
.can_adjust_raster_scales
= true;
1662 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1664 // Without an animation, we should cull child and grand_child from the
1665 // render_surface_layer_list.
1666 ASSERT_EQ(1U, render_surface_layer_list
.size());
1667 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1670 // Now put an animating transform on child.
1671 AddAnimatedTransformToController(
1672 child
->layer_animation_controller(), 10.0, 30, 0);
1675 RenderSurfaceLayerList render_surface_layer_list
;
1676 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1677 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1678 inputs
.can_adjust_raster_scales
= true;
1679 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1681 // With an animating transform, we should keep child and grand_child in the
1682 // render_surface_layer_list.
1683 ASSERT_EQ(3U, render_surface_layer_list
.size());
1684 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1685 EXPECT_EQ(child
->id(), render_surface_layer_list
.at(1)->id());
1686 EXPECT_EQ(grand_child
->id(), render_surface_layer_list
.at(2)->id());
1690 TEST_F(LayerTreeHostCommonTest
, IsClippedIsSetCorrectly
) {
1691 // Layer's IsClipped() property is set to true when:
1692 // - the layer clips its subtree, e.g. masks to bounds,
1693 // - the layer is clipped by an ancestor that contributes to the same
1695 // - a surface is clipped by an ancestor that contributes to the same
1698 // In particular, for a layer that owns a render surface:
1699 // - the render surface inherits any clip from ancestors, and does NOT
1700 // pass that clipped status to the layer itself.
1701 // - but if the layer itself masks to bounds, it is considered clipped
1702 // and propagates the clip to the subtree.
1704 const gfx::Transform identity_matrix
;
1705 scoped_refptr
<Layer
> root
= Layer::Create();
1706 scoped_refptr
<Layer
> parent
= Layer::Create();
1707 scoped_refptr
<Layer
> child1
= Layer::Create();
1708 scoped_refptr
<Layer
> child2
= Layer::Create();
1709 scoped_refptr
<Layer
> grand_child
= Layer::Create();
1710 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1711 make_scoped_refptr(new LayerWithForcedDrawsContent());
1712 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1713 make_scoped_refptr(new LayerWithForcedDrawsContent());
1714 root
->AddChild(parent
);
1715 parent
->AddChild(child1
);
1716 parent
->AddChild(child2
);
1717 child1
->AddChild(grand_child
);
1718 child2
->AddChild(leaf_node2
);
1719 grand_child
->AddChild(leaf_node1
);
1721 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1722 host
->SetRootLayer(root
);
1724 child2
->SetForceRenderSurface(true);
1726 SetLayerPropertiesForTesting(root
.get(),
1730 gfx::Size(100, 100),
1733 SetLayerPropertiesForTesting(parent
.get(),
1737 gfx::Size(100, 100),
1740 SetLayerPropertiesForTesting(child1
.get(),
1744 gfx::Size(100, 100),
1747 SetLayerPropertiesForTesting(child2
.get(),
1751 gfx::Size(100, 100),
1754 SetLayerPropertiesForTesting(grand_child
.get(),
1758 gfx::Size(100, 100),
1761 SetLayerPropertiesForTesting(leaf_node1
.get(),
1765 gfx::Size(100, 100),
1768 SetLayerPropertiesForTesting(leaf_node2
.get(),
1772 gfx::Size(100, 100),
1776 // Case 1: nothing is clipped except the root render surface.
1778 RenderSurfaceLayerList render_surface_layer_list
;
1779 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1780 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1781 inputs
.can_adjust_raster_scales
= true;
1782 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1784 ASSERT_TRUE(root
->render_surface());
1785 ASSERT_TRUE(child2
->render_surface());
1787 EXPECT_FALSE(root
->is_clipped());
1788 EXPECT_TRUE(root
->render_surface()->is_clipped());
1789 EXPECT_FALSE(parent
->is_clipped());
1790 EXPECT_FALSE(child1
->is_clipped());
1791 EXPECT_FALSE(child2
->is_clipped());
1792 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1793 EXPECT_FALSE(grand_child
->is_clipped());
1794 EXPECT_FALSE(leaf_node1
->is_clipped());
1795 EXPECT_FALSE(leaf_node2
->is_clipped());
1798 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1799 // surface are clipped. But layers that contribute to child2's surface are
1800 // not clipped explicitly because child2's surface already accounts for
1803 RenderSurfaceLayerList render_surface_layer_list
;
1804 parent
->SetMasksToBounds(true);
1805 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1806 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1807 inputs
.can_adjust_raster_scales
= true;
1808 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1810 ASSERT_TRUE(root
->render_surface());
1811 ASSERT_TRUE(child2
->render_surface());
1813 EXPECT_FALSE(root
->is_clipped());
1814 EXPECT_TRUE(root
->render_surface()->is_clipped());
1815 EXPECT_TRUE(parent
->is_clipped());
1816 EXPECT_TRUE(child1
->is_clipped());
1817 EXPECT_FALSE(child2
->is_clipped());
1818 EXPECT_TRUE(child2
->render_surface()->is_clipped());
1819 EXPECT_TRUE(grand_child
->is_clipped());
1820 EXPECT_TRUE(leaf_node1
->is_clipped());
1821 EXPECT_FALSE(leaf_node2
->is_clipped());
1824 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1825 // child2's render surface is not clipped.
1827 RenderSurfaceLayerList render_surface_layer_list
;
1828 parent
->SetMasksToBounds(false);
1829 child2
->SetMasksToBounds(true);
1830 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1831 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1832 inputs
.can_adjust_raster_scales
= true;
1833 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1835 ASSERT_TRUE(root
->render_surface());
1836 ASSERT_TRUE(child2
->render_surface());
1838 EXPECT_FALSE(root
->is_clipped());
1839 EXPECT_TRUE(root
->render_surface()->is_clipped());
1840 EXPECT_FALSE(parent
->is_clipped());
1841 EXPECT_FALSE(child1
->is_clipped());
1842 EXPECT_TRUE(child2
->is_clipped());
1843 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1844 EXPECT_FALSE(grand_child
->is_clipped());
1845 EXPECT_FALSE(leaf_node1
->is_clipped());
1846 EXPECT_TRUE(leaf_node2
->is_clipped());
1850 TEST_F(LayerTreeHostCommonTest
, DrawableContentRectForLayers
) {
1851 // Verify that layers get the appropriate DrawableContentRect when their
1852 // parent masksToBounds is true.
1854 // grand_child1 - completely inside the region; DrawableContentRect should
1855 // be the layer rect expressed in target space.
1856 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1857 // will be the intersection of layer bounds and the mask region.
1858 // grand_child3 - partially clipped and masksToBounds; the
1859 // DrawableContentRect will still be the intersection of layer bounds and
1861 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1865 const gfx::Transform identity_matrix
;
1866 scoped_refptr
<Layer
> parent
= Layer::Create();
1867 scoped_refptr
<Layer
> child
= Layer::Create();
1868 scoped_refptr
<Layer
> grand_child1
= Layer::Create();
1869 scoped_refptr
<Layer
> grand_child2
= Layer::Create();
1870 scoped_refptr
<Layer
> grand_child3
= Layer::Create();
1871 scoped_refptr
<Layer
> grand_child4
= Layer::Create();
1873 parent
->AddChild(child
);
1874 child
->AddChild(grand_child1
);
1875 child
->AddChild(grand_child2
);
1876 child
->AddChild(grand_child3
);
1877 child
->AddChild(grand_child4
);
1879 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1880 host
->SetRootLayer(parent
);
1882 SetLayerPropertiesForTesting(parent
.get(),
1886 gfx::Size(500, 500),
1889 SetLayerPropertiesForTesting(child
.get(),
1896 SetLayerPropertiesForTesting(grand_child1
.get(),
1899 gfx::PointF(5.f
, 5.f
),
1903 SetLayerPropertiesForTesting(grand_child2
.get(),
1906 gfx::PointF(15.f
, 15.f
),
1910 SetLayerPropertiesForTesting(grand_child3
.get(),
1913 gfx::PointF(15.f
, 15.f
),
1917 SetLayerPropertiesForTesting(grand_child4
.get(),
1920 gfx::PointF(45.f
, 45.f
),
1925 child
->SetMasksToBounds(true);
1926 grand_child3
->SetMasksToBounds(true);
1928 // Force everyone to be a render surface.
1929 child
->SetOpacity(0.4f
);
1930 grand_child1
->SetOpacity(0.5f
);
1931 grand_child2
->SetOpacity(0.5f
);
1932 grand_child3
->SetOpacity(0.5f
);
1933 grand_child4
->SetOpacity(0.5f
);
1935 RenderSurfaceLayerList render_surface_layer_list
;
1936 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1937 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1938 inputs
.can_adjust_raster_scales
= true;
1939 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1941 EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10),
1942 grand_child1
->drawable_content_rect());
1943 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
1944 grand_child3
->drawable_content_rect());
1945 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
1946 grand_child3
->drawable_content_rect());
1947 EXPECT_TRUE(grand_child4
->drawable_content_rect().IsEmpty());
1950 TEST_F(LayerTreeHostCommonTest
, ClipRectIsPropagatedCorrectlyToSurfaces
) {
1951 // Verify that render surfaces (and their layers) get the appropriate
1952 // clip rects when their parent masksToBounds is true.
1954 // Layers that own render surfaces (at least for now) do not inherit any
1955 // clipping; instead the surface will enforce the clip for the entire subtree.
1956 // They may still have a clip rect of their own layer bounds, however, if
1957 // masksToBounds was true.
1958 const gfx::Transform identity_matrix
;
1959 scoped_refptr
<Layer
> parent
= Layer::Create();
1960 scoped_refptr
<Layer
> child
= Layer::Create();
1961 scoped_refptr
<Layer
> grand_child1
= Layer::Create();
1962 scoped_refptr
<Layer
> grand_child2
= Layer::Create();
1963 scoped_refptr
<Layer
> grand_child3
= Layer::Create();
1964 scoped_refptr
<Layer
> grand_child4
= Layer::Create();
1965 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1966 make_scoped_refptr(new LayerWithForcedDrawsContent());
1967 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1968 make_scoped_refptr(new LayerWithForcedDrawsContent());
1969 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node3
=
1970 make_scoped_refptr(new LayerWithForcedDrawsContent());
1971 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node4
=
1972 make_scoped_refptr(new LayerWithForcedDrawsContent());
1974 parent
->AddChild(child
);
1975 child
->AddChild(grand_child1
);
1976 child
->AddChild(grand_child2
);
1977 child
->AddChild(grand_child3
);
1978 child
->AddChild(grand_child4
);
1980 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1981 host
->SetRootLayer(parent
);
1983 // the leaf nodes ensure that these grand_children become render surfaces for
1985 grand_child1
->AddChild(leaf_node1
);
1986 grand_child2
->AddChild(leaf_node2
);
1987 grand_child3
->AddChild(leaf_node3
);
1988 grand_child4
->AddChild(leaf_node4
);
1990 SetLayerPropertiesForTesting(parent
.get(),
1994 gfx::Size(500, 500),
1997 SetLayerPropertiesForTesting(child
.get(),
2004 SetLayerPropertiesForTesting(grand_child1
.get(),
2007 gfx::PointF(5.f
, 5.f
),
2011 SetLayerPropertiesForTesting(grand_child2
.get(),
2014 gfx::PointF(15.f
, 15.f
),
2018 SetLayerPropertiesForTesting(grand_child3
.get(),
2021 gfx::PointF(15.f
, 15.f
),
2025 SetLayerPropertiesForTesting(grand_child4
.get(),
2028 gfx::PointF(45.f
, 45.f
),
2032 SetLayerPropertiesForTesting(leaf_node1
.get(),
2039 SetLayerPropertiesForTesting(leaf_node2
.get(),
2046 SetLayerPropertiesForTesting(leaf_node3
.get(),
2053 SetLayerPropertiesForTesting(leaf_node4
.get(),
2061 child
->SetMasksToBounds(true);
2062 grand_child3
->SetMasksToBounds(true);
2063 grand_child4
->SetMasksToBounds(true);
2065 // Force everyone to be a render surface.
2066 child
->SetOpacity(0.4f
);
2067 child
->SetForceRenderSurface(true);
2068 grand_child1
->SetOpacity(0.5f
);
2069 grand_child1
->SetForceRenderSurface(true);
2070 grand_child2
->SetOpacity(0.5f
);
2071 grand_child2
->SetForceRenderSurface(true);
2072 grand_child3
->SetOpacity(0.5f
);
2073 grand_child3
->SetForceRenderSurface(true);
2074 grand_child4
->SetOpacity(0.5f
);
2075 grand_child4
->SetForceRenderSurface(true);
2077 RenderSurfaceLayerList render_surface_layer_list
;
2078 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
2079 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
2080 inputs
.can_adjust_raster_scales
= true;
2081 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
2082 ASSERT_TRUE(grand_child1
->render_surface());
2083 ASSERT_TRUE(grand_child2
->render_surface());
2084 ASSERT_TRUE(grand_child3
->render_surface());
2086 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2088 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
2089 grand_child1
->render_surface()->clip_rect());
2090 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
2091 grand_child2
->render_surface()->clip_rect());
2092 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
2093 grand_child3
->render_surface()->clip_rect());
2096 TEST_F(LayerTreeHostCommonTest
, AnimationsForRenderSurfaceHierarchy
) {
2097 scoped_refptr
<Layer
> parent
= Layer::Create();
2098 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
2099 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
2100 scoped_refptr
<Layer
> child_of_root
= Layer::Create();
2101 scoped_refptr
<Layer
> child_of_rs1
= Layer::Create();
2102 scoped_refptr
<Layer
> child_of_rs2
= Layer::Create();
2103 scoped_refptr
<Layer
> grand_child_of_root
= Layer::Create();
2104 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs1
=
2105 make_scoped_refptr(new LayerWithForcedDrawsContent());
2106 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs2
=
2107 make_scoped_refptr(new LayerWithForcedDrawsContent());
2108 parent
->AddChild(render_surface1
);
2109 parent
->AddChild(child_of_root
);
2110 render_surface1
->AddChild(child_of_rs1
);
2111 render_surface1
->AddChild(render_surface2
);
2112 render_surface2
->AddChild(child_of_rs2
);
2113 child_of_root
->AddChild(grand_child_of_root
);
2114 child_of_rs1
->AddChild(grand_child_of_rs1
);
2115 child_of_rs2
->AddChild(grand_child_of_rs2
);
2117 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2118 host
->SetRootLayer(parent
);
2120 // Make our render surfaces.
2121 render_surface1
->SetForceRenderSurface(true);
2122 render_surface2
->SetForceRenderSurface(true);
2124 gfx::Transform layer_transform
;
2125 layer_transform
.Translate(1.0, 1.0);
2127 SetLayerPropertiesForTesting(parent
.get(),
2129 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2130 gfx::PointF(2.5f
, 0.f
),
2134 SetLayerPropertiesForTesting(render_surface1
.get(),
2136 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2137 gfx::PointF(2.5f
, 0.f
),
2141 SetLayerPropertiesForTesting(render_surface2
.get(),
2143 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2144 gfx::PointF(2.5f
, 0.f
),
2148 SetLayerPropertiesForTesting(child_of_root
.get(),
2150 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2151 gfx::PointF(2.5f
, 0.f
),
2155 SetLayerPropertiesForTesting(child_of_rs1
.get(),
2157 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2158 gfx::PointF(2.5f
, 0.f
),
2162 SetLayerPropertiesForTesting(child_of_rs2
.get(),
2164 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2165 gfx::PointF(2.5f
, 0.f
),
2169 SetLayerPropertiesForTesting(grand_child_of_root
.get(),
2171 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2172 gfx::PointF(2.5f
, 0.f
),
2176 SetLayerPropertiesForTesting(grand_child_of_rs1
.get(),
2178 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2179 gfx::PointF(2.5f
, 0.f
),
2183 SetLayerPropertiesForTesting(grand_child_of_rs2
.get(),
2185 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2186 gfx::PointF(2.5f
, 0.f
),
2191 // Put an animated opacity on the render surface.
2192 AddOpacityTransitionToController(
2193 render_surface1
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2195 // Also put an animated opacity on a layer without descendants.
2196 AddOpacityTransitionToController(
2197 grand_child_of_root
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2199 // Put a transform animation on the render surface.
2200 AddAnimatedTransformToController(
2201 render_surface2
->layer_animation_controller(), 10.0, 30, 0);
2203 // Also put transform animations on grand_child_of_root, and
2204 // grand_child_of_rs2
2205 AddAnimatedTransformToController(
2206 grand_child_of_root
->layer_animation_controller(), 10.0, 30, 0);
2207 AddAnimatedTransformToController(
2208 grand_child_of_rs2
->layer_animation_controller(), 10.0, 30, 0);
2210 ExecuteCalculateDrawProperties(parent
.get());
2212 // Only layers that are associated with render surfaces should have an actual
2213 // RenderSurface() value.
2214 ASSERT_TRUE(parent
->render_surface());
2215 ASSERT_FALSE(child_of_root
->render_surface());
2216 ASSERT_FALSE(grand_child_of_root
->render_surface());
2218 ASSERT_TRUE(render_surface1
->render_surface());
2219 ASSERT_FALSE(child_of_rs1
->render_surface());
2220 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
2222 ASSERT_TRUE(render_surface2
->render_surface());
2223 ASSERT_FALSE(child_of_rs2
->render_surface());
2224 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
2226 // Verify all render target accessors
2227 EXPECT_EQ(parent
.get(), parent
->render_target());
2228 EXPECT_EQ(parent
.get(), child_of_root
->render_target());
2229 EXPECT_EQ(parent
.get(), grand_child_of_root
->render_target());
2231 EXPECT_EQ(render_surface1
.get(), render_surface1
->render_target());
2232 EXPECT_EQ(render_surface1
.get(), child_of_rs1
->render_target());
2233 EXPECT_EQ(render_surface1
.get(), grand_child_of_rs1
->render_target());
2235 EXPECT_EQ(render_surface2
.get(), render_surface2
->render_target());
2236 EXPECT_EQ(render_surface2
.get(), child_of_rs2
->render_target());
2237 EXPECT_EQ(render_surface2
.get(), grand_child_of_rs2
->render_target());
2239 // Verify draw_opacity_is_animating values
2240 EXPECT_FALSE(parent
->draw_opacity_is_animating());
2241 EXPECT_FALSE(child_of_root
->draw_opacity_is_animating());
2242 EXPECT_TRUE(grand_child_of_root
->draw_opacity_is_animating());
2243 EXPECT_FALSE(render_surface1
->draw_opacity_is_animating());
2244 EXPECT_TRUE(render_surface1
->render_surface()->draw_opacity_is_animating());
2245 EXPECT_FALSE(child_of_rs1
->draw_opacity_is_animating());
2246 EXPECT_FALSE(grand_child_of_rs1
->draw_opacity_is_animating());
2247 EXPECT_FALSE(render_surface2
->draw_opacity_is_animating());
2248 EXPECT_FALSE(render_surface2
->render_surface()->draw_opacity_is_animating());
2249 EXPECT_FALSE(child_of_rs2
->draw_opacity_is_animating());
2250 EXPECT_FALSE(grand_child_of_rs2
->draw_opacity_is_animating());
2252 // Verify draw_transform_is_animating values
2253 EXPECT_FALSE(parent
->draw_transform_is_animating());
2254 EXPECT_FALSE(child_of_root
->draw_transform_is_animating());
2255 EXPECT_TRUE(grand_child_of_root
->draw_transform_is_animating());
2256 EXPECT_FALSE(render_surface1
->draw_transform_is_animating());
2257 EXPECT_FALSE(render_surface1
->render_surface()
2258 ->target_surface_transforms_are_animating());
2259 EXPECT_FALSE(child_of_rs1
->draw_transform_is_animating());
2260 EXPECT_FALSE(grand_child_of_rs1
->draw_transform_is_animating());
2261 EXPECT_FALSE(render_surface2
->draw_transform_is_animating());
2262 EXPECT_TRUE(render_surface2
->render_surface()
2263 ->target_surface_transforms_are_animating());
2264 EXPECT_FALSE(child_of_rs2
->draw_transform_is_animating());
2265 EXPECT_TRUE(grand_child_of_rs2
->draw_transform_is_animating());
2267 // Verify screen_space_transform_is_animating values
2268 EXPECT_FALSE(parent
->screen_space_transform_is_animating());
2269 EXPECT_FALSE(child_of_root
->screen_space_transform_is_animating());
2270 EXPECT_TRUE(grand_child_of_root
->screen_space_transform_is_animating());
2271 EXPECT_FALSE(render_surface1
->screen_space_transform_is_animating());
2272 EXPECT_FALSE(render_surface1
->render_surface()
2273 ->screen_space_transforms_are_animating());
2274 EXPECT_FALSE(child_of_rs1
->screen_space_transform_is_animating());
2275 EXPECT_FALSE(grand_child_of_rs1
->screen_space_transform_is_animating());
2276 EXPECT_TRUE(render_surface2
->screen_space_transform_is_animating());
2277 EXPECT_TRUE(render_surface2
->render_surface()
2278 ->screen_space_transforms_are_animating());
2279 EXPECT_TRUE(child_of_rs2
->screen_space_transform_is_animating());
2280 EXPECT_TRUE(grand_child_of_rs2
->screen_space_transform_is_animating());
2282 // Sanity check. If these fail there is probably a bug in the test itself.
2283 // It is expected that we correctly set up transforms so that the y-component
2284 // of the screen-space transform encodes the "depth" of the layer in the tree.
2285 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
2286 EXPECT_FLOAT_EQ(2.0,
2287 child_of_root
->screen_space_transform().matrix().get(1, 3));
2289 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
2291 EXPECT_FLOAT_EQ(2.0,
2292 render_surface1
->screen_space_transform().matrix().get(1, 3));
2293 EXPECT_FLOAT_EQ(3.0,
2294 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2296 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2298 EXPECT_FLOAT_EQ(3.0,
2299 render_surface2
->screen_space_transform().matrix().get(1, 3));
2300 EXPECT_FLOAT_EQ(4.0,
2301 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2303 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2306 TEST_F(LayerTreeHostCommonTest
, VisibleRectForIdentityTransform
) {
2307 // Test the calculateVisibleRect() function works correctly for identity
2310 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2311 gfx::Transform layer_to_surface_transform
;
2313 // Case 1: Layer is contained within the surface.
2314 gfx::Rect layer_content_rect
= gfx::Rect(10, 10, 30, 30);
2315 gfx::Rect expected
= gfx::Rect(10, 10, 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_content_rect
= gfx::Rect(120, 120, 30, 30);
2322 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2323 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2324 EXPECT_TRUE(actual
.IsEmpty());
2326 // Case 3: Layer is partially overlapping the surface rect.
2327 layer_content_rect
= gfx::Rect(80, 80, 30, 30);
2328 expected
= gfx::Rect(80, 80, 20, 20);
2329 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2330 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2331 EXPECT_RECT_EQ(expected
, actual
);
2334 TEST_F(LayerTreeHostCommonTest
, VisibleRectForTranslations
) {
2335 // Test the calculateVisibleRect() function works correctly for scaling
2338 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2339 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2340 gfx::Transform layer_to_surface_transform
;
2342 // Case 1: Layer is contained within the surface.
2343 layer_to_surface_transform
.MakeIdentity();
2344 layer_to_surface_transform
.Translate(10.0, 10.0);
2345 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2346 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2347 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2348 EXPECT_RECT_EQ(expected
, actual
);
2350 // Case 2: Layer is outside the surface rect.
2351 layer_to_surface_transform
.MakeIdentity();
2352 layer_to_surface_transform
.Translate(120.0, 120.0);
2353 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2354 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2355 EXPECT_TRUE(actual
.IsEmpty());
2357 // Case 3: Layer is partially overlapping the surface rect.
2358 layer_to_surface_transform
.MakeIdentity();
2359 layer_to_surface_transform
.Translate(80.0, 80.0);
2360 expected
= gfx::Rect(0, 0, 20, 20);
2361 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2362 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2363 EXPECT_RECT_EQ(expected
, actual
);
2366 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor2DRotations
) {
2367 // Test the calculateVisibleRect() function works correctly for rotations
2368 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2369 // should return the g in the layer's space.
2371 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2372 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2373 gfx::Transform layer_to_surface_transform
;
2375 // Case 1: Layer is contained within the surface.
2376 layer_to_surface_transform
.MakeIdentity();
2377 layer_to_surface_transform
.Translate(50.0, 50.0);
2378 layer_to_surface_transform
.Rotate(45.0);
2379 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2380 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2381 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2382 EXPECT_RECT_EQ(expected
, actual
);
2384 // Case 2: Layer is outside the surface rect.
2385 layer_to_surface_transform
.MakeIdentity();
2386 layer_to_surface_transform
.Translate(-50.0, 0.0);
2387 layer_to_surface_transform
.Rotate(45.0);
2388 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2389 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2390 EXPECT_TRUE(actual
.IsEmpty());
2392 // Case 3: The layer is rotated about its top-left corner. In surface space,
2393 // the layer is oriented diagonally, with the left half outside of the render
2394 // surface. In this case, the g should still be the entire layer
2395 // (remember the g is computed in layer space); both the top-left
2396 // and bottom-right corners of the layer are still visible.
2397 layer_to_surface_transform
.MakeIdentity();
2398 layer_to_surface_transform
.Rotate(45.0);
2399 expected
= gfx::Rect(0, 0, 30, 30);
2400 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2401 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2402 EXPECT_RECT_EQ(expected
, actual
);
2404 // Case 4: The layer is rotated about its top-left corner, and translated
2405 // upwards. In surface space, the layer is oriented diagonally, with only the
2406 // top corner of the surface overlapping the layer. In layer space, the render
2407 // surface overlaps the right side of the layer. The g should be
2408 // the layer's right half.
2409 layer_to_surface_transform
.MakeIdentity();
2410 layer_to_surface_transform
.Translate(0.0, -sqrt(2.0) * 15.0);
2411 layer_to_surface_transform
.Rotate(45.0);
2412 expected
= gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
2413 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2414 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2415 EXPECT_RECT_EQ(expected
, actual
);
2418 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dOrthographicTransform
) {
2419 // Test that the calculateVisibleRect() function works correctly for 3d
2422 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2423 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2424 gfx::Transform layer_to_surface_transform
;
2426 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2427 // degrees, should be fully contained in the render surface.
2428 layer_to_surface_transform
.MakeIdentity();
2429 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2430 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2431 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2432 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2433 EXPECT_RECT_EQ(expected
, actual
);
2435 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2436 // degrees, but shifted to the side so only the right-half the layer would be
2437 // visible on the surface.
2438 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2439 SkMScalar half_width_of_rotated_layer
=
2440 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
2441 layer_to_surface_transform
.MakeIdentity();
2442 layer_to_surface_transform
.Translate(-half_width_of_rotated_layer
, 0.0);
2443 layer_to_surface_transform
.RotateAboutYAxis(45.0); // Rotates about the left
2444 // edge of the layer.
2445 expected
= gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
2446 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2447 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2448 EXPECT_RECT_EQ(expected
, actual
);
2451 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveTransform
) {
2452 // Test the calculateVisibleRect() function works correctly when the layer has
2453 // a perspective projection onto the target surface.
2455 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2456 gfx::Rect layer_content_rect
= gfx::Rect(-50, -50, 200, 200);
2457 gfx::Transform layer_to_surface_transform
;
2459 // Case 1: Even though the layer is twice as large as the surface, due to
2460 // perspective foreshortening, the layer will fit fully in the surface when
2461 // its translated more than the perspective amount.
2462 layer_to_surface_transform
.MakeIdentity();
2464 // The following sequence of transforms applies the perspective about the
2465 // center of the surface.
2466 layer_to_surface_transform
.Translate(50.0, 50.0);
2467 layer_to_surface_transform
.ApplyPerspectiveDepth(9.0);
2468 layer_to_surface_transform
.Translate(-50.0, -50.0);
2470 // This translate places the layer in front of the surface's projection plane.
2471 layer_to_surface_transform
.Translate3d(0.0, 0.0, -27.0);
2473 gfx::Rect expected
= gfx::Rect(-50, -50, 200, 200);
2474 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2475 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2476 EXPECT_RECT_EQ(expected
, actual
);
2478 // Case 2: same projection as before, except that the layer is also translated
2479 // to the side, so that only the right half of the layer should be visible.
2481 // Explanation of expected result: The perspective ratio is (z distance
2482 // between layer and camera origin) / (z distance between projection plane and
2483 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2484 // move a layer by translating -50 units in projected surface units (so that
2485 // only half of it is visible), then we would need to translate by (-36 / 9) *
2486 // -50 == -200 in the layer's units.
2487 layer_to_surface_transform
.Translate3d(-200.0, 0.0, 0.0);
2488 expected
= gfx::Rect(gfx::Point(50, -50),
2489 gfx::Size(100, 200)); // The right half of the layer's
2491 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2492 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2493 EXPECT_RECT_EQ(expected
, actual
);
2496 TEST_F(LayerTreeHostCommonTest
,
2497 VisibleRectFor3dOrthographicIsNotClippedBehindSurface
) {
2498 // There is currently no explicit concept of an orthographic projection plane
2499 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2500 // are technically behind the surface in an orthographic world should not be
2501 // clipped when they are flattened to the surface.
2503 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2504 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2505 gfx::Transform layer_to_surface_transform
;
2507 // This sequence of transforms effectively rotates the layer about the y-axis
2508 // at the center of the layer.
2509 layer_to_surface_transform
.MakeIdentity();
2510 layer_to_surface_transform
.Translate(50.0, 0.0);
2511 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2512 layer_to_surface_transform
.Translate(-50.0, 0.0);
2514 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2515 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2516 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2517 EXPECT_RECT_EQ(expected
, actual
);
2520 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveWhenClippedByW
) {
2521 // Test the calculateVisibleRect() function works correctly when projecting a
2522 // surface onto a layer, but the layer is partially behind the camera (not
2523 // just behind the projection plane). In this case, the cartesian coordinates
2524 // may seem to be valid, but actually they are not. The visible rect needs to
2525 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2526 // converting to cartesian coordinates.
2528 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2529 gfx::Rect layer_content_rect
= gfx::Rect(-10, -1, 20, 2);
2530 gfx::Transform layer_to_surface_transform
;
2532 // The layer is positioned so that the right half of the layer should be in
2533 // front of the camera, while the other half is behind the surface's
2534 // projection plane. The following sequence of transforms applies the
2535 // perspective and rotation about the center of the layer.
2536 layer_to_surface_transform
.MakeIdentity();
2537 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2538 layer_to_surface_transform
.Translate3d(-2.0, 0.0, 1.0);
2539 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2541 // Sanity check that this transform does indeed cause w < 0 when applying the
2542 // transform, otherwise this code is not testing the intended scenario.
2544 MathUtil::MapQuad(layer_to_surface_transform
,
2545 gfx::QuadF(gfx::RectF(layer_content_rect
)),
2547 ASSERT_TRUE(clipped
);
2549 int expected_x_position
= 0;
2550 int expected_width
= 10;
2551 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2552 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2553 EXPECT_EQ(expected_x_position
, actual
.x());
2554 EXPECT_EQ(expected_width
, actual
.width());
2557 TEST_F(LayerTreeHostCommonTest
, VisibleRectForPerspectiveUnprojection
) {
2558 // To determine visible rect in layer space, there needs to be an
2559 // un-projection from surface space to layer space. When the original
2560 // transform was a perspective projection that was clipped, it returns a rect
2561 // that encloses the clipped bounds. Un-projecting this new rect may require
2564 // This sequence of transforms causes one corner of the layer to protrude
2565 // across the w = 0 plane, and should be clipped.
2566 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2567 gfx::Rect layer_content_rect
= gfx::Rect(-10, -10, 20, 20);
2568 gfx::Transform layer_to_surface_transform
;
2569 layer_to_surface_transform
.MakeIdentity();
2570 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2571 layer_to_surface_transform
.Translate3d(0.0, 0.0, -5.0);
2572 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2573 layer_to_surface_transform
.RotateAboutXAxis(80.0);
2575 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2576 // code is not testing the intended scenario.
2578 gfx::RectF clipped_rect
=
2579 MathUtil::MapClippedRect(layer_to_surface_transform
, layer_content_rect
);
2580 MathUtil::ProjectQuad(
2581 Inverse(layer_to_surface_transform
), gfx::QuadF(clipped_rect
), &clipped
);
2582 ASSERT_TRUE(clipped
);
2584 // Only the corner of the layer is not visible on the surface because of being
2585 // clipped. But, the net result of rounding visible region to an axis-aligned
2586 // rect is that the entire layer should still be considered visible.
2587 gfx::Rect expected
= gfx::Rect(-10, -10, 20, 20);
2588 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2589 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2590 EXPECT_RECT_EQ(expected
, actual
);
2593 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsForSimpleLayers
) {
2594 scoped_refptr
<Layer
> root
= Layer::Create();
2595 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2596 make_scoped_refptr(new LayerWithForcedDrawsContent());
2597 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2598 make_scoped_refptr(new LayerWithForcedDrawsContent());
2599 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2600 make_scoped_refptr(new LayerWithForcedDrawsContent());
2601 root
->AddChild(child1
);
2602 root
->AddChild(child2
);
2603 root
->AddChild(child3
);
2605 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2606 host
->SetRootLayer(root
);
2608 gfx::Transform identity_matrix
;
2609 SetLayerPropertiesForTesting(root
.get(),
2613 gfx::Size(100, 100),
2616 SetLayerPropertiesForTesting(child1
.get(),
2623 SetLayerPropertiesForTesting(child2
.get(),
2626 gfx::PointF(75.f
, 75.f
),
2630 SetLayerPropertiesForTesting(child3
.get(),
2633 gfx::PointF(125.f
, 125.f
),
2638 ExecuteCalculateDrawProperties(root
.get());
2640 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2641 root
->render_surface()->DrawableContentRect());
2642 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2644 // Layers that do not draw content should have empty visible_content_rects.
2645 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2647 // layer visible_content_rects are clipped by their target surface.
2648 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
2649 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_content_rect());
2650 EXPECT_TRUE(child3
->visible_content_rect().IsEmpty());
2652 // layer drawable_content_rects are not clipped.
2653 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->drawable_content_rect());
2654 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2655 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2658 TEST_F(LayerTreeHostCommonTest
,
2659 DrawableAndVisibleContentRectsForLayersClippedByLayer
) {
2660 scoped_refptr
<Layer
> root
= Layer::Create();
2661 scoped_refptr
<Layer
> child
= Layer::Create();
2662 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child1
=
2663 make_scoped_refptr(new LayerWithForcedDrawsContent());
2664 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child2
=
2665 make_scoped_refptr(new LayerWithForcedDrawsContent());
2666 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child3
=
2667 make_scoped_refptr(new LayerWithForcedDrawsContent());
2668 root
->AddChild(child
);
2669 child
->AddChild(grand_child1
);
2670 child
->AddChild(grand_child2
);
2671 child
->AddChild(grand_child3
);
2673 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2674 host
->SetRootLayer(root
);
2676 gfx::Transform identity_matrix
;
2677 SetLayerPropertiesForTesting(root
.get(),
2681 gfx::Size(100, 100),
2684 SetLayerPropertiesForTesting(child
.get(),
2688 gfx::Size(100, 100),
2691 SetLayerPropertiesForTesting(grand_child1
.get(),
2694 gfx::PointF(5.f
, 5.f
),
2698 SetLayerPropertiesForTesting(grand_child2
.get(),
2701 gfx::PointF(75.f
, 75.f
),
2705 SetLayerPropertiesForTesting(grand_child3
.get(),
2708 gfx::PointF(125.f
, 125.f
),
2713 child
->SetMasksToBounds(true);
2714 ExecuteCalculateDrawProperties(root
.get());
2716 ASSERT_FALSE(child
->render_surface());
2718 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2719 root
->render_surface()->DrawableContentRect());
2720 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2722 // Layers that do not draw content should have empty visible content rects.
2723 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2724 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child
->visible_content_rect());
2726 // All grandchild visible content rects should be clipped by child.
2727 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1
->visible_content_rect());
2728 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2
->visible_content_rect());
2729 EXPECT_TRUE(grand_child3
->visible_content_rect().IsEmpty());
2731 // All grandchild DrawableContentRects should also be clipped by child.
2732 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50),
2733 grand_child1
->drawable_content_rect());
2734 EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25),
2735 grand_child2
->drawable_content_rect());
2736 EXPECT_TRUE(grand_child3
->drawable_content_rect().IsEmpty());
2739 TEST_F(LayerTreeHostCommonTest
,
2740 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface
) {
2741 scoped_refptr
<Layer
> root
= Layer::Create();
2742 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
2743 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2744 make_scoped_refptr(new LayerWithForcedDrawsContent());
2745 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2746 make_scoped_refptr(new LayerWithForcedDrawsContent());
2747 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2748 make_scoped_refptr(new LayerWithForcedDrawsContent());
2749 root
->AddChild(render_surface1
);
2750 render_surface1
->AddChild(child1
);
2751 render_surface1
->AddChild(child2
);
2752 render_surface1
->AddChild(child3
);
2754 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2755 host
->SetRootLayer(root
);
2757 gfx::Transform identity_matrix
;
2758 SetLayerPropertiesForTesting(root
.get(),
2762 gfx::Size(100, 100),
2765 SetLayerPropertiesForTesting(render_surface1
.get(),
2772 SetLayerPropertiesForTesting(child1
.get(),
2775 gfx::PointF(5.f
, 5.f
),
2779 SetLayerPropertiesForTesting(child2
.get(),
2782 gfx::PointF(75.f
, 75.f
),
2786 SetLayerPropertiesForTesting(child3
.get(),
2789 gfx::PointF(125.f
, 125.f
),
2794 render_surface1
->SetForceRenderSurface(true);
2795 ExecuteCalculateDrawProperties(root
.get());
2797 ASSERT_TRUE(render_surface1
->render_surface());
2799 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2800 root
->render_surface()->DrawableContentRect());
2801 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2803 // Layers that do not draw content should have empty visible content rects.
2804 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2805 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
2806 render_surface1
->visible_content_rect());
2808 // An unclipped surface grows its DrawableContentRect to include all drawable
2809 // regions of the subtree.
2810 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
2811 render_surface1
->render_surface()->DrawableContentRect());
2813 // All layers that draw content into the unclipped surface are also unclipped.
2814 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
2815 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
2816 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
2818 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2819 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2820 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2823 TEST_F(LayerTreeHostCommonTest
,
2824 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform
) {
2825 scoped_refptr
<Layer
> root
= Layer::Create();
2826 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2827 make_scoped_refptr(new LayerWithForcedDrawsContent());
2828 root
->AddChild(child
);
2830 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2831 host
->SetRootLayer(root
);
2833 // Case 1: a truly degenerate matrix
2834 gfx::Transform identity_matrix
;
2835 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2836 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2838 SetLayerPropertiesForTesting(root
.get(),
2842 gfx::Size(100, 100),
2845 SetLayerPropertiesForTesting(child
.get(),
2846 uninvertible_matrix
,
2848 gfx::PointF(5.f
, 5.f
),
2853 ExecuteCalculateDrawProperties(root
.get());
2855 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
2856 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2858 // Case 2: a matrix with flattened z, uninvertible and not visible according
2860 uninvertible_matrix
.MakeIdentity();
2861 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2862 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2864 SetLayerPropertiesForTesting(child
.get(),
2865 uninvertible_matrix
,
2867 gfx::PointF(5.f
, 5.f
),
2872 ExecuteCalculateDrawProperties(root
.get());
2874 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
2875 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2877 // Case 3: a matrix with flattened z, also uninvertible and not visible.
2878 uninvertible_matrix
.MakeIdentity();
2879 uninvertible_matrix
.Translate(500.0, 0.0);
2880 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2881 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2883 SetLayerPropertiesForTesting(child
.get(),
2884 uninvertible_matrix
,
2886 gfx::PointF(5.f
, 5.f
),
2891 ExecuteCalculateDrawProperties(root
.get());
2893 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
2894 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2897 TEST_F(LayerTreeHostCommonTest
,
2898 SingularTransformDoesNotPreventClearingDrawProperties
) {
2899 scoped_refptr
<Layer
> root
= Layer::Create();
2900 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2901 make_scoped_refptr(new LayerWithForcedDrawsContent());
2902 root
->AddChild(child
);
2904 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2905 host
->SetRootLayer(root
);
2907 gfx::Transform identity_matrix
;
2908 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2909 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2911 SetLayerPropertiesForTesting(root
.get(),
2912 uninvertible_matrix
,
2915 gfx::Size(100, 100),
2918 SetLayerPropertiesForTesting(child
.get(),
2921 gfx::PointF(5.f
, 5.f
),
2926 child
->draw_properties().sorted_for_recursion
= true;
2928 TransformOperations start_transform_operations
;
2929 start_transform_operations
.AppendScale(1.f
, 0.f
, 0.f
);
2931 TransformOperations end_transform_operations
;
2932 end_transform_operations
.AppendScale(1.f
, 1.f
, 0.f
);
2934 AddAnimatedTransformToLayer(
2935 root
.get(), 10.0, start_transform_operations
, end_transform_operations
);
2937 EXPECT_TRUE(root
->TransformIsAnimating());
2939 ExecuteCalculateDrawProperties(root
.get());
2941 EXPECT_FALSE(child
->draw_properties().sorted_for_recursion
);
2944 TEST_F(LayerTreeHostCommonTest
,
2945 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties
) {
2946 scoped_refptr
<Layer
> root
= Layer::Create();
2948 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2949 host
->SetRootLayer(root
);
2951 gfx::Transform identity_matrix
;
2952 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2953 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2955 SetLayerPropertiesForTesting(root
.get(),
2956 uninvertible_matrix
,
2959 gfx::Size(100, 100),
2963 root
->draw_properties().sorted_for_recursion
= true;
2965 EXPECT_FALSE(root
->TransformIsAnimating());
2967 ExecuteCalculateDrawProperties(root
.get());
2969 EXPECT_FALSE(root
->draw_properties().sorted_for_recursion
);
2972 TEST_F(LayerTreeHostCommonTest
,
2973 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface
) {
2974 scoped_refptr
<Layer
> root
= Layer::Create();
2975 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
2976 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2977 make_scoped_refptr(new LayerWithForcedDrawsContent());
2978 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2979 make_scoped_refptr(new LayerWithForcedDrawsContent());
2980 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2981 make_scoped_refptr(new LayerWithForcedDrawsContent());
2982 root
->AddChild(render_surface1
);
2983 render_surface1
->AddChild(child1
);
2984 render_surface1
->AddChild(child2
);
2985 render_surface1
->AddChild(child3
);
2987 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2988 host
->SetRootLayer(root
);
2990 gfx::Transform identity_matrix
;
2991 SetLayerPropertiesForTesting(root
.get(),
2995 gfx::Size(100, 100),
2998 SetLayerPropertiesForTesting(render_surface1
.get(),
3005 SetLayerPropertiesForTesting(child1
.get(),
3008 gfx::PointF(5.f
, 5.f
),
3012 SetLayerPropertiesForTesting(child2
.get(),
3015 gfx::PointF(75.f
, 75.f
),
3019 SetLayerPropertiesForTesting(child3
.get(),
3022 gfx::PointF(125.f
, 125.f
),
3027 root
->SetMasksToBounds(true);
3028 render_surface1
->SetForceRenderSurface(true);
3029 ExecuteCalculateDrawProperties(root
.get());
3031 ASSERT_TRUE(render_surface1
->render_surface());
3033 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3034 root
->render_surface()->DrawableContentRect());
3035 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3037 // Layers that do not draw content should have empty visible content rects.
3038 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3039 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3040 render_surface1
->visible_content_rect());
3042 // A clipped surface grows its DrawableContentRect to include all drawable
3043 // regions of the subtree, but also gets clamped by the ancestor's clip.
3044 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3045 render_surface1
->render_surface()->DrawableContentRect());
3047 // All layers that draw content into the surface have their visible content
3048 // rect clipped by the surface clip rect.
3049 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3050 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_content_rect());
3051 EXPECT_TRUE(child3
->visible_content_rect().IsEmpty());
3053 // But the DrawableContentRects are unclipped.
3054 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
3055 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
3056 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
3059 TEST_F(LayerTreeHostCommonTest
,
3060 DrawableAndVisibleContentRectsForSurfaceHierarchy
) {
3061 // Check that clipping does not propagate down surfaces.
3062 scoped_refptr
<Layer
> root
= Layer::Create();
3063 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3064 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
3065 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3066 make_scoped_refptr(new LayerWithForcedDrawsContent());
3067 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3068 make_scoped_refptr(new LayerWithForcedDrawsContent());
3069 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
3070 make_scoped_refptr(new LayerWithForcedDrawsContent());
3071 root
->AddChild(render_surface1
);
3072 render_surface1
->AddChild(render_surface2
);
3073 render_surface2
->AddChild(child1
);
3074 render_surface2
->AddChild(child2
);
3075 render_surface2
->AddChild(child3
);
3077 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3078 host
->SetRootLayer(root
);
3080 gfx::Transform identity_matrix
;
3081 SetLayerPropertiesForTesting(root
.get(),
3085 gfx::Size(100, 100),
3088 SetLayerPropertiesForTesting(render_surface1
.get(),
3095 SetLayerPropertiesForTesting(render_surface2
.get(),
3102 SetLayerPropertiesForTesting(child1
.get(),
3105 gfx::PointF(5.f
, 5.f
),
3109 SetLayerPropertiesForTesting(child2
.get(),
3112 gfx::PointF(75.f
, 75.f
),
3116 SetLayerPropertiesForTesting(child3
.get(),
3119 gfx::PointF(125.f
, 125.f
),
3124 root
->SetMasksToBounds(true);
3125 render_surface1
->SetForceRenderSurface(true);
3126 render_surface2
->SetForceRenderSurface(true);
3127 ExecuteCalculateDrawProperties(root
.get());
3129 ASSERT_TRUE(render_surface1
->render_surface());
3130 ASSERT_TRUE(render_surface2
->render_surface());
3132 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3133 root
->render_surface()->DrawableContentRect());
3134 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3136 // Layers that do not draw content should have empty visible content rects.
3137 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3138 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3139 render_surface1
->visible_content_rect());
3140 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3141 render_surface2
->visible_content_rect());
3143 // A clipped surface grows its DrawableContentRect to include all drawable
3144 // regions of the subtree, but also gets clamped by the ancestor's clip.
3145 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3146 render_surface1
->render_surface()->DrawableContentRect());
3148 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3149 // is only implicitly clipped by render_surface1's content rect. So,
3150 // render_surface2 grows to enclose all drawable content of its subtree.
3151 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
3152 render_surface2
->render_surface()->DrawableContentRect());
3154 // All layers that draw content into render_surface2 think they are unclipped.
3155 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3156 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
3157 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
3159 // DrawableContentRects are also unclipped.
3160 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
3161 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
3162 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
3165 TEST_F(LayerTreeHostCommonTest
,
3166 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface
) {
3167 // Layers that have non-axis aligned bounds (due to transforms) have an
3168 // expanded, axis-aligned DrawableContentRect and visible content rect.
3170 scoped_refptr
<Layer
> root
= Layer::Create();
3171 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3172 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3173 make_scoped_refptr(new LayerWithForcedDrawsContent());
3174 root
->AddChild(render_surface1
);
3175 render_surface1
->AddChild(child1
);
3177 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3178 host
->SetRootLayer(root
);
3180 gfx::Transform identity_matrix
;
3181 gfx::Transform child_rotation
;
3182 child_rotation
.Rotate(45.0);
3183 SetLayerPropertiesForTesting(root
.get(),
3187 gfx::Size(100, 100),
3190 SetLayerPropertiesForTesting(render_surface1
.get(),
3197 SetLayerPropertiesForTesting(child1
.get(),
3199 gfx::Point3F(25, 25, 0.f
),
3200 gfx::PointF(25.f
, 25.f
),
3205 render_surface1
->SetForceRenderSurface(true);
3206 ExecuteCalculateDrawProperties(root
.get());
3208 ASSERT_TRUE(render_surface1
->render_surface());
3210 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3211 root
->render_surface()->DrawableContentRect());
3212 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3214 // Layers that do not draw content should have empty visible content rects.
3215 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3216 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3217 render_surface1
->visible_content_rect());
3219 // The unclipped surface grows its DrawableContentRect to include all drawable
3220 // regions of the subtree.
3221 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3222 gfx::Rect expected_surface_drawable_content
=
3223 gfx::Rect(50 - diagonal_radius
,
3224 50 - diagonal_radius
,
3225 diagonal_radius
* 2,
3226 diagonal_radius
* 2);
3227 EXPECT_RECT_EQ(expected_surface_drawable_content
,
3228 render_surface1
->render_surface()->DrawableContentRect());
3230 // All layers that draw content into the unclipped surface are also unclipped.
3231 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3232 EXPECT_RECT_EQ(expected_surface_drawable_content
,
3233 child1
->drawable_content_rect());
3236 TEST_F(LayerTreeHostCommonTest
,
3237 DrawableAndVisibleContentRectsWithTransformOnClippedSurface
) {
3238 // Layers that have non-axis aligned bounds (due to transforms) have an
3239 // expanded, axis-aligned DrawableContentRect and visible content rect.
3241 scoped_refptr
<Layer
> root
= Layer::Create();
3242 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3243 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3244 make_scoped_refptr(new LayerWithForcedDrawsContent());
3245 root
->AddChild(render_surface1
);
3246 render_surface1
->AddChild(child1
);
3248 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3249 host
->SetRootLayer(root
);
3251 gfx::Transform identity_matrix
;
3252 gfx::Transform child_rotation
;
3253 child_rotation
.Rotate(45.0);
3254 SetLayerPropertiesForTesting(root
.get(),
3261 SetLayerPropertiesForTesting(render_surface1
.get(),
3269 SetLayerPropertiesForTesting(child1
.get(),
3271 gfx::Point3F(25, 25, 0.f
),
3272 gfx::PointF(25.f
, 25.f
),
3277 root
->SetMasksToBounds(true);
3278 render_surface1
->SetForceRenderSurface(true);
3279 ExecuteCalculateDrawProperties(root
.get());
3281 ASSERT_TRUE(render_surface1
->render_surface());
3283 // The clipped surface clamps the DrawableContentRect that encloses the
3285 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3286 gfx::Rect unclipped_surface_content
= gfx::Rect(50 - diagonal_radius
,
3287 50 - diagonal_radius
,
3288 diagonal_radius
* 2,
3289 diagonal_radius
* 2);
3290 gfx::Rect expected_surface_drawable_content
=
3291 gfx::IntersectRects(unclipped_surface_content
, gfx::Rect(0, 0, 50, 50));
3292 EXPECT_RECT_EQ(expected_surface_drawable_content
,
3293 render_surface1
->render_surface()->DrawableContentRect());
3295 // On the clipped surface, only a quarter of the child1 is visible, but when
3296 // rotating it back to child1's content space, the actual enclosing rect ends
3297 // up covering the full left half of child1.
3299 // Given the floating point math, this number is a little bit fuzzy.
3300 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1
->visible_content_rect());
3302 // The child's DrawableContentRect is unclipped.
3303 EXPECT_RECT_EQ(unclipped_surface_content
, child1
->drawable_content_rect());
3306 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsInHighDPI
) {
3307 MockContentLayerClient client
;
3309 scoped_refptr
<Layer
> root
= Layer::Create();
3310 scoped_refptr
<FakePictureLayer
> render_surface1
=
3311 CreateDrawablePictureLayer(&client
);
3312 scoped_refptr
<FakePictureLayer
> render_surface2
=
3313 CreateDrawablePictureLayer(&client
);
3314 scoped_refptr
<FakePictureLayer
> child1
= CreateDrawablePictureLayer(&client
);
3315 scoped_refptr
<FakePictureLayer
> child2
= CreateDrawablePictureLayer(&client
);
3316 scoped_refptr
<FakePictureLayer
> child3
= CreateDrawablePictureLayer(&client
);
3317 root
->AddChild(render_surface1
);
3318 render_surface1
->AddChild(render_surface2
);
3319 render_surface2
->AddChild(child1
);
3320 render_surface2
->AddChild(child2
);
3321 render_surface2
->AddChild(child3
);
3323 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3324 host
->SetRootLayer(root
);
3326 gfx::Transform identity_matrix
;
3327 SetLayerPropertiesForTesting(root
.get(),
3331 gfx::Size(100, 100),
3334 SetLayerPropertiesForTesting(render_surface1
.get(),
3337 gfx::PointF(5.f
, 5.f
),
3341 SetLayerPropertiesForTesting(render_surface2
.get(),
3344 gfx::PointF(5.f
, 5.f
),
3348 SetLayerPropertiesForTesting(child1
.get(),
3351 gfx::PointF(5.f
, 5.f
),
3355 SetLayerPropertiesForTesting(child2
.get(),
3358 gfx::PointF(75.f
, 75.f
),
3362 SetLayerPropertiesForTesting(child3
.get(),
3365 gfx::PointF(125.f
, 125.f
),
3370 float device_scale_factor
= 2.f
;
3372 root
->SetMasksToBounds(true);
3373 render_surface1
->SetForceRenderSurface(true);
3374 render_surface2
->SetForceRenderSurface(true);
3375 ExecuteCalculateDrawProperties(root
.get(), device_scale_factor
);
3377 ASSERT_TRUE(render_surface1
->render_surface());
3378 ASSERT_TRUE(render_surface2
->render_surface());
3380 // drawable_content_rects for all layers and surfaces are scaled by
3381 // device_scale_factor.
3382 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200),
3383 root
->render_surface()->DrawableContentRect());
3384 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root
->drawable_content_rect());
3385 EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190),
3386 render_surface1
->render_surface()->DrawableContentRect());
3388 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3389 // is only implicitly clipped by render_surface1.
3390 EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350),
3391 render_surface2
->render_surface()->DrawableContentRect());
3393 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1
->drawable_content_rect());
3394 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100),
3395 child2
->drawable_content_rect());
3396 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100),
3397 child3
->drawable_content_rect());
3399 // The root layer does not actually draw content of its own.
3400 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3402 // All layer visible content rects are not expressed in content space of each
3403 // layer, so they are not scaled by the device_scale_factor.
3404 EXPECT_RECT_EQ(gfx::Rect(0, 0, 3, 4),
3405 render_surface1
->visible_content_rect());
3406 EXPECT_RECT_EQ(gfx::Rect(0, 0, 7, 13),
3407 render_surface2
->visible_content_rect());
3408 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3409 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
3410 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
3413 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithoutPreserves3d
) {
3414 // Verify the behavior of back-face culling when there are no preserve-3d
3415 // layers. Note that 3d transforms still apply in this case, but they are
3416 // "flattened" to each parent layer according to current W3C spec.
3418 const gfx::Transform identity_matrix
;
3419 scoped_refptr
<Layer
> parent
= Layer::Create();
3420 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3421 make_scoped_refptr(new LayerWithForcedDrawsContent());
3422 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3423 make_scoped_refptr(new LayerWithForcedDrawsContent());
3424 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3425 make_scoped_refptr(new LayerWithForcedDrawsContent());
3426 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3427 make_scoped_refptr(new LayerWithForcedDrawsContent());
3428 scoped_refptr
<LayerWithForcedDrawsContent
>
3429 front_facing_child_of_front_facing_surface
=
3430 make_scoped_refptr(new LayerWithForcedDrawsContent());
3431 scoped_refptr
<LayerWithForcedDrawsContent
>
3432 back_facing_child_of_front_facing_surface
=
3433 make_scoped_refptr(new LayerWithForcedDrawsContent());
3434 scoped_refptr
<LayerWithForcedDrawsContent
>
3435 front_facing_child_of_back_facing_surface
=
3436 make_scoped_refptr(new LayerWithForcedDrawsContent());
3437 scoped_refptr
<LayerWithForcedDrawsContent
>
3438 back_facing_child_of_back_facing_surface
=
3439 make_scoped_refptr(new LayerWithForcedDrawsContent());
3441 parent
->AddChild(front_facing_child
);
3442 parent
->AddChild(back_facing_child
);
3443 parent
->AddChild(front_facing_surface
);
3444 parent
->AddChild(back_facing_surface
);
3445 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3446 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3447 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3448 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3450 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3451 host
->SetRootLayer(parent
);
3453 // Nothing is double-sided
3454 front_facing_child
->SetDoubleSided(false);
3455 back_facing_child
->SetDoubleSided(false);
3456 front_facing_surface
->SetDoubleSided(false);
3457 back_facing_surface
->SetDoubleSided(false);
3458 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3459 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3460 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3461 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3463 gfx::Transform backface_matrix
;
3464 backface_matrix
.Translate(50.0, 50.0);
3465 backface_matrix
.RotateAboutYAxis(180.0);
3466 backface_matrix
.Translate(-50.0, -50.0);
3468 // Having a descendant and opacity will force these to have render surfaces.
3469 front_facing_surface
->SetOpacity(0.5f
);
3470 back_facing_surface
->SetOpacity(0.5f
);
3472 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3473 // these layers should blindly use their own local transforms to determine
3474 // back-face culling.
3475 SetLayerPropertiesForTesting(parent
.get(),
3479 gfx::Size(100, 100),
3482 SetLayerPropertiesForTesting(front_facing_child
.get(),
3486 gfx::Size(100, 100),
3489 SetLayerPropertiesForTesting(back_facing_child
.get(),
3493 gfx::Size(100, 100),
3496 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3500 gfx::Size(100, 100),
3503 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3507 gfx::Size(100, 100),
3510 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3514 gfx::Size(100, 100),
3517 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3521 gfx::Size(100, 100),
3524 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3528 gfx::Size(100, 100),
3531 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3535 gfx::Size(100, 100),
3539 RenderSurfaceLayerList render_surface_layer_list
;
3540 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3541 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3542 inputs
.can_adjust_raster_scales
= true;
3543 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3545 // Verify which render surfaces were created.
3546 EXPECT_FALSE(front_facing_child
->render_surface());
3547 EXPECT_FALSE(back_facing_child
->render_surface());
3548 EXPECT_TRUE(front_facing_surface
->render_surface());
3549 EXPECT_TRUE(back_facing_surface
->render_surface());
3550 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3551 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3552 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3553 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3555 // Verify the render_surface_layer_list.
3556 ASSERT_EQ(3u, render_surface_layer_list
.size());
3557 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3558 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
3559 // Even though the back facing surface LAYER gets culled, the other
3560 // descendants should still be added, so the SURFACE should not be culled.
3561 EXPECT_EQ(back_facing_surface
->id(), render_surface_layer_list
.at(2)->id());
3563 // Verify root surface's layer list.
3566 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3567 EXPECT_EQ(front_facing_child
->id(),
3568 render_surface_layer_list
.at(0)
3573 EXPECT_EQ(front_facing_surface
->id(),
3574 render_surface_layer_list
.at(0)
3579 EXPECT_EQ(back_facing_surface
->id(),
3580 render_surface_layer_list
.at(0)
3586 // Verify front_facing_surface's layer list.
3589 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3590 EXPECT_EQ(front_facing_surface
->id(),
3591 render_surface_layer_list
.at(1)
3596 EXPECT_EQ(front_facing_child_of_front_facing_surface
->id(),
3597 render_surface_layer_list
.at(1)
3603 // Verify back_facing_surface's layer list; its own layer should be culled
3604 // from the surface list.
3607 render_surface_layer_list
.at(2)->render_surface()->layer_list().size());
3608 EXPECT_EQ(front_facing_child_of_back_facing_surface
->id(),
3609 render_surface_layer_list
.at(2)
3616 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithPreserves3d
) {
3617 // Verify the behavior of back-face culling when preserves-3d transform style
3620 const gfx::Transform identity_matrix
;
3621 scoped_refptr
<Layer
> parent
= Layer::Create();
3622 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3623 make_scoped_refptr(new LayerWithForcedDrawsContent());
3624 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3625 make_scoped_refptr(new LayerWithForcedDrawsContent());
3626 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3627 make_scoped_refptr(new LayerWithForcedDrawsContent());
3628 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3629 make_scoped_refptr(new LayerWithForcedDrawsContent());
3630 scoped_refptr
<LayerWithForcedDrawsContent
>
3631 front_facing_child_of_front_facing_surface
=
3632 make_scoped_refptr(new LayerWithForcedDrawsContent());
3633 scoped_refptr
<LayerWithForcedDrawsContent
>
3634 back_facing_child_of_front_facing_surface
=
3635 make_scoped_refptr(new LayerWithForcedDrawsContent());
3636 scoped_refptr
<LayerWithForcedDrawsContent
>
3637 front_facing_child_of_back_facing_surface
=
3638 make_scoped_refptr(new LayerWithForcedDrawsContent());
3639 scoped_refptr
<LayerWithForcedDrawsContent
>
3640 back_facing_child_of_back_facing_surface
=
3641 make_scoped_refptr(new LayerWithForcedDrawsContent());
3642 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer1
=
3643 make_scoped_refptr(new LayerWithForcedDrawsContent());
3644 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer2
=
3645 make_scoped_refptr(new LayerWithForcedDrawsContent());
3647 parent
->AddChild(front_facing_child
);
3648 parent
->AddChild(back_facing_child
);
3649 parent
->AddChild(front_facing_surface
);
3650 parent
->AddChild(back_facing_surface
);
3651 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3652 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3653 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3654 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3656 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3657 host
->SetRootLayer(parent
);
3659 // Nothing is double-sided
3660 front_facing_child
->SetDoubleSided(false);
3661 back_facing_child
->SetDoubleSided(false);
3662 front_facing_surface
->SetDoubleSided(false);
3663 back_facing_surface
->SetDoubleSided(false);
3664 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3665 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3666 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3667 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3669 gfx::Transform backface_matrix
;
3670 backface_matrix
.Translate(50.0, 50.0);
3671 backface_matrix
.RotateAboutYAxis(180.0);
3672 backface_matrix
.Translate(-50.0, -50.0);
3674 // Opacity will not force creation of render surfaces in this case because of
3675 // the preserve-3d transform style. Instead, an example of when a surface
3676 // would be created with preserve-3d is when there is a replica layer.
3677 front_facing_surface
->SetReplicaLayer(dummy_replica_layer1
.get());
3678 back_facing_surface
->SetReplicaLayer(dummy_replica_layer2
.get());
3680 // Each surface creates its own new 3d rendering context (as defined by W3C
3681 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3682 // rendering context should use the transform with respect to that context.
3683 // This 3d rendering context occurs when (a) parent's transform style is flat
3684 // and (b) the layer's transform style is preserve-3d.
3685 SetLayerPropertiesForTesting(parent
.get(),
3689 gfx::Size(100, 100),
3691 false); // parent transform style is flat.
3692 SetLayerPropertiesForTesting(front_facing_child
.get(),
3696 gfx::Size(100, 100),
3699 SetLayerPropertiesForTesting(back_facing_child
.get(),
3703 gfx::Size(100, 100),
3706 // surface transform style is preserve-3d.
3707 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3711 gfx::Size(100, 100),
3714 // surface transform style is preserve-3d.
3715 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3719 gfx::Size(100, 100),
3722 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3726 gfx::Size(100, 100),
3729 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3733 gfx::Size(100, 100),
3736 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3740 gfx::Size(100, 100),
3743 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3747 gfx::Size(100, 100),
3751 RenderSurfaceLayerList render_surface_layer_list
;
3752 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3753 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3754 inputs
.can_adjust_raster_scales
= true;
3755 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3757 // Verify which render surfaces were created.
3758 EXPECT_FALSE(front_facing_child
->render_surface());
3759 EXPECT_FALSE(back_facing_child
->render_surface());
3760 EXPECT_TRUE(front_facing_surface
->render_surface());
3761 EXPECT_FALSE(back_facing_surface
->render_surface());
3762 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3763 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3764 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3765 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3767 // Verify the render_surface_layer_list. The back-facing surface should be
3769 ASSERT_EQ(2u, render_surface_layer_list
.size());
3770 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3771 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
3773 // Verify root surface's layer list.
3776 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3777 EXPECT_EQ(front_facing_child
->id(),
3778 render_surface_layer_list
.at(0)
3779 ->render_surface()->layer_list().at(0)->id());
3780 EXPECT_EQ(front_facing_surface
->id(),
3781 render_surface_layer_list
.at(0)
3782 ->render_surface()->layer_list().at(1)->id());
3784 // Verify front_facing_surface's layer list.
3787 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3788 EXPECT_EQ(front_facing_surface
->id(),
3789 render_surface_layer_list
.at(1)
3790 ->render_surface()->layer_list().at(0)->id());
3791 EXPECT_EQ(front_facing_child_of_front_facing_surface
->id(),
3792 render_surface_layer_list
.at(1)
3793 ->render_surface()->layer_list().at(1)->id());
3796 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithAnimatingTransforms
) {
3797 // Verify that layers are appropriately culled when their back face is showing
3798 // and they are not double sided, while animations are going on.
3800 // Layers that are animating do not get culled on the main thread, as their
3801 // transforms should be treated as "unknown" so we can not be sure that their
3802 // back face is really showing.
3803 const gfx::Transform identity_matrix
;
3804 scoped_refptr
<Layer
> parent
= Layer::Create();
3805 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
3806 make_scoped_refptr(new LayerWithForcedDrawsContent());
3807 scoped_refptr
<LayerWithForcedDrawsContent
> animating_surface
=
3808 make_scoped_refptr(new LayerWithForcedDrawsContent());
3809 scoped_refptr
<LayerWithForcedDrawsContent
> child_of_animating_surface
=
3810 make_scoped_refptr(new LayerWithForcedDrawsContent());
3811 scoped_refptr
<LayerWithForcedDrawsContent
> animating_child
=
3812 make_scoped_refptr(new LayerWithForcedDrawsContent());
3813 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3814 make_scoped_refptr(new LayerWithForcedDrawsContent());
3816 parent
->AddChild(child
);
3817 parent
->AddChild(animating_surface
);
3818 animating_surface
->AddChild(child_of_animating_surface
);
3819 parent
->AddChild(animating_child
);
3820 parent
->AddChild(child2
);
3822 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3823 host
->SetRootLayer(parent
);
3825 // Nothing is double-sided
3826 child
->SetDoubleSided(false);
3827 child2
->SetDoubleSided(false);
3828 animating_surface
->SetDoubleSided(false);
3829 child_of_animating_surface
->SetDoubleSided(false);
3830 animating_child
->SetDoubleSided(false);
3832 gfx::Transform backface_matrix
;
3833 backface_matrix
.Translate(50.0, 50.0);
3834 backface_matrix
.RotateAboutYAxis(180.0);
3835 backface_matrix
.Translate(-50.0, -50.0);
3837 // Make our render surface.
3838 animating_surface
->SetForceRenderSurface(true);
3840 // Animate the transform on the render surface.
3841 AddAnimatedTransformToController(
3842 animating_surface
->layer_animation_controller(), 10.0, 30, 0);
3843 // This is just an animating layer, not a surface.
3844 AddAnimatedTransformToController(
3845 animating_child
->layer_animation_controller(), 10.0, 30, 0);
3847 SetLayerPropertiesForTesting(parent
.get(),
3851 gfx::Size(100, 100),
3854 SetLayerPropertiesForTesting(child
.get(),
3858 gfx::Size(100, 100),
3861 SetLayerPropertiesForTesting(animating_surface
.get(),
3865 gfx::Size(100, 100),
3868 SetLayerPropertiesForTesting(child_of_animating_surface
.get(),
3872 gfx::Size(100, 100),
3875 SetLayerPropertiesForTesting(animating_child
.get(),
3879 gfx::Size(100, 100),
3882 SetLayerPropertiesForTesting(child2
.get(),
3886 gfx::Size(100, 100),
3890 RenderSurfaceLayerList render_surface_layer_list
;
3891 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3892 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3893 inputs
.can_adjust_raster_scales
= true;
3894 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3896 EXPECT_FALSE(child
->render_surface());
3897 EXPECT_TRUE(animating_surface
->render_surface());
3898 EXPECT_FALSE(child_of_animating_surface
->render_surface());
3899 EXPECT_FALSE(animating_child
->render_surface());
3900 EXPECT_FALSE(child2
->render_surface());
3902 // Verify that the animating_child and child_of_animating_surface were not
3903 // culled, but that child was.
3904 ASSERT_EQ(2u, render_surface_layer_list
.size());
3905 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3906 EXPECT_EQ(animating_surface
->id(), render_surface_layer_list
.at(1)->id());
3908 // The non-animating child be culled from the layer list for the parent render
3912 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3913 EXPECT_EQ(animating_surface
->id(),
3914 render_surface_layer_list
.at(0)
3915 ->render_surface()->layer_list().at(0)->id());
3916 EXPECT_EQ(animating_child
->id(),
3917 render_surface_layer_list
.at(0)
3918 ->render_surface()->layer_list().at(1)->id());
3919 EXPECT_EQ(child2
->id(),
3920 render_surface_layer_list
.at(0)
3921 ->render_surface()->layer_list().at(2)->id());
3925 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3926 EXPECT_EQ(animating_surface
->id(),
3927 render_surface_layer_list
.at(1)
3928 ->render_surface()->layer_list().at(0)->id());
3929 EXPECT_EQ(child_of_animating_surface
->id(),
3930 render_surface_layer_list
.at(1)
3931 ->render_surface()->layer_list().at(1)->id());
3933 EXPECT_FALSE(child2
->visible_content_rect().IsEmpty());
3935 // The animating layers should have a visible content rect that represents the
3936 // area of the front face that is within the viewport.
3937 EXPECT_EQ(animating_child
->visible_content_rect(),
3938 gfx::Rect(animating_child
->content_bounds()));
3939 EXPECT_EQ(animating_surface
->visible_content_rect(),
3940 gfx::Rect(animating_surface
->content_bounds()));
3941 // And layers in the subtree of the animating layer should have valid visible
3942 // content rects also.
3943 EXPECT_EQ(child_of_animating_surface
->visible_content_rect(),
3944 gfx::Rect(child_of_animating_surface
->content_bounds()));
3947 TEST_F(LayerTreeHostCommonTest
,
3948 BackFaceCullingWithPreserves3dForFlatteningSurface
) {
3949 // Verify the behavior of back-face culling for a render surface that is
3950 // created when it flattens its subtree, and its parent has preserves-3d.
3952 const gfx::Transform identity_matrix
;
3953 scoped_refptr
<Layer
> parent
= Layer::Create();
3954 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3955 make_scoped_refptr(new LayerWithForcedDrawsContent());
3956 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3957 make_scoped_refptr(new LayerWithForcedDrawsContent());
3958 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3959 make_scoped_refptr(new LayerWithForcedDrawsContent());
3960 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3961 make_scoped_refptr(new LayerWithForcedDrawsContent());
3963 parent
->AddChild(front_facing_surface
);
3964 parent
->AddChild(back_facing_surface
);
3965 front_facing_surface
->AddChild(child1
);
3966 back_facing_surface
->AddChild(child2
);
3968 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3969 host
->SetRootLayer(parent
);
3971 // RenderSurfaces are not double-sided
3972 front_facing_surface
->SetDoubleSided(false);
3973 back_facing_surface
->SetDoubleSided(false);
3975 gfx::Transform backface_matrix
;
3976 backface_matrix
.Translate(50.0, 50.0);
3977 backface_matrix
.RotateAboutYAxis(180.0);
3978 backface_matrix
.Translate(-50.0, -50.0);
3980 SetLayerPropertiesForTesting(parent
.get(),
3984 gfx::Size(100, 100),
3986 true); // parent transform style is preserve3d.
3987 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3991 gfx::Size(100, 100),
3993 true); // surface transform style is flat.
3994 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3998 gfx::Size(100, 100),
4000 true); // surface transform style is flat.
4001 SetLayerPropertiesForTesting(child1
.get(),
4005 gfx::Size(100, 100),
4008 SetLayerPropertiesForTesting(child2
.get(),
4012 gfx::Size(100, 100),
4016 front_facing_surface
->Set3dSortingContextId(1);
4017 back_facing_surface
->Set3dSortingContextId(1);
4019 RenderSurfaceLayerList render_surface_layer_list
;
4020 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4021 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4022 inputs
.can_adjust_raster_scales
= true;
4023 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4025 // Verify which render surfaces were created.
4026 EXPECT_TRUE(front_facing_surface
->render_surface());
4028 back_facing_surface
->render_surface()); // because it should be culled
4029 EXPECT_FALSE(child1
->render_surface());
4030 EXPECT_FALSE(child2
->render_surface());
4032 // Verify the render_surface_layer_list. The back-facing surface should be
4034 ASSERT_EQ(2u, render_surface_layer_list
.size());
4035 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
4036 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
4038 // Verify root surface's layer list.
4041 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
4042 EXPECT_EQ(front_facing_surface
->id(),
4043 render_surface_layer_list
.at(0)
4044 ->render_surface()->layer_list().at(0)->id());
4046 // Verify front_facing_surface's layer list.
4049 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
4050 EXPECT_EQ(front_facing_surface
->id(),
4051 render_surface_layer_list
.at(1)
4052 ->render_surface()->layer_list().at(0)->id());
4053 EXPECT_EQ(child1
->id(),
4054 render_surface_layer_list
.at(1)
4055 ->render_surface()->layer_list().at(1)->id());
4058 class NoScaleContentLayer
: public ContentLayer
{
4060 static scoped_refptr
<NoScaleContentLayer
> Create(ContentLayerClient
* client
) {
4061 return make_scoped_refptr(new NoScaleContentLayer(client
));
4064 void CalculateContentsScale(float ideal_contents_scale
,
4065 float* contents_scale_x
,
4066 float* contents_scale_y
,
4067 gfx::Size
* content_bounds
) override
{
4068 // Skip over the ContentLayer to the base Layer class.
4069 Layer::CalculateContentsScale(ideal_contents_scale
,
4076 explicit NoScaleContentLayer(ContentLayerClient
* client
)
4077 : ContentLayer(client
) {}
4078 ~NoScaleContentLayer() override
{}
4081 scoped_refptr
<NoScaleContentLayer
> CreateNoScaleDrawableContentLayer(
4082 ContentLayerClient
* delegate
) {
4083 scoped_refptr
<NoScaleContentLayer
> to_return
=
4084 NoScaleContentLayer::Create(delegate
);
4085 to_return
->SetIsDrawable(true);
4089 TEST_F(LayerTreeHostCommonTest
, LayerTransformsInHighDPI
) {
4090 // Verify draw and screen space transforms of layers not in a surface.
4091 MockContentLayerClient delegate
;
4092 gfx::Transform identity_matrix
;
4094 scoped_refptr
<FakePictureLayer
> parent
=
4095 CreateDrawablePictureLayer(&delegate
);
4096 SetLayerPropertiesForTesting(parent
.get(),
4100 gfx::Size(100, 100),
4104 scoped_refptr
<FakePictureLayer
> child
= CreateDrawablePictureLayer(&delegate
);
4105 SetLayerPropertiesForTesting(child
.get(),
4108 gfx::PointF(2.f
, 2.f
),
4113 scoped_refptr
<FakePictureLayer
> child_empty
=
4114 CreateDrawablePictureLayer(&delegate
);
4115 SetLayerPropertiesForTesting(child_empty
.get(),
4118 gfx::PointF(2.f
, 2.f
),
4123 parent
->AddChild(child
);
4124 parent
->AddChild(child_empty
);
4126 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4127 host
->SetRootLayer(parent
);
4129 float device_scale_factor
= 2.5f
;
4130 float page_scale_factor
= 1.f
;
4132 RenderSurfaceLayerList render_surface_layer_list
;
4133 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4134 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4135 inputs
.device_scale_factor
= device_scale_factor
;
4136 inputs
.page_scale_factor
= page_scale_factor
;
4137 inputs
.can_adjust_raster_scales
= true;
4138 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4140 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4141 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, child
);
4142 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, child_empty
);
4144 EXPECT_EQ(1u, render_surface_layer_list
.size());
4146 // Verify parent transforms
4147 gfx::Transform expected_parent_transform
;
4148 expected_parent_transform
.Scale(device_scale_factor
* page_scale_factor
,
4149 device_scale_factor
* page_scale_factor
);
4150 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4151 parent
->screen_space_transform());
4152 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4153 parent
->draw_transform());
4155 // Verify results of transformed parent rects
4156 gfx::RectF
parent_content_bounds(parent
->content_bounds());
4158 gfx::RectF parent_draw_rect
=
4159 MathUtil::MapClippedRect(parent
->draw_transform(), parent_content_bounds
);
4160 gfx::RectF parent_screen_space_rect
= MathUtil::MapClippedRect(
4161 parent
->screen_space_transform(), parent_content_bounds
);
4163 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
4164 expected_parent_draw_rect
.Scale(device_scale_factor
);
4165 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
4166 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
4168 // Verify child and child_empty transforms. They should match.
4169 gfx::Transform expected_child_transform
;
4170 expected_child_transform
.Scale(device_scale_factor
, device_scale_factor
);
4171 expected_child_transform
.Translate(child
->position().x(),
4172 child
->position().y());
4173 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4174 child
->draw_transform());
4175 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4176 child
->screen_space_transform());
4177 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4178 child_empty
->draw_transform());
4179 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4180 child_empty
->screen_space_transform());
4182 // Verify results of transformed child and child_empty rects. They should
4184 gfx::RectF
child_content_bounds(child
->content_bounds());
4186 gfx::RectF child_draw_rect
=
4187 MathUtil::MapClippedRect(child
->draw_transform(), child_content_bounds
);
4188 gfx::RectF child_screen_space_rect
= MathUtil::MapClippedRect(
4189 child
->screen_space_transform(), child_content_bounds
);
4191 gfx::RectF child_empty_draw_rect
= MathUtil::MapClippedRect(
4192 child_empty
->draw_transform(), child_content_bounds
);
4193 gfx::RectF child_empty_screen_space_rect
= MathUtil::MapClippedRect(
4194 child_empty
->screen_space_transform(), child_content_bounds
);
4196 gfx::RectF
expected_child_draw_rect(child
->position(), child
->bounds());
4197 expected_child_draw_rect
.Scale(device_scale_factor
);
4198 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
4199 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
4200 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_draw_rect
);
4201 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_screen_space_rect
);
4204 TEST_F(LayerTreeHostCommonTest
, SurfaceLayerTransformsInHighDPI
) {
4205 // Verify draw and screen space transforms of layers in a surface.
4206 MockContentLayerClient delegate
;
4207 gfx::Transform identity_matrix
;
4209 gfx::Transform perspective_matrix
;
4210 perspective_matrix
.ApplyPerspectiveDepth(2.0);
4212 gfx::Transform scale_small_matrix
;
4213 scale_small_matrix
.Scale(SK_MScalar1
/ 10.f
, SK_MScalar1
/ 12.f
);
4215 scoped_refptr
<Layer
> root
= Layer::Create();
4217 scoped_refptr
<FakePictureLayer
> parent
=
4218 CreateDrawablePictureLayer(&delegate
);
4219 SetLayerPropertiesForTesting(parent
.get(),
4223 gfx::Size(100, 100),
4227 scoped_refptr
<FakePictureLayer
> perspective_surface
=
4228 CreateDrawablePictureLayer(&delegate
);
4229 SetLayerPropertiesForTesting(perspective_surface
.get(),
4230 perspective_matrix
* scale_small_matrix
,
4232 gfx::PointF(2.f
, 2.f
),
4237 scoped_refptr
<FakePictureLayer
> scale_surface
=
4238 CreateDrawablePictureLayer(&delegate
);
4239 SetLayerPropertiesForTesting(scale_surface
.get(),
4242 gfx::PointF(2.f
, 2.f
),
4247 perspective_surface
->SetForceRenderSurface(true);
4248 scale_surface
->SetForceRenderSurface(true);
4250 parent
->AddChild(perspective_surface
);
4251 parent
->AddChild(scale_surface
);
4252 root
->AddChild(parent
);
4254 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4255 host
->SetRootLayer(root
);
4257 float device_scale_factor
= 2.5f
;
4258 float page_scale_factor
= 3.f
;
4260 RenderSurfaceLayerList render_surface_layer_list
;
4261 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4262 root
.get(), parent
->bounds(), &render_surface_layer_list
);
4263 inputs
.device_scale_factor
= device_scale_factor
;
4264 inputs
.page_scale_factor
= page_scale_factor
;
4265 inputs
.page_scale_application_layer
= root
.get();
4266 inputs
.can_adjust_raster_scales
= true;
4267 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4269 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4270 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4271 perspective_surface
);
4272 // Ideal scale is the max 2d scale component of the combined transform up to
4273 // the nearest render target. Here this includes the layer transform as well
4274 // as the device and page scale factors.
4275 gfx::Transform transform
= scale_small_matrix
;
4276 transform
.Scale(device_scale_factor
* page_scale_factor
,
4277 device_scale_factor
* page_scale_factor
);
4278 gfx::Vector2dF scales
=
4279 MathUtil::ComputeTransform2dScaleComponents(transform
, 0.f
);
4280 float max_2d_scale
= std::max(scales
.x(), scales
.y());
4281 EXPECT_IDEAL_SCALE_EQ(max_2d_scale
, scale_surface
);
4283 // The ideal scale will draw 1:1 with its render target space along
4284 // the larger-scale axis.
4285 gfx::Vector2dF target_space_transform_scales
=
4286 MathUtil::ComputeTransform2dScaleComponents(
4287 scale_surface
->draw_properties().target_space_transform
, 0.f
);
4288 EXPECT_FLOAT_EQ(max_2d_scale
,
4289 std::max(target_space_transform_scales
.x(),
4290 target_space_transform_scales
.y()));
4292 EXPECT_EQ(3u, render_surface_layer_list
.size());
4294 gfx::Transform expected_parent_draw_transform
;
4295 expected_parent_draw_transform
.Scale(device_scale_factor
* page_scale_factor
,
4296 device_scale_factor
* page_scale_factor
);
4297 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform
,
4298 parent
->draw_transform());
4300 // The scale for the perspective surface is not known, so it is rendered 1:1
4301 // with the screen, and then scaled during drawing.
4302 gfx::Transform expected_perspective_surface_draw_transform
;
4303 expected_perspective_surface_draw_transform
.Translate(
4304 device_scale_factor
* page_scale_factor
*
4305 perspective_surface
->position().x(),
4306 device_scale_factor
* page_scale_factor
*
4307 perspective_surface
->position().y());
4308 expected_perspective_surface_draw_transform
.PreconcatTransform(
4309 perspective_matrix
);
4310 expected_perspective_surface_draw_transform
.PreconcatTransform(
4311 scale_small_matrix
);
4312 gfx::Transform expected_perspective_surface_layer_draw_transform
;
4313 expected_perspective_surface_layer_draw_transform
.Scale(
4314 device_scale_factor
* page_scale_factor
,
4315 device_scale_factor
* page_scale_factor
);
4316 EXPECT_TRANSFORMATION_MATRIX_EQ(
4317 expected_perspective_surface_draw_transform
,
4318 perspective_surface
->render_surface()->draw_transform());
4319 EXPECT_TRANSFORMATION_MATRIX_EQ(
4320 expected_perspective_surface_layer_draw_transform
,
4321 perspective_surface
->draw_transform());
4324 // TODO(sohanjg): Remove this test when ContentLayer is removed.
4325 TEST_F(LayerTreeHostCommonTest
,
4326 LayerTransformsInHighDPIAccurateScaleZeroChildPosition
) {
4327 // Verify draw and screen space transforms of layers not in a surface.
4328 MockContentLayerClient delegate
;
4329 gfx::Transform identity_matrix
;
4331 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4332 SetLayerPropertiesForTesting(parent
.get(),
4336 gfx::Size(133, 133),
4340 scoped_refptr
<ContentLayer
> child
= CreateDrawableContentLayer(&delegate
);
4341 SetLayerPropertiesForTesting(child
.get(),
4349 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4350 CreateNoScaleDrawableContentLayer(&delegate
);
4351 SetLayerPropertiesForTesting(child_no_scale
.get(),
4359 parent
->AddChild(child
);
4360 parent
->AddChild(child_no_scale
);
4362 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4363 host
->SetRootLayer(parent
);
4365 float device_scale_factor
= 1.7f
;
4366 float page_scale_factor
= 1.f
;
4368 RenderSurfaceLayerList render_surface_layer_list
;
4369 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4370 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4371 inputs
.device_scale_factor
= device_scale_factor
;
4372 inputs
.page_scale_factor
= page_scale_factor
;
4373 inputs
.page_scale_application_layer
= parent
.get();
4374 inputs
.can_adjust_raster_scales
= true;
4375 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4377 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4378 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, child
);
4379 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4381 EXPECT_EQ(1u, render_surface_layer_list
.size());
4383 // Verify parent transforms
4384 gfx::Transform expected_parent_transform
;
4385 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4386 parent
->screen_space_transform());
4387 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4388 parent
->draw_transform());
4390 // Verify results of transformed parent rects
4391 gfx::RectF
parent_content_bounds(parent
->content_bounds());
4393 gfx::RectF parent_draw_rect
=
4394 MathUtil::MapClippedRect(parent
->draw_transform(), parent_content_bounds
);
4395 gfx::RectF parent_screen_space_rect
= MathUtil::MapClippedRect(
4396 parent
->screen_space_transform(), parent_content_bounds
);
4398 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
4399 expected_parent_draw_rect
.Scale(device_scale_factor
);
4400 expected_parent_draw_rect
.set_width(ceil(expected_parent_draw_rect
.width()));
4401 expected_parent_draw_rect
.set_height(
4402 ceil(expected_parent_draw_rect
.height()));
4403 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
4404 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
4406 // Verify child transforms
4407 gfx::Transform expected_child_transform
;
4408 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4409 child
->draw_transform());
4410 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4411 child
->screen_space_transform());
4413 // Verify results of transformed child rects
4414 gfx::RectF
child_content_bounds(child
->content_bounds());
4416 gfx::RectF child_draw_rect
=
4417 MathUtil::MapClippedRect(child
->draw_transform(), child_content_bounds
);
4418 gfx::RectF child_screen_space_rect
= MathUtil::MapClippedRect(
4419 child
->screen_space_transform(), child_content_bounds
);
4421 gfx::RectF
expected_child_draw_rect(child
->bounds());
4422 expected_child_draw_rect
.Scale(device_scale_factor
);
4423 expected_child_draw_rect
.set_width(ceil(expected_child_draw_rect
.width()));
4424 expected_child_draw_rect
.set_height(ceil(expected_child_draw_rect
.height()));
4425 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
4426 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
4428 // Verify child_no_scale transforms
4429 gfx::Transform expected_child_no_scale_transform
= child
->draw_transform();
4430 // All transforms operate on content rects. The child's content rect
4431 // incorporates device scale, but the child_no_scale does not; add it here.
4432 expected_child_no_scale_transform
.Scale(device_scale_factor
,
4433 device_scale_factor
);
4434 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4435 child_no_scale
->draw_transform());
4436 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4437 child_no_scale
->screen_space_transform());
4440 // TODO(sohanjg): Remove this test when ContentLayer is removed.
4441 TEST_F(LayerTreeHostCommonTest
, ContentsScale
) {
4442 MockContentLayerClient delegate
;
4443 gfx::Transform identity_matrix
;
4445 gfx::Transform parent_scale_matrix
;
4446 SkMScalar initial_parent_scale
= 1.75;
4447 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4449 gfx::Transform child_scale_matrix
;
4450 SkMScalar initial_child_scale
= 1.25;
4451 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4453 scoped_refptr
<Layer
> root
= Layer::Create();
4454 root
->SetBounds(gfx::Size(100, 100));
4456 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4457 SetLayerPropertiesForTesting(parent
.get(),
4458 parent_scale_matrix
,
4461 gfx::Size(100, 100),
4465 scoped_refptr
<ContentLayer
> child_scale
=
4466 CreateDrawableContentLayer(&delegate
);
4467 SetLayerPropertiesForTesting(child_scale
.get(),
4470 gfx::PointF(2.f
, 2.f
),
4475 scoped_refptr
<ContentLayer
> child_empty
=
4476 CreateDrawableContentLayer(&delegate
);
4477 SetLayerPropertiesForTesting(child_empty
.get(),
4480 gfx::PointF(2.f
, 2.f
),
4485 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4486 CreateNoScaleDrawableContentLayer(&delegate
);
4487 SetLayerPropertiesForTesting(child_no_scale
.get(),
4490 gfx::PointF(12.f
, 12.f
),
4495 root
->AddChild(parent
);
4497 parent
->AddChild(child_scale
);
4498 parent
->AddChild(child_empty
);
4499 parent
->AddChild(child_no_scale
);
4501 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4502 host
->SetRootLayer(root
);
4504 float device_scale_factor
= 2.5f
;
4505 float page_scale_factor
= 1.f
;
4508 RenderSurfaceLayerList render_surface_layer_list
;
4509 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4510 root
.get(), root
->bounds(), &render_surface_layer_list
);
4511 inputs
.device_scale_factor
= device_scale_factor
;
4512 inputs
.page_scale_factor
= page_scale_factor
;
4513 inputs
.page_scale_application_layer
= root
.get();
4514 inputs
.can_adjust_raster_scales
= true;
4515 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4517 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4518 initial_parent_scale
, parent
);
4519 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4520 initial_parent_scale
* initial_child_scale
,
4522 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4523 initial_parent_scale
* initial_child_scale
,
4525 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4527 // The parent is scaled up and shouldn't need to scale during draw. The
4528 // child that can scale its contents should also not need to scale during
4529 // draw. This shouldn't change if the child has empty bounds. The other
4531 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(0, 0));
4532 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(1, 1));
4533 EXPECT_FLOAT_EQ(1.0, child_scale
->draw_transform().matrix().get(0, 0));
4534 EXPECT_FLOAT_EQ(1.0, child_scale
->draw_transform().matrix().get(1, 1));
4535 EXPECT_FLOAT_EQ(1.0, child_empty
->draw_transform().matrix().get(0, 0));
4536 EXPECT_FLOAT_EQ(1.0, child_empty
->draw_transform().matrix().get(1, 1));
4537 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4538 initial_parent_scale
* initial_child_scale
,
4539 child_no_scale
->draw_transform().matrix().get(0, 0));
4540 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4541 initial_parent_scale
* initial_child_scale
,
4542 child_no_scale
->draw_transform().matrix().get(1, 1));
4545 // If the device_scale_factor or page_scale_factor changes, then it should be
4546 // updated using the initial transform as the raster scale.
4547 device_scale_factor
= 2.25f
;
4548 page_scale_factor
= 1.25f
;
4551 RenderSurfaceLayerList render_surface_layer_list
;
4552 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4553 root
.get(), root
->bounds(), &render_surface_layer_list
);
4554 inputs
.device_scale_factor
= device_scale_factor
;
4555 inputs
.page_scale_factor
= page_scale_factor
;
4556 inputs
.page_scale_application_layer
= root
.get();
4557 inputs
.can_adjust_raster_scales
= true;
4558 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4560 EXPECT_CONTENTS_SCALE_EQ(
4561 device_scale_factor
* page_scale_factor
* initial_parent_scale
, parent
);
4562 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4563 initial_parent_scale
* initial_child_scale
,
4565 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4566 initial_parent_scale
* initial_child_scale
,
4568 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4571 // If the transform changes, we expect the raster scale to be reset to 1.0.
4572 SkMScalar second_child_scale
= 1.75;
4573 child_scale_matrix
.Scale(second_child_scale
/ initial_child_scale
,
4574 second_child_scale
/ initial_child_scale
);
4575 child_scale
->SetTransform(child_scale_matrix
);
4576 child_empty
->SetTransform(child_scale_matrix
);
4579 RenderSurfaceLayerList render_surface_layer_list
;
4580 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4581 root
.get(), root
->bounds(), &render_surface_layer_list
);
4582 inputs
.device_scale_factor
= device_scale_factor
;
4583 inputs
.page_scale_factor
= page_scale_factor
;
4584 inputs
.page_scale_application_layer
= root
.get();
4585 inputs
.can_adjust_raster_scales
= true;
4586 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4588 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4589 initial_parent_scale
,
4591 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4593 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4595 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4598 // If the device_scale_factor or page_scale_factor changes, then it should be
4599 // updated, but still using 1.0 as the raster scale.
4600 device_scale_factor
= 2.75f
;
4601 page_scale_factor
= 1.75f
;
4604 RenderSurfaceLayerList render_surface_layer_list
;
4605 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4606 root
.get(), root
->bounds(), &render_surface_layer_list
);
4607 inputs
.device_scale_factor
= device_scale_factor
;
4608 inputs
.page_scale_factor
= page_scale_factor
;
4609 inputs
.page_scale_application_layer
= root
.get();
4610 inputs
.can_adjust_raster_scales
= true;
4611 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4613 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4614 initial_parent_scale
,
4616 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4618 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4620 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4624 // TODO(sohanjg): Remove this test when ContentLayer is removed.
4625 TEST_F(LayerTreeHostCommonTest
,
4626 ContentsScale_LayerTransformsDontAffectContentsScale
) {
4627 MockContentLayerClient delegate
;
4628 gfx::Transform identity_matrix
;
4630 gfx::Transform parent_scale_matrix
;
4631 SkMScalar initial_parent_scale
= 1.75;
4632 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4634 gfx::Transform child_scale_matrix
;
4635 SkMScalar initial_child_scale
= 1.25;
4636 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4638 scoped_refptr
<Layer
> root
= Layer::Create();
4639 root
->SetBounds(gfx::Size(100, 100));
4641 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4642 SetLayerPropertiesForTesting(parent
.get(),
4643 parent_scale_matrix
,
4646 gfx::Size(100, 100),
4650 scoped_refptr
<ContentLayer
> child_scale
=
4651 CreateDrawableContentLayer(&delegate
);
4652 SetLayerPropertiesForTesting(child_scale
.get(),
4655 gfx::PointF(2.f
, 2.f
),
4660 scoped_refptr
<ContentLayer
> child_empty
=
4661 CreateDrawableContentLayer(&delegate
);
4662 SetLayerPropertiesForTesting(child_empty
.get(),
4665 gfx::PointF(2.f
, 2.f
),
4670 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4671 CreateNoScaleDrawableContentLayer(&delegate
);
4672 SetLayerPropertiesForTesting(child_no_scale
.get(),
4675 gfx::PointF(12.f
, 12.f
),
4680 root
->AddChild(parent
);
4682 parent
->AddChild(child_scale
);
4683 parent
->AddChild(child_empty
);
4684 parent
->AddChild(child_no_scale
);
4686 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4687 host
->SetRootLayer(root
);
4689 RenderSurfaceLayerList render_surface_layer_list
;
4691 float device_scale_factor
= 2.5f
;
4692 float page_scale_factor
= 1.f
;
4694 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4695 root
.get(), root
->bounds(), &render_surface_layer_list
);
4696 inputs
.device_scale_factor
= device_scale_factor
;
4697 inputs
.page_scale_factor
= page_scale_factor
;
4698 inputs
.page_scale_application_layer
= root
.get(),
4699 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4701 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4702 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4704 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4706 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4708 // Since the transform scale does not affect contents scale, it should affect
4709 // the draw transform instead.
4710 EXPECT_FLOAT_EQ(initial_parent_scale
,
4711 parent
->draw_transform().matrix().get(0, 0));
4712 EXPECT_FLOAT_EQ(initial_parent_scale
,
4713 parent
->draw_transform().matrix().get(1, 1));
4714 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4715 child_scale
->draw_transform().matrix().get(0, 0));
4716 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4717 child_scale
->draw_transform().matrix().get(1, 1));
4718 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4719 child_empty
->draw_transform().matrix().get(0, 0));
4720 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4721 child_empty
->draw_transform().matrix().get(1, 1));
4722 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4723 initial_parent_scale
* initial_child_scale
,
4724 child_no_scale
->draw_transform().matrix().get(0, 0));
4725 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4726 initial_parent_scale
* initial_child_scale
,
4727 child_no_scale
->draw_transform().matrix().get(1, 1));
4730 TEST_F(LayerTreeHostCommonTest
, SmallIdealScale
) {
4731 MockContentLayerClient delegate
;
4732 gfx::Transform identity_matrix
;
4734 gfx::Transform parent_scale_matrix
;
4735 SkMScalar initial_parent_scale
= 1.75;
4736 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4738 gfx::Transform child_scale_matrix
;
4739 SkMScalar initial_child_scale
= 0.25;
4740 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4742 scoped_refptr
<Layer
> root
= Layer::Create();
4743 root
->SetBounds(gfx::Size(100, 100));
4745 scoped_refptr
<FakePictureLayer
> parent
=
4746 CreateDrawablePictureLayer(&delegate
);
4747 SetLayerPropertiesForTesting(parent
.get(),
4748 parent_scale_matrix
,
4751 gfx::Size(100, 100),
4755 scoped_refptr
<FakePictureLayer
> child_scale
=
4756 CreateDrawablePictureLayer(&delegate
);
4757 SetLayerPropertiesForTesting(child_scale
.get(),
4760 gfx::PointF(2.f
, 2.f
),
4765 root
->AddChild(parent
);
4767 parent
->AddChild(child_scale
);
4769 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4770 host
->SetRootLayer(root
);
4772 float device_scale_factor
= 2.5f
;
4773 float page_scale_factor
= 0.01f
;
4776 RenderSurfaceLayerList render_surface_layer_list
;
4777 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4778 root
.get(), root
->bounds(), &render_surface_layer_list
);
4779 inputs
.device_scale_factor
= device_scale_factor
;
4780 inputs
.page_scale_factor
= page_scale_factor
;
4781 inputs
.page_scale_application_layer
= root
.get();
4782 inputs
.can_adjust_raster_scales
= true;
4783 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4785 // The ideal scale is able to go below 1.
4786 float expected_ideal_scale
=
4787 device_scale_factor
* page_scale_factor
* initial_parent_scale
;
4788 EXPECT_LT(expected_ideal_scale
, 1.f
);
4789 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, parent
);
4791 expected_ideal_scale
= device_scale_factor
* page_scale_factor
*
4792 initial_parent_scale
* initial_child_scale
;
4793 EXPECT_LT(expected_ideal_scale
, 1.f
);
4794 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, child_scale
);
4798 TEST_F(LayerTreeHostCommonTest
, ContentsScaleForSurfaces
) {
4799 MockContentLayerClient delegate
;
4800 gfx::Transform identity_matrix
;
4802 gfx::Transform parent_scale_matrix
;
4803 SkMScalar initial_parent_scale
= 2.0;
4804 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4806 gfx::Transform child_scale_matrix
;
4807 SkMScalar initial_child_scale
= 3.0;
4808 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4810 scoped_refptr
<Layer
> root
= Layer::Create();
4811 root
->SetBounds(gfx::Size(100, 100));
4813 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4814 SetLayerPropertiesForTesting(parent
.get(),
4815 parent_scale_matrix
,
4818 gfx::Size(100, 100),
4822 scoped_refptr
<ContentLayer
> surface_scale
=
4823 CreateDrawableContentLayer(&delegate
);
4824 SetLayerPropertiesForTesting(surface_scale
.get(),
4827 gfx::PointF(2.f
, 2.f
),
4832 scoped_refptr
<ContentLayer
> surface_scale_child_scale
=
4833 CreateDrawableContentLayer(&delegate
);
4834 SetLayerPropertiesForTesting(surface_scale_child_scale
.get(),
4842 scoped_refptr
<NoScaleContentLayer
> surface_scale_child_no_scale
=
4843 CreateNoScaleDrawableContentLayer(&delegate
);
4844 SetLayerPropertiesForTesting(surface_scale_child_no_scale
.get(),
4852 scoped_refptr
<NoScaleContentLayer
> surface_no_scale
=
4853 CreateNoScaleDrawableContentLayer(&delegate
);
4854 SetLayerPropertiesForTesting(surface_no_scale
.get(),
4857 gfx::PointF(12.f
, 12.f
),
4862 scoped_refptr
<ContentLayer
> surface_no_scale_child_scale
=
4863 CreateDrawableContentLayer(&delegate
);
4864 SetLayerPropertiesForTesting(surface_no_scale_child_scale
.get(),
4872 scoped_refptr
<NoScaleContentLayer
> surface_no_scale_child_no_scale
=
4873 CreateNoScaleDrawableContentLayer(&delegate
);
4874 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale
.get(),
4882 root
->AddChild(parent
);
4884 parent
->AddChild(surface_scale
);
4885 parent
->AddChild(surface_no_scale
);
4887 surface_scale
->SetForceRenderSurface(true);
4888 surface_scale
->AddChild(surface_scale_child_scale
);
4889 surface_scale
->AddChild(surface_scale_child_no_scale
);
4891 surface_no_scale
->SetForceRenderSurface(true);
4892 surface_no_scale
->AddChild(surface_no_scale_child_scale
);
4893 surface_no_scale
->AddChild(surface_no_scale_child_no_scale
);
4895 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4896 host
->SetRootLayer(root
);
4898 SkMScalar device_scale_factor
= 5;
4899 SkMScalar page_scale_factor
= 7;
4901 RenderSurfaceLayerList render_surface_layer_list
;
4902 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4903 root
.get(), root
->bounds(), &render_surface_layer_list
);
4904 inputs
.device_scale_factor
= device_scale_factor
;
4905 inputs
.page_scale_factor
= page_scale_factor
;
4906 inputs
.page_scale_application_layer
= root
.get();
4907 inputs
.can_adjust_raster_scales
= true;
4908 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4910 EXPECT_CONTENTS_SCALE_EQ(
4911 device_scale_factor
* page_scale_factor
* initial_parent_scale
, parent
);
4912 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4913 initial_parent_scale
* initial_child_scale
,
4915 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale
);
4916 EXPECT_CONTENTS_SCALE_EQ(
4917 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4918 initial_child_scale
* initial_child_scale
,
4919 surface_scale_child_scale
);
4920 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale
);
4921 EXPECT_CONTENTS_SCALE_EQ(
4922 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4923 initial_child_scale
* initial_child_scale
,
4924 surface_no_scale_child_scale
);
4925 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale
);
4927 // The parent is scaled up and shouldn't need to scale during draw.
4928 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(0, 0));
4929 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(1, 1));
4931 // RenderSurfaces should always be 1:1 with their target.
4934 surface_scale
->render_surface()->draw_transform().matrix().get(0, 0));
4937 surface_scale
->render_surface()->draw_transform().matrix().get(1, 1));
4939 // The surface_scale can apply contents scale so the layer shouldn't need to
4940 // scale during draw.
4941 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(0, 0));
4942 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(1, 1));
4944 // The surface_scale_child_scale can apply contents scale so it shouldn't need
4945 // to scale during draw.
4947 1.0, surface_scale_child_scale
->draw_transform().matrix().get(0, 0));
4949 1.0, surface_scale_child_scale
->draw_transform().matrix().get(1, 1));
4951 // The surface_scale_child_no_scale can not apply contents scale, so it needs
4952 // to be scaled during draw.
4954 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4955 initial_child_scale
* initial_child_scale
,
4956 surface_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
4958 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4959 initial_child_scale
* initial_child_scale
,
4960 surface_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
4962 // RenderSurfaces should always be 1:1 with their target.
4965 surface_no_scale
->render_surface()->draw_transform().matrix().get(0, 0));
4968 surface_no_scale
->render_surface()->draw_transform().matrix().get(1, 1));
4970 // The surface_no_scale layer can not apply contents scale, so it needs to be
4971 // scaled during draw.
4972 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4973 initial_parent_scale
* initial_child_scale
,
4974 surface_no_scale
->draw_transform().matrix().get(0, 0));
4975 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4976 initial_parent_scale
* initial_child_scale
,
4977 surface_no_scale
->draw_transform().matrix().get(1, 1));
4979 // The surface_scale_child_scale can apply contents scale so it shouldn't need
4980 // to scale during draw.
4982 1.0, surface_no_scale_child_scale
->draw_transform().matrix().get(0, 0));
4984 1.0, surface_no_scale_child_scale
->draw_transform().matrix().get(1, 1));
4986 // The surface_scale_child_no_scale can not apply contents scale, so it needs
4987 // to be scaled during draw.
4989 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4990 initial_child_scale
* initial_child_scale
,
4991 surface_no_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
4993 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4994 initial_child_scale
* initial_child_scale
,
4995 surface_no_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
4998 // TODO(sohanjg): Remove this test when ContentLayer is removed.
4999 TEST_F(LayerTreeHostCommonTest
,
5000 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale
) {
5001 MockContentLayerClient delegate
;
5002 gfx::Transform identity_matrix
;
5004 gfx::Transform parent_scale_matrix
;
5005 SkMScalar initial_parent_scale
= 2.0;
5006 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
5008 gfx::Transform child_scale_matrix
;
5009 SkMScalar initial_child_scale
= 3.0;
5010 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
5012 scoped_refptr
<Layer
> root
= Layer::Create();
5013 root
->SetBounds(gfx::Size(100, 100));
5015 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
5016 SetLayerPropertiesForTesting(parent
.get(),
5017 parent_scale_matrix
,
5020 gfx::Size(100, 100),
5024 scoped_refptr
<ContentLayer
> surface_scale
=
5025 CreateDrawableContentLayer(&delegate
);
5026 SetLayerPropertiesForTesting(surface_scale
.get(),
5029 gfx::PointF(2.f
, 2.f
),
5034 scoped_refptr
<ContentLayer
> surface_scale_child_scale
=
5035 CreateDrawableContentLayer(&delegate
);
5036 SetLayerPropertiesForTesting(surface_scale_child_scale
.get(),
5044 scoped_refptr
<NoScaleContentLayer
> surface_scale_child_no_scale
=
5045 CreateNoScaleDrawableContentLayer(&delegate
);
5046 SetLayerPropertiesForTesting(surface_scale_child_no_scale
.get(),
5054 scoped_refptr
<NoScaleContentLayer
> surface_no_scale
=
5055 CreateNoScaleDrawableContentLayer(&delegate
);
5056 SetLayerPropertiesForTesting(surface_no_scale
.get(),
5059 gfx::PointF(12.f
, 12.f
),
5064 scoped_refptr
<ContentLayer
> surface_no_scale_child_scale
=
5065 CreateDrawableContentLayer(&delegate
);
5066 SetLayerPropertiesForTesting(surface_no_scale_child_scale
.get(),
5074 scoped_refptr
<NoScaleContentLayer
> surface_no_scale_child_no_scale
=
5075 CreateNoScaleDrawableContentLayer(&delegate
);
5076 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale
.get(),
5084 root
->AddChild(parent
);
5086 parent
->AddChild(surface_scale
);
5087 parent
->AddChild(surface_no_scale
);
5089 surface_scale
->SetForceRenderSurface(true);
5090 surface_scale
->AddChild(surface_scale_child_scale
);
5091 surface_scale
->AddChild(surface_scale_child_no_scale
);
5093 surface_no_scale
->SetForceRenderSurface(true);
5094 surface_no_scale
->AddChild(surface_no_scale_child_scale
);
5095 surface_no_scale
->AddChild(surface_no_scale_child_no_scale
);
5097 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5098 host
->SetRootLayer(root
);
5100 RenderSurfaceLayerList render_surface_layer_list
;
5102 SkMScalar device_scale_factor
= 5.0;
5103 SkMScalar page_scale_factor
= 7.0;
5104 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5105 root
.get(), root
->bounds(), &render_surface_layer_list
);
5106 inputs
.device_scale_factor
= device_scale_factor
;
5107 inputs
.page_scale_factor
= page_scale_factor
;
5108 inputs
.page_scale_application_layer
= root
.get();
5109 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5111 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5113 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5115 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_no_scale
);
5116 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5117 surface_scale_child_scale
);
5118 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_scale_child_no_scale
);
5119 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5120 surface_no_scale_child_scale
);
5121 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_no_scale_child_no_scale
);
5123 // The parent is scaled up during draw, since its contents are not scaled by
5124 // the transform hierarchy.
5125 EXPECT_FLOAT_EQ(initial_parent_scale
,
5126 parent
->draw_transform().matrix().get(0, 0));
5127 EXPECT_FLOAT_EQ(initial_parent_scale
,
5128 parent
->draw_transform().matrix().get(1, 1));
5130 // The child surface is scaled up during draw since its subtree is not scaled
5131 // by the transform hierarchy.
5133 initial_parent_scale
* initial_child_scale
,
5134 surface_scale
->render_surface()->draw_transform().matrix().get(0, 0));
5136 initial_parent_scale
* initial_child_scale
,
5137 surface_scale
->render_surface()->draw_transform().matrix().get(1, 1));
5139 // The surface_scale's RenderSurface is scaled during draw, so the layer does
5140 // not need to be scaled when drawing into its surface.
5141 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(0, 0));
5142 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(1, 1));
5144 // The surface_scale_child_scale is scaled when drawing into its surface,
5145 // since its content bounds are not scaled by the transform hierarchy.
5147 initial_child_scale
,
5148 surface_scale_child_scale
->draw_transform().matrix().get(0, 0));
5150 initial_child_scale
,
5151 surface_scale_child_scale
->draw_transform().matrix().get(1, 1));
5153 // The surface_scale_child_no_scale has a fixed contents scale of 1, so it
5154 // needs to be scaled by the device and page scale factors, along with the
5155 // transform hierarchy.
5157 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5158 surface_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5160 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5161 surface_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5163 // The child surface is scaled up during draw since its subtree is not scaled
5164 // by the transform hierarchy.
5166 initial_parent_scale
* initial_child_scale
,
5167 surface_no_scale
->render_surface()->draw_transform().matrix().get(0, 0));
5169 initial_parent_scale
* initial_child_scale
,
5170 surface_no_scale
->render_surface()->draw_transform().matrix().get(1, 1));
5172 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
5173 // be scaled by the device and page scale factors. Its surface is already
5174 // scaled by the transform hierarchy so those don't need to scale the layer's
5176 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
,
5177 surface_no_scale
->draw_transform().matrix().get(0, 0));
5178 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
,
5179 surface_no_scale
->draw_transform().matrix().get(1, 1));
5181 // The surface_no_scale_child_scale has its contents scaled by the page and
5182 // device scale factors, but needs to be scaled by the transform hierarchy
5185 initial_child_scale
,
5186 surface_no_scale_child_scale
->draw_transform().matrix().get(0, 0));
5188 initial_child_scale
,
5189 surface_no_scale_child_scale
->draw_transform().matrix().get(1, 1));
5191 // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it
5192 // needs to be scaled by the device and page scale factors. It also needs to
5193 // be scaled by any transform heirarchy below its target surface.
5195 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5196 surface_no_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5198 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5199 surface_no_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5202 TEST_F(LayerTreeHostCommonTest
, IdealScaleForAnimatingLayer
) {
5203 MockContentLayerClient delegate
;
5204 gfx::Transform identity_matrix
;
5206 gfx::Transform parent_scale_matrix
;
5207 SkMScalar initial_parent_scale
= 1.75;
5208 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
5210 gfx::Transform child_scale_matrix
;
5211 SkMScalar initial_child_scale
= 1.25;
5212 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
5214 scoped_refptr
<Layer
> root
= Layer::Create();
5215 root
->SetBounds(gfx::Size(100, 100));
5217 scoped_refptr
<FakePictureLayer
> parent
=
5218 CreateDrawablePictureLayer(&delegate
);
5219 SetLayerPropertiesForTesting(parent
.get(),
5220 parent_scale_matrix
,
5223 gfx::Size(100, 100),
5227 scoped_refptr
<FakePictureLayer
> child_scale
=
5228 CreateDrawablePictureLayer(&delegate
);
5229 SetLayerPropertiesForTesting(child_scale
.get(),
5232 gfx::PointF(2.f
, 2.f
),
5237 root
->AddChild(parent
);
5239 parent
->AddChild(child_scale
);
5241 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5242 host
->SetRootLayer(root
);
5245 RenderSurfaceLayerList render_surface_layer_list
;
5246 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5247 root
.get(), root
->bounds(), &render_surface_layer_list
);
5248 inputs
.can_adjust_raster_scales
= true;
5249 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5251 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale
, parent
);
5252 // Animating layers compute ideal scale in the same way as when
5254 EXPECT_IDEAL_SCALE_EQ(initial_child_scale
* initial_parent_scale
,
5259 // TODO(sohanjg): Remove this test when ContentLayer is removed.
5260 TEST_F(LayerTreeHostCommonTest
,
5261 ChangeInContentBoundsOrScaleTriggersPushProperties
) {
5262 MockContentLayerClient delegate
;
5263 scoped_refptr
<Layer
> root
= Layer::Create();
5264 scoped_refptr
<Layer
> child
= CreateDrawableContentLayer(&delegate
);
5265 root
->AddChild(child
);
5267 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5268 host
->SetRootLayer(root
);
5270 gfx::Transform identity_matrix
;
5271 SetLayerPropertiesForTesting(root
.get(),
5275 gfx::Size(100, 100),
5278 SetLayerPropertiesForTesting(child
.get(),
5282 gfx::Size(100, 100),
5286 root
->reset_needs_push_properties_for_testing();
5287 child
->reset_needs_push_properties_for_testing();
5289 // This will change both layers' content bounds.
5290 ExecuteCalculateDrawProperties(root
.get());
5291 EXPECT_TRUE(root
->needs_push_properties());
5292 EXPECT_TRUE(child
->needs_push_properties());
5294 root
->reset_needs_push_properties_for_testing();
5295 child
->reset_needs_push_properties_for_testing();
5297 // This will change only the child layer's contents scale and content bounds,
5298 // since the root layer is not a ContentsScalingLayer.
5299 ExecuteCalculateDrawProperties(root
.get(), 2.f
);
5300 EXPECT_FALSE(root
->needs_push_properties());
5301 EXPECT_TRUE(child
->needs_push_properties());
5303 root
->reset_needs_push_properties_for_testing();
5304 child
->reset_needs_push_properties_for_testing();
5306 // This will not change either layer's contents scale or content bounds.
5307 ExecuteCalculateDrawProperties(root
.get(), 2.f
);
5308 EXPECT_FALSE(root
->needs_push_properties());
5309 EXPECT_FALSE(child
->needs_push_properties());
5312 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceTransformsInHighDPI
) {
5313 MockContentLayerClient delegate
;
5314 gfx::Transform identity_matrix
;
5316 scoped_refptr
<FakePictureLayer
> parent
=
5317 CreateDrawablePictureLayer(&delegate
);
5318 SetLayerPropertiesForTesting(parent
.get(),
5326 scoped_refptr
<FakePictureLayer
> child
= CreateDrawablePictureLayer(&delegate
);
5327 SetLayerPropertiesForTesting(child
.get(),
5330 gfx::PointF(2.f
, 2.f
),
5335 gfx::Transform replica_transform
;
5336 replica_transform
.Scale(1.0, -1.0);
5337 scoped_refptr
<FakePictureLayer
> replica
=
5338 CreateDrawablePictureLayer(&delegate
);
5339 SetLayerPropertiesForTesting(replica
.get(),
5342 gfx::PointF(2.f
, 2.f
),
5347 // This layer should end up in the same surface as child, with the same draw
5348 // and screen space transforms.
5349 scoped_refptr
<FakePictureLayer
> duplicate_child_non_owner
=
5350 CreateDrawablePictureLayer(&delegate
);
5351 SetLayerPropertiesForTesting(duplicate_child_non_owner
.get(),
5359 parent
->AddChild(child
);
5360 child
->AddChild(duplicate_child_non_owner
);
5361 child
->SetReplicaLayer(replica
.get());
5363 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5364 host
->SetRootLayer(parent
);
5366 RenderSurfaceLayerList render_surface_layer_list
;
5368 float device_scale_factor
= 1.5f
;
5369 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5370 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
5371 inputs
.device_scale_factor
= device_scale_factor
;
5372 inputs
.can_adjust_raster_scales
= true;
5373 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5375 // We should have two render surfaces. The root's render surface and child's
5376 // render surface (it needs one because it has a replica layer).
5377 EXPECT_EQ(2u, render_surface_layer_list
.size());
5379 gfx::Transform expected_parent_transform
;
5380 expected_parent_transform
.Scale(device_scale_factor
, device_scale_factor
);
5381 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
5382 parent
->screen_space_transform());
5383 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
5384 parent
->draw_transform());
5386 gfx::Transform expected_draw_transform
;
5387 expected_draw_transform
.Scale(device_scale_factor
, device_scale_factor
);
5388 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform
,
5389 child
->draw_transform());
5391 gfx::Transform expected_screen_space_transform
;
5392 expected_screen_space_transform
.Scale(device_scale_factor
,
5393 device_scale_factor
);
5394 expected_screen_space_transform
.Translate(child
->position().x(),
5395 child
->position().y());
5396 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform
,
5397 child
->screen_space_transform());
5399 gfx::Transform expected_duplicate_child_draw_transform
=
5400 child
->draw_transform();
5401 EXPECT_TRANSFORMATION_MATRIX_EQ(child
->draw_transform(),
5402 duplicate_child_non_owner
->draw_transform());
5403 EXPECT_TRANSFORMATION_MATRIX_EQ(
5404 child
->screen_space_transform(),
5405 duplicate_child_non_owner
->screen_space_transform());
5406 EXPECT_RECT_EQ(child
->drawable_content_rect(),
5407 duplicate_child_non_owner
->drawable_content_rect());
5408 EXPECT_EQ(child
->content_bounds(),
5409 duplicate_child_non_owner
->content_bounds());
5411 gfx::Transform expected_render_surface_draw_transform
;
5412 expected_render_surface_draw_transform
.Translate(
5413 device_scale_factor
* child
->position().x(),
5414 device_scale_factor
* child
->position().y());
5415 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform
,
5416 child
->render_surface()->draw_transform());
5418 gfx::Transform expected_surface_draw_transform
;
5419 expected_surface_draw_transform
.Translate(device_scale_factor
* 2.f
,
5420 device_scale_factor
* 2.f
);
5421 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform
,
5422 child
->render_surface()->draw_transform());
5424 gfx::Transform expected_surface_screen_space_transform
;
5425 expected_surface_screen_space_transform
.Translate(device_scale_factor
* 2.f
,
5426 device_scale_factor
* 2.f
);
5427 EXPECT_TRANSFORMATION_MATRIX_EQ(
5428 expected_surface_screen_space_transform
,
5429 child
->render_surface()->screen_space_transform());
5431 gfx::Transform expected_replica_draw_transform
;
5432 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
5433 expected_replica_draw_transform
.matrix().set(0, 3, 6.0);
5434 expected_replica_draw_transform
.matrix().set(1, 3, 6.0);
5435 EXPECT_TRANSFORMATION_MATRIX_EQ(
5436 expected_replica_draw_transform
,
5437 child
->render_surface()->replica_draw_transform());
5439 gfx::Transform expected_replica_screen_space_transform
;
5440 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
5441 expected_replica_screen_space_transform
.matrix().set(0, 3, 6.0);
5442 expected_replica_screen_space_transform
.matrix().set(1, 3, 6.0);
5443 EXPECT_TRANSFORMATION_MATRIX_EQ(
5444 expected_replica_screen_space_transform
,
5445 child
->render_surface()->replica_screen_space_transform());
5446 EXPECT_TRANSFORMATION_MATRIX_EQ(
5447 expected_replica_screen_space_transform
,
5448 child
->render_surface()->replica_screen_space_transform());
5451 TEST_F(LayerTreeHostCommonTest
,
5452 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition
) {
5453 MockContentLayerClient delegate
;
5454 gfx::Transform identity_matrix
;
5456 scoped_refptr
<FakePictureLayer
> parent
=
5457 CreateDrawablePictureLayer(&delegate
);
5458 SetLayerPropertiesForTesting(parent
.get(),
5466 scoped_refptr
<FakePictureLayer
> child
= CreateDrawablePictureLayer(&delegate
);
5467 SetLayerPropertiesForTesting(child
.get(),
5475 gfx::Transform replica_transform
;
5476 replica_transform
.Scale(1.0, -1.0);
5477 scoped_refptr
<FakePictureLayer
> replica
=
5478 CreateDrawablePictureLayer(&delegate
);
5479 SetLayerPropertiesForTesting(replica
.get(),
5487 parent
->AddChild(child
);
5488 child
->SetReplicaLayer(replica
.get());
5490 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5491 host
->SetRootLayer(parent
);
5493 float device_scale_factor
= 1.7f
;
5495 RenderSurfaceLayerList render_surface_layer_list
;
5496 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5497 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
5498 inputs
.device_scale_factor
= device_scale_factor
;
5499 inputs
.can_adjust_raster_scales
= true;
5500 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5502 // We should have two render surfaces. The root's render surface and child's
5503 // render surface (it needs one because it has a replica layer).
5504 EXPECT_EQ(2u, render_surface_layer_list
.size());
5506 gfx::Transform identity_transform
;
5507 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5508 child
->render_surface()->draw_transform());
5509 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5510 child
->render_surface()->draw_transform());
5511 EXPECT_TRANSFORMATION_MATRIX_EQ(
5512 identity_transform
, child
->render_surface()->screen_space_transform());
5514 gfx::Transform expected_replica_draw_transform
;
5515 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
5516 EXPECT_TRANSFORMATION_MATRIX_EQ(
5517 expected_replica_draw_transform
,
5518 child
->render_surface()->replica_draw_transform());
5520 gfx::Transform expected_replica_screen_space_transform
;
5521 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
5522 EXPECT_TRANSFORMATION_MATRIX_EQ(
5523 expected_replica_screen_space_transform
,
5524 child
->render_surface()->replica_screen_space_transform());
5527 TEST_F(LayerTreeHostCommonTest
, SubtreeSearch
) {
5528 scoped_refptr
<Layer
> root
= Layer::Create();
5529 scoped_refptr
<Layer
> child
= Layer::Create();
5530 scoped_refptr
<Layer
> grand_child
= Layer::Create();
5531 scoped_refptr
<Layer
> mask_layer
= Layer::Create();
5532 scoped_refptr
<Layer
> replica_layer
= Layer::Create();
5534 grand_child
->SetReplicaLayer(replica_layer
.get());
5535 child
->AddChild(grand_child
.get());
5536 child
->SetMaskLayer(mask_layer
.get());
5537 root
->AddChild(child
.get());
5539 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5540 host
->SetRootLayer(root
);
5542 int nonexistent_id
= -1;
5543 EXPECT_EQ(root
.get(),
5544 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), root
->id()));
5545 EXPECT_EQ(child
.get(),
5546 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), child
->id()));
5549 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), grand_child
->id()));
5552 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), mask_layer
->id()));
5554 replica_layer
.get(),
5555 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), replica_layer
->id()));
5557 0, LayerTreeHostCommon::FindLayerInSubtree(root
.get(), nonexistent_id
));
5560 TEST_F(LayerTreeHostCommonTest
, TransparentChildRenderSurfaceCreation
) {
5561 scoped_refptr
<Layer
> root
= Layer::Create();
5562 scoped_refptr
<Layer
> child
= Layer::Create();
5563 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
5564 make_scoped_refptr(new LayerWithForcedDrawsContent());
5566 const gfx::Transform identity_matrix
;
5567 SetLayerPropertiesForTesting(root
.get(),
5571 gfx::Size(100, 100),
5574 SetLayerPropertiesForTesting(child
.get(),
5581 SetLayerPropertiesForTesting(grand_child
.get(),
5589 root
->AddChild(child
);
5590 child
->AddChild(grand_child
);
5591 child
->SetOpacity(0.5f
);
5593 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5594 host
->SetRootLayer(root
);
5596 ExecuteCalculateDrawProperties(root
.get());
5598 EXPECT_FALSE(child
->render_surface());
5601 TEST_F(LayerTreeHostCommonTest
, OpacityAnimatingOnPendingTree
) {
5602 FakeImplProxy proxy
;
5603 TestSharedBitmapManager shared_bitmap_manager
;
5604 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5605 host_impl
.CreatePendingTree();
5606 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
5608 const gfx::Transform identity_matrix
;
5609 SetLayerPropertiesForTesting(root
.get(),
5613 gfx::Size(100, 100),
5616 root
->SetDrawsContent(true);
5618 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
5619 SetLayerPropertiesForTesting(child
.get(),
5626 child
->SetDrawsContent(true);
5627 child
->SetOpacity(0.0f
);
5629 // Add opacity animation.
5630 AddOpacityTransitionToController(
5631 child
->layer_animation_controller(), 10.0, 0.0f
, 1.0f
, false);
5633 root
->AddChild(child
.Pass());
5635 LayerImplList render_surface_layer_list
;
5636 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5637 root
.get(), root
->bounds(), &render_surface_layer_list
);
5638 inputs
.can_adjust_raster_scales
= true;
5639 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5641 // We should have one render surface and two layers. The child
5642 // layer should be included even though it is transparent.
5643 ASSERT_EQ(1u, render_surface_layer_list
.size());
5644 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5647 typedef std::tr1::tuple
<bool, bool> LCDTextTestParam
;
5649 : public LayerTreeHostCommonTestBase
,
5650 public testing::TestWithParam
<LCDTextTestParam
> {
5652 virtual void SetUp() {
5653 can_use_lcd_text_
= std::tr1::get
<0>(GetParam());
5655 root_
= Layer::Create();
5656 child_
= Layer::Create();
5657 grand_child_
= Layer::Create();
5658 child_
->AddChild(grand_child_
.get());
5659 root_
->AddChild(child_
.get());
5661 gfx::Transform identity_matrix
;
5662 SetLayerPropertiesForTesting(root_
.get(),
5669 SetLayerPropertiesForTesting(child_
.get(),
5676 SetLayerPropertiesForTesting(grand_child_
.get(),
5684 child_
->SetForceRenderSurface(std::tr1::get
<1>(GetParam()));
5686 host_
= CreateFakeLayerTreeHost();
5687 host_
->SetRootLayer(root_
);
5690 bool can_use_lcd_text_
;
5691 scoped_ptr
<FakeLayerTreeHost
> host_
;
5692 scoped_refptr
<Layer
> root_
;
5693 scoped_refptr
<Layer
> child_
;
5694 scoped_refptr
<Layer
> grand_child_
;
5697 TEST_P(LCDTextTest
, CanUseLCDText
) {
5698 // Case 1: Identity transform.
5699 gfx::Transform identity_matrix
;
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_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5704 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5706 // Case 2: Integral translation.
5707 gfx::Transform integral_translation
;
5708 integral_translation
.Translate(1.0, 2.0);
5709 child_
->SetTransform(integral_translation
);
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_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5714 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5716 // Case 3: Non-integral translation.
5717 gfx::Transform non_integral_translation
;
5718 non_integral_translation
.Translate(1.5, 2.5);
5719 child_
->SetTransform(non_integral_translation
);
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 4: Rotation.
5727 gfx::Transform rotation
;
5728 rotation
.Rotate(10.0);
5729 child_
->SetTransform(rotation
);
5730 ExecuteCalculateDrawProperties(
5731 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5732 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5733 EXPECT_FALSE(child_
->can_use_lcd_text());
5734 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5737 gfx::Transform scale
;
5738 scale
.Scale(2.0, 2.0);
5739 child_
->SetTransform(scale
);
5740 ExecuteCalculateDrawProperties(
5741 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5742 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5743 EXPECT_FALSE(child_
->can_use_lcd_text());
5744 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5747 gfx::Transform skew
;
5749 child_
->SetTransform(skew
);
5750 ExecuteCalculateDrawProperties(
5751 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5752 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5753 EXPECT_FALSE(child_
->can_use_lcd_text());
5754 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5756 // Case 7: Translucent.
5757 child_
->SetTransform(identity_matrix
);
5758 child_
->SetOpacity(0.5f
);
5759 ExecuteCalculateDrawProperties(
5760 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5761 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5762 EXPECT_FALSE(child_
->can_use_lcd_text());
5763 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5765 // Case 8: Sanity check: restore transform and opacity.
5766 child_
->SetTransform(identity_matrix
);
5767 child_
->SetOpacity(1.f
);
5768 ExecuteCalculateDrawProperties(
5769 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5770 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5771 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5772 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5775 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimation
) {
5776 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
5777 ExecuteCalculateDrawProperties(
5778 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5779 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5780 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5781 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5783 // Add opacity animation.
5784 child_
->SetOpacity(0.9f
);
5785 AddOpacityTransitionToController(
5786 child_
->layer_animation_controller(), 10.0, 0.9f
, 0.1f
, false);
5788 ExecuteCalculateDrawProperties(
5789 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5790 // Text AA should not be adjusted while animation is active.
5791 // Make sure LCD text AA setting remains unchanged.
5792 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5793 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5794 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5797 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest
,
5799 testing::Combine(testing::Bool(), testing::Bool()));
5801 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayer
) {
5802 FakeImplProxy proxy
;
5803 TestSharedBitmapManager shared_bitmap_manager
;
5804 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5805 host_impl
.CreatePendingTree();
5806 const gfx::Transform identity_matrix
;
5808 scoped_refptr
<Layer
> root
= Layer::Create();
5809 SetLayerPropertiesForTesting(root
.get(),
5816 root
->SetIsDrawable(true);
5818 scoped_refptr
<Layer
> child
= Layer::Create();
5819 SetLayerPropertiesForTesting(child
.get(),
5826 child
->SetIsDrawable(true);
5828 scoped_refptr
<Layer
> grand_child
= Layer::Create();
5829 SetLayerPropertiesForTesting(grand_child
.get(),
5836 grand_child
->SetIsDrawable(true);
5837 grand_child
->SetHideLayerAndSubtree(true);
5839 child
->AddChild(grand_child
);
5840 root
->AddChild(child
);
5842 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5843 host
->SetRootLayer(root
);
5845 RenderSurfaceLayerList render_surface_layer_list
;
5846 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5847 root
.get(), root
->bounds(), &render_surface_layer_list
);
5848 inputs
.can_adjust_raster_scales
= true;
5849 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5851 // We should have one render surface and two layers. The grand child has
5853 ASSERT_EQ(1u, render_surface_layer_list
.size());
5854 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5855 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
5856 EXPECT_EQ(child
->id(), root
->render_surface()->layer_list().at(1)->id());
5859 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayerImpl
) {
5860 FakeImplProxy proxy
;
5861 TestSharedBitmapManager shared_bitmap_manager
;
5862 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5863 host_impl
.CreatePendingTree();
5864 const gfx::Transform identity_matrix
;
5866 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
5867 SetLayerPropertiesForTesting(root
.get(),
5874 root
->SetDrawsContent(true);
5876 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
5877 SetLayerPropertiesForTesting(child
.get(),
5884 child
->SetDrawsContent(true);
5886 scoped_ptr
<LayerImpl
> grand_child
=
5887 LayerImpl::Create(host_impl
.pending_tree(), 3);
5888 SetLayerPropertiesForTesting(grand_child
.get(),
5895 grand_child
->SetDrawsContent(true);
5896 grand_child
->SetHideLayerAndSubtree(true);
5898 child
->AddChild(grand_child
.Pass());
5899 root
->AddChild(child
.Pass());
5901 LayerImplList render_surface_layer_list
;
5902 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5903 root
.get(), root
->bounds(), &render_surface_layer_list
);
5904 inputs
.can_adjust_raster_scales
= true;
5905 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5907 // We should have one render surface and two layers. The grand child has
5909 ASSERT_EQ(1u, render_surface_layer_list
.size());
5910 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5911 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
5912 EXPECT_EQ(2, root
->render_surface()->layer_list().at(1)->id());
5915 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayers
) {
5916 FakeImplProxy proxy
;
5917 TestSharedBitmapManager shared_bitmap_manager
;
5918 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5919 host_impl
.CreatePendingTree();
5920 const gfx::Transform identity_matrix
;
5922 scoped_refptr
<Layer
> root
= Layer::Create();
5923 SetLayerPropertiesForTesting(root
.get(),
5930 root
->SetIsDrawable(true);
5932 scoped_refptr
<Layer
> child
= Layer::Create();
5933 SetLayerPropertiesForTesting(child
.get(),
5940 child
->SetIsDrawable(true);
5941 child
->SetHideLayerAndSubtree(true);
5943 scoped_refptr
<Layer
> grand_child
= Layer::Create();
5944 SetLayerPropertiesForTesting(grand_child
.get(),
5951 grand_child
->SetIsDrawable(true);
5953 child
->AddChild(grand_child
);
5954 root
->AddChild(child
);
5956 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5957 host
->SetRootLayer(root
);
5959 RenderSurfaceLayerList render_surface_layer_list
;
5960 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5961 root
.get(), root
->bounds(), &render_surface_layer_list
);
5962 inputs
.can_adjust_raster_scales
= true;
5963 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5965 // We should have one render surface and one layers. The child has
5966 // hidden itself and the grand child.
5967 ASSERT_EQ(1u, render_surface_layer_list
.size());
5968 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
5969 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
5972 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayersImpl
) {
5973 FakeImplProxy proxy
;
5974 TestSharedBitmapManager shared_bitmap_manager
;
5975 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5976 host_impl
.CreatePendingTree();
5977 const gfx::Transform identity_matrix
;
5979 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
5980 SetLayerPropertiesForTesting(root
.get(),
5987 root
->SetDrawsContent(true);
5989 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
5990 SetLayerPropertiesForTesting(child
.get(),
5997 child
->SetDrawsContent(true);
5998 child
->SetHideLayerAndSubtree(true);
6000 scoped_ptr
<LayerImpl
> grand_child
=
6001 LayerImpl::Create(host_impl
.pending_tree(), 3);
6002 SetLayerPropertiesForTesting(grand_child
.get(),
6009 grand_child
->SetDrawsContent(true);
6011 child
->AddChild(grand_child
.Pass());
6012 root
->AddChild(child
.Pass());
6014 LayerImplList render_surface_layer_list
;
6015 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6016 root
.get(), root
->bounds(), &render_surface_layer_list
);
6017 inputs
.can_adjust_raster_scales
= true;
6018 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6020 // We should have one render surface and one layers. The child has
6021 // hidden itself and the grand child.
6022 ASSERT_EQ(1u, render_surface_layer_list
.size());
6023 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
6024 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
6027 void EmptyCopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {}
6029 TEST_F(LayerTreeHostCommonTest
, SubtreeHiddenWithCopyRequest
) {
6030 FakeImplProxy proxy
;
6031 TestSharedBitmapManager shared_bitmap_manager
;
6032 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6033 host_impl
.CreatePendingTree();
6034 const gfx::Transform identity_matrix
;
6036 scoped_refptr
<Layer
> root
= Layer::Create();
6037 SetLayerPropertiesForTesting(root
.get(),
6044 root
->SetIsDrawable(true);
6046 scoped_refptr
<Layer
> copy_grand_parent
= Layer::Create();
6047 SetLayerPropertiesForTesting(copy_grand_parent
.get(),
6054 copy_grand_parent
->SetIsDrawable(true);
6056 scoped_refptr
<Layer
> copy_parent
= Layer::Create();
6057 SetLayerPropertiesForTesting(copy_parent
.get(),
6064 copy_parent
->SetIsDrawable(true);
6065 copy_parent
->SetForceRenderSurface(true);
6067 scoped_refptr
<Layer
> copy_layer
= Layer::Create();
6068 SetLayerPropertiesForTesting(copy_layer
.get(),
6075 copy_layer
->SetIsDrawable(true);
6077 scoped_refptr
<Layer
> copy_child
= Layer::Create();
6078 SetLayerPropertiesForTesting(copy_child
.get(),
6085 copy_child
->SetIsDrawable(true);
6087 scoped_refptr
<Layer
> copy_grand_parent_sibling_before
= Layer::Create();
6088 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before
.get(),
6095 copy_grand_parent_sibling_before
->SetIsDrawable(true);
6097 scoped_refptr
<Layer
> copy_grand_parent_sibling_after
= Layer::Create();
6098 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after
.get(),
6105 copy_grand_parent_sibling_after
->SetIsDrawable(true);
6107 copy_layer
->AddChild(copy_child
);
6108 copy_parent
->AddChild(copy_layer
);
6109 copy_grand_parent
->AddChild(copy_parent
);
6110 root
->AddChild(copy_grand_parent_sibling_before
);
6111 root
->AddChild(copy_grand_parent
);
6112 root
->AddChild(copy_grand_parent_sibling_after
);
6114 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6115 host
->SetRootLayer(root
);
6117 // Hide the copy_grand_parent and its subtree. But make a copy request in that
6118 // hidden subtree on copy_layer.
6119 copy_grand_parent
->SetHideLayerAndSubtree(true);
6120 copy_grand_parent_sibling_before
->SetHideLayerAndSubtree(true);
6121 copy_grand_parent_sibling_after
->SetHideLayerAndSubtree(true);
6122 copy_layer
->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6123 base::Bind(&EmptyCopyOutputCallback
)));
6124 EXPECT_TRUE(copy_layer
->HasCopyRequest());
6126 RenderSurfaceLayerList render_surface_layer_list
;
6127 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6128 root
.get(), root
->bounds(), &render_surface_layer_list
);
6129 inputs
.can_adjust_raster_scales
= true;
6130 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6132 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
6133 EXPECT_TRUE(copy_grand_parent
->draw_properties().
6134 layer_or_descendant_has_copy_request
);
6135 EXPECT_TRUE(copy_parent
->draw_properties().
6136 layer_or_descendant_has_copy_request
);
6137 EXPECT_TRUE(copy_layer
->draw_properties().
6138 layer_or_descendant_has_copy_request
);
6139 EXPECT_FALSE(copy_child
->draw_properties().
6140 layer_or_descendant_has_copy_request
);
6141 EXPECT_FALSE(copy_grand_parent_sibling_before
->draw_properties().
6142 layer_or_descendant_has_copy_request
);
6143 EXPECT_FALSE(copy_grand_parent_sibling_after
->draw_properties().
6144 layer_or_descendant_has_copy_request
);
6146 // We should have three render surfaces, one for the root, one for the parent
6147 // since it owns a surface, and one for the copy_layer.
6148 ASSERT_EQ(3u, render_surface_layer_list
.size());
6149 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
6150 EXPECT_EQ(copy_parent
->id(), render_surface_layer_list
.at(1)->id());
6151 EXPECT_EQ(copy_layer
->id(), render_surface_layer_list
.at(2)->id());
6153 // The root render surface should have 2 contributing layers. The
6154 // copy_grand_parent is hidden along with its siblings, but the copy_parent
6155 // will appear since something in its subtree needs to be drawn for a copy
6157 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
6158 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6159 EXPECT_EQ(copy_parent
->id(),
6160 root
->render_surface()->layer_list().at(1)->id());
6162 // Nothing actually draws into the copy parent, so only the copy_layer will
6163 // appear in its list, since it needs to be drawn for the copy request.
6164 ASSERT_EQ(1u, copy_parent
->render_surface()->layer_list().size());
6165 EXPECT_EQ(copy_layer
->id(),
6166 copy_parent
->render_surface()->layer_list().at(0)->id());
6168 // The copy_layer's render surface should have two contributing layers.
6169 ASSERT_EQ(2u, copy_layer
->render_surface()->layer_list().size());
6170 EXPECT_EQ(copy_layer
->id(),
6171 copy_layer
->render_surface()->layer_list().at(0)->id());
6172 EXPECT_EQ(copy_child
->id(),
6173 copy_layer
->render_surface()->layer_list().at(1)->id());
6176 TEST_F(LayerTreeHostCommonTest
, ClippedOutCopyRequest
) {
6177 FakeImplProxy proxy
;
6178 TestSharedBitmapManager shared_bitmap_manager
;
6179 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6180 host_impl
.CreatePendingTree();
6181 const gfx::Transform identity_matrix
;
6183 scoped_refptr
<Layer
> root
= Layer::Create();
6184 SetLayerPropertiesForTesting(root
.get(),
6191 root
->SetIsDrawable(true);
6193 scoped_refptr
<Layer
> copy_parent
= Layer::Create();
6194 SetLayerPropertiesForTesting(copy_parent
.get(),
6201 copy_parent
->SetIsDrawable(true);
6202 copy_parent
->SetMasksToBounds(true);
6204 scoped_refptr
<Layer
> copy_layer
= Layer::Create();
6205 SetLayerPropertiesForTesting(copy_layer
.get(),
6212 copy_layer
->SetIsDrawable(true);
6214 scoped_refptr
<Layer
> copy_child
= Layer::Create();
6215 SetLayerPropertiesForTesting(copy_child
.get(),
6222 copy_child
->SetIsDrawable(true);
6224 copy_layer
->AddChild(copy_child
);
6225 copy_parent
->AddChild(copy_layer
);
6226 root
->AddChild(copy_parent
);
6228 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6229 host
->SetRootLayer(root
);
6231 copy_layer
->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6232 base::Bind(&EmptyCopyOutputCallback
)));
6233 EXPECT_TRUE(copy_layer
->HasCopyRequest());
6235 RenderSurfaceLayerList render_surface_layer_list
;
6236 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6237 root
.get(), root
->bounds(), &render_surface_layer_list
);
6238 inputs
.can_adjust_raster_scales
= true;
6239 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6241 // We should have one render surface, as the others are clipped out.
6242 ASSERT_EQ(1u, render_surface_layer_list
.size());
6243 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
6245 // The root render surface should only have 1 contributing layer, since the
6246 // other layers are empty/clipped away.
6247 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
6248 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6251 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInsideSurface
) {
6252 FakeImplProxy proxy
;
6253 TestSharedBitmapManager shared_bitmap_manager
;
6254 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6255 host_impl
.CreatePendingTree();
6256 const gfx::Transform identity_matrix
;
6258 scoped_refptr
<Layer
> root
= Layer::Create();
6259 SetLayerPropertiesForTesting(root
.get(),
6266 root
->SetIsDrawable(true);
6268 // The surface is moved slightly outside of the viewport.
6269 scoped_refptr
<Layer
> surface
= Layer::Create();
6270 SetLayerPropertiesForTesting(surface
.get(),
6273 gfx::PointF(-10, -20),
6277 surface
->SetForceRenderSurface(true);
6279 scoped_refptr
<Layer
> surface_child
= Layer::Create();
6280 SetLayerPropertiesForTesting(surface_child
.get(),
6287 surface_child
->SetIsDrawable(true);
6289 surface
->AddChild(surface_child
);
6290 root
->AddChild(surface
);
6292 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6293 host
->SetRootLayer(root
);
6295 RenderSurfaceLayerList render_surface_layer_list
;
6296 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6297 root
.get(), root
->bounds(), &render_surface_layer_list
);
6298 inputs
.can_adjust_raster_scales
= true;
6299 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6301 // The visible_content_rect for the |surface_child| should not be clipped by
6303 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
6304 surface_child
->visible_content_rect().ToString());
6307 TEST_F(LayerTreeHostCommonTest
, TransformedClipParent
) {
6308 // Ensure that a transform between the layer and its render surface is not a
6309 // problem. Constructs the following layer tree.
6311 // root (a render surface)
6313 // + clip_parent (scaled)
6314 // + intervening_clipping_layer
6317 // The render surface should be resized correctly and the clip child should
6318 // inherit the right clip rect.
6319 scoped_refptr
<Layer
> root
= Layer::Create();
6320 scoped_refptr
<Layer
> render_surface
= Layer::Create();
6321 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6322 scoped_refptr
<Layer
> intervening
= Layer::Create();
6323 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6324 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6326 root
->AddChild(render_surface
);
6327 render_surface
->AddChild(clip_parent
);
6328 clip_parent
->AddChild(intervening
);
6329 intervening
->AddChild(clip_child
);
6331 clip_child
->SetClipParent(clip_parent
.get());
6333 intervening
->SetMasksToBounds(true);
6334 clip_parent
->SetMasksToBounds(true);
6336 render_surface
->SetForceRenderSurface(true);
6338 gfx::Transform scale_transform
;
6339 scale_transform
.Scale(2, 2);
6341 gfx::Transform identity_transform
;
6343 SetLayerPropertiesForTesting(root
.get(),
6350 SetLayerPropertiesForTesting(render_surface
.get(),
6357 SetLayerPropertiesForTesting(clip_parent
.get(),
6360 gfx::PointF(1.f
, 1.f
),
6364 SetLayerPropertiesForTesting(intervening
.get(),
6367 gfx::PointF(1.f
, 1.f
),
6371 SetLayerPropertiesForTesting(clip_child
.get(),
6374 gfx::PointF(1.f
, 1.f
),
6379 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6380 host
->SetRootLayer(root
);
6382 ExecuteCalculateDrawProperties(root
.get());
6384 ASSERT_TRUE(root
->render_surface());
6385 ASSERT_TRUE(render_surface
->render_surface());
6387 // Ensure that we've inherited our clip parent's clip and weren't affected
6388 // by the intervening clip layer.
6389 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
6390 clip_parent
->clip_rect().ToString());
6391 ASSERT_EQ(clip_parent
->clip_rect().ToString(),
6392 clip_child
->clip_rect().ToString());
6393 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
6394 intervening
->clip_rect().ToString());
6396 // Ensure that the render surface reports a content rect that has been grown
6397 // to accomodate for the clip child.
6398 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
6399 render_surface
->render_surface()->content_rect().ToString());
6401 // The above check implies the two below, but they nicely demonstrate that
6402 // we've grown, despite the intervening layer's clip.
6403 ASSERT_TRUE(clip_parent
->clip_rect().Contains(
6404 render_surface
->render_surface()->content_rect()));
6405 ASSERT_FALSE(intervening
->clip_rect().Contains(
6406 render_surface
->render_surface()->content_rect()));
6409 TEST_F(LayerTreeHostCommonTest
, ClipParentWithInterveningRenderSurface
) {
6410 // Ensure that intervening render surfaces are not a problem in the basic
6411 // case. In the following tree, both render surfaces should be resized to
6412 // accomodate for the clip child, despite an intervening clip.
6414 // root (a render surface)
6415 // + clip_parent (masks to bounds)
6416 // + render_surface1 (sets opacity)
6417 // + intervening (masks to bounds)
6418 // + render_surface2 (also sets opacity)
6421 scoped_refptr
<Layer
> root
= Layer::Create();
6422 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6423 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
6424 scoped_refptr
<Layer
> intervening
= Layer::Create();
6425 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
6426 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6427 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6429 root
->AddChild(clip_parent
);
6430 clip_parent
->AddChild(render_surface1
);
6431 render_surface1
->AddChild(intervening
);
6432 intervening
->AddChild(render_surface2
);
6433 render_surface2
->AddChild(clip_child
);
6435 clip_child
->SetClipParent(clip_parent
.get());
6437 intervening
->SetMasksToBounds(true);
6438 clip_parent
->SetMasksToBounds(true);
6440 render_surface1
->SetForceRenderSurface(true);
6441 render_surface2
->SetForceRenderSurface(true);
6443 gfx::Transform translation_transform
;
6444 translation_transform
.Translate(2, 2);
6446 gfx::Transform identity_transform
;
6447 SetLayerPropertiesForTesting(root
.get(),
6454 SetLayerPropertiesForTesting(clip_parent
.get(),
6455 translation_transform
,
6457 gfx::PointF(1.f
, 1.f
),
6461 SetLayerPropertiesForTesting(render_surface1
.get(),
6468 SetLayerPropertiesForTesting(intervening
.get(),
6471 gfx::PointF(1.f
, 1.f
),
6475 SetLayerPropertiesForTesting(render_surface2
.get(),
6482 SetLayerPropertiesForTesting(clip_child
.get(),
6485 gfx::PointF(-10.f
, -10.f
),
6490 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6491 host
->SetRootLayer(root
);
6493 ExecuteCalculateDrawProperties(root
.get());
6495 EXPECT_TRUE(root
->render_surface());
6496 EXPECT_TRUE(render_surface1
->render_surface());
6497 EXPECT_TRUE(render_surface2
->render_surface());
6499 // Since the render surfaces could have expanded, they should not clip (their
6500 // bounds would no longer be reliable). We should resort to layer clipping
6502 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6503 render_surface1
->render_surface()->clip_rect().ToString());
6504 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6505 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6506 render_surface2
->render_surface()->clip_rect().ToString());
6507 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
6509 // NB: clip rects are in target space.
6510 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6511 render_surface1
->clip_rect().ToString());
6512 EXPECT_TRUE(render_surface1
->is_clipped());
6514 // This value is inherited from the clipping ancestor layer, 'intervening'.
6515 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6516 render_surface2
->clip_rect().ToString());
6517 EXPECT_TRUE(render_surface2
->is_clipped());
6519 // The content rects of both render surfaces should both have expanded to
6520 // contain the clip child.
6521 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6522 render_surface1
->render_surface()->content_rect().ToString());
6523 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6524 render_surface2
->render_surface()->content_rect().ToString());
6526 // The clip child should have inherited the clip parent's clip (projected to
6527 // the right space, of course), and should have the correctly sized visible
6529 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6530 clip_child
->clip_rect().ToString());
6531 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
6532 clip_child
->visible_content_rect().ToString());
6533 EXPECT_TRUE(clip_child
->is_clipped());
6536 TEST_F(LayerTreeHostCommonTest
, ClipParentScrolledInterveningLayer
) {
6537 // Ensure that intervening render surfaces are not a problem, even if there
6538 // is a scroll involved. Note, we do _not_ have to consider any other sort
6541 // root (a render surface)
6542 // + clip_parent (masks to bounds)
6543 // + render_surface1 (sets opacity)
6544 // + intervening (masks to bounds AND scrolls)
6545 // + render_surface2 (also sets opacity)
6548 scoped_refptr
<Layer
> root
= Layer::Create();
6549 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6550 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
6551 scoped_refptr
<Layer
> intervening
= Layer::Create();
6552 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
6553 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6554 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6556 root
->AddChild(clip_parent
);
6557 clip_parent
->AddChild(render_surface1
);
6558 render_surface1
->AddChild(intervening
);
6559 intervening
->AddChild(render_surface2
);
6560 render_surface2
->AddChild(clip_child
);
6562 clip_child
->SetClipParent(clip_parent
.get());
6564 intervening
->SetMasksToBounds(true);
6565 clip_parent
->SetMasksToBounds(true);
6566 intervening
->SetScrollClipLayerId(clip_parent
->id());
6567 intervening
->SetScrollOffset(gfx::ScrollOffset(3, 3));
6569 render_surface1
->SetForceRenderSurface(true);
6570 render_surface2
->SetForceRenderSurface(true);
6572 gfx::Transform translation_transform
;
6573 translation_transform
.Translate(2, 2);
6575 gfx::Transform identity_transform
;
6576 SetLayerPropertiesForTesting(root
.get(),
6583 SetLayerPropertiesForTesting(clip_parent
.get(),
6584 translation_transform
,
6586 gfx::PointF(1.f
, 1.f
),
6590 SetLayerPropertiesForTesting(render_surface1
.get(),
6597 SetLayerPropertiesForTesting(intervening
.get(),
6600 gfx::PointF(1.f
, 1.f
),
6604 SetLayerPropertiesForTesting(render_surface2
.get(),
6611 SetLayerPropertiesForTesting(clip_child
.get(),
6614 gfx::PointF(-10.f
, -10.f
),
6619 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6620 host
->SetRootLayer(root
);
6622 ExecuteCalculateDrawProperties(root
.get());
6624 EXPECT_TRUE(root
->render_surface());
6625 EXPECT_TRUE(render_surface1
->render_surface());
6626 EXPECT_TRUE(render_surface2
->render_surface());
6628 // Since the render surfaces could have expanded, they should not clip (their
6629 // bounds would no longer be reliable). We should resort to layer clipping
6631 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6632 render_surface1
->render_surface()->clip_rect().ToString());
6633 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6634 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6635 render_surface2
->render_surface()->clip_rect().ToString());
6636 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
6638 // NB: clip rects are in target space.
6639 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6640 render_surface1
->clip_rect().ToString());
6641 EXPECT_TRUE(render_surface1
->is_clipped());
6643 // This value is inherited from the clipping ancestor layer, 'intervening'.
6644 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
6645 render_surface2
->clip_rect().ToString());
6646 EXPECT_TRUE(render_surface2
->is_clipped());
6648 // The content rects of both render surfaces should both have expanded to
6649 // contain the clip child.
6650 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6651 render_surface1
->render_surface()->content_rect().ToString());
6652 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6653 render_surface2
->render_surface()->content_rect().ToString());
6655 // The clip child should have inherited the clip parent's clip (projected to
6656 // the right space, of course), and should have the correctly sized visible
6658 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6659 clip_child
->clip_rect().ToString());
6660 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
6661 clip_child
->visible_content_rect().ToString());
6662 EXPECT_TRUE(clip_child
->is_clipped());
6665 TEST_F(LayerTreeHostCommonTest
, DescendantsOfClipChildren
) {
6666 // Ensures that descendants of the clip child inherit the correct clip.
6668 // root (a render surface)
6669 // + clip_parent (masks to bounds)
6670 // + intervening (masks to bounds)
6674 scoped_refptr
<Layer
> root
= Layer::Create();
6675 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6676 scoped_refptr
<Layer
> intervening
= Layer::Create();
6677 scoped_refptr
<Layer
> clip_child
= Layer::Create();
6678 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
6679 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6681 root
->AddChild(clip_parent
);
6682 clip_parent
->AddChild(intervening
);
6683 intervening
->AddChild(clip_child
);
6684 clip_child
->AddChild(child
);
6686 clip_child
->SetClipParent(clip_parent
.get());
6688 intervening
->SetMasksToBounds(true);
6689 clip_parent
->SetMasksToBounds(true);
6691 gfx::Transform identity_transform
;
6692 SetLayerPropertiesForTesting(root
.get(),
6699 SetLayerPropertiesForTesting(clip_parent
.get(),
6706 SetLayerPropertiesForTesting(intervening
.get(),
6713 SetLayerPropertiesForTesting(clip_child
.get(),
6720 SetLayerPropertiesForTesting(child
.get(),
6728 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6729 host
->SetRootLayer(root
);
6731 ExecuteCalculateDrawProperties(root
.get());
6733 EXPECT_TRUE(root
->render_surface());
6735 // Neither the clip child nor its descendant should have inherited the clip
6736 // from |intervening|.
6737 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6738 clip_child
->clip_rect().ToString());
6739 EXPECT_TRUE(clip_child
->is_clipped());
6740 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6741 child
->visible_content_rect().ToString());
6742 EXPECT_TRUE(child
->is_clipped());
6745 TEST_F(LayerTreeHostCommonTest
,
6746 SurfacesShouldBeUnaffectedByNonDescendantClipChildren
) {
6747 // Ensures that non-descendant clip children in the tree do not affect
6750 // root (a render surface)
6751 // + clip_parent (masks to bounds)
6752 // + render_surface1
6754 // + render_surface2
6757 // In this example render_surface2 should be unaffected by clip_child.
6758 scoped_refptr
<Layer
> root
= Layer::Create();
6759 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6760 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
6761 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6762 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6763 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
6764 scoped_refptr
<LayerWithForcedDrawsContent
> non_clip_child
=
6765 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6767 root
->AddChild(clip_parent
);
6768 clip_parent
->AddChild(render_surface1
);
6769 render_surface1
->AddChild(clip_child
);
6770 clip_parent
->AddChild(render_surface2
);
6771 render_surface2
->AddChild(non_clip_child
);
6773 clip_child
->SetClipParent(clip_parent
.get());
6775 clip_parent
->SetMasksToBounds(true);
6776 render_surface1
->SetMasksToBounds(true);
6778 gfx::Transform identity_transform
;
6779 SetLayerPropertiesForTesting(root
.get(),
6786 SetLayerPropertiesForTesting(clip_parent
.get(),
6793 SetLayerPropertiesForTesting(render_surface1
.get(),
6800 SetLayerPropertiesForTesting(render_surface2
.get(),
6807 SetLayerPropertiesForTesting(clip_child
.get(),
6814 SetLayerPropertiesForTesting(non_clip_child
.get(),
6822 render_surface1
->SetForceRenderSurface(true);
6823 render_surface2
->SetForceRenderSurface(true);
6825 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6826 host
->SetRootLayer(root
);
6828 ExecuteCalculateDrawProperties(root
.get());
6830 EXPECT_TRUE(root
->render_surface());
6831 EXPECT_TRUE(render_surface1
->render_surface());
6832 EXPECT_TRUE(render_surface2
->render_surface());
6834 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6835 render_surface1
->clip_rect().ToString());
6836 EXPECT_TRUE(render_surface1
->is_clipped());
6838 // The render surface should not clip (it has unclipped descendants), instead
6839 // it should rely on layer clipping.
6840 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6841 render_surface1
->render_surface()->clip_rect().ToString());
6842 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6844 // That said, it should have grown to accomodate the unclipped descendant.
6845 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
6846 render_surface1
->render_surface()->content_rect().ToString());
6848 // This render surface should clip. It has no unclipped descendants.
6849 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6850 render_surface2
->clip_rect().ToString());
6851 EXPECT_TRUE(render_surface2
->render_surface()->is_clipped());
6853 // It also shouldn't have grown to accomodate the clip child.
6854 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6855 render_surface2
->render_surface()->content_rect().ToString());
6857 // Sanity check our num_unclipped_descendants values.
6858 EXPECT_EQ(1, render_surface1
->num_unclipped_descendants());
6859 EXPECT_EQ(0, render_surface2
->num_unclipped_descendants());
6862 TEST_F(LayerTreeHostCommonTest
, CanRenderToSeparateSurface
) {
6863 FakeImplProxy proxy
;
6864 TestSharedBitmapManager shared_bitmap_manager
;
6865 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6866 scoped_ptr
<LayerImpl
> root
=
6867 LayerImpl::Create(host_impl
.active_tree(), 12345);
6868 scoped_ptr
<LayerImpl
> child1
=
6869 LayerImpl::Create(host_impl
.active_tree(), 123456);
6870 scoped_ptr
<LayerImpl
> child2
=
6871 LayerImpl::Create(host_impl
.active_tree(), 1234567);
6872 scoped_ptr
<LayerImpl
> child3
=
6873 LayerImpl::Create(host_impl
.active_tree(), 12345678);
6875 gfx::Transform identity_matrix
;
6876 gfx::Point3F transform_origin
;
6877 gfx::PointF position
;
6878 gfx::Size
bounds(100, 100);
6879 SetLayerPropertiesForTesting(root
.get(),
6886 root
->SetDrawsContent(true);
6888 // This layer structure normally forces render surface due to preserves3d
6890 SetLayerPropertiesForTesting(child1
.get(),
6897 child1
->SetDrawsContent(true);
6898 SetLayerPropertiesForTesting(child2
.get(),
6905 child2
->SetDrawsContent(true);
6906 SetLayerPropertiesForTesting(child3
.get(),
6913 child3
->SetDrawsContent(true);
6915 child2
->Set3dSortingContextId(1);
6916 child3
->Set3dSortingContextId(1);
6918 child2
->AddChild(child3
.Pass());
6919 child1
->AddChild(child2
.Pass());
6920 root
->AddChild(child1
.Pass());
6923 LayerImplList render_surface_layer_list
;
6924 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root
.get());
6925 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6926 root
.get(), root
->bounds(), &render_surface_layer_list
);
6927 inputs
.can_render_to_separate_surface
= true;
6928 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6930 EXPECT_EQ(2u, render_surface_layer_list
.size());
6934 LayerImplList render_surface_layer_list
;
6935 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6936 root
.get(), root
->bounds(), &render_surface_layer_list
);
6937 inputs
.can_render_to_separate_surface
= false;
6938 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6940 EXPECT_EQ(1u, render_surface_layer_list
.size());
6944 TEST_F(LayerTreeHostCommonTest
, DoNotIncludeBackfaceInvisibleSurfaces
) {
6945 scoped_refptr
<Layer
> root
= Layer::Create();
6946 scoped_refptr
<Layer
> render_surface
= Layer::Create();
6947 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
6948 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6950 root
->AddChild(render_surface
);
6951 render_surface
->AddChild(child
);
6953 gfx::Transform identity_transform
;
6954 SetLayerPropertiesForTesting(root
.get(),
6961 SetLayerPropertiesForTesting(render_surface
.get(),
6968 SetLayerPropertiesForTesting(child
.get(),
6976 root
->SetShouldFlattenTransform(false);
6977 root
->Set3dSortingContextId(1);
6978 render_surface
->SetDoubleSided(false);
6979 render_surface
->SetForceRenderSurface(true);
6981 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6982 host
->SetRootLayer(root
);
6984 ExecuteCalculateDrawProperties(root
.get());
6986 EXPECT_EQ(2u, render_surface_layer_list()->size());
6988 render_surface_layer_list()->at(0)
6989 ->render_surface()->layer_list().size());
6991 render_surface_layer_list()->at(1)
6992 ->render_surface()->layer_list().size());
6994 gfx::Transform rotation_transform
= identity_transform
;
6995 rotation_transform
.RotateAboutXAxis(180.0);
6997 render_surface
->SetTransform(rotation_transform
);
6999 ExecuteCalculateDrawProperties(root
.get());
7001 EXPECT_EQ(1u, render_surface_layer_list()->size());
7003 render_surface_layer_list()->at(0)
7004 ->render_surface()->layer_list().size());
7007 TEST_F(LayerTreeHostCommonTest
, ClippedByScrollParent
) {
7008 // Checks that the simple case (being clipped by a scroll parent that would
7009 // have been processed before you anyhow) results in the right clips.
7012 // + scroll_parent_border
7013 // | + scroll_parent_clip
7014 // | + scroll_parent
7017 scoped_refptr
<Layer
> root
= Layer::Create();
7018 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7019 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7020 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7021 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7022 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7023 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7025 root
->AddChild(scroll_child
);
7027 root
->AddChild(scroll_parent_border
);
7028 scroll_parent_border
->AddChild(scroll_parent_clip
);
7029 scroll_parent_clip
->AddChild(scroll_parent
);
7031 scroll_parent_clip
->SetMasksToBounds(true);
7033 scroll_child
->SetScrollParent(scroll_parent
.get());
7035 gfx::Transform identity_transform
;
7036 SetLayerPropertiesForTesting(root
.get(),
7043 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7050 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7057 SetLayerPropertiesForTesting(scroll_parent
.get(),
7064 SetLayerPropertiesForTesting(scroll_child
.get(),
7072 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7073 host
->SetRootLayer(root
);
7075 ExecuteCalculateDrawProperties(root
.get());
7077 EXPECT_TRUE(root
->render_surface());
7079 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7080 scroll_child
->clip_rect().ToString());
7081 EXPECT_TRUE(scroll_child
->is_clipped());
7084 TEST_F(LayerTreeHostCommonTest
, SingularTransformSubtreesDoNotDraw
) {
7085 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
7086 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7087 scoped_refptr
<LayerWithForcedDrawsContent
> parent
=
7088 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7089 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7090 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7092 root
->AddChild(parent
);
7093 parent
->AddChild(child
);
7095 gfx::Transform identity_transform
;
7096 SetLayerPropertiesForTesting(root
.get(),
7103 root
->SetForceRenderSurface(true);
7104 SetLayerPropertiesForTesting(parent
.get(),
7111 parent
->SetForceRenderSurface(true);
7112 SetLayerPropertiesForTesting(child
.get(),
7119 child
->SetForceRenderSurface(true);
7121 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7122 host
->SetRootLayer(root
);
7124 ExecuteCalculateDrawProperties(root
.get());
7126 EXPECT_EQ(3u, render_surface_layer_list()->size());
7128 gfx::Transform singular_transform
;
7129 singular_transform
.Scale3d(
7130 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
7132 child
->SetTransform(singular_transform
);
7134 ExecuteCalculateDrawProperties(root
.get());
7136 EXPECT_EQ(2u, render_surface_layer_list()->size());
7138 // Ensure that the entire subtree under a layer with singular transform does
7139 // not get rendered.
7140 parent
->SetTransform(singular_transform
);
7141 child
->SetTransform(identity_transform
);
7143 ExecuteCalculateDrawProperties(root
.get());
7145 EXPECT_EQ(1u, render_surface_layer_list()->size());
7148 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollParent
) {
7149 // Checks that clipping by a scroll parent that follows you in paint order
7150 // still results in correct clipping.
7154 // + scroll_parent_border
7155 // + scroll_parent_clip
7158 scoped_refptr
<Layer
> root
= Layer::Create();
7159 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7160 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7161 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7162 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7163 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7164 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7166 root
->AddChild(scroll_parent_border
);
7167 scroll_parent_border
->AddChild(scroll_parent_clip
);
7168 scroll_parent_clip
->AddChild(scroll_parent
);
7170 root
->AddChild(scroll_child
);
7172 scroll_parent_clip
->SetMasksToBounds(true);
7174 scroll_child
->SetScrollParent(scroll_parent
.get());
7176 gfx::Transform identity_transform
;
7177 SetLayerPropertiesForTesting(root
.get(),
7184 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7191 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7198 SetLayerPropertiesForTesting(scroll_parent
.get(),
7205 SetLayerPropertiesForTesting(scroll_child
.get(),
7213 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7214 host
->SetRootLayer(root
);
7216 ExecuteCalculateDrawProperties(root
.get());
7218 EXPECT_TRUE(root
->render_surface());
7220 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7221 scroll_child
->clip_rect().ToString());
7222 EXPECT_TRUE(scroll_child
->is_clipped());
7225 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollGrandparent
) {
7226 // Checks that clipping by a scroll parent and scroll grandparent that follow
7227 // you in paint order still results in correct clipping.
7231 // + scroll_parent_border
7232 // | + scroll_parent_clip
7233 // | + scroll_parent
7234 // + scroll_grandparent_border
7235 // + scroll_grandparent_clip
7236 // + scroll_grandparent
7238 scoped_refptr
<Layer
> root
= Layer::Create();
7239 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7240 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7241 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7242 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7244 scoped_refptr
<Layer
> scroll_grandparent_border
= Layer::Create();
7245 scoped_refptr
<Layer
> scroll_grandparent_clip
= Layer::Create();
7246 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_grandparent
=
7247 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7249 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7250 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7252 root
->AddChild(scroll_child
);
7254 root
->AddChild(scroll_parent_border
);
7255 scroll_parent_border
->AddChild(scroll_parent_clip
);
7256 scroll_parent_clip
->AddChild(scroll_parent
);
7258 root
->AddChild(scroll_grandparent_border
);
7259 scroll_grandparent_border
->AddChild(scroll_grandparent_clip
);
7260 scroll_grandparent_clip
->AddChild(scroll_grandparent
);
7262 scroll_parent_clip
->SetMasksToBounds(true);
7263 scroll_grandparent_clip
->SetMasksToBounds(true);
7265 scroll_child
->SetScrollParent(scroll_parent
.get());
7266 scroll_parent_border
->SetScrollParent(scroll_grandparent
.get());
7268 gfx::Transform identity_transform
;
7269 SetLayerPropertiesForTesting(root
.get(),
7276 SetLayerPropertiesForTesting(scroll_grandparent_border
.get(),
7283 SetLayerPropertiesForTesting(scroll_grandparent_clip
.get(),
7290 SetLayerPropertiesForTesting(scroll_grandparent
.get(),
7297 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7304 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7311 SetLayerPropertiesForTesting(scroll_parent
.get(),
7318 SetLayerPropertiesForTesting(scroll_child
.get(),
7326 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7327 host
->SetRootLayer(root
);
7329 ExecuteCalculateDrawProperties(root
.get());
7331 EXPECT_TRUE(root
->render_surface());
7333 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7334 scroll_child
->clip_rect().ToString());
7335 EXPECT_TRUE(scroll_child
->is_clipped());
7337 // Despite the fact that we visited the above layers out of order to get the
7338 // correct clip, the layer lists should be unaffected.
7339 EXPECT_EQ(3u, root
->render_surface()->layer_list().size());
7340 EXPECT_EQ(scroll_child
.get(),
7341 root
->render_surface()->layer_list().at(0).get());
7342 EXPECT_EQ(scroll_parent
.get(),
7343 root
->render_surface()->layer_list().at(1).get());
7344 EXPECT_EQ(scroll_grandparent
.get(),
7345 root
->render_surface()->layer_list().at(2).get());
7348 TEST_F(LayerTreeHostCommonTest
, OutOfOrderClippingRequiresRSLLSorting
) {
7349 // Ensures that even if we visit layers out of order, we still produce a
7350 // correctly ordered render surface layer list.
7353 // + scroll_parent_border
7354 // + scroll_parent_clip
7356 // + render_surface1
7357 // + scroll_grandparent_border
7358 // + scroll_grandparent_clip
7359 // + scroll_grandparent
7360 // + render_surface2
7362 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
7363 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7365 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7366 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7367 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7368 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7369 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface1
=
7370 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7372 scoped_refptr
<Layer
> scroll_grandparent_border
= Layer::Create();
7373 scoped_refptr
<Layer
> scroll_grandparent_clip
= Layer::Create();
7374 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_grandparent
=
7375 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7376 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface2
=
7377 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7379 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7380 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7382 root
->AddChild(scroll_child
);
7384 root
->AddChild(scroll_parent_border
);
7385 scroll_parent_border
->AddChild(scroll_parent_clip
);
7386 scroll_parent_clip
->AddChild(scroll_parent
);
7387 scroll_parent
->AddChild(render_surface2
);
7389 root
->AddChild(scroll_grandparent_border
);
7390 scroll_grandparent_border
->AddChild(scroll_grandparent_clip
);
7391 scroll_grandparent_clip
->AddChild(scroll_grandparent
);
7392 scroll_grandparent
->AddChild(render_surface1
);
7394 scroll_parent_clip
->SetMasksToBounds(true);
7395 scroll_grandparent_clip
->SetMasksToBounds(true);
7397 scroll_child
->SetScrollParent(scroll_parent
.get());
7398 scroll_parent_border
->SetScrollParent(scroll_grandparent
.get());
7400 render_surface1
->SetForceRenderSurface(true);
7401 render_surface2
->SetForceRenderSurface(true);
7403 gfx::Transform identity_transform
;
7404 SetLayerPropertiesForTesting(root
.get(),
7411 SetLayerPropertiesForTesting(scroll_grandparent_border
.get(),
7418 SetLayerPropertiesForTesting(scroll_grandparent_clip
.get(),
7425 SetLayerPropertiesForTesting(scroll_grandparent
.get(),
7432 SetLayerPropertiesForTesting(render_surface1
.get(),
7439 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7446 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7453 SetLayerPropertiesForTesting(scroll_parent
.get(),
7460 SetLayerPropertiesForTesting(render_surface2
.get(),
7467 SetLayerPropertiesForTesting(scroll_child
.get(),
7475 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7476 host
->SetRootLayer(root
);
7478 RenderSurfaceLayerList render_surface_layer_list
;
7479 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
7483 &render_surface_layer_list
);
7485 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7487 EXPECT_TRUE(root
->render_surface());
7489 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7490 scroll_child
->clip_rect().ToString());
7491 EXPECT_TRUE(scroll_child
->is_clipped());
7493 // Despite the fact that we had to process the layers out of order to get the
7494 // right clip, our render_surface_layer_list's order should be unaffected.
7495 EXPECT_EQ(3u, render_surface_layer_list
.size());
7496 EXPECT_EQ(root
.get(), render_surface_layer_list
.at(0));
7497 EXPECT_EQ(render_surface2
.get(), render_surface_layer_list
.at(1));
7498 EXPECT_EQ(render_surface1
.get(), render_surface_layer_list
.at(2));
7499 EXPECT_TRUE(render_surface_layer_list
.at(0)->render_surface());
7500 EXPECT_TRUE(render_surface_layer_list
.at(1)->render_surface());
7501 EXPECT_TRUE(render_surface_layer_list
.at(2)->render_surface());
7504 TEST_F(LayerTreeHostCommonTest
, DoNotClobberSorting
) {
7505 // We rearrange layer list contributions if we have to visit children out of
7506 // order, but it should be a 'stable' rearrangement. That is, the layer list
7507 // additions for a single layer should not be reordered, though their position
7508 // wrt to the contributions due to a sibling may vary.
7514 // + scroll_parent_border
7515 // + scroll_parent_clip
7518 FakeImplProxy proxy
;
7519 TestSharedBitmapManager shared_bitmap_manager
;
7520 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7521 host_impl
.CreatePendingTree();
7522 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7523 scoped_ptr
<LayerImpl
> scroll_parent_border
=
7524 LayerImpl::Create(host_impl
.active_tree(), 2);
7525 scoped_ptr
<LayerImpl
> scroll_parent_clip
=
7526 LayerImpl::Create(host_impl
.active_tree(), 3);
7527 scoped_ptr
<LayerImpl
> scroll_parent
=
7528 LayerImpl::Create(host_impl
.active_tree(), 4);
7529 scoped_ptr
<LayerImpl
> scroll_child
=
7530 LayerImpl::Create(host_impl
.active_tree(), 5);
7531 scoped_ptr
<LayerImpl
> bottom_content
=
7532 LayerImpl::Create(host_impl
.active_tree(), 6);
7533 scoped_ptr
<LayerImpl
> top_content
=
7534 LayerImpl::Create(host_impl
.active_tree(), 7);
7536 scroll_parent_clip
->SetMasksToBounds(true);
7538 scroll_child
->SetScrollParent(scroll_parent
.get());
7539 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
7540 scroll_children
->insert(scroll_child
.get());
7541 scroll_parent
->SetScrollChildren(scroll_children
.release());
7543 scroll_child
->SetDrawsContent(true);
7544 scroll_parent
->SetDrawsContent(true);
7545 top_content
->SetDrawsContent(true);
7546 bottom_content
->SetDrawsContent(true);
7548 gfx::Transform identity_transform
;
7549 gfx::Transform top_transform
;
7550 top_transform
.Translate3d(0.0, 0.0, 5.0);
7551 gfx::Transform bottom_transform
;
7552 bottom_transform
.Translate3d(0.0, 0.0, 3.0);
7554 SetLayerPropertiesForTesting(root
.get(),
7561 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7568 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7575 SetLayerPropertiesForTesting(scroll_parent
.get(),
7582 SetLayerPropertiesForTesting(scroll_child
.get(),
7589 SetLayerPropertiesForTesting(top_content
.get(),
7596 SetLayerPropertiesForTesting(bottom_content
.get(),
7604 scroll_child
->SetShouldFlattenTransform(false);
7605 scroll_child
->Set3dSortingContextId(1);
7607 scroll_child
->AddChild(top_content
.Pass());
7608 scroll_child
->AddChild(bottom_content
.Pass());
7609 root
->AddChild(scroll_child
.Pass());
7611 scroll_parent_clip
->AddChild(scroll_parent
.Pass());
7612 scroll_parent_border
->AddChild(scroll_parent_clip
.Pass());
7613 root
->AddChild(scroll_parent_border
.Pass());
7615 LayerImplList render_surface_layer_list
;
7616 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7617 root
.get(), root
->bounds(), &render_surface_layer_list
);
7619 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7621 EXPECT_TRUE(root
->render_surface());
7623 // If we don't sort by depth and let the layers get added in the order they
7624 // would normally be visited in, then layers 6 and 7 will be out of order. In
7625 // other words, although we've had to shift 5, 6, and 7 to appear before 4
7626 // in the list (because of the scroll parent relationship), this should not
7627 // have an effect on the the order of 5, 6, and 7 (which had been reordered
7628 // due to layer sorting).
7629 EXPECT_EQ(4u, root
->render_surface()->layer_list().size());
7630 EXPECT_EQ(5, root
->render_surface()->layer_list().at(0)->id());
7631 EXPECT_EQ(6, root
->render_surface()->layer_list().at(1)->id());
7632 EXPECT_EQ(7, root
->render_surface()->layer_list().at(2)->id());
7633 EXPECT_EQ(4, root
->render_surface()->layer_list().at(3)->id());
7636 TEST_F(LayerTreeHostCommonTest
, ScrollCompensationWithRounding
) {
7637 // This test verifies that a scrolling layer that gets snapped to
7638 // integer coordinates doesn't move a fixed position child.
7645 FakeImplProxy proxy
;
7646 TestSharedBitmapManager shared_bitmap_manager
;
7647 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7648 host_impl
.CreatePendingTree();
7649 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7650 scoped_ptr
<LayerImpl
> container
=
7651 LayerImpl::Create(host_impl
.active_tree(), 2);
7652 LayerImpl
* container_layer
= container
.get();
7653 scoped_ptr
<LayerImpl
> scroller
=
7654 LayerImpl::Create(host_impl
.active_tree(), 3);
7655 LayerImpl
* scroll_layer
= scroller
.get();
7656 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
7657 LayerImpl
* fixed_layer
= fixed
.get();
7659 container
->SetIsContainerForFixedPositionLayers(true);
7661 LayerPositionConstraint constraint
;
7662 constraint
.set_is_fixed_position(true);
7663 fixed
->SetPositionConstraint(constraint
);
7665 scroller
->SetScrollClipLayer(container
->id());
7667 gfx::Transform identity_transform
;
7668 gfx::Transform container_transform
;
7669 container_transform
.Translate3d(10.0, 20.0, 0.0);
7670 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
7672 SetLayerPropertiesForTesting(root
.get(),
7679 SetLayerPropertiesForTesting(container
.get(),
7680 container_transform
,
7686 SetLayerPropertiesForTesting(scroller
.get(),
7693 SetLayerPropertiesForTesting(fixed
.get(),
7701 scroller
->AddChild(fixed
.Pass());
7702 container
->AddChild(scroller
.Pass());
7703 root
->AddChild(container
.Pass());
7705 // Rounded to integers already.
7707 gfx::Vector2dF
scroll_delta(3.0, 5.0);
7708 scroll_layer
->SetScrollDelta(scroll_delta
);
7710 LayerImplList render_surface_layer_list
;
7711 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7712 root
.get(), root
->bounds(), &render_surface_layer_list
);
7713 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7715 EXPECT_TRANSFORMATION_MATRIX_EQ(
7716 container_layer
->draw_properties().screen_space_transform
,
7717 fixed_layer
->draw_properties().screen_space_transform
);
7719 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7721 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
7722 .screen_space_transform
.To2dTranslation(),
7723 container_offset
- scroll_delta
);
7726 // Scroll delta requiring rounding.
7728 gfx::Vector2dF
scroll_delta(4.1f
, 8.1f
);
7729 scroll_layer
->SetScrollDelta(scroll_delta
);
7731 gfx::Vector2dF
rounded_scroll_delta(4.f
, 8.f
);
7733 LayerImplList render_surface_layer_list
;
7734 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7735 root
.get(), root
->bounds(), &render_surface_layer_list
);
7736 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7738 EXPECT_TRANSFORMATION_MATRIX_EQ(
7739 container_layer
->draw_properties().screen_space_transform
,
7740 fixed_layer
->draw_properties().screen_space_transform
);
7742 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7744 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
7745 .screen_space_transform
.To2dTranslation(),
7746 container_offset
- rounded_scroll_delta
);
7749 // Scale is applied earlier in the tree.
7751 gfx::Transform scaled_container_transform
= container_transform
;
7752 scaled_container_transform
.Scale3d(3.0, 3.0, 1.0);
7753 container_layer
->SetTransform(scaled_container_transform
);
7755 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
7756 scroll_layer
->SetScrollDelta(scroll_delta
);
7758 LayerImplList render_surface_layer_list
;
7759 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7760 root
.get(), root
->bounds(), &render_surface_layer_list
);
7761 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7763 EXPECT_TRANSFORMATION_MATRIX_EQ(
7764 container_layer
->draw_properties().screen_space_transform
,
7765 fixed_layer
->draw_properties().screen_space_transform
);
7767 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7770 container_layer
->SetTransform(container_transform
);
7773 // Scale is applied on the scroll layer itself.
7775 gfx::Transform scale_transform
;
7776 scale_transform
.Scale3d(3.0, 3.0, 1.0);
7777 scroll_layer
->SetTransform(scale_transform
);
7779 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
7780 scroll_layer
->SetScrollDelta(scroll_delta
);
7782 LayerImplList render_surface_layer_list
;
7783 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7784 root
.get(), root
->bounds(), &render_surface_layer_list
);
7785 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7788 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7791 scroll_layer
->SetTransform(identity_transform
);
7795 class AnimationScaleFactorTrackingLayerImpl
: public LayerImpl
{
7797 static scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> Create(
7798 LayerTreeImpl
* tree_impl
,
7800 return make_scoped_ptr(
7801 new AnimationScaleFactorTrackingLayerImpl(tree_impl
, id
));
7804 ~AnimationScaleFactorTrackingLayerImpl() override
{}
7807 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl
* tree_impl
,
7809 : LayerImpl(tree_impl
, id
) {
7810 SetDrawsContent(true);
7814 TEST_F(LayerTreeHostCommonTest
, MaximumAnimationScaleFactor
) {
7815 FakeImplProxy proxy
;
7816 TestSharedBitmapManager shared_bitmap_manager
;
7817 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7818 gfx::Transform identity_matrix
;
7819 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_parent
=
7820 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 1);
7821 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> parent
=
7822 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 2);
7823 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> child
=
7824 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 3);
7825 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_child
=
7826 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 4);
7828 AnimationScaleFactorTrackingLayerImpl
* parent_raw
= parent
.get();
7829 AnimationScaleFactorTrackingLayerImpl
* child_raw
= child
.get();
7830 AnimationScaleFactorTrackingLayerImpl
* grand_child_raw
= grand_child
.get();
7832 child
->AddChild(grand_child
.Pass());
7833 parent
->AddChild(child
.Pass());
7834 grand_parent
->AddChild(parent
.Pass());
7836 SetLayerPropertiesForTesting(grand_parent
.get(),
7843 SetLayerPropertiesForTesting(parent_raw
,
7850 SetLayerPropertiesForTesting(child_raw
,
7857 SetLayerPropertiesForTesting(grand_child_raw
,
7865 ExecuteCalculateDrawProperties(grand_parent
.get());
7867 // No layers have animations.
7869 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7871 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7872 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7874 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7876 TransformOperations translation
;
7877 translation
.AppendTranslate(1.f
, 2.f
, 3.f
);
7879 AddAnimatedTransformToLayer(
7880 parent_raw
, 1.0, TransformOperations(), translation
);
7882 // No layers have scale-affecting animations.
7884 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7886 parent_raw
->draw_properties().maximum_animation_contents_scale
);
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 TransformOperations scale
;
7892 scale
.AppendScale(5.f
, 4.f
, 3.f
);
7894 AddAnimatedTransformToLayer(child_raw
, 1.0, TransformOperations(), scale
);
7895 ExecuteCalculateDrawProperties(grand_parent
.get());
7897 // Only |child| has a scale-affecting animation.
7899 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7901 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7902 EXPECT_EQ(5.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7904 5.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7906 AddAnimatedTransformToLayer(
7907 grand_parent
.get(), 1.0, TransformOperations(), scale
);
7908 ExecuteCalculateDrawProperties(grand_parent
.get());
7910 // |grand_parent| and |child| have scale-affecting animations.
7912 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7914 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7915 // We don't support combining animated scales from two nodes; 0.f means
7916 // that the maximum scale could not be computed.
7917 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7919 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7921 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
7922 ExecuteCalculateDrawProperties(grand_parent
.get());
7924 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
7926 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7928 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7929 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7931 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7933 grand_parent
->layer_animation_controller()->AbortAnimations(
7934 Animation::Transform
);
7935 parent_raw
->layer_animation_controller()->AbortAnimations(
7936 Animation::Transform
);
7937 child_raw
->layer_animation_controller()->AbortAnimations(
7938 Animation::Transform
);
7940 TransformOperations perspective
;
7941 perspective
.AppendPerspective(10.f
);
7943 AddAnimatedTransformToLayer(
7944 child_raw
, 1.0, TransformOperations(), perspective
);
7945 ExecuteCalculateDrawProperties(grand_parent
.get());
7947 // |child| has a scale-affecting animation but computing the maximum of this
7948 // animation is not supported.
7950 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7952 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7953 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7955 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7957 child_raw
->layer_animation_controller()->AbortAnimations(
7958 Animation::Transform
);
7960 gfx::Transform scale_matrix
;
7961 scale_matrix
.Scale(1.f
, 2.f
);
7962 grand_parent
->SetTransform(scale_matrix
);
7963 parent_raw
->SetTransform(scale_matrix
);
7964 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
7965 ExecuteCalculateDrawProperties(grand_parent
.get());
7967 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
7968 // animation with maximum scale 5.f.
7970 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7972 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7974 child_raw
->draw_properties().maximum_animation_contents_scale
);
7977 grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7979 gfx::Transform perspective_matrix
;
7980 perspective_matrix
.ApplyPerspectiveDepth(2.f
);
7981 child_raw
->SetTransform(perspective_matrix
);
7982 ExecuteCalculateDrawProperties(grand_parent
.get());
7984 // |child| has a transform that's neither a translation nor a scale.
7986 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7988 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7989 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7991 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7993 parent_raw
->SetTransform(perspective_matrix
);
7994 ExecuteCalculateDrawProperties(grand_parent
.get());
7996 // |parent| and |child| have transforms that are neither translations nor
7999 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8001 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8002 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8004 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8006 parent_raw
->SetTransform(identity_matrix
);
8007 child_raw
->SetTransform(identity_matrix
);
8008 grand_parent
->SetTransform(perspective_matrix
);
8010 ExecuteCalculateDrawProperties(grand_parent
.get());
8012 // |grand_parent| has a transform that's neither a translation nor a scale.
8014 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8016 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8017 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8019 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8022 static int membership_id(LayerImpl
* layer
) {
8023 return layer
->draw_properties().last_drawn_render_surface_layer_list_id
;
8026 static void GatherDrawnLayers(LayerImplList
* rsll
,
8027 std::set
<LayerImpl
*>* drawn_layers
) {
8028 for (LayerIterator
<LayerImpl
> it
= LayerIterator
<LayerImpl
>::Begin(rsll
),
8029 end
= LayerIterator
<LayerImpl
>::End(rsll
);
8032 LayerImpl
* layer
= *it
;
8033 if (it
.represents_itself())
8034 drawn_layers
->insert(layer
);
8036 if (!it
.represents_contributing_render_surface())
8039 if (layer
->mask_layer())
8040 drawn_layers
->insert(layer
->mask_layer());
8041 if (layer
->replica_layer() && layer
->replica_layer()->mask_layer())
8042 drawn_layers
->insert(layer
->replica_layer()->mask_layer());
8046 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceLayerListMembership
) {
8047 FakeImplProxy proxy
;
8048 TestSharedBitmapManager shared_bitmap_manager
;
8049 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
8050 gfx::Transform identity_matrix
;
8052 scoped_ptr
<LayerImpl
> grand_parent
=
8053 LayerImpl::Create(host_impl
.active_tree(), 1);
8054 scoped_ptr
<LayerImpl
> parent
= LayerImpl::Create(host_impl
.active_tree(), 3);
8055 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 5);
8056 scoped_ptr
<LayerImpl
> grand_child1
=
8057 LayerImpl::Create(host_impl
.active_tree(), 7);
8058 scoped_ptr
<LayerImpl
> grand_child2
=
8059 LayerImpl::Create(host_impl
.active_tree(), 9);
8061 LayerImpl
* grand_parent_raw
= grand_parent
.get();
8062 LayerImpl
* parent_raw
= parent
.get();
8063 LayerImpl
* child_raw
= child
.get();
8064 LayerImpl
* grand_child1_raw
= grand_child1
.get();
8065 LayerImpl
* grand_child2_raw
= grand_child2
.get();
8067 child
->AddChild(grand_child1
.Pass());
8068 child
->AddChild(grand_child2
.Pass());
8069 parent
->AddChild(child
.Pass());
8070 grand_parent
->AddChild(parent
.Pass());
8072 SetLayerPropertiesForTesting(grand_parent_raw
,
8079 SetLayerPropertiesForTesting(parent_raw
,
8086 SetLayerPropertiesForTesting(child_raw
,
8093 SetLayerPropertiesForTesting(grand_child1_raw
,
8100 SetLayerPropertiesForTesting(grand_child2_raw
,
8108 // Start with nothing being drawn.
8109 ExecuteCalculateDrawProperties(grand_parent_raw
);
8110 int member_id
= render_surface_layer_list_count();
8112 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8113 EXPECT_NE(member_id
, membership_id(parent_raw
));
8114 EXPECT_NE(member_id
, membership_id(child_raw
));
8115 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8116 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8118 std::set
<LayerImpl
*> expected
;
8119 std::set
<LayerImpl
*> actual
;
8120 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8121 EXPECT_EQ(expected
, actual
);
8123 // If we force render surface, but none of the layers are in the layer list,
8124 // then this layer should not appear in RSLL.
8125 grand_child1_raw
->SetForceRenderSurface(true);
8127 ExecuteCalculateDrawProperties(grand_parent_raw
);
8128 member_id
= render_surface_layer_list_count();
8130 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8131 EXPECT_NE(member_id
, membership_id(parent_raw
));
8132 EXPECT_NE(member_id
, membership_id(child_raw
));
8133 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8134 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8138 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8139 EXPECT_EQ(expected
, actual
);
8141 // However, if we say that this layer also draws content, it will appear in
8143 grand_child1_raw
->SetDrawsContent(true);
8145 ExecuteCalculateDrawProperties(grand_parent_raw
);
8146 member_id
= render_surface_layer_list_count();
8148 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8149 EXPECT_NE(member_id
, membership_id(parent_raw
));
8150 EXPECT_NE(member_id
, membership_id(child_raw
));
8151 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
8152 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8155 expected
.insert(grand_child1_raw
);
8158 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8159 EXPECT_EQ(expected
, actual
);
8161 // Now child is forced to have a render surface, and one if its children draws
8163 grand_child1_raw
->SetDrawsContent(false);
8164 grand_child1_raw
->SetForceRenderSurface(false);
8165 child_raw
->SetForceRenderSurface(true);
8166 grand_child2_raw
->SetDrawsContent(true);
8168 ExecuteCalculateDrawProperties(grand_parent_raw
);
8169 member_id
= render_surface_layer_list_count();
8171 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8172 EXPECT_NE(member_id
, membership_id(parent_raw
));
8173 EXPECT_NE(member_id
, membership_id(child_raw
));
8174 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8175 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8178 expected
.insert(grand_child2_raw
);
8181 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8182 EXPECT_EQ(expected
, actual
);
8184 // Add a mask layer to child.
8185 child_raw
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6).Pass());
8187 ExecuteCalculateDrawProperties(grand_parent_raw
);
8188 member_id
= render_surface_layer_list_count();
8190 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8191 EXPECT_NE(member_id
, membership_id(parent_raw
));
8192 EXPECT_NE(member_id
, membership_id(child_raw
));
8193 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8194 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8195 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8198 expected
.insert(grand_child2_raw
);
8199 expected
.insert(child_raw
->mask_layer());
8202 expected
.insert(grand_child2_raw
);
8203 expected
.insert(child_raw
->mask_layer());
8206 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8207 EXPECT_EQ(expected
, actual
);
8209 // Add replica mask layer.
8210 scoped_ptr
<LayerImpl
> replica_layer
=
8211 LayerImpl::Create(host_impl
.active_tree(), 20);
8212 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 21));
8213 child_raw
->SetReplicaLayer(replica_layer
.Pass());
8215 ExecuteCalculateDrawProperties(grand_parent_raw
);
8216 member_id
= render_surface_layer_list_count();
8218 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8219 EXPECT_NE(member_id
, membership_id(parent_raw
));
8220 EXPECT_NE(member_id
, membership_id(child_raw
));
8221 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8222 EXPECT_EQ(member_id
, membership_id(child_raw
->replica_layer()->mask_layer()));
8223 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8224 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8227 expected
.insert(grand_child2_raw
);
8228 expected
.insert(child_raw
->mask_layer());
8229 expected
.insert(child_raw
->replica_layer()->mask_layer());
8232 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8233 EXPECT_EQ(expected
, actual
);
8235 child_raw
->TakeReplicaLayer();
8237 // With nothing drawing, we should have no layers.
8238 grand_child2_raw
->SetDrawsContent(false);
8240 ExecuteCalculateDrawProperties(grand_parent_raw
);
8241 member_id
= render_surface_layer_list_count();
8243 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8244 EXPECT_NE(member_id
, membership_id(parent_raw
));
8245 EXPECT_NE(member_id
, membership_id(child_raw
));
8246 EXPECT_NE(member_id
, membership_id(child_raw
->mask_layer()));
8247 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8248 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8252 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8253 EXPECT_EQ(expected
, actual
);
8255 // Child itself draws means that we should have the child and the mask in the
8257 child_raw
->SetDrawsContent(true);
8259 ExecuteCalculateDrawProperties(grand_parent_raw
);
8260 member_id
= render_surface_layer_list_count();
8262 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8263 EXPECT_NE(member_id
, membership_id(parent_raw
));
8264 EXPECT_EQ(member_id
, membership_id(child_raw
));
8265 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8266 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8267 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8270 expected
.insert(child_raw
);
8271 expected
.insert(child_raw
->mask_layer());
8273 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8274 EXPECT_EQ(expected
, actual
);
8276 child_raw
->TakeMaskLayer();
8278 // Now everyone's a member!
8279 grand_parent_raw
->SetDrawsContent(true);
8280 parent_raw
->SetDrawsContent(true);
8281 child_raw
->SetDrawsContent(true);
8282 grand_child1_raw
->SetDrawsContent(true);
8283 grand_child2_raw
->SetDrawsContent(true);
8285 ExecuteCalculateDrawProperties(grand_parent_raw
);
8286 member_id
= render_surface_layer_list_count();
8288 EXPECT_EQ(member_id
, membership_id(grand_parent_raw
));
8289 EXPECT_EQ(member_id
, membership_id(parent_raw
));
8290 EXPECT_EQ(member_id
, membership_id(child_raw
));
8291 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
8292 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8295 expected
.insert(grand_parent_raw
);
8296 expected
.insert(parent_raw
);
8297 expected
.insert(child_raw
);
8298 expected
.insert(grand_child1_raw
);
8299 expected
.insert(grand_child2_raw
);
8302 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8303 EXPECT_EQ(expected
, actual
);
8306 TEST_F(LayerTreeHostCommonTest
, DrawPropertyScales
) {
8307 FakeImplProxy proxy
;
8308 TestSharedBitmapManager shared_bitmap_manager
;
8309 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
8311 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
8312 LayerImpl
* root_layer
= root
.get();
8313 scoped_ptr
<LayerImpl
> child1
= LayerImpl::Create(host_impl
.active_tree(), 2);
8314 LayerImpl
* child1_layer
= child1
.get();
8315 scoped_ptr
<LayerImpl
> child2
= LayerImpl::Create(host_impl
.active_tree(), 3);
8316 LayerImpl
* child2_layer
= child2
.get();
8318 root
->AddChild(child1
.Pass());
8319 root
->AddChild(child2
.Pass());
8321 gfx::Transform identity_matrix
, scale_transform_child1
,
8322 scale_transform_child2
;
8323 scale_transform_child1
.Scale(2, 3);
8324 scale_transform_child2
.Scale(4, 5);
8326 SetLayerPropertiesForTesting(root_layer
,
8333 SetLayerPropertiesForTesting(child1_layer
,
8334 scale_transform_child1
,
8341 child1_layer
->SetMaskLayer(
8342 LayerImpl::Create(host_impl
.active_tree(), 4).Pass());
8344 scoped_ptr
<LayerImpl
> replica_layer
=
8345 LayerImpl::Create(host_impl
.active_tree(), 5);
8346 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6));
8347 child1_layer
->SetReplicaLayer(replica_layer
.Pass());
8349 ExecuteCalculateDrawProperties(root_layer
);
8351 TransformOperations scale
;
8352 scale
.AppendScale(5.f
, 8.f
, 3.f
);
8354 AddAnimatedTransformToLayer(child2_layer
, 1.0, TransformOperations(), scale
);
8355 SetLayerPropertiesForTesting(child2_layer
,
8356 scale_transform_child2
,
8363 ExecuteCalculateDrawProperties(root_layer
);
8365 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().ideal_contents_scale
);
8366 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8368 3.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8369 EXPECT_FLOAT_EQ(3.f
,
8370 child1_layer
->replica_layer()
8373 .ideal_contents_scale
);
8374 EXPECT_FLOAT_EQ(5.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8377 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8379 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8380 EXPECT_FLOAT_EQ(0.f
,
8381 child1_layer
->mask_layer()
8383 .maximum_animation_contents_scale
);
8384 EXPECT_FLOAT_EQ(0.f
,
8385 child1_layer
->replica_layer()
8388 .maximum_animation_contents_scale
);
8390 8.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8392 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8393 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().page_scale_factor
);
8395 1.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8396 EXPECT_FLOAT_EQ(1.f
,
8397 child1_layer
->replica_layer()
8400 .page_scale_factor
);
8401 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().page_scale_factor
);
8403 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().device_scale_factor
);
8404 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().device_scale_factor
);
8406 1.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8407 EXPECT_FLOAT_EQ(1.f
,
8408 child1_layer
->replica_layer()
8411 .device_scale_factor
);
8412 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().device_scale_factor
);
8414 // Changing page-scale would affect ideal_contents_scale and
8415 // maximum_animation_contents_scale.
8417 float page_scale_factor
= 3.f
;
8418 float device_scale_factor
= 1.0f
;
8419 std::vector
<LayerImpl
*> render_surface_layer_list
;
8420 gfx::Size device_viewport_size
=
8421 gfx::Size(root_layer
->bounds().width() * device_scale_factor
,
8422 root_layer
->bounds().height() * device_scale_factor
);
8423 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
8424 root_layer
, device_viewport_size
, &render_surface_layer_list
);
8426 inputs
.page_scale_factor
= page_scale_factor
;
8427 inputs
.can_adjust_raster_scales
= true;
8428 inputs
.page_scale_application_layer
= root_layer
;
8429 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8431 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().ideal_contents_scale
);
8432 EXPECT_FLOAT_EQ(9.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8434 9.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8435 EXPECT_FLOAT_EQ(9.f
,
8436 child1_layer
->replica_layer()
8439 .ideal_contents_scale
);
8440 EXPECT_FLOAT_EQ(15.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8443 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8445 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8446 EXPECT_FLOAT_EQ(0.f
,
8447 child1_layer
->mask_layer()
8449 .maximum_animation_contents_scale
);
8450 EXPECT_FLOAT_EQ(0.f
,
8451 child1_layer
->replica_layer()
8454 .maximum_animation_contents_scale
);
8456 24.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8458 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8459 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().page_scale_factor
);
8461 3.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8462 EXPECT_FLOAT_EQ(3.f
,
8463 child1_layer
->replica_layer()
8466 .page_scale_factor
);
8467 EXPECT_FLOAT_EQ(3.f
, child2_layer
->draw_properties().page_scale_factor
);
8469 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().device_scale_factor
);
8470 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().device_scale_factor
);
8472 1.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8473 EXPECT_FLOAT_EQ(1.f
,
8474 child1_layer
->replica_layer()
8477 .device_scale_factor
);
8478 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().device_scale_factor
);
8480 // Changing device-scale would affect ideal_contents_scale and
8481 // maximum_animation_contents_scale.
8483 device_scale_factor
= 4.0f
;
8484 inputs
.device_scale_factor
= device_scale_factor
;
8485 inputs
.can_adjust_raster_scales
= true;
8486 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8488 EXPECT_FLOAT_EQ(4.f
, root_layer
->draw_properties().ideal_contents_scale
);
8489 EXPECT_FLOAT_EQ(36.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8491 36.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8492 EXPECT_FLOAT_EQ(36.f
,
8493 child1_layer
->replica_layer()
8496 .ideal_contents_scale
);
8497 EXPECT_FLOAT_EQ(60.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8500 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8502 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8503 EXPECT_FLOAT_EQ(0.f
,
8504 child1_layer
->mask_layer()
8506 .maximum_animation_contents_scale
);
8507 EXPECT_FLOAT_EQ(0.f
,
8508 child1_layer
->replica_layer()
8511 .maximum_animation_contents_scale
);
8513 96.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8515 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8516 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().page_scale_factor
);
8518 3.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8519 EXPECT_FLOAT_EQ(3.f
,
8520 child1_layer
->replica_layer()
8523 .page_scale_factor
);
8524 EXPECT_FLOAT_EQ(3.f
, child2_layer
->draw_properties().page_scale_factor
);
8526 EXPECT_FLOAT_EQ(4.f
, root_layer
->draw_properties().device_scale_factor
);
8527 EXPECT_FLOAT_EQ(4.f
, child1_layer
->draw_properties().device_scale_factor
);
8529 4.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8530 EXPECT_FLOAT_EQ(4.f
,
8531 child1_layer
->replica_layer()
8534 .device_scale_factor
);
8535 EXPECT_FLOAT_EQ(4.f
, child2_layer
->draw_properties().device_scale_factor
);
8538 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInChildRenderSurface
) {
8539 scoped_refptr
<Layer
> root
= Layer::Create();
8540 SetLayerPropertiesForTesting(root
.get(),
8544 gfx::Size(768 / 2, 3000),
8547 root
->SetIsDrawable(true);
8549 scoped_refptr
<Layer
> clip
= Layer::Create();
8550 SetLayerPropertiesForTesting(clip
.get(),
8554 gfx::Size(768 / 2, 10000),
8557 clip
->SetMasksToBounds(true);
8559 scoped_refptr
<Layer
> content
= Layer::Create();
8560 SetLayerPropertiesForTesting(content
.get(),
8564 gfx::Size(768 / 2, 10000),
8567 content
->SetIsDrawable(true);
8568 content
->SetForceRenderSurface(true);
8570 root
->AddChild(clip
);
8571 clip
->AddChild(content
);
8573 FakeLayerTreeHostClient
client(FakeLayerTreeHostClient::DIRECT_3D
);
8574 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(&client
);
8575 host
->SetRootLayer(root
);
8577 gfx::Size
device_viewport_size(768, 582);
8578 RenderSurfaceLayerList render_surface_layer_list
;
8579 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
8580 host
->root_layer(), device_viewport_size
, &render_surface_layer_list
);
8581 inputs
.device_scale_factor
= 2.f
;
8582 inputs
.page_scale_factor
= 1.f
;
8583 inputs
.page_scale_application_layer
= NULL
;
8584 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8586 // Layers in the root render surface have their visible content rect clipped
8588 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root
->visible_content_rect());
8590 // Layers drawing to a child render surface should still have their visible
8591 // content rect clipped by the viewport.
8592 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content
->visible_content_rect());