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/keyframed_animation_curve.h"
11 #include "cc/animation/layer_animation_controller.h"
12 #include "cc/animation/transform_operations.h"
13 #include "cc/base/math_util.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_content_layer_client.h"
25 #include "cc/test/fake_impl_proxy.h"
26 #include "cc/test/fake_layer_tree_host.h"
27 #include "cc/test/fake_layer_tree_host_impl.h"
28 #include "cc/test/fake_output_surface.h"
29 #include "cc/test/fake_picture_layer.h"
30 #include "cc/test/fake_picture_layer_impl.h"
31 #include "cc/test/geometry_test_utils.h"
32 #include "cc/test/layer_tree_host_common_test.h"
33 #include "cc/test/test_task_graph_runner.h"
34 #include "cc/trees/layer_tree_impl.h"
35 #include "cc/trees/proxy.h"
36 #include "cc/trees/single_thread_proxy.h"
37 #include "testing/gmock/include/gmock/gmock.h"
38 #include "testing/gtest/include/gtest/gtest.h"
39 #include "ui/gfx/geometry/quad_f.h"
40 #include "ui/gfx/geometry/vector2d_conversions.h"
41 #include "ui/gfx/transform.h"
46 class LayerWithForcedDrawsContent
: public Layer
{
48 explicit LayerWithForcedDrawsContent(const LayerSettings
& settings
)
51 bool DrawsContent() const override
;
54 ~LayerWithForcedDrawsContent() override
{}
57 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
59 class MockContentLayerClient
: public ContentLayerClient
{
61 MockContentLayerClient() {}
62 ~MockContentLayerClient() override
{}
63 void PaintContents(SkCanvas
* canvas
,
64 const gfx::Rect
& clip
,
65 PaintingControlSetting picture_control
) override
{}
66 scoped_refptr
<DisplayItemList
> PaintContentsToDisplayList(
67 const gfx::Rect
& clip
,
68 PaintingControlSetting picture_control
) override
{
72 bool FillsBoundsCompletely() const override
{ return false; }
73 size_t GetApproximateUnsharedMemoryUsage() const override
{ return 0; }
76 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
78 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
79 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
82 #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
84 EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \
87 class LayerTreeSettingsScaleContent
: public LayerTreeSettings
{
89 LayerTreeSettingsScaleContent() {
90 layer_transforms_should_scale_layer_contents
= true;
94 class LayerTreeHostCommonScalingTest
: public LayerTreeHostCommonTest
{
96 LayerTreeHostCommonScalingTest()
97 : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {}
100 TEST_F(LayerTreeHostCommonTest
, TransformsForNoOpLayer
) {
101 // Sanity check: For layers positioned at zero, with zero size,
102 // and with identity transforms, then the draw transform,
103 // screen space transform, and the hierarchy passed on to children
104 // layers should also be identity transforms.
106 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
107 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
108 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
109 parent
->AddChild(child
);
110 child
->AddChild(grand_child
);
112 host()->SetRootLayer(parent
);
114 gfx::Transform identity_matrix
;
115 SetLayerPropertiesForTesting(parent
.get(),
122 SetLayerPropertiesForTesting(child
.get(),
129 SetLayerPropertiesForTesting(grand_child
.get(),
137 ExecuteCalculateDrawProperties(parent
.get());
139 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
140 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
141 child
->screen_space_transform());
142 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
143 grand_child
->draw_transform());
144 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
145 grand_child
->screen_space_transform());
148 TEST_F(LayerTreeHostCommonTest
, DoNotSkipLayersWithHandlers
) {
149 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
150 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
151 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
152 parent
->AddChild(child
);
153 child
->AddChild(grand_child
);
155 host()->SetRootLayer(parent
);
157 gfx::Transform identity_matrix
;
158 SetLayerPropertiesForTesting(parent
.get(),
165 SetLayerPropertiesForTesting(child
.get(),
172 // This would have previously caused us to skip our subtree, but this would be
173 // wrong; we need up-to-date draw properties to do hit testing on the layers
175 child
->SetOpacity(0.f
);
176 SetLayerPropertiesForTesting(grand_child
.get(),
183 grand_child
->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
185 ExecuteCalculateDrawProperties(parent
.get());
187 // Check that we've computed draw properties for the subtree rooted at
189 EXPECT_FALSE(child
->draw_transform().IsIdentity());
190 EXPECT_FALSE(grand_child
->draw_transform().IsIdentity());
193 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleLayer
) {
194 gfx::Transform identity_matrix
;
195 scoped_refptr
<Layer
> layer
= Layer::Create(layer_settings());
197 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
198 SetLayerPropertiesForTesting(root
.get(),
205 root
->AddChild(layer
);
207 host()->SetRootLayer(root
);
209 // Case 2: Setting the bounds of the layer should not affect either the draw
210 // transform or the screenspace transform.
211 gfx::Transform translation_to_center
;
212 translation_to_center
.Translate(5.0, 6.0);
213 SetLayerPropertiesForTesting(layer
.get(),
220 ExecuteCalculateDrawProperties(root
.get());
221 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
222 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
223 layer
->screen_space_transform());
225 // Case 3: The anchor point by itself (without a layer transform) should have
226 // no effect on the transforms.
227 SetLayerPropertiesForTesting(layer
.get(),
229 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
234 ExecuteCalculateDrawProperties(root
.get());
235 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
236 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
237 layer
->screen_space_transform());
239 // Case 4: A change in actual position affects both the draw transform and
240 // screen space transform.
241 gfx::Transform position_transform
;
242 position_transform
.Translate(0.f
, 1.2f
);
243 SetLayerPropertiesForTesting(layer
.get(),
245 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
246 gfx::PointF(0.f
, 1.2f
),
250 ExecuteCalculateDrawProperties(root
.get());
251 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
, layer
->draw_transform());
252 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
,
253 layer
->screen_space_transform());
255 // Case 5: In the correct sequence of transforms, the layer transform should
256 // pre-multiply the translation_to_center. This is easily tested by using a
257 // scale transform, because scale and translation are not commutative.
258 gfx::Transform layer_transform
;
259 layer_transform
.Scale3d(2.0, 2.0, 1.0);
260 SetLayerPropertiesForTesting(layer
.get(),
267 ExecuteCalculateDrawProperties(root
.get());
268 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
, layer
->draw_transform());
269 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
,
270 layer
->screen_space_transform());
272 // Case 6: The layer transform should occur with respect to the anchor point.
273 gfx::Transform translation_to_anchor
;
274 translation_to_anchor
.Translate(5.0, 0.0);
275 gfx::Transform expected_result
=
276 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
277 SetLayerPropertiesForTesting(layer
.get(),
279 gfx::Point3F(5.0f
, 0.f
, 0.f
),
284 ExecuteCalculateDrawProperties(root
.get());
285 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
286 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
287 layer
->screen_space_transform());
289 // Case 7: Verify that position pre-multiplies the layer transform. The
290 // current implementation of CalculateDrawProperties does this implicitly, but
291 // it is still worth testing to detect accidental regressions.
292 expected_result
= position_transform
* translation_to_anchor
*
293 layer_transform
* Inverse(translation_to_anchor
);
294 SetLayerPropertiesForTesting(layer
.get(),
296 gfx::Point3F(5.0f
, 0.f
, 0.f
),
297 gfx::PointF(0.f
, 1.2f
),
301 ExecuteCalculateDrawProperties(root
.get());
302 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
303 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
304 layer
->screen_space_transform());
307 TEST_F(LayerTreeHostCommonTest
, TransformsAboutScrollOffset
) {
308 const gfx::ScrollOffset
kScrollOffset(50, 100);
309 const gfx::Vector2dF
kScrollDelta(2.34f
, 5.67f
);
310 const gfx::Vector2d
kMaxScrollOffset(200, 200);
311 const gfx::PointF
kScrollLayerPosition(-kScrollOffset
.x(),
313 const float kPageScale
= 0.888f
;
314 const float kDeviceScale
= 1.666f
;
317 TestSharedBitmapManager shared_bitmap_manager
;
318 TestTaskGraphRunner task_graph_runner
;
319 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
322 gfx::Transform identity_matrix
;
323 scoped_ptr
<LayerImpl
> sublayer_scoped_ptr(
324 LayerImpl::Create(host_impl
.active_tree(), 1));
325 LayerImpl
* sublayer
= sublayer_scoped_ptr
.get();
326 SetLayerPropertiesForTesting(sublayer
, identity_matrix
, gfx::Point3F(),
327 gfx::PointF(), gfx::Size(500, 500), true, false,
330 scoped_ptr
<LayerImpl
> scroll_layer_scoped_ptr(
331 LayerImpl::Create(host_impl
.active_tree(), 2));
332 LayerImpl
* scroll_layer
= scroll_layer_scoped_ptr
.get();
333 SetLayerPropertiesForTesting(scroll_layer
, identity_matrix
, gfx::Point3F(),
334 gfx::PointF(), gfx::Size(10, 20), true, false,
336 scoped_ptr
<LayerImpl
> clip_layer_scoped_ptr(
337 LayerImpl::Create(host_impl
.active_tree(), 4));
338 LayerImpl
* clip_layer
= clip_layer_scoped_ptr
.get();
340 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
341 clip_layer
->SetBounds(
342 gfx::Size(scroll_layer
->bounds().width() + kMaxScrollOffset
.x(),
343 scroll_layer
->bounds().height() + kMaxScrollOffset
.y()));
344 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
345 scroll_layer
->SetScrollDelta(kScrollDelta
);
346 gfx::Transform impl_transform
;
347 scroll_layer
->AddChild(sublayer_scoped_ptr
.Pass());
348 LayerImpl
* scroll_layer_raw_ptr
= scroll_layer_scoped_ptr
.get();
349 clip_layer
->AddChild(scroll_layer_scoped_ptr
.Pass());
350 scroll_layer_raw_ptr
->PushScrollOffsetFromMainThread(kScrollOffset
);
352 scoped_ptr
<LayerImpl
> root(LayerImpl::Create(host_impl
.active_tree(), 3));
353 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
354 gfx::PointF(), gfx::Size(3, 4), true, false,
356 root
->AddChild(clip_layer_scoped_ptr
.Pass());
357 root
->SetHasRenderSurface(true);
359 ExecuteCalculateDrawProperties(
360 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
361 gfx::Transform expected_transform
= identity_matrix
;
362 gfx::PointF sub_layer_screen_position
= kScrollLayerPosition
- kScrollDelta
;
363 expected_transform
.Translate(MathUtil::Round(sub_layer_screen_position
.x() *
364 kPageScale
* kDeviceScale
),
365 MathUtil::Round(sub_layer_screen_position
.y() *
366 kPageScale
* kDeviceScale
));
367 expected_transform
.Scale(kPageScale
* kDeviceScale
,
368 kPageScale
* kDeviceScale
);
369 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
370 sublayer
->draw_transform());
371 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
372 sublayer
->screen_space_transform());
374 gfx::Transform arbitrary_translate
;
375 const float kTranslateX
= 10.6f
;
376 const float kTranslateY
= 20.6f
;
377 arbitrary_translate
.Translate(kTranslateX
, kTranslateY
);
378 SetLayerPropertiesForTesting(scroll_layer
, arbitrary_translate
,
379 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
381 ExecuteCalculateDrawProperties(
382 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
383 expected_transform
.MakeIdentity();
384 expected_transform
.Translate(
385 MathUtil::Round(kTranslateX
* kPageScale
* kDeviceScale
+
386 sub_layer_screen_position
.x() * kPageScale
*
388 MathUtil::Round(kTranslateY
* kPageScale
* kDeviceScale
+
389 sub_layer_screen_position
.y() * kPageScale
*
391 expected_transform
.Scale(kPageScale
* kDeviceScale
,
392 kPageScale
* kDeviceScale
);
393 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
394 sublayer
->draw_transform());
397 TEST_F(LayerTreeHostCommonTest
, TransformsForSimpleHierarchy
) {
398 gfx::Transform identity_matrix
;
399 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
400 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
401 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
402 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
403 root
->AddChild(parent
);
404 parent
->AddChild(child
);
405 child
->AddChild(grand_child
);
407 host()->SetRootLayer(root
);
409 // One-time setup of root layer
410 SetLayerPropertiesForTesting(root
.get(),
418 // Case 1: parent's anchor point should not affect child or grand_child.
419 SetLayerPropertiesForTesting(parent
.get(),
421 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
426 SetLayerPropertiesForTesting(child
.get(),
433 SetLayerPropertiesForTesting(grand_child
.get(),
440 ExecuteCalculateDrawProperties(root
.get());
441 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
442 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
443 child
->screen_space_transform());
444 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
445 grand_child
->draw_transform());
446 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
447 grand_child
->screen_space_transform());
449 // Case 2: parent's position affects child and grand_child.
450 gfx::Transform parent_position_transform
;
451 parent_position_transform
.Translate(0.f
, 1.2f
);
452 SetLayerPropertiesForTesting(parent
.get(),
454 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
455 gfx::PointF(0.f
, 1.2f
),
459 SetLayerPropertiesForTesting(child
.get(),
466 SetLayerPropertiesForTesting(grand_child
.get(),
473 ExecuteCalculateDrawProperties(root
.get());
474 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
475 child
->draw_transform());
476 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
477 child
->screen_space_transform());
478 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
479 grand_child
->draw_transform());
480 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
481 grand_child
->screen_space_transform());
483 // Case 3: parent's local transform affects child and grandchild
484 gfx::Transform parent_layer_transform
;
485 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
486 gfx::Transform parent_translation_to_anchor
;
487 parent_translation_to_anchor
.Translate(2.5, 3.0);
488 gfx::Transform parent_composite_transform
=
489 parent_translation_to_anchor
* parent_layer_transform
*
490 Inverse(parent_translation_to_anchor
);
491 SetLayerPropertiesForTesting(parent
.get(),
492 parent_layer_transform
,
493 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
498 SetLayerPropertiesForTesting(child
.get(),
505 SetLayerPropertiesForTesting(grand_child
.get(),
512 ExecuteCalculateDrawProperties(root
.get());
513 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
514 child
->draw_transform());
515 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
516 child
->screen_space_transform());
517 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
518 grand_child
->draw_transform());
519 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
520 grand_child
->screen_space_transform());
523 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleRenderSurface
) {
524 LayerImpl
* root
= root_layer();
525 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
526 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
527 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
528 grand_child
->SetDrawsContent(true);
530 gfx::Transform identity_matrix
;
531 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
532 gfx::PointF(), gfx::Size(1, 2), true, false,
535 // Child is set up so that a new render surface should be created.
536 child
->SetOpacity(0.5f
);
538 gfx::Transform parent_layer_transform
;
539 parent_layer_transform
.Scale3d(1.f
, 0.9f
, 1.f
);
540 gfx::Transform parent_translation_to_anchor
;
541 parent_translation_to_anchor
.Translate(25.0, 30.0);
543 gfx::Transform parent_composite_transform
=
544 parent_translation_to_anchor
* parent_layer_transform
*
545 Inverse(parent_translation_to_anchor
);
546 gfx::Vector2dF parent_composite_scale
=
547 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
549 gfx::Transform surface_sublayer_transform
;
550 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
551 parent_composite_scale
.y());
552 gfx::Transform surface_sublayer_composite_transform
=
553 parent_composite_transform
* Inverse(surface_sublayer_transform
);
555 SetLayerPropertiesForTesting(parent
, parent_layer_transform
,
556 gfx::Point3F(25.0f
, 30.0f
, 0.f
), gfx::PointF(),
557 gfx::Size(100, 120), true, false, false);
558 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
559 gfx::PointF(), gfx::Size(16, 18), true, false,
561 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
562 gfx::PointF(), gfx::Size(8, 10), true, false,
564 ExecuteCalculateDrawProperties(root
);
566 // Render surface should have been created now.
567 ASSERT_TRUE(child
->render_surface());
568 ASSERT_EQ(child
, child
->render_target());
570 // The child layer's draw transform should refer to its new render surface.
571 // The screen-space transform, however, should still refer to the root.
572 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform
,
573 child
->draw_transform());
574 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
575 child
->screen_space_transform());
577 // Because the grand_child is the only drawable content, the child's render
578 // surface will tighten its bounds to the grand_child. The scale at which the
579 // surface's subtree is drawn must be removed from the composite transform.
580 EXPECT_TRANSFORMATION_MATRIX_EQ(
581 surface_sublayer_composite_transform
,
582 child
->render_target()->render_surface()->draw_transform());
584 // The screen space is the same as the target since the child surface draws
586 EXPECT_TRANSFORMATION_MATRIX_EQ(
587 surface_sublayer_composite_transform
,
588 child
->render_target()->render_surface()->screen_space_transform());
591 TEST_F(LayerTreeHostCommonTest
, TransformsForReplica
) {
592 LayerImpl
* root
= root_layer();
593 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
594 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
595 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
596 grand_child
->SetDrawsContent(true);
597 scoped_ptr
<LayerImpl
> child_replica
=
598 LayerImpl::Create(host_impl()->active_tree(), 100);
600 // One-time setup of root layer
601 gfx::Transform identity_matrix
;
602 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
603 gfx::PointF(), gfx::Size(1, 2), true, false,
606 // Child is set up so that a new render surface should be created.
607 child
->SetOpacity(0.5f
);
609 gfx::Transform parent_layer_transform
;
610 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
611 gfx::Transform parent_translation_to_anchor
;
612 parent_translation_to_anchor
.Translate(2.5, 3.0);
613 gfx::Transform parent_composite_transform
=
614 parent_translation_to_anchor
* parent_layer_transform
*
615 Inverse(parent_translation_to_anchor
);
616 gfx::Transform replica_layer_transform
;
617 replica_layer_transform
.Scale3d(3.0, 3.0, 1.0);
618 gfx::Vector2dF parent_composite_scale
=
619 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
621 gfx::Transform surface_sublayer_transform
;
622 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
623 parent_composite_scale
.y());
624 gfx::Transform replica_composite_transform
=
625 parent_composite_transform
* replica_layer_transform
*
626 Inverse(surface_sublayer_transform
);
627 child_replica
->SetDrawsContent(true);
628 // Child's render surface should not exist yet.
629 ASSERT_FALSE(child
->render_surface());
631 SetLayerPropertiesForTesting(parent
, parent_layer_transform
,
632 gfx::Point3F(2.5f
, 3.0f
, 0.f
), gfx::PointF(),
633 gfx::Size(10, 12), true, false, false);
634 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
635 gfx::PointF(), gfx::Size(16, 18), true, false,
637 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
638 gfx::PointF(-0.5f
, -0.5f
), gfx::Size(1, 1), true,
640 SetLayerPropertiesForTesting(child_replica
.get(), replica_layer_transform
,
641 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
643 child
->SetReplicaLayer(child_replica
.Pass());
645 ExecuteCalculateDrawProperties(root
);
647 // Render surface should have been created now.
648 ASSERT_TRUE(child
->render_surface());
649 ASSERT_EQ(child
, child
->render_target());
651 EXPECT_TRANSFORMATION_MATRIX_EQ(
652 replica_composite_transform
,
653 child
->render_target()->render_surface()->replica_draw_transform());
654 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform
,
655 child
->render_target()
657 ->replica_screen_space_transform());
660 TEST_F(LayerTreeHostCommonTest
, TransformsForRenderSurfaceHierarchy
) {
661 // This test creates a more complex tree and verifies it all at once. This
662 // covers the following cases:
663 // - layers that are described w.r.t. a render surface: should have draw
664 // transforms described w.r.t. that surface
665 // - A render surface described w.r.t. an ancestor render surface: should
666 // have a draw transform described w.r.t. that ancestor surface
667 // - Replicas of a render surface are described w.r.t. the replica's
668 // transform around its anchor, along with the surface itself.
669 // - Sanity check on recursion: verify transforms of layers described w.r.t.
670 // a render surface that is described w.r.t. an ancestor render surface.
671 // - verifying that each layer has a reference to the correct render surface
672 // and render target values.
674 LayerImpl
* root
= root_layer();
675 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
676 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(parent
);
677 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(render_surface1
);
678 LayerImpl
* child_of_root
= AddChild
<LayerImpl
>(parent
);
679 LayerImpl
* child_of_rs1
= AddChild
<LayerImpl
>(render_surface1
);
680 LayerImpl
* child_of_rs2
= AddChild
<LayerImpl
>(render_surface2
);
681 LayerImpl
* grand_child_of_root
= AddChild
<LayerImpl
>(child_of_root
);
682 LayerImpl
* grand_child_of_rs1
= AddChild
<LayerImpl
>(child_of_rs1
);
683 grand_child_of_rs1
->SetDrawsContent(true);
684 LayerImpl
* grand_child_of_rs2
= AddChild
<LayerImpl
>(child_of_rs2
);
685 grand_child_of_rs2
->SetDrawsContent(true);
687 scoped_ptr
<LayerImpl
> replica_of_rs1
=
688 LayerImpl::Create(host_impl()->active_tree(), 101);
689 scoped_ptr
<LayerImpl
> replica_of_rs2
=
690 LayerImpl::Create(host_impl()->active_tree(), 102);
692 // In combination with descendant draws content, opacity != 1 forces the layer
693 // to have a new render surface.
694 render_surface1
->SetOpacity(0.5f
);
695 render_surface2
->SetOpacity(0.33f
);
697 // One-time setup of root layer
698 gfx::Transform identity_matrix
;
699 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
700 gfx::PointF(), gfx::Size(1, 2), true, false,
703 // All layers in the tree are initialized with an anchor at .25 and a size of
704 // (10,10). matrix "A" is the composite layer transform used in all layers,
705 // Matrix "R" is the composite replica transform used in all replica layers.
706 gfx::Transform translation_to_anchor
;
707 translation_to_anchor
.Translate(2.5, 0.0);
708 gfx::Transform layer_transform
;
709 layer_transform
.Translate(1.0, 1.0);
710 gfx::Transform replica_layer_transform
;
711 replica_layer_transform
.Scale3d(-2.0, 5.0, 1.0);
714 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
715 gfx::Transform R
= A
* translation_to_anchor
* replica_layer_transform
*
716 Inverse(translation_to_anchor
);
718 gfx::Vector2dF surface1_parent_transform_scale
=
719 MathUtil::ComputeTransform2dScaleComponents(A
, 1.f
);
720 gfx::Transform surface1_sublayer_transform
;
721 surface1_sublayer_transform
.Scale(surface1_parent_transform_scale
.x(),
722 surface1_parent_transform_scale
.y());
724 // SS1 = transform given to the subtree of render_surface1
725 gfx::Transform SS1
= surface1_sublayer_transform
;
726 // S1 = transform to move from render_surface1 pixels to the layer space of
728 gfx::Transform S1
= Inverse(surface1_sublayer_transform
);
730 gfx::Vector2dF surface2_parent_transform_scale
=
731 MathUtil::ComputeTransform2dScaleComponents(SS1
* A
, 1.f
);
732 gfx::Transform surface2_sublayer_transform
;
733 surface2_sublayer_transform
.Scale(surface2_parent_transform_scale
.x(),
734 surface2_parent_transform_scale
.y());
736 // SS2 = transform given to the subtree of render_surface2
737 gfx::Transform SS2
= surface2_sublayer_transform
;
738 // S2 = transform to move from render_surface2 pixels to the layer space of
740 gfx::Transform S2
= Inverse(surface2_sublayer_transform
);
742 SetLayerPropertiesForTesting(parent
, layer_transform
,
743 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
744 gfx::Size(10, 10), true, false, false);
745 SetLayerPropertiesForTesting(render_surface1
, layer_transform
,
746 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
747 gfx::Size(10, 10), true, false, true);
748 SetLayerPropertiesForTesting(render_surface2
, layer_transform
,
749 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
750 gfx::Size(10, 10), true, false, true);
751 SetLayerPropertiesForTesting(child_of_root
, layer_transform
,
752 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
753 gfx::Size(10, 10), true, false, false);
754 SetLayerPropertiesForTesting(child_of_rs1
, layer_transform
,
755 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
756 gfx::Size(10, 10), true, false, false);
757 SetLayerPropertiesForTesting(child_of_rs2
, layer_transform
,
758 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
759 gfx::Size(10, 10), true, false, false);
760 SetLayerPropertiesForTesting(grand_child_of_root
, layer_transform
,
761 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
762 gfx::Size(10, 10), true, false, false);
763 SetLayerPropertiesForTesting(grand_child_of_rs1
, layer_transform
,
764 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
765 gfx::Size(10, 10), true, false, false);
766 SetLayerPropertiesForTesting(grand_child_of_rs2
, layer_transform
,
767 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
768 gfx::Size(10, 10), true, false, false);
769 SetLayerPropertiesForTesting(replica_of_rs1
.get(), replica_layer_transform
,
770 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
771 gfx::Size(), true, false, false);
772 SetLayerPropertiesForTesting(replica_of_rs2
.get(), replica_layer_transform
,
773 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
774 gfx::Size(), true, false, false);
776 render_surface1
->SetReplicaLayer(replica_of_rs1
.Pass());
777 render_surface2
->SetReplicaLayer(replica_of_rs2
.Pass());
778 ExecuteCalculateDrawProperties(root
);
780 // Only layers that are associated with render surfaces should have an actual
781 // RenderSurface() value.
782 ASSERT_TRUE(root
->render_surface());
783 ASSERT_FALSE(child_of_root
->render_surface());
784 ASSERT_FALSE(grand_child_of_root
->render_surface());
786 ASSERT_TRUE(render_surface1
->render_surface());
787 ASSERT_FALSE(child_of_rs1
->render_surface());
788 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
790 ASSERT_TRUE(render_surface2
->render_surface());
791 ASSERT_FALSE(child_of_rs2
->render_surface());
792 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
794 // Verify all render target accessors
795 EXPECT_EQ(root
, parent
->render_target());
796 EXPECT_EQ(root
, child_of_root
->render_target());
797 EXPECT_EQ(root
, grand_child_of_root
->render_target());
799 EXPECT_EQ(render_surface1
, render_surface1
->render_target());
800 EXPECT_EQ(render_surface1
, child_of_rs1
->render_target());
801 EXPECT_EQ(render_surface1
, grand_child_of_rs1
->render_target());
803 EXPECT_EQ(render_surface2
, render_surface2
->render_target());
804 EXPECT_EQ(render_surface2
, child_of_rs2
->render_target());
805 EXPECT_EQ(render_surface2
, grand_child_of_rs2
->render_target());
807 // Verify layer draw transforms note that draw transforms are described with
808 // respect to the nearest ancestor render surface but screen space transforms
809 // are described with respect to the root.
810 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->draw_transform());
811 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
, child_of_root
->draw_transform());
812 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
813 grand_child_of_root
->draw_transform());
815 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
, render_surface1
->draw_transform());
816 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
, child_of_rs1
->draw_transform());
817 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
* A
,
818 grand_child_of_rs1
->draw_transform());
820 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
, render_surface2
->draw_transform());
821 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
, child_of_rs2
->draw_transform());
822 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
* A
,
823 grand_child_of_rs2
->draw_transform());
825 // Verify layer screen-space transforms
827 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->screen_space_transform());
828 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
829 child_of_root
->screen_space_transform());
830 EXPECT_TRANSFORMATION_MATRIX_EQ(
831 A
* A
* A
, grand_child_of_root
->screen_space_transform());
833 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
834 render_surface1
->screen_space_transform());
835 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
836 child_of_rs1
->screen_space_transform());
837 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
838 grand_child_of_rs1
->screen_space_transform());
840 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
841 render_surface2
->screen_space_transform());
842 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
843 child_of_rs2
->screen_space_transform());
844 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
* A
,
845 grand_child_of_rs2
->screen_space_transform());
847 // Verify render surface transforms.
849 // Draw transform of render surface 1 is described with respect to root.
850 EXPECT_TRANSFORMATION_MATRIX_EQ(
851 A
* A
* S1
, render_surface1
->render_surface()->draw_transform());
852 EXPECT_TRANSFORMATION_MATRIX_EQ(
853 A
* R
* S1
, render_surface1
->render_surface()->replica_draw_transform());
854 EXPECT_TRANSFORMATION_MATRIX_EQ(
855 A
* A
* S1
, render_surface1
->render_surface()->screen_space_transform());
856 EXPECT_TRANSFORMATION_MATRIX_EQ(
858 render_surface1
->render_surface()->replica_screen_space_transform());
859 // Draw transform of render surface 2 is described with respect to render
861 EXPECT_TRANSFORMATION_MATRIX_EQ(
862 SS1
* A
* S2
, render_surface2
->render_surface()->draw_transform());
863 EXPECT_TRANSFORMATION_MATRIX_EQ(
865 render_surface2
->render_surface()->replica_draw_transform());
866 EXPECT_TRANSFORMATION_MATRIX_EQ(
868 render_surface2
->render_surface()->screen_space_transform());
869 EXPECT_TRANSFORMATION_MATRIX_EQ(
871 render_surface2
->render_surface()->replica_screen_space_transform());
873 // Sanity check. If these fail there is probably a bug in the test itself. It
874 // is expected that we correctly set up transforms so that the y-component of
875 // the screen-space transform encodes the "depth" of the layer in the tree.
876 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
878 child_of_root
->screen_space_transform().matrix().get(1, 3));
880 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
883 render_surface1
->screen_space_transform().matrix().get(1, 3));
885 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
887 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
890 render_surface2
->screen_space_transform().matrix().get(1, 3));
892 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
894 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
897 TEST_F(LayerTreeHostCommonTest
, TransformsForFlatteningLayer
) {
898 // For layers that flatten their subtree, there should be an orthographic
899 // projection (for x and y values) in the middle of the transform sequence.
900 // Note that the way the code is currently implemented, it is not expected to
901 // use a canonical orthographic projection.
903 LayerImpl
* root
= root_layer();
904 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
905 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
906 grand_child
->SetDrawsContent(true);
907 LayerImpl
* great_grand_child
= AddChild
<LayerImpl
>(grand_child
);
908 great_grand_child
->SetDrawsContent(true);
910 gfx::Transform rotation_about_y_axis
;
911 rotation_about_y_axis
.RotateAboutYAxis(30.0);
913 const gfx::Transform identity_matrix
;
914 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
915 gfx::PointF(), gfx::Size(100, 100), true, false,
917 SetLayerPropertiesForTesting(child
, rotation_about_y_axis
, gfx::Point3F(),
918 gfx::PointF(), gfx::Size(10, 10), true, false,
920 SetLayerPropertiesForTesting(grand_child
, rotation_about_y_axis
,
921 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
923 SetLayerPropertiesForTesting(great_grand_child
, identity_matrix
,
924 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
927 // No layers in this test should preserve 3d.
928 ASSERT_TRUE(root
->should_flatten_transform());
929 ASSERT_TRUE(child
->should_flatten_transform());
930 ASSERT_TRUE(grand_child
->should_flatten_transform());
931 ASSERT_TRUE(great_grand_child
->should_flatten_transform());
933 gfx::Transform expected_child_draw_transform
= rotation_about_y_axis
;
934 gfx::Transform expected_child_screen_space_transform
= rotation_about_y_axis
;
935 gfx::Transform expected_grand_child_draw_transform
=
936 rotation_about_y_axis
; // draws onto child's render surface
937 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
938 flattened_rotation_about_y
.FlattenTo2d();
939 gfx::Transform expected_grand_child_screen_space_transform
=
940 flattened_rotation_about_y
* rotation_about_y_axis
;
941 gfx::Transform expected_great_grand_child_draw_transform
=
942 flattened_rotation_about_y
;
943 gfx::Transform expected_great_grand_child_screen_space_transform
=
944 flattened_rotation_about_y
* flattened_rotation_about_y
;
946 ExecuteCalculateDrawProperties(root
);
948 // The child's draw transform should have been taken by its surface.
949 ASSERT_TRUE(child
->render_surface());
950 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform
,
951 child
->render_surface()->draw_transform());
952 EXPECT_TRANSFORMATION_MATRIX_EQ(
953 expected_child_screen_space_transform
,
954 child
->render_surface()->screen_space_transform());
955 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
956 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform
,
957 child
->screen_space_transform());
958 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform
,
959 grand_child
->draw_transform());
960 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform
,
961 grand_child
->screen_space_transform());
962 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform
,
963 great_grand_child
->draw_transform());
964 EXPECT_TRANSFORMATION_MATRIX_EQ(
965 expected_great_grand_child_screen_space_transform
,
966 great_grand_child
->screen_space_transform());
969 TEST_F(LayerTreeHostCommonTest
, LayerFullyContainedWithinClipInTargetSpace
) {
970 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
971 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
972 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
973 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
975 gfx::Transform child_transform
;
976 child_transform
.Translate(50.0, 50.0);
977 child_transform
.RotateAboutZAxis(30.0);
979 gfx::Transform grand_child_transform
;
980 grand_child_transform
.RotateAboutYAxis(90.0);
982 const gfx::Transform identity_matrix
;
983 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
984 gfx::PointF(), gfx::Size(200, 200), true, false);
985 SetLayerPropertiesForTesting(child
.get(), child_transform
, gfx::Point3F(),
986 gfx::PointF(), gfx::Size(10, 10), true, false);
987 SetLayerPropertiesForTesting(grand_child
.get(), grand_child_transform
,
988 gfx::Point3F(), gfx::PointF(),
989 gfx::Size(100, 100), true, false);
991 root
->AddChild(child
);
992 child
->AddChild(grand_child
);
993 grand_child
->SetShouldFlattenTransform(false);
995 host()->SetRootLayer(root
);
997 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
999 // Mapping grand_child's bounds to target space produces a non-empty rect
1000 // that is fully contained within the target's bounds, so grand_child should
1001 // be considered fully visible.
1002 EXPECT_EQ(gfx::Rect(grand_child
->bounds()),
1003 grand_child
->visible_rect_from_property_trees());
1006 TEST_F(LayerTreeHostCommonTest
, TransformsForDegenerateIntermediateLayer
) {
1007 // A layer that is empty in one axis, but not the other, was accidentally
1008 // skipping a necessary translation. Without that translation, the coordinate
1009 // space of the layer's draw transform is incorrect.
1011 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1012 // but if that layer becomes a render surface, then its draw transform is
1013 // implicitly inherited by the rest of the subtree, which then is positioned
1014 // incorrectly as a result.
1016 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1017 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
1018 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1019 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1021 // The child height is zero, but has non-zero width that should be accounted
1022 // for while computing draw transforms.
1023 const gfx::Transform identity_matrix
;
1024 SetLayerPropertiesForTesting(root
.get(),
1028 gfx::Size(100, 100),
1031 SetLayerPropertiesForTesting(child
.get(),
1038 SetLayerPropertiesForTesting(grand_child
.get(),
1046 root
->AddChild(child
);
1047 child
->AddChild(grand_child
);
1048 child
->SetForceRenderSurface(true);
1050 host()->SetRootLayer(root
);
1052 ExecuteCalculateDrawProperties(root
.get());
1054 ASSERT_TRUE(child
->render_surface());
1055 // This is the real test, the rest are sanity checks.
1056 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1057 child
->render_surface()->draw_transform());
1058 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1059 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1060 grand_child
->draw_transform());
1063 TEST_F(LayerTreeHostCommonTest
, TransformAboveRootLayer
) {
1064 // Transformations applied at the root of the tree should be forwarded
1065 // to child layers instead of applied to the root RenderSurface.
1066 const gfx::Transform identity_matrix
;
1067 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
1068 new LayerWithForcedDrawsContent(layer_settings());
1069 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1070 new LayerWithForcedDrawsContent(layer_settings());
1071 child
->SetScrollClipLayerId(root
->id());
1072 root
->AddChild(child
);
1074 host()->SetRootLayer(root
);
1076 SetLayerPropertiesForTesting(root
.get(),
1083 SetLayerPropertiesForTesting(child
.get(),
1091 gfx::Transform translate
;
1092 translate
.Translate(50, 50);
1094 RenderSurfaceLayerList render_surface_layer_list
;
1095 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1096 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1097 inputs
.can_adjust_raster_scales
= true;
1098 inputs
.property_trees
->needs_rebuild
= true;
1099 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1100 EXPECT_EQ(translate
, root
->draw_properties().target_space_transform
);
1101 EXPECT_EQ(translate
, child
->draw_properties().target_space_transform
);
1102 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1105 gfx::Transform scale
;
1108 RenderSurfaceLayerList render_surface_layer_list
;
1109 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1110 root
.get(), root
->bounds(), scale
, &render_surface_layer_list
);
1111 inputs
.can_adjust_raster_scales
= true;
1112 inputs
.property_trees
->needs_rebuild
= true;
1113 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1114 EXPECT_EQ(scale
, root
->draw_properties().target_space_transform
);
1115 EXPECT_EQ(scale
, child
->draw_properties().target_space_transform
);
1116 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1119 gfx::Transform rotate
;
1122 RenderSurfaceLayerList render_surface_layer_list
;
1123 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1124 root
.get(), root
->bounds(), rotate
, &render_surface_layer_list
);
1125 inputs
.can_adjust_raster_scales
= true;
1126 inputs
.property_trees
->needs_rebuild
= true;
1127 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1128 EXPECT_EQ(rotate
, root
->draw_properties().target_space_transform
);
1129 EXPECT_EQ(rotate
, child
->draw_properties().target_space_transform
);
1130 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1133 gfx::Transform composite
;
1134 composite
.ConcatTransform(translate
);
1135 composite
.ConcatTransform(scale
);
1136 composite
.ConcatTransform(rotate
);
1138 RenderSurfaceLayerList render_surface_layer_list
;
1139 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1140 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1141 inputs
.can_adjust_raster_scales
= true;
1142 inputs
.property_trees
->needs_rebuild
= true;
1143 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1144 EXPECT_EQ(composite
, root
->draw_properties().target_space_transform
);
1145 EXPECT_EQ(composite
, child
->draw_properties().target_space_transform
);
1146 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1149 // Verify it composes correctly with device scale.
1150 float device_scale_factor
= 1.5f
;
1153 RenderSurfaceLayerList render_surface_layer_list
;
1154 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1155 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1156 inputs
.device_scale_factor
= device_scale_factor
;
1157 inputs
.can_adjust_raster_scales
= true;
1158 inputs
.property_trees
->needs_rebuild
= true;
1159 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1160 gfx::Transform device_scaled_translate
= translate
;
1161 device_scaled_translate
.Scale(device_scale_factor
, device_scale_factor
);
1162 EXPECT_EQ(device_scaled_translate
,
1163 root
->draw_properties().target_space_transform
);
1164 EXPECT_EQ(device_scaled_translate
,
1165 child
->draw_properties().target_space_transform
);
1166 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1169 // Verify it composes correctly with page scale.
1170 float page_scale_factor
= 2.f
;
1173 RenderSurfaceLayerList render_surface_layer_list
;
1174 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1175 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1176 inputs
.page_scale_factor
= page_scale_factor
;
1177 inputs
.page_scale_layer
= root
.get();
1178 inputs
.can_adjust_raster_scales
= true;
1179 inputs
.property_trees
->needs_rebuild
= true;
1180 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1181 gfx::Transform page_scaled_translate
= translate
;
1182 page_scaled_translate
.Scale(page_scale_factor
, page_scale_factor
);
1183 EXPECT_EQ(page_scaled_translate
,
1184 root
->draw_properties().target_space_transform
);
1185 EXPECT_EQ(page_scaled_translate
,
1186 child
->draw_properties().target_space_transform
);
1187 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1190 // Verify that it composes correctly with transforms directly on root layer.
1191 root
->SetTransform(composite
);
1194 RenderSurfaceLayerList render_surface_layer_list
;
1195 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1196 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1197 inputs
.can_adjust_raster_scales
= true;
1198 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1199 gfx::Transform compositeSquared
= composite
;
1200 compositeSquared
.ConcatTransform(composite
);
1201 EXPECT_TRANSFORMATION_MATRIX_EQ(
1202 compositeSquared
, root
->draw_properties().target_space_transform
);
1203 EXPECT_TRANSFORMATION_MATRIX_EQ(
1204 compositeSquared
, child
->draw_properties().target_space_transform
);
1205 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1209 TEST_F(LayerTreeHostCommonTest
,
1210 RenderSurfaceListForRenderSurfaceWithClippedLayer
) {
1211 LayerImpl
* parent
= root_layer();
1212 parent
->SetMasksToBounds(true);
1213 LayerImpl
* render_surface1
= AddChildToRoot
<LayerImpl
>();
1214 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface1
);
1215 child
->SetDrawsContent(true);
1217 const gfx::Transform identity_matrix
;
1218 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1219 gfx::PointF(), gfx::Size(10, 10), true, false,
1221 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
1222 gfx::PointF(), gfx::Size(10, 10), true, false,
1224 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1225 gfx::PointF(30.f
, 30.f
), gfx::Size(10, 10), true,
1228 ExecuteCalculateDrawProperties(parent
);
1230 // The child layer's content is entirely outside the parent's clip rect, so
1231 // the intermediate render surface should not be listed here, even if it was
1232 // forced to be created. Render surfaces without children or visible content
1233 // are unexpected at draw time (e.g. we might try to create a content texture
1235 ASSERT_TRUE(parent
->render_surface());
1236 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
1239 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceListForTransparentChild
) {
1240 LayerImpl
* parent
= root_layer();
1241 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(parent
);
1242 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface1
);
1243 child
->SetDrawsContent(true);
1245 const gfx::Transform identity_matrix
;
1246 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
1247 gfx::PointF(), gfx::Size(10, 10), true, false,
1249 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1250 gfx::PointF(), gfx::Size(10, 10), true, false,
1252 render_surface1
->SetOpacity(0.f
);
1254 LayerImplList render_surface_layer_list
;
1255 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1256 parent
, parent
->bounds(), &render_surface_layer_list
);
1257 inputs
.can_adjust_raster_scales
= true;
1258 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1260 // Since the layer is transparent, render_surface1->render_surface() should
1261 // not have gotten added anywhere. Also, the drawable content rect should not
1262 // have been extended by the children.
1263 ASSERT_TRUE(parent
->render_surface());
1264 EXPECT_EQ(0U, parent
->render_surface()->layer_list().size());
1265 EXPECT_EQ(1U, render_surface_layer_list
.size());
1266 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1267 EXPECT_EQ(gfx::Rect(), parent
->drawable_content_rect());
1270 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceForBlendMode
) {
1271 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1272 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1273 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1275 host()->SetRootLayer(parent
);
1277 const gfx::Transform identity_matrix
;
1278 const SkXfermode::Mode blend_mode
= SkXfermode::kMultiply_Mode
;
1279 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
1280 gfx::PointF(), gfx::Size(10, 10), true, false);
1282 parent
->AddChild(child
);
1283 child
->SetBlendMode(blend_mode
);
1284 child
->SetOpacity(0.5f
);
1286 RenderSurfaceLayerList render_surface_layer_list
;
1287 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1288 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1289 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1291 // Since the child layer has a blend mode other than normal, it should get
1292 // its own render surface. Also, layer's draw_properties should contain the
1293 // default blend mode, since the render surface becomes responsible for
1294 // applying the blend mode.
1295 ASSERT_TRUE(child
->render_surface());
1296 EXPECT_EQ(1.0f
, child
->draw_opacity());
1297 EXPECT_EQ(0.5f
, child
->render_surface()->draw_opacity());
1298 EXPECT_EQ(SkXfermode::kSrcOver_Mode
, child
->draw_properties().blend_mode
);
1301 TEST_F(LayerTreeHostCommonTest
, ForceRenderSurface
) {
1302 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1303 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
1304 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1305 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1306 render_surface1
->SetForceRenderSurface(true);
1308 host()->SetRootLayer(parent
);
1310 const gfx::Transform identity_matrix
;
1311 SetLayerPropertiesForTesting(parent
.get(),
1318 SetLayerPropertiesForTesting(render_surface1
.get(),
1325 SetLayerPropertiesForTesting(child
.get(),
1333 parent
->AddChild(render_surface1
);
1334 render_surface1
->AddChild(child
);
1336 // Sanity check before the actual test
1337 EXPECT_FALSE(parent
->render_surface());
1338 EXPECT_FALSE(render_surface1
->render_surface());
1341 RenderSurfaceLayerList render_surface_layer_list
;
1342 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1343 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1344 inputs
.can_adjust_raster_scales
= true;
1345 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1347 // The root layer always creates a render surface
1348 EXPECT_TRUE(parent
->render_surface());
1349 EXPECT_TRUE(render_surface1
->render_surface());
1353 RenderSurfaceLayerList render_surface_layer_list
;
1354 render_surface1
->SetForceRenderSurface(false);
1355 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1356 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1357 inputs
.can_adjust_raster_scales
= true;
1358 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1359 EXPECT_TRUE(parent
->render_surface());
1360 EXPECT_FALSE(render_surface1
->render_surface());
1364 TEST_F(LayerTreeHostCommonTest
, RenderSurfacesFlattenScreenSpaceTransform
) {
1365 // Render surfaces act as a flattening point for their subtree, so should
1366 // always flatten the target-to-screen space transform seen by descendants.
1368 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1369 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1370 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1371 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1372 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1373 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1375 gfx::Transform rotation_about_y_axis
;
1376 rotation_about_y_axis
.RotateAboutYAxis(30.0);
1377 // Make |parent| have a render surface.
1378 parent
->SetOpacity(0.9f
);
1380 const gfx::Transform identity_matrix
;
1381 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
1382 gfx::PointF(), gfx::Size(100, 100), true, false);
1383 SetLayerPropertiesForTesting(parent
.get(), rotation_about_y_axis
,
1384 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1386 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
1387 gfx::PointF(), gfx::Size(10, 10), true, false);
1388 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
1389 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1392 root
->AddChild(parent
);
1393 parent
->AddChild(child
);
1394 child
->AddChild(grand_child
);
1396 grand_child
->SetShouldFlattenTransform(false);
1398 host()->SetRootLayer(root
);
1400 // Only grand_child should preserve 3d.
1401 EXPECT_TRUE(root
->should_flatten_transform());
1402 EXPECT_TRUE(parent
->should_flatten_transform());
1403 EXPECT_TRUE(child
->should_flatten_transform());
1404 EXPECT_FALSE(grand_child
->should_flatten_transform());
1406 gfx::Transform expected_child_draw_transform
= identity_matrix
;
1407 gfx::Transform expected_grand_child_draw_transform
= identity_matrix
;
1409 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
1410 flattened_rotation_about_y
.FlattenTo2d();
1412 ExecuteCalculateDrawProperties(root
.get());
1414 EXPECT_TRUE(parent
->render_surface());
1415 EXPECT_FALSE(child
->render_surface());
1416 EXPECT_FALSE(grand_child
->render_surface());
1418 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1419 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1420 grand_child
->draw_transform());
1422 // The screen-space transform inherited by |child| and |grand_child| should
1423 // have been flattened at their render target. In particular, the fact that
1424 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1425 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y
,
1426 child
->screen_space_transform());
1427 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y
,
1428 grand_child
->screen_space_transform());
1431 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsRenderSurfaces
) {
1432 // The entire subtree of layers that are outside the clip rect should be
1433 // culled away, and should not affect the render_surface_layer_list.
1435 // The test tree is set up as follows:
1436 // - all layers except the leaf_nodes are forced to be a new render surface
1437 // that have something to draw.
1438 // - parent is a large container layer.
1439 // - child has masksToBounds=true to cause clipping.
1440 // - grand_child is positioned outside of the child's bounds
1441 // - great_grand_child is also kept outside child's bounds.
1443 // In this configuration, grand_child and great_grand_child are completely
1444 // outside the clip rect, and they should never get scheduled on the list of
1447 LayerImpl
* parent
= root_layer();
1448 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
1449 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
1450 LayerImpl
* great_grand_child
= AddChild
<LayerImpl
>(grand_child
);
1452 // leaf_node1 ensures that parent and child are kept on the
1453 // render_surface_layer_list, even though grand_child and great_grand_child
1454 // should be clipped.
1455 LayerImpl
* leaf_node1
= AddChild
<LayerImpl
>(child
);
1456 leaf_node1
->SetDrawsContent(true);
1457 LayerImpl
* leaf_node2
= AddChild
<LayerImpl
>(great_grand_child
);
1458 leaf_node2
->SetDrawsContent(true);
1460 const gfx::Transform identity_matrix
;
1462 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1463 gfx::PointF(), gfx::Size(500, 500), true, false,
1465 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1466 gfx::PointF(), gfx::Size(20, 20), true, false,
1468 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
1469 gfx::PointF(45.f
, 45.f
), gfx::Size(10, 10), true,
1471 SetLayerPropertiesForTesting(great_grand_child
, identity_matrix
,
1472 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1473 true, false, false);
1474 SetLayerPropertiesForTesting(leaf_node1
, identity_matrix
, gfx::Point3F(),
1475 gfx::PointF(), gfx::Size(500, 500), true, false,
1477 SetLayerPropertiesForTesting(leaf_node2
, identity_matrix
, gfx::Point3F(),
1478 gfx::PointF(), gfx::Size(20, 20), true, false,
1481 child
->SetMasksToBounds(true);
1482 child
->SetOpacity(0.4f
);
1483 grand_child
->SetOpacity(0.5f
);
1484 great_grand_child
->SetOpacity(0.4f
);
1486 ExecuteCalculateDrawProperties(parent
);
1488 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
1489 EXPECT_EQ(parent
->id(), render_surface_layer_list_impl()->at(0)->id());
1490 EXPECT_EQ(child
->id(), render_surface_layer_list_impl()->at(1)->id());
1493 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsSurfaceWithoutVisibleContent
) {
1494 // When a render surface has a clip rect, it is used to clip the content rect
1497 // The test tree is set up as follows:
1498 // - parent is a container layer that masksToBounds=true to cause clipping.
1499 // - child is a render surface, which has a clip rect set to the bounds of
1501 // - grand_child is a render surface, and the only visible content in child.
1502 // It is positioned outside of the clip rect from parent.
1504 // In this configuration, grand_child should be outside the clipped
1505 // content rect of the child, making grand_child not appear in the
1506 // render_surface_layer_list.
1508 LayerImpl
* parent
= root_layer();
1509 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
1510 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
1511 LayerImpl
* leaf_node
= AddChild
<LayerImpl
>(grand_child
);
1512 leaf_node
->SetDrawsContent(true);
1514 const gfx::Transform identity_matrix
;
1516 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1517 gfx::PointF(), gfx::Size(100, 100), true, false,
1519 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1520 gfx::PointF(), gfx::Size(20, 20), true, false,
1522 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
1523 gfx::PointF(200.f
, 200.f
), gfx::Size(10, 10),
1525 SetLayerPropertiesForTesting(leaf_node
, identity_matrix
, gfx::Point3F(),
1526 gfx::PointF(), gfx::Size(10, 10), true, false,
1529 parent
->SetMasksToBounds(true);
1530 child
->SetOpacity(0.4f
);
1531 grand_child
->SetOpacity(0.4f
);
1533 ExecuteCalculateDrawProperties(parent
);
1535 // We should cull child and grand_child from the
1536 // render_surface_layer_list.
1537 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
1538 EXPECT_EQ(parent
->id(), render_surface_layer_list_impl()->at(0)->id());
1541 TEST_F(LayerTreeHostCommonTest
, IsClippedIsSetCorrectly
) {
1542 // Layer's IsClipped() property is set to true when:
1543 // - the layer clips its subtree, e.g. masks to bounds,
1544 // - the layer is clipped by an ancestor that contributes to the same
1546 // - a surface is clipped by an ancestor that contributes to the same
1549 // In particular, for a layer that owns a render surface:
1550 // - the render surface inherits any clip from ancestors, and does NOT
1551 // pass that clipped status to the layer itself.
1552 // - but if the layer itself masks to bounds, it is considered clipped
1553 // and propagates the clip to the subtree.
1555 const gfx::Transform identity_matrix
;
1556 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1557 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1558 scoped_refptr
<Layer
> child1
= Layer::Create(layer_settings());
1559 scoped_refptr
<Layer
> child2
= Layer::Create(layer_settings());
1560 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
1561 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1562 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1563 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1564 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1565 root
->AddChild(parent
);
1566 parent
->AddChild(child1
);
1567 parent
->AddChild(child2
);
1568 child1
->AddChild(grand_child
);
1569 child2
->AddChild(leaf_node2
);
1570 grand_child
->AddChild(leaf_node1
);
1572 host()->SetRootLayer(root
);
1574 child2
->SetForceRenderSurface(true);
1576 SetLayerPropertiesForTesting(root
.get(),
1580 gfx::Size(100, 100),
1583 SetLayerPropertiesForTesting(parent
.get(),
1587 gfx::Size(100, 100),
1590 SetLayerPropertiesForTesting(child1
.get(),
1594 gfx::Size(100, 100),
1597 SetLayerPropertiesForTesting(child2
.get(),
1601 gfx::Size(100, 100),
1604 SetLayerPropertiesForTesting(grand_child
.get(),
1608 gfx::Size(100, 100),
1611 SetLayerPropertiesForTesting(leaf_node1
.get(),
1615 gfx::Size(100, 100),
1618 SetLayerPropertiesForTesting(leaf_node2
.get(),
1622 gfx::Size(100, 100),
1626 // Case 1: nothing is clipped except the root render surface.
1628 RenderSurfaceLayerList render_surface_layer_list
;
1629 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1630 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1631 inputs
.can_adjust_raster_scales
= true;
1632 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1634 ASSERT_TRUE(root
->render_surface());
1635 ASSERT_TRUE(child2
->render_surface());
1637 EXPECT_FALSE(root
->is_clipped());
1638 EXPECT_TRUE(root
->render_surface()->is_clipped());
1639 EXPECT_FALSE(parent
->is_clipped());
1640 EXPECT_FALSE(child1
->is_clipped());
1641 EXPECT_FALSE(child2
->is_clipped());
1642 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1643 EXPECT_FALSE(grand_child
->is_clipped());
1644 EXPECT_FALSE(leaf_node1
->is_clipped());
1645 EXPECT_FALSE(leaf_node2
->is_clipped());
1648 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1649 // surface are clipped. But layers that contribute to child2's surface are
1650 // not clipped explicitly because child2's surface already accounts for
1653 RenderSurfaceLayerList render_surface_layer_list
;
1654 parent
->SetMasksToBounds(true);
1655 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1656 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1657 inputs
.can_adjust_raster_scales
= true;
1658 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1660 ASSERT_TRUE(root
->render_surface());
1661 ASSERT_TRUE(child2
->render_surface());
1663 EXPECT_FALSE(root
->is_clipped());
1664 EXPECT_TRUE(root
->render_surface()->is_clipped());
1665 EXPECT_TRUE(parent
->is_clipped());
1666 EXPECT_TRUE(child1
->is_clipped());
1667 EXPECT_FALSE(child2
->is_clipped());
1668 EXPECT_TRUE(child2
->render_surface()->is_clipped());
1669 EXPECT_TRUE(grand_child
->is_clipped());
1670 EXPECT_TRUE(leaf_node1
->is_clipped());
1671 EXPECT_FALSE(leaf_node2
->is_clipped());
1674 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1675 // child2's render surface is not clipped.
1677 RenderSurfaceLayerList render_surface_layer_list
;
1678 parent
->SetMasksToBounds(false);
1679 child2
->SetMasksToBounds(true);
1680 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1681 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1682 inputs
.can_adjust_raster_scales
= true;
1683 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1685 ASSERT_TRUE(root
->render_surface());
1686 ASSERT_TRUE(child2
->render_surface());
1688 EXPECT_FALSE(root
->is_clipped());
1689 EXPECT_TRUE(root
->render_surface()->is_clipped());
1690 EXPECT_FALSE(parent
->is_clipped());
1691 EXPECT_FALSE(child1
->is_clipped());
1692 EXPECT_TRUE(child2
->is_clipped());
1693 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1694 EXPECT_FALSE(grand_child
->is_clipped());
1695 EXPECT_FALSE(leaf_node1
->is_clipped());
1696 EXPECT_TRUE(leaf_node2
->is_clipped());
1700 TEST_F(LayerTreeHostCommonTest
, DrawableContentRectForLayers
) {
1701 // Verify that layers get the appropriate DrawableContentRect when their
1702 // parent masksToBounds is true.
1704 // grand_child1 - completely inside the region; DrawableContentRect should
1705 // be the layer rect expressed in target space.
1706 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1707 // will be the intersection of layer bounds and the mask region.
1708 // grand_child3 - partially clipped and masksToBounds; the
1709 // DrawableContentRect will still be the intersection of layer bounds and
1711 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1715 const gfx::Transform identity_matrix
;
1716 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1717 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
1718 scoped_refptr
<Layer
> grand_child1
= Layer::Create(layer_settings());
1719 scoped_refptr
<Layer
> grand_child2
= Layer::Create(layer_settings());
1720 scoped_refptr
<Layer
> grand_child3
= Layer::Create(layer_settings());
1721 scoped_refptr
<Layer
> grand_child4
= Layer::Create(layer_settings());
1723 parent
->AddChild(child
);
1724 child
->AddChild(grand_child1
);
1725 child
->AddChild(grand_child2
);
1726 child
->AddChild(grand_child3
);
1727 child
->AddChild(grand_child4
);
1729 host()->SetRootLayer(parent
);
1731 SetLayerPropertiesForTesting(parent
.get(),
1735 gfx::Size(500, 500),
1738 SetLayerPropertiesForTesting(child
.get(),
1745 SetLayerPropertiesForTesting(grand_child1
.get(),
1748 gfx::PointF(5.f
, 5.f
),
1752 SetLayerPropertiesForTesting(grand_child2
.get(),
1755 gfx::PointF(15.f
, 15.f
),
1759 SetLayerPropertiesForTesting(grand_child3
.get(),
1762 gfx::PointF(15.f
, 15.f
),
1766 SetLayerPropertiesForTesting(grand_child4
.get(),
1769 gfx::PointF(45.f
, 45.f
),
1774 child
->SetMasksToBounds(true);
1775 grand_child3
->SetMasksToBounds(true);
1777 // Force everyone to be a render surface.
1778 child
->SetOpacity(0.4f
);
1779 grand_child1
->SetOpacity(0.5f
);
1780 grand_child2
->SetOpacity(0.5f
);
1781 grand_child3
->SetOpacity(0.5f
);
1782 grand_child4
->SetOpacity(0.5f
);
1784 RenderSurfaceLayerList render_surface_layer_list
;
1785 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1786 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1787 inputs
.can_adjust_raster_scales
= true;
1788 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1790 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1
->drawable_content_rect());
1791 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3
->drawable_content_rect());
1792 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3
->drawable_content_rect());
1793 EXPECT_TRUE(grand_child4
->drawable_content_rect().IsEmpty());
1796 TEST_F(LayerTreeHostCommonTest
, ClipRectIsPropagatedCorrectlyToSurfaces
) {
1797 // Verify that render surfaces (and their layers) get the appropriate
1798 // clip rects when their parent masksToBounds is true.
1800 // Layers that own render surfaces (at least for now) do not inherit any
1801 // clipping; instead the surface will enforce the clip for the entire subtree.
1802 // They may still have a clip rect of their own layer bounds, however, if
1803 // masksToBounds was true.
1804 LayerImpl
* parent
= root_layer();
1805 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
1806 LayerImpl
* grand_child1
= AddChild
<LayerImpl
>(child
);
1807 LayerImpl
* grand_child2
= AddChild
<LayerImpl
>(child
);
1808 LayerImpl
* grand_child3
= AddChild
<LayerImpl
>(child
);
1809 LayerImpl
* grand_child4
= AddChild
<LayerImpl
>(child
);
1810 // the leaf nodes ensure that these grand_children become render surfaces for
1812 LayerImpl
* leaf_node1
= AddChild
<LayerImpl
>(grand_child1
);
1813 leaf_node1
->SetDrawsContent(true);
1814 LayerImpl
* leaf_node2
= AddChild
<LayerImpl
>(grand_child2
);
1815 leaf_node2
->SetDrawsContent(true);
1816 LayerImpl
* leaf_node3
= AddChild
<LayerImpl
>(grand_child3
);
1817 leaf_node3
->SetDrawsContent(true);
1818 LayerImpl
* leaf_node4
= AddChild
<LayerImpl
>(grand_child4
);
1819 leaf_node4
->SetDrawsContent(true);
1821 const gfx::Transform identity_matrix
;
1823 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1824 gfx::PointF(), gfx::Size(500, 500), true, false,
1826 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1827 gfx::PointF(), gfx::Size(20, 20), true, false,
1829 SetLayerPropertiesForTesting(grand_child1
, identity_matrix
, gfx::Point3F(),
1830 gfx::PointF(5.f
, 5.f
), gfx::Size(10, 10), true,
1832 SetLayerPropertiesForTesting(grand_child2
, identity_matrix
, gfx::Point3F(),
1833 gfx::PointF(15.f
, 15.f
), gfx::Size(10, 10), true,
1835 SetLayerPropertiesForTesting(grand_child3
, identity_matrix
, gfx::Point3F(),
1836 gfx::PointF(15.f
, 15.f
), gfx::Size(10, 10), true,
1838 SetLayerPropertiesForTesting(grand_child4
, identity_matrix
, gfx::Point3F(),
1839 gfx::PointF(45.f
, 45.f
), gfx::Size(10, 10), true,
1841 SetLayerPropertiesForTesting(leaf_node1
, identity_matrix
, gfx::Point3F(),
1842 gfx::PointF(), gfx::Size(10, 10), true, false,
1844 SetLayerPropertiesForTesting(leaf_node2
, identity_matrix
, gfx::Point3F(),
1845 gfx::PointF(), gfx::Size(10, 10), true, false,
1847 SetLayerPropertiesForTesting(leaf_node3
, identity_matrix
, gfx::Point3F(),
1848 gfx::PointF(), gfx::Size(10, 10), true, false,
1850 SetLayerPropertiesForTesting(leaf_node4
, identity_matrix
, gfx::Point3F(),
1851 gfx::PointF(), gfx::Size(10, 10), true, false,
1854 child
->SetMasksToBounds(true);
1855 grand_child3
->SetMasksToBounds(true);
1856 grand_child4
->SetMasksToBounds(true);
1858 // Force everyone to be a render surface.
1859 child
->SetOpacity(0.4f
);
1860 grand_child1
->SetOpacity(0.5f
);
1861 grand_child2
->SetOpacity(0.5f
);
1862 grand_child3
->SetOpacity(0.5f
);
1863 grand_child4
->SetOpacity(0.5f
);
1865 ExecuteCalculateDrawProperties(parent
);
1867 ASSERT_TRUE(grand_child1
->render_surface());
1868 ASSERT_TRUE(grand_child2
->render_surface());
1869 ASSERT_TRUE(grand_child3
->render_surface());
1871 // Surfaces are clipped by their parent, but un-affected by the owning layer's
1873 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1874 grand_child1
->render_surface()->clip_rect());
1875 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1876 grand_child2
->render_surface()->clip_rect());
1877 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1878 grand_child3
->render_surface()->clip_rect());
1881 TEST_F(LayerTreeHostCommonTest
, AnimationsForRenderSurfaceHierarchy
) {
1882 LayerImpl
* parent
= root_layer();
1883 LayerImpl
* render_surface1
= AddChildToRoot
<LayerImpl
>();
1884 LayerImpl
* child_of_rs1
= AddChild
<LayerImpl
>(render_surface1
);
1885 LayerImpl
* grand_child_of_rs1
= AddChild
<LayerImpl
>(child_of_rs1
);
1886 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(render_surface1
);
1887 LayerImpl
* child_of_rs2
= AddChild
<LayerImpl
>(render_surface2
);
1888 LayerImpl
* grand_child_of_rs2
= AddChild
<LayerImpl
>(child_of_rs2
);
1889 LayerImpl
* child_of_root
= AddChildToRoot
<LayerImpl
>();
1890 LayerImpl
* grand_child_of_root
= AddChild
<LayerImpl
>(child_of_root
);
1892 grand_child_of_rs1
->SetDrawsContent(true);
1893 grand_child_of_rs2
->SetDrawsContent(true);
1895 gfx::Transform layer_transform
;
1896 layer_transform
.Translate(1.0, 1.0);
1898 SetLayerPropertiesForTesting(
1899 parent
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1900 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, true);
1901 SetLayerPropertiesForTesting(
1902 render_surface1
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1903 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, true);
1904 SetLayerPropertiesForTesting(
1905 render_surface2
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1906 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, true);
1907 SetLayerPropertiesForTesting(
1908 child_of_root
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1909 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1910 SetLayerPropertiesForTesting(
1911 child_of_rs1
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1912 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1913 SetLayerPropertiesForTesting(
1914 child_of_rs2
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1915 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1916 SetLayerPropertiesForTesting(
1917 grand_child_of_root
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1918 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1919 SetLayerPropertiesForTesting(
1920 grand_child_of_rs1
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1921 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1922 SetLayerPropertiesForTesting(
1923 grand_child_of_rs2
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1924 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1926 // Put an animated opacity on the render surface.
1927 AddOpacityTransitionToController(
1928 render_surface1
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
1930 // Also put an animated opacity on a layer without descendants.
1931 AddOpacityTransitionToController(
1932 grand_child_of_root
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
1934 // Put a transform animation on the render surface.
1935 AddAnimatedTransformToController(
1936 render_surface2
->layer_animation_controller(), 10.0, 30, 0);
1938 // Also put transform animations on grand_child_of_root, and
1939 // grand_child_of_rs2
1940 AddAnimatedTransformToController(
1941 grand_child_of_root
->layer_animation_controller(), 10.0, 30, 0);
1942 AddAnimatedTransformToController(
1943 grand_child_of_rs2
->layer_animation_controller(), 10.0, 30, 0);
1945 ExecuteCalculateDrawProperties(parent
);
1947 // Only layers that are associated with render surfaces should have an actual
1948 // RenderSurface() value.
1949 ASSERT_TRUE(parent
->render_surface());
1950 ASSERT_FALSE(child_of_root
->render_surface());
1951 ASSERT_FALSE(grand_child_of_root
->render_surface());
1953 ASSERT_TRUE(render_surface1
->render_surface());
1954 ASSERT_FALSE(child_of_rs1
->render_surface());
1955 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
1957 ASSERT_TRUE(render_surface2
->render_surface());
1958 ASSERT_FALSE(child_of_rs2
->render_surface());
1959 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
1961 // Verify all render target accessors
1962 EXPECT_EQ(parent
, parent
->render_target());
1963 EXPECT_EQ(parent
, child_of_root
->render_target());
1964 EXPECT_EQ(parent
, grand_child_of_root
->render_target());
1966 EXPECT_EQ(render_surface1
, render_surface1
->render_target());
1967 EXPECT_EQ(render_surface1
, child_of_rs1
->render_target());
1968 EXPECT_EQ(render_surface1
, grand_child_of_rs1
->render_target());
1970 EXPECT_EQ(render_surface2
, render_surface2
->render_target());
1971 EXPECT_EQ(render_surface2
, child_of_rs2
->render_target());
1972 EXPECT_EQ(render_surface2
, grand_child_of_rs2
->render_target());
1974 // Verify screen_space_transform_is_animating values
1975 EXPECT_FALSE(parent
->screen_space_transform_is_animating());
1976 EXPECT_FALSE(child_of_root
->screen_space_transform_is_animating());
1977 EXPECT_TRUE(grand_child_of_root
->screen_space_transform_is_animating());
1978 EXPECT_FALSE(render_surface1
->screen_space_transform_is_animating());
1979 EXPECT_FALSE(child_of_rs1
->screen_space_transform_is_animating());
1980 EXPECT_FALSE(grand_child_of_rs1
->screen_space_transform_is_animating());
1981 EXPECT_TRUE(render_surface2
->screen_space_transform_is_animating());
1982 EXPECT_TRUE(child_of_rs2
->screen_space_transform_is_animating());
1983 EXPECT_TRUE(grand_child_of_rs2
->screen_space_transform_is_animating());
1985 // Sanity check. If these fail there is probably a bug in the test itself.
1986 // It is expected that we correctly set up transforms so that the y-component
1987 // of the screen-space transform encodes the "depth" of the layer in the tree.
1988 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
1989 EXPECT_FLOAT_EQ(2.0,
1990 child_of_root
->screen_space_transform().matrix().get(1, 3));
1992 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
1994 EXPECT_FLOAT_EQ(2.0,
1995 render_surface1
->screen_space_transform().matrix().get(1, 3));
1996 EXPECT_FLOAT_EQ(3.0,
1997 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
1999 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2001 EXPECT_FLOAT_EQ(3.0,
2002 render_surface2
->screen_space_transform().matrix().get(1, 3));
2003 EXPECT_FLOAT_EQ(4.0,
2004 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2006 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2009 TEST_F(LayerTreeHostCommonTest
,
2010 ScreenSpaceTransformIsAnimatingWithDelayedAnimation
) {
2011 LayerImpl
* parent
= root_layer();
2012 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
2013 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
2014 LayerImpl
* great_grand_child
= AddChild
<LayerImpl
>(grand_child
);
2016 parent
->SetDrawsContent(true);
2017 child
->SetDrawsContent(true);
2018 grand_child
->SetDrawsContent(true);
2019 great_grand_child
->SetDrawsContent(true);
2021 gfx::Transform identity
;
2023 SetLayerPropertiesForTesting(parent
, identity
, gfx::Point3F(), gfx::PointF(),
2024 gfx::Size(10, 10), true, false, true);
2025 SetLayerPropertiesForTesting(child
, identity
, gfx::Point3F(), gfx::PointF(),
2026 gfx::Size(10, 10), true, false, false);
2027 SetLayerPropertiesForTesting(grand_child
, identity
, gfx::Point3F(),
2028 gfx::PointF(), gfx::Size(10, 10), true, false,
2030 SetLayerPropertiesForTesting(great_grand_child
, identity
, gfx::Point3F(),
2031 gfx::PointF(), gfx::Size(10, 10), true, false,
2034 // Add a transform animation with a start delay to |grand_child|.
2035 scoped_ptr
<Animation
> animation
= Animation::Create(
2036 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1.0)).Pass(), 0, 1,
2037 Animation::TRANSFORM
);
2038 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
2039 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
2040 grand_child
->layer_animation_controller()->AddAnimation(animation
.Pass());
2042 ExecuteCalculateDrawProperties(parent
);
2044 EXPECT_FALSE(parent
->screen_space_transform_is_animating());
2045 EXPECT_FALSE(child
->screen_space_transform_is_animating());
2047 EXPECT_FALSE(grand_child
->TransformIsAnimating());
2048 EXPECT_TRUE(grand_child
->HasPotentiallyRunningTransformAnimation());
2049 EXPECT_TRUE(grand_child
->screen_space_transform_is_animating());
2050 EXPECT_TRUE(great_grand_child
->screen_space_transform_is_animating());
2053 TEST_F(LayerTreeHostCommonTest
, VisibleRectForIdentityTransform
) {
2054 // Test the calculateVisibleRect() function works correctly for identity
2057 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2058 gfx::Transform layer_to_surface_transform
;
2060 // Case 1: Layer is contained within the surface.
2061 gfx::Rect layer_content_rect
= gfx::Rect(10, 10, 30, 30);
2062 gfx::Rect expected
= gfx::Rect(10, 10, 30, 30);
2063 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2064 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2065 EXPECT_EQ(expected
, actual
);
2067 // Case 2: Layer is outside the surface rect.
2068 layer_content_rect
= gfx::Rect(120, 120, 30, 30);
2069 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2070 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2071 EXPECT_TRUE(actual
.IsEmpty());
2073 // Case 3: Layer is partially overlapping the surface rect.
2074 layer_content_rect
= gfx::Rect(80, 80, 30, 30);
2075 expected
= gfx::Rect(80, 80, 20, 20);
2076 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2077 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2078 EXPECT_EQ(expected
, actual
);
2081 TEST_F(LayerTreeHostCommonTest
, VisibleRectForTranslations
) {
2082 // Test the calculateVisibleRect() function works correctly for scaling
2085 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2086 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2087 gfx::Transform layer_to_surface_transform
;
2089 // Case 1: Layer is contained within the surface.
2090 layer_to_surface_transform
.MakeIdentity();
2091 layer_to_surface_transform
.Translate(10.0, 10.0);
2092 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2093 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2094 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2095 EXPECT_EQ(expected
, actual
);
2097 // Case 2: Layer is outside the surface rect.
2098 layer_to_surface_transform
.MakeIdentity();
2099 layer_to_surface_transform
.Translate(120.0, 120.0);
2100 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2101 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2102 EXPECT_TRUE(actual
.IsEmpty());
2104 // Case 3: Layer is partially overlapping the surface rect.
2105 layer_to_surface_transform
.MakeIdentity();
2106 layer_to_surface_transform
.Translate(80.0, 80.0);
2107 expected
= gfx::Rect(0, 0, 20, 20);
2108 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2109 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2110 EXPECT_EQ(expected
, actual
);
2113 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor2DRotations
) {
2114 // Test the calculateVisibleRect() function works correctly for rotations
2115 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2116 // should return the g in the layer's space.
2118 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2119 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2120 gfx::Transform layer_to_surface_transform
;
2122 // Case 1: Layer is contained within the surface.
2123 layer_to_surface_transform
.MakeIdentity();
2124 layer_to_surface_transform
.Translate(50.0, 50.0);
2125 layer_to_surface_transform
.Rotate(45.0);
2126 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2127 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2128 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2129 EXPECT_EQ(expected
, actual
);
2131 // Case 2: Layer is outside the surface rect.
2132 layer_to_surface_transform
.MakeIdentity();
2133 layer_to_surface_transform
.Translate(-50.0, 0.0);
2134 layer_to_surface_transform
.Rotate(45.0);
2135 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2136 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2137 EXPECT_TRUE(actual
.IsEmpty());
2139 // Case 3: The layer is rotated about its top-left corner. In surface space,
2140 // the layer is oriented diagonally, with the left half outside of the render
2141 // surface. In this case, the g should still be the entire layer
2142 // (remember the g is computed in layer space); both the top-left
2143 // and bottom-right corners of the layer are still visible.
2144 layer_to_surface_transform
.MakeIdentity();
2145 layer_to_surface_transform
.Rotate(45.0);
2146 expected
= gfx::Rect(0, 0, 30, 30);
2147 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2148 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2149 EXPECT_EQ(expected
, actual
);
2151 // Case 4: The layer is rotated about its top-left corner, and translated
2152 // upwards. In surface space, the layer is oriented diagonally, with only the
2153 // top corner of the surface overlapping the layer. In layer space, the render
2154 // surface overlaps the right side of the layer. The g should be
2155 // the layer's right half.
2156 layer_to_surface_transform
.MakeIdentity();
2157 layer_to_surface_transform
.Translate(0.0, -sqrt(2.0) * 15.0);
2158 layer_to_surface_transform
.Rotate(45.0);
2159 expected
= gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
2160 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2161 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2162 EXPECT_EQ(expected
, actual
);
2165 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dOrthographicTransform
) {
2166 // Test that the calculateVisibleRect() function works correctly for 3d
2169 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2170 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2171 gfx::Transform layer_to_surface_transform
;
2173 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2174 // degrees, should be fully contained in the render surface.
2175 layer_to_surface_transform
.MakeIdentity();
2176 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2177 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2178 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2179 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2180 EXPECT_EQ(expected
, actual
);
2182 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2183 // degrees, but shifted to the side so only the right-half the layer would be
2184 // visible on the surface.
2185 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2186 SkMScalar half_width_of_rotated_layer
=
2187 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
2188 layer_to_surface_transform
.MakeIdentity();
2189 layer_to_surface_transform
.Translate(-half_width_of_rotated_layer
, 0.0);
2190 layer_to_surface_transform
.RotateAboutYAxis(45.0); // Rotates about the left
2191 // edge of the layer.
2192 expected
= gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
2193 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2194 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2195 EXPECT_EQ(expected
, actual
);
2198 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveTransform
) {
2199 // Test the calculateVisibleRect() function works correctly when the layer has
2200 // a perspective projection onto the target surface.
2202 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2203 gfx::Rect layer_content_rect
= gfx::Rect(-50, -50, 200, 200);
2204 gfx::Transform layer_to_surface_transform
;
2206 // Case 1: Even though the layer is twice as large as the surface, due to
2207 // perspective foreshortening, the layer will fit fully in the surface when
2208 // its translated more than the perspective amount.
2209 layer_to_surface_transform
.MakeIdentity();
2211 // The following sequence of transforms applies the perspective about the
2212 // center of the surface.
2213 layer_to_surface_transform
.Translate(50.0, 50.0);
2214 layer_to_surface_transform
.ApplyPerspectiveDepth(9.0);
2215 layer_to_surface_transform
.Translate(-50.0, -50.0);
2217 // This translate places the layer in front of the surface's projection plane.
2218 layer_to_surface_transform
.Translate3d(0.0, 0.0, -27.0);
2220 gfx::Rect expected
= gfx::Rect(-50, -50, 200, 200);
2221 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2222 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2223 EXPECT_EQ(expected
, actual
);
2225 // Case 2: same projection as before, except that the layer is also translated
2226 // to the side, so that only the right half of the layer should be visible.
2228 // Explanation of expected result: The perspective ratio is (z distance
2229 // between layer and camera origin) / (z distance between projection plane and
2230 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2231 // move a layer by translating -50 units in projected surface units (so that
2232 // only half of it is visible), then we would need to translate by (-36 / 9) *
2233 // -50 == -200 in the layer's units.
2234 layer_to_surface_transform
.Translate3d(-200.0, 0.0, 0.0);
2235 expected
= gfx::Rect(gfx::Point(50, -50),
2236 gfx::Size(100, 200)); // The right half of the layer's
2238 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2239 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2240 EXPECT_EQ(expected
, actual
);
2243 TEST_F(LayerTreeHostCommonTest
,
2244 VisibleRectFor3dOrthographicIsNotClippedBehindSurface
) {
2245 // There is currently no explicit concept of an orthographic projection plane
2246 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2247 // are technically behind the surface in an orthographic world should not be
2248 // clipped when they are flattened to the surface.
2250 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2251 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2252 gfx::Transform layer_to_surface_transform
;
2254 // This sequence of transforms effectively rotates the layer about the y-axis
2255 // at the center of the layer.
2256 layer_to_surface_transform
.MakeIdentity();
2257 layer_to_surface_transform
.Translate(50.0, 0.0);
2258 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2259 layer_to_surface_transform
.Translate(-50.0, 0.0);
2261 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2262 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2263 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2264 EXPECT_EQ(expected
, actual
);
2267 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveWhenClippedByW
) {
2268 // Test the calculateVisibleRect() function works correctly when projecting a
2269 // surface onto a layer, but the layer is partially behind the camera (not
2270 // just behind the projection plane). In this case, the cartesian coordinates
2271 // may seem to be valid, but actually they are not. The visible rect needs to
2272 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2273 // converting to cartesian coordinates.
2275 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2276 gfx::Rect layer_content_rect
= gfx::Rect(-10, -1, 20, 2);
2277 gfx::Transform layer_to_surface_transform
;
2279 // The layer is positioned so that the right half of the layer should be in
2280 // front of the camera, while the other half is behind the surface's
2281 // projection plane. The following sequence of transforms applies the
2282 // perspective and rotation about the center of the layer.
2283 layer_to_surface_transform
.MakeIdentity();
2284 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2285 layer_to_surface_transform
.Translate3d(-2.0, 0.0, 1.0);
2286 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2288 // Sanity check that this transform does indeed cause w < 0 when applying the
2289 // transform, otherwise this code is not testing the intended scenario.
2291 MathUtil::MapQuad(layer_to_surface_transform
,
2292 gfx::QuadF(gfx::RectF(layer_content_rect
)),
2294 ASSERT_TRUE(clipped
);
2296 int expected_x_position
= 0;
2297 int expected_width
= 10;
2298 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2299 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2300 EXPECT_EQ(expected_x_position
, actual
.x());
2301 EXPECT_EQ(expected_width
, actual
.width());
2304 TEST_F(LayerTreeHostCommonTest
, VisibleRectForPerspectiveUnprojection
) {
2305 // To determine visible rect in layer space, there needs to be an
2306 // un-projection from surface space to layer space. When the original
2307 // transform was a perspective projection that was clipped, it returns a rect
2308 // that encloses the clipped bounds. Un-projecting this new rect may require
2311 // This sequence of transforms causes one corner of the layer to protrude
2312 // across the w = 0 plane, and should be clipped.
2313 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2314 gfx::Rect layer_content_rect
= gfx::Rect(-10, -10, 20, 20);
2315 gfx::Transform layer_to_surface_transform
;
2316 layer_to_surface_transform
.MakeIdentity();
2317 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2318 layer_to_surface_transform
.Translate3d(0.0, 0.0, -5.0);
2319 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2320 layer_to_surface_transform
.RotateAboutXAxis(80.0);
2322 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2323 // code is not testing the intended scenario.
2325 gfx::RectF clipped_rect
=
2326 MathUtil::MapClippedRect(layer_to_surface_transform
, layer_content_rect
);
2327 MathUtil::ProjectQuad(
2328 Inverse(layer_to_surface_transform
), gfx::QuadF(clipped_rect
), &clipped
);
2329 ASSERT_TRUE(clipped
);
2331 // Only the corner of the layer is not visible on the surface because of being
2332 // clipped. But, the net result of rounding visible region to an axis-aligned
2333 // rect is that the entire layer should still be considered visible.
2334 gfx::Rect expected
= gfx::Rect(-10, -10, 20, 20);
2335 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2336 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2337 EXPECT_EQ(expected
, actual
);
2340 TEST_F(LayerTreeHostCommonTest
,
2341 VisibleRectsForPositionedRootLayerClippedByViewport
) {
2342 scoped_refptr
<Layer
> root
=
2343 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2344 host()->SetRootLayer(root
);
2346 gfx::Transform identity_matrix
;
2347 // Root layer is positioned at (60, 70). The default device viewport size
2348 // is (0, 0, 100x100) in target space. So the root layer's visible rect
2349 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space.
2350 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2351 gfx::PointF(60, 70), gfx::Size(100, 100), true,
2353 ExecuteCalculateDrawProperties(root
.get());
2355 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2356 root
->render_surface()->DrawableContentRect());
2357 // In target space, not clipped.
2358 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root
->drawable_content_rect());
2359 // In layer space, clipped.
2360 EXPECT_EQ(gfx::Rect(0, 0, 40, 30), root
->visible_layer_rect());
2363 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsForSimpleLayers
) {
2364 LayerImpl
* root
= root_layer();
2365 LayerImpl
* child1_layer
= AddChildToRoot
<LayerImpl
>();
2366 child1_layer
->SetDrawsContent(true);
2367 LayerImpl
* child2_layer
= AddChildToRoot
<LayerImpl
>();
2368 child2_layer
->SetDrawsContent(true);
2369 LayerImpl
* child3_layer
= AddChildToRoot
<LayerImpl
>();
2370 child3_layer
->SetDrawsContent(true);
2372 gfx::Transform identity_matrix
;
2373 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2374 gfx::PointF(), gfx::Size(100, 100), true, false,
2376 SetLayerPropertiesForTesting(child1_layer
, identity_matrix
, gfx::Point3F(),
2377 gfx::PointF(), gfx::Size(50, 50), true, false,
2379 SetLayerPropertiesForTesting(child2_layer
, identity_matrix
, gfx::Point3F(),
2380 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2382 SetLayerPropertiesForTesting(child3_layer
, identity_matrix
, gfx::Point3F(),
2383 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2384 true, false, false);
2386 ExecuteCalculateDrawProperties(root
);
2388 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2389 root
->render_surface()->DrawableContentRect());
2390 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2392 // Layers that do not draw content should have empty visible_layer_rects.
2393 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2395 // layer visible_layer_rects are clipped by their target surface.
2396 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer
->visible_layer_rect());
2397 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer
->visible_layer_rect());
2398 EXPECT_TRUE(child3_layer
->visible_layer_rect().IsEmpty());
2400 // layer drawable_content_rects are not clipped.
2401 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer
->drawable_content_rect());
2402 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer
->drawable_content_rect());
2403 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer
->drawable_content_rect());
2406 TEST_F(LayerTreeHostCommonTest
,
2407 DrawableAndVisibleContentRectsForLayersClippedByLayer
) {
2408 LayerImpl
* root
= root_layer();
2409 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
2410 LayerImpl
* grand_child1
= AddChild
<LayerImpl
>(child
);
2411 grand_child1
->SetDrawsContent(true);
2412 LayerImpl
* grand_child2
= AddChild
<LayerImpl
>(child
);
2413 grand_child2
->SetDrawsContent(true);
2414 LayerImpl
* grand_child3
= AddChild
<LayerImpl
>(child
);
2415 grand_child3
->SetDrawsContent(true);
2417 gfx::Transform identity_matrix
;
2418 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2419 gfx::PointF(), gfx::Size(100, 100), true, false,
2421 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
2422 gfx::PointF(), gfx::Size(100, 100), true, false,
2424 SetLayerPropertiesForTesting(grand_child1
, identity_matrix
, gfx::Point3F(),
2425 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2427 SetLayerPropertiesForTesting(grand_child2
, identity_matrix
, gfx::Point3F(),
2428 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2430 SetLayerPropertiesForTesting(grand_child3
, identity_matrix
, gfx::Point3F(),
2431 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2432 true, false, false);
2434 child
->SetMasksToBounds(true);
2435 ExecuteCalculateDrawProperties(root
);
2437 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2438 root
->render_surface()->DrawableContentRect());
2439 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2441 // Layers that do not draw content should have empty visible content rects.
2442 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2443 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child
->visible_layer_rect());
2445 // All grandchild visible content rects should be clipped by child.
2446 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1
->visible_layer_rect());
2447 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2
->visible_layer_rect());
2448 EXPECT_TRUE(grand_child3
->visible_layer_rect().IsEmpty());
2450 // All grandchild DrawableContentRects should also be clipped by child.
2451 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1
->drawable_content_rect());
2452 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2
->drawable_content_rect());
2453 EXPECT_TRUE(grand_child3
->drawable_content_rect().IsEmpty());
2456 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectWithClippingAndScaling
) {
2457 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2458 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
2459 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
2460 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2461 root
->AddChild(child
);
2462 child
->AddChild(grand_child
);
2464 host()->SetRootLayer(root
);
2466 gfx::Transform identity_matrix
;
2467 gfx::Transform child_scale_matrix
;
2468 child_scale_matrix
.Scale(0.25f
, 0.25f
);
2469 gfx::Transform grand_child_scale_matrix
;
2470 grand_child_scale_matrix
.Scale(0.246f
, 0.246f
);
2471 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2472 gfx::PointF(), gfx::Size(100, 100), true, false);
2473 SetLayerPropertiesForTesting(child
.get(), child_scale_matrix
, gfx::Point3F(),
2474 gfx::PointF(), gfx::Size(10, 10), true, false);
2475 SetLayerPropertiesForTesting(grand_child
.get(), grand_child_scale_matrix
,
2476 gfx::Point3F(), gfx::PointF(),
2477 gfx::Size(100, 100), true, false);
2479 child
->SetMasksToBounds(true);
2480 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
2482 // The visible rect is expanded to integer coordinates in target space before
2483 // being projected back to layer space, where it is once again expanded to
2484 // integer coordinates.
2485 EXPECT_EQ(gfx::Rect(49, 49), grand_child
->visible_rect_from_property_trees());
2488 TEST_F(LayerTreeHostCommonTest
,
2489 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface
) {
2490 LayerImpl
* root
= root_layer();
2491 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
2492 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
2493 child1
->SetDrawsContent(true);
2494 LayerImpl
* child2
= AddChild
<LayerImpl
>(render_surface
);
2495 child2
->SetDrawsContent(true);
2496 LayerImpl
* child3
= AddChild
<LayerImpl
>(render_surface
);
2497 child3
->SetDrawsContent(true);
2499 gfx::Transform identity_matrix
;
2500 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2501 gfx::PointF(), gfx::Size(100, 100), true, false,
2503 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
2504 gfx::PointF(), gfx::Size(3, 4), true, false,
2506 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
2507 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2509 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
2510 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2512 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
2513 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2514 true, false, false);
2516 ExecuteCalculateDrawProperties(root
);
2518 ASSERT_TRUE(render_surface
->render_surface());
2520 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2521 root
->render_surface()->DrawableContentRect());
2522 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2524 // Layers that do not draw content should have empty visible content rects.
2525 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2526 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface
->visible_layer_rect());
2528 // An unclipped surface grows its DrawableContentRect to include all drawable
2529 // regions of the subtree.
2530 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2531 render_surface
->render_surface()->DrawableContentRect());
2533 // All layers that draw content into the unclipped surface are also unclipped.
2534 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
2535 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_layer_rect());
2536 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_layer_rect());
2538 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2539 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2540 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2543 TEST_F(LayerTreeHostCommonTest
,
2544 VisibleContentRectsForClippedSurfaceWithEmptyClip
) {
2545 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2546 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2547 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2548 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2549 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2550 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2551 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2552 root
->AddChild(child1
);
2553 root
->AddChild(child2
);
2554 root
->AddChild(child3
);
2556 host()->SetRootLayer(root
);
2558 gfx::Transform identity_matrix
;
2559 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2560 gfx::PointF(), gfx::Size(100, 100), true, false);
2561 SetLayerPropertiesForTesting(child1
.get(), identity_matrix
, gfx::Point3F(),
2562 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2564 SetLayerPropertiesForTesting(child2
.get(), identity_matrix
, gfx::Point3F(),
2565 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2567 SetLayerPropertiesForTesting(child3
.get(), identity_matrix
, gfx::Point3F(),
2568 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2571 RenderSurfaceLayerList render_surface_layer_list
;
2572 // Now set the root render surface an empty clip.
2573 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
2574 root
.get(), gfx::Size(), &render_surface_layer_list
);
2576 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
2577 ASSERT_TRUE(root
->render_surface());
2578 EXPECT_FALSE(root
->is_clipped());
2581 EXPECT_EQ(empty
, root
->render_surface()->clip_rect());
2582 EXPECT_TRUE(root
->render_surface()->is_clipped());
2584 // Visible content rect calculation will check if the target surface is
2585 // clipped or not. An empty clip rect does not indicate the render surface
2587 EXPECT_EQ(empty
, child1
->visible_layer_rect());
2588 EXPECT_EQ(empty
, child2
->visible_layer_rect());
2589 EXPECT_EQ(empty
, child3
->visible_layer_rect());
2592 TEST_F(LayerTreeHostCommonTest
,
2593 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform
) {
2594 LayerImpl
* root
= root_layer();
2595 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
2596 child
->SetDrawsContent(true);
2598 // Case 1: a truly degenerate matrix
2599 gfx::Transform identity_matrix
;
2600 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2601 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2603 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2604 gfx::PointF(), gfx::Size(100, 100), true, false,
2606 SetLayerPropertiesForTesting(child
, uninvertible_matrix
, gfx::Point3F(),
2607 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2610 ExecuteCalculateDrawProperties(root
);
2612 EXPECT_TRUE(child
->visible_layer_rect().IsEmpty());
2613 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2615 // Case 2: a matrix with flattened z, uninvertible and not visible according
2617 uninvertible_matrix
.MakeIdentity();
2618 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2619 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2621 SetLayerPropertiesForTesting(child
, uninvertible_matrix
, gfx::Point3F(),
2622 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2625 ExecuteCalculateDrawProperties(root
);
2627 EXPECT_TRUE(child
->visible_layer_rect().IsEmpty());
2628 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2630 // Case 3: a matrix with flattened z, also uninvertible and not visible.
2631 uninvertible_matrix
.MakeIdentity();
2632 uninvertible_matrix
.Translate(500.0, 0.0);
2633 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2634 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2636 SetLayerPropertiesForTesting(child
, uninvertible_matrix
, gfx::Point3F(),
2637 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2640 ExecuteCalculateDrawProperties(root
);
2642 EXPECT_TRUE(child
->visible_layer_rect().IsEmpty());
2643 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2646 TEST_F(LayerTreeHostCommonTest
,
2647 VisibleContentRectForLayerWithUninvertibleDrawTransform
) {
2648 LayerImpl
* root
= root_layer();
2649 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
2650 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
2651 child
->SetDrawsContent(true);
2652 grand_child
->SetDrawsContent(true);
2654 gfx::Transform identity_matrix
;
2656 gfx::Transform perspective
;
2657 perspective
.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
2659 gfx::Transform rotation
;
2660 rotation
.RotateAboutYAxis(45.0);
2662 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2663 gfx::PointF(), gfx::Size(100, 100), true, false,
2665 SetLayerPropertiesForTesting(child
, perspective
, gfx::Point3F(),
2666 gfx::PointF(10.f
, 10.f
), gfx::Size(100, 100),
2667 false, true, false);
2668 SetLayerPropertiesForTesting(grand_child
, rotation
, gfx::Point3F(),
2669 gfx::PointF(), gfx::Size(100, 100), false, true,
2672 ExecuteCalculateDrawProperties(root
);
2674 // Though all layers have invertible transforms, matrix multiplication using
2675 // floating-point math makes the draw transform uninvertible.
2676 EXPECT_FALSE(grand_child
->draw_transform().IsInvertible());
2678 // CalcDrawProps only skips a subtree when a layer's own transform is
2679 // uninvertible, not when its draw transform is invertible, since CDP makes
2680 // skipping decisions before computing a layer's draw transform. Property
2681 // trees make skipping decisions after computing draw transforms, so could be
2682 // made to skip layers with an uninvertible draw transform (once CDP is
2684 EXPECT_EQ(gfx::Rect(grand_child
->bounds()),
2685 grand_child
->visible_layer_rect());
2688 TEST_F(LayerTreeHostCommonTest
,
2689 OcclusionForLayerWithUninvertibleDrawTransform
) {
2690 FakeImplProxy proxy
;
2691 TestSharedBitmapManager shared_bitmap_manager
;
2692 TestTaskGraphRunner task_graph_runner
;
2693 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
2694 &task_graph_runner
);
2695 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
2696 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 2);
2697 scoped_ptr
<LayerImpl
> grand_child
=
2698 LayerImpl::Create(host_impl
.active_tree(), 3);
2699 scoped_ptr
<LayerImpl
> occluding_child
=
2700 LayerImpl::Create(host_impl
.active_tree(), 4);
2701 child
->SetDrawsContent(true);
2702 grand_child
->SetDrawsContent(true);
2703 occluding_child
->SetDrawsContent(true);
2704 occluding_child
->SetContentsOpaque(true);
2706 gfx::Transform identity_matrix
;
2707 gfx::Transform perspective
;
2708 perspective
.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
2710 gfx::Transform rotation
;
2711 rotation
.RotateAboutYAxis(45.0);
2713 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2714 gfx::PointF(), gfx::Size(1000, 1000), true,
2716 SetLayerPropertiesForTesting(child
.get(), perspective
, gfx::Point3F(),
2717 gfx::PointF(10.f
, 10.f
), gfx::Size(300, 300),
2718 false, true, false);
2719 SetLayerPropertiesForTesting(grand_child
.get(), rotation
, gfx::Point3F(),
2720 gfx::PointF(), gfx::Size(200, 200), false, true,
2722 SetLayerPropertiesForTesting(occluding_child
.get(), identity_matrix
,
2723 gfx::Point3F(), gfx::PointF(),
2724 gfx::Size(200, 200), false, false, false);
2726 host_impl
.SetViewportSize(root
->bounds());
2728 child
->AddChild(grand_child
.Pass());
2729 root
->AddChild(child
.Pass());
2730 root
->AddChild(occluding_child
.Pass());
2731 host_impl
.active_tree()->SetRootLayer(root
.Pass());
2732 host_impl
.InitializeRenderer(FakeOutputSurface::Create3d());
2733 bool update_lcd_text
= false;
2734 host_impl
.active_tree()->UpdateDrawProperties(update_lcd_text
);
2736 LayerImpl
* grand_child_ptr
=
2737 host_impl
.active_tree()->root_layer()->children()[0]->children()[0];
2739 // Though all layers have invertible transforms, matrix multiplication using
2740 // floating-point math makes the draw transform uninvertible.
2741 EXPECT_FALSE(grand_child_ptr
->draw_transform().IsInvertible());
2743 // Since |grand_child| has an uninvertible draw transform, it is treated as
2744 // unoccluded (even though |occluding_child| comes later in draw order, and
2745 // hence potentially occludes it).
2746 gfx::Rect layer_bounds
= gfx::Rect(grand_child_ptr
->bounds());
2749 grand_child_ptr
->draw_properties()
2750 .occlusion_in_content_space
.GetUnoccludedContentRect(layer_bounds
));
2753 TEST_F(LayerTreeHostCommonTest
,
2754 SingularTransformDoesNotPreventClearingDrawProperties
) {
2755 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2756 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2757 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2758 root
->AddChild(child
);
2760 host()->SetRootLayer(root
);
2762 gfx::Transform identity_matrix
;
2763 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2764 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2766 SetLayerPropertiesForTesting(root
.get(),
2767 uninvertible_matrix
,
2770 gfx::Size(100, 100),
2773 SetLayerPropertiesForTesting(child
.get(),
2776 gfx::PointF(5.f
, 5.f
),
2781 child
->set_sorted_for_recursion(true);
2783 TransformOperations start_transform_operations
;
2784 start_transform_operations
.AppendScale(1.f
, 0.f
, 0.f
);
2786 TransformOperations end_transform_operations
;
2787 end_transform_operations
.AppendScale(1.f
, 1.f
, 0.f
);
2789 AddAnimatedTransformToLayer(
2790 root
.get(), 10.0, start_transform_operations
, end_transform_operations
);
2792 EXPECT_TRUE(root
->TransformIsAnimating());
2794 ExecuteCalculateDrawProperties(root
.get());
2796 EXPECT_FALSE(child
->sorted_for_recursion());
2799 TEST_F(LayerTreeHostCommonTest
,
2800 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties
) {
2801 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2803 host()->SetRootLayer(root
);
2805 gfx::Transform identity_matrix
;
2806 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2807 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2809 SetLayerPropertiesForTesting(root
.get(),
2810 uninvertible_matrix
,
2813 gfx::Size(100, 100),
2817 root
->set_sorted_for_recursion(true);
2819 EXPECT_FALSE(root
->TransformIsAnimating());
2821 ExecuteCalculateDrawProperties(root
.get());
2823 EXPECT_FALSE(root
->sorted_for_recursion());
2826 TEST_F(LayerTreeHostCommonTest
,
2827 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface
) {
2828 LayerImpl
* root
= root_layer();
2829 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
2830 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
2831 child1
->SetDrawsContent(true);
2832 LayerImpl
* child2
= AddChild
<LayerImpl
>(render_surface
);
2833 child2
->SetDrawsContent(true);
2834 LayerImpl
* child3
= AddChild
<LayerImpl
>(render_surface
);
2835 child3
->SetDrawsContent(true);
2837 gfx::Transform identity_matrix
;
2838 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2839 gfx::PointF(), gfx::Size(100, 100), true, false,
2841 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
2842 gfx::PointF(), gfx::Size(3, 4), true, false,
2844 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
2845 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2847 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
2848 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2850 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
2851 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2852 true, false, false);
2854 root
->SetMasksToBounds(true);
2856 ExecuteCalculateDrawProperties(root
);
2858 ASSERT_TRUE(render_surface
->render_surface());
2860 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2861 root
->render_surface()->DrawableContentRect());
2862 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2864 // Layers that do not draw content should have empty visible content rects.
2865 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2866 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface
->visible_layer_rect());
2868 // A clipped surface grows its DrawableContentRect to include all drawable
2869 // regions of the subtree, but also gets clamped by the ancestor's clip.
2870 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
2871 render_surface
->render_surface()->DrawableContentRect());
2873 // All layers that draw content into the surface have their visible content
2874 // rect clipped by the surface clip rect.
2875 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
2876 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_layer_rect());
2877 EXPECT_TRUE(child3
->visible_layer_rect().IsEmpty());
2879 // But the DrawableContentRects are unclipped.
2880 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2881 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2882 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2885 TEST_F(LayerTreeHostCommonTest
,
2886 DrawableAndVisibleContentRectsForSurfaceHierarchy
) {
2887 // Check that clipping does not propagate down surfaces.
2888 LayerImpl
* root
= root_layer();
2889 LayerImpl
* render_surface1
= AddChildToRoot
<LayerImpl
>();
2890 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(render_surface1
);
2891 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface2
);
2892 child1
->SetDrawsContent(true);
2893 LayerImpl
* child2
= AddChild
<LayerImpl
>(render_surface2
);
2894 child2
->SetDrawsContent(true);
2895 LayerImpl
* child3
= AddChild
<LayerImpl
>(render_surface2
);
2896 child3
->SetDrawsContent(true);
2898 gfx::Transform identity_matrix
;
2899 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2900 gfx::PointF(), gfx::Size(100, 100), true, false,
2902 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
2903 gfx::PointF(), gfx::Size(3, 4), true, false,
2905 SetLayerPropertiesForTesting(render_surface2
, identity_matrix
, gfx::Point3F(),
2906 gfx::PointF(), gfx::Size(7, 13), true, false,
2908 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
2909 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2911 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
2912 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2914 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
2915 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2916 true, false, false);
2918 root
->SetMasksToBounds(true);
2920 ExecuteCalculateDrawProperties(root
);
2922 ASSERT_TRUE(render_surface1
->render_surface());
2923 ASSERT_TRUE(render_surface2
->render_surface());
2925 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2926 root
->render_surface()->DrawableContentRect());
2927 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2929 // Layers that do not draw content should have empty visible content rects.
2930 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2931 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_layer_rect());
2932 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2
->visible_layer_rect());
2934 // A clipped surface grows its DrawableContentRect to include all drawable
2935 // regions of the subtree, but also gets clamped by the ancestor's clip.
2936 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
2937 render_surface1
->render_surface()->DrawableContentRect());
2939 // render_surface1 lives in the "unclipped universe" of render_surface1, and
2940 // is only implicitly clipped by render_surface1's content rect. So,
2941 // render_surface2 grows to enclose all drawable content of its subtree.
2942 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2943 render_surface2
->render_surface()->DrawableContentRect());
2945 // All layers that draw content into render_surface2 think they are unclipped.
2946 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
2947 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_layer_rect());
2948 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_layer_rect());
2950 // DrawableContentRects are also unclipped.
2951 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2952 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2953 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2956 TEST_F(LayerTreeHostCommonTest
,
2957 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface
) {
2958 // Layers that have non-axis aligned bounds (due to transforms) have an
2959 // expanded, axis-aligned DrawableContentRect and visible content rect.
2960 LayerImpl
* root
= root_layer();
2961 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
2962 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
2963 child1
->SetDrawsContent(true);
2965 gfx::Transform identity_matrix
;
2966 gfx::Transform child_rotation
;
2967 child_rotation
.Rotate(45.0);
2968 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2969 gfx::PointF(), gfx::Size(100, 100), true, false,
2971 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
2972 gfx::PointF(), gfx::Size(3, 4), true, false,
2974 SetLayerPropertiesForTesting(
2975 child1
, child_rotation
, gfx::Point3F(25, 25, 0.f
),
2976 gfx::PointF(25.f
, 25.f
), gfx::Size(50, 50), true, false, false);
2978 ExecuteCalculateDrawProperties(root
);
2980 ASSERT_TRUE(render_surface
->render_surface());
2982 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2983 root
->render_surface()->DrawableContentRect());
2984 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2986 // Layers that do not draw content should have empty visible content rects.
2987 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2988 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface
->visible_layer_rect());
2990 // The unclipped surface grows its DrawableContentRect to include all drawable
2991 // regions of the subtree.
2992 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
2993 gfx::Rect expected_surface_drawable_content
=
2994 gfx::Rect(50 - diagonal_radius
,
2995 50 - diagonal_radius
,
2996 diagonal_radius
* 2,
2997 diagonal_radius
* 2);
2998 EXPECT_EQ(expected_surface_drawable_content
,
2999 render_surface
->render_surface()->DrawableContentRect());
3001 // All layers that draw content into the unclipped surface are also unclipped.
3002 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
3003 EXPECT_EQ(expected_surface_drawable_content
, child1
->drawable_content_rect());
3006 TEST_F(LayerTreeHostCommonTest
,
3007 DrawableAndVisibleContentRectsWithTransformOnClippedSurface
) {
3008 // Layers that have non-axis aligned bounds (due to transforms) have an
3009 // expanded, axis-aligned DrawableContentRect and visible content rect.
3010 LayerImpl
* root
= root_layer();
3011 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
3012 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
3013 child1
->SetDrawsContent(true);
3015 gfx::Transform identity_matrix
;
3016 gfx::Transform child_rotation
;
3017 child_rotation
.Rotate(45.0);
3018 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
3019 gfx::PointF(), gfx::Size(50, 50), true, false,
3021 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
3022 gfx::PointF(), gfx::Size(3, 4), true, false,
3025 SetLayerPropertiesForTesting(
3026 child1
, child_rotation
, gfx::Point3F(25, 25, 0.f
),
3027 gfx::PointF(25.f
, 25.f
), gfx::Size(50, 50), true, false, false);
3029 root
->SetMasksToBounds(true);
3031 ExecuteCalculateDrawProperties(root
);
3033 ASSERT_TRUE(render_surface
->render_surface());
3035 // The clipped surface clamps the DrawableContentRect that encloses the
3037 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3038 gfx::Rect unclipped_surface_content
= gfx::Rect(50 - diagonal_radius
,
3039 50 - diagonal_radius
,
3040 diagonal_radius
* 2,
3041 diagonal_radius
* 2);
3042 gfx::Rect expected_surface_drawable_content
=
3043 gfx::IntersectRects(unclipped_surface_content
, gfx::Rect(0, 0, 50, 50));
3044 EXPECT_EQ(expected_surface_drawable_content
,
3045 render_surface
->render_surface()->DrawableContentRect());
3047 // On the clipped surface, only a quarter of the child1 is visible, but when
3048 // rotating it back to child1's content space, the actual enclosing rect ends
3049 // up covering the full left half of child1.
3051 // Given the floating point math, this number is a little bit fuzzy.
3052 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1
->visible_layer_rect());
3054 // The child's DrawableContentRect is unclipped.
3055 EXPECT_EQ(unclipped_surface_content
, child1
->drawable_content_rect());
3058 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsInHighDPI
) {
3059 LayerImpl
* root
= root_layer();
3060 FakePictureLayerImpl
* render_surface1
=
3061 AddChildToRoot
<FakePictureLayerImpl
>();
3062 render_surface1
->SetDrawsContent(true);
3063 FakePictureLayerImpl
* render_surface2
=
3064 AddChild
<FakePictureLayerImpl
>(render_surface1
);
3065 render_surface2
->SetDrawsContent(true);
3066 FakePictureLayerImpl
* child1
=
3067 AddChild
<FakePictureLayerImpl
>(render_surface2
);
3068 child1
->SetDrawsContent(true);
3069 FakePictureLayerImpl
* child2
=
3070 AddChild
<FakePictureLayerImpl
>(render_surface2
);
3071 child2
->SetDrawsContent(true);
3072 FakePictureLayerImpl
* child3
=
3073 AddChild
<FakePictureLayerImpl
>(render_surface2
);
3074 child3
->SetDrawsContent(true);
3076 gfx::Transform identity_matrix
;
3077 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
3078 gfx::PointF(), gfx::Size(100, 100), true, false,
3080 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
3081 gfx::PointF(5.f
, 5.f
), gfx::Size(3, 4), true,
3083 SetLayerPropertiesForTesting(render_surface2
, identity_matrix
, gfx::Point3F(),
3084 gfx::PointF(5.f
, 5.f
), gfx::Size(7, 13), true,
3086 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
3087 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
3089 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
3090 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
3092 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
3093 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
3094 true, false, false);
3096 float device_scale_factor
= 2.f
;
3098 root
->SetMasksToBounds(true);
3100 ExecuteCalculateDrawProperties(root
, device_scale_factor
);
3102 ASSERT_TRUE(render_surface1
->render_surface());
3103 ASSERT_TRUE(render_surface2
->render_surface());
3105 // drawable_content_rects for all layers and surfaces are scaled by
3106 // device_scale_factor.
3107 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
3108 root
->render_surface()->DrawableContentRect());
3109 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root
->drawable_content_rect());
3110 EXPECT_EQ(gfx::Rect(10, 10, 190, 190),
3111 render_surface1
->render_surface()->DrawableContentRect());
3113 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3114 // is only implicitly clipped by render_surface1.
3115 EXPECT_EQ(gfx::Rect(10, 10, 350, 350),
3116 render_surface2
->render_surface()->DrawableContentRect());
3118 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1
->drawable_content_rect());
3119 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2
->drawable_content_rect());
3120 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3
->drawable_content_rect());
3122 // The root layer does not actually draw content of its own.
3123 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
3125 // All layer visible content rects are not expressed in content space of each
3126 // layer, so they are not scaled by the device_scale_factor.
3127 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1
->visible_layer_rect());
3128 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2
->visible_layer_rect());
3129 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
3130 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_layer_rect());
3131 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_layer_rect());
3134 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithoutPreserves3d
) {
3135 // Verify the behavior of back-face culling when there are no preserve-3d
3136 // layers. Note that 3d transforms still apply in this case, but they are
3137 // "flattened" to each parent layer according to current W3C spec.
3139 const gfx::Transform identity_matrix
;
3140 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3141 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3142 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3143 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3144 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3145 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3146 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3147 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3148 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3149 scoped_refptr
<LayerWithForcedDrawsContent
>
3150 front_facing_child_of_front_facing_surface
=
3151 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3152 scoped_refptr
<LayerWithForcedDrawsContent
>
3153 back_facing_child_of_front_facing_surface
=
3154 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3155 scoped_refptr
<LayerWithForcedDrawsContent
>
3156 front_facing_child_of_back_facing_surface
=
3157 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3158 scoped_refptr
<LayerWithForcedDrawsContent
>
3159 back_facing_child_of_back_facing_surface
=
3160 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3162 parent
->AddChild(front_facing_child
);
3163 parent
->AddChild(back_facing_child
);
3164 parent
->AddChild(front_facing_surface
);
3165 parent
->AddChild(back_facing_surface
);
3166 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3167 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3168 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3169 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3171 host()->SetRootLayer(parent
);
3173 // Nothing is double-sided
3174 front_facing_child
->SetDoubleSided(false);
3175 back_facing_child
->SetDoubleSided(false);
3176 front_facing_surface
->SetDoubleSided(false);
3177 back_facing_surface
->SetDoubleSided(false);
3178 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3179 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3180 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3181 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3183 gfx::Transform backface_matrix
;
3184 backface_matrix
.Translate(50.0, 50.0);
3185 backface_matrix
.RotateAboutYAxis(180.0);
3186 backface_matrix
.Translate(-50.0, -50.0);
3188 // Having a descendant and opacity will force these to have render surfaces.
3189 front_facing_surface
->SetOpacity(0.5f
);
3190 back_facing_surface
->SetOpacity(0.5f
);
3192 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3193 // these layers should blindly use their own local transforms to determine
3194 // back-face culling.
3195 SetLayerPropertiesForTesting(parent
.get(),
3199 gfx::Size(100, 100),
3202 SetLayerPropertiesForTesting(front_facing_child
.get(),
3206 gfx::Size(100, 100),
3209 SetLayerPropertiesForTesting(back_facing_child
.get(),
3213 gfx::Size(100, 100),
3216 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3220 gfx::Size(100, 100),
3223 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3227 gfx::Size(100, 100),
3230 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3234 gfx::Size(100, 100),
3237 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3241 gfx::Size(100, 100),
3244 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3248 gfx::Size(100, 100),
3251 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3255 gfx::Size(100, 100),
3259 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3261 // Verify which render surfaces were created.
3262 EXPECT_FALSE(front_facing_child
->render_surface());
3263 EXPECT_FALSE(back_facing_child
->render_surface());
3264 EXPECT_TRUE(front_facing_surface
->render_surface());
3265 EXPECT_TRUE(back_facing_surface
->render_surface());
3266 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3267 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3268 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3269 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3271 EXPECT_EQ(4u, update_layer_list().size());
3272 EXPECT_TRUE(UpdateLayerListContains(front_facing_child
->id()));
3273 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface
->id()));
3274 EXPECT_TRUE(UpdateLayerListContains(
3275 front_facing_child_of_front_facing_surface
->id()));
3277 UpdateLayerListContains(front_facing_child_of_back_facing_surface
->id()));
3280 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithPreserves3d
) {
3281 // Verify the behavior of back-face culling when preserves-3d transform style
3284 const gfx::Transform identity_matrix
;
3285 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3286 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3287 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3288 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3289 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3290 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3291 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3292 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3293 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3294 scoped_refptr
<LayerWithForcedDrawsContent
>
3295 front_facing_child_of_front_facing_surface
=
3296 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3297 scoped_refptr
<LayerWithForcedDrawsContent
>
3298 back_facing_child_of_front_facing_surface
=
3299 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3300 scoped_refptr
<LayerWithForcedDrawsContent
>
3301 front_facing_child_of_back_facing_surface
=
3302 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3303 scoped_refptr
<LayerWithForcedDrawsContent
>
3304 back_facing_child_of_back_facing_surface
=
3305 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3306 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer1
=
3307 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3308 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer2
=
3309 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3311 parent
->AddChild(front_facing_child
);
3312 parent
->AddChild(back_facing_child
);
3313 parent
->AddChild(front_facing_surface
);
3314 parent
->AddChild(back_facing_surface
);
3315 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3316 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3317 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3318 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3320 host()->SetRootLayer(parent
);
3322 // Nothing is double-sided
3323 front_facing_child
->SetDoubleSided(false);
3324 back_facing_child
->SetDoubleSided(false);
3325 front_facing_surface
->SetDoubleSided(false);
3326 back_facing_surface
->SetDoubleSided(false);
3327 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3328 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3329 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3330 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3332 gfx::Transform backface_matrix
;
3333 backface_matrix
.Translate(50.0, 50.0);
3334 backface_matrix
.RotateAboutYAxis(180.0);
3335 backface_matrix
.Translate(-50.0, -50.0);
3337 // Opacity will not force creation of render surfaces in this case because of
3338 // the preserve-3d transform style. Instead, an example of when a surface
3339 // would be created with preserve-3d is when there is a replica layer.
3340 front_facing_surface
->SetReplicaLayer(dummy_replica_layer1
.get());
3341 back_facing_surface
->SetReplicaLayer(dummy_replica_layer2
.get());
3343 // Each surface creates its own new 3d rendering context (as defined by W3C
3344 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3345 // rendering context should use the transform with respect to that context.
3346 // This 3d rendering context occurs when (a) parent's transform style is flat
3347 // and (b) the layer's transform style is preserve-3d.
3348 SetLayerPropertiesForTesting(parent
.get(),
3352 gfx::Size(100, 100),
3354 false); // parent transform style is flat.
3355 SetLayerPropertiesForTesting(front_facing_child
.get(),
3359 gfx::Size(100, 100),
3362 SetLayerPropertiesForTesting(back_facing_child
.get(),
3366 gfx::Size(100, 100),
3369 // surface transform style is preserve-3d.
3370 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3374 gfx::Size(100, 100),
3377 // surface transform style is preserve-3d.
3378 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3382 gfx::Size(100, 100),
3385 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3389 gfx::Size(100, 100),
3392 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3396 gfx::Size(100, 100),
3399 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3403 gfx::Size(100, 100),
3406 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3410 gfx::Size(100, 100),
3414 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3416 // Verify which render surfaces were created and used.
3417 EXPECT_FALSE(front_facing_child
->render_surface());
3418 EXPECT_FALSE(back_facing_child
->render_surface());
3419 EXPECT_TRUE(front_facing_surface
->render_surface());
3420 EXPECT_NE(back_facing_surface
->render_target(), back_facing_surface
);
3421 // We expect that a render_surface was created but not used.
3422 EXPECT_TRUE(back_facing_surface
->render_surface());
3423 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3424 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3425 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3426 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3428 EXPECT_EQ(3u, update_layer_list().size());
3430 EXPECT_TRUE(UpdateLayerListContains(front_facing_child
->id()));
3431 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface
->id()));
3432 EXPECT_TRUE(UpdateLayerListContains(
3433 front_facing_child_of_front_facing_surface
->id()));
3436 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithAnimatingTransforms
) {
3437 // Verify that layers are appropriately culled when their back face is showing
3438 // and they are not double sided, while animations are going on.
3440 // Layers that are animating do not get culled on the main thread, as their
3441 // transforms should be treated as "unknown" so we can not be sure that their
3442 // back face is really showing.
3443 const gfx::Transform identity_matrix
;
3444 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3445 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
3446 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3447 scoped_refptr
<LayerWithForcedDrawsContent
> animating_surface
=
3448 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3449 scoped_refptr
<LayerWithForcedDrawsContent
> child_of_animating_surface
=
3450 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3451 scoped_refptr
<LayerWithForcedDrawsContent
> animating_child
=
3452 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3453 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3454 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3456 parent
->AddChild(child
);
3457 parent
->AddChild(animating_surface
);
3458 animating_surface
->AddChild(child_of_animating_surface
);
3459 parent
->AddChild(animating_child
);
3460 parent
->AddChild(child2
);
3462 host()->SetRootLayer(parent
);
3464 // Nothing is double-sided
3465 child
->SetDoubleSided(false);
3466 child2
->SetDoubleSided(false);
3467 animating_surface
->SetDoubleSided(false);
3468 child_of_animating_surface
->SetDoubleSided(false);
3469 animating_child
->SetDoubleSided(false);
3471 gfx::Transform backface_matrix
;
3472 backface_matrix
.Translate(50.0, 50.0);
3473 backface_matrix
.RotateAboutYAxis(180.0);
3474 backface_matrix
.Translate(-50.0, -50.0);
3476 // Make our render surface.
3477 animating_surface
->SetForceRenderSurface(true);
3479 // Animate the transform on the render surface.
3480 AddAnimatedTransformToController(
3481 animating_surface
->layer_animation_controller(), 10.0, 30, 0);
3482 // This is just an animating layer, not a surface.
3483 AddAnimatedTransformToController(
3484 animating_child
->layer_animation_controller(), 10.0, 30, 0);
3486 SetLayerPropertiesForTesting(parent
.get(),
3490 gfx::Size(100, 100),
3493 SetLayerPropertiesForTesting(child
.get(),
3497 gfx::Size(100, 100),
3500 SetLayerPropertiesForTesting(animating_surface
.get(),
3504 gfx::Size(100, 100),
3507 SetLayerPropertiesForTesting(child_of_animating_surface
.get(),
3511 gfx::Size(100, 100),
3514 SetLayerPropertiesForTesting(animating_child
.get(),
3518 gfx::Size(100, 100),
3521 SetLayerPropertiesForTesting(child2
.get(),
3525 gfx::Size(100, 100),
3529 RenderSurfaceLayerList render_surface_layer_list
;
3530 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3531 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3532 inputs
.can_adjust_raster_scales
= true;
3533 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3535 EXPECT_FALSE(child
->render_surface());
3536 EXPECT_TRUE(animating_surface
->render_surface());
3537 EXPECT_FALSE(child_of_animating_surface
->render_surface());
3538 EXPECT_FALSE(animating_child
->render_surface());
3539 EXPECT_FALSE(child2
->render_surface());
3541 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3543 EXPECT_EQ(4u, update_layer_list().size());
3545 // The non-animating child be culled from the layer list for the parent render
3547 EXPECT_TRUE(UpdateLayerListContains(animating_surface
->id()));
3548 EXPECT_TRUE(UpdateLayerListContains(animating_child
->id()));
3549 EXPECT_TRUE(UpdateLayerListContains(child2
->id()));
3550 EXPECT_TRUE(UpdateLayerListContains(child_of_animating_surface
->id()));
3552 EXPECT_FALSE(child2
->visible_rect_from_property_trees().IsEmpty());
3554 // The animating layers should have a visible content rect that represents the
3555 // area of the front face that is within the viewport.
3556 EXPECT_EQ(animating_child
->visible_rect_from_property_trees(),
3557 gfx::Rect(animating_child
->bounds()));
3558 EXPECT_EQ(animating_surface
->visible_rect_from_property_trees(),
3559 gfx::Rect(animating_surface
->bounds()));
3560 // And layers in the subtree of the animating layer should have valid visible
3561 // content rects also.
3562 EXPECT_EQ(child_of_animating_surface
->visible_rect_from_property_trees(),
3563 gfx::Rect(child_of_animating_surface
->bounds()));
3566 TEST_F(LayerTreeHostCommonTest
,
3567 BackFaceCullingWithPreserves3dForFlatteningSurface
) {
3568 // Verify the behavior of back-face culling for a render surface that is
3569 // created when it flattens its subtree, and its parent has preserves-3d.
3571 const gfx::Transform identity_matrix
;
3572 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3573 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3574 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3575 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3576 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3577 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3578 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3579 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3580 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3582 parent
->AddChild(front_facing_surface
);
3583 parent
->AddChild(back_facing_surface
);
3584 front_facing_surface
->AddChild(child1
);
3585 back_facing_surface
->AddChild(child2
);
3587 host()->SetRootLayer(parent
);
3589 // RenderSurfaces are not double-sided
3590 front_facing_surface
->SetDoubleSided(false);
3591 back_facing_surface
->SetDoubleSided(false);
3593 gfx::Transform backface_matrix
;
3594 backface_matrix
.Translate(50.0, 50.0);
3595 backface_matrix
.RotateAboutYAxis(180.0);
3596 backface_matrix
.Translate(-50.0, -50.0);
3598 SetLayerPropertiesForTesting(parent
.get(),
3602 gfx::Size(100, 100),
3604 true); // parent transform style is preserve3d.
3605 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3609 gfx::Size(100, 100),
3611 true); // surface transform style is flat.
3612 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3616 gfx::Size(100, 100),
3618 true); // surface transform style is flat.
3619 SetLayerPropertiesForTesting(child1
.get(),
3623 gfx::Size(100, 100),
3626 SetLayerPropertiesForTesting(child2
.get(),
3630 gfx::Size(100, 100),
3634 front_facing_surface
->Set3dSortingContextId(1);
3635 back_facing_surface
->Set3dSortingContextId(1);
3637 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3639 // Verify which render surfaces were created and used.
3640 EXPECT_TRUE(front_facing_surface
->render_surface());
3642 // We expect the render surface to have been created, but remain unused.
3643 EXPECT_TRUE(back_facing_surface
->render_surface());
3644 EXPECT_NE(back_facing_surface
->render_target(),
3645 back_facing_surface
); // because it should be culled
3646 EXPECT_FALSE(child1
->render_surface());
3647 EXPECT_FALSE(child2
->render_surface());
3649 EXPECT_EQ(2u, update_layer_list().size());
3650 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface
->id()));
3651 EXPECT_TRUE(UpdateLayerListContains(child1
->id()));
3654 TEST_F(LayerTreeHostCommonScalingTest
, LayerTransformsInHighDPI
) {
3655 // Verify draw and screen space transforms of layers not in a surface.
3656 gfx::Transform identity_matrix
;
3658 LayerImpl
* parent
= root_layer();
3659 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
3660 gfx::PointF(), gfx::Size(100, 100), false, true,
3663 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
3664 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
3665 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3668 LayerImpl
* child_empty
= AddChildToRoot
<LayerImpl
>();
3669 SetLayerPropertiesForTesting(child_empty
, identity_matrix
, gfx::Point3F(),
3670 gfx::PointF(2.f
, 2.f
), gfx::Size(), false, true,
3673 float device_scale_factor
= 2.5f
;
3674 gfx::Size
viewport_size(100, 100);
3675 ExecuteCalculateDrawProperties(parent
, device_scale_factor
);
3677 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
, parent
);
3678 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
, child
);
3679 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
, child_empty
);
3681 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
3683 // Verify parent transforms
3684 gfx::Transform expected_parent_transform
;
3685 expected_parent_transform
.Scale(device_scale_factor
, device_scale_factor
);
3686 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
3687 parent
->screen_space_transform());
3688 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
3689 parent
->draw_transform());
3691 // Verify results of transformed parent rects
3692 gfx::RectF
parent_bounds(parent
->bounds());
3694 gfx::RectF parent_draw_rect
=
3695 MathUtil::MapClippedRect(parent
->draw_transform(), parent_bounds
);
3696 gfx::RectF parent_screen_space_rect
=
3697 MathUtil::MapClippedRect(parent
->screen_space_transform(), parent_bounds
);
3699 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
3700 expected_parent_draw_rect
.Scale(device_scale_factor
);
3701 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
3702 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
3704 // Verify child and child_empty transforms. They should match.
3705 gfx::Transform expected_child_transform
;
3706 expected_child_transform
.Scale(device_scale_factor
, device_scale_factor
);
3707 expected_child_transform
.Translate(child
->position().x(),
3708 child
->position().y());
3709 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3710 child
->draw_transform());
3711 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3712 child
->screen_space_transform());
3713 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3714 child_empty
->draw_transform());
3715 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3716 child_empty
->screen_space_transform());
3718 // Verify results of transformed child and child_empty rects. They should
3720 gfx::RectF
child_bounds(child
->bounds());
3722 gfx::RectF child_draw_rect
=
3723 MathUtil::MapClippedRect(child
->draw_transform(), child_bounds
);
3724 gfx::RectF child_screen_space_rect
=
3725 MathUtil::MapClippedRect(child
->screen_space_transform(), child_bounds
);
3727 gfx::RectF child_empty_draw_rect
=
3728 MathUtil::MapClippedRect(child_empty
->draw_transform(), child_bounds
);
3729 gfx::RectF child_empty_screen_space_rect
= MathUtil::MapClippedRect(
3730 child_empty
->screen_space_transform(), child_bounds
);
3732 gfx::RectF
expected_child_draw_rect(child
->position(), child
->bounds());
3733 expected_child_draw_rect
.Scale(device_scale_factor
);
3734 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
3735 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
3736 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_draw_rect
);
3737 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_screen_space_rect
);
3740 TEST_F(LayerTreeHostCommonScalingTest
, SurfaceLayerTransformsInHighDPI
) {
3741 // Verify draw and screen space transforms of layers in a surface.
3742 gfx::Transform identity_matrix
;
3743 gfx::Transform perspective_matrix
;
3744 perspective_matrix
.ApplyPerspectiveDepth(2.0);
3746 gfx::Transform scale_small_matrix
;
3747 scale_small_matrix
.Scale(SK_MScalar1
/ 10.f
, SK_MScalar1
/ 12.f
);
3749 LayerImpl
* root
= root_layer();
3750 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
3751 gfx::PointF(), gfx::Size(100, 100), false, true,
3753 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
3754 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
3755 gfx::PointF(), gfx::Size(100, 100), false, true,
3758 LayerImpl
* perspective_surface
= AddChild
<LayerImpl
>(parent
);
3759 SetLayerPropertiesForTesting(perspective_surface
,
3760 perspective_matrix
* scale_small_matrix
,
3761 gfx::Point3F(), gfx::PointF(2.f
, 2.f
),
3762 gfx::Size(10, 10), false, true, true);
3763 perspective_surface
->SetDrawsContent(true);
3765 LayerImpl
* scale_surface
= AddChild
<LayerImpl
>(parent
);
3766 SetLayerPropertiesForTesting(scale_surface
, scale_small_matrix
,
3767 gfx::Point3F(), gfx::PointF(2.f
, 2.f
),
3768 gfx::Size(10, 10), false, true, true);
3769 scale_surface
->SetDrawsContent(true);
3771 float device_scale_factor
= 2.5f
;
3772 float page_scale_factor
= 3.f
;
3773 ExecuteCalculateDrawProperties(root
, device_scale_factor
, page_scale_factor
,
3776 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
3777 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
,
3778 perspective_surface
);
3779 // Ideal scale is the max 2d scale component of the combined transform up to
3780 // the nearest render target. Here this includes the layer transform as well
3781 // as the device and page scale factors.
3782 gfx::Transform transform
= scale_small_matrix
;
3783 transform
.Scale(device_scale_factor
* page_scale_factor
,
3784 device_scale_factor
* page_scale_factor
);
3785 gfx::Vector2dF scales
=
3786 MathUtil::ComputeTransform2dScaleComponents(transform
, 0.f
);
3787 float max_2d_scale
= std::max(scales
.x(), scales
.y());
3788 EXPECT_IDEAL_SCALE_EQ(max_2d_scale
, scale_surface
);
3790 // The ideal scale will draw 1:1 with its render target space along
3791 // the larger-scale axis.
3792 gfx::Vector2dF target_space_transform_scales
=
3793 MathUtil::ComputeTransform2dScaleComponents(
3794 scale_surface
->draw_properties().target_space_transform
, 0.f
);
3795 EXPECT_FLOAT_EQ(max_2d_scale
,
3796 std::max(target_space_transform_scales
.x(),
3797 target_space_transform_scales
.y()));
3799 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
3801 gfx::Transform expected_parent_draw_transform
;
3802 expected_parent_draw_transform
.Scale(device_scale_factor
* page_scale_factor
,
3803 device_scale_factor
* page_scale_factor
);
3804 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform
,
3805 parent
->draw_transform());
3807 // The scale for the perspective surface is not known, so it is rendered 1:1
3808 // with the screen, and then scaled during drawing.
3809 gfx::Transform expected_perspective_surface_draw_transform
;
3810 expected_perspective_surface_draw_transform
.Translate(
3811 device_scale_factor
* page_scale_factor
*
3812 perspective_surface
->position().x(),
3813 device_scale_factor
* page_scale_factor
*
3814 perspective_surface
->position().y());
3815 expected_perspective_surface_draw_transform
.PreconcatTransform(
3816 perspective_matrix
);
3817 expected_perspective_surface_draw_transform
.PreconcatTransform(
3818 scale_small_matrix
);
3819 gfx::Transform expected_perspective_surface_layer_draw_transform
;
3820 expected_perspective_surface_layer_draw_transform
.Scale(
3821 device_scale_factor
* page_scale_factor
,
3822 device_scale_factor
* page_scale_factor
);
3823 EXPECT_TRANSFORMATION_MATRIX_EQ(
3824 expected_perspective_surface_draw_transform
,
3825 perspective_surface
->render_surface()->draw_transform());
3826 EXPECT_TRANSFORMATION_MATRIX_EQ(
3827 expected_perspective_surface_layer_draw_transform
,
3828 perspective_surface
->draw_transform());
3831 TEST_F(LayerTreeHostCommonScalingTest
, SmallIdealScale
) {
3832 gfx::Transform parent_scale_matrix
;
3833 SkMScalar initial_parent_scale
= 1.75;
3834 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
3836 gfx::Transform child_scale_matrix
;
3837 SkMScalar initial_child_scale
= 0.25;
3838 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
3840 LayerImpl
* root
= root_layer();
3841 root
->SetBounds(gfx::Size(100, 100));
3843 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
3844 SetLayerPropertiesForTesting(parent
, parent_scale_matrix
, gfx::Point3F(),
3845 gfx::PointF(), gfx::Size(100, 100), false, true,
3848 LayerImpl
* child_scale
= AddChild
<LayerImpl
>(parent
);
3849 SetLayerPropertiesForTesting(child_scale
, child_scale_matrix
, gfx::Point3F(),
3850 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3853 float device_scale_factor
= 2.5f
;
3854 float page_scale_factor
= 0.01f
;
3857 ExecuteCalculateDrawProperties(root
, device_scale_factor
, page_scale_factor
,
3860 // The ideal scale is able to go below 1.
3861 float expected_ideal_scale
=
3862 device_scale_factor
* page_scale_factor
* initial_parent_scale
;
3863 EXPECT_LT(expected_ideal_scale
, 1.f
);
3864 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, parent
);
3866 expected_ideal_scale
= device_scale_factor
* page_scale_factor
*
3867 initial_parent_scale
* initial_child_scale
;
3868 EXPECT_LT(expected_ideal_scale
, 1.f
);
3869 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, child_scale
);
3873 TEST_F(LayerTreeHostCommonScalingTest
, IdealScaleForAnimatingLayer
) {
3874 gfx::Transform parent_scale_matrix
;
3875 SkMScalar initial_parent_scale
= 1.75;
3876 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
3878 gfx::Transform child_scale_matrix
;
3879 SkMScalar initial_child_scale
= 1.25;
3880 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
3882 LayerImpl
* root
= root_layer();
3883 root
->SetBounds(gfx::Size(100, 100));
3885 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
3886 SetLayerPropertiesForTesting(parent
, parent_scale_matrix
, gfx::Point3F(),
3887 gfx::PointF(), gfx::Size(100, 100), false, true,
3890 LayerImpl
* child_scale
= AddChild
<LayerImpl
>(parent
);
3891 SetLayerPropertiesForTesting(child_scale
, child_scale_matrix
, gfx::Point3F(),
3892 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3896 ExecuteCalculateDrawProperties(root
);
3898 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale
, parent
);
3899 // Animating layers compute ideal scale in the same way as when
3901 EXPECT_IDEAL_SCALE_EQ(initial_child_scale
* initial_parent_scale
,
3906 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceTransformsInHighDPI
) {
3907 gfx::Transform identity_matrix
;
3909 LayerImpl
* parent
= root_layer();
3910 parent
->SetDrawsContent(true);
3911 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
3912 gfx::PointF(), gfx::Size(30, 30), false, true,
3915 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
3916 child
->SetDrawsContent(true);
3917 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
3918 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3921 gfx::Transform replica_transform
;
3922 replica_transform
.Scale(1.0, -1.0);
3924 scoped_ptr
<LayerImpl
> replica
=
3925 LayerImpl::Create(host_impl()->active_tree(), 7);
3926 SetLayerPropertiesForTesting(replica
.get(), replica_transform
, gfx::Point3F(),
3927 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3929 child
->SetReplicaLayer(replica
.Pass());
3931 // This layer should end up in the same surface as child, with the same draw
3932 // and screen space transforms.
3933 LayerImpl
* duplicate_child_non_owner
= AddChild
<LayerImpl
>(child
);
3934 duplicate_child_non_owner
->SetDrawsContent(true);
3935 SetLayerPropertiesForTesting(duplicate_child_non_owner
, identity_matrix
,
3936 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
3937 false, true, false);
3939 float device_scale_factor
= 1.5f
;
3940 ExecuteCalculateDrawProperties(parent
, device_scale_factor
);
3942 // We should have two render surfaces. The root's render surface and child's
3943 // render surface (it needs one because it has a replica layer).
3944 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
3946 gfx::Transform expected_parent_transform
;
3947 expected_parent_transform
.Scale(device_scale_factor
, device_scale_factor
);
3948 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
3949 parent
->screen_space_transform());
3950 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
3951 parent
->draw_transform());
3953 gfx::Transform expected_draw_transform
;
3954 expected_draw_transform
.Scale(device_scale_factor
, device_scale_factor
);
3955 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform
,
3956 child
->draw_transform());
3958 gfx::Transform expected_screen_space_transform
;
3959 expected_screen_space_transform
.Scale(device_scale_factor
,
3960 device_scale_factor
);
3961 expected_screen_space_transform
.Translate(child
->position().x(),
3962 child
->position().y());
3963 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform
,
3964 child
->screen_space_transform());
3966 gfx::Transform expected_duplicate_child_draw_transform
=
3967 child
->draw_transform();
3968 EXPECT_TRANSFORMATION_MATRIX_EQ(child
->draw_transform(),
3969 duplicate_child_non_owner
->draw_transform());
3970 EXPECT_TRANSFORMATION_MATRIX_EQ(
3971 child
->screen_space_transform(),
3972 duplicate_child_non_owner
->screen_space_transform());
3973 EXPECT_EQ(child
->drawable_content_rect(),
3974 duplicate_child_non_owner
->drawable_content_rect());
3975 EXPECT_EQ(child
->bounds(), duplicate_child_non_owner
->bounds());
3977 gfx::Transform expected_render_surface_draw_transform
;
3978 expected_render_surface_draw_transform
.Translate(
3979 device_scale_factor
* child
->position().x(),
3980 device_scale_factor
* child
->position().y());
3981 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform
,
3982 child
->render_surface()->draw_transform());
3984 gfx::Transform expected_surface_draw_transform
;
3985 expected_surface_draw_transform
.Translate(device_scale_factor
* 2.f
,
3986 device_scale_factor
* 2.f
);
3987 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform
,
3988 child
->render_surface()->draw_transform());
3990 gfx::Transform expected_surface_screen_space_transform
;
3991 expected_surface_screen_space_transform
.Translate(device_scale_factor
* 2.f
,
3992 device_scale_factor
* 2.f
);
3993 EXPECT_TRANSFORMATION_MATRIX_EQ(
3994 expected_surface_screen_space_transform
,
3995 child
->render_surface()->screen_space_transform());
3997 gfx::Transform expected_replica_draw_transform
;
3998 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
3999 expected_replica_draw_transform
.matrix().set(0, 3, 6.0);
4000 expected_replica_draw_transform
.matrix().set(1, 3, 6.0);
4001 EXPECT_TRANSFORMATION_MATRIX_EQ(
4002 expected_replica_draw_transform
,
4003 child
->render_surface()->replica_draw_transform());
4005 gfx::Transform expected_replica_screen_space_transform
;
4006 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
4007 expected_replica_screen_space_transform
.matrix().set(0, 3, 6.0);
4008 expected_replica_screen_space_transform
.matrix().set(1, 3, 6.0);
4009 EXPECT_TRANSFORMATION_MATRIX_EQ(
4010 expected_replica_screen_space_transform
,
4011 child
->render_surface()->replica_screen_space_transform());
4012 EXPECT_TRANSFORMATION_MATRIX_EQ(
4013 expected_replica_screen_space_transform
,
4014 child
->render_surface()->replica_screen_space_transform());
4017 TEST_F(LayerTreeHostCommonTest
,
4018 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition
) {
4019 gfx::Transform identity_matrix
;
4021 LayerImpl
* parent
= root_layer();
4022 parent
->SetDrawsContent(true);
4023 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
4024 gfx::PointF(), gfx::Size(33, 31), false, true,
4027 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
4028 child
->SetDrawsContent(true);
4029 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
4030 gfx::PointF(), gfx::Size(13, 11), false, true,
4033 gfx::Transform replica_transform
;
4034 replica_transform
.Scale(1.0, -1.0);
4035 scoped_ptr
<LayerImpl
> replica
=
4036 LayerImpl::Create(host_impl()->active_tree(), 7);
4037 SetLayerPropertiesForTesting(replica
.get(), replica_transform
, gfx::Point3F(),
4038 gfx::PointF(), gfx::Size(13, 11), false, true,
4040 child
->SetReplicaLayer(replica
.Pass());
4042 float device_scale_factor
= 1.7f
;
4043 ExecuteCalculateDrawProperties(parent
, device_scale_factor
);
4045 // We should have two render surfaces. The root's render surface and child's
4046 // render surface (it needs one because it has a replica layer).
4047 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
4049 gfx::Transform identity_transform
;
4050 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
4051 child
->render_surface()->draw_transform());
4052 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
4053 child
->render_surface()->draw_transform());
4054 EXPECT_TRANSFORMATION_MATRIX_EQ(
4055 identity_transform
, child
->render_surface()->screen_space_transform());
4057 gfx::Transform expected_replica_draw_transform
;
4058 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
4059 EXPECT_TRANSFORMATION_MATRIX_EQ(
4060 expected_replica_draw_transform
,
4061 child
->render_surface()->replica_draw_transform());
4063 gfx::Transform expected_replica_screen_space_transform
;
4064 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
4065 EXPECT_TRANSFORMATION_MATRIX_EQ(
4066 expected_replica_screen_space_transform
,
4067 child
->render_surface()->replica_screen_space_transform());
4070 TEST_F(LayerTreeHostCommonTest
, SubtreeSearch
) {
4071 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4072 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
4073 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
4074 scoped_refptr
<Layer
> mask_layer
= Layer::Create(layer_settings());
4075 scoped_refptr
<Layer
> replica_layer
= Layer::Create(layer_settings());
4077 grand_child
->SetReplicaLayer(replica_layer
.get());
4078 child
->AddChild(grand_child
.get());
4079 child
->SetMaskLayer(mask_layer
.get());
4080 root
->AddChild(child
.get());
4082 host()->SetRootLayer(root
);
4084 int nonexistent_id
= -1;
4085 EXPECT_EQ(root
.get(),
4086 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), root
->id()));
4087 EXPECT_EQ(child
.get(),
4088 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), child
->id()));
4091 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), grand_child
->id()));
4094 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), mask_layer
->id()));
4096 replica_layer
.get(),
4097 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), replica_layer
->id()));
4099 0, LayerTreeHostCommon::FindLayerInSubtree(root
.get(), nonexistent_id
));
4102 TEST_F(LayerTreeHostCommonTest
, TransparentChildRenderSurfaceCreation
) {
4103 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4104 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
4105 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
4106 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4108 const gfx::Transform identity_matrix
;
4109 SetLayerPropertiesForTesting(root
.get(),
4113 gfx::Size(100, 100),
4116 SetLayerPropertiesForTesting(child
.get(),
4123 SetLayerPropertiesForTesting(grand_child
.get(),
4131 root
->AddChild(child
);
4132 child
->AddChild(grand_child
);
4133 child
->SetOpacity(0.5f
);
4135 host()->SetRootLayer(root
);
4137 ExecuteCalculateDrawProperties(root
.get());
4139 EXPECT_FALSE(child
->render_surface());
4142 TEST_F(LayerTreeHostCommonTest
, OpacityAnimatingOnPendingTree
) {
4143 FakeImplProxy proxy
;
4144 TestSharedBitmapManager shared_bitmap_manager
;
4145 TestTaskGraphRunner task_graph_runner
;
4146 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4147 &task_graph_runner
);
4148 host_impl
.CreatePendingTree();
4149 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4151 const gfx::Transform identity_matrix
;
4152 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4153 gfx::PointF(), gfx::Size(100, 100), true, false,
4155 root
->SetDrawsContent(true);
4157 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
4158 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
4159 gfx::PointF(), gfx::Size(50, 50), true, false,
4161 child
->SetDrawsContent(true);
4162 child
->SetOpacity(0.0f
);
4164 // Add opacity animation.
4165 AddOpacityTransitionToController(
4166 child
->layer_animation_controller(), 10.0, 0.0f
, 1.0f
, false);
4168 root
->AddChild(child
.Pass());
4169 root
->SetHasRenderSurface(true);
4171 LayerImplList render_surface_layer_list
;
4172 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4173 root
.get(), root
->bounds(), &render_surface_layer_list
);
4174 inputs
.can_adjust_raster_scales
= true;
4175 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4177 // We should have one render surface and two layers. The child
4178 // layer should be included even though it is transparent.
4179 ASSERT_EQ(1u, render_surface_layer_list
.size());
4180 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
4183 using LCDTextTestParam
= std::tr1::tuple
<bool, bool, bool>;
4184 class LCDTextTest
: public LayerTreeHostCommonTestBase
,
4185 public testing::TestWithParam
<LCDTextTestParam
> {
4188 : LayerTreeHostCommonTestBase(LayerTreeSettings()),
4189 host_impl_(&proxy_
, &shared_bitmap_manager_
, &task_graph_runner_
),
4192 grand_child_(nullptr) {}
4195 void SetUp() override
{
4196 can_use_lcd_text_
= std::tr1::get
<0>(GetParam());
4197 layers_always_allowed_lcd_text_
= std::tr1::get
<1>(GetParam());
4199 scoped_ptr
<LayerImpl
> root_ptr
=
4200 LayerImpl::Create(host_impl_
.active_tree(), 1);
4201 scoped_ptr
<LayerImpl
> child_ptr
=
4202 LayerImpl::Create(host_impl_
.active_tree(), 2);
4203 scoped_ptr
<LayerImpl
> grand_child_ptr
=
4204 LayerImpl::Create(host_impl_
.active_tree(), 3);
4206 // Stash raw pointers to look at later.
4207 root_
= root_ptr
.get();
4208 child_
= child_ptr
.get();
4209 grand_child_
= grand_child_ptr
.get();
4211 child_
->AddChild(grand_child_ptr
.Pass());
4212 root_
->AddChild(child_ptr
.Pass());
4213 host_impl_
.active_tree()->SetRootLayer(root_ptr
.Pass());
4215 root_
->SetContentsOpaque(true);
4216 child_
->SetContentsOpaque(true);
4217 grand_child_
->SetContentsOpaque(true);
4219 root_
->SetDrawsContent(true);
4220 child_
->SetDrawsContent(true);
4221 grand_child_
->SetDrawsContent(true);
4223 gfx::Transform identity_matrix
;
4224 SetLayerPropertiesForTesting(root_
, identity_matrix
, gfx::Point3F(),
4225 gfx::PointF(), gfx::Size(1, 1), true, false,
4227 SetLayerPropertiesForTesting(child_
, identity_matrix
, gfx::Point3F(),
4228 gfx::PointF(), gfx::Size(1, 1), true, false,
4229 std::tr1::get
<2>(GetParam()));
4230 SetLayerPropertiesForTesting(grand_child_
, identity_matrix
, gfx::Point3F(),
4231 gfx::PointF(), gfx::Size(1, 1), true, false,
4235 bool can_use_lcd_text_
;
4236 bool layers_always_allowed_lcd_text_
;
4238 FakeImplProxy proxy_
;
4239 TestSharedBitmapManager shared_bitmap_manager_
;
4240 TestTaskGraphRunner task_graph_runner_
;
4241 FakeLayerTreeHostImpl host_impl_
;
4245 LayerImpl
* grand_child_
;
4248 TEST_P(LCDTextTest
, CanUseLCDText
) {
4249 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
4250 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
4252 // Case 1: Identity transform.
4253 gfx::Transform identity_matrix
;
4254 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4255 layers_always_allowed_lcd_text_
);
4256 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4257 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4258 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4260 // Case 2: Integral translation.
4261 gfx::Transform integral_translation
;
4262 integral_translation
.Translate(1.0, 2.0);
4263 child_
->SetTransform(integral_translation
);
4264 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4265 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4266 layers_always_allowed_lcd_text_
);
4267 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4268 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4269 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4271 // Case 3: Non-integral translation.
4272 gfx::Transform non_integral_translation
;
4273 non_integral_translation
.Translate(1.5, 2.5);
4274 child_
->SetTransform(non_integral_translation
);
4275 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4276 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4277 layers_always_allowed_lcd_text_
);
4278 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4279 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4280 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4282 // Case 4: Rotation.
4283 gfx::Transform rotation
;
4284 rotation
.Rotate(10.0);
4285 child_
->SetTransform(rotation
);
4286 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4287 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4288 layers_always_allowed_lcd_text_
);
4289 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4290 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4291 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4294 gfx::Transform scale
;
4295 scale
.Scale(2.0, 2.0);
4296 child_
->SetTransform(scale
);
4297 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4298 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4299 layers_always_allowed_lcd_text_
);
4300 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4301 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4302 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4305 gfx::Transform skew
;
4307 child_
->SetTransform(skew
);
4308 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4309 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4310 layers_always_allowed_lcd_text_
);
4311 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4312 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4313 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4315 // Case 7: Translucent.
4316 child_
->SetTransform(identity_matrix
);
4317 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4318 child_
->SetOpacity(0.5f
);
4319 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4320 layers_always_allowed_lcd_text_
);
4321 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4322 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4323 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4325 // Case 8: Sanity check: restore transform and opacity.
4326 child_
->SetTransform(identity_matrix
);
4327 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4328 child_
->SetOpacity(1.f
);
4329 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4330 layers_always_allowed_lcd_text_
);
4331 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4332 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4333 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4335 // Case 9: Non-opaque content.
4336 child_
->SetContentsOpaque(false);
4337 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4338 layers_always_allowed_lcd_text_
);
4339 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4340 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4341 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4343 // Case 10: Sanity check: restore content opaqueness.
4344 child_
->SetContentsOpaque(true);
4345 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4346 layers_always_allowed_lcd_text_
);
4347 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4348 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4349 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4352 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimation
) {
4353 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
4354 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
4356 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
4357 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4358 layers_always_allowed_lcd_text_
);
4359 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4360 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4361 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4363 // Add opacity animation.
4364 child_
->SetOpacity(0.9f
);
4365 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4366 AddOpacityTransitionToController(
4367 child_
->layer_animation_controller(), 10.0, 0.9f
, 0.1f
, false);
4369 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4370 layers_always_allowed_lcd_text_
);
4371 // Text LCD should be adjusted while animation is active.
4372 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4373 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4374 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4377 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimationContentsOpaque
) {
4378 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
4379 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
4381 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
4382 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4383 layers_always_allowed_lcd_text_
);
4384 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4385 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4386 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4388 // Mark contents non-opaque within the first animation frame.
4389 child_
->SetContentsOpaque(false);
4390 AddOpacityTransitionToController(child_
->layer_animation_controller(), 10.0,
4393 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4394 layers_always_allowed_lcd_text_
);
4395 // LCD text should be disabled for non-opaque layers even during animations.
4396 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4397 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4398 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4401 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest
,
4403 testing::Combine(testing::Bool(),
4407 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayerImpl
) {
4408 FakeImplProxy proxy
;
4409 TestSharedBitmapManager shared_bitmap_manager
;
4410 TestTaskGraphRunner task_graph_runner
;
4411 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4412 &task_graph_runner
);
4413 host_impl
.CreatePendingTree();
4414 const gfx::Transform identity_matrix
;
4416 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4417 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4418 gfx::PointF(), gfx::Size(50, 50), true, false,
4420 root
->SetDrawsContent(true);
4422 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
4423 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
4424 gfx::PointF(), gfx::Size(40, 40), true, false,
4426 child
->SetDrawsContent(true);
4428 scoped_ptr
<LayerImpl
> grand_child
=
4429 LayerImpl::Create(host_impl
.pending_tree(), 3);
4430 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
4431 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4432 true, false, false);
4433 grand_child
->SetDrawsContent(true);
4434 grand_child
->SetHideLayerAndSubtree(true);
4436 child
->AddChild(grand_child
.Pass());
4437 root
->AddChild(child
.Pass());
4438 root
->SetHasRenderSurface(true);
4440 LayerImplList render_surface_layer_list
;
4441 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4442 root
.get(), root
->bounds(), &render_surface_layer_list
);
4443 inputs
.can_adjust_raster_scales
= true;
4444 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4446 // We should have one render surface and two layers. The grand child has
4448 ASSERT_EQ(1u, render_surface_layer_list
.size());
4449 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
4450 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
4451 EXPECT_EQ(2, root
->render_surface()->layer_list().at(1)->id());
4454 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayersImpl
) {
4455 FakeImplProxy proxy
;
4456 TestSharedBitmapManager shared_bitmap_manager
;
4457 TestTaskGraphRunner task_graph_runner
;
4458 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4459 &task_graph_runner
);
4460 host_impl
.CreatePendingTree();
4461 const gfx::Transform identity_matrix
;
4463 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4464 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4465 gfx::PointF(), gfx::Size(50, 50), true, false,
4467 root
->SetDrawsContent(true);
4469 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
4470 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
4471 gfx::PointF(), gfx::Size(40, 40), true, false,
4473 child
->SetDrawsContent(true);
4474 child
->SetHideLayerAndSubtree(true);
4476 scoped_ptr
<LayerImpl
> grand_child
=
4477 LayerImpl::Create(host_impl
.pending_tree(), 3);
4478 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
4479 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4480 true, false, false);
4481 grand_child
->SetDrawsContent(true);
4483 child
->AddChild(grand_child
.Pass());
4484 root
->AddChild(child
.Pass());
4486 LayerImplList render_surface_layer_list
;
4487 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4488 root
.get(), root
->bounds(), &render_surface_layer_list
);
4489 inputs
.can_adjust_raster_scales
= true;
4490 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4492 // We should have one render surface and one layers. The child has
4493 // hidden itself and the grand child.
4494 ASSERT_EQ(1u, render_surface_layer_list
.size());
4495 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
4496 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
4499 void EmptyCopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {}
4501 TEST_F(LayerTreeHostCommonTest
, SubtreeHiddenWithCopyRequest
) {
4502 FakeImplProxy proxy
;
4503 TestSharedBitmapManager shared_bitmap_manager
;
4504 TestTaskGraphRunner task_graph_runner
;
4505 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4506 &task_graph_runner
);
4507 host_impl
.CreatePendingTree();
4508 const gfx::Transform identity_matrix
;
4510 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4511 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4512 gfx::PointF(), gfx::Size(50, 50), true, false,
4514 root
->SetDrawsContent(true);
4516 scoped_ptr
<LayerImpl
> copy_grand_parent
=
4517 LayerImpl::Create(host_impl
.pending_tree(), 2);
4518 SetLayerPropertiesForTesting(copy_grand_parent
.get(), identity_matrix
,
4519 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
4520 true, false, false);
4521 copy_grand_parent
->SetDrawsContent(true);
4522 LayerImpl
* copy_grand_parent_layer
= copy_grand_parent
.get();
4524 scoped_ptr
<LayerImpl
> copy_parent
=
4525 LayerImpl::Create(host_impl
.pending_tree(), 3);
4526 SetLayerPropertiesForTesting(copy_parent
.get(), identity_matrix
,
4527 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4529 copy_parent
->SetDrawsContent(true);
4530 LayerImpl
* copy_parent_layer
= copy_parent
.get();
4532 scoped_ptr
<LayerImpl
> copy_request
=
4533 LayerImpl::Create(host_impl
.pending_tree(), 4);
4534 SetLayerPropertiesForTesting(copy_request
.get(), identity_matrix
,
4535 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4537 copy_request
->SetDrawsContent(true);
4538 LayerImpl
* copy_layer
= copy_request
.get();
4540 scoped_ptr
<LayerImpl
> copy_child
=
4541 LayerImpl::Create(host_impl
.pending_tree(), 5);
4542 SetLayerPropertiesForTesting(copy_child
.get(), identity_matrix
,
4543 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4544 true, false, false);
4545 copy_child
->SetDrawsContent(true);
4546 LayerImpl
* copy_child_layer
= copy_child
.get();
4548 scoped_ptr
<LayerImpl
> copy_grand_parent_sibling_before
=
4549 LayerImpl::Create(host_impl
.pending_tree(), 6);
4550 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before
.get(),
4551 identity_matrix
, gfx::Point3F(), gfx::PointF(),
4552 gfx::Size(40, 40), true, false, false);
4553 copy_grand_parent_sibling_before
->SetDrawsContent(true);
4554 LayerImpl
* copy_grand_parent_sibling_before_layer
=
4555 copy_grand_parent_sibling_before
.get();
4557 scoped_ptr
<LayerImpl
> copy_grand_parent_sibling_after
=
4558 LayerImpl::Create(host_impl
.pending_tree(), 7);
4559 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after
.get(),
4560 identity_matrix
, gfx::Point3F(), gfx::PointF(),
4561 gfx::Size(40, 40), true, false, false);
4562 copy_grand_parent_sibling_after
->SetDrawsContent(true);
4563 LayerImpl
* copy_grand_parent_sibling_after_layer
=
4564 copy_grand_parent_sibling_after
.get();
4566 copy_request
->AddChild(copy_child
.Pass());
4567 copy_parent
->AddChild(copy_request
.Pass());
4568 copy_grand_parent
->AddChild(copy_parent
.Pass());
4569 root
->AddChild(copy_grand_parent_sibling_before
.Pass());
4570 root
->AddChild(copy_grand_parent
.Pass());
4571 root
->AddChild(copy_grand_parent_sibling_after
.Pass());
4573 // Hide the copy_grand_parent and its subtree. But make a copy request in that
4574 // hidden subtree on copy_layer.
4575 copy_grand_parent_layer
->SetHideLayerAndSubtree(true);
4576 copy_grand_parent_sibling_before_layer
->SetHideLayerAndSubtree(true);
4577 copy_grand_parent_sibling_after_layer
->SetHideLayerAndSubtree(true);
4579 ScopedPtrVector
<CopyOutputRequest
> copy_requests
;
4580 copy_requests
.push_back(
4581 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback
)));
4582 copy_layer
->PassCopyRequests(©_requests
);
4583 EXPECT_TRUE(copy_layer
->HasCopyRequest());
4585 LayerImplList render_surface_layer_list
;
4586 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4587 root
.get(), root
->bounds(), &render_surface_layer_list
);
4588 inputs
.can_adjust_raster_scales
= true;
4589 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4591 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
4592 EXPECT_TRUE(copy_grand_parent_layer
->draw_properties()
4593 .layer_or_descendant_has_copy_request
);
4594 EXPECT_TRUE(copy_parent_layer
->draw_properties()
4595 .layer_or_descendant_has_copy_request
);
4597 copy_layer
->draw_properties().layer_or_descendant_has_copy_request
);
4599 copy_child_layer
->draw_properties().layer_or_descendant_has_copy_request
);
4600 EXPECT_FALSE(copy_grand_parent_sibling_before_layer
->draw_properties()
4601 .layer_or_descendant_has_copy_request
);
4602 EXPECT_FALSE(copy_grand_parent_sibling_after_layer
->draw_properties()
4603 .layer_or_descendant_has_copy_request
);
4605 // We should have three render surfaces, one for the root, one for the parent
4606 // since it owns a surface, and one for the copy_layer.
4607 ASSERT_EQ(3u, render_surface_layer_list
.size());
4608 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
4609 EXPECT_EQ(copy_parent_layer
->id(), render_surface_layer_list
.at(1)->id());
4610 EXPECT_EQ(copy_layer
->id(), render_surface_layer_list
.at(2)->id());
4612 // The root render surface should have 2 contributing layers. The
4613 // copy_grand_parent is hidden along with its siblings, but the copy_parent
4614 // will appear since something in its subtree needs to be drawn for a copy
4616 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
4617 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
4618 EXPECT_EQ(copy_parent_layer
->id(),
4619 root
->render_surface()->layer_list().at(1)->id());
4621 // Nothing actually draws into the copy parent, so only the copy_layer will
4622 // appear in its list, since it needs to be drawn for the copy request.
4623 ASSERT_EQ(1u, copy_parent_layer
->render_surface()->layer_list().size());
4624 EXPECT_EQ(copy_layer
->id(),
4625 copy_parent_layer
->render_surface()->layer_list().at(0)->id());
4627 // The copy_layer's render surface should have two contributing layers.
4628 ASSERT_EQ(2u, copy_layer
->render_surface()->layer_list().size());
4629 EXPECT_EQ(copy_layer
->id(),
4630 copy_layer
->render_surface()->layer_list().at(0)->id());
4631 EXPECT_EQ(copy_child_layer
->id(),
4632 copy_layer
->render_surface()->layer_list().at(1)->id());
4635 TEST_F(LayerTreeHostCommonTest
, ClippedOutCopyRequest
) {
4636 FakeImplProxy proxy
;
4637 TestSharedBitmapManager shared_bitmap_manager
;
4638 TestTaskGraphRunner task_graph_runner
;
4639 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4640 &task_graph_runner
);
4641 host_impl
.CreatePendingTree();
4642 const gfx::Transform identity_matrix
;
4644 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4645 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4646 gfx::PointF(), gfx::Size(50, 50), true, false,
4648 root
->SetDrawsContent(true);
4650 scoped_ptr
<LayerImpl
> copy_parent
=
4651 LayerImpl::Create(host_impl
.pending_tree(), 2);
4652 SetLayerPropertiesForTesting(copy_parent
.get(), identity_matrix
,
4653 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
4655 copy_parent
->SetDrawsContent(true);
4656 copy_parent
->SetMasksToBounds(true);
4658 scoped_ptr
<LayerImpl
> copy_layer
=
4659 LayerImpl::Create(host_impl
.pending_tree(), 3);
4660 SetLayerPropertiesForTesting(copy_layer
.get(), identity_matrix
,
4661 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4663 copy_layer
->SetDrawsContent(true);
4665 scoped_ptr
<LayerImpl
> copy_child
=
4666 LayerImpl::Create(host_impl
.pending_tree(), 4);
4667 SetLayerPropertiesForTesting(copy_child
.get(), identity_matrix
,
4668 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4669 true, false, false);
4670 copy_child
->SetDrawsContent(true);
4672 ScopedPtrVector
<CopyOutputRequest
> copy_requests
;
4673 copy_requests
.push_back(
4674 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback
)));
4675 copy_layer
->PassCopyRequests(©_requests
);
4676 EXPECT_TRUE(copy_layer
->HasCopyRequest());
4678 copy_layer
->AddChild(copy_child
.Pass());
4679 copy_parent
->AddChild(copy_layer
.Pass());
4680 root
->AddChild(copy_parent
.Pass());
4682 LayerImplList render_surface_layer_list
;
4683 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4684 root
.get(), root
->bounds(), &render_surface_layer_list
);
4685 inputs
.can_adjust_raster_scales
= true;
4686 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4688 // We should have one render surface, as the others are clipped out.
4689 ASSERT_EQ(1u, render_surface_layer_list
.size());
4690 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
4692 // The root render surface should only have 1 contributing layer, since the
4693 // other layers are empty/clipped away.
4694 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
4695 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
4698 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInsideSurface
) {
4699 FakeImplProxy proxy
;
4700 TestSharedBitmapManager shared_bitmap_manager
;
4701 TestTaskGraphRunner task_graph_runner
;
4702 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4703 &task_graph_runner
);
4704 host_impl
.CreatePendingTree();
4705 const gfx::Transform identity_matrix
;
4707 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4708 SetLayerPropertiesForTesting(root
.get(),
4715 root
->SetIsDrawable(true);
4717 // The surface is moved slightly outside of the viewport.
4718 scoped_refptr
<Layer
> surface
= Layer::Create(layer_settings());
4719 SetLayerPropertiesForTesting(surface
.get(),
4722 gfx::PointF(-10, -20),
4726 surface
->SetForceRenderSurface(true);
4728 scoped_refptr
<Layer
> surface_child
= Layer::Create(layer_settings());
4729 SetLayerPropertiesForTesting(surface_child
.get(),
4736 surface_child
->SetIsDrawable(true);
4738 surface
->AddChild(surface_child
);
4739 root
->AddChild(surface
);
4741 host()->SetRootLayer(root
);
4743 RenderSurfaceLayerList render_surface_layer_list
;
4744 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4745 root
.get(), root
->bounds(), &render_surface_layer_list
);
4746 inputs
.can_adjust_raster_scales
= true;
4747 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4749 // The visible_layer_rect for the |surface_child| should not be clipped by
4751 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
4752 surface_child
->visible_layer_rect().ToString());
4755 TEST_F(LayerTreeHostCommonTest
, TransformedClipParent
) {
4756 // Ensure that a transform between the layer and its render surface is not a
4757 // problem. Constructs the following layer tree.
4759 // root (a render surface)
4761 // + clip_parent (scaled)
4762 // + intervening_clipping_layer
4765 // The render surface should be resized correctly and the clip child should
4766 // inherit the right clip rect.
4767 LayerImpl
* root
= root_layer();
4768 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
4769 LayerImpl
* clip_parent
= AddChild
<LayerImpl
>(render_surface
);
4770 LayerImpl
* intervening
= AddChild
<LayerImpl
>(clip_parent
);
4771 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(intervening
);
4772 clip_child
->SetDrawsContent(true);
4773 clip_child
->SetClipParent(clip_parent
);
4774 scoped_ptr
<std::set
<LayerImpl
*>> clip_children(new std::set
<LayerImpl
*>);
4775 clip_children
->insert(clip_child
);
4776 clip_parent
->SetClipChildren(clip_children
.release());
4778 intervening
->SetMasksToBounds(true);
4779 clip_parent
->SetMasksToBounds(true);
4781 gfx::Transform scale_transform
;
4782 scale_transform
.Scale(2, 2);
4784 gfx::Transform identity_transform
;
4786 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
4787 gfx::PointF(), gfx::Size(50, 50), true, false,
4789 SetLayerPropertiesForTesting(render_surface
, identity_transform
,
4790 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4792 SetLayerPropertiesForTesting(clip_parent
, scale_transform
, gfx::Point3F(),
4793 gfx::PointF(1.f
, 1.f
), gfx::Size(10, 10), true,
4795 SetLayerPropertiesForTesting(intervening
, identity_transform
, gfx::Point3F(),
4796 gfx::PointF(1.f
, 1.f
), gfx::Size(5, 5), true,
4798 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
4799 gfx::PointF(1.f
, 1.f
), gfx::Size(10, 10), true,
4802 ExecuteCalculateDrawProperties(root
);
4804 ASSERT_TRUE(root
->render_surface());
4805 ASSERT_TRUE(render_surface
->render_surface());
4807 // Ensure that we've inherited our clip parent's clip and weren't affected
4808 // by the intervening clip layer.
4809 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
4810 clip_parent
->clip_rect().ToString());
4811 ASSERT_EQ(clip_parent
->clip_rect().ToString(),
4812 clip_child
->clip_rect().ToString());
4813 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
4814 intervening
->clip_rect().ToString());
4816 // Ensure that the render surface reports a content rect that has been grown
4817 // to accomodate for the clip child.
4818 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
4819 render_surface
->render_surface()->content_rect().ToString());
4821 // The above check implies the two below, but they nicely demonstrate that
4822 // we've grown, despite the intervening layer's clip.
4823 ASSERT_TRUE(clip_parent
->clip_rect().Contains(
4824 render_surface
->render_surface()->content_rect()));
4825 ASSERT_FALSE(intervening
->clip_rect().Contains(
4826 render_surface
->render_surface()->content_rect()));
4829 TEST_F(LayerTreeHostCommonTest
, ClipParentWithInterveningRenderSurface
) {
4830 // Ensure that intervening render surfaces are not a problem in the basic
4831 // case. In the following tree, both render surfaces should be resized to
4832 // accomodate for the clip child, despite an intervening clip.
4834 // root (a render surface)
4835 // + clip_parent (masks to bounds)
4836 // + render_surface1 (sets opacity)
4837 // + intervening (masks to bounds)
4838 // + render_surface2 (also sets opacity)
4841 LayerImpl
* root
= root_layer();
4842 LayerImpl
* clip_parent
= AddChildToRoot
<LayerImpl
>();
4843 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(clip_parent
);
4844 LayerImpl
* intervening
= AddChild
<LayerImpl
>(render_surface1
);
4845 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(intervening
);
4846 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(render_surface2
);
4847 clip_child
->SetDrawsContent(true);
4849 clip_child
->SetClipParent(clip_parent
);
4851 intervening
->SetMasksToBounds(true);
4852 clip_parent
->SetMasksToBounds(true);
4854 gfx::Transform translation_transform
;
4855 translation_transform
.Translate(2, 2);
4857 gfx::Transform identity_transform
;
4858 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
4859 gfx::PointF(), gfx::Size(50, 50), true, false,
4861 SetLayerPropertiesForTesting(clip_parent
, translation_transform
,
4862 gfx::Point3F(), gfx::PointF(1.f
, 1.f
),
4863 gfx::Size(40, 40), true, false, false);
4864 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
4865 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4867 SetLayerPropertiesForTesting(intervening
, identity_transform
, gfx::Point3F(),
4868 gfx::PointF(1.f
, 1.f
), gfx::Size(5, 5), true,
4870 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
4871 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4873 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
4874 gfx::PointF(-10.f
, -10.f
), gfx::Size(60, 60),
4875 true, false, false);
4877 ExecuteCalculateDrawProperties(root
);
4879 EXPECT_TRUE(root
->render_surface());
4880 EXPECT_TRUE(render_surface1
->render_surface());
4881 EXPECT_TRUE(render_surface2
->render_surface());
4883 // Since the render surfaces could have expanded, they should not clip (their
4884 // bounds would no longer be reliable). We should resort to layer clipping
4886 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4887 render_surface1
->render_surface()->clip_rect().ToString());
4888 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
4889 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4890 render_surface2
->render_surface()->clip_rect().ToString());
4891 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
4893 // NB: clip rects are in target space.
4894 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4895 render_surface1
->clip_rect().ToString());
4896 EXPECT_TRUE(render_surface1
->is_clipped());
4898 // This value is inherited from the clipping ancestor layer, 'intervening'.
4899 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
4900 render_surface2
->clip_rect().ToString());
4901 EXPECT_TRUE(render_surface2
->is_clipped());
4903 // The content rects of both render surfaces should both have expanded to
4904 // contain the clip child.
4905 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4906 render_surface1
->render_surface()->content_rect().ToString());
4907 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
4908 render_surface2
->render_surface()->content_rect().ToString());
4910 // The clip child should have inherited the clip parent's clip (projected to
4911 // the right space, of course), and should have the correctly sized visible
4913 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
4914 clip_child
->clip_rect().ToString());
4915 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
4916 clip_child
->visible_layer_rect().ToString());
4917 EXPECT_TRUE(clip_child
->is_clipped());
4920 TEST_F(LayerTreeHostCommonTest
, ClipParentScrolledInterveningLayer
) {
4921 // Ensure that intervening render surfaces are not a problem, even if there
4922 // is a scroll involved. Note, we do _not_ have to consider any other sort
4925 // root (a render surface)
4926 // + clip_parent (masks to bounds)
4927 // + render_surface1 (sets opacity)
4928 // + intervening (masks to bounds AND scrolls)
4929 // + render_surface2 (also sets opacity)
4932 LayerImpl
* root
= root_layer();
4933 LayerImpl
* clip_parent
= AddChildToRoot
<LayerImpl
>();
4934 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(clip_parent
);
4935 LayerImpl
* intervening
= AddChild
<LayerImpl
>(render_surface1
);
4936 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(intervening
);
4937 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(render_surface2
);
4938 clip_child
->SetDrawsContent(true);
4940 clip_child
->SetClipParent(clip_parent
);
4942 intervening
->SetMasksToBounds(true);
4943 clip_parent
->SetMasksToBounds(true);
4944 intervening
->SetScrollClipLayer(clip_parent
->id());
4945 intervening
->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
4947 gfx::Transform translation_transform
;
4948 translation_transform
.Translate(2, 2);
4950 gfx::Transform identity_transform
;
4951 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
4952 gfx::PointF(), gfx::Size(50, 50), true, false,
4954 SetLayerPropertiesForTesting(clip_parent
, translation_transform
,
4955 gfx::Point3F(), gfx::PointF(1.f
, 1.f
),
4956 gfx::Size(40, 40), true, false, false);
4957 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
4958 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4960 SetLayerPropertiesForTesting(intervening
, identity_transform
, gfx::Point3F(),
4961 gfx::PointF(1.f
, 1.f
), gfx::Size(5, 5), true,
4963 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
4964 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4966 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
4967 gfx::PointF(-10.f
, -10.f
), gfx::Size(60, 60),
4968 true, false, false);
4970 ExecuteCalculateDrawProperties(root
);
4972 EXPECT_TRUE(root
->render_surface());
4973 EXPECT_TRUE(render_surface1
->render_surface());
4974 EXPECT_TRUE(render_surface2
->render_surface());
4976 // Since the render surfaces could have expanded, they should not clip (their
4977 // bounds would no longer be reliable). We should resort to layer clipping
4979 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4980 render_surface1
->render_surface()->clip_rect().ToString());
4981 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
4982 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4983 render_surface2
->render_surface()->clip_rect().ToString());
4984 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
4986 // NB: clip rects are in target space.
4987 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4988 render_surface1
->clip_rect().ToString());
4989 EXPECT_TRUE(render_surface1
->is_clipped());
4991 // This value is inherited from the clipping ancestor layer, 'intervening'.
4992 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
4993 render_surface2
->clip_rect().ToString());
4994 EXPECT_TRUE(render_surface2
->is_clipped());
4996 // The content rects of both render surfaces should both have expanded to
4997 // contain the clip child.
4998 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4999 render_surface1
->render_surface()->content_rect().ToString());
5000 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
5001 render_surface2
->render_surface()->content_rect().ToString());
5003 // The clip child should have inherited the clip parent's clip (projected to
5004 // the right space, of course), and should have the correctly sized visible
5006 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
5007 clip_child
->clip_rect().ToString());
5008 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
5009 clip_child
->visible_layer_rect().ToString());
5010 EXPECT_TRUE(clip_child
->is_clipped());
5013 TEST_F(LayerTreeHostCommonTest
, DescendantsOfClipChildren
) {
5014 // Ensures that descendants of the clip child inherit the correct clip.
5016 // root (a render surface)
5017 // + clip_parent (masks to bounds)
5018 // + intervening (masks to bounds)
5022 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5023 scoped_refptr
<Layer
> clip_parent
= Layer::Create(layer_settings());
5024 scoped_refptr
<Layer
> intervening
= Layer::Create(layer_settings());
5025 scoped_refptr
<Layer
> clip_child
= Layer::Create(layer_settings());
5026 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
5027 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5029 root
->AddChild(clip_parent
);
5030 clip_parent
->AddChild(intervening
);
5031 intervening
->AddChild(clip_child
);
5032 clip_child
->AddChild(child
);
5034 clip_child
->SetClipParent(clip_parent
.get());
5036 intervening
->SetMasksToBounds(true);
5037 clip_parent
->SetMasksToBounds(true);
5039 gfx::Transform identity_transform
;
5040 SetLayerPropertiesForTesting(root
.get(),
5047 SetLayerPropertiesForTesting(clip_parent
.get(),
5054 SetLayerPropertiesForTesting(intervening
.get(),
5061 SetLayerPropertiesForTesting(clip_child
.get(),
5068 SetLayerPropertiesForTesting(child
.get(),
5076 host()->SetRootLayer(root
);
5078 ExecuteCalculateDrawProperties(root
.get());
5080 EXPECT_TRUE(root
->render_surface());
5082 // Neither the clip child nor its descendant should have inherited the clip
5083 // from |intervening|.
5084 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5085 clip_child
->clip_rect().ToString());
5086 EXPECT_TRUE(clip_child
->is_clipped());
5087 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5088 child
->visible_layer_rect().ToString());
5089 EXPECT_TRUE(child
->is_clipped());
5092 TEST_F(LayerTreeHostCommonTest
,
5093 SurfacesShouldBeUnaffectedByNonDescendantClipChildren
) {
5094 // Ensures that non-descendant clip children in the tree do not affect
5097 // root (a render surface)
5098 // + clip_parent (masks to bounds)
5099 // + render_surface1
5101 // + render_surface2
5104 // In this example render_surface2 should be unaffected by clip_child.
5105 LayerImpl
* root
= root_layer();
5106 LayerImpl
* clip_parent
= AddChildToRoot
<LayerImpl
>();
5107 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(clip_parent
);
5108 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(render_surface1
);
5109 clip_child
->SetDrawsContent(true);
5110 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(clip_parent
);
5111 LayerImpl
* non_clip_child
= AddChild
<LayerImpl
>(render_surface2
);
5112 non_clip_child
->SetDrawsContent(true);
5114 clip_child
->SetClipParent(clip_parent
);
5115 scoped_ptr
<std::set
<LayerImpl
*>> clip_children(new std::set
<LayerImpl
*>);
5116 clip_children
->insert(clip_child
);
5117 clip_parent
->SetClipChildren(clip_children
.release());
5119 clip_parent
->SetMasksToBounds(true);
5120 render_surface1
->SetMasksToBounds(true);
5122 gfx::Transform identity_transform
;
5123 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5124 gfx::PointF(), gfx::Size(15, 15), true, false,
5126 SetLayerPropertiesForTesting(clip_parent
, identity_transform
, gfx::Point3F(),
5127 gfx::PointF(), gfx::Size(10, 10), true, false,
5129 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
5130 gfx::Point3F(), gfx::PointF(5, 5),
5131 gfx::Size(5, 5), true, false, true);
5132 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
5133 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
5135 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
5136 gfx::PointF(-1, 1), gfx::Size(10, 10), true,
5138 SetLayerPropertiesForTesting(non_clip_child
, identity_transform
,
5139 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
5140 true, false, false);
5142 ExecuteCalculateDrawProperties(root
);
5144 EXPECT_TRUE(root
->render_surface());
5145 EXPECT_TRUE(render_surface1
->render_surface());
5146 EXPECT_TRUE(render_surface2
->render_surface());
5148 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5149 render_surface1
->clip_rect().ToString());
5150 EXPECT_TRUE(render_surface1
->is_clipped());
5152 // The render surface should not clip (it has unclipped descendants), instead
5153 // it should rely on layer clipping.
5154 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5155 render_surface1
->render_surface()->clip_rect().ToString());
5156 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
5158 // That said, it should have grown to accomodate the unclipped descendant.
5159 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
5160 render_surface1
->render_surface()->content_rect().ToString());
5162 // This render surface should clip. It has no unclipped descendants.
5163 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5164 render_surface2
->clip_rect().ToString());
5165 EXPECT_TRUE(render_surface2
->render_surface()->is_clipped());
5167 // It also shouldn't have grown to accomodate the clip child.
5168 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5169 render_surface2
->render_surface()->content_rect().ToString());
5171 // Sanity check our num_unclipped_descendants values.
5172 EXPECT_EQ(1u, render_surface1
->num_unclipped_descendants());
5173 EXPECT_EQ(0u, render_surface2
->num_unclipped_descendants());
5176 TEST_F(LayerTreeHostCommonTest
, CanRenderToSeparateSurface
) {
5177 FakeImplProxy proxy
;
5178 TestSharedBitmapManager shared_bitmap_manager
;
5179 TestTaskGraphRunner task_graph_runner
;
5180 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5181 &task_graph_runner
);
5182 scoped_ptr
<LayerImpl
> root
=
5183 LayerImpl::Create(host_impl
.active_tree(), 12345);
5184 scoped_ptr
<LayerImpl
> child1
=
5185 LayerImpl::Create(host_impl
.active_tree(), 123456);
5186 scoped_ptr
<LayerImpl
> child2
=
5187 LayerImpl::Create(host_impl
.active_tree(), 1234567);
5188 scoped_ptr
<LayerImpl
> child3
=
5189 LayerImpl::Create(host_impl
.active_tree(), 12345678);
5191 gfx::Transform identity_matrix
;
5192 gfx::Point3F transform_origin
;
5193 gfx::PointF position
;
5194 gfx::Size
bounds(100, 100);
5195 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
5196 position
, bounds
, true, false, true);
5197 root
->SetDrawsContent(true);
5199 // This layer structure normally forces render surface due to preserves3d
5201 SetLayerPropertiesForTesting(child1
.get(), identity_matrix
, transform_origin
,
5202 position
, bounds
, false, true, true);
5203 child1
->SetDrawsContent(true);
5204 SetLayerPropertiesForTesting(child2
.get(), identity_matrix
, transform_origin
,
5205 position
, bounds
, true, false, false);
5206 child2
->SetDrawsContent(true);
5207 SetLayerPropertiesForTesting(child3
.get(), identity_matrix
, transform_origin
,
5208 position
, bounds
, true, false, false);
5209 child3
->SetDrawsContent(true);
5211 child2
->Set3dSortingContextId(1);
5212 child3
->Set3dSortingContextId(1);
5214 child2
->AddChild(child3
.Pass());
5215 child1
->AddChild(child2
.Pass());
5216 root
->AddChild(child1
.Pass());
5219 LayerImplList render_surface_layer_list
;
5220 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root
.get());
5221 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5222 root
.get(), root
->bounds(), &render_surface_layer_list
);
5223 inputs
.can_render_to_separate_surface
= true;
5224 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5226 EXPECT_EQ(2u, render_surface_layer_list
.size());
5228 int count_represents_target_render_surface
= 0;
5229 int count_represents_contributing_render_surface
= 0;
5230 int count_represents_itself
= 0;
5231 LayerIterator end
= LayerIterator::End(&render_surface_layer_list
);
5232 for (LayerIterator it
= LayerIterator::Begin(&render_surface_layer_list
);
5234 if (it
.represents_target_render_surface())
5235 count_represents_target_render_surface
++;
5236 if (it
.represents_contributing_render_surface())
5237 count_represents_contributing_render_surface
++;
5238 if (it
.represents_itself())
5239 count_represents_itself
++;
5242 // Two render surfaces.
5243 EXPECT_EQ(2, count_represents_target_render_surface
);
5244 // Second render surface contributes to root render surface.
5245 EXPECT_EQ(1, count_represents_contributing_render_surface
);
5246 // All 4 layers represent itself.
5247 EXPECT_EQ(4, count_represents_itself
);
5251 LayerImplList render_surface_layer_list
;
5252 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5253 root
.get(), root
->bounds(), &render_surface_layer_list
);
5254 inputs
.can_render_to_separate_surface
= false;
5255 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5257 EXPECT_EQ(1u, render_surface_layer_list
.size());
5259 int count_represents_target_render_surface
= 0;
5260 int count_represents_contributing_render_surface
= 0;
5261 int count_represents_itself
= 0;
5262 LayerIterator end
= LayerIterator::End(&render_surface_layer_list
);
5263 for (LayerIterator it
= LayerIterator::Begin(&render_surface_layer_list
);
5265 if (it
.represents_target_render_surface())
5266 count_represents_target_render_surface
++;
5267 if (it
.represents_contributing_render_surface())
5268 count_represents_contributing_render_surface
++;
5269 if (it
.represents_itself())
5270 count_represents_itself
++;
5273 // Only root layer has a render surface.
5274 EXPECT_EQ(1, count_represents_target_render_surface
);
5275 // No layer contributes a render surface to root render surface.
5276 EXPECT_EQ(0, count_represents_contributing_render_surface
);
5277 // All 4 layers represent itself.
5278 EXPECT_EQ(4, count_represents_itself
);
5282 TEST_F(LayerTreeHostCommonTest
, DoNotIncludeBackfaceInvisibleSurfaces
) {
5283 LayerImpl
* root
= root_layer();
5284 LayerImpl
* render_surface
= AddChild
<LayerImpl
>(root
);
5285 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface
);
5286 child
->SetDrawsContent(true);
5288 gfx::Transform identity_transform
;
5289 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5290 gfx::PointF(), gfx::Size(50, 50), true, false,
5292 SetLayerPropertiesForTesting(render_surface
, identity_transform
,
5293 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5295 SetLayerPropertiesForTesting(child
, identity_transform
, gfx::Point3F(),
5296 gfx::PointF(), gfx::Size(20, 20), true, false,
5299 root
->SetShouldFlattenTransform(false);
5300 root
->Set3dSortingContextId(1);
5301 render_surface
->SetDoubleSided(false);
5303 ExecuteCalculateDrawProperties(root
);
5305 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
5306 EXPECT_EQ(1u, render_surface_layer_list_impl()
5311 EXPECT_EQ(1u, render_surface_layer_list_impl()
5317 gfx::Transform rotation_transform
= identity_transform
;
5318 rotation_transform
.RotateAboutXAxis(180.0);
5320 render_surface
->SetTransform(rotation_transform
);
5322 ExecuteCalculateDrawProperties(root
);
5324 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
5325 EXPECT_EQ(0u, render_surface_layer_list_impl()
5332 TEST_F(LayerTreeHostCommonTest
, ClippedByScrollParent
) {
5333 // Checks that the simple case (being clipped by a scroll parent that would
5334 // have been processed before you anyhow) results in the right clips.
5337 // + scroll_parent_border
5338 // | + scroll_parent_clip
5339 // | + scroll_parent
5342 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5343 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create(layer_settings());
5344 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create(layer_settings());
5345 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
5346 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5347 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
5348 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5350 root
->AddChild(scroll_child
);
5352 root
->AddChild(scroll_parent_border
);
5353 scroll_parent_border
->AddChild(scroll_parent_clip
);
5354 scroll_parent_clip
->AddChild(scroll_parent
);
5356 scroll_parent_clip
->SetMasksToBounds(true);
5358 scroll_child
->SetScrollParent(scroll_parent
.get());
5360 gfx::Transform identity_transform
;
5361 SetLayerPropertiesForTesting(root
.get(),
5368 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
5375 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
5382 SetLayerPropertiesForTesting(scroll_parent
.get(),
5389 SetLayerPropertiesForTesting(scroll_child
.get(),
5397 host()->SetRootLayer(root
);
5399 ExecuteCalculateDrawProperties(root
.get());
5401 EXPECT_TRUE(root
->render_surface());
5403 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
5404 scroll_child
->clip_rect().ToString());
5405 EXPECT_TRUE(scroll_child
->is_clipped());
5408 TEST_F(LayerTreeHostCommonTest
, SingularTransformSubtreesDoNotDraw
) {
5409 LayerImpl
* root
= root_layer();
5410 root
->SetDrawsContent(true);
5411 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
5412 parent
->SetDrawsContent(true);
5413 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
5414 child
->SetDrawsContent(true);
5416 gfx::Transform identity_transform
;
5417 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5418 gfx::PointF(), gfx::Size(50, 50), true, true,
5420 SetLayerPropertiesForTesting(parent
, identity_transform
, gfx::Point3F(),
5421 gfx::PointF(), gfx::Size(30, 30), true, true,
5423 SetLayerPropertiesForTesting(child
, identity_transform
, gfx::Point3F(),
5424 gfx::PointF(), gfx::Size(20, 20), true, true,
5427 ExecuteCalculateDrawProperties(root
);
5429 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
5431 gfx::Transform singular_transform
;
5432 singular_transform
.Scale3d(
5433 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
5435 child
->SetTransform(singular_transform
);
5437 ExecuteCalculateDrawProperties(root
);
5439 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
5441 // Ensure that the entire subtree under a layer with singular transform does
5442 // not get rendered.
5443 parent
->SetTransform(singular_transform
);
5444 child
->SetTransform(identity_transform
);
5446 ExecuteCalculateDrawProperties(root
);
5448 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
5451 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollParent
) {
5452 // Checks that clipping by a scroll parent that follows you in paint order
5453 // still results in correct clipping.
5456 // + scroll_parent_border
5457 // + scroll_parent_clip
5461 LayerImpl
* root
= root_layer();
5462 LayerImpl
* scroll_parent_border
= AddChild
<LayerImpl
>(root
);
5463 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
5464 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
5465 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
5467 scroll_parent
->SetDrawsContent(true);
5468 scroll_child
->SetDrawsContent(true);
5470 scroll_parent_clip
->SetMasksToBounds(true);
5472 scroll_child
->SetScrollParent(scroll_parent
);
5473 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
5474 scroll_children
->insert(scroll_child
);
5475 scroll_parent
->SetScrollChildren(scroll_children
.release());
5477 gfx::Transform identity_transform
;
5478 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5479 gfx::PointF(), gfx::Size(50, 50), true, false,
5481 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
5482 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5483 true, false, false);
5484 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
5485 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5486 true, false, false);
5487 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
5488 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5489 true, false, false);
5490 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
5491 gfx::PointF(), gfx::Size(50, 50), true, false,
5494 ExecuteCalculateDrawProperties(root
);
5496 EXPECT_TRUE(root
->render_surface());
5498 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
5499 scroll_child
->clip_rect().ToString());
5500 EXPECT_TRUE(scroll_child
->is_clipped());
5503 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollGrandparent
) {
5504 // Checks that clipping by a scroll parent and scroll grandparent that follow
5505 // you in paint order still results in correct clipping.
5509 // + scroll_parent_border
5510 // | + scroll_parent_clip
5511 // | + scroll_parent
5512 // + scroll_grandparent_border
5513 // + scroll_grandparent_clip
5514 // + scroll_grandparent
5516 LayerImpl
* root
= root_layer();
5517 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
5518 LayerImpl
* scroll_parent_border
= AddChild
<LayerImpl
>(root
);
5519 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
5520 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
5521 LayerImpl
* scroll_grandparent_border
= AddChild
<LayerImpl
>(root
);
5522 LayerImpl
* scroll_grandparent_clip
=
5523 AddChild
<LayerImpl
>(scroll_grandparent_border
);
5524 LayerImpl
* scroll_grandparent
= AddChild
<LayerImpl
>(scroll_grandparent_clip
);
5526 scroll_parent
->SetDrawsContent(true);
5527 scroll_grandparent
->SetDrawsContent(true);
5528 scroll_child
->SetDrawsContent(true);
5530 scroll_parent_clip
->SetMasksToBounds(true);
5531 scroll_grandparent_clip
->SetMasksToBounds(true);
5533 scroll_child
->SetScrollParent(scroll_parent
);
5534 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
5535 scroll_children
->insert(scroll_child
);
5536 scroll_parent
->SetScrollChildren(scroll_children
.release());
5538 scroll_parent_border
->SetScrollParent(scroll_grandparent
);
5539 scroll_children
.reset(new std::set
<LayerImpl
*>);
5540 scroll_children
->insert(scroll_parent_border
);
5541 scroll_grandparent
->SetScrollChildren(scroll_children
.release());
5543 gfx::Transform identity_transform
;
5544 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5545 gfx::PointF(), gfx::Size(50, 50), true, false,
5547 SetLayerPropertiesForTesting(scroll_grandparent_border
, identity_transform
,
5548 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5549 true, false, false);
5550 SetLayerPropertiesForTesting(scroll_grandparent_clip
, identity_transform
,
5551 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5552 true, false, false);
5553 SetLayerPropertiesForTesting(scroll_grandparent
, identity_transform
,
5554 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5555 true, false, false);
5556 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
5557 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5558 true, false, false);
5559 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
5560 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5561 true, false, false);
5562 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
5563 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5564 true, false, false);
5565 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
5566 gfx::PointF(), gfx::Size(50, 50), true, false,
5569 ExecuteCalculateDrawProperties(root
);
5571 EXPECT_TRUE(root
->render_surface());
5573 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
5574 scroll_child
->clip_rect().ToString());
5575 EXPECT_TRUE(scroll_child
->is_clipped());
5577 // Despite the fact that we visited the above layers out of order to get the
5578 // correct clip, the layer lists should be unaffected.
5579 EXPECT_EQ(3u, root
->render_surface()->layer_list().size());
5580 EXPECT_EQ(scroll_child
, root
->render_surface()->layer_list().at(0));
5581 EXPECT_EQ(scroll_parent
, root
->render_surface()->layer_list().at(1));
5582 EXPECT_EQ(scroll_grandparent
, root
->render_surface()->layer_list().at(2));
5585 TEST_F(LayerTreeHostCommonTest
, OutOfOrderClippingRequiresRSLLSorting
) {
5586 // Ensures that even if we visit layers out of order, we still produce a
5587 // correctly ordered render surface layer list.
5590 // + scroll_parent_border
5591 // + scroll_parent_clip
5593 // + render_surface2
5594 // + scroll_grandparent_border
5595 // + scroll_grandparent_clip
5596 // + scroll_grandparent
5597 // + render_surface1
5599 LayerImpl
* root
= root_layer();
5600 root
->SetDrawsContent(true);
5602 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
5603 scroll_child
->SetDrawsContent(true);
5605 LayerImpl
* scroll_parent_border
= AddChild
<LayerImpl
>(root
);
5606 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
5607 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
5608 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(scroll_parent
);
5609 LayerImpl
* scroll_grandparent_border
= AddChild
<LayerImpl
>(root
);
5610 LayerImpl
* scroll_grandparent_clip
=
5611 AddChild
<LayerImpl
>(scroll_grandparent_border
);
5612 LayerImpl
* scroll_grandparent
= AddChild
<LayerImpl
>(scroll_grandparent_clip
);
5613 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(scroll_grandparent
);
5615 scroll_parent
->SetDrawsContent(true);
5616 render_surface1
->SetDrawsContent(true);
5617 scroll_grandparent
->SetDrawsContent(true);
5618 render_surface2
->SetDrawsContent(true);
5620 scroll_parent_clip
->SetMasksToBounds(true);
5621 scroll_grandparent_clip
->SetMasksToBounds(true);
5623 scroll_child
->SetScrollParent(scroll_parent
);
5624 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
5625 scroll_children
->insert(scroll_child
);
5626 scroll_parent
->SetScrollChildren(scroll_children
.release());
5628 scroll_parent_border
->SetScrollParent(scroll_grandparent
);
5629 scroll_children
.reset(new std::set
<LayerImpl
*>);
5630 scroll_children
->insert(scroll_parent_border
);
5631 scroll_grandparent
->SetScrollChildren(scroll_children
.release());
5633 gfx::Transform identity_transform
;
5634 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5635 gfx::PointF(), gfx::Size(50, 50), true, false,
5637 SetLayerPropertiesForTesting(scroll_grandparent_border
, identity_transform
,
5638 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5639 true, false, false);
5640 SetLayerPropertiesForTesting(scroll_grandparent_clip
, identity_transform
,
5641 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5642 true, false, false);
5643 SetLayerPropertiesForTesting(scroll_grandparent
, identity_transform
,
5644 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5645 true, false, false);
5646 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
5647 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5649 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
5650 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5651 true, false, false);
5652 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
5653 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5654 true, false, false);
5655 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
5656 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5657 true, false, false);
5658 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
5659 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5661 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
5662 gfx::PointF(), gfx::Size(50, 50), true, false,
5665 ExecuteCalculateDrawProperties(root
);
5667 EXPECT_TRUE(root
->render_surface());
5669 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
5670 scroll_child
->clip_rect().ToString());
5671 EXPECT_TRUE(scroll_child
->is_clipped());
5673 // Despite the fact that we had to process the layers out of order to get the
5674 // right clip, our render_surface_layer_list's order should be unaffected.
5675 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
5676 EXPECT_EQ(root
, render_surface_layer_list_impl()->at(0));
5677 EXPECT_EQ(render_surface2
, render_surface_layer_list_impl()->at(1));
5678 EXPECT_EQ(render_surface1
, render_surface_layer_list_impl()->at(2));
5679 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
5680 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
5681 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
5684 TEST_F(LayerTreeHostCommonTest
, FixedPositionWithInterveningRenderSurface
) {
5685 // Ensures that when we have a render surface between a fixed position layer
5686 // and its container, we compute the fixed position layer's draw transform
5687 // with respect to that intervening render surface, not with respect to its
5688 // container's render target.
5695 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5696 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface
=
5697 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5698 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
5699 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5700 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
5701 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5703 root
->AddChild(render_surface
);
5704 render_surface
->AddChild(fixed
);
5705 fixed
->AddChild(child
);
5707 root
->SetIsContainerForFixedPositionLayers(true);
5708 render_surface
->SetForceRenderSurface(true);
5710 LayerPositionConstraint constraint
;
5711 constraint
.set_is_fixed_position(true);
5712 fixed
->SetPositionConstraint(constraint
);
5714 SetLayerPropertiesForTesting(root
.get(), gfx::Transform(), gfx::Point3F(),
5715 gfx::PointF(), gfx::Size(50, 50), true, false);
5716 SetLayerPropertiesForTesting(render_surface
.get(), gfx::Transform(),
5717 gfx::Point3F(), gfx::PointF(7.f
, 9.f
),
5718 gfx::Size(50, 50), true, false);
5719 SetLayerPropertiesForTesting(fixed
.get(), gfx::Transform(), gfx::Point3F(),
5720 gfx::PointF(10.f
, 15.f
), gfx::Size(50, 50), true,
5722 SetLayerPropertiesForTesting(child
.get(), gfx::Transform(), gfx::Point3F(),
5723 gfx::PointF(1.f
, 2.f
), gfx::Size(50, 50), true,
5726 host()->SetRootLayer(root
);
5728 ExecuteCalculateDrawProperties(root
.get());
5730 gfx::Transform expected_fixed_draw_transform
;
5731 expected_fixed_draw_transform
.Translate(10.f
, 15.f
);
5732 EXPECT_EQ(expected_fixed_draw_transform
, fixed
->draw_transform());
5734 gfx::Transform expected_fixed_screen_space_transform
;
5735 expected_fixed_screen_space_transform
.Translate(17.f
, 24.f
);
5736 EXPECT_EQ(expected_fixed_screen_space_transform
,
5737 fixed
->screen_space_transform());
5739 gfx::Transform expected_child_draw_transform
;
5740 expected_child_draw_transform
.Translate(11.f
, 17.f
);
5741 EXPECT_EQ(expected_child_draw_transform
, child
->draw_transform());
5743 gfx::Transform expected_child_screen_space_transform
;
5744 expected_child_screen_space_transform
.Translate(18.f
, 26.f
);
5745 EXPECT_EQ(expected_child_screen_space_transform
,
5746 child
->screen_space_transform());
5749 TEST_F(LayerTreeHostCommonTest
, ScrollCompensationWithRounding
) {
5750 // This test verifies that a scrolling layer that gets snapped to
5751 // integer coordinates doesn't move a fixed position child.
5758 FakeImplProxy proxy
;
5759 TestSharedBitmapManager shared_bitmap_manager
;
5760 TestTaskGraphRunner task_graph_runner
;
5761 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5762 &task_graph_runner
);
5763 host_impl
.CreatePendingTree();
5764 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
5765 scoped_ptr
<LayerImpl
> container
=
5766 LayerImpl::Create(host_impl
.active_tree(), 2);
5767 LayerImpl
* container_layer
= container
.get();
5768 scoped_ptr
<LayerImpl
> scroller
=
5769 LayerImpl::Create(host_impl
.active_tree(), 3);
5770 LayerImpl
* scroll_layer
= scroller
.get();
5771 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
5772 LayerImpl
* fixed_layer
= fixed
.get();
5774 container
->SetIsContainerForFixedPositionLayers(true);
5776 LayerPositionConstraint constraint
;
5777 constraint
.set_is_fixed_position(true);
5778 fixed
->SetPositionConstraint(constraint
);
5780 scroller
->SetScrollClipLayer(container
->id());
5782 gfx::Transform identity_transform
;
5783 gfx::Transform container_transform
;
5784 container_transform
.Translate3d(10.0, 20.0, 0.0);
5785 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
5787 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
5788 gfx::PointF(), gfx::Size(50, 50), true, false,
5790 SetLayerPropertiesForTesting(container
.get(), container_transform
,
5791 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5792 true, false, false);
5793 SetLayerPropertiesForTesting(scroller
.get(), identity_transform
,
5794 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5795 true, false, false);
5796 SetLayerPropertiesForTesting(fixed
.get(), identity_transform
, gfx::Point3F(),
5797 gfx::PointF(), gfx::Size(50, 50), true, false,
5800 scroller
->AddChild(fixed
.Pass());
5801 container
->AddChild(scroller
.Pass());
5802 root
->AddChild(container
.Pass());
5804 // Rounded to integers already.
5806 gfx::Vector2dF
scroll_delta(3.0, 5.0);
5807 scroll_layer
->SetScrollDelta(scroll_delta
);
5809 LayerImplList render_surface_layer_list
;
5810 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5811 root
.get(), root
->bounds(), &render_surface_layer_list
);
5812 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5814 EXPECT_TRANSFORMATION_MATRIX_EQ(
5815 container_layer
->draw_properties().screen_space_transform
,
5816 fixed_layer
->draw_properties().screen_space_transform
);
5818 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5820 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
5821 .screen_space_transform
.To2dTranslation(),
5822 container_offset
- scroll_delta
);
5825 // Scroll delta requiring rounding.
5827 gfx::Vector2dF
scroll_delta(4.1f
, 8.1f
);
5828 scroll_layer
->SetScrollDelta(scroll_delta
);
5830 gfx::Vector2dF
rounded_scroll_delta(4.f
, 8.f
);
5832 LayerImplList render_surface_layer_list
;
5833 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5834 root
.get(), root
->bounds(), &render_surface_layer_list
);
5835 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5837 EXPECT_TRANSFORMATION_MATRIX_EQ(
5838 container_layer
->draw_properties().screen_space_transform
,
5839 fixed_layer
->draw_properties().screen_space_transform
);
5841 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5843 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
5844 .screen_space_transform
.To2dTranslation(),
5845 container_offset
- rounded_scroll_delta
);
5848 // Scale is applied earlier in the tree.
5850 gfx::Transform scaled_container_transform
= container_transform
;
5851 scaled_container_transform
.Scale3d(3.0, 3.0, 1.0);
5852 container_layer
->SetTransform(scaled_container_transform
);
5854 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
5855 scroll_layer
->SetScrollDelta(scroll_delta
);
5857 LayerImplList render_surface_layer_list
;
5858 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5859 root
.get(), root
->bounds(), &render_surface_layer_list
);
5860 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5862 EXPECT_TRANSFORMATION_MATRIX_EQ(
5863 container_layer
->draw_properties().screen_space_transform
,
5864 fixed_layer
->draw_properties().screen_space_transform
);
5866 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5869 container_layer
->SetTransform(container_transform
);
5872 // Scale is applied on the scroll layer itself.
5874 gfx::Transform scale_transform
;
5875 scale_transform
.Scale3d(3.0, 3.0, 1.0);
5876 scroll_layer
->SetTransform(scale_transform
);
5878 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
5879 scroll_layer
->SetScrollDelta(scroll_delta
);
5881 LayerImplList render_surface_layer_list
;
5882 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5883 root
.get(), root
->bounds(), &render_surface_layer_list
);
5884 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5887 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5890 scroll_layer
->SetTransform(identity_transform
);
5894 TEST_F(LayerTreeHostCommonTest
,
5895 ScrollCompensationMainScrollOffsetFractionalPart
) {
5896 // This test verifies that a scrolling layer that has fractional scroll offset
5897 // from main doesn't move a fixed position child.
5904 FakeImplProxy proxy
;
5905 TestSharedBitmapManager shared_bitmap_manager
;
5906 TestTaskGraphRunner task_graph_runner
;
5907 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5908 &task_graph_runner
);
5909 host_impl
.CreatePendingTree();
5910 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
5911 scoped_ptr
<LayerImpl
> container
=
5912 LayerImpl::Create(host_impl
.active_tree(), 2);
5913 LayerImpl
* container_layer
= container
.get();
5914 scoped_ptr
<LayerImpl
> scroller
=
5915 LayerImpl::Create(host_impl
.active_tree(), 3);
5916 LayerImpl
* scroll_layer
= scroller
.get();
5917 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
5918 LayerImpl
* fixed_layer
= fixed
.get();
5920 container
->SetIsContainerForFixedPositionLayers(true);
5922 LayerPositionConstraint constraint
;
5923 constraint
.set_is_fixed_position(true);
5924 fixed
->SetPositionConstraint(constraint
);
5926 scroller
->SetScrollClipLayer(container
->id());
5928 gfx::Transform identity_transform
;
5929 gfx::Transform container_transform
;
5930 container_transform
.Translate3d(10.0, 20.0, 0.0);
5931 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
5933 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
5934 gfx::PointF(), gfx::Size(50, 50), true, false,
5936 SetLayerPropertiesForTesting(container
.get(), container_transform
,
5937 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5938 true, false, false);
5939 SetLayerPropertiesForTesting(scroller
.get(), identity_transform
,
5940 gfx::Point3F(), gfx::PointF(0.0, 0.0),
5941 gfx::Size(30, 30), true, false, false);
5943 gfx::ScrollOffset
scroll_offset(3.3, 4.2);
5944 gfx::Vector2dF
main_scroll_fractional_part(0.3f
, 0.2f
);
5945 gfx::Vector2dF
scroll_delta(0.1f
, 0.4f
);
5946 // Blink only uses the integer part of the scroll_offset for fixed
5948 SetLayerPropertiesForTesting(fixed
.get(), identity_transform
, gfx::Point3F(),
5949 gfx::PointF(3.0f
, 4.0f
), gfx::Size(50, 50), true,
5951 scroll_layer
->PushScrollOffsetFromMainThread(scroll_offset
);
5952 scroll_layer
->SetScrollDelta(scroll_delta
);
5953 scroll_layer
->SetScrollCompensationAdjustment(main_scroll_fractional_part
);
5955 scroller
->AddChild(fixed
.Pass());
5956 container
->AddChild(scroller
.Pass());
5957 root
->AddChild(container
.Pass());
5959 LayerImplList render_surface_layer_list
;
5960 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5961 root
.get(), root
->bounds(), &render_surface_layer_list
);
5962 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5964 EXPECT_TRANSFORMATION_MATRIX_EQ(
5965 container_layer
->draw_properties().screen_space_transform
,
5966 fixed_layer
->draw_properties().screen_space_transform
);
5968 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5971 gfx::ScrollOffset effective_scroll_offset
=
5972 ScrollOffsetWithDelta(scroll_offset
, scroll_delta
);
5973 gfx::Vector2d rounded_effective_scroll_offset
=
5974 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset
));
5976 scroll_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5977 container_offset
- rounded_effective_scroll_offset
);
5980 TEST_F(LayerTreeHostCommonTest
,
5981 ScrollSnappingWithAnimatedScreenSpaceTransform
) {
5982 // This test verifies that a scrolling layer whose screen space transform is
5983 // animating doesn't get snapped to integer coordinates.
5991 LayerImpl
* root
= root_layer();
5992 LayerImpl
* animated_layer
= AddChildToRoot
<FakePictureLayerImpl
>();
5993 LayerImpl
* surface
= AddChild
<LayerImpl
>(animated_layer
);
5994 LayerImpl
* container
= AddChild
<LayerImpl
>(surface
);
5995 LayerImpl
* scroller
= AddChild
<LayerImpl
>(container
);
5996 scroller
->SetScrollClipLayer(container
->id());
5997 scroller
->SetDrawsContent(true);
5999 gfx::Transform identity_transform
;
6000 gfx::Transform start_scale
;
6001 start_scale
.Scale(1.5f
, 1.5f
);
6002 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
6003 gfx::PointF(), gfx::Size(50, 50), true, false,
6005 SetLayerPropertiesForTesting(animated_layer
, start_scale
, gfx::Point3F(),
6006 gfx::PointF(), gfx::Size(50, 50), true, false,
6008 SetLayerPropertiesForTesting(surface
, identity_transform
, gfx::Point3F(),
6009 gfx::PointF(), gfx::Size(50, 50), true, false,
6011 SetLayerPropertiesForTesting(container
, identity_transform
, gfx::Point3F(),
6012 gfx::PointF(), gfx::Size(50, 50), true, false,
6014 SetLayerPropertiesForTesting(scroller
, identity_transform
, gfx::Point3F(),
6015 gfx::PointF(), gfx::Size(100, 100), true, false,
6018 gfx::Transform end_scale
;
6019 end_scale
.Scale(2.f
, 2.f
);
6020 TransformOperations start_operations
;
6021 start_operations
.AppendMatrix(start_scale
);
6022 TransformOperations end_operations
;
6023 end_operations
.AppendMatrix(end_scale
);
6024 AddAnimatedTransformToLayer(animated_layer
, 1.0, start_operations
,
6027 gfx::Vector2dF
scroll_delta(5.f
, 9.f
);
6028 scroller
->SetScrollDelta(scroll_delta
);
6030 ExecuteCalculateDrawProperties(root
);
6032 gfx::Vector2dF
expected_draw_transform_translation(-7.5f
, -13.5f
);
6033 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation
,
6034 scroller
->draw_transform().To2dTranslation());
6037 class AnimationScaleFactorTrackingLayerImpl
: public LayerImpl
{
6039 static scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> Create(
6040 LayerTreeImpl
* tree_impl
,
6042 return make_scoped_ptr(
6043 new AnimationScaleFactorTrackingLayerImpl(tree_impl
, id
));
6046 ~AnimationScaleFactorTrackingLayerImpl() override
{}
6049 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl
* tree_impl
,
6051 : LayerImpl(tree_impl
, id
) {
6052 SetDrawsContent(true);
6056 TEST_F(LayerTreeHostCommonTest
, MaximumAnimationScaleFactor
) {
6057 FakeImplProxy proxy
;
6058 TestSharedBitmapManager shared_bitmap_manager
;
6059 TestTaskGraphRunner task_graph_runner
;
6060 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
6061 &task_graph_runner
);
6062 gfx::Transform identity_matrix
;
6063 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_parent
=
6064 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 1);
6065 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> parent
=
6066 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 2);
6067 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> child
=
6068 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 3);
6069 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_child
=
6070 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 4);
6072 AnimationScaleFactorTrackingLayerImpl
* parent_raw
= parent
.get();
6073 AnimationScaleFactorTrackingLayerImpl
* child_raw
= child
.get();
6074 AnimationScaleFactorTrackingLayerImpl
* grand_child_raw
= grand_child
.get();
6076 child
->AddChild(grand_child
.Pass());
6077 parent
->AddChild(child
.Pass());
6078 grand_parent
->AddChild(parent
.Pass());
6080 SetLayerPropertiesForTesting(grand_parent
.get(), identity_matrix
,
6081 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6083 SetLayerPropertiesForTesting(parent_raw
, identity_matrix
, gfx::Point3F(),
6084 gfx::PointF(), gfx::Size(1, 2), true, false,
6086 SetLayerPropertiesForTesting(child_raw
, identity_matrix
, gfx::Point3F(),
6087 gfx::PointF(), gfx::Size(1, 2), true, false,
6090 SetLayerPropertiesForTesting(grand_child_raw
, identity_matrix
, gfx::Point3F(),
6091 gfx::PointF(), gfx::Size(1, 2), true, false,
6094 ExecuteCalculateDrawProperties(grand_parent
.get());
6096 // No layers have animations.
6098 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6100 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6101 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6103 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6105 TransformOperations translation
;
6106 translation
.AppendTranslate(1.f
, 2.f
, 3.f
);
6108 AddAnimatedTransformToLayer(
6109 parent_raw
, 1.0, TransformOperations(), translation
);
6111 // No layers have scale-affecting animations.
6113 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6115 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6116 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6118 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6120 TransformOperations scale
;
6121 scale
.AppendScale(5.f
, 4.f
, 3.f
);
6123 AddAnimatedTransformToLayer(child_raw
, 1.0, TransformOperations(), scale
);
6124 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6125 ExecuteCalculateDrawProperties(grand_parent
.get());
6127 // Only |child| has a scale-affecting animation.
6129 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6131 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6132 EXPECT_EQ(5.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6134 5.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6136 AddAnimatedTransformToLayer(
6137 grand_parent
.get(), 1.0, TransformOperations(), scale
);
6138 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6139 ExecuteCalculateDrawProperties(grand_parent
.get());
6141 // |grand_parent| and |child| have scale-affecting animations.
6143 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6145 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6146 // We don't support combining animated scales from two nodes; 0.f means
6147 // that the maximum scale could not be computed.
6148 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6150 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6152 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
6153 parent_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6154 ExecuteCalculateDrawProperties(grand_parent
.get());
6156 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
6158 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6160 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6161 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6163 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6165 grand_parent
->layer_animation_controller()->AbortAnimations(
6166 Animation::TRANSFORM
);
6167 parent_raw
->layer_animation_controller()->AbortAnimations(
6168 Animation::TRANSFORM
);
6169 child_raw
->layer_animation_controller()->AbortAnimations(
6170 Animation::TRANSFORM
);
6172 TransformOperations perspective
;
6173 perspective
.AppendPerspective(10.f
);
6175 AddAnimatedTransformToLayer(
6176 child_raw
, 1.0, TransformOperations(), perspective
);
6177 ExecuteCalculateDrawProperties(grand_parent
.get());
6179 // |child| has a scale-affecting animation but computing the maximum of this
6180 // animation is not supported.
6182 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6184 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6185 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6187 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6189 child_raw
->layer_animation_controller()->AbortAnimations(
6190 Animation::TRANSFORM
);
6192 gfx::Transform scale_matrix
;
6193 scale_matrix
.Scale(1.f
, 2.f
);
6194 grand_parent
->SetTransform(scale_matrix
);
6195 parent_raw
->SetTransform(scale_matrix
);
6196 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6197 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
6198 ExecuteCalculateDrawProperties(grand_parent
.get());
6200 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
6201 // animation with maximum scale 5.f.
6203 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6205 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6207 child_raw
->draw_properties().maximum_animation_contents_scale
);
6210 grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6212 gfx::Transform perspective_matrix
;
6213 perspective_matrix
.ApplyPerspectiveDepth(2.f
);
6214 child_raw
->SetTransform(perspective_matrix
);
6215 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6216 ExecuteCalculateDrawProperties(grand_parent
.get());
6218 // |child| has a transform that's neither a translation nor a scale.
6220 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6222 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6223 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6225 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6227 parent_raw
->SetTransform(perspective_matrix
);
6228 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6229 ExecuteCalculateDrawProperties(grand_parent
.get());
6231 // |parent| and |child| have transforms that are neither translations nor
6234 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6236 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6237 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6239 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6241 parent_raw
->SetTransform(identity_matrix
);
6242 child_raw
->SetTransform(identity_matrix
);
6243 grand_parent
->SetTransform(perspective_matrix
);
6244 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6246 ExecuteCalculateDrawProperties(grand_parent
.get());
6248 // |grand_parent| has a transform that's neither a translation nor a scale.
6250 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6252 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6253 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6255 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6258 static int membership_id(LayerImpl
* layer
) {
6259 return layer
->draw_properties().last_drawn_render_surface_layer_list_id
;
6262 static void GatherDrawnLayers(LayerImplList
* rsll
,
6263 std::set
<LayerImpl
*>* drawn_layers
) {
6264 for (LayerIterator it
= LayerIterator::Begin(rsll
),
6265 end
= LayerIterator::End(rsll
);
6267 LayerImpl
* layer
= *it
;
6268 if (it
.represents_itself())
6269 drawn_layers
->insert(layer
);
6271 if (!it
.represents_contributing_render_surface())
6274 if (layer
->mask_layer())
6275 drawn_layers
->insert(layer
->mask_layer());
6276 if (layer
->replica_layer() && layer
->replica_layer()->mask_layer())
6277 drawn_layers
->insert(layer
->replica_layer()->mask_layer());
6281 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceLayerListMembership
) {
6282 FakeImplProxy proxy
;
6283 TestSharedBitmapManager shared_bitmap_manager
;
6284 TestTaskGraphRunner task_graph_runner
;
6285 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
6286 &task_graph_runner
);
6287 gfx::Transform identity_matrix
;
6289 scoped_ptr
<LayerImpl
> grand_parent
=
6290 LayerImpl::Create(host_impl
.active_tree(), 1);
6291 scoped_ptr
<LayerImpl
> parent
= LayerImpl::Create(host_impl
.active_tree(), 3);
6292 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 5);
6293 scoped_ptr
<LayerImpl
> grand_child1
=
6294 LayerImpl::Create(host_impl
.active_tree(), 7);
6295 scoped_ptr
<LayerImpl
> grand_child2
=
6296 LayerImpl::Create(host_impl
.active_tree(), 9);
6298 LayerImpl
* grand_parent_raw
= grand_parent
.get();
6299 LayerImpl
* parent_raw
= parent
.get();
6300 LayerImpl
* child_raw
= child
.get();
6301 LayerImpl
* grand_child1_raw
= grand_child1
.get();
6302 LayerImpl
* grand_child2_raw
= grand_child2
.get();
6304 child
->AddChild(grand_child1
.Pass());
6305 child
->AddChild(grand_child2
.Pass());
6306 parent
->AddChild(child
.Pass());
6307 grand_parent
->AddChild(parent
.Pass());
6309 SetLayerPropertiesForTesting(grand_parent_raw
, identity_matrix
,
6310 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6312 SetLayerPropertiesForTesting(parent_raw
, identity_matrix
, gfx::Point3F(),
6313 gfx::PointF(), gfx::Size(1, 2), true, false,
6316 SetLayerPropertiesForTesting(child_raw
, identity_matrix
, gfx::Point3F(),
6317 gfx::PointF(), gfx::Size(1, 2), true, false,
6320 SetLayerPropertiesForTesting(grand_child1_raw
, identity_matrix
,
6321 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6322 true, false, false);
6324 SetLayerPropertiesForTesting(grand_child2_raw
, identity_matrix
,
6325 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6326 true, false, false);
6328 // Start with nothing being drawn.
6329 ExecuteCalculateDrawProperties(grand_parent_raw
);
6330 int member_id
= render_surface_layer_list_count();
6332 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6333 EXPECT_NE(member_id
, membership_id(parent_raw
));
6334 EXPECT_NE(member_id
, membership_id(child_raw
));
6335 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6336 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6338 std::set
<LayerImpl
*> expected
;
6339 std::set
<LayerImpl
*> actual
;
6340 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6341 EXPECT_EQ(expected
, actual
);
6343 // If we force render surface, but none of the layers are in the layer list,
6344 // then this layer should not appear in RSLL.
6345 grand_child1_raw
->SetHasRenderSurface(true);
6347 ExecuteCalculateDrawProperties(grand_parent_raw
);
6348 member_id
= render_surface_layer_list_count();
6350 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6351 EXPECT_NE(member_id
, membership_id(parent_raw
));
6352 EXPECT_NE(member_id
, membership_id(child_raw
));
6353 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6354 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6358 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6359 EXPECT_EQ(expected
, actual
);
6361 // However, if we say that this layer also draws content, it will appear in
6363 grand_child1_raw
->SetDrawsContent(true);
6365 ExecuteCalculateDrawProperties(grand_parent_raw
);
6366 member_id
= render_surface_layer_list_count();
6368 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6369 EXPECT_NE(member_id
, membership_id(parent_raw
));
6370 EXPECT_NE(member_id
, membership_id(child_raw
));
6371 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
6372 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6375 expected
.insert(grand_child1_raw
);
6378 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6379 EXPECT_EQ(expected
, actual
);
6381 // Now child is forced to have a render surface, and one if its children draws
6383 grand_child1_raw
->SetDrawsContent(false);
6384 grand_child1_raw
->SetHasRenderSurface(false);
6385 child_raw
->SetHasRenderSurface(true);
6386 grand_child2_raw
->SetDrawsContent(true);
6388 ExecuteCalculateDrawProperties(grand_parent_raw
);
6389 member_id
= render_surface_layer_list_count();
6391 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6392 EXPECT_NE(member_id
, membership_id(parent_raw
));
6393 EXPECT_NE(member_id
, membership_id(child_raw
));
6394 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6395 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6398 expected
.insert(grand_child2_raw
);
6401 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6402 EXPECT_EQ(expected
, actual
);
6404 // Add a mask layer to child.
6405 child_raw
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6).Pass());
6406 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6408 ExecuteCalculateDrawProperties(grand_parent_raw
);
6409 member_id
= render_surface_layer_list_count();
6411 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6412 EXPECT_NE(member_id
, membership_id(parent_raw
));
6413 EXPECT_NE(member_id
, membership_id(child_raw
));
6414 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
6415 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6416 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6419 expected
.insert(grand_child2_raw
);
6420 expected
.insert(child_raw
->mask_layer());
6423 expected
.insert(grand_child2_raw
);
6424 expected
.insert(child_raw
->mask_layer());
6427 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6428 EXPECT_EQ(expected
, actual
);
6430 // Add replica mask layer.
6431 scoped_ptr
<LayerImpl
> replica_layer
=
6432 LayerImpl::Create(host_impl
.active_tree(), 20);
6433 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 21));
6434 child_raw
->SetReplicaLayer(replica_layer
.Pass());
6436 ExecuteCalculateDrawProperties(grand_parent_raw
);
6437 member_id
= render_surface_layer_list_count();
6439 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6440 EXPECT_NE(member_id
, membership_id(parent_raw
));
6441 EXPECT_NE(member_id
, membership_id(child_raw
));
6442 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
6443 EXPECT_EQ(member_id
, membership_id(child_raw
->replica_layer()->mask_layer()));
6444 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6445 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6448 expected
.insert(grand_child2_raw
);
6449 expected
.insert(child_raw
->mask_layer());
6450 expected
.insert(child_raw
->replica_layer()->mask_layer());
6453 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6454 EXPECT_EQ(expected
, actual
);
6456 child_raw
->TakeReplicaLayer();
6458 // With nothing drawing, we should have no layers.
6459 grand_child2_raw
->SetDrawsContent(false);
6461 ExecuteCalculateDrawProperties(grand_parent_raw
);
6462 member_id
= render_surface_layer_list_count();
6464 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6465 EXPECT_NE(member_id
, membership_id(parent_raw
));
6466 EXPECT_NE(member_id
, membership_id(child_raw
));
6467 EXPECT_NE(member_id
, membership_id(child_raw
->mask_layer()));
6468 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6469 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6473 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6474 EXPECT_EQ(expected
, actual
);
6476 // Child itself draws means that we should have the child and the mask in the
6478 child_raw
->SetDrawsContent(true);
6480 ExecuteCalculateDrawProperties(grand_parent_raw
);
6481 member_id
= render_surface_layer_list_count();
6483 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6484 EXPECT_NE(member_id
, membership_id(parent_raw
));
6485 EXPECT_EQ(member_id
, membership_id(child_raw
));
6486 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
6487 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6488 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6491 expected
.insert(child_raw
);
6492 expected
.insert(child_raw
->mask_layer());
6494 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6495 EXPECT_EQ(expected
, actual
);
6497 child_raw
->TakeMaskLayer();
6498 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6500 // Now everyone's a member!
6501 grand_parent_raw
->SetDrawsContent(true);
6502 parent_raw
->SetDrawsContent(true);
6503 child_raw
->SetDrawsContent(true);
6504 grand_child1_raw
->SetDrawsContent(true);
6505 grand_child2_raw
->SetDrawsContent(true);
6507 ExecuteCalculateDrawProperties(grand_parent_raw
);
6508 member_id
= render_surface_layer_list_count();
6510 EXPECT_EQ(member_id
, membership_id(grand_parent_raw
));
6511 EXPECT_EQ(member_id
, membership_id(parent_raw
));
6512 EXPECT_EQ(member_id
, membership_id(child_raw
));
6513 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
6514 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6517 expected
.insert(grand_parent_raw
);
6518 expected
.insert(parent_raw
);
6519 expected
.insert(child_raw
);
6520 expected
.insert(grand_child1_raw
);
6521 expected
.insert(grand_child2_raw
);
6524 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6525 EXPECT_EQ(expected
, actual
);
6528 TEST_F(LayerTreeHostCommonTest
, DrawPropertyScales
) {
6529 FakeImplProxy proxy
;
6530 TestSharedBitmapManager shared_bitmap_manager
;
6531 TestTaskGraphRunner task_graph_runner
;
6532 LayerTreeSettings settings
;
6533 settings
.layer_transforms_should_scale_layer_contents
= true;
6534 FakeLayerTreeHostImpl
host_impl(settings
, &proxy
, &shared_bitmap_manager
,
6535 &task_graph_runner
);
6537 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
6538 LayerImpl
* root_layer
= root
.get();
6539 scoped_ptr
<LayerImpl
> child1
= LayerImpl::Create(host_impl
.active_tree(), 2);
6540 LayerImpl
* child1_layer
= child1
.get();
6541 scoped_ptr
<LayerImpl
> child2
= LayerImpl::Create(host_impl
.active_tree(), 3);
6542 LayerImpl
* child2_layer
= child2
.get();
6544 root
->AddChild(child1
.Pass());
6545 root
->AddChild(child2
.Pass());
6546 root
->SetHasRenderSurface(true);
6548 gfx::Transform identity_matrix
, scale_transform_child1
,
6549 scale_transform_child2
;
6550 scale_transform_child1
.Scale(2, 3);
6551 scale_transform_child2
.Scale(4, 5);
6553 SetLayerPropertiesForTesting(root_layer
, identity_matrix
, gfx::Point3F(),
6554 gfx::PointF(), gfx::Size(1, 1), true, false,
6556 SetLayerPropertiesForTesting(child1_layer
, scale_transform_child1
,
6557 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
6560 child1_layer
->SetMaskLayer(
6561 LayerImpl::Create(host_impl
.active_tree(), 4).Pass());
6563 scoped_ptr
<LayerImpl
> replica_layer
=
6564 LayerImpl::Create(host_impl
.active_tree(), 5);
6565 replica_layer
->SetHasRenderSurface(true);
6566 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6));
6567 child1_layer
->SetReplicaLayer(replica_layer
.Pass());
6568 child1_layer
->SetHasRenderSurface(true);
6570 ExecuteCalculateDrawProperties(root_layer
);
6572 TransformOperations scale
;
6573 scale
.AppendScale(5.f
, 8.f
, 3.f
);
6575 AddAnimatedTransformToLayer(child2_layer
, 1.0, TransformOperations(), scale
);
6576 SetLayerPropertiesForTesting(child2_layer
, scale_transform_child2
,
6577 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
6580 ExecuteCalculateDrawProperties(root_layer
);
6582 EXPECT_FLOAT_EQ(1.f
, root_layer
->GetIdealContentsScale());
6583 EXPECT_FLOAT_EQ(3.f
, child1_layer
->GetIdealContentsScale());
6584 EXPECT_FLOAT_EQ(3.f
, child1_layer
->mask_layer()->GetIdealContentsScale());
6585 EXPECT_FLOAT_EQ(5.f
, child2_layer
->GetIdealContentsScale());
6588 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
6590 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
6591 EXPECT_FLOAT_EQ(0.f
,
6592 child1_layer
->mask_layer()
6594 .maximum_animation_contents_scale
);
6595 EXPECT_FLOAT_EQ(0.f
,
6596 child1_layer
->replica_layer()
6599 .maximum_animation_contents_scale
);
6601 8.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
6603 // Changing page-scale would affect ideal_contents_scale and
6604 // maximum_animation_contents_scale.
6606 float page_scale_factor
= 3.f
;
6607 float device_scale_factor
= 1.0f
;
6608 std::vector
<LayerImpl
*> render_surface_layer_list
;
6609 gfx::Size device_viewport_size
=
6610 gfx::Size(root_layer
->bounds().width() * device_scale_factor
,
6611 root_layer
->bounds().height() * device_scale_factor
);
6612 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6613 root_layer
, device_viewport_size
, &render_surface_layer_list
);
6615 inputs
.page_scale_factor
= page_scale_factor
;
6616 inputs
.can_adjust_raster_scales
= true;
6617 inputs
.page_scale_layer
= root_layer
;
6618 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6620 EXPECT_FLOAT_EQ(3.f
, root_layer
->GetIdealContentsScale());
6621 EXPECT_FLOAT_EQ(9.f
, child1_layer
->GetIdealContentsScale());
6622 EXPECT_FLOAT_EQ(9.f
, child1_layer
->mask_layer()->GetIdealContentsScale());
6625 child1_layer
->replica_layer()->mask_layer()->GetIdealContentsScale());
6626 EXPECT_FLOAT_EQ(15.f
, child2_layer
->GetIdealContentsScale());
6629 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
6631 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
6632 EXPECT_FLOAT_EQ(0.f
,
6633 child1_layer
->mask_layer()
6635 .maximum_animation_contents_scale
);
6636 EXPECT_FLOAT_EQ(0.f
,
6637 child1_layer
->replica_layer()
6640 .maximum_animation_contents_scale
);
6642 24.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
6644 // Changing device-scale would affect ideal_contents_scale and
6645 // maximum_animation_contents_scale.
6647 device_scale_factor
= 4.0f
;
6648 inputs
.device_scale_factor
= device_scale_factor
;
6649 inputs
.can_adjust_raster_scales
= true;
6650 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6652 EXPECT_FLOAT_EQ(12.f
, root_layer
->GetIdealContentsScale());
6653 EXPECT_FLOAT_EQ(36.f
, child1_layer
->GetIdealContentsScale());
6654 EXPECT_FLOAT_EQ(36.f
, child1_layer
->mask_layer()->GetIdealContentsScale());
6657 child1_layer
->replica_layer()->mask_layer()->GetIdealContentsScale());
6658 EXPECT_FLOAT_EQ(60.f
, child2_layer
->GetIdealContentsScale());
6661 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
6663 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
6664 EXPECT_FLOAT_EQ(0.f
,
6665 child1_layer
->mask_layer()
6667 .maximum_animation_contents_scale
);
6668 EXPECT_FLOAT_EQ(0.f
,
6669 child1_layer
->replica_layer()
6672 .maximum_animation_contents_scale
);
6674 96.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
6677 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInChildRenderSurface
) {
6678 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6679 SetLayerPropertiesForTesting(root
.get(),
6683 gfx::Size(768 / 2, 3000),
6686 root
->SetIsDrawable(true);
6688 scoped_refptr
<Layer
> clip
= Layer::Create(layer_settings());
6689 SetLayerPropertiesForTesting(clip
.get(),
6693 gfx::Size(768 / 2, 10000),
6696 clip
->SetMasksToBounds(true);
6698 scoped_refptr
<Layer
> content
= Layer::Create(layer_settings());
6699 SetLayerPropertiesForTesting(content
.get(),
6703 gfx::Size(768 / 2, 10000),
6706 content
->SetIsDrawable(true);
6707 content
->SetForceRenderSurface(true);
6709 root
->AddChild(clip
);
6710 clip
->AddChild(content
);
6712 host()->SetRootLayer(root
);
6714 gfx::Size
device_viewport_size(768, 582);
6715 RenderSurfaceLayerList render_surface_layer_list
;
6716 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6717 host()->root_layer(), device_viewport_size
, &render_surface_layer_list
);
6718 inputs
.device_scale_factor
= 2.f
;
6719 inputs
.page_scale_factor
= 1.f
;
6720 inputs
.page_scale_layer
= NULL
;
6721 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6723 // Layers in the root render surface have their visible content rect clipped
6725 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
6726 root
->visible_rect_from_property_trees());
6728 // Layers drawing to a child render surface should still have their visible
6729 // content rect clipped by the viewport.
6730 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
6731 content
->visible_rect_from_property_trees());
6734 TEST_F(LayerTreeHostCommonTest
, BoundsDeltaAffectVisibleContentRect
) {
6735 FakeImplProxy proxy
;
6736 TestSharedBitmapManager shared_bitmap_manager
;
6737 TestTaskGraphRunner task_graph_runner
;
6738 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
6739 &task_graph_runner
);
6741 // Set two layers: the root layer clips it's child,
6742 // the child draws its content.
6744 gfx::Size root_size
= gfx::Size(300, 500);
6746 // Sublayer should be bigger than the root enlarged by bounds_delta.
6747 gfx::Size sublayer_size
= gfx::Size(300, 1000);
6749 // Device viewport accomidated the root and the top controls.
6750 gfx::Size device_viewport_size
= gfx::Size(300, 600);
6751 gfx::Transform identity_matrix
;
6753 host_impl
.SetViewportSize(device_viewport_size
);
6754 host_impl
.active_tree()->SetRootLayer(
6755 LayerImpl::Create(host_impl
.active_tree(), 1));
6757 LayerImpl
* root
= host_impl
.active_tree()->root_layer();
6758 SetLayerPropertiesForTesting(root
,
6766 root
->SetMasksToBounds(true);
6768 root
->AddChild(LayerImpl::Create(host_impl
.active_tree(), 2));
6770 LayerImpl
* sublayer
= root
->child_at(0);
6771 SetLayerPropertiesForTesting(sublayer
,
6779 sublayer
->SetDrawsContent(true);
6781 LayerImplList layer_impl_list
;
6782 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6783 root
, device_viewport_size
, &layer_impl_list
);
6785 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6787 EXPECT_EQ(gfx::Rect(root_size
), sublayer
->visible_layer_rect());
6789 root
->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
6791 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6793 gfx::Rect
affected_by_delta(0, 0, root_size
.width(),
6794 root_size
.height() + 50);
6795 EXPECT_EQ(affected_by_delta
, sublayer
->visible_layer_rect());
6798 TEST_F(LayerTreeHostCommonTest
, NodesAffectedByBoundsDeltaGetUpdated
) {
6799 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6800 scoped_refptr
<Layer
> inner_viewport_container_layer
=
6801 Layer::Create(layer_settings());
6802 scoped_refptr
<Layer
> inner_viewport_scroll_layer
=
6803 Layer::Create(layer_settings());
6804 scoped_refptr
<Layer
> outer_viewport_container_layer
=
6805 Layer::Create(layer_settings());
6806 scoped_refptr
<Layer
> outer_viewport_scroll_layer
=
6807 Layer::Create(layer_settings());
6809 root
->AddChild(inner_viewport_container_layer
);
6810 inner_viewport_container_layer
->AddChild(inner_viewport_scroll_layer
);
6811 inner_viewport_scroll_layer
->AddChild(outer_viewport_container_layer
);
6812 outer_viewport_container_layer
->AddChild(outer_viewport_scroll_layer
);
6814 inner_viewport_scroll_layer
->SetScrollClipLayerId(
6815 inner_viewport_container_layer
->id());
6816 outer_viewport_scroll_layer
->SetScrollClipLayerId(
6817 outer_viewport_container_layer
->id());
6819 inner_viewport_scroll_layer
->SetIsContainerForFixedPositionLayers(true);
6820 outer_viewport_scroll_layer
->SetIsContainerForFixedPositionLayers(true);
6822 host()->SetRootLayer(root
);
6823 host()->RegisterViewportLayers(nullptr, root
, inner_viewport_scroll_layer
,
6824 outer_viewport_scroll_layer
);
6826 scoped_refptr
<Layer
> fixed_to_inner
= Layer::Create(layer_settings());
6827 scoped_refptr
<Layer
> fixed_to_outer
= Layer::Create(layer_settings());
6829 inner_viewport_scroll_layer
->AddChild(fixed_to_inner
);
6830 outer_viewport_scroll_layer
->AddChild(fixed_to_outer
);
6832 LayerPositionConstraint fixed_to_right
;
6833 fixed_to_right
.set_is_fixed_position(true);
6834 fixed_to_right
.set_is_fixed_to_right_edge(true);
6836 fixed_to_inner
->SetPositionConstraint(fixed_to_right
);
6837 fixed_to_outer
->SetPositionConstraint(fixed_to_right
);
6839 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6841 TransformTree
& transform_tree
= host()->property_trees()->transform_tree
;
6842 EXPECT_TRUE(transform_tree
.HasNodesAffectedByInnerViewportBoundsDelta());
6843 EXPECT_TRUE(transform_tree
.HasNodesAffectedByOuterViewportBoundsDelta());
6845 LayerPositionConstraint fixed_to_left
;
6846 fixed_to_left
.set_is_fixed_position(true);
6847 fixed_to_inner
->SetPositionConstraint(fixed_to_left
);
6849 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6850 EXPECT_FALSE(transform_tree
.HasNodesAffectedByInnerViewportBoundsDelta());
6851 EXPECT_TRUE(transform_tree
.HasNodesAffectedByOuterViewportBoundsDelta());
6853 fixed_to_outer
->SetPositionConstraint(fixed_to_left
);
6855 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6856 EXPECT_FALSE(transform_tree
.HasNodesAffectedByInnerViewportBoundsDelta());
6857 EXPECT_FALSE(transform_tree
.HasNodesAffectedByOuterViewportBoundsDelta());
6860 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectForAnimatedLayer
) {
6861 const gfx::Transform identity_matrix
;
6862 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6863 scoped_refptr
<LayerWithForcedDrawsContent
> animated
=
6864 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6866 root
->AddChild(animated
);
6868 host()->SetRootLayer(root
);
6870 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
6871 gfx::PointF(), gfx::Size(100, 100), true, false);
6872 SetLayerPropertiesForTesting(animated
.get(), identity_matrix
, gfx::Point3F(),
6873 gfx::PointF(), gfx::Size(20, 20), true, false);
6875 root
->SetMasksToBounds(true);
6876 root
->SetForceRenderSurface(true);
6877 animated
->SetOpacity(0.f
);
6879 AddOpacityTransitionToController(animated
->layer_animation_controller(), 10.0,
6882 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6884 EXPECT_FALSE(animated
->visible_rect_from_property_trees().IsEmpty());
6887 TEST_F(LayerTreeHostCommonTest
,
6888 VisibleContentRectForAnimatedLayerWithSingularTransform
) {
6889 const gfx::Transform identity_matrix
;
6890 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6891 scoped_refptr
<Layer
> clip
= Layer::Create(layer_settings());
6892 scoped_refptr
<LayerWithForcedDrawsContent
> animated
=
6893 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6894 scoped_refptr
<LayerWithForcedDrawsContent
> surface
=
6895 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6896 scoped_refptr
<LayerWithForcedDrawsContent
> descendant_of_animation
=
6897 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6899 root
->AddChild(clip
);
6900 clip
->AddChild(animated
);
6901 animated
->AddChild(surface
);
6902 surface
->AddChild(descendant_of_animation
);
6904 clip
->SetMasksToBounds(true);
6905 surface
->SetForceRenderSurface(true);
6907 host()->SetRootLayer(root
);
6909 gfx::Transform uninvertible_matrix
;
6910 uninvertible_matrix
.Scale3d(6.f
, 6.f
, 0.f
);
6912 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
6913 gfx::PointF(), gfx::Size(100, 100), true, false);
6914 SetLayerPropertiesForTesting(clip
.get(), identity_matrix
, gfx::Point3F(),
6915 gfx::PointF(), gfx::Size(10, 10), true, false);
6916 SetLayerPropertiesForTesting(animated
.get(), uninvertible_matrix
,
6917 gfx::Point3F(), gfx::PointF(),
6918 gfx::Size(120, 120), true, false);
6919 SetLayerPropertiesForTesting(surface
.get(), identity_matrix
, gfx::Point3F(),
6920 gfx::PointF(), gfx::Size(100, 100), true, false);
6921 SetLayerPropertiesForTesting(descendant_of_animation
.get(), identity_matrix
,
6922 gfx::Point3F(), gfx::PointF(),
6923 gfx::Size(200, 200), true, false);
6925 TransformOperations start_transform_operations
;
6926 start_transform_operations
.AppendMatrix(uninvertible_matrix
);
6927 TransformOperations end_transform_operations
;
6929 AddAnimatedTransformToLayer(animated
.get(), 10.0, start_transform_operations
,
6930 end_transform_operations
);
6932 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6934 // The animated layer has a singular transform and maps to a non-empty rect in
6935 // clipped target space, so is treated as fully visible.
6936 EXPECT_EQ(gfx::Rect(120, 120), animated
->visible_rect_from_property_trees());
6938 // The singular transform on |animated| is flattened when inherited by
6939 // |surface|, and this happens to make it invertible.
6940 EXPECT_EQ(gfx::Rect(2, 2), surface
->visible_rect_from_property_trees());
6941 EXPECT_EQ(gfx::Rect(2, 2),
6942 descendant_of_animation
->visible_rect_from_property_trees());
6944 gfx::Transform zero_matrix
;
6945 zero_matrix
.Scale3d(0.f
, 0.f
, 0.f
);
6946 SetLayerPropertiesForTesting(animated
.get(), zero_matrix
, gfx::Point3F(),
6947 gfx::PointF(), gfx::Size(120, 120), true, false);
6949 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6951 // The animated layer maps to the empty rect in clipped target space, so is
6952 // treated as having an empty visible rect.
6953 EXPECT_EQ(gfx::Rect(), animated
->visible_rect_from_property_trees());
6955 // This time, flattening does not make |animated|'s transform invertible. This
6956 // means the clip cannot be projected into |surface|'s space, so we treat
6957 // |surface| and layers that draw into it as having empty visible rect.
6958 EXPECT_EQ(gfx::Rect(), surface
->visible_rect_from_property_trees());
6959 EXPECT_EQ(gfx::Rect(),
6960 descendant_of_animation
->visible_rect_from_property_trees());
6963 // Verify that having an animated filter (but no current filter, as these
6964 // are mutually exclusive) correctly creates a render surface.
6965 TEST_F(LayerTreeHostCommonTest
, AnimatedFilterCreatesRenderSurface
) {
6966 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6967 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
6968 scoped_refptr
<Layer
> grandchild
= Layer::Create(layer_settings());
6969 root
->AddChild(child
);
6970 child
->AddChild(grandchild
);
6972 gfx::Transform identity_transform
;
6973 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
6974 gfx::PointF(), gfx::Size(50, 50), true, false);
6975 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
6976 gfx::PointF(), gfx::Size(50, 50), true, false);
6977 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
6978 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6980 host()->SetRootLayer(root
);
6982 AddAnimatedFilterToLayer(child
.get(), 10.0, 0.1f
, 0.2f
);
6984 ExecuteCalculateDrawProperties(root
.get());
6986 EXPECT_TRUE(root
->render_surface());
6987 EXPECT_TRUE(child
->render_surface());
6988 EXPECT_FALSE(grandchild
->render_surface());
6990 EXPECT_TRUE(root
->filters().IsEmpty());
6991 EXPECT_TRUE(child
->filters().IsEmpty());
6992 EXPECT_TRUE(grandchild
->filters().IsEmpty());
6994 EXPECT_FALSE(root
->FilterIsAnimating());
6995 EXPECT_TRUE(child
->FilterIsAnimating());
6996 EXPECT_FALSE(grandchild
->FilterIsAnimating());
6999 // Verify that having a filter animation with a delayed start time creates a
7001 TEST_F(LayerTreeHostCommonTest
, DelayedFilterAnimationCreatesRenderSurface
) {
7002 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7003 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7004 scoped_refptr
<Layer
> grandchild
= Layer::Create(layer_settings());
7005 root
->AddChild(child
);
7006 child
->AddChild(grandchild
);
7008 gfx::Transform identity_transform
;
7009 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7010 gfx::PointF(), gfx::Size(50, 50), true, false);
7011 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7012 gfx::PointF(), gfx::Size(50, 50), true, false);
7013 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7014 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7016 host()->SetRootLayer(root
);
7018 scoped_ptr
<KeyframedFilterAnimationCurve
> curve(
7019 KeyframedFilterAnimationCurve::Create());
7020 FilterOperations start_filters
;
7021 start_filters
.Append(FilterOperation::CreateBrightnessFilter(0.1f
));
7022 FilterOperations end_filters
;
7023 end_filters
.Append(FilterOperation::CreateBrightnessFilter(0.3f
));
7025 FilterKeyframe::Create(base::TimeDelta(), start_filters
, nullptr));
7026 curve
->AddKeyframe(FilterKeyframe::Create(
7027 base::TimeDelta::FromMilliseconds(100), end_filters
, nullptr));
7028 scoped_ptr
<Animation
> animation
=
7029 Animation::Create(curve
.Pass(), 0, 1, Animation::FILTER
);
7030 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
7031 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7032 child
->layer_animation_controller()->AddAnimation(animation
.Pass());
7034 ExecuteCalculateDrawProperties(root
.get());
7036 EXPECT_TRUE(root
->render_surface());
7037 EXPECT_TRUE(child
->render_surface());
7038 EXPECT_FALSE(grandchild
->render_surface());
7040 EXPECT_TRUE(root
->filters().IsEmpty());
7041 EXPECT_TRUE(child
->filters().IsEmpty());
7042 EXPECT_TRUE(grandchild
->filters().IsEmpty());
7044 EXPECT_FALSE(root
->FilterIsAnimating());
7045 EXPECT_FALSE(root
->HasPotentiallyRunningFilterAnimation());
7046 EXPECT_FALSE(child
->FilterIsAnimating());
7047 EXPECT_TRUE(child
->HasPotentiallyRunningFilterAnimation());
7048 EXPECT_FALSE(grandchild
->FilterIsAnimating());
7049 EXPECT_FALSE(grandchild
->HasPotentiallyRunningFilterAnimation());
7052 // Ensures that the property tree code accounts for offsets between fixed
7053 // position layers and their respective containers.
7054 TEST_F(LayerTreeHostCommonTest
, PropertyTreesAccountForFixedParentOffset
) {
7055 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7056 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7057 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
7058 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7060 root
->AddChild(child
);
7061 child
->AddChild(grandchild
);
7063 gfx::Transform identity_transform
;
7064 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7065 gfx::PointF(), gfx::Size(50, 50), true, false);
7066 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7067 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7069 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7070 gfx::Point3F(), gfx::PointF(-1000, -1000),
7071 gfx::Size(50, 50), true, false);
7073 root
->SetMasksToBounds(true);
7074 root
->SetIsContainerForFixedPositionLayers(true);
7075 LayerPositionConstraint constraint
;
7076 constraint
.set_is_fixed_position(true);
7077 grandchild
->SetPositionConstraint(constraint
);
7079 root
->SetIsContainerForFixedPositionLayers(true);
7081 host()->SetRootLayer(root
);
7083 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7085 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7086 grandchild
->visible_rect_from_property_trees());
7089 // Ensures that the property tree code accounts for offsets between fixed
7090 // position containers and their transform tree parents, when a fixed position
7091 // layer's container is its layer tree parent, but this parent doesn't have its
7092 // own transform tree node.
7093 TEST_F(LayerTreeHostCommonTest
,
7094 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent
) {
7095 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7096 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7097 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
7098 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7100 root
->AddChild(child
);
7101 child
->AddChild(grandchild
);
7103 gfx::Transform identity_transform
;
7104 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7105 gfx::PointF(), gfx::Size(50, 50), true, false);
7106 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7107 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7109 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7110 gfx::Point3F(), gfx::PointF(-1000, -1000),
7111 gfx::Size(50, 50), true, false);
7113 root
->SetMasksToBounds(true);
7114 child
->SetIsContainerForFixedPositionLayers(true);
7115 LayerPositionConstraint constraint
;
7116 constraint
.set_is_fixed_position(true);
7117 grandchild
->SetPositionConstraint(constraint
);
7119 root
->SetIsContainerForFixedPositionLayers(true);
7121 host()->SetRootLayer(root
);
7123 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7125 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7126 grandchild
->visible_rect_from_property_trees());
7129 TEST_F(LayerTreeHostCommonTest
, CombineClipsUsingContentTarget
) {
7130 // In the following layer tree, the layer |box|'s render target is |surface|.
7131 // |surface| also creates a transform node. We want to combine clips for |box|
7132 // in the space of its target (i.e., |surface|), not its target's target. This
7133 // test ensures that happens.
7135 gfx::Transform rotate
;
7137 gfx::Transform identity
;
7139 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7140 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7141 gfx::PointF(), gfx::Size(2500, 1500), true,
7144 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7145 SetLayerPropertiesForTesting(frame_clip
.get(), identity
, gfx::Point3F(),
7146 gfx::PointF(), gfx::Size(2500, 1500), true,
7148 frame_clip
->SetMasksToBounds(true);
7150 scoped_refptr
<Layer
> rotated
= Layer::Create(layer_settings());
7151 SetLayerPropertiesForTesting(rotated
.get(), rotate
,
7152 gfx::Point3F(1250, 250, 0), gfx::PointF(),
7153 gfx::Size(2500, 500), true, false);
7155 scoped_refptr
<Layer
> surface
= Layer::Create(layer_settings());
7156 SetLayerPropertiesForTesting(surface
.get(), rotate
, gfx::Point3F(),
7157 gfx::PointF(), gfx::Size(2500, 500), true,
7159 surface
->SetOpacity(0.5);
7161 scoped_refptr
<LayerWithForcedDrawsContent
> container
=
7162 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7163 SetLayerPropertiesForTesting(container
.get(), identity
, gfx::Point3F(),
7164 gfx::PointF(), gfx::Size(300, 300), true, false);
7166 scoped_refptr
<LayerWithForcedDrawsContent
> box
=
7167 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7168 SetLayerPropertiesForTesting(box
.get(), identity
, gfx::Point3F(),
7169 gfx::PointF(), gfx::Size(100, 100), true, false);
7171 root
->AddChild(frame_clip
);
7172 frame_clip
->AddChild(rotated
);
7173 rotated
->AddChild(surface
);
7174 surface
->AddChild(container
);
7175 surface
->AddChild(box
);
7177 host()->SetRootLayer(root
);
7179 ExecuteCalculateDrawProperties(root
.get());
7182 TEST_F(LayerTreeHostCommonTest
, OnlyApplyFixedPositioningOnce
) {
7183 gfx::Transform identity
;
7184 gfx::Transform translate_z
;
7185 translate_z
.Translate3d(0, 0, 10);
7187 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7188 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7189 gfx::PointF(), gfx::Size(800, 800), true, false);
7190 root
->SetIsContainerForFixedPositionLayers(true);
7192 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7193 SetLayerPropertiesForTesting(frame_clip
.get(), translate_z
, gfx::Point3F(),
7194 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7196 frame_clip
->SetMasksToBounds(true);
7198 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
7199 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7200 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
7201 gfx::PointF(), gfx::Size(1000, 1000), true,
7204 LayerPositionConstraint constraint
;
7205 constraint
.set_is_fixed_position(true);
7206 fixed
->SetPositionConstraint(constraint
);
7208 root
->AddChild(frame_clip
);
7209 frame_clip
->AddChild(fixed
);
7211 host()->SetRootLayer(root
);
7213 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7215 gfx::Rect
expected(0, 0, 100, 100);
7216 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
7219 TEST_F(LayerTreeHostCommonTest
,
7220 PropertyTreesAccountForScrollCompensationAdjustment
) {
7221 gfx::Transform identity
;
7222 gfx::Transform translate_z
;
7223 translate_z
.Translate3d(0, 0, 10);
7225 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7226 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7227 gfx::PointF(), gfx::Size(800, 800), true, false);
7228 root
->SetIsContainerForFixedPositionLayers(true);
7230 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7231 SetLayerPropertiesForTesting(frame_clip
.get(), translate_z
, gfx::Point3F(),
7232 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7234 frame_clip
->SetMasksToBounds(true);
7236 scoped_refptr
<LayerWithForcedDrawsContent
> scroller
=
7237 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7238 SetLayerPropertiesForTesting(scroller
.get(), identity
, gfx::Point3F(),
7239 gfx::PointF(), gfx::Size(1000, 1000), true,
7242 scroller
->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f
, 0.7f
));
7243 scroller
->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7));
7244 scroller
->SetScrollClipLayerId(frame_clip
->id());
7246 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
7247 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7248 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
7249 gfx::PointF(), gfx::Size(50, 50), true, false);
7251 LayerPositionConstraint constraint
;
7252 constraint
.set_is_fixed_position(true);
7253 fixed
->SetPositionConstraint(constraint
);
7255 scoped_refptr
<LayerWithForcedDrawsContent
> fixed_child
=
7256 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7257 SetLayerPropertiesForTesting(fixed_child
.get(), identity
, gfx::Point3F(),
7258 gfx::PointF(), gfx::Size(10, 10), true, false);
7260 fixed_child
->SetPositionConstraint(constraint
);
7262 root
->AddChild(frame_clip
);
7263 frame_clip
->AddChild(scroller
);
7264 scroller
->AddChild(fixed
);
7265 fixed
->AddChild(fixed_child
);
7267 host()->SetRootLayer(root
);
7269 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7271 gfx::Rect
expected(0, 0, 50, 50);
7272 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
7274 expected
= gfx::Rect(0, 0, 10, 10);
7275 EXPECT_EQ(expected
, fixed_child
->visible_rect_from_property_trees());
7278 TEST_F(LayerTreeHostCommonTest
, FixedClipsShouldBeAssociatedWithTheRightNode
) {
7279 gfx::Transform identity
;
7281 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7282 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7283 gfx::PointF(), gfx::Size(800, 800), true, false);
7284 root
->SetIsContainerForFixedPositionLayers(true);
7286 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7287 SetLayerPropertiesForTesting(frame_clip
.get(), identity
, gfx::Point3F(),
7288 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7290 frame_clip
->SetMasksToBounds(true);
7292 scoped_refptr
<LayerWithForcedDrawsContent
> scroller
=
7293 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7294 SetLayerPropertiesForTesting(scroller
.get(), identity
, gfx::Point3F(),
7295 gfx::PointF(), gfx::Size(1000, 1000), true,
7298 scroller
->SetScrollOffset(gfx::ScrollOffset(100, 100));
7299 scroller
->SetScrollClipLayerId(frame_clip
->id());
7301 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
7302 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7303 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
7304 gfx::PointF(100, 100), gfx::Size(50, 50), true,
7307 LayerPositionConstraint constraint
;
7308 constraint
.set_is_fixed_position(true);
7309 fixed
->SetPositionConstraint(constraint
);
7310 fixed
->SetForceRenderSurface(true);
7311 fixed
->SetMasksToBounds(true);
7313 root
->AddChild(frame_clip
);
7314 frame_clip
->AddChild(scroller
);
7315 scroller
->AddChild(fixed
);
7317 host()->SetRootLayer(root
);
7319 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7321 gfx::Rect
expected(0, 0, 50, 50);
7322 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
7325 TEST_F(LayerTreeHostCommonTest
, ChangingAxisAlignmentTriggersRebuild
) {
7326 gfx::Transform identity
;
7327 gfx::Transform translate
;
7328 gfx::Transform rotate
;
7330 translate
.Translate(10, 10);
7333 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7334 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7335 gfx::PointF(), gfx::Size(800, 800), true, false);
7336 root
->SetIsContainerForFixedPositionLayers(true);
7338 host()->SetRootLayer(root
);
7340 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7341 EXPECT_FALSE(host()->property_trees()->needs_rebuild
);
7343 root
->SetTransform(translate
);
7344 EXPECT_FALSE(host()->property_trees()->needs_rebuild
);
7346 root
->SetTransform(rotate
);
7347 EXPECT_TRUE(host()->property_trees()->needs_rebuild
);
7350 TEST_F(LayerTreeHostCommonTest
, ChangeTransformOrigin
) {
7351 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7352 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7353 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7354 root
->AddChild(child
);
7356 host()->SetRootLayer(root
);
7358 gfx::Transform identity_matrix
;
7359 gfx::Transform scale_matrix
;
7360 scale_matrix
.Scale(2.f
, 2.f
);
7361 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
7362 gfx::PointF(), gfx::Size(100, 100), true, false);
7363 SetLayerPropertiesForTesting(child
.get(), scale_matrix
, gfx::Point3F(),
7364 gfx::PointF(), gfx::Size(10, 10), true, false);
7366 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7367 EXPECT_EQ(gfx::Rect(10, 10), child
->visible_rect_from_property_trees());
7369 child
->SetTransformOrigin(gfx::Point3F(10.f
, 10.f
, 10.f
));
7371 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7372 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child
->visible_rect_from_property_trees());
7375 TEST_F(LayerTreeHostCommonTest
, UpdateScrollChildPosition
) {
7376 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7377 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7378 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7379 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7380 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7382 root
->AddChild(scroll_child
);
7383 root
->AddChild(scroll_parent
);
7384 scroll_child
->SetScrollParent(scroll_parent
.get());
7385 scroll_parent
->SetScrollClipLayerId(root
->id());
7387 host()->SetRootLayer(root
);
7389 gfx::Transform identity_transform
;
7390 gfx::Transform scale
;
7391 scale
.Scale(2.f
, 2.f
);
7392 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7393 gfx::PointF(), gfx::Size(50, 50), true, false);
7394 SetLayerPropertiesForTesting(scroll_child
.get(), scale
, gfx::Point3F(),
7395 gfx::PointF(), gfx::Size(40, 40), true, false);
7396 SetLayerPropertiesForTesting(scroll_parent
.get(), identity_transform
,
7397 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7400 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7401 EXPECT_EQ(gfx::Rect(25, 25),
7402 scroll_child
->visible_rect_from_property_trees());
7404 scroll_child
->SetPosition(gfx::PointF(0, -10.f
));
7405 scroll_parent
->SetScrollOffset(gfx::ScrollOffset(0.f
, 10.f
));
7406 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7407 EXPECT_EQ(gfx::Rect(0, 5, 25, 25),
7408 scroll_child
->visible_rect_from_property_trees());
7411 static void CopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {
7414 TEST_F(LayerTreeHostCommonTest
, SkippingSubtreeMain
) {
7415 gfx::Transform identity
;
7416 FakeContentLayerClient client
;
7417 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7418 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7419 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7420 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
7421 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7422 scoped_refptr
<FakePictureLayer
> greatgrandchild(
7423 FakePictureLayer::Create(layer_settings(), &client
));
7424 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7425 gfx::PointF(), gfx::Size(100, 100), true, false);
7426 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7427 gfx::PointF(), gfx::Size(10, 10), true, false);
7428 SetLayerPropertiesForTesting(grandchild
.get(), identity
, gfx::Point3F(),
7429 gfx::PointF(), gfx::Size(10, 10), true, false);
7430 SetLayerPropertiesForTesting(greatgrandchild
.get(), identity
, gfx::Point3F(),
7431 gfx::PointF(), gfx::Size(10, 10), true, false);
7433 root
->AddChild(child
);
7434 child
->AddChild(grandchild
);
7435 grandchild
->AddChild(greatgrandchild
);
7437 host()->SetRootLayer(root
);
7439 // Check the non-skipped case.
7440 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7441 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7443 // Now we will reset the visible rect from property trees for the grandchild,
7444 // and we will configure |child| in several ways that should force the subtree
7445 // to be skipped. The visible content rect for |grandchild| should, therefore,
7447 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7448 gfx::Transform singular
;
7449 singular
.matrix().set(0, 0, 0);
7451 child
->SetTransform(singular
);
7452 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7453 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
7454 child
->SetTransform(identity
);
7456 child
->SetHideLayerAndSubtree(true);
7457 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7458 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
7459 child
->SetHideLayerAndSubtree(false);
7461 gfx::Transform zero_z_scale
;
7462 zero_z_scale
.Scale3d(1, 1, 0);
7463 child
->SetTransform(zero_z_scale
);
7465 // Add a transform animation with a start delay. Now, even though |child| has
7466 // a singular transform, the subtree should still get processed.
7467 int animation_id
= 0;
7468 scoped_ptr
<Animation
> animation
= Animation::Create(
7469 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1.0)).Pass(),
7470 animation_id
, 1, Animation::TRANSFORM
);
7471 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
7472 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7473 child
->AddAnimation(animation
.Pass());
7474 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7475 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7476 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7478 child
->RemoveAnimation(animation_id
);
7479 child
->SetTransform(identity
);
7480 child
->SetOpacity(0.f
);
7481 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7482 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
7484 // Now, even though child has zero opacity, we will configure |grandchild| and
7485 // |greatgrandchild| in several ways that should force the subtree to be
7486 // processed anyhow.
7487 grandchild
->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10)));
7488 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7489 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7490 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7491 grandchild
->SetTouchEventHandlerRegion(Region());
7492 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7493 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
7494 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7496 greatgrandchild
->RequestCopyOfOutput(
7497 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback
)));
7498 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7499 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7500 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7502 // Add an opacity animation with a start delay.
7504 animation
= Animation::Create(
7505 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
7506 animation_id
, 1, Animation::OPACITY
);
7507 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
7508 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7509 child
->AddAnimation(animation
.Pass());
7510 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7511 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7514 TEST_F(LayerTreeHostCommonTest
, SkippingSubtreeImpl
) {
7515 FakeImplProxy proxy
;
7516 TestSharedBitmapManager shared_bitmap_manager
;
7517 TestTaskGraphRunner task_graph_runner
;
7518 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
7519 &task_graph_runner
);
7521 gfx::Transform identity
;
7522 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7523 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 2);
7524 scoped_ptr
<LayerImpl
> grandchild
=
7525 LayerImpl::Create(host_impl
.active_tree(), 3);
7527 scoped_ptr
<FakePictureLayerImpl
> greatgrandchild(
7528 FakePictureLayerImpl::Create(host_impl
.active_tree(), 4));
7530 child
->SetDrawsContent(true);
7531 grandchild
->SetDrawsContent(true);
7532 greatgrandchild
->SetDrawsContent(true);
7534 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7535 gfx::PointF(), gfx::Size(100, 100), true, false,
7537 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7538 gfx::PointF(), gfx::Size(10, 10), true, false,
7540 SetLayerPropertiesForTesting(grandchild
.get(), identity
, gfx::Point3F(),
7541 gfx::PointF(), gfx::Size(10, 10), true, false,
7543 SetLayerPropertiesForTesting(greatgrandchild
.get(), identity
, gfx::Point3F(),
7544 gfx::PointF(), gfx::Size(10, 10), true, false,
7547 LayerImpl
* child_ptr
= child
.get();
7548 LayerImpl
* grandchild_ptr
= grandchild
.get();
7549 LayerImpl
* greatgrandchild_ptr
= greatgrandchild
.get();
7551 grandchild
->AddChild(greatgrandchild
.Pass());
7552 child
->AddChild(grandchild
.Pass());
7553 root
->AddChild(child
.Pass());
7555 // Check the non-skipped case.
7556 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7557 EXPECT_EQ(gfx::Rect(10, 10),
7558 grandchild_ptr
->visible_rect_from_property_trees());
7560 // Now we will reset the visible rect from property trees for the grandchild,
7561 // and we will configure |child| in several ways that should force the subtree
7562 // to be skipped. The visible content rect for |grandchild| should, therefore,
7564 grandchild_ptr
->set_visible_rect_from_property_trees(gfx::Rect());
7565 gfx::Transform singular
;
7566 singular
.matrix().set(0, 0, 0);
7568 child_ptr
->SetTransform(singular
);
7569 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7570 EXPECT_EQ(gfx::Rect(0, 0),
7571 grandchild_ptr
->visible_rect_from_property_trees());
7572 child_ptr
->SetTransform(identity
);
7574 child_ptr
->SetHideLayerAndSubtree(true);
7575 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7576 EXPECT_EQ(gfx::Rect(0, 0),
7577 grandchild_ptr
->visible_rect_from_property_trees());
7578 child_ptr
->SetHideLayerAndSubtree(false);
7580 child_ptr
->SetOpacity(0.f
);
7581 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7582 EXPECT_EQ(gfx::Rect(0, 0),
7583 grandchild_ptr
->visible_rect_from_property_trees());
7585 // Now, even though child has zero opacity, we will configure |grandchild| and
7586 // |greatgrandchild| in several ways that should force the subtree to be
7587 // processed anyhow.
7588 grandchild_ptr
->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10)));
7589 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7590 EXPECT_EQ(gfx::Rect(10, 10),
7591 grandchild_ptr
->visible_rect_from_property_trees());
7592 grandchild_ptr
->set_visible_rect_from_property_trees(gfx::Rect());
7593 grandchild_ptr
->SetTouchEventHandlerRegion(Region());
7594 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7595 EXPECT_EQ(gfx::Rect(0, 0),
7596 grandchild_ptr
->visible_rect_from_property_trees());
7597 grandchild_ptr
->set_visible_rect_from_property_trees(gfx::Rect());
7599 ScopedPtrVector
<CopyOutputRequest
> requests
;
7600 requests
.push_back(CopyOutputRequest::CreateEmptyRequest());
7602 greatgrandchild_ptr
->PassCopyRequests(&requests
);
7603 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7604 EXPECT_EQ(gfx::Rect(10, 10),
7605 grandchild_ptr
->visible_rect_from_property_trees());
7608 TEST_F(LayerTreeHostCommonTest
, SkippingLayer
) {
7609 gfx::Transform identity
;
7610 FakeContentLayerClient client
;
7611 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7612 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7613 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7614 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7615 gfx::PointF(), gfx::Size(100, 100), true, false);
7616 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7617 gfx::PointF(), gfx::Size(10, 10), true, false);
7618 root
->AddChild(child
);
7620 host()->SetRootLayer(root
);
7622 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7623 EXPECT_EQ(gfx::Rect(10, 10), child
->visible_rect_from_property_trees());
7624 child
->set_visible_rect_from_property_trees(gfx::Rect());
7626 child
->SetHideLayerAndSubtree(true);
7627 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7628 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7629 child
->SetHideLayerAndSubtree(false);
7631 child
->SetBounds(gfx::Size());
7632 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7633 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7634 child
->SetBounds(gfx::Size(10, 10));
7636 gfx::Transform rotate
;
7637 child
->SetDoubleSided(false);
7638 rotate
.RotateAboutXAxis(180.f
);
7639 child
->SetTransform(rotate
);
7640 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7641 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7642 child
->SetDoubleSided(true);
7643 child
->SetTransform(identity
);
7645 child
->SetOpacity(0.f
);
7646 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7647 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7650 TEST_F(LayerTreeHostCommonTest
, LayerTreeRebuildTest
) {
7651 // Ensure that the treewalk in LayerTreeHostCommom::
7652 // PreCalculateMetaInformation happens when its required.
7653 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7654 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
7655 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7657 root
->AddChild(parent
);
7658 parent
->AddChild(child
);
7660 child
->SetClipParent(root
.get());
7662 gfx::Transform identity
;
7664 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7665 gfx::PointF(), gfx::Size(100, 100), true, false);
7666 SetLayerPropertiesForTesting(parent
.get(), identity
, gfx::Point3F(),
7667 gfx::PointF(), gfx::Size(100, 100), true, false);
7668 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7669 gfx::PointF(), gfx::Size(100, 100), true, false);
7671 host()->SetRootLayer(root
);
7673 ExecuteCalculateDrawProperties(root
.get());
7674 EXPECT_EQ(parent
->draw_properties().num_unclipped_descendants
, 1u);
7676 // Ensure the dynamic update to input handlers happens.
7677 child
->SetHaveWheelEventHandlers(true);
7678 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_input_handler
);
7679 ExecuteCalculateDrawProperties(root
.get());
7680 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_input_handler
);
7682 child
->SetHaveWheelEventHandlers(false);
7683 EXPECT_FALSE(root
->draw_properties().layer_or_descendant_has_input_handler
);
7684 ExecuteCalculateDrawProperties(root
.get());
7685 EXPECT_FALSE(root
->draw_properties().layer_or_descendant_has_input_handler
);
7687 child
->RequestCopyOfOutput(
7688 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback
)));
7689 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
7690 ExecuteCalculateDrawProperties(root
.get());
7691 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
7694 TEST_F(LayerTreeHostCommonTest
, InputHandlersRecursiveUpdateTest
) {
7695 // Ensure that the treewalk in LayertreeHostCommon::
7696 // PreCalculateMetaInformation updates input handlers correctly.
7697 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7698 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7700 root
->AddChild(child
);
7702 child
->SetHaveWheelEventHandlers(true);
7704 gfx::Transform identity
;
7706 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7707 gfx::PointF(), gfx::Size(100, 100), true, false);
7708 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7709 gfx::PointF(), gfx::Size(100, 100), true, false);
7711 host()->SetRootLayer(root
);
7713 EXPECT_EQ(root
->num_layer_or_descendants_with_input_handler(), 0);
7714 ExecuteCalculateDrawProperties(root
.get());
7715 EXPECT_EQ(root
->num_layer_or_descendants_with_input_handler(), 1);
7716 child
->SetHaveWheelEventHandlers(false);
7717 EXPECT_EQ(root
->num_layer_or_descendants_with_input_handler(), 0);
7720 TEST_F(LayerTreeHostCommonTest
, ResetPropertyTreeIndices
) {
7721 gfx::Transform identity
;
7722 gfx::Transform translate_z
;
7723 translate_z
.Translate3d(0, 0, 10);
7725 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7726 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7727 gfx::PointF(), gfx::Size(800, 800), true, false);
7729 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7730 SetLayerPropertiesForTesting(child
.get(), translate_z
, gfx::Point3F(),
7731 gfx::PointF(), gfx::Size(100, 100), true, false);
7733 root
->AddChild(child
);
7735 host()->SetRootLayer(root
);
7737 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7738 EXPECT_NE(-1, child
->transform_tree_index());
7740 child
->RemoveFromParent();
7742 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7743 EXPECT_EQ(-1, child
->transform_tree_index());
7746 TEST_F(LayerTreeHostCommonTest
, ResetLayerDrawPropertiestest
) {
7747 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7748 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7750 root
->AddChild(child
);
7751 gfx::Transform identity
;
7753 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7754 gfx::PointF(), gfx::Size(100, 100), true, false);
7755 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7756 gfx::PointF(), gfx::Size(100, 100), true, false);
7758 host()->SetRootLayer(root
);
7760 EXPECT_FALSE(root
->layer_or_descendant_is_drawn());
7761 EXPECT_FALSE(root
->visited());
7762 EXPECT_FALSE(root
->sorted_for_recursion());
7763 EXPECT_FALSE(child
->layer_or_descendant_is_drawn());
7764 EXPECT_FALSE(child
->visited());
7765 EXPECT_FALSE(child
->sorted_for_recursion());
7767 root
->set_layer_or_descendant_is_drawn(true);
7768 root
->set_visited(true);
7769 root
->set_sorted_for_recursion(true);
7770 child
->set_layer_or_descendant_is_drawn(true);
7771 child
->set_visited(true);
7772 child
->set_sorted_for_recursion(true);
7774 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root
.get());
7776 EXPECT_FALSE(root
->layer_or_descendant_is_drawn());
7777 EXPECT_FALSE(root
->visited());
7778 EXPECT_FALSE(root
->sorted_for_recursion());
7779 EXPECT_FALSE(child
->layer_or_descendant_is_drawn());
7780 EXPECT_FALSE(child
->visited());
7781 EXPECT_FALSE(child
->sorted_for_recursion());
7784 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceClipsSubtree
) {
7785 // Ensure that a Clip Node is added when a render surface applies clip.
7786 LayerImpl
* root
= root_layer();
7787 LayerImpl
* significant_transform
= AddChildToRoot
<LayerImpl
>();
7788 LayerImpl
* layer_clips_subtree
= AddChild
<LayerImpl
>(significant_transform
);
7789 LayerImpl
* render_surface
= AddChild
<LayerImpl
>(layer_clips_subtree
);
7790 LayerImpl
* test_layer
= AddChild
<LayerImpl
>(render_surface
);
7792 const gfx::Transform identity_matrix
;
7793 // This transform should be a significant one so that a transform node is
7795 gfx::Transform transform1
;
7796 transform1
.RotateAboutYAxis(45);
7797 transform1
.RotateAboutXAxis(30);
7798 // This transform should be a 3d transform as we want the render surface
7799 // to flatten the transform
7800 gfx::Transform transform2
;
7801 transform2
.Translate3d(10, 10, 10);
7803 layer_clips_subtree
->SetMasksToBounds(true);
7804 test_layer
->SetDrawsContent(true);
7806 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
7807 gfx::PointF(), gfx::Size(30, 30), true, false,
7809 SetLayerPropertiesForTesting(significant_transform
, transform1
,
7810 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7811 true, false, false);
7812 SetLayerPropertiesForTesting(layer_clips_subtree
, identity_matrix
,
7813 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7814 true, false, false);
7815 SetLayerPropertiesForTesting(render_surface
, transform2
, gfx::Point3F(),
7816 gfx::PointF(), gfx::Size(30, 30), true, false,
7818 SetLayerPropertiesForTesting(test_layer
, identity_matrix
, gfx::Point3F(),
7819 gfx::PointF(), gfx::Size(30, 30), true, false,
7822 ExecuteCalculateDrawProperties(root
);
7824 TransformTree transform_tree
=
7825 root
->layer_tree_impl()->property_trees()->transform_tree
;
7826 TransformNode
* transform_node
=
7827 transform_tree
.Node(significant_transform
->transform_tree_index());
7828 EXPECT_EQ(transform_node
->owner_id
, significant_transform
->id());
7830 ClipTree clip_tree
= root
->layer_tree_impl()->property_trees()->clip_tree
;
7831 ClipNode
* clip_node
= clip_tree
.Node(render_surface
->clip_tree_index());
7832 EXPECT_TRUE(clip_node
->data
.inherit_parent_target_space_clip
);
7833 EXPECT_EQ(test_layer
->visible_rect_from_property_trees(), gfx::RectF(30, 21));
7836 TEST_F(LayerTreeHostCommonTest
, TransformOfParentClipNodeAncestorOfTarget
) {
7837 // Ensure that when parent clip node's transform is an ancestor of current
7838 // clip node's target, clip is 'projected' from parent space to current
7839 // target space and visible rects are calculated correctly.
7840 LayerImpl
* root
= root_layer();
7841 LayerImpl
* clip_layer
= AddChild
<LayerImpl
>(root
);
7842 LayerImpl
* target_layer
= AddChild
<LayerImpl
>(clip_layer
);
7843 LayerImpl
* test_layer
= AddChild
<LayerImpl
>(target_layer
);
7845 const gfx::Transform identity_matrix
;
7846 gfx::Transform transform
;
7847 transform
.RotateAboutYAxis(45);
7848 clip_layer
->SetMasksToBounds(true);
7849 target_layer
->SetMasksToBounds(true);
7850 test_layer
->SetDrawsContent(true);
7852 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
7853 gfx::PointF(), gfx::Size(30, 30), true, false,
7855 SetLayerPropertiesForTesting(clip_layer
, transform
, gfx::Point3F(),
7856 gfx::PointF(), gfx::Size(30, 30), true, false,
7858 SetLayerPropertiesForTesting(target_layer
, transform
, gfx::Point3F(),
7859 gfx::PointF(), gfx::Size(30, 30), true, false,
7861 SetLayerPropertiesForTesting(test_layer
, identity_matrix
, gfx::Point3F(),
7862 gfx::PointF(), gfx::Size(30, 30), true, false,
7864 ExecuteCalculateDrawProperties(root
);
7866 ClipTree clip_tree
= root
->layer_tree_impl()->property_trees()->clip_tree
;
7867 ClipNode
* clip_node
= clip_tree
.Node(target_layer
->clip_tree_index());
7868 EXPECT_EQ(clip_node
->data
.combined_clip
, gfx::RectF(30, 30));
7869 EXPECT_EQ(test_layer
->visible_rect_from_property_trees(), gfx::RectF(30, 30));