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/draw_property_utils.h"
35 #include "cc/trees/layer_tree_impl.h"
36 #include "cc/trees/proxy.h"
37 #include "cc/trees/single_thread_proxy.h"
38 #include "testing/gmock/include/gmock/gmock.h"
39 #include "testing/gtest/include/gtest/gtest.h"
40 #include "ui/gfx/geometry/quad_f.h"
41 #include "ui/gfx/geometry/vector2d_conversions.h"
42 #include "ui/gfx/transform.h"
47 class LayerWithForcedDrawsContent
: public Layer
{
49 explicit LayerWithForcedDrawsContent(const LayerSettings
& settings
)
52 bool DrawsContent() const override
;
55 ~LayerWithForcedDrawsContent() override
{}
58 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
60 class MockContentLayerClient
: public ContentLayerClient
{
62 MockContentLayerClient() {}
63 ~MockContentLayerClient() override
{}
64 void PaintContents(SkCanvas
* canvas
,
65 const gfx::Rect
& clip
,
66 PaintingControlSetting picture_control
) override
{}
67 scoped_refptr
<DisplayItemList
> PaintContentsToDisplayList(
68 const gfx::Rect
& clip
,
69 PaintingControlSetting picture_control
) override
{
73 bool FillsBoundsCompletely() const override
{ return false; }
74 size_t GetApproximateUnsharedMemoryUsage() const override
{ return 0; }
77 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
79 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
80 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
83 #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
85 EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \
88 class LayerTreeSettingsScaleContent
: public LayerTreeSettings
{
90 LayerTreeSettingsScaleContent() {
91 layer_transforms_should_scale_layer_contents
= true;
95 class LayerTreeHostCommonScalingTest
: public LayerTreeHostCommonTest
{
97 LayerTreeHostCommonScalingTest()
98 : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {}
101 TEST_F(LayerTreeHostCommonTest
, TransformsForNoOpLayer
) {
102 // Sanity check: For layers positioned at zero, with zero size,
103 // and with identity transforms, then the draw transform,
104 // screen space transform, and the hierarchy passed on to children
105 // layers should also be identity transforms.
107 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
108 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
109 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
110 parent
->AddChild(child
);
111 child
->AddChild(grand_child
);
113 host()->SetRootLayer(parent
);
115 gfx::Transform identity_matrix
;
116 SetLayerPropertiesForTesting(parent
.get(),
123 SetLayerPropertiesForTesting(child
.get(),
130 SetLayerPropertiesForTesting(grand_child
.get(),
138 ExecuteCalculateDrawProperties(parent
.get());
140 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
141 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
142 child
->screen_space_transform());
143 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
144 grand_child
->draw_transform());
145 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
146 grand_child
->screen_space_transform());
149 TEST_F(LayerTreeHostCommonTest
, DoNotSkipLayersWithHandlers
) {
150 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
151 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
152 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
153 parent
->AddChild(child
);
154 child
->AddChild(grand_child
);
156 host()->SetRootLayer(parent
);
158 gfx::Transform identity_matrix
;
159 SetLayerPropertiesForTesting(parent
.get(),
166 SetLayerPropertiesForTesting(child
.get(),
173 // This would have previously caused us to skip our subtree, but this would be
174 // wrong; we need up-to-date draw properties to do hit testing on the layers
176 child
->SetOpacity(0.f
);
177 SetLayerPropertiesForTesting(grand_child
.get(),
184 grand_child
->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
186 ExecuteCalculateDrawProperties(parent
.get());
188 // Check that we've computed draw properties for the subtree rooted at
190 EXPECT_FALSE(child
->draw_transform().IsIdentity());
191 EXPECT_FALSE(grand_child
->draw_transform().IsIdentity());
194 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleLayer
) {
195 gfx::Transform identity_matrix
;
196 scoped_refptr
<Layer
> layer
= Layer::Create(layer_settings());
198 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
199 SetLayerPropertiesForTesting(root
.get(),
206 root
->AddChild(layer
);
208 host()->SetRootLayer(root
);
210 // Case 2: Setting the bounds of the layer should not affect either the draw
211 // transform or the screenspace transform.
212 gfx::Transform translation_to_center
;
213 translation_to_center
.Translate(5.0, 6.0);
214 SetLayerPropertiesForTesting(layer
.get(),
221 ExecuteCalculateDrawProperties(root
.get());
222 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
223 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
224 layer
->screen_space_transform());
226 // Case 3: The anchor point by itself (without a layer transform) should have
227 // no effect on the transforms.
228 SetLayerPropertiesForTesting(layer
.get(),
230 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
235 ExecuteCalculateDrawProperties(root
.get());
236 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
237 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
238 layer
->screen_space_transform());
240 // Case 4: A change in actual position affects both the draw transform and
241 // screen space transform.
242 gfx::Transform position_transform
;
243 position_transform
.Translate(0.f
, 1.2f
);
244 SetLayerPropertiesForTesting(layer
.get(),
246 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
247 gfx::PointF(0.f
, 1.2f
),
251 ExecuteCalculateDrawProperties(root
.get());
252 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
, layer
->draw_transform());
253 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
,
254 layer
->screen_space_transform());
256 // Case 5: In the correct sequence of transforms, the layer transform should
257 // pre-multiply the translation_to_center. This is easily tested by using a
258 // scale transform, because scale and translation are not commutative.
259 gfx::Transform layer_transform
;
260 layer_transform
.Scale3d(2.0, 2.0, 1.0);
261 SetLayerPropertiesForTesting(layer
.get(),
268 ExecuteCalculateDrawProperties(root
.get());
269 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
, layer
->draw_transform());
270 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
,
271 layer
->screen_space_transform());
273 // Case 6: The layer transform should occur with respect to the anchor point.
274 gfx::Transform translation_to_anchor
;
275 translation_to_anchor
.Translate(5.0, 0.0);
276 gfx::Transform expected_result
=
277 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
278 SetLayerPropertiesForTesting(layer
.get(),
280 gfx::Point3F(5.0f
, 0.f
, 0.f
),
285 ExecuteCalculateDrawProperties(root
.get());
286 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
287 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
288 layer
->screen_space_transform());
290 // Case 7: Verify that position pre-multiplies the layer transform. The
291 // current implementation of CalculateDrawProperties does this implicitly, but
292 // it is still worth testing to detect accidental regressions.
293 expected_result
= position_transform
* translation_to_anchor
*
294 layer_transform
* Inverse(translation_to_anchor
);
295 SetLayerPropertiesForTesting(layer
.get(),
297 gfx::Point3F(5.0f
, 0.f
, 0.f
),
298 gfx::PointF(0.f
, 1.2f
),
302 ExecuteCalculateDrawProperties(root
.get());
303 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
304 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
305 layer
->screen_space_transform());
308 TEST_F(LayerTreeHostCommonTest
, TransformsAboutScrollOffset
) {
309 const gfx::ScrollOffset
kScrollOffset(50, 100);
310 const gfx::Vector2dF
kScrollDelta(2.34f
, 5.67f
);
311 const gfx::Vector2d
kMaxScrollOffset(200, 200);
312 const gfx::PointF
kScrollLayerPosition(-kScrollOffset
.x(),
314 const float kPageScale
= 0.888f
;
315 const float kDeviceScale
= 1.666f
;
318 TestSharedBitmapManager shared_bitmap_manager
;
319 TestTaskGraphRunner task_graph_runner
;
320 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
323 gfx::Transform identity_matrix
;
324 scoped_ptr
<LayerImpl
> sublayer_scoped_ptr(
325 LayerImpl::Create(host_impl
.active_tree(), 1));
326 LayerImpl
* sublayer
= sublayer_scoped_ptr
.get();
327 SetLayerPropertiesForTesting(sublayer
, identity_matrix
, gfx::Point3F(),
328 gfx::PointF(), gfx::Size(500, 500), true, false,
331 scoped_ptr
<LayerImpl
> scroll_layer_scoped_ptr(
332 LayerImpl::Create(host_impl
.active_tree(), 2));
333 LayerImpl
* scroll_layer
= scroll_layer_scoped_ptr
.get();
334 SetLayerPropertiesForTesting(scroll_layer
, identity_matrix
, gfx::Point3F(),
335 gfx::PointF(), gfx::Size(10, 20), true, false,
337 scoped_ptr
<LayerImpl
> clip_layer_scoped_ptr(
338 LayerImpl::Create(host_impl
.active_tree(), 4));
339 LayerImpl
* clip_layer
= clip_layer_scoped_ptr
.get();
341 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
342 clip_layer
->SetBounds(
343 gfx::Size(scroll_layer
->bounds().width() + kMaxScrollOffset
.x(),
344 scroll_layer
->bounds().height() + kMaxScrollOffset
.y()));
345 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
346 scroll_layer
->SetScrollDelta(kScrollDelta
);
347 gfx::Transform impl_transform
;
348 scroll_layer
->AddChild(sublayer_scoped_ptr
.Pass());
349 LayerImpl
* scroll_layer_raw_ptr
= scroll_layer_scoped_ptr
.get();
350 clip_layer
->AddChild(scroll_layer_scoped_ptr
.Pass());
351 scroll_layer_raw_ptr
->PushScrollOffsetFromMainThread(kScrollOffset
);
353 scoped_ptr
<LayerImpl
> root(LayerImpl::Create(host_impl
.active_tree(), 3));
354 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
355 gfx::PointF(), gfx::Size(3, 4), true, false,
357 root
->AddChild(clip_layer_scoped_ptr
.Pass());
358 root
->SetHasRenderSurface(true);
360 ExecuteCalculateDrawProperties(
361 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
362 gfx::Transform expected_transform
= identity_matrix
;
363 gfx::PointF sub_layer_screen_position
= kScrollLayerPosition
- kScrollDelta
;
364 expected_transform
.Translate(MathUtil::Round(sub_layer_screen_position
.x() *
365 kPageScale
* kDeviceScale
),
366 MathUtil::Round(sub_layer_screen_position
.y() *
367 kPageScale
* kDeviceScale
));
368 expected_transform
.Scale(kPageScale
* kDeviceScale
,
369 kPageScale
* kDeviceScale
);
370 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
371 sublayer
->draw_transform());
372 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
373 sublayer
->screen_space_transform());
375 gfx::Transform arbitrary_translate
;
376 const float kTranslateX
= 10.6f
;
377 const float kTranslateY
= 20.6f
;
378 arbitrary_translate
.Translate(kTranslateX
, kTranslateY
);
379 SetLayerPropertiesForTesting(scroll_layer
, arbitrary_translate
,
380 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
382 ExecuteCalculateDrawProperties(
383 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
384 expected_transform
.MakeIdentity();
385 expected_transform
.Translate(
386 MathUtil::Round(kTranslateX
* kPageScale
* kDeviceScale
+
387 sub_layer_screen_position
.x() * kPageScale
*
389 MathUtil::Round(kTranslateY
* kPageScale
* kDeviceScale
+
390 sub_layer_screen_position
.y() * kPageScale
*
392 expected_transform
.Scale(kPageScale
* kDeviceScale
,
393 kPageScale
* kDeviceScale
);
394 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
395 sublayer
->draw_transform());
398 TEST_F(LayerTreeHostCommonTest
, TransformsForSimpleHierarchy
) {
399 gfx::Transform identity_matrix
;
400 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
401 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
402 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
403 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
404 root
->AddChild(parent
);
405 parent
->AddChild(child
);
406 child
->AddChild(grand_child
);
408 host()->SetRootLayer(root
);
410 // One-time setup of root layer
411 SetLayerPropertiesForTesting(root
.get(),
419 // Case 1: parent's anchor point should not affect child or grand_child.
420 SetLayerPropertiesForTesting(parent
.get(),
422 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
427 SetLayerPropertiesForTesting(child
.get(),
434 SetLayerPropertiesForTesting(grand_child
.get(),
441 ExecuteCalculateDrawProperties(root
.get());
442 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
443 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
444 child
->screen_space_transform());
445 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
446 grand_child
->draw_transform());
447 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
448 grand_child
->screen_space_transform());
450 // Case 2: parent's position affects child and grand_child.
451 gfx::Transform parent_position_transform
;
452 parent_position_transform
.Translate(0.f
, 1.2f
);
453 SetLayerPropertiesForTesting(parent
.get(),
455 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
456 gfx::PointF(0.f
, 1.2f
),
460 SetLayerPropertiesForTesting(child
.get(),
467 SetLayerPropertiesForTesting(grand_child
.get(),
474 ExecuteCalculateDrawProperties(root
.get());
475 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
476 child
->draw_transform());
477 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
478 child
->screen_space_transform());
479 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
480 grand_child
->draw_transform());
481 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
482 grand_child
->screen_space_transform());
484 // Case 3: parent's local transform affects child and grandchild
485 gfx::Transform parent_layer_transform
;
486 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
487 gfx::Transform parent_translation_to_anchor
;
488 parent_translation_to_anchor
.Translate(2.5, 3.0);
489 gfx::Transform parent_composite_transform
=
490 parent_translation_to_anchor
* parent_layer_transform
*
491 Inverse(parent_translation_to_anchor
);
492 SetLayerPropertiesForTesting(parent
.get(),
493 parent_layer_transform
,
494 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
499 SetLayerPropertiesForTesting(child
.get(),
506 SetLayerPropertiesForTesting(grand_child
.get(),
513 ExecuteCalculateDrawProperties(root
.get());
514 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
515 child
->draw_transform());
516 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
517 child
->screen_space_transform());
518 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
519 grand_child
->draw_transform());
520 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
521 grand_child
->screen_space_transform());
524 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleRenderSurface
) {
525 LayerImpl
* root
= root_layer();
526 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
527 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
528 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
529 grand_child
->SetDrawsContent(true);
531 gfx::Transform identity_matrix
;
532 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
533 gfx::PointF(), gfx::Size(1, 2), true, false,
536 // Child is set up so that a new render surface should be created.
537 child
->SetOpacity(0.5f
);
539 gfx::Transform parent_layer_transform
;
540 parent_layer_transform
.Scale3d(1.f
, 0.9f
, 1.f
);
541 gfx::Transform parent_translation_to_anchor
;
542 parent_translation_to_anchor
.Translate(25.0, 30.0);
544 gfx::Transform parent_composite_transform
=
545 parent_translation_to_anchor
* parent_layer_transform
*
546 Inverse(parent_translation_to_anchor
);
547 gfx::Vector2dF parent_composite_scale
=
548 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
550 gfx::Transform surface_sublayer_transform
;
551 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
552 parent_composite_scale
.y());
553 gfx::Transform surface_sublayer_composite_transform
=
554 parent_composite_transform
* Inverse(surface_sublayer_transform
);
556 SetLayerPropertiesForTesting(parent
, parent_layer_transform
,
557 gfx::Point3F(25.0f
, 30.0f
, 0.f
), gfx::PointF(),
558 gfx::Size(100, 120), true, false, false);
559 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
560 gfx::PointF(), gfx::Size(16, 18), true, false,
562 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
563 gfx::PointF(), gfx::Size(8, 10), true, false,
565 ExecuteCalculateDrawProperties(root
);
567 // Render surface should have been created now.
568 ASSERT_TRUE(child
->render_surface());
569 ASSERT_EQ(child
, child
->render_target());
571 // The child layer's draw transform should refer to its new render surface.
572 // The screen-space transform, however, should still refer to the root.
573 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform
,
574 child
->draw_transform());
575 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
576 child
->screen_space_transform());
578 // Because the grand_child is the only drawable content, the child's render
579 // surface will tighten its bounds to the grand_child. The scale at which the
580 // surface's subtree is drawn must be removed from the composite transform.
581 EXPECT_TRANSFORMATION_MATRIX_EQ(
582 surface_sublayer_composite_transform
,
583 child
->render_target()->render_surface()->draw_transform());
585 // The screen space is the same as the target since the child surface draws
587 EXPECT_TRANSFORMATION_MATRIX_EQ(
588 surface_sublayer_composite_transform
,
589 child
->render_target()->render_surface()->screen_space_transform());
592 TEST_F(LayerTreeHostCommonTest
, TransformsForReplica
) {
593 LayerImpl
* root
= root_layer();
594 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
595 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
596 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
597 grand_child
->SetDrawsContent(true);
598 scoped_ptr
<LayerImpl
> child_replica
=
599 LayerImpl::Create(host_impl()->active_tree(), 100);
601 // One-time setup of root layer
602 gfx::Transform identity_matrix
;
603 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
604 gfx::PointF(), gfx::Size(1, 2), true, false,
607 // Child is set up so that a new render surface should be created.
608 child
->SetOpacity(0.5f
);
610 gfx::Transform parent_layer_transform
;
611 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
612 gfx::Transform parent_translation_to_anchor
;
613 parent_translation_to_anchor
.Translate(2.5, 3.0);
614 gfx::Transform parent_composite_transform
=
615 parent_translation_to_anchor
* parent_layer_transform
*
616 Inverse(parent_translation_to_anchor
);
617 gfx::Transform replica_layer_transform
;
618 replica_layer_transform
.Scale3d(3.0, 3.0, 1.0);
619 gfx::Vector2dF parent_composite_scale
=
620 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
622 gfx::Transform surface_sublayer_transform
;
623 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
624 parent_composite_scale
.y());
625 gfx::Transform replica_composite_transform
=
626 parent_composite_transform
* replica_layer_transform
*
627 Inverse(surface_sublayer_transform
);
628 child_replica
->SetDrawsContent(true);
629 // Child's render surface should not exist yet.
630 ASSERT_FALSE(child
->render_surface());
632 SetLayerPropertiesForTesting(parent
, parent_layer_transform
,
633 gfx::Point3F(2.5f
, 3.0f
, 0.f
), gfx::PointF(),
634 gfx::Size(10, 12), true, false, false);
635 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
636 gfx::PointF(), gfx::Size(16, 18), true, false,
638 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
639 gfx::PointF(-0.5f
, -0.5f
), gfx::Size(1, 1), true,
641 SetLayerPropertiesForTesting(child_replica
.get(), replica_layer_transform
,
642 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
644 child
->SetReplicaLayer(child_replica
.Pass());
646 ExecuteCalculateDrawProperties(root
);
648 // Render surface should have been created now.
649 ASSERT_TRUE(child
->render_surface());
650 ASSERT_EQ(child
, child
->render_target());
652 EXPECT_TRANSFORMATION_MATRIX_EQ(
653 replica_composite_transform
,
654 child
->render_target()->render_surface()->replica_draw_transform());
655 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform
,
656 child
->render_target()
658 ->replica_screen_space_transform());
661 TEST_F(LayerTreeHostCommonTest
, TransformsForRenderSurfaceHierarchy
) {
662 // This test creates a more complex tree and verifies it all at once. This
663 // covers the following cases:
664 // - layers that are described w.r.t. a render surface: should have draw
665 // transforms described w.r.t. that surface
666 // - A render surface described w.r.t. an ancestor render surface: should
667 // have a draw transform described w.r.t. that ancestor surface
668 // - Replicas of a render surface are described w.r.t. the replica's
669 // transform around its anchor, along with the surface itself.
670 // - Sanity check on recursion: verify transforms of layers described w.r.t.
671 // a render surface that is described w.r.t. an ancestor render surface.
672 // - verifying that each layer has a reference to the correct render surface
673 // and render target values.
675 LayerImpl
* root
= root_layer();
676 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
677 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(parent
);
678 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(render_surface1
);
679 LayerImpl
* child_of_root
= AddChild
<LayerImpl
>(parent
);
680 LayerImpl
* child_of_rs1
= AddChild
<LayerImpl
>(render_surface1
);
681 LayerImpl
* child_of_rs2
= AddChild
<LayerImpl
>(render_surface2
);
682 LayerImpl
* grand_child_of_root
= AddChild
<LayerImpl
>(child_of_root
);
683 LayerImpl
* grand_child_of_rs1
= AddChild
<LayerImpl
>(child_of_rs1
);
684 grand_child_of_rs1
->SetDrawsContent(true);
685 LayerImpl
* grand_child_of_rs2
= AddChild
<LayerImpl
>(child_of_rs2
);
686 grand_child_of_rs2
->SetDrawsContent(true);
688 scoped_ptr
<LayerImpl
> replica_of_rs1
=
689 LayerImpl::Create(host_impl()->active_tree(), 101);
690 scoped_ptr
<LayerImpl
> replica_of_rs2
=
691 LayerImpl::Create(host_impl()->active_tree(), 102);
693 // In combination with descendant draws content, opacity != 1 forces the layer
694 // to have a new render surface.
695 render_surface1
->SetOpacity(0.5f
);
696 render_surface2
->SetOpacity(0.33f
);
698 // One-time setup of root layer
699 gfx::Transform identity_matrix
;
700 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
701 gfx::PointF(), gfx::Size(1, 2), true, false,
704 // All layers in the tree are initialized with an anchor at .25 and a size of
705 // (10,10). matrix "A" is the composite layer transform used in all layers,
706 // Matrix "R" is the composite replica transform used in all replica layers.
707 gfx::Transform translation_to_anchor
;
708 translation_to_anchor
.Translate(2.5, 0.0);
709 gfx::Transform layer_transform
;
710 layer_transform
.Translate(1.0, 1.0);
711 gfx::Transform replica_layer_transform
;
712 replica_layer_transform
.Scale3d(-2.0, 5.0, 1.0);
715 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
716 gfx::Transform R
= A
* translation_to_anchor
* replica_layer_transform
*
717 Inverse(translation_to_anchor
);
719 gfx::Vector2dF surface1_parent_transform_scale
=
720 MathUtil::ComputeTransform2dScaleComponents(A
, 1.f
);
721 gfx::Transform surface1_sublayer_transform
;
722 surface1_sublayer_transform
.Scale(surface1_parent_transform_scale
.x(),
723 surface1_parent_transform_scale
.y());
725 // SS1 = transform given to the subtree of render_surface1
726 gfx::Transform SS1
= surface1_sublayer_transform
;
727 // S1 = transform to move from render_surface1 pixels to the layer space of
729 gfx::Transform S1
= Inverse(surface1_sublayer_transform
);
731 gfx::Vector2dF surface2_parent_transform_scale
=
732 MathUtil::ComputeTransform2dScaleComponents(SS1
* A
, 1.f
);
733 gfx::Transform surface2_sublayer_transform
;
734 surface2_sublayer_transform
.Scale(surface2_parent_transform_scale
.x(),
735 surface2_parent_transform_scale
.y());
737 // SS2 = transform given to the subtree of render_surface2
738 gfx::Transform SS2
= surface2_sublayer_transform
;
739 // S2 = transform to move from render_surface2 pixels to the layer space of
741 gfx::Transform S2
= Inverse(surface2_sublayer_transform
);
743 SetLayerPropertiesForTesting(parent
, layer_transform
,
744 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
745 gfx::Size(10, 10), true, false, false);
746 SetLayerPropertiesForTesting(render_surface1
, layer_transform
,
747 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
748 gfx::Size(10, 10), true, false, true);
749 SetLayerPropertiesForTesting(render_surface2
, layer_transform
,
750 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
751 gfx::Size(10, 10), true, false, true);
752 SetLayerPropertiesForTesting(child_of_root
, layer_transform
,
753 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
754 gfx::Size(10, 10), true, false, false);
755 SetLayerPropertiesForTesting(child_of_rs1
, layer_transform
,
756 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
757 gfx::Size(10, 10), true, false, false);
758 SetLayerPropertiesForTesting(child_of_rs2
, layer_transform
,
759 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
760 gfx::Size(10, 10), true, false, false);
761 SetLayerPropertiesForTesting(grand_child_of_root
, layer_transform
,
762 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
763 gfx::Size(10, 10), true, false, false);
764 SetLayerPropertiesForTesting(grand_child_of_rs1
, layer_transform
,
765 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
766 gfx::Size(10, 10), true, false, false);
767 SetLayerPropertiesForTesting(grand_child_of_rs2
, layer_transform
,
768 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
769 gfx::Size(10, 10), true, false, false);
770 SetLayerPropertiesForTesting(replica_of_rs1
.get(), replica_layer_transform
,
771 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
772 gfx::Size(), true, false, false);
773 SetLayerPropertiesForTesting(replica_of_rs2
.get(), replica_layer_transform
,
774 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
775 gfx::Size(), true, false, false);
777 render_surface1
->SetReplicaLayer(replica_of_rs1
.Pass());
778 render_surface2
->SetReplicaLayer(replica_of_rs2
.Pass());
779 ExecuteCalculateDrawProperties(root
);
781 // Only layers that are associated with render surfaces should have an actual
782 // RenderSurface() value.
783 ASSERT_TRUE(root
->render_surface());
784 ASSERT_FALSE(child_of_root
->render_surface());
785 ASSERT_FALSE(grand_child_of_root
->render_surface());
787 ASSERT_TRUE(render_surface1
->render_surface());
788 ASSERT_FALSE(child_of_rs1
->render_surface());
789 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
791 ASSERT_TRUE(render_surface2
->render_surface());
792 ASSERT_FALSE(child_of_rs2
->render_surface());
793 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
795 // Verify all render target accessors
796 EXPECT_EQ(root
, parent
->render_target());
797 EXPECT_EQ(root
, child_of_root
->render_target());
798 EXPECT_EQ(root
, grand_child_of_root
->render_target());
800 EXPECT_EQ(render_surface1
, render_surface1
->render_target());
801 EXPECT_EQ(render_surface1
, child_of_rs1
->render_target());
802 EXPECT_EQ(render_surface1
, grand_child_of_rs1
->render_target());
804 EXPECT_EQ(render_surface2
, render_surface2
->render_target());
805 EXPECT_EQ(render_surface2
, child_of_rs2
->render_target());
806 EXPECT_EQ(render_surface2
, grand_child_of_rs2
->render_target());
808 // Verify layer draw transforms note that draw transforms are described with
809 // respect to the nearest ancestor render surface but screen space transforms
810 // are described with respect to the root.
811 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->draw_transform());
812 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
, child_of_root
->draw_transform());
813 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
814 grand_child_of_root
->draw_transform());
816 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
, render_surface1
->draw_transform());
817 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
, child_of_rs1
->draw_transform());
818 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
* A
,
819 grand_child_of_rs1
->draw_transform());
821 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
, render_surface2
->draw_transform());
822 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
, child_of_rs2
->draw_transform());
823 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
* A
,
824 grand_child_of_rs2
->draw_transform());
826 // Verify layer screen-space transforms
828 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->screen_space_transform());
829 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
830 child_of_root
->screen_space_transform());
831 EXPECT_TRANSFORMATION_MATRIX_EQ(
832 A
* A
* A
, grand_child_of_root
->screen_space_transform());
834 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
835 render_surface1
->screen_space_transform());
836 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
837 child_of_rs1
->screen_space_transform());
838 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
839 grand_child_of_rs1
->screen_space_transform());
841 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
842 render_surface2
->screen_space_transform());
843 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
844 child_of_rs2
->screen_space_transform());
845 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
* A
,
846 grand_child_of_rs2
->screen_space_transform());
848 // Verify render surface transforms.
850 // Draw transform of render surface 1 is described with respect to root.
851 EXPECT_TRANSFORMATION_MATRIX_EQ(
852 A
* A
* S1
, render_surface1
->render_surface()->draw_transform());
853 EXPECT_TRANSFORMATION_MATRIX_EQ(
854 A
* R
* S1
, render_surface1
->render_surface()->replica_draw_transform());
855 EXPECT_TRANSFORMATION_MATRIX_EQ(
856 A
* A
* S1
, render_surface1
->render_surface()->screen_space_transform());
857 EXPECT_TRANSFORMATION_MATRIX_EQ(
859 render_surface1
->render_surface()->replica_screen_space_transform());
860 // Draw transform of render surface 2 is described with respect to render
862 EXPECT_TRANSFORMATION_MATRIX_EQ(
863 SS1
* A
* S2
, render_surface2
->render_surface()->draw_transform());
864 EXPECT_TRANSFORMATION_MATRIX_EQ(
866 render_surface2
->render_surface()->replica_draw_transform());
867 EXPECT_TRANSFORMATION_MATRIX_EQ(
869 render_surface2
->render_surface()->screen_space_transform());
870 EXPECT_TRANSFORMATION_MATRIX_EQ(
872 render_surface2
->render_surface()->replica_screen_space_transform());
874 // Sanity check. If these fail there is probably a bug in the test itself. It
875 // is expected that we correctly set up transforms so that the y-component of
876 // the screen-space transform encodes the "depth" of the layer in the tree.
877 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
879 child_of_root
->screen_space_transform().matrix().get(1, 3));
881 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
884 render_surface1
->screen_space_transform().matrix().get(1, 3));
886 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
888 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
891 render_surface2
->screen_space_transform().matrix().get(1, 3));
893 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
895 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
898 TEST_F(LayerTreeHostCommonTest
, TransformsForFlatteningLayer
) {
899 // For layers that flatten their subtree, there should be an orthographic
900 // projection (for x and y values) in the middle of the transform sequence.
901 // Note that the way the code is currently implemented, it is not expected to
902 // use a canonical orthographic projection.
904 LayerImpl
* root
= root_layer();
905 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
906 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
907 grand_child
->SetDrawsContent(true);
908 LayerImpl
* great_grand_child
= AddChild
<LayerImpl
>(grand_child
);
909 great_grand_child
->SetDrawsContent(true);
911 gfx::Transform rotation_about_y_axis
;
912 rotation_about_y_axis
.RotateAboutYAxis(30.0);
914 const gfx::Transform identity_matrix
;
915 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
916 gfx::PointF(), gfx::Size(100, 100), true, false,
918 SetLayerPropertiesForTesting(child
, rotation_about_y_axis
, gfx::Point3F(),
919 gfx::PointF(), gfx::Size(10, 10), true, false,
921 SetLayerPropertiesForTesting(grand_child
, rotation_about_y_axis
,
922 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
924 SetLayerPropertiesForTesting(great_grand_child
, identity_matrix
,
925 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
928 // No layers in this test should preserve 3d.
929 ASSERT_TRUE(root
->should_flatten_transform());
930 ASSERT_TRUE(child
->should_flatten_transform());
931 ASSERT_TRUE(grand_child
->should_flatten_transform());
932 ASSERT_TRUE(great_grand_child
->should_flatten_transform());
934 gfx::Transform expected_child_draw_transform
= rotation_about_y_axis
;
935 gfx::Transform expected_child_screen_space_transform
= rotation_about_y_axis
;
936 gfx::Transform expected_grand_child_draw_transform
=
937 rotation_about_y_axis
; // draws onto child's render surface
938 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
939 flattened_rotation_about_y
.FlattenTo2d();
940 gfx::Transform expected_grand_child_screen_space_transform
=
941 flattened_rotation_about_y
* rotation_about_y_axis
;
942 gfx::Transform expected_great_grand_child_draw_transform
=
943 flattened_rotation_about_y
;
944 gfx::Transform expected_great_grand_child_screen_space_transform
=
945 flattened_rotation_about_y
* flattened_rotation_about_y
;
947 ExecuteCalculateDrawProperties(root
);
949 // The child's draw transform should have been taken by its surface.
950 ASSERT_TRUE(child
->render_surface());
951 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform
,
952 child
->render_surface()->draw_transform());
953 EXPECT_TRANSFORMATION_MATRIX_EQ(
954 expected_child_screen_space_transform
,
955 child
->render_surface()->screen_space_transform());
956 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
957 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform
,
958 child
->screen_space_transform());
959 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform
,
960 grand_child
->draw_transform());
961 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform
,
962 grand_child
->screen_space_transform());
963 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform
,
964 great_grand_child
->draw_transform());
965 EXPECT_TRANSFORMATION_MATRIX_EQ(
966 expected_great_grand_child_screen_space_transform
,
967 great_grand_child
->screen_space_transform());
970 TEST_F(LayerTreeHostCommonTest
, LayerFullyContainedWithinClipInTargetSpace
) {
971 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
972 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
973 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
974 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
976 gfx::Transform child_transform
;
977 child_transform
.Translate(50.0, 50.0);
978 child_transform
.RotateAboutZAxis(30.0);
980 gfx::Transform grand_child_transform
;
981 grand_child_transform
.RotateAboutYAxis(90.0);
983 const gfx::Transform identity_matrix
;
984 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
985 gfx::PointF(), gfx::Size(200, 200), true, false);
986 SetLayerPropertiesForTesting(child
.get(), child_transform
, gfx::Point3F(),
987 gfx::PointF(), gfx::Size(10, 10), true, false);
988 SetLayerPropertiesForTesting(grand_child
.get(), grand_child_transform
,
989 gfx::Point3F(), gfx::PointF(),
990 gfx::Size(100, 100), true, false);
992 root
->AddChild(child
);
993 child
->AddChild(grand_child
);
994 grand_child
->SetShouldFlattenTransform(false);
996 host()->SetRootLayer(root
);
998 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
1000 // Mapping grand_child's bounds to target space produces a non-empty rect
1001 // that is fully contained within the target's bounds, so grand_child should
1002 // be considered fully visible.
1003 EXPECT_EQ(gfx::Rect(grand_child
->bounds()),
1004 grand_child
->visible_rect_from_property_trees());
1007 TEST_F(LayerTreeHostCommonTest
, TransformsForDegenerateIntermediateLayer
) {
1008 // A layer that is empty in one axis, but not the other, was accidentally
1009 // skipping a necessary translation. Without that translation, the coordinate
1010 // space of the layer's draw transform is incorrect.
1012 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1013 // but if that layer becomes a render surface, then its draw transform is
1014 // implicitly inherited by the rest of the subtree, which then is positioned
1015 // incorrectly as a result.
1017 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1018 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
1019 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1020 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1022 // The child height is zero, but has non-zero width that should be accounted
1023 // for while computing draw transforms.
1024 const gfx::Transform identity_matrix
;
1025 SetLayerPropertiesForTesting(root
.get(),
1029 gfx::Size(100, 100),
1032 SetLayerPropertiesForTesting(child
.get(),
1039 SetLayerPropertiesForTesting(grand_child
.get(),
1047 root
->AddChild(child
);
1048 child
->AddChild(grand_child
);
1049 child
->SetForceRenderSurface(true);
1051 host()->SetRootLayer(root
);
1053 ExecuteCalculateDrawProperties(root
.get());
1055 ASSERT_TRUE(child
->render_surface());
1056 // This is the real test, the rest are sanity checks.
1057 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1058 child
->render_surface()->draw_transform());
1059 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1060 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1061 grand_child
->draw_transform());
1064 TEST_F(LayerTreeHostCommonTest
, TransformAboveRootLayer
) {
1065 // Transformations applied at the root of the tree should be forwarded
1066 // to child layers instead of applied to the root RenderSurface.
1067 const gfx::Transform identity_matrix
;
1068 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
1069 new LayerWithForcedDrawsContent(layer_settings());
1070 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1071 new LayerWithForcedDrawsContent(layer_settings());
1072 child
->SetScrollClipLayerId(root
->id());
1073 root
->AddChild(child
);
1075 host()->SetRootLayer(root
);
1077 SetLayerPropertiesForTesting(root
.get(),
1084 SetLayerPropertiesForTesting(child
.get(),
1092 gfx::Transform translate
;
1093 translate
.Translate(50, 50);
1095 RenderSurfaceLayerList render_surface_layer_list
;
1096 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1097 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1098 inputs
.can_adjust_raster_scales
= true;
1099 inputs
.property_trees
->needs_rebuild
= true;
1100 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1101 EXPECT_EQ(translate
, root
->draw_properties().target_space_transform
);
1102 EXPECT_EQ(translate
, child
->draw_properties().target_space_transform
);
1103 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1106 gfx::Transform scale
;
1109 RenderSurfaceLayerList render_surface_layer_list
;
1110 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1111 root
.get(), root
->bounds(), scale
, &render_surface_layer_list
);
1112 inputs
.can_adjust_raster_scales
= true;
1113 inputs
.property_trees
->needs_rebuild
= true;
1114 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1115 EXPECT_EQ(scale
, root
->draw_properties().target_space_transform
);
1116 EXPECT_EQ(scale
, child
->draw_properties().target_space_transform
);
1117 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1120 gfx::Transform rotate
;
1123 RenderSurfaceLayerList render_surface_layer_list
;
1124 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1125 root
.get(), root
->bounds(), rotate
, &render_surface_layer_list
);
1126 inputs
.can_adjust_raster_scales
= true;
1127 inputs
.property_trees
->needs_rebuild
= true;
1128 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1129 EXPECT_EQ(rotate
, root
->draw_properties().target_space_transform
);
1130 EXPECT_EQ(rotate
, child
->draw_properties().target_space_transform
);
1131 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1134 gfx::Transform composite
;
1135 composite
.ConcatTransform(translate
);
1136 composite
.ConcatTransform(scale
);
1137 composite
.ConcatTransform(rotate
);
1139 RenderSurfaceLayerList render_surface_layer_list
;
1140 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1141 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1142 inputs
.can_adjust_raster_scales
= true;
1143 inputs
.property_trees
->needs_rebuild
= true;
1144 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1145 EXPECT_EQ(composite
, root
->draw_properties().target_space_transform
);
1146 EXPECT_EQ(composite
, child
->draw_properties().target_space_transform
);
1147 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1150 // Verify it composes correctly with device scale.
1151 float device_scale_factor
= 1.5f
;
1154 RenderSurfaceLayerList render_surface_layer_list
;
1155 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1156 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1157 inputs
.device_scale_factor
= device_scale_factor
;
1158 inputs
.can_adjust_raster_scales
= true;
1159 inputs
.property_trees
->needs_rebuild
= true;
1160 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1161 gfx::Transform device_scaled_translate
= translate
;
1162 device_scaled_translate
.Scale(device_scale_factor
, device_scale_factor
);
1163 EXPECT_EQ(device_scaled_translate
,
1164 root
->draw_properties().target_space_transform
);
1165 EXPECT_EQ(device_scaled_translate
,
1166 child
->draw_properties().target_space_transform
);
1167 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1170 // Verify it composes correctly with page scale.
1171 float page_scale_factor
= 2.f
;
1174 RenderSurfaceLayerList render_surface_layer_list
;
1175 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1176 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1177 inputs
.page_scale_factor
= page_scale_factor
;
1178 inputs
.page_scale_layer
= root
.get();
1179 inputs
.can_adjust_raster_scales
= true;
1180 inputs
.property_trees
->needs_rebuild
= true;
1181 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1182 gfx::Transform page_scaled_translate
= translate
;
1183 page_scaled_translate
.Scale(page_scale_factor
, page_scale_factor
);
1184 EXPECT_EQ(page_scaled_translate
,
1185 root
->draw_properties().target_space_transform
);
1186 EXPECT_EQ(page_scaled_translate
,
1187 child
->draw_properties().target_space_transform
);
1188 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1191 // Verify that it composes correctly with transforms directly on root layer.
1192 root
->SetTransform(composite
);
1195 RenderSurfaceLayerList render_surface_layer_list
;
1196 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1197 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1198 inputs
.can_adjust_raster_scales
= true;
1199 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1200 gfx::Transform compositeSquared
= composite
;
1201 compositeSquared
.ConcatTransform(composite
);
1202 EXPECT_TRANSFORMATION_MATRIX_EQ(
1203 compositeSquared
, root
->draw_properties().target_space_transform
);
1204 EXPECT_TRANSFORMATION_MATRIX_EQ(
1205 compositeSquared
, child
->draw_properties().target_space_transform
);
1206 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1210 TEST_F(LayerTreeHostCommonTest
,
1211 RenderSurfaceListForRenderSurfaceWithClippedLayer
) {
1212 LayerImpl
* parent
= root_layer();
1213 parent
->SetMasksToBounds(true);
1214 LayerImpl
* render_surface1
= AddChildToRoot
<LayerImpl
>();
1215 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface1
);
1216 child
->SetDrawsContent(true);
1218 const gfx::Transform identity_matrix
;
1219 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1220 gfx::PointF(), gfx::Size(10, 10), true, false,
1222 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
1223 gfx::PointF(), gfx::Size(10, 10), true, false,
1225 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1226 gfx::PointF(30.f
, 30.f
), gfx::Size(10, 10), true,
1229 ExecuteCalculateDrawProperties(parent
);
1231 // The child layer's content is entirely outside the parent's clip rect, so
1232 // the intermediate render surface should not be listed here, even if it was
1233 // forced to be created. Render surfaces without children or visible content
1234 // are unexpected at draw time (e.g. we might try to create a content texture
1236 ASSERT_TRUE(parent
->render_surface());
1237 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
1240 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceListForTransparentChild
) {
1241 LayerImpl
* parent
= root_layer();
1242 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(parent
);
1243 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface1
);
1244 child
->SetDrawsContent(true);
1246 const gfx::Transform identity_matrix
;
1247 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
1248 gfx::PointF(), gfx::Size(10, 10), true, false,
1250 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1251 gfx::PointF(), gfx::Size(10, 10), true, false,
1253 render_surface1
->SetOpacity(0.f
);
1255 LayerImplList render_surface_layer_list
;
1256 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1257 parent
, parent
->bounds(), &render_surface_layer_list
);
1258 inputs
.can_adjust_raster_scales
= true;
1259 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1261 // Since the layer is transparent, render_surface1->render_surface() should
1262 // not have gotten added anywhere. Also, the drawable content rect should not
1263 // have been extended by the children.
1264 ASSERT_TRUE(parent
->render_surface());
1265 EXPECT_EQ(0U, parent
->render_surface()->layer_list().size());
1266 EXPECT_EQ(1U, render_surface_layer_list
.size());
1267 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1268 EXPECT_EQ(gfx::Rect(), parent
->drawable_content_rect());
1271 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceForBlendMode
) {
1272 LayerImpl
* parent
= root_layer();
1273 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
1274 child
->SetDrawsContent(true);
1276 const gfx::Transform identity_matrix
;
1277 const SkXfermode::Mode blend_mode
= SkXfermode::kMultiply_Mode
;
1278 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1279 gfx::PointF(), gfx::Size(10, 10), true, false,
1281 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1282 gfx::PointF(), gfx::Size(10, 10), true, false,
1285 child
->SetBlendMode(blend_mode
);
1286 child
->SetOpacity(0.5f
);
1288 ExecuteCalculateDrawProperties(parent
);
1290 // Since the child layer has a blend mode other than normal, it should get
1291 // its own render surface. Also, layer's draw_properties should contain the
1292 // default blend mode, since the render surface becomes responsible for
1293 // applying the blend mode.
1294 ASSERT_TRUE(child
->render_surface());
1295 EXPECT_EQ(1.0f
, child
->draw_opacity());
1296 EXPECT_EQ(0.5f
, child
->render_surface()->draw_opacity());
1297 EXPECT_EQ(SkXfermode::kSrcOver_Mode
, child
->draw_blend_mode());
1300 TEST_F(LayerTreeHostCommonTest
, ForceRenderSurface
) {
1301 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1302 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
1303 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1304 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1305 render_surface1
->SetForceRenderSurface(true);
1307 host()->SetRootLayer(parent
);
1309 const gfx::Transform identity_matrix
;
1310 SetLayerPropertiesForTesting(parent
.get(),
1317 SetLayerPropertiesForTesting(render_surface1
.get(),
1324 SetLayerPropertiesForTesting(child
.get(),
1332 parent
->AddChild(render_surface1
);
1333 render_surface1
->AddChild(child
);
1335 // Sanity check before the actual test
1336 EXPECT_FALSE(parent
->render_surface());
1337 EXPECT_FALSE(render_surface1
->render_surface());
1340 RenderSurfaceLayerList render_surface_layer_list
;
1341 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1342 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1343 inputs
.can_adjust_raster_scales
= true;
1344 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1346 // The root layer always creates a render surface
1347 EXPECT_TRUE(parent
->render_surface());
1348 EXPECT_TRUE(render_surface1
->render_surface());
1352 RenderSurfaceLayerList render_surface_layer_list
;
1353 render_surface1
->SetForceRenderSurface(false);
1354 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1355 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1356 inputs
.can_adjust_raster_scales
= true;
1357 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1358 EXPECT_TRUE(parent
->render_surface());
1359 EXPECT_FALSE(render_surface1
->render_surface());
1363 TEST_F(LayerTreeHostCommonTest
, RenderSurfacesFlattenScreenSpaceTransform
) {
1364 // Render surfaces act as a flattening point for their subtree, so should
1365 // always flatten the target-to-screen space transform seen by descendants.
1367 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1368 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1369 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1370 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1371 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1372 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1374 gfx::Transform rotation_about_y_axis
;
1375 rotation_about_y_axis
.RotateAboutYAxis(30.0);
1376 // Make |parent| have a render surface.
1377 parent
->SetOpacity(0.9f
);
1379 const gfx::Transform identity_matrix
;
1380 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
1381 gfx::PointF(), gfx::Size(100, 100), true, false);
1382 SetLayerPropertiesForTesting(parent
.get(), rotation_about_y_axis
,
1383 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1385 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
1386 gfx::PointF(), gfx::Size(10, 10), true, false);
1387 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
1388 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1391 root
->AddChild(parent
);
1392 parent
->AddChild(child
);
1393 child
->AddChild(grand_child
);
1395 grand_child
->SetShouldFlattenTransform(false);
1397 host()->SetRootLayer(root
);
1399 // Only grand_child should preserve 3d.
1400 EXPECT_TRUE(root
->should_flatten_transform());
1401 EXPECT_TRUE(parent
->should_flatten_transform());
1402 EXPECT_TRUE(child
->should_flatten_transform());
1403 EXPECT_FALSE(grand_child
->should_flatten_transform());
1405 gfx::Transform expected_child_draw_transform
= identity_matrix
;
1406 gfx::Transform expected_grand_child_draw_transform
= identity_matrix
;
1408 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
1409 flattened_rotation_about_y
.FlattenTo2d();
1411 ExecuteCalculateDrawProperties(root
.get());
1413 EXPECT_TRUE(parent
->render_surface());
1414 EXPECT_FALSE(child
->render_surface());
1415 EXPECT_FALSE(grand_child
->render_surface());
1417 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1418 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1419 grand_child
->draw_transform());
1421 // The screen-space transform inherited by |child| and |grand_child| should
1422 // have been flattened at their render target. In particular, the fact that
1423 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1424 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y
,
1425 child
->screen_space_transform());
1426 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y
,
1427 grand_child
->screen_space_transform());
1430 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsRenderSurfaces
) {
1431 // The entire subtree of layers that are outside the clip rect should be
1432 // culled away, and should not affect the render_surface_layer_list.
1434 // The test tree is set up as follows:
1435 // - all layers except the leaf_nodes are forced to be a new render surface
1436 // that have something to draw.
1437 // - parent is a large container layer.
1438 // - child has masksToBounds=true to cause clipping.
1439 // - grand_child is positioned outside of the child's bounds
1440 // - great_grand_child is also kept outside child's bounds.
1442 // In this configuration, grand_child and great_grand_child are completely
1443 // outside the clip rect, and they should never get scheduled on the list of
1446 LayerImpl
* parent
= root_layer();
1447 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
1448 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
1449 LayerImpl
* great_grand_child
= AddChild
<LayerImpl
>(grand_child
);
1451 // leaf_node1 ensures that parent and child are kept on the
1452 // render_surface_layer_list, even though grand_child and great_grand_child
1453 // should be clipped.
1454 LayerImpl
* leaf_node1
= AddChild
<LayerImpl
>(child
);
1455 leaf_node1
->SetDrawsContent(true);
1456 LayerImpl
* leaf_node2
= AddChild
<LayerImpl
>(great_grand_child
);
1457 leaf_node2
->SetDrawsContent(true);
1459 const gfx::Transform identity_matrix
;
1461 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1462 gfx::PointF(), gfx::Size(500, 500), true, false,
1464 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1465 gfx::PointF(), gfx::Size(20, 20), true, false,
1467 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
1468 gfx::PointF(45.f
, 45.f
), gfx::Size(10, 10), true,
1470 SetLayerPropertiesForTesting(great_grand_child
, identity_matrix
,
1471 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1472 true, false, false);
1473 SetLayerPropertiesForTesting(leaf_node1
, identity_matrix
, gfx::Point3F(),
1474 gfx::PointF(), gfx::Size(500, 500), true, false,
1476 SetLayerPropertiesForTesting(leaf_node2
, identity_matrix
, gfx::Point3F(),
1477 gfx::PointF(), gfx::Size(20, 20), true, false,
1480 child
->SetMasksToBounds(true);
1481 child
->SetOpacity(0.4f
);
1482 grand_child
->SetOpacity(0.5f
);
1483 great_grand_child
->SetOpacity(0.4f
);
1485 ExecuteCalculateDrawProperties(parent
);
1487 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
1488 EXPECT_EQ(parent
->id(), render_surface_layer_list_impl()->at(0)->id());
1489 EXPECT_EQ(child
->id(), render_surface_layer_list_impl()->at(1)->id());
1492 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsSurfaceWithoutVisibleContent
) {
1493 // When a render surface has a clip rect, it is used to clip the content rect
1496 // The test tree is set up as follows:
1497 // - parent is a container layer that masksToBounds=true to cause clipping.
1498 // - child is a render surface, which has a clip rect set to the bounds of
1500 // - grand_child is a render surface, and the only visible content in child.
1501 // It is positioned outside of the clip rect from parent.
1503 // In this configuration, grand_child should be outside the clipped
1504 // content rect of the child, making grand_child not appear in the
1505 // render_surface_layer_list.
1507 LayerImpl
* parent
= root_layer();
1508 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
1509 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
1510 LayerImpl
* leaf_node
= AddChild
<LayerImpl
>(grand_child
);
1511 leaf_node
->SetDrawsContent(true);
1513 const gfx::Transform identity_matrix
;
1515 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1516 gfx::PointF(), gfx::Size(100, 100), true, false,
1518 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1519 gfx::PointF(), gfx::Size(20, 20), true, false,
1521 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
1522 gfx::PointF(200.f
, 200.f
), gfx::Size(10, 10),
1524 SetLayerPropertiesForTesting(leaf_node
, identity_matrix
, gfx::Point3F(),
1525 gfx::PointF(), gfx::Size(10, 10), true, false,
1528 parent
->SetMasksToBounds(true);
1529 child
->SetOpacity(0.4f
);
1530 grand_child
->SetOpacity(0.4f
);
1532 ExecuteCalculateDrawProperties(parent
);
1534 // We should cull child and grand_child from the
1535 // render_surface_layer_list.
1536 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
1537 EXPECT_EQ(parent
->id(), render_surface_layer_list_impl()->at(0)->id());
1540 TEST_F(LayerTreeHostCommonTest
, IsClippedIsSetCorrectly
) {
1541 // Layer's IsClipped() property is set to true when:
1542 // - the layer clips its subtree, e.g. masks to bounds,
1543 // - the layer is clipped by an ancestor that contributes to the same
1545 // - a surface is clipped by an ancestor that contributes to the same
1548 // In particular, for a layer that owns a render surface:
1549 // - the render surface inherits any clip from ancestors, and does NOT
1550 // pass that clipped status to the layer itself.
1551 // - but if the layer itself masks to bounds, it is considered clipped
1552 // and propagates the clip to the subtree.
1554 const gfx::Transform identity_matrix
;
1555 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1556 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1557 scoped_refptr
<Layer
> child1
= Layer::Create(layer_settings());
1558 scoped_refptr
<Layer
> child2
= Layer::Create(layer_settings());
1559 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
1560 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1561 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1562 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1563 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1564 root
->AddChild(parent
);
1565 parent
->AddChild(child1
);
1566 parent
->AddChild(child2
);
1567 child1
->AddChild(grand_child
);
1568 child2
->AddChild(leaf_node2
);
1569 grand_child
->AddChild(leaf_node1
);
1571 host()->SetRootLayer(root
);
1573 child2
->SetForceRenderSurface(true);
1575 SetLayerPropertiesForTesting(root
.get(),
1579 gfx::Size(100, 100),
1582 SetLayerPropertiesForTesting(parent
.get(),
1586 gfx::Size(100, 100),
1589 SetLayerPropertiesForTesting(child1
.get(),
1593 gfx::Size(100, 100),
1596 SetLayerPropertiesForTesting(child2
.get(),
1600 gfx::Size(100, 100),
1603 SetLayerPropertiesForTesting(grand_child
.get(),
1607 gfx::Size(100, 100),
1610 SetLayerPropertiesForTesting(leaf_node1
.get(),
1614 gfx::Size(100, 100),
1617 SetLayerPropertiesForTesting(leaf_node2
.get(),
1621 gfx::Size(100, 100),
1625 // Case 1: nothing is clipped except the root render surface.
1627 RenderSurfaceLayerList render_surface_layer_list
;
1628 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1629 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1630 inputs
.can_adjust_raster_scales
= true;
1631 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1633 ASSERT_TRUE(root
->render_surface());
1634 ASSERT_TRUE(child2
->render_surface());
1636 EXPECT_FALSE(root
->is_clipped());
1637 EXPECT_FALSE(parent
->is_clipped());
1638 EXPECT_FALSE(child1
->is_clipped());
1639 EXPECT_FALSE(child2
->is_clipped());
1640 EXPECT_FALSE(grand_child
->is_clipped());
1641 EXPECT_FALSE(leaf_node1
->is_clipped());
1642 EXPECT_FALSE(leaf_node2
->is_clipped());
1645 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1646 // surface are clipped. But layers that contribute to child2's surface are
1647 // not clipped explicitly because child2's surface already accounts for
1650 RenderSurfaceLayerList render_surface_layer_list
;
1651 parent
->SetMasksToBounds(true);
1652 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1653 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1654 inputs
.can_adjust_raster_scales
= true;
1655 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1657 ASSERT_TRUE(root
->render_surface());
1658 ASSERT_TRUE(child2
->render_surface());
1660 EXPECT_FALSE(root
->is_clipped());
1661 EXPECT_TRUE(parent
->is_clipped());
1662 EXPECT_TRUE(child1
->is_clipped());
1663 EXPECT_FALSE(child2
->is_clipped());
1664 EXPECT_TRUE(grand_child
->is_clipped());
1665 EXPECT_TRUE(leaf_node1
->is_clipped());
1666 EXPECT_FALSE(leaf_node2
->is_clipped());
1669 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1670 // child2's render surface is not clipped.
1672 RenderSurfaceLayerList render_surface_layer_list
;
1673 parent
->SetMasksToBounds(false);
1674 child2
->SetMasksToBounds(true);
1675 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1676 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1677 inputs
.can_adjust_raster_scales
= true;
1678 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1680 ASSERT_TRUE(root
->render_surface());
1681 ASSERT_TRUE(child2
->render_surface());
1683 EXPECT_FALSE(root
->is_clipped());
1684 EXPECT_FALSE(parent
->is_clipped());
1685 EXPECT_FALSE(child1
->is_clipped());
1686 EXPECT_TRUE(child2
->is_clipped());
1687 EXPECT_FALSE(grand_child
->is_clipped());
1688 EXPECT_FALSE(leaf_node1
->is_clipped());
1689 EXPECT_TRUE(leaf_node2
->is_clipped());
1693 TEST_F(LayerTreeHostCommonTest
, IsClippedIsSetCorrectlyLayerImpl
) {
1694 // This is identical to the IsClippedIsSetCorrectly test,
1695 // but tests render surfaces instead of the layers.
1697 const gfx::Transform identity_matrix
;
1698 LayerImpl
* root
= root_layer();
1699 LayerImpl
* parent
= AddChild
<LayerImpl
>(root
);
1700 LayerImpl
* child1
= AddChild
<LayerImpl
>(parent
);
1701 LayerImpl
* child2
= AddChild
<LayerImpl
>(parent
);
1702 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child1
);
1703 LayerImpl
* leaf_node1
= AddChild
<LayerImpl
>(grand_child
);
1704 leaf_node1
->SetDrawsContent(true);
1705 LayerImpl
* leaf_node2
= AddChild
<LayerImpl
>(child2
);
1706 leaf_node2
->SetDrawsContent(true);
1708 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
1709 gfx::PointF(), gfx::Size(100, 100), true, false,
1711 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1712 gfx::PointF(), gfx::Size(100, 100), true, false,
1714 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
1715 gfx::PointF(), gfx::Size(100, 100), true, false,
1717 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
1718 gfx::PointF(), gfx::Size(100, 100), true, false,
1720 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
1721 gfx::PointF(), gfx::Size(100, 100), true, false,
1723 SetLayerPropertiesForTesting(leaf_node1
, identity_matrix
, gfx::Point3F(),
1724 gfx::PointF(), gfx::Size(100, 100), true, false,
1726 SetLayerPropertiesForTesting(leaf_node2
, identity_matrix
, gfx::Point3F(),
1727 gfx::PointF(), gfx::Size(100, 100), true, false,
1730 // Case 1: nothing is clipped except the root render surface.
1732 ExecuteCalculateDrawProperties(root
);
1734 ASSERT_TRUE(root
->render_surface());
1735 ASSERT_TRUE(child2
->render_surface());
1737 EXPECT_FALSE(root
->is_clipped());
1738 EXPECT_TRUE(root
->render_surface()->is_clipped());
1739 EXPECT_FALSE(parent
->is_clipped());
1740 EXPECT_FALSE(child1
->is_clipped());
1741 EXPECT_FALSE(child2
->is_clipped());
1742 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1743 EXPECT_FALSE(grand_child
->is_clipped());
1744 EXPECT_FALSE(leaf_node1
->is_clipped());
1745 EXPECT_FALSE(leaf_node2
->is_clipped());
1748 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1749 // surface are clipped. But layers that contribute to child2's surface are
1750 // not clipped explicitly because child2's surface already accounts for
1753 parent
->SetMasksToBounds(true);
1755 parent
->set_is_clipped(true);
1756 child1
->set_is_clipped(true);
1757 grand_child
->set_is_clipped(true);
1758 leaf_node1
->set_is_clipped(true);
1759 host_impl()->active_tree()->property_trees()->needs_rebuild
= true;
1761 ExecuteCalculateDrawProperties(root
);
1763 ASSERT_TRUE(root
->render_surface());
1764 ASSERT_TRUE(child2
->render_surface());
1766 EXPECT_TRUE(root
->render_surface()->is_clipped());
1767 EXPECT_TRUE(child2
->render_surface()->is_clipped());
1769 parent
->SetMasksToBounds(false);
1770 parent
->set_is_clipped(false);
1771 child1
->set_is_clipped(false);
1772 grand_child
->set_is_clipped(false);
1773 leaf_node1
->set_is_clipped(false);
1776 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1777 // child2's render surface is not clipped.
1779 child2
->SetMasksToBounds(true);
1780 child2
->set_is_clipped(true);
1781 leaf_node2
->set_is_clipped(true);
1782 host_impl()->active_tree()->property_trees()->needs_rebuild
= true;
1784 ExecuteCalculateDrawProperties(root
);
1786 ASSERT_TRUE(root
->render_surface());
1787 ASSERT_TRUE(child2
->render_surface());
1789 EXPECT_FALSE(root
->is_clipped());
1790 EXPECT_TRUE(root
->render_surface()->is_clipped());
1791 EXPECT_FALSE(parent
->is_clipped());
1792 EXPECT_FALSE(child1
->is_clipped());
1793 EXPECT_TRUE(child2
->is_clipped());
1794 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1795 EXPECT_FALSE(grand_child
->is_clipped());
1796 EXPECT_FALSE(leaf_node1
->is_clipped());
1797 EXPECT_TRUE(leaf_node2
->is_clipped());
1801 TEST_F(LayerTreeHostCommonTest
, DrawableContentRectForLayers
) {
1802 // Verify that layers get the appropriate DrawableContentRect when their
1803 // parent masksToBounds is true.
1805 // grand_child1 - completely inside the region; DrawableContentRect should
1806 // be the layer rect expressed in target space.
1807 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1808 // will be the intersection of layer bounds and the mask region.
1809 // grand_child3 - partially clipped and masksToBounds; the
1810 // DrawableContentRect will still be the intersection of layer bounds and
1812 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1816 const gfx::Transform identity_matrix
;
1817 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1818 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
1819 scoped_refptr
<Layer
> grand_child1
= Layer::Create(layer_settings());
1820 scoped_refptr
<Layer
> grand_child2
= Layer::Create(layer_settings());
1821 scoped_refptr
<Layer
> grand_child3
= Layer::Create(layer_settings());
1822 scoped_refptr
<Layer
> grand_child4
= Layer::Create(layer_settings());
1824 parent
->AddChild(child
);
1825 child
->AddChild(grand_child1
);
1826 child
->AddChild(grand_child2
);
1827 child
->AddChild(grand_child3
);
1828 child
->AddChild(grand_child4
);
1830 host()->SetRootLayer(parent
);
1832 SetLayerPropertiesForTesting(parent
.get(),
1836 gfx::Size(500, 500),
1839 SetLayerPropertiesForTesting(child
.get(),
1846 SetLayerPropertiesForTesting(grand_child1
.get(),
1849 gfx::PointF(5.f
, 5.f
),
1853 SetLayerPropertiesForTesting(grand_child2
.get(),
1856 gfx::PointF(15.f
, 15.f
),
1860 SetLayerPropertiesForTesting(grand_child3
.get(),
1863 gfx::PointF(15.f
, 15.f
),
1867 SetLayerPropertiesForTesting(grand_child4
.get(),
1870 gfx::PointF(45.f
, 45.f
),
1875 child
->SetMasksToBounds(true);
1876 grand_child3
->SetMasksToBounds(true);
1878 // Force everyone to be a render surface.
1879 child
->SetOpacity(0.4f
);
1880 grand_child1
->SetOpacity(0.5f
);
1881 grand_child2
->SetOpacity(0.5f
);
1882 grand_child3
->SetOpacity(0.5f
);
1883 grand_child4
->SetOpacity(0.5f
);
1885 RenderSurfaceLayerList render_surface_layer_list
;
1886 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1887 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1888 inputs
.can_adjust_raster_scales
= true;
1889 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1891 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1
->drawable_content_rect());
1892 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3
->drawable_content_rect());
1893 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3
->drawable_content_rect());
1894 EXPECT_TRUE(grand_child4
->drawable_content_rect().IsEmpty());
1897 TEST_F(LayerTreeHostCommonTest
, ClipRectIsPropagatedCorrectlyToSurfaces
) {
1898 // Verify that render surfaces (and their layers) get the appropriate
1899 // clip rects when their parent masksToBounds is true.
1901 // Layers that own render surfaces (at least for now) do not inherit any
1902 // clipping; instead the surface will enforce the clip for the entire subtree.
1903 // They may still have a clip rect of their own layer bounds, however, if
1904 // masksToBounds was true.
1905 LayerImpl
* parent
= root_layer();
1906 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
1907 LayerImpl
* grand_child1
= AddChild
<LayerImpl
>(child
);
1908 LayerImpl
* grand_child2
= AddChild
<LayerImpl
>(child
);
1909 LayerImpl
* grand_child3
= AddChild
<LayerImpl
>(child
);
1910 LayerImpl
* grand_child4
= AddChild
<LayerImpl
>(child
);
1911 // the leaf nodes ensure that these grand_children become render surfaces for
1913 LayerImpl
* leaf_node1
= AddChild
<LayerImpl
>(grand_child1
);
1914 leaf_node1
->SetDrawsContent(true);
1915 LayerImpl
* leaf_node2
= AddChild
<LayerImpl
>(grand_child2
);
1916 leaf_node2
->SetDrawsContent(true);
1917 LayerImpl
* leaf_node3
= AddChild
<LayerImpl
>(grand_child3
);
1918 leaf_node3
->SetDrawsContent(true);
1919 LayerImpl
* leaf_node4
= AddChild
<LayerImpl
>(grand_child4
);
1920 leaf_node4
->SetDrawsContent(true);
1922 const gfx::Transform identity_matrix
;
1924 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1925 gfx::PointF(), gfx::Size(500, 500), true, false,
1927 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1928 gfx::PointF(), gfx::Size(20, 20), true, false,
1930 SetLayerPropertiesForTesting(grand_child1
, identity_matrix
, gfx::Point3F(),
1931 gfx::PointF(5.f
, 5.f
), gfx::Size(10, 10), true,
1933 SetLayerPropertiesForTesting(grand_child2
, identity_matrix
, gfx::Point3F(),
1934 gfx::PointF(15.f
, 15.f
), gfx::Size(10, 10), true,
1936 SetLayerPropertiesForTesting(grand_child3
, identity_matrix
, gfx::Point3F(),
1937 gfx::PointF(15.f
, 15.f
), gfx::Size(10, 10), true,
1939 SetLayerPropertiesForTesting(grand_child4
, identity_matrix
, gfx::Point3F(),
1940 gfx::PointF(45.f
, 45.f
), gfx::Size(10, 10), true,
1942 SetLayerPropertiesForTesting(leaf_node1
, identity_matrix
, gfx::Point3F(),
1943 gfx::PointF(), gfx::Size(10, 10), true, false,
1945 SetLayerPropertiesForTesting(leaf_node2
, identity_matrix
, gfx::Point3F(),
1946 gfx::PointF(), gfx::Size(10, 10), true, false,
1948 SetLayerPropertiesForTesting(leaf_node3
, identity_matrix
, gfx::Point3F(),
1949 gfx::PointF(), gfx::Size(10, 10), true, false,
1951 SetLayerPropertiesForTesting(leaf_node4
, identity_matrix
, gfx::Point3F(),
1952 gfx::PointF(), gfx::Size(10, 10), true, false,
1955 child
->SetMasksToBounds(true);
1956 grand_child3
->SetMasksToBounds(true);
1957 grand_child4
->SetMasksToBounds(true);
1959 // Force everyone to be a render surface.
1960 child
->SetOpacity(0.4f
);
1961 grand_child1
->SetOpacity(0.5f
);
1962 grand_child2
->SetOpacity(0.5f
);
1963 grand_child3
->SetOpacity(0.5f
);
1964 grand_child4
->SetOpacity(0.5f
);
1966 ExecuteCalculateDrawProperties(parent
);
1968 ASSERT_TRUE(grand_child1
->render_surface());
1969 ASSERT_TRUE(grand_child2
->render_surface());
1970 ASSERT_TRUE(grand_child3
->render_surface());
1972 // Surfaces are clipped by their parent, but un-affected by the owning layer's
1974 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1975 grand_child1
->render_surface()->clip_rect());
1976 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1977 grand_child2
->render_surface()->clip_rect());
1978 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1979 grand_child3
->render_surface()->clip_rect());
1982 TEST_F(LayerTreeHostCommonTest
, AnimationsForRenderSurfaceHierarchy
) {
1983 LayerImpl
* parent
= root_layer();
1984 LayerImpl
* render_surface1
= AddChildToRoot
<LayerImpl
>();
1985 LayerImpl
* child_of_rs1
= AddChild
<LayerImpl
>(render_surface1
);
1986 LayerImpl
* grand_child_of_rs1
= AddChild
<LayerImpl
>(child_of_rs1
);
1987 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(render_surface1
);
1988 LayerImpl
* child_of_rs2
= AddChild
<LayerImpl
>(render_surface2
);
1989 LayerImpl
* grand_child_of_rs2
= AddChild
<LayerImpl
>(child_of_rs2
);
1990 LayerImpl
* child_of_root
= AddChildToRoot
<LayerImpl
>();
1991 LayerImpl
* grand_child_of_root
= AddChild
<LayerImpl
>(child_of_root
);
1993 grand_child_of_rs1
->SetDrawsContent(true);
1994 grand_child_of_rs2
->SetDrawsContent(true);
1996 gfx::Transform layer_transform
;
1997 layer_transform
.Translate(1.0, 1.0);
1999 SetLayerPropertiesForTesting(
2000 parent
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2001 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, true);
2002 SetLayerPropertiesForTesting(
2003 render_surface1
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2004 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, true);
2005 SetLayerPropertiesForTesting(
2006 render_surface2
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2007 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, true);
2008 SetLayerPropertiesForTesting(
2009 child_of_root
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2010 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
2011 SetLayerPropertiesForTesting(
2012 child_of_rs1
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2013 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
2014 SetLayerPropertiesForTesting(
2015 child_of_rs2
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2016 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
2017 SetLayerPropertiesForTesting(
2018 grand_child_of_root
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2019 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
2020 SetLayerPropertiesForTesting(
2021 grand_child_of_rs1
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2022 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
2023 SetLayerPropertiesForTesting(
2024 grand_child_of_rs2
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
2025 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
2027 // Put an animated opacity on the render surface.
2028 AddOpacityTransitionToController(
2029 render_surface1
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2031 // Also put an animated opacity on a layer without descendants.
2032 AddOpacityTransitionToController(
2033 grand_child_of_root
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2035 // Put a transform animation on the render surface.
2036 AddAnimatedTransformToController(
2037 render_surface2
->layer_animation_controller(), 10.0, 30, 0);
2039 // Also put transform animations on grand_child_of_root, and
2040 // grand_child_of_rs2
2041 AddAnimatedTransformToController(
2042 grand_child_of_root
->layer_animation_controller(), 10.0, 30, 0);
2043 AddAnimatedTransformToController(
2044 grand_child_of_rs2
->layer_animation_controller(), 10.0, 30, 0);
2046 ExecuteCalculateDrawProperties(parent
);
2048 // Only layers that are associated with render surfaces should have an actual
2049 // RenderSurface() value.
2050 ASSERT_TRUE(parent
->render_surface());
2051 ASSERT_FALSE(child_of_root
->render_surface());
2052 ASSERT_FALSE(grand_child_of_root
->render_surface());
2054 ASSERT_TRUE(render_surface1
->render_surface());
2055 ASSERT_FALSE(child_of_rs1
->render_surface());
2056 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
2058 ASSERT_TRUE(render_surface2
->render_surface());
2059 ASSERT_FALSE(child_of_rs2
->render_surface());
2060 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
2062 // Verify all render target accessors
2063 EXPECT_EQ(parent
, parent
->render_target());
2064 EXPECT_EQ(parent
, child_of_root
->render_target());
2065 EXPECT_EQ(parent
, grand_child_of_root
->render_target());
2067 EXPECT_EQ(render_surface1
, render_surface1
->render_target());
2068 EXPECT_EQ(render_surface1
, child_of_rs1
->render_target());
2069 EXPECT_EQ(render_surface1
, grand_child_of_rs1
->render_target());
2071 EXPECT_EQ(render_surface2
, render_surface2
->render_target());
2072 EXPECT_EQ(render_surface2
, child_of_rs2
->render_target());
2073 EXPECT_EQ(render_surface2
, grand_child_of_rs2
->render_target());
2075 // Verify screen_space_transform_is_animating values
2076 EXPECT_FALSE(parent
->screen_space_transform_is_animating());
2077 EXPECT_FALSE(child_of_root
->screen_space_transform_is_animating());
2078 EXPECT_TRUE(grand_child_of_root
->screen_space_transform_is_animating());
2079 EXPECT_FALSE(render_surface1
->screen_space_transform_is_animating());
2080 EXPECT_FALSE(child_of_rs1
->screen_space_transform_is_animating());
2081 EXPECT_FALSE(grand_child_of_rs1
->screen_space_transform_is_animating());
2082 EXPECT_TRUE(render_surface2
->screen_space_transform_is_animating());
2083 EXPECT_TRUE(child_of_rs2
->screen_space_transform_is_animating());
2084 EXPECT_TRUE(grand_child_of_rs2
->screen_space_transform_is_animating());
2086 // Sanity check. If these fail there is probably a bug in the test itself.
2087 // It is expected that we correctly set up transforms so that the y-component
2088 // of the screen-space transform encodes the "depth" of the layer in the tree.
2089 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
2090 EXPECT_FLOAT_EQ(2.0,
2091 child_of_root
->screen_space_transform().matrix().get(1, 3));
2093 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
2095 EXPECT_FLOAT_EQ(2.0,
2096 render_surface1
->screen_space_transform().matrix().get(1, 3));
2097 EXPECT_FLOAT_EQ(3.0,
2098 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2100 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2102 EXPECT_FLOAT_EQ(3.0,
2103 render_surface2
->screen_space_transform().matrix().get(1, 3));
2104 EXPECT_FLOAT_EQ(4.0,
2105 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2107 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2110 TEST_F(LayerTreeHostCommonTest
,
2111 ScreenSpaceTransformIsAnimatingWithDelayedAnimation
) {
2112 LayerImpl
* parent
= root_layer();
2113 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
2114 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
2115 LayerImpl
* great_grand_child
= AddChild
<LayerImpl
>(grand_child
);
2117 parent
->SetDrawsContent(true);
2118 child
->SetDrawsContent(true);
2119 grand_child
->SetDrawsContent(true);
2120 great_grand_child
->SetDrawsContent(true);
2122 gfx::Transform identity
;
2124 SetLayerPropertiesForTesting(parent
, identity
, gfx::Point3F(), gfx::PointF(),
2125 gfx::Size(10, 10), true, false, true);
2126 SetLayerPropertiesForTesting(child
, identity
, gfx::Point3F(), gfx::PointF(),
2127 gfx::Size(10, 10), true, false, false);
2128 SetLayerPropertiesForTesting(grand_child
, identity
, gfx::Point3F(),
2129 gfx::PointF(), gfx::Size(10, 10), true, false,
2131 SetLayerPropertiesForTesting(great_grand_child
, identity
, gfx::Point3F(),
2132 gfx::PointF(), gfx::Size(10, 10), true, false,
2135 // Add a transform animation with a start delay to |grand_child|.
2136 scoped_ptr
<Animation
> animation
= Animation::Create(
2137 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1.0)).Pass(), 0, 1,
2138 Animation::TRANSFORM
);
2139 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
2140 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
2141 grand_child
->layer_animation_controller()->AddAnimation(animation
.Pass());
2143 ExecuteCalculateDrawProperties(parent
);
2145 EXPECT_FALSE(parent
->screen_space_transform_is_animating());
2146 EXPECT_FALSE(child
->screen_space_transform_is_animating());
2148 EXPECT_FALSE(grand_child
->TransformIsAnimating());
2149 EXPECT_TRUE(grand_child
->HasPotentiallyRunningTransformAnimation());
2150 EXPECT_TRUE(grand_child
->screen_space_transform_is_animating());
2151 EXPECT_TRUE(great_grand_child
->screen_space_transform_is_animating());
2154 TEST_F(LayerTreeHostCommonTest
, VisibleRectForIdentityTransform
) {
2155 // Test the calculateVisibleRect() function works correctly for identity
2158 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2159 gfx::Transform layer_to_surface_transform
;
2161 // Case 1: Layer is contained within the surface.
2162 gfx::Rect layer_content_rect
= gfx::Rect(10, 10, 30, 30);
2163 gfx::Rect expected
= gfx::Rect(10, 10, 30, 30);
2164 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2165 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2166 EXPECT_EQ(expected
, actual
);
2168 // Case 2: Layer is outside the surface rect.
2169 layer_content_rect
= gfx::Rect(120, 120, 30, 30);
2170 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2171 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2172 EXPECT_TRUE(actual
.IsEmpty());
2174 // Case 3: Layer is partially overlapping the surface rect.
2175 layer_content_rect
= gfx::Rect(80, 80, 30, 30);
2176 expected
= gfx::Rect(80, 80, 20, 20);
2177 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2178 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2179 EXPECT_EQ(expected
, actual
);
2182 TEST_F(LayerTreeHostCommonTest
, VisibleRectForTranslations
) {
2183 // Test the calculateVisibleRect() function works correctly for scaling
2186 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2187 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2188 gfx::Transform layer_to_surface_transform
;
2190 // Case 1: Layer is contained within the surface.
2191 layer_to_surface_transform
.MakeIdentity();
2192 layer_to_surface_transform
.Translate(10.0, 10.0);
2193 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2194 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2195 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2196 EXPECT_EQ(expected
, actual
);
2198 // Case 2: Layer is outside the surface rect.
2199 layer_to_surface_transform
.MakeIdentity();
2200 layer_to_surface_transform
.Translate(120.0, 120.0);
2201 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2202 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2203 EXPECT_TRUE(actual
.IsEmpty());
2205 // Case 3: Layer is partially overlapping the surface rect.
2206 layer_to_surface_transform
.MakeIdentity();
2207 layer_to_surface_transform
.Translate(80.0, 80.0);
2208 expected
= gfx::Rect(0, 0, 20, 20);
2209 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2210 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2211 EXPECT_EQ(expected
, actual
);
2214 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor2DRotations
) {
2215 // Test the calculateVisibleRect() function works correctly for rotations
2216 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2217 // should return the g in the layer's space.
2219 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2220 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2221 gfx::Transform layer_to_surface_transform
;
2223 // Case 1: Layer is contained within the surface.
2224 layer_to_surface_transform
.MakeIdentity();
2225 layer_to_surface_transform
.Translate(50.0, 50.0);
2226 layer_to_surface_transform
.Rotate(45.0);
2227 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2228 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2229 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2230 EXPECT_EQ(expected
, actual
);
2232 // Case 2: Layer is outside the surface rect.
2233 layer_to_surface_transform
.MakeIdentity();
2234 layer_to_surface_transform
.Translate(-50.0, 0.0);
2235 layer_to_surface_transform
.Rotate(45.0);
2236 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2237 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2238 EXPECT_TRUE(actual
.IsEmpty());
2240 // Case 3: The layer is rotated about its top-left corner. In surface space,
2241 // the layer is oriented diagonally, with the left half outside of the render
2242 // surface. In this case, the g should still be the entire layer
2243 // (remember the g is computed in layer space); both the top-left
2244 // and bottom-right corners of the layer are still visible.
2245 layer_to_surface_transform
.MakeIdentity();
2246 layer_to_surface_transform
.Rotate(45.0);
2247 expected
= gfx::Rect(0, 0, 30, 30);
2248 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2249 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2250 EXPECT_EQ(expected
, actual
);
2252 // Case 4: The layer is rotated about its top-left corner, and translated
2253 // upwards. In surface space, the layer is oriented diagonally, with only the
2254 // top corner of the surface overlapping the layer. In layer space, the render
2255 // surface overlaps the right side of the layer. The g should be
2256 // the layer's right half.
2257 layer_to_surface_transform
.MakeIdentity();
2258 layer_to_surface_transform
.Translate(0.0, -sqrt(2.0) * 15.0);
2259 layer_to_surface_transform
.Rotate(45.0);
2260 expected
= gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
2261 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2262 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2263 EXPECT_EQ(expected
, actual
);
2266 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dOrthographicTransform
) {
2267 // Test that the calculateVisibleRect() function works correctly for 3d
2270 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2271 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2272 gfx::Transform layer_to_surface_transform
;
2274 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2275 // degrees, should be fully contained in the render surface.
2276 layer_to_surface_transform
.MakeIdentity();
2277 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2278 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2279 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2280 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2281 EXPECT_EQ(expected
, actual
);
2283 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2284 // degrees, but shifted to the side so only the right-half the layer would be
2285 // visible on the surface.
2286 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2287 SkMScalar half_width_of_rotated_layer
=
2288 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
2289 layer_to_surface_transform
.MakeIdentity();
2290 layer_to_surface_transform
.Translate(-half_width_of_rotated_layer
, 0.0);
2291 layer_to_surface_transform
.RotateAboutYAxis(45.0); // Rotates about the left
2292 // edge of the layer.
2293 expected
= gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
2294 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2295 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2296 EXPECT_EQ(expected
, actual
);
2299 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveTransform
) {
2300 // Test the calculateVisibleRect() function works correctly when the layer has
2301 // a perspective projection onto the target surface.
2303 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2304 gfx::Rect layer_content_rect
= gfx::Rect(-50, -50, 200, 200);
2305 gfx::Transform layer_to_surface_transform
;
2307 // Case 1: Even though the layer is twice as large as the surface, due to
2308 // perspective foreshortening, the layer will fit fully in the surface when
2309 // its translated more than the perspective amount.
2310 layer_to_surface_transform
.MakeIdentity();
2312 // The following sequence of transforms applies the perspective about the
2313 // center of the surface.
2314 layer_to_surface_transform
.Translate(50.0, 50.0);
2315 layer_to_surface_transform
.ApplyPerspectiveDepth(9.0);
2316 layer_to_surface_transform
.Translate(-50.0, -50.0);
2318 // This translate places the layer in front of the surface's projection plane.
2319 layer_to_surface_transform
.Translate3d(0.0, 0.0, -27.0);
2321 gfx::Rect expected
= gfx::Rect(-50, -50, 200, 200);
2322 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2323 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2324 EXPECT_EQ(expected
, actual
);
2326 // Case 2: same projection as before, except that the layer is also translated
2327 // to the side, so that only the right half of the layer should be visible.
2329 // Explanation of expected result: The perspective ratio is (z distance
2330 // between layer and camera origin) / (z distance between projection plane and
2331 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2332 // move a layer by translating -50 units in projected surface units (so that
2333 // only half of it is visible), then we would need to translate by (-36 / 9) *
2334 // -50 == -200 in the layer's units.
2335 layer_to_surface_transform
.Translate3d(-200.0, 0.0, 0.0);
2336 expected
= gfx::Rect(gfx::Point(50, -50),
2337 gfx::Size(100, 200)); // The right half of the layer's
2339 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2340 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2341 EXPECT_EQ(expected
, actual
);
2344 TEST_F(LayerTreeHostCommonTest
,
2345 VisibleRectFor3dOrthographicIsNotClippedBehindSurface
) {
2346 // There is currently no explicit concept of an orthographic projection plane
2347 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2348 // are technically behind the surface in an orthographic world should not be
2349 // clipped when they are flattened to the surface.
2351 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2352 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2353 gfx::Transform layer_to_surface_transform
;
2355 // This sequence of transforms effectively rotates the layer about the y-axis
2356 // at the center of the layer.
2357 layer_to_surface_transform
.MakeIdentity();
2358 layer_to_surface_transform
.Translate(50.0, 0.0);
2359 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2360 layer_to_surface_transform
.Translate(-50.0, 0.0);
2362 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2363 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2364 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2365 EXPECT_EQ(expected
, actual
);
2368 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveWhenClippedByW
) {
2369 // Test the calculateVisibleRect() function works correctly when projecting a
2370 // surface onto a layer, but the layer is partially behind the camera (not
2371 // just behind the projection plane). In this case, the cartesian coordinates
2372 // may seem to be valid, but actually they are not. The visible rect needs to
2373 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2374 // converting to cartesian coordinates.
2376 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2377 gfx::Rect layer_content_rect
= gfx::Rect(-10, -1, 20, 2);
2378 gfx::Transform layer_to_surface_transform
;
2380 // The layer is positioned so that the right half of the layer should be in
2381 // front of the camera, while the other half is behind the surface's
2382 // projection plane. The following sequence of transforms applies the
2383 // perspective and rotation about the center of the layer.
2384 layer_to_surface_transform
.MakeIdentity();
2385 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2386 layer_to_surface_transform
.Translate3d(-2.0, 0.0, 1.0);
2387 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2389 // Sanity check that this transform does indeed cause w < 0 when applying the
2390 // transform, otherwise this code is not testing the intended scenario.
2392 MathUtil::MapQuad(layer_to_surface_transform
,
2393 gfx::QuadF(gfx::RectF(layer_content_rect
)),
2395 ASSERT_TRUE(clipped
);
2397 int expected_x_position
= 0;
2398 int expected_width
= 10;
2399 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2400 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2401 EXPECT_EQ(expected_x_position
, actual
.x());
2402 EXPECT_EQ(expected_width
, actual
.width());
2405 TEST_F(LayerTreeHostCommonTest
, VisibleRectForPerspectiveUnprojection
) {
2406 // To determine visible rect in layer space, there needs to be an
2407 // un-projection from surface space to layer space. When the original
2408 // transform was a perspective projection that was clipped, it returns a rect
2409 // that encloses the clipped bounds. Un-projecting this new rect may require
2412 // This sequence of transforms causes one corner of the layer to protrude
2413 // across the w = 0 plane, and should be clipped.
2414 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2415 gfx::Rect layer_content_rect
= gfx::Rect(-10, -10, 20, 20);
2416 gfx::Transform layer_to_surface_transform
;
2417 layer_to_surface_transform
.MakeIdentity();
2418 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2419 layer_to_surface_transform
.Translate3d(0.0, 0.0, -5.0);
2420 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2421 layer_to_surface_transform
.RotateAboutXAxis(80.0);
2423 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2424 // code is not testing the intended scenario.
2426 gfx::RectF clipped_rect
=
2427 MathUtil::MapClippedRect(layer_to_surface_transform
, layer_content_rect
);
2428 MathUtil::ProjectQuad(
2429 Inverse(layer_to_surface_transform
), gfx::QuadF(clipped_rect
), &clipped
);
2430 ASSERT_TRUE(clipped
);
2432 // Only the corner of the layer is not visible on the surface because of being
2433 // clipped. But, the net result of rounding visible region to an axis-aligned
2434 // rect is that the entire layer should still be considered visible.
2435 gfx::Rect expected
= gfx::Rect(-10, -10, 20, 20);
2436 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2437 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2438 EXPECT_EQ(expected
, actual
);
2441 TEST_F(LayerTreeHostCommonTest
,
2442 VisibleRectsForPositionedRootLayerClippedByViewport
) {
2443 scoped_refptr
<Layer
> root
=
2444 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2445 host()->SetRootLayer(root
);
2447 gfx::Transform identity_matrix
;
2448 // Root layer is positioned at (60, 70). The default device viewport size
2449 // is (0, 0, 100x100) in target space. So the root layer's visible rect
2450 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space.
2451 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2452 gfx::PointF(60, 70), gfx::Size(100, 100), true,
2454 ExecuteCalculateDrawProperties(root
.get());
2456 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2457 root
->render_surface()->DrawableContentRect());
2458 // In target space, not clipped.
2459 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root
->drawable_content_rect());
2460 // In layer space, clipped.
2461 EXPECT_EQ(gfx::Rect(0, 0, 40, 30), root
->visible_layer_rect());
2464 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsForSimpleLayers
) {
2465 LayerImpl
* root
= root_layer();
2466 LayerImpl
* child1_layer
= AddChildToRoot
<LayerImpl
>();
2467 child1_layer
->SetDrawsContent(true);
2468 LayerImpl
* child2_layer
= AddChildToRoot
<LayerImpl
>();
2469 child2_layer
->SetDrawsContent(true);
2470 LayerImpl
* child3_layer
= AddChildToRoot
<LayerImpl
>();
2471 child3_layer
->SetDrawsContent(true);
2473 gfx::Transform identity_matrix
;
2474 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2475 gfx::PointF(), gfx::Size(100, 100), true, false,
2477 SetLayerPropertiesForTesting(child1_layer
, identity_matrix
, gfx::Point3F(),
2478 gfx::PointF(), gfx::Size(50, 50), true, false,
2480 SetLayerPropertiesForTesting(child2_layer
, identity_matrix
, gfx::Point3F(),
2481 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2483 SetLayerPropertiesForTesting(child3_layer
, identity_matrix
, gfx::Point3F(),
2484 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2485 true, false, false);
2487 ExecuteCalculateDrawProperties(root
);
2489 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2490 root
->render_surface()->DrawableContentRect());
2491 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2493 // Layers that do not draw content should have empty visible_layer_rects.
2494 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2496 // layer visible_layer_rects are clipped by their target surface.
2497 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer
->visible_layer_rect());
2498 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer
->visible_layer_rect());
2499 EXPECT_TRUE(child3_layer
->visible_layer_rect().IsEmpty());
2501 // layer drawable_content_rects are not clipped.
2502 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer
->drawable_content_rect());
2503 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer
->drawable_content_rect());
2504 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer
->drawable_content_rect());
2507 TEST_F(LayerTreeHostCommonTest
,
2508 DrawableAndVisibleContentRectsForLayersClippedByLayer
) {
2509 LayerImpl
* root
= root_layer();
2510 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
2511 LayerImpl
* grand_child1
= AddChild
<LayerImpl
>(child
);
2512 grand_child1
->SetDrawsContent(true);
2513 LayerImpl
* grand_child2
= AddChild
<LayerImpl
>(child
);
2514 grand_child2
->SetDrawsContent(true);
2515 LayerImpl
* grand_child3
= AddChild
<LayerImpl
>(child
);
2516 grand_child3
->SetDrawsContent(true);
2518 gfx::Transform identity_matrix
;
2519 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2520 gfx::PointF(), gfx::Size(100, 100), true, false,
2522 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
2523 gfx::PointF(), gfx::Size(100, 100), true, false,
2525 SetLayerPropertiesForTesting(grand_child1
, identity_matrix
, gfx::Point3F(),
2526 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2528 SetLayerPropertiesForTesting(grand_child2
, identity_matrix
, gfx::Point3F(),
2529 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2531 SetLayerPropertiesForTesting(grand_child3
, identity_matrix
, gfx::Point3F(),
2532 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2533 true, false, false);
2535 child
->SetMasksToBounds(true);
2536 ExecuteCalculateDrawProperties(root
);
2538 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2539 root
->render_surface()->DrawableContentRect());
2540 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2542 // Layers that do not draw content should have empty visible content rects.
2543 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2544 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child
->visible_layer_rect());
2546 // All grandchild visible content rects should be clipped by child.
2547 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1
->visible_layer_rect());
2548 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2
->visible_layer_rect());
2549 EXPECT_TRUE(grand_child3
->visible_layer_rect().IsEmpty());
2551 // All grandchild DrawableContentRects should also be clipped by child.
2552 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1
->drawable_content_rect());
2553 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2
->drawable_content_rect());
2554 EXPECT_TRUE(grand_child3
->drawable_content_rect().IsEmpty());
2557 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectWithClippingAndScaling
) {
2558 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2559 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
2560 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
2561 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2562 root
->AddChild(child
);
2563 child
->AddChild(grand_child
);
2565 host()->SetRootLayer(root
);
2567 gfx::Transform identity_matrix
;
2568 gfx::Transform child_scale_matrix
;
2569 child_scale_matrix
.Scale(0.25f
, 0.25f
);
2570 gfx::Transform grand_child_scale_matrix
;
2571 grand_child_scale_matrix
.Scale(0.246f
, 0.246f
);
2572 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2573 gfx::PointF(), gfx::Size(100, 100), true, false);
2574 SetLayerPropertiesForTesting(child
.get(), child_scale_matrix
, gfx::Point3F(),
2575 gfx::PointF(), gfx::Size(10, 10), true, false);
2576 SetLayerPropertiesForTesting(grand_child
.get(), grand_child_scale_matrix
,
2577 gfx::Point3F(), gfx::PointF(),
2578 gfx::Size(100, 100), true, false);
2580 child
->SetMasksToBounds(true);
2581 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
2583 // The visible rect is expanded to integer coordinates in target space before
2584 // being projected back to layer space, where it is once again expanded to
2585 // integer coordinates.
2586 EXPECT_EQ(gfx::Rect(49, 49), grand_child
->visible_rect_from_property_trees());
2589 TEST_F(LayerTreeHostCommonTest
,
2590 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface
) {
2591 LayerImpl
* root
= root_layer();
2592 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
2593 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
2594 child1
->SetDrawsContent(true);
2595 LayerImpl
* child2
= AddChild
<LayerImpl
>(render_surface
);
2596 child2
->SetDrawsContent(true);
2597 LayerImpl
* child3
= AddChild
<LayerImpl
>(render_surface
);
2598 child3
->SetDrawsContent(true);
2600 gfx::Transform identity_matrix
;
2601 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2602 gfx::PointF(), gfx::Size(100, 100), true, false,
2604 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
2605 gfx::PointF(), gfx::Size(3, 4), true, false,
2607 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
2608 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2610 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
2611 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2613 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
2614 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2615 true, false, false);
2617 ExecuteCalculateDrawProperties(root
);
2619 ASSERT_TRUE(render_surface
->render_surface());
2621 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2622 root
->render_surface()->DrawableContentRect());
2623 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2625 // Layers that do not draw content should have empty visible content rects.
2626 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2627 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface
->visible_layer_rect());
2629 // An unclipped surface grows its DrawableContentRect to include all drawable
2630 // regions of the subtree.
2631 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2632 render_surface
->render_surface()->DrawableContentRect());
2634 // All layers that draw content into the unclipped surface are also unclipped.
2635 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
2636 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_layer_rect());
2637 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_layer_rect());
2639 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2640 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2641 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2644 TEST_F(LayerTreeHostCommonTest
,
2645 VisibleContentRectsForClippedSurfaceWithEmptyClip
) {
2646 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2647 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2648 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2649 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2650 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2651 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2652 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2653 root
->AddChild(child1
);
2654 root
->AddChild(child2
);
2655 root
->AddChild(child3
);
2657 host()->SetRootLayer(root
);
2659 gfx::Transform identity_matrix
;
2660 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2661 gfx::PointF(), gfx::Size(100, 100), true, false);
2662 SetLayerPropertiesForTesting(child1
.get(), identity_matrix
, gfx::Point3F(),
2663 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2665 SetLayerPropertiesForTesting(child2
.get(), identity_matrix
, gfx::Point3F(),
2666 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2668 SetLayerPropertiesForTesting(child3
.get(), identity_matrix
, gfx::Point3F(),
2669 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2672 RenderSurfaceLayerList render_surface_layer_list
;
2673 // Now set the root render surface an empty clip.
2674 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
2675 root
.get(), gfx::Size(), &render_surface_layer_list
);
2677 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
2678 ASSERT_TRUE(root
->render_surface());
2679 EXPECT_FALSE(root
->is_clipped());
2682 EXPECT_EQ(empty
, root
->render_surface()->clip_rect());
2683 EXPECT_TRUE(root
->render_surface()->is_clipped());
2685 // Visible content rect calculation will check if the target surface is
2686 // clipped or not. An empty clip rect does not indicate the render surface
2688 EXPECT_EQ(empty
, child1
->visible_layer_rect());
2689 EXPECT_EQ(empty
, child2
->visible_layer_rect());
2690 EXPECT_EQ(empty
, child3
->visible_layer_rect());
2693 TEST_F(LayerTreeHostCommonTest
,
2694 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform
) {
2695 LayerImpl
* root
= root_layer();
2696 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
2697 child
->SetDrawsContent(true);
2699 // Case 1: a truly degenerate matrix
2700 gfx::Transform identity_matrix
;
2701 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2702 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2704 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2705 gfx::PointF(), gfx::Size(100, 100), true, false,
2707 SetLayerPropertiesForTesting(child
, uninvertible_matrix
, gfx::Point3F(),
2708 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2711 ExecuteCalculateDrawProperties(root
);
2713 EXPECT_TRUE(child
->visible_layer_rect().IsEmpty());
2714 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2716 // Case 2: a matrix with flattened z, uninvertible and not visible according
2718 uninvertible_matrix
.MakeIdentity();
2719 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2720 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2722 SetLayerPropertiesForTesting(child
, uninvertible_matrix
, gfx::Point3F(),
2723 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2726 ExecuteCalculateDrawProperties(root
);
2728 EXPECT_TRUE(child
->visible_layer_rect().IsEmpty());
2729 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2731 // Case 3: a matrix with flattened z, also uninvertible and not visible.
2732 uninvertible_matrix
.MakeIdentity();
2733 uninvertible_matrix
.Translate(500.0, 0.0);
2734 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2735 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2737 SetLayerPropertiesForTesting(child
, uninvertible_matrix
, gfx::Point3F(),
2738 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2741 ExecuteCalculateDrawProperties(root
);
2743 EXPECT_TRUE(child
->visible_layer_rect().IsEmpty());
2744 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2747 TEST_F(LayerTreeHostCommonTest
,
2748 VisibleContentRectForLayerWithUninvertibleDrawTransform
) {
2749 LayerImpl
* root
= root_layer();
2750 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
2751 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
2752 child
->SetDrawsContent(true);
2753 grand_child
->SetDrawsContent(true);
2755 gfx::Transform identity_matrix
;
2757 gfx::Transform perspective
;
2758 perspective
.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
2760 gfx::Transform rotation
;
2761 rotation
.RotateAboutYAxis(45.0);
2763 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2764 gfx::PointF(), gfx::Size(100, 100), true, false,
2766 SetLayerPropertiesForTesting(child
, perspective
, gfx::Point3F(),
2767 gfx::PointF(10.f
, 10.f
), gfx::Size(100, 100),
2768 false, true, false);
2769 SetLayerPropertiesForTesting(grand_child
, rotation
, gfx::Point3F(),
2770 gfx::PointF(), gfx::Size(100, 100), false, true,
2773 ExecuteCalculateDrawProperties(root
);
2775 // Though all layers have invertible transforms, matrix multiplication using
2776 // floating-point math makes the draw transform uninvertible.
2777 EXPECT_FALSE(grand_child
->draw_transform().IsInvertible());
2779 // CalcDrawProps only skips a subtree when a layer's own transform is
2780 // uninvertible, not when its draw transform is invertible, since CDP makes
2781 // skipping decisions before computing a layer's draw transform. Property
2782 // trees make skipping decisions after computing draw transforms, so could be
2783 // made to skip layers with an uninvertible draw transform (once CDP is
2785 EXPECT_EQ(gfx::Rect(grand_child
->bounds()),
2786 grand_child
->visible_layer_rect());
2789 TEST_F(LayerTreeHostCommonTest
,
2790 OcclusionForLayerWithUninvertibleDrawTransform
) {
2791 FakeImplProxy proxy
;
2792 TestSharedBitmapManager shared_bitmap_manager
;
2793 TestTaskGraphRunner task_graph_runner
;
2794 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
2795 &task_graph_runner
);
2796 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
2797 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 2);
2798 scoped_ptr
<LayerImpl
> grand_child
=
2799 LayerImpl::Create(host_impl
.active_tree(), 3);
2800 scoped_ptr
<LayerImpl
> occluding_child
=
2801 LayerImpl::Create(host_impl
.active_tree(), 4);
2802 child
->SetDrawsContent(true);
2803 grand_child
->SetDrawsContent(true);
2804 occluding_child
->SetDrawsContent(true);
2805 occluding_child
->SetContentsOpaque(true);
2807 gfx::Transform identity_matrix
;
2808 gfx::Transform perspective
;
2809 perspective
.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
2811 gfx::Transform rotation
;
2812 rotation
.RotateAboutYAxis(45.0);
2814 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2815 gfx::PointF(), gfx::Size(1000, 1000), true,
2817 SetLayerPropertiesForTesting(child
.get(), perspective
, gfx::Point3F(),
2818 gfx::PointF(10.f
, 10.f
), gfx::Size(300, 300),
2819 false, true, false);
2820 SetLayerPropertiesForTesting(grand_child
.get(), rotation
, gfx::Point3F(),
2821 gfx::PointF(), gfx::Size(200, 200), false, true,
2823 SetLayerPropertiesForTesting(occluding_child
.get(), identity_matrix
,
2824 gfx::Point3F(), gfx::PointF(),
2825 gfx::Size(200, 200), false, false, false);
2827 host_impl
.SetViewportSize(root
->bounds());
2829 child
->AddChild(grand_child
.Pass());
2830 root
->AddChild(child
.Pass());
2831 root
->AddChild(occluding_child
.Pass());
2832 host_impl
.active_tree()->SetRootLayer(root
.Pass());
2833 host_impl
.InitializeRenderer(FakeOutputSurface::Create3d());
2834 bool update_lcd_text
= false;
2835 host_impl
.active_tree()->UpdateDrawProperties(update_lcd_text
);
2837 LayerImpl
* grand_child_ptr
=
2838 host_impl
.active_tree()->root_layer()->children()[0]->children()[0];
2840 // Though all layers have invertible transforms, matrix multiplication using
2841 // floating-point math makes the draw transform uninvertible.
2842 EXPECT_FALSE(grand_child_ptr
->draw_transform().IsInvertible());
2844 // Since |grand_child| has an uninvertible draw transform, it is treated as
2845 // unoccluded (even though |occluding_child| comes later in draw order, and
2846 // hence potentially occludes it).
2847 gfx::Rect layer_bounds
= gfx::Rect(grand_child_ptr
->bounds());
2850 grand_child_ptr
->draw_properties()
2851 .occlusion_in_content_space
.GetUnoccludedContentRect(layer_bounds
));
2854 TEST_F(LayerTreeHostCommonTest
,
2855 SingularTransformDoesNotPreventClearingDrawProperties
) {
2856 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2857 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2858 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2859 root
->AddChild(child
);
2861 host()->SetRootLayer(root
);
2863 gfx::Transform identity_matrix
;
2864 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2865 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2867 SetLayerPropertiesForTesting(root
.get(),
2868 uninvertible_matrix
,
2871 gfx::Size(100, 100),
2874 SetLayerPropertiesForTesting(child
.get(),
2877 gfx::PointF(5.f
, 5.f
),
2882 child
->set_sorted_for_recursion(true);
2884 TransformOperations start_transform_operations
;
2885 start_transform_operations
.AppendScale(1.f
, 0.f
, 0.f
);
2887 TransformOperations end_transform_operations
;
2888 end_transform_operations
.AppendScale(1.f
, 1.f
, 0.f
);
2890 AddAnimatedTransformToLayer(
2891 root
.get(), 10.0, start_transform_operations
, end_transform_operations
);
2893 EXPECT_TRUE(root
->TransformIsAnimating());
2895 ExecuteCalculateDrawProperties(root
.get());
2897 EXPECT_FALSE(child
->sorted_for_recursion());
2900 TEST_F(LayerTreeHostCommonTest
,
2901 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties
) {
2902 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2904 host()->SetRootLayer(root
);
2906 gfx::Transform identity_matrix
;
2907 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2908 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2910 SetLayerPropertiesForTesting(root
.get(),
2911 uninvertible_matrix
,
2914 gfx::Size(100, 100),
2918 root
->set_sorted_for_recursion(true);
2920 EXPECT_FALSE(root
->TransformIsAnimating());
2922 ExecuteCalculateDrawProperties(root
.get());
2924 EXPECT_FALSE(root
->sorted_for_recursion());
2927 TEST_F(LayerTreeHostCommonTest
,
2928 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface
) {
2929 LayerImpl
* root
= root_layer();
2930 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
2931 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
2932 child1
->SetDrawsContent(true);
2933 LayerImpl
* child2
= AddChild
<LayerImpl
>(render_surface
);
2934 child2
->SetDrawsContent(true);
2935 LayerImpl
* child3
= AddChild
<LayerImpl
>(render_surface
);
2936 child3
->SetDrawsContent(true);
2938 gfx::Transform identity_matrix
;
2939 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2940 gfx::PointF(), gfx::Size(100, 100), true, false,
2942 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
2943 gfx::PointF(), gfx::Size(3, 4), true, false,
2945 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
2946 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2948 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
2949 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2951 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
2952 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2953 true, false, false);
2955 root
->SetMasksToBounds(true);
2957 ExecuteCalculateDrawProperties(root
);
2959 ASSERT_TRUE(render_surface
->render_surface());
2961 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2962 root
->render_surface()->DrawableContentRect());
2963 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2965 // Layers that do not draw content should have empty visible content rects.
2966 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2967 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface
->visible_layer_rect());
2969 // A clipped surface grows its DrawableContentRect to include all drawable
2970 // regions of the subtree, but also gets clamped by the ancestor's clip.
2971 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
2972 render_surface
->render_surface()->DrawableContentRect());
2974 // All layers that draw content into the surface have their visible content
2975 // rect clipped by the surface clip rect.
2976 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
2977 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_layer_rect());
2978 EXPECT_TRUE(child3
->visible_layer_rect().IsEmpty());
2980 // But the DrawableContentRects are unclipped.
2981 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2982 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2983 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2986 TEST_F(LayerTreeHostCommonTest
,
2987 DrawableAndVisibleContentRectsForSurfaceHierarchy
) {
2988 // Check that clipping does not propagate down surfaces.
2989 LayerImpl
* root
= root_layer();
2990 LayerImpl
* render_surface1
= AddChildToRoot
<LayerImpl
>();
2991 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(render_surface1
);
2992 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface2
);
2993 child1
->SetDrawsContent(true);
2994 LayerImpl
* child2
= AddChild
<LayerImpl
>(render_surface2
);
2995 child2
->SetDrawsContent(true);
2996 LayerImpl
* child3
= AddChild
<LayerImpl
>(render_surface2
);
2997 child3
->SetDrawsContent(true);
2999 gfx::Transform identity_matrix
;
3000 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
3001 gfx::PointF(), gfx::Size(100, 100), true, false,
3003 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
3004 gfx::PointF(), gfx::Size(3, 4), true, false,
3006 SetLayerPropertiesForTesting(render_surface2
, identity_matrix
, gfx::Point3F(),
3007 gfx::PointF(), gfx::Size(7, 13), true, false,
3009 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
3010 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
3012 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
3013 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
3015 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
3016 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
3017 true, false, false);
3019 root
->SetMasksToBounds(true);
3021 ExecuteCalculateDrawProperties(root
);
3023 ASSERT_TRUE(render_surface1
->render_surface());
3024 ASSERT_TRUE(render_surface2
->render_surface());
3026 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3027 root
->render_surface()->DrawableContentRect());
3028 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3030 // Layers that do not draw content should have empty visible content rects.
3031 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
3032 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_layer_rect());
3033 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2
->visible_layer_rect());
3035 // A clipped surface grows its DrawableContentRect to include all drawable
3036 // regions of the subtree, but also gets clamped by the ancestor's clip.
3037 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3038 render_surface1
->render_surface()->DrawableContentRect());
3040 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3041 // is only implicitly clipped by render_surface1's content rect. So,
3042 // render_surface2 grows to enclose all drawable content of its subtree.
3043 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
3044 render_surface2
->render_surface()->DrawableContentRect());
3046 // All layers that draw content into render_surface2 think they are unclipped.
3047 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
3048 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_layer_rect());
3049 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_layer_rect());
3051 // DrawableContentRects are also unclipped.
3052 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
3053 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
3054 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
3057 TEST_F(LayerTreeHostCommonTest
,
3058 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface
) {
3059 // Layers that have non-axis aligned bounds (due to transforms) have an
3060 // expanded, axis-aligned DrawableContentRect and visible content rect.
3061 LayerImpl
* root
= root_layer();
3062 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
3063 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
3064 child1
->SetDrawsContent(true);
3066 gfx::Transform identity_matrix
;
3067 gfx::Transform child_rotation
;
3068 child_rotation
.Rotate(45.0);
3069 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
3070 gfx::PointF(), gfx::Size(100, 100), true, false,
3072 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
3073 gfx::PointF(), gfx::Size(3, 4), true, false,
3075 SetLayerPropertiesForTesting(
3076 child1
, child_rotation
, gfx::Point3F(25, 25, 0.f
),
3077 gfx::PointF(25.f
, 25.f
), gfx::Size(50, 50), true, false, false);
3079 ExecuteCalculateDrawProperties(root
);
3081 ASSERT_TRUE(render_surface
->render_surface());
3083 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3084 root
->render_surface()->DrawableContentRect());
3085 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3087 // Layers that do not draw content should have empty visible content rects.
3088 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
3089 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface
->visible_layer_rect());
3091 // The unclipped surface grows its DrawableContentRect to include all drawable
3092 // regions of the subtree.
3093 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3094 gfx::Rect expected_surface_drawable_content
=
3095 gfx::Rect(50 - diagonal_radius
,
3096 50 - diagonal_radius
,
3097 diagonal_radius
* 2,
3098 diagonal_radius
* 2);
3099 EXPECT_EQ(expected_surface_drawable_content
,
3100 render_surface
->render_surface()->DrawableContentRect());
3102 // All layers that draw content into the unclipped surface are also unclipped.
3103 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
3104 EXPECT_EQ(expected_surface_drawable_content
, child1
->drawable_content_rect());
3107 TEST_F(LayerTreeHostCommonTest
,
3108 DrawableAndVisibleContentRectsWithTransformOnClippedSurface
) {
3109 // Layers that have non-axis aligned bounds (due to transforms) have an
3110 // expanded, axis-aligned DrawableContentRect and visible content rect.
3111 LayerImpl
* root
= root_layer();
3112 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
3113 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
3114 child1
->SetDrawsContent(true);
3116 gfx::Transform identity_matrix
;
3117 gfx::Transform child_rotation
;
3118 child_rotation
.Rotate(45.0);
3119 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
3120 gfx::PointF(), gfx::Size(50, 50), true, false,
3122 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
3123 gfx::PointF(), gfx::Size(3, 4), true, false,
3126 SetLayerPropertiesForTesting(
3127 child1
, child_rotation
, gfx::Point3F(25, 25, 0.f
),
3128 gfx::PointF(25.f
, 25.f
), gfx::Size(50, 50), true, false, false);
3130 root
->SetMasksToBounds(true);
3132 ExecuteCalculateDrawProperties(root
);
3134 ASSERT_TRUE(render_surface
->render_surface());
3136 // The clipped surface clamps the DrawableContentRect that encloses the
3138 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3139 gfx::Rect unclipped_surface_content
= gfx::Rect(50 - diagonal_radius
,
3140 50 - diagonal_radius
,
3141 diagonal_radius
* 2,
3142 diagonal_radius
* 2);
3143 gfx::Rect expected_surface_drawable_content
=
3144 gfx::IntersectRects(unclipped_surface_content
, gfx::Rect(0, 0, 50, 50));
3145 EXPECT_EQ(expected_surface_drawable_content
,
3146 render_surface
->render_surface()->DrawableContentRect());
3148 // On the clipped surface, only a quarter of the child1 is visible, but when
3149 // rotating it back to child1's content space, the actual enclosing rect ends
3150 // up covering the full left half of child1.
3152 // Given the floating point math, this number is a little bit fuzzy.
3153 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1
->visible_layer_rect());
3155 // The child's DrawableContentRect is unclipped.
3156 EXPECT_EQ(unclipped_surface_content
, child1
->drawable_content_rect());
3159 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsInHighDPI
) {
3160 LayerImpl
* root
= root_layer();
3161 FakePictureLayerImpl
* render_surface1
=
3162 AddChildToRoot
<FakePictureLayerImpl
>();
3163 render_surface1
->SetDrawsContent(true);
3164 FakePictureLayerImpl
* render_surface2
=
3165 AddChild
<FakePictureLayerImpl
>(render_surface1
);
3166 render_surface2
->SetDrawsContent(true);
3167 FakePictureLayerImpl
* child1
=
3168 AddChild
<FakePictureLayerImpl
>(render_surface2
);
3169 child1
->SetDrawsContent(true);
3170 FakePictureLayerImpl
* child2
=
3171 AddChild
<FakePictureLayerImpl
>(render_surface2
);
3172 child2
->SetDrawsContent(true);
3173 FakePictureLayerImpl
* child3
=
3174 AddChild
<FakePictureLayerImpl
>(render_surface2
);
3175 child3
->SetDrawsContent(true);
3177 gfx::Transform identity_matrix
;
3178 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
3179 gfx::PointF(), gfx::Size(100, 100), true, false,
3181 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
3182 gfx::PointF(5.f
, 5.f
), gfx::Size(3, 4), true,
3184 SetLayerPropertiesForTesting(render_surface2
, identity_matrix
, gfx::Point3F(),
3185 gfx::PointF(5.f
, 5.f
), gfx::Size(7, 13), true,
3187 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
3188 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
3190 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
3191 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
3193 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
3194 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
3195 true, false, false);
3197 float device_scale_factor
= 2.f
;
3199 root
->SetMasksToBounds(true);
3201 ExecuteCalculateDrawProperties(root
, device_scale_factor
);
3203 ASSERT_TRUE(render_surface1
->render_surface());
3204 ASSERT_TRUE(render_surface2
->render_surface());
3206 // drawable_content_rects for all layers and surfaces are scaled by
3207 // device_scale_factor.
3208 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
3209 root
->render_surface()->DrawableContentRect());
3210 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root
->drawable_content_rect());
3211 EXPECT_EQ(gfx::Rect(10, 10, 190, 190),
3212 render_surface1
->render_surface()->DrawableContentRect());
3214 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3215 // is only implicitly clipped by render_surface1.
3216 EXPECT_EQ(gfx::Rect(10, 10, 350, 350),
3217 render_surface2
->render_surface()->DrawableContentRect());
3219 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1
->drawable_content_rect());
3220 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2
->drawable_content_rect());
3221 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3
->drawable_content_rect());
3223 // The root layer does not actually draw content of its own.
3224 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
3226 // All layer visible content rects are not expressed in content space of each
3227 // layer, so they are not scaled by the device_scale_factor.
3228 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1
->visible_layer_rect());
3229 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2
->visible_layer_rect());
3230 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
3231 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_layer_rect());
3232 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_layer_rect());
3235 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithoutPreserves3d
) {
3236 // Verify the behavior of back-face culling when there are no preserve-3d
3237 // layers. Note that 3d transforms still apply in this case, but they are
3238 // "flattened" to each parent layer according to current W3C spec.
3240 const gfx::Transform identity_matrix
;
3241 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3242 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3243 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3244 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3245 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3246 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3247 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3248 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3249 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3250 scoped_refptr
<LayerWithForcedDrawsContent
>
3251 front_facing_child_of_front_facing_surface
=
3252 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3253 scoped_refptr
<LayerWithForcedDrawsContent
>
3254 back_facing_child_of_front_facing_surface
=
3255 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3256 scoped_refptr
<LayerWithForcedDrawsContent
>
3257 front_facing_child_of_back_facing_surface
=
3258 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3259 scoped_refptr
<LayerWithForcedDrawsContent
>
3260 back_facing_child_of_back_facing_surface
=
3261 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3263 parent
->AddChild(front_facing_child
);
3264 parent
->AddChild(back_facing_child
);
3265 parent
->AddChild(front_facing_surface
);
3266 parent
->AddChild(back_facing_surface
);
3267 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3268 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3269 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3270 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3272 host()->SetRootLayer(parent
);
3274 // Nothing is double-sided
3275 front_facing_child
->SetDoubleSided(false);
3276 back_facing_child
->SetDoubleSided(false);
3277 front_facing_surface
->SetDoubleSided(false);
3278 back_facing_surface
->SetDoubleSided(false);
3279 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3280 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3281 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3282 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3284 gfx::Transform backface_matrix
;
3285 backface_matrix
.Translate(50.0, 50.0);
3286 backface_matrix
.RotateAboutYAxis(180.0);
3287 backface_matrix
.Translate(-50.0, -50.0);
3289 // Having a descendant and opacity will force these to have render surfaces.
3290 front_facing_surface
->SetOpacity(0.5f
);
3291 back_facing_surface
->SetOpacity(0.5f
);
3293 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3294 // these layers should blindly use their own local transforms to determine
3295 // back-face culling.
3296 SetLayerPropertiesForTesting(parent
.get(),
3300 gfx::Size(100, 100),
3303 SetLayerPropertiesForTesting(front_facing_child
.get(),
3307 gfx::Size(100, 100),
3310 SetLayerPropertiesForTesting(back_facing_child
.get(),
3314 gfx::Size(100, 100),
3317 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3321 gfx::Size(100, 100),
3324 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3328 gfx::Size(100, 100),
3331 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3335 gfx::Size(100, 100),
3338 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3342 gfx::Size(100, 100),
3345 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3349 gfx::Size(100, 100),
3352 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3356 gfx::Size(100, 100),
3360 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3362 // Verify which render surfaces were created.
3363 EXPECT_FALSE(front_facing_child
->render_surface());
3364 EXPECT_FALSE(back_facing_child
->render_surface());
3365 EXPECT_TRUE(front_facing_surface
->render_surface());
3366 EXPECT_TRUE(back_facing_surface
->render_surface());
3367 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3368 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3369 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3370 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3372 EXPECT_EQ(4u, update_layer_list().size());
3373 EXPECT_TRUE(UpdateLayerListContains(front_facing_child
->id()));
3374 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface
->id()));
3375 EXPECT_TRUE(UpdateLayerListContains(
3376 front_facing_child_of_front_facing_surface
->id()));
3378 UpdateLayerListContains(front_facing_child_of_back_facing_surface
->id()));
3381 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithPreserves3d
) {
3382 // Verify the behavior of back-face culling when preserves-3d transform style
3385 const gfx::Transform identity_matrix
;
3386 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3387 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3388 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3389 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3390 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3391 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3392 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3393 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3394 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3395 scoped_refptr
<LayerWithForcedDrawsContent
>
3396 front_facing_child_of_front_facing_surface
=
3397 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3398 scoped_refptr
<LayerWithForcedDrawsContent
>
3399 back_facing_child_of_front_facing_surface
=
3400 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3401 scoped_refptr
<LayerWithForcedDrawsContent
>
3402 front_facing_child_of_back_facing_surface
=
3403 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3404 scoped_refptr
<LayerWithForcedDrawsContent
>
3405 back_facing_child_of_back_facing_surface
=
3406 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3407 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer1
=
3408 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3409 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer2
=
3410 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3412 parent
->AddChild(front_facing_child
);
3413 parent
->AddChild(back_facing_child
);
3414 parent
->AddChild(front_facing_surface
);
3415 parent
->AddChild(back_facing_surface
);
3416 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3417 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3418 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3419 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3421 host()->SetRootLayer(parent
);
3423 // Nothing is double-sided
3424 front_facing_child
->SetDoubleSided(false);
3425 back_facing_child
->SetDoubleSided(false);
3426 front_facing_surface
->SetDoubleSided(false);
3427 back_facing_surface
->SetDoubleSided(false);
3428 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3429 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3430 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3431 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3433 gfx::Transform backface_matrix
;
3434 backface_matrix
.Translate(50.0, 50.0);
3435 backface_matrix
.RotateAboutYAxis(180.0);
3436 backface_matrix
.Translate(-50.0, -50.0);
3438 // Opacity will not force creation of render surfaces in this case because of
3439 // the preserve-3d transform style. Instead, an example of when a surface
3440 // would be created with preserve-3d is when there is a replica layer.
3441 front_facing_surface
->SetReplicaLayer(dummy_replica_layer1
.get());
3442 back_facing_surface
->SetReplicaLayer(dummy_replica_layer2
.get());
3444 // Each surface creates its own new 3d rendering context (as defined by W3C
3445 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3446 // rendering context should use the transform with respect to that context.
3447 // This 3d rendering context occurs when (a) parent's transform style is flat
3448 // and (b) the layer's transform style is preserve-3d.
3449 SetLayerPropertiesForTesting(parent
.get(),
3453 gfx::Size(100, 100),
3455 false); // parent transform style is flat.
3456 SetLayerPropertiesForTesting(front_facing_child
.get(),
3460 gfx::Size(100, 100),
3463 SetLayerPropertiesForTesting(back_facing_child
.get(),
3467 gfx::Size(100, 100),
3470 // surface transform style is preserve-3d.
3471 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3475 gfx::Size(100, 100),
3478 // surface transform style is preserve-3d.
3479 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3483 gfx::Size(100, 100),
3486 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3490 gfx::Size(100, 100),
3493 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3497 gfx::Size(100, 100),
3500 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3504 gfx::Size(100, 100),
3507 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3511 gfx::Size(100, 100),
3515 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3517 // Verify which render surfaces were created and used.
3518 EXPECT_FALSE(front_facing_child
->render_surface());
3519 EXPECT_FALSE(back_facing_child
->render_surface());
3520 EXPECT_TRUE(front_facing_surface
->render_surface());
3521 EXPECT_NE(back_facing_surface
->render_target(), back_facing_surface
);
3522 // We expect that a render_surface was created but not used.
3523 EXPECT_TRUE(back_facing_surface
->render_surface());
3524 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3525 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3526 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3527 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3529 EXPECT_EQ(3u, update_layer_list().size());
3531 EXPECT_TRUE(UpdateLayerListContains(front_facing_child
->id()));
3532 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface
->id()));
3533 EXPECT_TRUE(UpdateLayerListContains(
3534 front_facing_child_of_front_facing_surface
->id()));
3537 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithAnimatingTransforms
) {
3538 // Verify that layers are appropriately culled when their back face is showing
3539 // and they are not double sided, while animations are going on.
3541 // Layers that are animating do not get culled on the main thread, as their
3542 // transforms should be treated as "unknown" so we can not be sure that their
3543 // back face is really showing.
3544 const gfx::Transform identity_matrix
;
3545 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3546 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
3547 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3548 scoped_refptr
<LayerWithForcedDrawsContent
> animating_surface
=
3549 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3550 scoped_refptr
<LayerWithForcedDrawsContent
> child_of_animating_surface
=
3551 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3552 scoped_refptr
<LayerWithForcedDrawsContent
> animating_child
=
3553 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3554 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3555 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3557 parent
->AddChild(child
);
3558 parent
->AddChild(animating_surface
);
3559 animating_surface
->AddChild(child_of_animating_surface
);
3560 parent
->AddChild(animating_child
);
3561 parent
->AddChild(child2
);
3563 host()->SetRootLayer(parent
);
3565 // Nothing is double-sided
3566 child
->SetDoubleSided(false);
3567 child2
->SetDoubleSided(false);
3568 animating_surface
->SetDoubleSided(false);
3569 child_of_animating_surface
->SetDoubleSided(false);
3570 animating_child
->SetDoubleSided(false);
3572 gfx::Transform backface_matrix
;
3573 backface_matrix
.Translate(50.0, 50.0);
3574 backface_matrix
.RotateAboutYAxis(180.0);
3575 backface_matrix
.Translate(-50.0, -50.0);
3577 // Make our render surface.
3578 animating_surface
->SetForceRenderSurface(true);
3580 // Animate the transform on the render surface.
3581 AddAnimatedTransformToController(
3582 animating_surface
->layer_animation_controller(), 10.0, 30, 0);
3583 // This is just an animating layer, not a surface.
3584 AddAnimatedTransformToController(
3585 animating_child
->layer_animation_controller(), 10.0, 30, 0);
3587 SetLayerPropertiesForTesting(parent
.get(),
3591 gfx::Size(100, 100),
3594 SetLayerPropertiesForTesting(child
.get(),
3598 gfx::Size(100, 100),
3601 SetLayerPropertiesForTesting(animating_surface
.get(),
3605 gfx::Size(100, 100),
3608 SetLayerPropertiesForTesting(child_of_animating_surface
.get(),
3612 gfx::Size(100, 100),
3615 SetLayerPropertiesForTesting(animating_child
.get(),
3619 gfx::Size(100, 100),
3622 SetLayerPropertiesForTesting(child2
.get(),
3626 gfx::Size(100, 100),
3630 RenderSurfaceLayerList render_surface_layer_list
;
3631 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3632 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3633 inputs
.can_adjust_raster_scales
= true;
3634 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3636 EXPECT_FALSE(child
->render_surface());
3637 EXPECT_TRUE(animating_surface
->render_surface());
3638 EXPECT_FALSE(child_of_animating_surface
->render_surface());
3639 EXPECT_FALSE(animating_child
->render_surface());
3640 EXPECT_FALSE(child2
->render_surface());
3642 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3644 EXPECT_EQ(4u, update_layer_list().size());
3646 // The non-animating child be culled from the layer list for the parent render
3648 EXPECT_TRUE(UpdateLayerListContains(animating_surface
->id()));
3649 EXPECT_TRUE(UpdateLayerListContains(animating_child
->id()));
3650 EXPECT_TRUE(UpdateLayerListContains(child2
->id()));
3651 EXPECT_TRUE(UpdateLayerListContains(child_of_animating_surface
->id()));
3653 EXPECT_FALSE(child2
->visible_rect_from_property_trees().IsEmpty());
3655 // The animating layers should have a visible content rect that represents the
3656 // area of the front face that is within the viewport.
3657 EXPECT_EQ(animating_child
->visible_rect_from_property_trees(),
3658 gfx::Rect(animating_child
->bounds()));
3659 EXPECT_EQ(animating_surface
->visible_rect_from_property_trees(),
3660 gfx::Rect(animating_surface
->bounds()));
3661 // And layers in the subtree of the animating layer should have valid visible
3662 // content rects also.
3663 EXPECT_EQ(child_of_animating_surface
->visible_rect_from_property_trees(),
3664 gfx::Rect(child_of_animating_surface
->bounds()));
3667 TEST_F(LayerTreeHostCommonTest
,
3668 BackFaceCullingWithPreserves3dForFlatteningSurface
) {
3669 // Verify the behavior of back-face culling for a render surface that is
3670 // created when it flattens its subtree, and its parent has preserves-3d.
3672 const gfx::Transform identity_matrix
;
3673 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3674 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3675 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3676 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3677 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3678 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3679 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3680 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3681 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3683 parent
->AddChild(front_facing_surface
);
3684 parent
->AddChild(back_facing_surface
);
3685 front_facing_surface
->AddChild(child1
);
3686 back_facing_surface
->AddChild(child2
);
3688 host()->SetRootLayer(parent
);
3690 // RenderSurfaces are not double-sided
3691 front_facing_surface
->SetDoubleSided(false);
3692 back_facing_surface
->SetDoubleSided(false);
3694 gfx::Transform backface_matrix
;
3695 backface_matrix
.Translate(50.0, 50.0);
3696 backface_matrix
.RotateAboutYAxis(180.0);
3697 backface_matrix
.Translate(-50.0, -50.0);
3699 SetLayerPropertiesForTesting(parent
.get(),
3703 gfx::Size(100, 100),
3705 true); // parent transform style is preserve3d.
3706 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3710 gfx::Size(100, 100),
3712 true); // surface transform style is flat.
3713 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3717 gfx::Size(100, 100),
3719 true); // surface transform style is flat.
3720 SetLayerPropertiesForTesting(child1
.get(),
3724 gfx::Size(100, 100),
3727 SetLayerPropertiesForTesting(child2
.get(),
3731 gfx::Size(100, 100),
3735 front_facing_surface
->Set3dSortingContextId(1);
3736 back_facing_surface
->Set3dSortingContextId(1);
3738 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3740 // Verify which render surfaces were created and used.
3741 EXPECT_TRUE(front_facing_surface
->render_surface());
3743 // We expect the render surface to have been created, but remain unused.
3744 EXPECT_TRUE(back_facing_surface
->render_surface());
3745 EXPECT_NE(back_facing_surface
->render_target(),
3746 back_facing_surface
); // because it should be culled
3747 EXPECT_FALSE(child1
->render_surface());
3748 EXPECT_FALSE(child2
->render_surface());
3750 EXPECT_EQ(2u, update_layer_list().size());
3751 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface
->id()));
3752 EXPECT_TRUE(UpdateLayerListContains(child1
->id()));
3755 TEST_F(LayerTreeHostCommonScalingTest
, LayerTransformsInHighDPI
) {
3756 // Verify draw and screen space transforms of layers not in a surface.
3757 gfx::Transform identity_matrix
;
3759 LayerImpl
* parent
= root_layer();
3760 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
3761 gfx::PointF(), gfx::Size(100, 100), false, true,
3764 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
3765 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
3766 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3769 LayerImpl
* child_empty
= AddChildToRoot
<LayerImpl
>();
3770 SetLayerPropertiesForTesting(child_empty
, identity_matrix
, gfx::Point3F(),
3771 gfx::PointF(2.f
, 2.f
), gfx::Size(), false, true,
3774 float device_scale_factor
= 2.5f
;
3775 gfx::Size
viewport_size(100, 100);
3776 ExecuteCalculateDrawProperties(parent
, device_scale_factor
);
3778 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
, parent
);
3779 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
, child
);
3780 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
, child_empty
);
3782 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
3784 // Verify parent transforms
3785 gfx::Transform expected_parent_transform
;
3786 expected_parent_transform
.Scale(device_scale_factor
, device_scale_factor
);
3787 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
3788 parent
->screen_space_transform());
3789 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
3790 parent
->draw_transform());
3792 // Verify results of transformed parent rects
3793 gfx::RectF
parent_bounds(parent
->bounds());
3795 gfx::RectF parent_draw_rect
=
3796 MathUtil::MapClippedRect(parent
->draw_transform(), parent_bounds
);
3797 gfx::RectF parent_screen_space_rect
=
3798 MathUtil::MapClippedRect(parent
->screen_space_transform(), parent_bounds
);
3800 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
3801 expected_parent_draw_rect
.Scale(device_scale_factor
);
3802 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
3803 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
3805 // Verify child and child_empty transforms. They should match.
3806 gfx::Transform expected_child_transform
;
3807 expected_child_transform
.Scale(device_scale_factor
, device_scale_factor
);
3808 expected_child_transform
.Translate(child
->position().x(),
3809 child
->position().y());
3810 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3811 child
->draw_transform());
3812 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3813 child
->screen_space_transform());
3814 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3815 child_empty
->draw_transform());
3816 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3817 child_empty
->screen_space_transform());
3819 // Verify results of transformed child and child_empty rects. They should
3821 gfx::RectF
child_bounds(child
->bounds());
3823 gfx::RectF child_draw_rect
=
3824 MathUtil::MapClippedRect(child
->draw_transform(), child_bounds
);
3825 gfx::RectF child_screen_space_rect
=
3826 MathUtil::MapClippedRect(child
->screen_space_transform(), child_bounds
);
3828 gfx::RectF child_empty_draw_rect
=
3829 MathUtil::MapClippedRect(child_empty
->draw_transform(), child_bounds
);
3830 gfx::RectF child_empty_screen_space_rect
= MathUtil::MapClippedRect(
3831 child_empty
->screen_space_transform(), child_bounds
);
3833 gfx::RectF
expected_child_draw_rect(child
->position(), child
->bounds());
3834 expected_child_draw_rect
.Scale(device_scale_factor
);
3835 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
3836 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
3837 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_draw_rect
);
3838 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_screen_space_rect
);
3841 TEST_F(LayerTreeHostCommonScalingTest
, SurfaceLayerTransformsInHighDPI
) {
3842 // Verify draw and screen space transforms of layers in a surface.
3843 gfx::Transform identity_matrix
;
3844 gfx::Transform perspective_matrix
;
3845 perspective_matrix
.ApplyPerspectiveDepth(2.0);
3847 gfx::Transform scale_small_matrix
;
3848 scale_small_matrix
.Scale(SK_MScalar1
/ 10.f
, SK_MScalar1
/ 12.f
);
3850 LayerImpl
* root
= root_layer();
3851 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
3852 gfx::PointF(), gfx::Size(100, 100), false, true,
3854 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
3855 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
3856 gfx::PointF(), gfx::Size(100, 100), false, true,
3859 LayerImpl
* perspective_surface
= AddChild
<LayerImpl
>(parent
);
3860 SetLayerPropertiesForTesting(perspective_surface
,
3861 perspective_matrix
* scale_small_matrix
,
3862 gfx::Point3F(), gfx::PointF(2.f
, 2.f
),
3863 gfx::Size(10, 10), false, true, true);
3864 perspective_surface
->SetDrawsContent(true);
3866 LayerImpl
* scale_surface
= AddChild
<LayerImpl
>(parent
);
3867 SetLayerPropertiesForTesting(scale_surface
, scale_small_matrix
,
3868 gfx::Point3F(), gfx::PointF(2.f
, 2.f
),
3869 gfx::Size(10, 10), false, true, true);
3870 scale_surface
->SetDrawsContent(true);
3872 float device_scale_factor
= 2.5f
;
3873 float page_scale_factor
= 3.f
;
3874 ExecuteCalculateDrawProperties(root
, device_scale_factor
, page_scale_factor
,
3877 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
3878 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
,
3879 perspective_surface
);
3880 // Ideal scale is the max 2d scale component of the combined transform up to
3881 // the nearest render target. Here this includes the layer transform as well
3882 // as the device and page scale factors.
3883 gfx::Transform transform
= scale_small_matrix
;
3884 transform
.Scale(device_scale_factor
* page_scale_factor
,
3885 device_scale_factor
* page_scale_factor
);
3886 gfx::Vector2dF scales
=
3887 MathUtil::ComputeTransform2dScaleComponents(transform
, 0.f
);
3888 float max_2d_scale
= std::max(scales
.x(), scales
.y());
3889 EXPECT_IDEAL_SCALE_EQ(max_2d_scale
, scale_surface
);
3891 // The ideal scale will draw 1:1 with its render target space along
3892 // the larger-scale axis.
3893 gfx::Vector2dF target_space_transform_scales
=
3894 MathUtil::ComputeTransform2dScaleComponents(
3895 scale_surface
->draw_properties().target_space_transform
, 0.f
);
3896 EXPECT_FLOAT_EQ(max_2d_scale
,
3897 std::max(target_space_transform_scales
.x(),
3898 target_space_transform_scales
.y()));
3900 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
3902 gfx::Transform expected_parent_draw_transform
;
3903 expected_parent_draw_transform
.Scale(device_scale_factor
* page_scale_factor
,
3904 device_scale_factor
* page_scale_factor
);
3905 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform
,
3906 parent
->draw_transform());
3908 // The scale for the perspective surface is not known, so it is rendered 1:1
3909 // with the screen, and then scaled during drawing.
3910 gfx::Transform expected_perspective_surface_draw_transform
;
3911 expected_perspective_surface_draw_transform
.Translate(
3912 device_scale_factor
* page_scale_factor
*
3913 perspective_surface
->position().x(),
3914 device_scale_factor
* page_scale_factor
*
3915 perspective_surface
->position().y());
3916 expected_perspective_surface_draw_transform
.PreconcatTransform(
3917 perspective_matrix
);
3918 expected_perspective_surface_draw_transform
.PreconcatTransform(
3919 scale_small_matrix
);
3920 gfx::Transform expected_perspective_surface_layer_draw_transform
;
3921 expected_perspective_surface_layer_draw_transform
.Scale(
3922 device_scale_factor
* page_scale_factor
,
3923 device_scale_factor
* page_scale_factor
);
3924 EXPECT_TRANSFORMATION_MATRIX_EQ(
3925 expected_perspective_surface_draw_transform
,
3926 perspective_surface
->render_surface()->draw_transform());
3927 EXPECT_TRANSFORMATION_MATRIX_EQ(
3928 expected_perspective_surface_layer_draw_transform
,
3929 perspective_surface
->draw_transform());
3932 TEST_F(LayerTreeHostCommonScalingTest
, SmallIdealScale
) {
3933 gfx::Transform parent_scale_matrix
;
3934 SkMScalar initial_parent_scale
= 1.75;
3935 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
3937 gfx::Transform child_scale_matrix
;
3938 SkMScalar initial_child_scale
= 0.25;
3939 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
3941 LayerImpl
* root
= root_layer();
3942 root
->SetBounds(gfx::Size(100, 100));
3944 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
3945 SetLayerPropertiesForTesting(parent
, parent_scale_matrix
, gfx::Point3F(),
3946 gfx::PointF(), gfx::Size(100, 100), false, true,
3949 LayerImpl
* child_scale
= AddChild
<LayerImpl
>(parent
);
3950 SetLayerPropertiesForTesting(child_scale
, child_scale_matrix
, gfx::Point3F(),
3951 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3954 float device_scale_factor
= 2.5f
;
3955 float page_scale_factor
= 0.01f
;
3958 ExecuteCalculateDrawProperties(root
, device_scale_factor
, page_scale_factor
,
3961 // The ideal scale is able to go below 1.
3962 float expected_ideal_scale
=
3963 device_scale_factor
* page_scale_factor
* initial_parent_scale
;
3964 EXPECT_LT(expected_ideal_scale
, 1.f
);
3965 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, parent
);
3967 expected_ideal_scale
= device_scale_factor
* page_scale_factor
*
3968 initial_parent_scale
* initial_child_scale
;
3969 EXPECT_LT(expected_ideal_scale
, 1.f
);
3970 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, child_scale
);
3974 TEST_F(LayerTreeHostCommonScalingTest
, IdealScaleForAnimatingLayer
) {
3975 gfx::Transform parent_scale_matrix
;
3976 SkMScalar initial_parent_scale
= 1.75;
3977 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
3979 gfx::Transform child_scale_matrix
;
3980 SkMScalar initial_child_scale
= 1.25;
3981 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
3983 LayerImpl
* root
= root_layer();
3984 root
->SetBounds(gfx::Size(100, 100));
3986 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
3987 SetLayerPropertiesForTesting(parent
, parent_scale_matrix
, gfx::Point3F(),
3988 gfx::PointF(), gfx::Size(100, 100), false, true,
3991 LayerImpl
* child_scale
= AddChild
<LayerImpl
>(parent
);
3992 SetLayerPropertiesForTesting(child_scale
, child_scale_matrix
, gfx::Point3F(),
3993 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3997 ExecuteCalculateDrawProperties(root
);
3999 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale
, parent
);
4000 // Animating layers compute ideal scale in the same way as when
4002 EXPECT_IDEAL_SCALE_EQ(initial_child_scale
* initial_parent_scale
,
4007 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceTransformsInHighDPI
) {
4008 gfx::Transform identity_matrix
;
4010 LayerImpl
* parent
= root_layer();
4011 parent
->SetDrawsContent(true);
4012 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
4013 gfx::PointF(), gfx::Size(30, 30), false, true,
4016 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
4017 child
->SetDrawsContent(true);
4018 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
4019 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
4022 gfx::Transform replica_transform
;
4023 replica_transform
.Scale(1.0, -1.0);
4025 scoped_ptr
<LayerImpl
> replica
=
4026 LayerImpl::Create(host_impl()->active_tree(), 7);
4027 SetLayerPropertiesForTesting(replica
.get(), replica_transform
, gfx::Point3F(),
4028 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
4030 child
->SetReplicaLayer(replica
.Pass());
4032 // This layer should end up in the same surface as child, with the same draw
4033 // and screen space transforms.
4034 LayerImpl
* duplicate_child_non_owner
= AddChild
<LayerImpl
>(child
);
4035 duplicate_child_non_owner
->SetDrawsContent(true);
4036 SetLayerPropertiesForTesting(duplicate_child_non_owner
, identity_matrix
,
4037 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4038 false, true, false);
4040 float device_scale_factor
= 1.5f
;
4041 ExecuteCalculateDrawProperties(parent
, device_scale_factor
);
4043 // We should have two render surfaces. The root's render surface and child's
4044 // render surface (it needs one because it has a replica layer).
4045 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
4047 gfx::Transform expected_parent_transform
;
4048 expected_parent_transform
.Scale(device_scale_factor
, device_scale_factor
);
4049 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4050 parent
->screen_space_transform());
4051 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4052 parent
->draw_transform());
4054 gfx::Transform expected_draw_transform
;
4055 expected_draw_transform
.Scale(device_scale_factor
, device_scale_factor
);
4056 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform
,
4057 child
->draw_transform());
4059 gfx::Transform expected_screen_space_transform
;
4060 expected_screen_space_transform
.Scale(device_scale_factor
,
4061 device_scale_factor
);
4062 expected_screen_space_transform
.Translate(child
->position().x(),
4063 child
->position().y());
4064 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform
,
4065 child
->screen_space_transform());
4067 gfx::Transform expected_duplicate_child_draw_transform
=
4068 child
->draw_transform();
4069 EXPECT_TRANSFORMATION_MATRIX_EQ(child
->draw_transform(),
4070 duplicate_child_non_owner
->draw_transform());
4071 EXPECT_TRANSFORMATION_MATRIX_EQ(
4072 child
->screen_space_transform(),
4073 duplicate_child_non_owner
->screen_space_transform());
4074 EXPECT_EQ(child
->drawable_content_rect(),
4075 duplicate_child_non_owner
->drawable_content_rect());
4076 EXPECT_EQ(child
->bounds(), duplicate_child_non_owner
->bounds());
4078 gfx::Transform expected_render_surface_draw_transform
;
4079 expected_render_surface_draw_transform
.Translate(
4080 device_scale_factor
* child
->position().x(),
4081 device_scale_factor
* child
->position().y());
4082 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform
,
4083 child
->render_surface()->draw_transform());
4085 gfx::Transform expected_surface_draw_transform
;
4086 expected_surface_draw_transform
.Translate(device_scale_factor
* 2.f
,
4087 device_scale_factor
* 2.f
);
4088 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform
,
4089 child
->render_surface()->draw_transform());
4091 gfx::Transform expected_surface_screen_space_transform
;
4092 expected_surface_screen_space_transform
.Translate(device_scale_factor
* 2.f
,
4093 device_scale_factor
* 2.f
);
4094 EXPECT_TRANSFORMATION_MATRIX_EQ(
4095 expected_surface_screen_space_transform
,
4096 child
->render_surface()->screen_space_transform());
4098 gfx::Transform expected_replica_draw_transform
;
4099 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
4100 expected_replica_draw_transform
.matrix().set(0, 3, 6.0);
4101 expected_replica_draw_transform
.matrix().set(1, 3, 6.0);
4102 EXPECT_TRANSFORMATION_MATRIX_EQ(
4103 expected_replica_draw_transform
,
4104 child
->render_surface()->replica_draw_transform());
4106 gfx::Transform expected_replica_screen_space_transform
;
4107 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
4108 expected_replica_screen_space_transform
.matrix().set(0, 3, 6.0);
4109 expected_replica_screen_space_transform
.matrix().set(1, 3, 6.0);
4110 EXPECT_TRANSFORMATION_MATRIX_EQ(
4111 expected_replica_screen_space_transform
,
4112 child
->render_surface()->replica_screen_space_transform());
4113 EXPECT_TRANSFORMATION_MATRIX_EQ(
4114 expected_replica_screen_space_transform
,
4115 child
->render_surface()->replica_screen_space_transform());
4118 TEST_F(LayerTreeHostCommonTest
,
4119 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition
) {
4120 gfx::Transform identity_matrix
;
4122 LayerImpl
* parent
= root_layer();
4123 parent
->SetDrawsContent(true);
4124 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
4125 gfx::PointF(), gfx::Size(33, 31), false, true,
4128 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
4129 child
->SetDrawsContent(true);
4130 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
4131 gfx::PointF(), gfx::Size(13, 11), false, true,
4134 gfx::Transform replica_transform
;
4135 replica_transform
.Scale(1.0, -1.0);
4136 scoped_ptr
<LayerImpl
> replica
=
4137 LayerImpl::Create(host_impl()->active_tree(), 7);
4138 SetLayerPropertiesForTesting(replica
.get(), replica_transform
, gfx::Point3F(),
4139 gfx::PointF(), gfx::Size(13, 11), false, true,
4141 child
->SetReplicaLayer(replica
.Pass());
4143 float device_scale_factor
= 1.7f
;
4144 ExecuteCalculateDrawProperties(parent
, device_scale_factor
);
4146 // We should have two render surfaces. The root's render surface and child's
4147 // render surface (it needs one because it has a replica layer).
4148 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
4150 gfx::Transform identity_transform
;
4151 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
4152 child
->render_surface()->draw_transform());
4153 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
4154 child
->render_surface()->draw_transform());
4155 EXPECT_TRANSFORMATION_MATRIX_EQ(
4156 identity_transform
, child
->render_surface()->screen_space_transform());
4158 gfx::Transform expected_replica_draw_transform
;
4159 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
4160 EXPECT_TRANSFORMATION_MATRIX_EQ(
4161 expected_replica_draw_transform
,
4162 child
->render_surface()->replica_draw_transform());
4164 gfx::Transform expected_replica_screen_space_transform
;
4165 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
4166 EXPECT_TRANSFORMATION_MATRIX_EQ(
4167 expected_replica_screen_space_transform
,
4168 child
->render_surface()->replica_screen_space_transform());
4171 TEST_F(LayerTreeHostCommonTest
, SubtreeSearch
) {
4172 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4173 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
4174 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
4175 scoped_refptr
<Layer
> mask_layer
= Layer::Create(layer_settings());
4176 scoped_refptr
<Layer
> replica_layer
= Layer::Create(layer_settings());
4178 grand_child
->SetReplicaLayer(replica_layer
.get());
4179 child
->AddChild(grand_child
.get());
4180 child
->SetMaskLayer(mask_layer
.get());
4181 root
->AddChild(child
.get());
4183 host()->SetRootLayer(root
);
4185 int nonexistent_id
= -1;
4186 EXPECT_EQ(root
.get(),
4187 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), root
->id()));
4188 EXPECT_EQ(child
.get(),
4189 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), child
->id()));
4192 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), grand_child
->id()));
4195 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), mask_layer
->id()));
4197 replica_layer
.get(),
4198 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), replica_layer
->id()));
4200 0, LayerTreeHostCommon::FindLayerInSubtree(root
.get(), nonexistent_id
));
4203 TEST_F(LayerTreeHostCommonTest
, TransparentChildRenderSurfaceCreation
) {
4204 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4205 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
4206 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
4207 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4209 const gfx::Transform identity_matrix
;
4210 SetLayerPropertiesForTesting(root
.get(),
4214 gfx::Size(100, 100),
4217 SetLayerPropertiesForTesting(child
.get(),
4224 SetLayerPropertiesForTesting(grand_child
.get(),
4232 root
->AddChild(child
);
4233 child
->AddChild(grand_child
);
4234 child
->SetOpacity(0.5f
);
4236 host()->SetRootLayer(root
);
4238 ExecuteCalculateDrawProperties(root
.get());
4240 EXPECT_FALSE(child
->render_surface());
4243 TEST_F(LayerTreeHostCommonTest
, OpacityAnimatingOnPendingTree
) {
4244 FakeImplProxy proxy
;
4245 TestSharedBitmapManager shared_bitmap_manager
;
4246 TestTaskGraphRunner task_graph_runner
;
4247 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4248 &task_graph_runner
);
4249 host_impl
.CreatePendingTree();
4250 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4252 const gfx::Transform identity_matrix
;
4253 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4254 gfx::PointF(), gfx::Size(100, 100), true, false,
4256 root
->SetDrawsContent(true);
4258 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
4259 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
4260 gfx::PointF(), gfx::Size(50, 50), true, false,
4262 child
->SetDrawsContent(true);
4263 child
->SetOpacity(0.0f
);
4265 // Add opacity animation.
4266 AddOpacityTransitionToController(
4267 child
->layer_animation_controller(), 10.0, 0.0f
, 1.0f
, false);
4269 root
->AddChild(child
.Pass());
4270 root
->SetHasRenderSurface(true);
4272 LayerImplList render_surface_layer_list
;
4273 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4274 root
.get(), root
->bounds(), &render_surface_layer_list
);
4275 inputs
.can_adjust_raster_scales
= true;
4276 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4278 // We should have one render surface and two layers. The child
4279 // layer should be included even though it is transparent.
4280 ASSERT_EQ(1u, render_surface_layer_list
.size());
4281 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
4284 using LCDTextTestParam
= std::tr1::tuple
<bool, bool, bool>;
4285 class LCDTextTest
: public LayerTreeHostCommonTestBase
,
4286 public testing::TestWithParam
<LCDTextTestParam
> {
4289 : LayerTreeHostCommonTestBase(LayerTreeSettings()),
4290 host_impl_(&proxy_
, &shared_bitmap_manager_
, &task_graph_runner_
),
4293 grand_child_(nullptr) {}
4296 void SetUp() override
{
4297 can_use_lcd_text_
= std::tr1::get
<0>(GetParam());
4298 layers_always_allowed_lcd_text_
= std::tr1::get
<1>(GetParam());
4300 scoped_ptr
<LayerImpl
> root_ptr
=
4301 LayerImpl::Create(host_impl_
.active_tree(), 1);
4302 scoped_ptr
<LayerImpl
> child_ptr
=
4303 LayerImpl::Create(host_impl_
.active_tree(), 2);
4304 scoped_ptr
<LayerImpl
> grand_child_ptr
=
4305 LayerImpl::Create(host_impl_
.active_tree(), 3);
4307 // Stash raw pointers to look at later.
4308 root_
= root_ptr
.get();
4309 child_
= child_ptr
.get();
4310 grand_child_
= grand_child_ptr
.get();
4312 child_
->AddChild(grand_child_ptr
.Pass());
4313 root_
->AddChild(child_ptr
.Pass());
4314 host_impl_
.active_tree()->SetRootLayer(root_ptr
.Pass());
4316 root_
->SetContentsOpaque(true);
4317 child_
->SetContentsOpaque(true);
4318 grand_child_
->SetContentsOpaque(true);
4320 root_
->SetDrawsContent(true);
4321 child_
->SetDrawsContent(true);
4322 grand_child_
->SetDrawsContent(true);
4324 gfx::Transform identity_matrix
;
4325 SetLayerPropertiesForTesting(root_
, identity_matrix
, gfx::Point3F(),
4326 gfx::PointF(), gfx::Size(1, 1), true, false,
4328 SetLayerPropertiesForTesting(child_
, identity_matrix
, gfx::Point3F(),
4329 gfx::PointF(), gfx::Size(1, 1), true, false,
4330 std::tr1::get
<2>(GetParam()));
4331 SetLayerPropertiesForTesting(grand_child_
, identity_matrix
, gfx::Point3F(),
4332 gfx::PointF(), gfx::Size(1, 1), true, false,
4336 bool can_use_lcd_text_
;
4337 bool layers_always_allowed_lcd_text_
;
4339 FakeImplProxy proxy_
;
4340 TestSharedBitmapManager shared_bitmap_manager_
;
4341 TestTaskGraphRunner task_graph_runner_
;
4342 FakeLayerTreeHostImpl host_impl_
;
4346 LayerImpl
* grand_child_
;
4349 TEST_P(LCDTextTest
, CanUseLCDText
) {
4350 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
4351 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
4353 // Case 1: Identity transform.
4354 gfx::Transform identity_matrix
;
4355 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4356 layers_always_allowed_lcd_text_
);
4357 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4358 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4359 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4361 // Case 2: Integral translation.
4362 gfx::Transform integral_translation
;
4363 integral_translation
.Translate(1.0, 2.0);
4364 child_
->SetTransform(integral_translation
);
4365 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4366 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4367 layers_always_allowed_lcd_text_
);
4368 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4369 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4370 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4372 // Case 3: Non-integral translation.
4373 gfx::Transform non_integral_translation
;
4374 non_integral_translation
.Translate(1.5, 2.5);
4375 child_
->SetTransform(non_integral_translation
);
4376 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4377 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4378 layers_always_allowed_lcd_text_
);
4379 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4380 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4381 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4383 // Case 4: Rotation.
4384 gfx::Transform rotation
;
4385 rotation
.Rotate(10.0);
4386 child_
->SetTransform(rotation
);
4387 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4388 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4389 layers_always_allowed_lcd_text_
);
4390 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4391 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4392 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4395 gfx::Transform scale
;
4396 scale
.Scale(2.0, 2.0);
4397 child_
->SetTransform(scale
);
4398 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4399 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4400 layers_always_allowed_lcd_text_
);
4401 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4402 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4403 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4406 gfx::Transform skew
;
4408 child_
->SetTransform(skew
);
4409 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4410 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4411 layers_always_allowed_lcd_text_
);
4412 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4413 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4414 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4416 // Case 7: Translucent.
4417 child_
->SetTransform(identity_matrix
);
4418 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4419 child_
->SetOpacity(0.5f
);
4420 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4421 layers_always_allowed_lcd_text_
);
4422 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4423 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4424 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4426 // Case 8: Sanity check: restore transform and opacity.
4427 child_
->SetTransform(identity_matrix
);
4428 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4429 child_
->SetOpacity(1.f
);
4430 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4431 layers_always_allowed_lcd_text_
);
4432 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4433 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4434 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4436 // Case 9: Non-opaque content.
4437 child_
->SetContentsOpaque(false);
4438 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4439 layers_always_allowed_lcd_text_
);
4440 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4441 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4442 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4444 // Case 10: Sanity check: restore content opaqueness.
4445 child_
->SetContentsOpaque(true);
4446 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4447 layers_always_allowed_lcd_text_
);
4448 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4449 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4450 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4453 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimation
) {
4454 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
4455 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
4457 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
4458 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4459 layers_always_allowed_lcd_text_
);
4460 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4461 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4462 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4464 // Add opacity animation.
4465 child_
->SetOpacity(0.9f
);
4466 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4467 AddOpacityTransitionToController(
4468 child_
->layer_animation_controller(), 10.0, 0.9f
, 0.1f
, false);
4470 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4471 layers_always_allowed_lcd_text_
);
4472 // Text LCD should be adjusted while animation is active.
4473 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4474 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4475 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4478 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimationContentsOpaque
) {
4479 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
4480 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
4482 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
4483 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4484 layers_always_allowed_lcd_text_
);
4485 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4486 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4487 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4489 // Mark contents non-opaque within the first animation frame.
4490 child_
->SetContentsOpaque(false);
4491 AddOpacityTransitionToController(child_
->layer_animation_controller(), 10.0,
4494 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4495 layers_always_allowed_lcd_text_
);
4496 // LCD text should be disabled for non-opaque layers even during animations.
4497 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4498 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4499 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4502 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest
,
4504 testing::Combine(testing::Bool(),
4508 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayerImpl
) {
4509 FakeImplProxy proxy
;
4510 TestSharedBitmapManager shared_bitmap_manager
;
4511 TestTaskGraphRunner task_graph_runner
;
4512 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4513 &task_graph_runner
);
4514 host_impl
.CreatePendingTree();
4515 const gfx::Transform identity_matrix
;
4517 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4518 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4519 gfx::PointF(), gfx::Size(50, 50), true, false,
4521 root
->SetDrawsContent(true);
4523 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
4524 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
4525 gfx::PointF(), gfx::Size(40, 40), true, false,
4527 child
->SetDrawsContent(true);
4529 scoped_ptr
<LayerImpl
> grand_child
=
4530 LayerImpl::Create(host_impl
.pending_tree(), 3);
4531 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
4532 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4533 true, false, false);
4534 grand_child
->SetDrawsContent(true);
4535 grand_child
->SetHideLayerAndSubtree(true);
4537 child
->AddChild(grand_child
.Pass());
4538 root
->AddChild(child
.Pass());
4539 root
->SetHasRenderSurface(true);
4541 LayerImplList render_surface_layer_list
;
4542 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4543 root
.get(), root
->bounds(), &render_surface_layer_list
);
4544 inputs
.can_adjust_raster_scales
= true;
4545 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4547 // We should have one render surface and two layers. The grand child has
4549 ASSERT_EQ(1u, render_surface_layer_list
.size());
4550 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
4551 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
4552 EXPECT_EQ(2, root
->render_surface()->layer_list().at(1)->id());
4555 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayersImpl
) {
4556 FakeImplProxy proxy
;
4557 TestSharedBitmapManager shared_bitmap_manager
;
4558 TestTaskGraphRunner task_graph_runner
;
4559 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4560 &task_graph_runner
);
4561 host_impl
.CreatePendingTree();
4562 const gfx::Transform identity_matrix
;
4564 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4565 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4566 gfx::PointF(), gfx::Size(50, 50), true, false,
4568 root
->SetDrawsContent(true);
4570 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
4571 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
4572 gfx::PointF(), gfx::Size(40, 40), true, false,
4574 child
->SetDrawsContent(true);
4575 child
->SetHideLayerAndSubtree(true);
4577 scoped_ptr
<LayerImpl
> grand_child
=
4578 LayerImpl::Create(host_impl
.pending_tree(), 3);
4579 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
4580 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4581 true, false, false);
4582 grand_child
->SetDrawsContent(true);
4584 child
->AddChild(grand_child
.Pass());
4585 root
->AddChild(child
.Pass());
4587 LayerImplList render_surface_layer_list
;
4588 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4589 root
.get(), root
->bounds(), &render_surface_layer_list
);
4590 inputs
.can_adjust_raster_scales
= true;
4591 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4593 // We should have one render surface and one layers. The child has
4594 // hidden itself and the grand child.
4595 ASSERT_EQ(1u, render_surface_layer_list
.size());
4596 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
4597 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
4600 void EmptyCopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {}
4602 TEST_F(LayerTreeHostCommonTest
, SubtreeHiddenWithCopyRequest
) {
4603 FakeImplProxy proxy
;
4604 TestSharedBitmapManager shared_bitmap_manager
;
4605 TestTaskGraphRunner task_graph_runner
;
4606 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4607 &task_graph_runner
);
4608 host_impl
.CreatePendingTree();
4609 const gfx::Transform identity_matrix
;
4611 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4612 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4613 gfx::PointF(), gfx::Size(50, 50), true, false,
4615 root
->SetDrawsContent(true);
4617 scoped_ptr
<LayerImpl
> copy_grand_parent
=
4618 LayerImpl::Create(host_impl
.pending_tree(), 2);
4619 SetLayerPropertiesForTesting(copy_grand_parent
.get(), identity_matrix
,
4620 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
4621 true, false, false);
4622 copy_grand_parent
->SetDrawsContent(true);
4623 LayerImpl
* copy_grand_parent_layer
= copy_grand_parent
.get();
4625 scoped_ptr
<LayerImpl
> copy_parent
=
4626 LayerImpl::Create(host_impl
.pending_tree(), 3);
4627 SetLayerPropertiesForTesting(copy_parent
.get(), identity_matrix
,
4628 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4630 copy_parent
->SetDrawsContent(true);
4631 LayerImpl
* copy_parent_layer
= copy_parent
.get();
4633 scoped_ptr
<LayerImpl
> copy_request
=
4634 LayerImpl::Create(host_impl
.pending_tree(), 4);
4635 SetLayerPropertiesForTesting(copy_request
.get(), identity_matrix
,
4636 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4638 copy_request
->SetDrawsContent(true);
4639 LayerImpl
* copy_layer
= copy_request
.get();
4641 scoped_ptr
<LayerImpl
> copy_child
=
4642 LayerImpl::Create(host_impl
.pending_tree(), 5);
4643 SetLayerPropertiesForTesting(copy_child
.get(), identity_matrix
,
4644 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4645 true, false, false);
4646 copy_child
->SetDrawsContent(true);
4647 LayerImpl
* copy_child_layer
= copy_child
.get();
4649 scoped_ptr
<LayerImpl
> copy_grand_parent_sibling_before
=
4650 LayerImpl::Create(host_impl
.pending_tree(), 6);
4651 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before
.get(),
4652 identity_matrix
, gfx::Point3F(), gfx::PointF(),
4653 gfx::Size(40, 40), true, false, false);
4654 copy_grand_parent_sibling_before
->SetDrawsContent(true);
4655 LayerImpl
* copy_grand_parent_sibling_before_layer
=
4656 copy_grand_parent_sibling_before
.get();
4658 scoped_ptr
<LayerImpl
> copy_grand_parent_sibling_after
=
4659 LayerImpl::Create(host_impl
.pending_tree(), 7);
4660 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after
.get(),
4661 identity_matrix
, gfx::Point3F(), gfx::PointF(),
4662 gfx::Size(40, 40), true, false, false);
4663 copy_grand_parent_sibling_after
->SetDrawsContent(true);
4664 LayerImpl
* copy_grand_parent_sibling_after_layer
=
4665 copy_grand_parent_sibling_after
.get();
4667 copy_request
->AddChild(copy_child
.Pass());
4668 copy_parent
->AddChild(copy_request
.Pass());
4669 copy_grand_parent
->AddChild(copy_parent
.Pass());
4670 root
->AddChild(copy_grand_parent_sibling_before
.Pass());
4671 root
->AddChild(copy_grand_parent
.Pass());
4672 root
->AddChild(copy_grand_parent_sibling_after
.Pass());
4674 // Hide the copy_grand_parent and its subtree. But make a copy request in that
4675 // hidden subtree on copy_layer.
4676 copy_grand_parent_layer
->SetHideLayerAndSubtree(true);
4677 copy_grand_parent_sibling_before_layer
->SetHideLayerAndSubtree(true);
4678 copy_grand_parent_sibling_after_layer
->SetHideLayerAndSubtree(true);
4680 ScopedPtrVector
<CopyOutputRequest
> copy_requests
;
4681 copy_requests
.push_back(
4682 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback
)));
4683 copy_layer
->PassCopyRequests(©_requests
);
4684 EXPECT_TRUE(copy_layer
->HasCopyRequest());
4686 LayerImplList render_surface_layer_list
;
4687 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4688 root
.get(), root
->bounds(), &render_surface_layer_list
);
4689 inputs
.can_adjust_raster_scales
= true;
4690 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4692 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
4693 EXPECT_TRUE(copy_grand_parent_layer
->draw_properties()
4694 .layer_or_descendant_has_copy_request
);
4695 EXPECT_TRUE(copy_parent_layer
->draw_properties()
4696 .layer_or_descendant_has_copy_request
);
4698 copy_layer
->draw_properties().layer_or_descendant_has_copy_request
);
4700 copy_child_layer
->draw_properties().layer_or_descendant_has_copy_request
);
4701 EXPECT_FALSE(copy_grand_parent_sibling_before_layer
->draw_properties()
4702 .layer_or_descendant_has_copy_request
);
4703 EXPECT_FALSE(copy_grand_parent_sibling_after_layer
->draw_properties()
4704 .layer_or_descendant_has_copy_request
);
4706 // We should have three render surfaces, one for the root, one for the parent
4707 // since it owns a surface, and one for the copy_layer.
4708 ASSERT_EQ(3u, render_surface_layer_list
.size());
4709 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
4710 EXPECT_EQ(copy_parent_layer
->id(), render_surface_layer_list
.at(1)->id());
4711 EXPECT_EQ(copy_layer
->id(), render_surface_layer_list
.at(2)->id());
4713 // The root render surface should have 2 contributing layers. The
4714 // copy_grand_parent is hidden along with its siblings, but the copy_parent
4715 // will appear since something in its subtree needs to be drawn for a copy
4717 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
4718 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
4719 EXPECT_EQ(copy_parent_layer
->id(),
4720 root
->render_surface()->layer_list().at(1)->id());
4722 // Nothing actually draws into the copy parent, so only the copy_layer will
4723 // appear in its list, since it needs to be drawn for the copy request.
4724 ASSERT_EQ(1u, copy_parent_layer
->render_surface()->layer_list().size());
4725 EXPECT_EQ(copy_layer
->id(),
4726 copy_parent_layer
->render_surface()->layer_list().at(0)->id());
4728 // The copy_layer's render surface should have two contributing layers.
4729 ASSERT_EQ(2u, copy_layer
->render_surface()->layer_list().size());
4730 EXPECT_EQ(copy_layer
->id(),
4731 copy_layer
->render_surface()->layer_list().at(0)->id());
4732 EXPECT_EQ(copy_child_layer
->id(),
4733 copy_layer
->render_surface()->layer_list().at(1)->id());
4736 TEST_F(LayerTreeHostCommonTest
, ClippedOutCopyRequest
) {
4737 FakeImplProxy proxy
;
4738 TestSharedBitmapManager shared_bitmap_manager
;
4739 TestTaskGraphRunner task_graph_runner
;
4740 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4741 &task_graph_runner
);
4742 host_impl
.CreatePendingTree();
4743 const gfx::Transform identity_matrix
;
4745 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4746 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4747 gfx::PointF(), gfx::Size(50, 50), true, false,
4749 root
->SetDrawsContent(true);
4751 scoped_ptr
<LayerImpl
> copy_parent
=
4752 LayerImpl::Create(host_impl
.pending_tree(), 2);
4753 SetLayerPropertiesForTesting(copy_parent
.get(), identity_matrix
,
4754 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
4756 copy_parent
->SetDrawsContent(true);
4757 copy_parent
->SetMasksToBounds(true);
4759 scoped_ptr
<LayerImpl
> copy_layer
=
4760 LayerImpl::Create(host_impl
.pending_tree(), 3);
4761 SetLayerPropertiesForTesting(copy_layer
.get(), identity_matrix
,
4762 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4764 copy_layer
->SetDrawsContent(true);
4766 scoped_ptr
<LayerImpl
> copy_child
=
4767 LayerImpl::Create(host_impl
.pending_tree(), 4);
4768 SetLayerPropertiesForTesting(copy_child
.get(), identity_matrix
,
4769 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4770 true, false, false);
4771 copy_child
->SetDrawsContent(true);
4773 ScopedPtrVector
<CopyOutputRequest
> copy_requests
;
4774 copy_requests
.push_back(
4775 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback
)));
4776 copy_layer
->PassCopyRequests(©_requests
);
4777 EXPECT_TRUE(copy_layer
->HasCopyRequest());
4779 copy_layer
->AddChild(copy_child
.Pass());
4780 copy_parent
->AddChild(copy_layer
.Pass());
4781 root
->AddChild(copy_parent
.Pass());
4783 LayerImplList render_surface_layer_list
;
4784 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4785 root
.get(), root
->bounds(), &render_surface_layer_list
);
4786 inputs
.can_adjust_raster_scales
= true;
4787 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4789 // We should have one render surface, as the others are clipped out.
4790 ASSERT_EQ(1u, render_surface_layer_list
.size());
4791 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
4793 // The root render surface should only have 1 contributing layer, since the
4794 // other layers are empty/clipped away.
4795 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
4796 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
4799 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInsideSurface
) {
4800 FakeImplProxy proxy
;
4801 TestSharedBitmapManager shared_bitmap_manager
;
4802 TestTaskGraphRunner task_graph_runner
;
4803 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4804 &task_graph_runner
);
4805 host_impl
.CreatePendingTree();
4806 const gfx::Transform identity_matrix
;
4808 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4809 SetLayerPropertiesForTesting(root
.get(),
4816 root
->SetIsDrawable(true);
4818 // The surface is moved slightly outside of the viewport.
4819 scoped_refptr
<Layer
> surface
= Layer::Create(layer_settings());
4820 SetLayerPropertiesForTesting(surface
.get(),
4823 gfx::PointF(-10, -20),
4827 surface
->SetForceRenderSurface(true);
4829 scoped_refptr
<Layer
> surface_child
= Layer::Create(layer_settings());
4830 SetLayerPropertiesForTesting(surface_child
.get(),
4837 surface_child
->SetIsDrawable(true);
4839 surface
->AddChild(surface_child
);
4840 root
->AddChild(surface
);
4842 host()->SetRootLayer(root
);
4844 RenderSurfaceLayerList render_surface_layer_list
;
4845 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4846 root
.get(), root
->bounds(), &render_surface_layer_list
);
4847 inputs
.can_adjust_raster_scales
= true;
4848 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4850 // The visible_layer_rect for the |surface_child| should not be clipped by
4852 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
4853 surface_child
->visible_layer_rect().ToString());
4856 TEST_F(LayerTreeHostCommonTest
, TransformedClipParent
) {
4857 // Ensure that a transform between the layer and its render surface is not a
4858 // problem. Constructs the following layer tree.
4860 // root (a render surface)
4862 // + clip_parent (scaled)
4863 // + intervening_clipping_layer
4866 // The render surface should be resized correctly and the clip child should
4867 // inherit the right clip rect.
4868 LayerImpl
* root
= root_layer();
4869 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
4870 LayerImpl
* clip_parent
= AddChild
<LayerImpl
>(render_surface
);
4871 LayerImpl
* intervening
= AddChild
<LayerImpl
>(clip_parent
);
4872 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(intervening
);
4873 clip_child
->SetDrawsContent(true);
4874 clip_child
->SetClipParent(clip_parent
);
4875 scoped_ptr
<std::set
<LayerImpl
*>> clip_children(new std::set
<LayerImpl
*>);
4876 clip_children
->insert(clip_child
);
4877 clip_parent
->SetClipChildren(clip_children
.release());
4879 intervening
->SetMasksToBounds(true);
4880 clip_parent
->SetMasksToBounds(true);
4882 gfx::Transform scale_transform
;
4883 scale_transform
.Scale(2, 2);
4885 gfx::Transform identity_transform
;
4887 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
4888 gfx::PointF(), gfx::Size(50, 50), true, false,
4890 SetLayerPropertiesForTesting(render_surface
, identity_transform
,
4891 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4893 SetLayerPropertiesForTesting(clip_parent
, scale_transform
, gfx::Point3F(),
4894 gfx::PointF(1.f
, 1.f
), gfx::Size(10, 10), true,
4896 SetLayerPropertiesForTesting(intervening
, identity_transform
, gfx::Point3F(),
4897 gfx::PointF(1.f
, 1.f
), gfx::Size(5, 5), true,
4899 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
4900 gfx::PointF(1.f
, 1.f
), gfx::Size(10, 10), true,
4903 ExecuteCalculateDrawProperties(root
);
4905 ASSERT_TRUE(root
->render_surface());
4906 ASSERT_TRUE(render_surface
->render_surface());
4908 // Ensure that we've inherited our clip parent's clip and weren't affected
4909 // by the intervening clip layer.
4910 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
4911 clip_parent
->clip_rect().ToString());
4912 ASSERT_EQ(clip_parent
->clip_rect().ToString(),
4913 clip_child
->clip_rect().ToString());
4914 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
4915 intervening
->clip_rect().ToString());
4917 // Ensure that the render surface reports a content rect that has been grown
4918 // to accomodate for the clip child.
4919 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
4920 render_surface
->render_surface()->content_rect().ToString());
4922 // The above check implies the two below, but they nicely demonstrate that
4923 // we've grown, despite the intervening layer's clip.
4924 ASSERT_TRUE(clip_parent
->clip_rect().Contains(
4925 render_surface
->render_surface()->content_rect()));
4926 ASSERT_FALSE(intervening
->clip_rect().Contains(
4927 render_surface
->render_surface()->content_rect()));
4930 TEST_F(LayerTreeHostCommonTest
, ClipParentWithInterveningRenderSurface
) {
4931 // Ensure that intervening render surfaces are not a problem in the basic
4932 // case. In the following tree, both render surfaces should be resized to
4933 // accomodate for the clip child, despite an intervening clip.
4935 // root (a render surface)
4936 // + clip_parent (masks to bounds)
4937 // + render_surface1 (sets opacity)
4938 // + intervening (masks to bounds)
4939 // + render_surface2 (also sets opacity)
4942 LayerImpl
* root
= root_layer();
4943 LayerImpl
* clip_parent
= AddChildToRoot
<LayerImpl
>();
4944 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(clip_parent
);
4945 LayerImpl
* intervening
= AddChild
<LayerImpl
>(render_surface1
);
4946 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(intervening
);
4947 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(render_surface2
);
4948 clip_child
->SetDrawsContent(true);
4950 clip_child
->SetClipParent(clip_parent
);
4952 intervening
->SetMasksToBounds(true);
4953 clip_parent
->SetMasksToBounds(true);
4955 gfx::Transform translation_transform
;
4956 translation_transform
.Translate(2, 2);
4958 gfx::Transform identity_transform
;
4959 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
4960 gfx::PointF(), gfx::Size(50, 50), true, false,
4962 SetLayerPropertiesForTesting(clip_parent
, translation_transform
,
4963 gfx::Point3F(), gfx::PointF(1.f
, 1.f
),
4964 gfx::Size(40, 40), true, false, false);
4965 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
4966 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4968 SetLayerPropertiesForTesting(intervening
, identity_transform
, gfx::Point3F(),
4969 gfx::PointF(1.f
, 1.f
), gfx::Size(5, 5), true,
4971 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
4972 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4974 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
4975 gfx::PointF(-10.f
, -10.f
), gfx::Size(60, 60),
4976 true, false, false);
4978 ExecuteCalculateDrawProperties(root
);
4980 EXPECT_TRUE(root
->render_surface());
4981 EXPECT_TRUE(render_surface1
->render_surface());
4982 EXPECT_TRUE(render_surface2
->render_surface());
4984 // Since the render surfaces could have expanded, they should not clip (their
4985 // bounds would no longer be reliable). We should resort to layer clipping
4987 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4988 render_surface1
->render_surface()->clip_rect().ToString());
4989 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
4990 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4991 render_surface2
->render_surface()->clip_rect().ToString());
4992 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
4994 // NB: clip rects are in target space.
4995 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4996 render_surface1
->clip_rect().ToString());
4997 EXPECT_TRUE(render_surface1
->is_clipped());
4999 // This value is inherited from the clipping ancestor layer, 'intervening'.
5000 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5001 render_surface2
->clip_rect().ToString());
5002 EXPECT_TRUE(render_surface2
->is_clipped());
5004 // The content rects of both render surfaces should both have expanded to
5005 // contain the clip child.
5006 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5007 render_surface1
->render_surface()->content_rect().ToString());
5008 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
5009 render_surface2
->render_surface()->content_rect().ToString());
5011 // The clip child should have inherited the clip parent's clip (projected to
5012 // the right space, of course), and should have the correctly sized visible
5014 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
5015 clip_child
->clip_rect().ToString());
5016 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
5017 clip_child
->visible_layer_rect().ToString());
5018 EXPECT_TRUE(clip_child
->is_clipped());
5021 TEST_F(LayerTreeHostCommonTest
, ClipParentScrolledInterveningLayer
) {
5022 // Ensure that intervening render surfaces are not a problem, even if there
5023 // is a scroll involved. Note, we do _not_ have to consider any other sort
5026 // root (a render surface)
5027 // + clip_parent (masks to bounds)
5028 // + render_surface1 (sets opacity)
5029 // + intervening (masks to bounds AND scrolls)
5030 // + render_surface2 (also sets opacity)
5033 LayerImpl
* root
= root_layer();
5034 LayerImpl
* clip_parent
= AddChildToRoot
<LayerImpl
>();
5035 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(clip_parent
);
5036 LayerImpl
* intervening
= AddChild
<LayerImpl
>(render_surface1
);
5037 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(intervening
);
5038 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(render_surface2
);
5039 clip_child
->SetDrawsContent(true);
5041 clip_child
->SetClipParent(clip_parent
);
5043 intervening
->SetMasksToBounds(true);
5044 clip_parent
->SetMasksToBounds(true);
5045 intervening
->SetScrollClipLayer(clip_parent
->id());
5046 intervening
->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
5048 gfx::Transform translation_transform
;
5049 translation_transform
.Translate(2, 2);
5051 gfx::Transform identity_transform
;
5052 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5053 gfx::PointF(), gfx::Size(50, 50), true, false,
5055 SetLayerPropertiesForTesting(clip_parent
, translation_transform
,
5056 gfx::Point3F(), gfx::PointF(1.f
, 1.f
),
5057 gfx::Size(40, 40), true, false, false);
5058 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
5059 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5061 SetLayerPropertiesForTesting(intervening
, identity_transform
, gfx::Point3F(),
5062 gfx::PointF(1.f
, 1.f
), gfx::Size(5, 5), true,
5064 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
5065 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5067 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
5068 gfx::PointF(-10.f
, -10.f
), gfx::Size(60, 60),
5069 true, false, false);
5071 ExecuteCalculateDrawProperties(root
);
5073 EXPECT_TRUE(root
->render_surface());
5074 EXPECT_TRUE(render_surface1
->render_surface());
5075 EXPECT_TRUE(render_surface2
->render_surface());
5077 // Since the render surfaces could have expanded, they should not clip (their
5078 // bounds would no longer be reliable). We should resort to layer clipping
5080 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5081 render_surface1
->render_surface()->clip_rect().ToString());
5082 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
5083 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5084 render_surface2
->render_surface()->clip_rect().ToString());
5085 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
5087 // NB: clip rects are in target space.
5088 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5089 render_surface1
->clip_rect().ToString());
5090 EXPECT_TRUE(render_surface1
->is_clipped());
5092 // This value is inherited from the clipping ancestor layer, 'intervening'.
5093 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
5094 render_surface2
->clip_rect().ToString());
5095 EXPECT_TRUE(render_surface2
->is_clipped());
5097 // The content rects of both render surfaces should both have expanded to
5098 // contain the clip child.
5099 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5100 render_surface1
->render_surface()->content_rect().ToString());
5101 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
5102 render_surface2
->render_surface()->content_rect().ToString());
5104 // The clip child should have inherited the clip parent's clip (projected to
5105 // the right space, of course), and should have the correctly sized visible
5107 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
5108 clip_child
->clip_rect().ToString());
5109 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
5110 clip_child
->visible_layer_rect().ToString());
5111 EXPECT_TRUE(clip_child
->is_clipped());
5114 TEST_F(LayerTreeHostCommonTest
, DescendantsOfClipChildren
) {
5115 // Ensures that descendants of the clip child inherit the correct clip.
5117 // root (a render surface)
5118 // + clip_parent (masks to bounds)
5119 // + intervening (masks to bounds)
5123 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5124 scoped_refptr
<Layer
> clip_parent
= Layer::Create(layer_settings());
5125 scoped_refptr
<Layer
> intervening
= Layer::Create(layer_settings());
5126 scoped_refptr
<Layer
> clip_child
= Layer::Create(layer_settings());
5127 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
5128 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5130 root
->AddChild(clip_parent
);
5131 clip_parent
->AddChild(intervening
);
5132 intervening
->AddChild(clip_child
);
5133 clip_child
->AddChild(child
);
5135 clip_child
->SetClipParent(clip_parent
.get());
5137 intervening
->SetMasksToBounds(true);
5138 clip_parent
->SetMasksToBounds(true);
5140 gfx::Transform identity_transform
;
5141 SetLayerPropertiesForTesting(root
.get(),
5148 SetLayerPropertiesForTesting(clip_parent
.get(),
5155 SetLayerPropertiesForTesting(intervening
.get(),
5162 SetLayerPropertiesForTesting(clip_child
.get(),
5169 SetLayerPropertiesForTesting(child
.get(),
5177 host()->SetRootLayer(root
);
5179 ExecuteCalculateDrawProperties(root
.get());
5181 EXPECT_TRUE(root
->render_surface());
5183 // Neither the clip child nor its descendant should have inherited the clip
5184 // from |intervening|.
5185 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5186 clip_child
->clip_rect().ToString());
5187 EXPECT_TRUE(clip_child
->is_clipped());
5188 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5189 child
->visible_layer_rect().ToString());
5190 EXPECT_TRUE(child
->is_clipped());
5193 TEST_F(LayerTreeHostCommonTest
,
5194 SurfacesShouldBeUnaffectedByNonDescendantClipChildren
) {
5195 // Ensures that non-descendant clip children in the tree do not affect
5198 // root (a render surface)
5199 // + clip_parent (masks to bounds)
5200 // + render_surface1
5202 // + render_surface2
5205 // In this example render_surface2 should be unaffected by clip_child.
5206 LayerImpl
* root
= root_layer();
5207 LayerImpl
* clip_parent
= AddChildToRoot
<LayerImpl
>();
5208 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(clip_parent
);
5209 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(render_surface1
);
5210 clip_child
->SetDrawsContent(true);
5211 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(clip_parent
);
5212 LayerImpl
* non_clip_child
= AddChild
<LayerImpl
>(render_surface2
);
5213 non_clip_child
->SetDrawsContent(true);
5215 clip_child
->SetClipParent(clip_parent
);
5216 scoped_ptr
<std::set
<LayerImpl
*>> clip_children(new std::set
<LayerImpl
*>);
5217 clip_children
->insert(clip_child
);
5218 clip_parent
->SetClipChildren(clip_children
.release());
5220 clip_parent
->SetMasksToBounds(true);
5221 render_surface1
->SetMasksToBounds(true);
5223 gfx::Transform identity_transform
;
5224 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5225 gfx::PointF(), gfx::Size(15, 15), true, false,
5227 SetLayerPropertiesForTesting(clip_parent
, identity_transform
, gfx::Point3F(),
5228 gfx::PointF(), gfx::Size(10, 10), true, false,
5230 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
5231 gfx::Point3F(), gfx::PointF(5, 5),
5232 gfx::Size(5, 5), true, false, true);
5233 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
5234 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
5236 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
5237 gfx::PointF(-1, 1), gfx::Size(10, 10), true,
5239 SetLayerPropertiesForTesting(non_clip_child
, identity_transform
,
5240 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
5241 true, false, false);
5243 ExecuteCalculateDrawProperties(root
);
5245 EXPECT_TRUE(root
->render_surface());
5246 EXPECT_TRUE(render_surface1
->render_surface());
5247 EXPECT_TRUE(render_surface2
->render_surface());
5249 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5250 render_surface1
->clip_rect().ToString());
5251 EXPECT_TRUE(render_surface1
->is_clipped());
5253 // The render surface should not clip (it has unclipped descendants), instead
5254 // it should rely on layer clipping.
5255 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5256 render_surface1
->render_surface()->clip_rect().ToString());
5257 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
5259 // That said, it should have grown to accomodate the unclipped descendant.
5260 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
5261 render_surface1
->render_surface()->content_rect().ToString());
5263 // This render surface should clip. It has no unclipped descendants.
5264 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5265 render_surface2
->clip_rect().ToString());
5266 EXPECT_TRUE(render_surface2
->render_surface()->is_clipped());
5268 // It also shouldn't have grown to accomodate the clip child.
5269 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5270 render_surface2
->render_surface()->content_rect().ToString());
5272 // Sanity check our num_unclipped_descendants values.
5273 EXPECT_EQ(1u, render_surface1
->num_unclipped_descendants());
5274 EXPECT_EQ(0u, render_surface2
->num_unclipped_descendants());
5277 TEST_F(LayerTreeHostCommonTest
, CanRenderToSeparateSurface
) {
5278 FakeImplProxy proxy
;
5279 TestSharedBitmapManager shared_bitmap_manager
;
5280 TestTaskGraphRunner task_graph_runner
;
5281 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5282 &task_graph_runner
);
5283 scoped_ptr
<LayerImpl
> root
=
5284 LayerImpl::Create(host_impl
.active_tree(), 12345);
5285 scoped_ptr
<LayerImpl
> child1
=
5286 LayerImpl::Create(host_impl
.active_tree(), 123456);
5287 scoped_ptr
<LayerImpl
> child2
=
5288 LayerImpl::Create(host_impl
.active_tree(), 1234567);
5289 scoped_ptr
<LayerImpl
> child3
=
5290 LayerImpl::Create(host_impl
.active_tree(), 12345678);
5292 gfx::Transform identity_matrix
;
5293 gfx::Point3F transform_origin
;
5294 gfx::PointF position
;
5295 gfx::Size
bounds(100, 100);
5296 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
5297 position
, bounds
, true, false, true);
5298 root
->SetDrawsContent(true);
5300 // This layer structure normally forces render surface due to preserves3d
5302 SetLayerPropertiesForTesting(child1
.get(), identity_matrix
, transform_origin
,
5303 position
, bounds
, false, true, true);
5304 child1
->SetDrawsContent(true);
5305 SetLayerPropertiesForTesting(child2
.get(), identity_matrix
, transform_origin
,
5306 position
, bounds
, true, false, false);
5307 child2
->SetDrawsContent(true);
5308 SetLayerPropertiesForTesting(child3
.get(), identity_matrix
, transform_origin
,
5309 position
, bounds
, true, false, false);
5310 child3
->SetDrawsContent(true);
5312 child2
->Set3dSortingContextId(1);
5313 child3
->Set3dSortingContextId(1);
5315 child2
->AddChild(child3
.Pass());
5316 child1
->AddChild(child2
.Pass());
5317 root
->AddChild(child1
.Pass());
5320 LayerImplList render_surface_layer_list
;
5321 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root
.get());
5322 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5323 root
.get(), root
->bounds(), &render_surface_layer_list
);
5324 inputs
.can_render_to_separate_surface
= true;
5325 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5327 EXPECT_EQ(2u, render_surface_layer_list
.size());
5329 int count_represents_target_render_surface
= 0;
5330 int count_represents_contributing_render_surface
= 0;
5331 int count_represents_itself
= 0;
5332 LayerIterator end
= LayerIterator::End(&render_surface_layer_list
);
5333 for (LayerIterator it
= LayerIterator::Begin(&render_surface_layer_list
);
5335 if (it
.represents_target_render_surface())
5336 count_represents_target_render_surface
++;
5337 if (it
.represents_contributing_render_surface())
5338 count_represents_contributing_render_surface
++;
5339 if (it
.represents_itself())
5340 count_represents_itself
++;
5343 // Two render surfaces.
5344 EXPECT_EQ(2, count_represents_target_render_surface
);
5345 // Second render surface contributes to root render surface.
5346 EXPECT_EQ(1, count_represents_contributing_render_surface
);
5347 // All 4 layers represent itself.
5348 EXPECT_EQ(4, count_represents_itself
);
5352 LayerImplList render_surface_layer_list
;
5353 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5354 root
.get(), root
->bounds(), &render_surface_layer_list
);
5355 inputs
.can_render_to_separate_surface
= false;
5356 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5358 EXPECT_EQ(1u, render_surface_layer_list
.size());
5360 int count_represents_target_render_surface
= 0;
5361 int count_represents_contributing_render_surface
= 0;
5362 int count_represents_itself
= 0;
5363 LayerIterator end
= LayerIterator::End(&render_surface_layer_list
);
5364 for (LayerIterator it
= LayerIterator::Begin(&render_surface_layer_list
);
5366 if (it
.represents_target_render_surface())
5367 count_represents_target_render_surface
++;
5368 if (it
.represents_contributing_render_surface())
5369 count_represents_contributing_render_surface
++;
5370 if (it
.represents_itself())
5371 count_represents_itself
++;
5374 // Only root layer has a render surface.
5375 EXPECT_EQ(1, count_represents_target_render_surface
);
5376 // No layer contributes a render surface to root render surface.
5377 EXPECT_EQ(0, count_represents_contributing_render_surface
);
5378 // All 4 layers represent itself.
5379 EXPECT_EQ(4, count_represents_itself
);
5383 TEST_F(LayerTreeHostCommonTest
, DoNotIncludeBackfaceInvisibleSurfaces
) {
5384 LayerImpl
* root
= root_layer();
5385 LayerImpl
* render_surface
= AddChild
<LayerImpl
>(root
);
5386 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface
);
5387 child
->SetDrawsContent(true);
5389 gfx::Transform identity_transform
;
5390 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5391 gfx::PointF(), gfx::Size(50, 50), true, false,
5393 SetLayerPropertiesForTesting(render_surface
, identity_transform
,
5394 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5396 SetLayerPropertiesForTesting(child
, identity_transform
, gfx::Point3F(),
5397 gfx::PointF(), gfx::Size(20, 20), true, false,
5400 root
->SetShouldFlattenTransform(false);
5401 root
->Set3dSortingContextId(1);
5402 render_surface
->SetDoubleSided(false);
5404 ExecuteCalculateDrawProperties(root
);
5406 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
5407 EXPECT_EQ(1u, render_surface_layer_list_impl()
5412 EXPECT_EQ(1u, render_surface_layer_list_impl()
5418 gfx::Transform rotation_transform
= identity_transform
;
5419 rotation_transform
.RotateAboutXAxis(180.0);
5421 render_surface
->SetTransform(rotation_transform
);
5423 ExecuteCalculateDrawProperties(root
);
5425 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
5426 EXPECT_EQ(0u, render_surface_layer_list_impl()
5433 TEST_F(LayerTreeHostCommonTest
, ClippedByScrollParent
) {
5434 // Checks that the simple case (being clipped by a scroll parent that would
5435 // have been processed before you anyhow) results in the right clips.
5438 // + scroll_parent_border
5439 // | + scroll_parent_clip
5440 // | + scroll_parent
5443 LayerImpl
* root
= root_layer();
5444 LayerImpl
* scroll_parent_border
= AddChildToRoot
<LayerImpl
>();
5445 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
5446 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
5447 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
5449 scroll_parent
->SetDrawsContent(true);
5450 scroll_child
->SetDrawsContent(true);
5451 scroll_parent_clip
->SetMasksToBounds(true);
5453 scroll_child
->SetScrollParent(scroll_parent
);
5454 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
5455 scroll_children
->insert(scroll_child
);
5456 scroll_parent
->SetScrollChildren(scroll_children
.release());
5458 gfx::Transform identity_transform
;
5459 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5460 gfx::PointF(), gfx::Size(50, 50), true, false,
5462 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
5463 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5464 true, false, false);
5465 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
5466 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5467 true, false, false);
5468 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
5469 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5470 true, false, false);
5471 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
5472 gfx::PointF(), gfx::Size(50, 50), true, false,
5475 ExecuteCalculateDrawProperties(root
);
5477 EXPECT_TRUE(root
->render_surface());
5479 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
5480 scroll_child
->clip_rect().ToString());
5481 EXPECT_TRUE(scroll_child
->is_clipped());
5484 TEST_F(LayerTreeHostCommonTest
, SingularTransformSubtreesDoNotDraw
) {
5485 LayerImpl
* root
= root_layer();
5486 root
->SetDrawsContent(true);
5487 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
5488 parent
->SetDrawsContent(true);
5489 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
5490 child
->SetDrawsContent(true);
5492 gfx::Transform identity_transform
;
5493 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5494 gfx::PointF(), gfx::Size(50, 50), true, true,
5496 SetLayerPropertiesForTesting(parent
, identity_transform
, gfx::Point3F(),
5497 gfx::PointF(), gfx::Size(30, 30), true, true,
5499 SetLayerPropertiesForTesting(child
, identity_transform
, gfx::Point3F(),
5500 gfx::PointF(), gfx::Size(20, 20), true, true,
5503 ExecuteCalculateDrawProperties(root
);
5505 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
5507 gfx::Transform singular_transform
;
5508 singular_transform
.Scale3d(
5509 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
5511 child
->SetTransform(singular_transform
);
5513 ExecuteCalculateDrawProperties(root
);
5515 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
5517 // Ensure that the entire subtree under a layer with singular transform does
5518 // not get rendered.
5519 parent
->SetTransform(singular_transform
);
5520 child
->SetTransform(identity_transform
);
5522 ExecuteCalculateDrawProperties(root
);
5524 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
5527 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollParent
) {
5528 // Checks that clipping by a scroll parent that follows you in paint order
5529 // still results in correct clipping.
5532 // + scroll_parent_border
5533 // + scroll_parent_clip
5537 LayerImpl
* root
= root_layer();
5538 LayerImpl
* scroll_parent_border
= AddChild
<LayerImpl
>(root
);
5539 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
5540 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
5541 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
5543 scroll_parent
->SetDrawsContent(true);
5544 scroll_child
->SetDrawsContent(true);
5546 scroll_parent_clip
->SetMasksToBounds(true);
5548 scroll_child
->SetScrollParent(scroll_parent
);
5549 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
5550 scroll_children
->insert(scroll_child
);
5551 scroll_parent
->SetScrollChildren(scroll_children
.release());
5553 gfx::Transform identity_transform
;
5554 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5555 gfx::PointF(), gfx::Size(50, 50), true, false,
5557 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
5558 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5559 true, false, false);
5560 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
5561 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5562 true, false, false);
5563 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
5564 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5565 true, false, false);
5566 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
5567 gfx::PointF(), gfx::Size(50, 50), true, false,
5570 ExecuteCalculateDrawProperties(root
);
5572 EXPECT_TRUE(root
->render_surface());
5574 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
5575 scroll_child
->clip_rect().ToString());
5576 EXPECT_TRUE(scroll_child
->is_clipped());
5579 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollGrandparent
) {
5580 // Checks that clipping by a scroll parent and scroll grandparent that follow
5581 // you in paint order still results in correct clipping.
5585 // + scroll_parent_border
5586 // | + scroll_parent_clip
5587 // | + scroll_parent
5588 // + scroll_grandparent_border
5589 // + scroll_grandparent_clip
5590 // + scroll_grandparent
5592 LayerImpl
* root
= root_layer();
5593 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
5594 LayerImpl
* scroll_parent_border
= AddChild
<LayerImpl
>(root
);
5595 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
5596 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
5597 LayerImpl
* scroll_grandparent_border
= AddChild
<LayerImpl
>(root
);
5598 LayerImpl
* scroll_grandparent_clip
=
5599 AddChild
<LayerImpl
>(scroll_grandparent_border
);
5600 LayerImpl
* scroll_grandparent
= AddChild
<LayerImpl
>(scroll_grandparent_clip
);
5602 scroll_parent
->SetDrawsContent(true);
5603 scroll_grandparent
->SetDrawsContent(true);
5604 scroll_child
->SetDrawsContent(true);
5606 scroll_parent_clip
->SetMasksToBounds(true);
5607 scroll_grandparent_clip
->SetMasksToBounds(true);
5609 scroll_child
->SetScrollParent(scroll_parent
);
5610 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
5611 scroll_children
->insert(scroll_child
);
5612 scroll_parent
->SetScrollChildren(scroll_children
.release());
5614 scroll_parent_border
->SetScrollParent(scroll_grandparent
);
5615 scroll_children
.reset(new std::set
<LayerImpl
*>);
5616 scroll_children
->insert(scroll_parent_border
);
5617 scroll_grandparent
->SetScrollChildren(scroll_children
.release());
5619 gfx::Transform identity_transform
;
5620 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5621 gfx::PointF(), gfx::Size(50, 50), true, false,
5623 SetLayerPropertiesForTesting(scroll_grandparent_border
, identity_transform
,
5624 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5625 true, false, false);
5626 SetLayerPropertiesForTesting(scroll_grandparent_clip
, identity_transform
,
5627 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5628 true, false, false);
5629 SetLayerPropertiesForTesting(scroll_grandparent
, identity_transform
,
5630 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5631 true, false, false);
5632 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
5633 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5634 true, false, false);
5635 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
5636 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5637 true, false, false);
5638 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
5639 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5640 true, false, false);
5641 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
5642 gfx::PointF(), gfx::Size(50, 50), true, false,
5645 ExecuteCalculateDrawProperties(root
);
5647 EXPECT_TRUE(root
->render_surface());
5649 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
5650 scroll_child
->clip_rect().ToString());
5651 EXPECT_TRUE(scroll_child
->is_clipped());
5653 // Despite the fact that we visited the above layers out of order to get the
5654 // correct clip, the layer lists should be unaffected.
5655 EXPECT_EQ(3u, root
->render_surface()->layer_list().size());
5656 EXPECT_EQ(scroll_child
, root
->render_surface()->layer_list().at(0));
5657 EXPECT_EQ(scroll_parent
, root
->render_surface()->layer_list().at(1));
5658 EXPECT_EQ(scroll_grandparent
, root
->render_surface()->layer_list().at(2));
5661 TEST_F(LayerTreeHostCommonTest
, OutOfOrderClippingRequiresRSLLSorting
) {
5662 // Ensures that even if we visit layers out of order, we still produce a
5663 // correctly ordered render surface layer list.
5666 // + scroll_parent_border
5667 // + scroll_parent_clip
5669 // + render_surface2
5670 // + scroll_grandparent_border
5671 // + scroll_grandparent_clip
5672 // + scroll_grandparent
5673 // + render_surface1
5675 LayerImpl
* root
= root_layer();
5676 root
->SetDrawsContent(true);
5678 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
5679 scroll_child
->SetDrawsContent(true);
5681 LayerImpl
* scroll_parent_border
= AddChild
<LayerImpl
>(root
);
5682 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
5683 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
5684 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(scroll_parent
);
5685 LayerImpl
* scroll_grandparent_border
= AddChild
<LayerImpl
>(root
);
5686 LayerImpl
* scroll_grandparent_clip
=
5687 AddChild
<LayerImpl
>(scroll_grandparent_border
);
5688 LayerImpl
* scroll_grandparent
= AddChild
<LayerImpl
>(scroll_grandparent_clip
);
5689 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(scroll_grandparent
);
5691 scroll_parent
->SetDrawsContent(true);
5692 render_surface1
->SetDrawsContent(true);
5693 scroll_grandparent
->SetDrawsContent(true);
5694 render_surface2
->SetDrawsContent(true);
5696 scroll_parent_clip
->SetMasksToBounds(true);
5697 scroll_grandparent_clip
->SetMasksToBounds(true);
5699 scroll_child
->SetScrollParent(scroll_parent
);
5700 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
5701 scroll_children
->insert(scroll_child
);
5702 scroll_parent
->SetScrollChildren(scroll_children
.release());
5704 scroll_parent_border
->SetScrollParent(scroll_grandparent
);
5705 scroll_children
.reset(new std::set
<LayerImpl
*>);
5706 scroll_children
->insert(scroll_parent_border
);
5707 scroll_grandparent
->SetScrollChildren(scroll_children
.release());
5709 gfx::Transform identity_transform
;
5710 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5711 gfx::PointF(), gfx::Size(50, 50), true, false,
5713 SetLayerPropertiesForTesting(scroll_grandparent_border
, identity_transform
,
5714 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5715 true, false, false);
5716 SetLayerPropertiesForTesting(scroll_grandparent_clip
, identity_transform
,
5717 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5718 true, false, false);
5719 SetLayerPropertiesForTesting(scroll_grandparent
, identity_transform
,
5720 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5721 true, false, false);
5722 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
5723 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5725 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
5726 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5727 true, false, false);
5728 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
5729 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5730 true, false, false);
5731 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
5732 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5733 true, false, false);
5734 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
5735 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5737 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
5738 gfx::PointF(), gfx::Size(50, 50), true, false,
5741 ExecuteCalculateDrawProperties(root
);
5743 EXPECT_TRUE(root
->render_surface());
5745 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
5746 scroll_child
->clip_rect().ToString());
5747 EXPECT_TRUE(scroll_child
->is_clipped());
5749 // Despite the fact that we had to process the layers out of order to get the
5750 // right clip, our render_surface_layer_list's order should be unaffected.
5751 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
5752 EXPECT_EQ(root
, render_surface_layer_list_impl()->at(0));
5753 EXPECT_EQ(render_surface2
, render_surface_layer_list_impl()->at(1));
5754 EXPECT_EQ(render_surface1
, render_surface_layer_list_impl()->at(2));
5755 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
5756 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
5757 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
5760 TEST_F(LayerTreeHostCommonTest
, FixedPositionWithInterveningRenderSurface
) {
5761 // Ensures that when we have a render surface between a fixed position layer
5762 // and its container, we compute the fixed position layer's draw transform
5763 // with respect to that intervening render surface, not with respect to its
5764 // container's render target.
5771 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5772 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface
=
5773 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5774 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
5775 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5776 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
5777 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5779 root
->AddChild(render_surface
);
5780 render_surface
->AddChild(fixed
);
5781 fixed
->AddChild(child
);
5783 root
->SetIsContainerForFixedPositionLayers(true);
5784 render_surface
->SetForceRenderSurface(true);
5786 LayerPositionConstraint constraint
;
5787 constraint
.set_is_fixed_position(true);
5788 fixed
->SetPositionConstraint(constraint
);
5790 SetLayerPropertiesForTesting(root
.get(), gfx::Transform(), gfx::Point3F(),
5791 gfx::PointF(), gfx::Size(50, 50), true, false);
5792 SetLayerPropertiesForTesting(render_surface
.get(), gfx::Transform(),
5793 gfx::Point3F(), gfx::PointF(7.f
, 9.f
),
5794 gfx::Size(50, 50), true, false);
5795 SetLayerPropertiesForTesting(fixed
.get(), gfx::Transform(), gfx::Point3F(),
5796 gfx::PointF(10.f
, 15.f
), gfx::Size(50, 50), true,
5798 SetLayerPropertiesForTesting(child
.get(), gfx::Transform(), gfx::Point3F(),
5799 gfx::PointF(1.f
, 2.f
), gfx::Size(50, 50), true,
5802 host()->SetRootLayer(root
);
5804 ExecuteCalculateDrawProperties(root
.get());
5806 TransformTree
& tree
= host()->property_trees()->transform_tree
;
5808 gfx::Transform expected_fixed_draw_transform
;
5809 expected_fixed_draw_transform
.Translate(10.f
, 15.f
);
5810 EXPECT_EQ(expected_fixed_draw_transform
,
5811 DrawTransformFromPropertyTrees(fixed
.get(), tree
));
5813 gfx::Transform expected_fixed_screen_space_transform
;
5814 expected_fixed_screen_space_transform
.Translate(17.f
, 24.f
);
5815 EXPECT_EQ(expected_fixed_screen_space_transform
,
5816 ScreenSpaceTransformFromPropertyTrees(fixed
.get(), tree
));
5818 gfx::Transform expected_child_draw_transform
;
5819 expected_child_draw_transform
.Translate(11.f
, 17.f
);
5820 EXPECT_EQ(expected_child_draw_transform
,
5821 DrawTransformFromPropertyTrees(child
.get(), tree
));
5823 gfx::Transform expected_child_screen_space_transform
;
5824 expected_child_screen_space_transform
.Translate(18.f
, 26.f
);
5825 EXPECT_EQ(expected_child_screen_space_transform
,
5826 ScreenSpaceTransformFromPropertyTrees(child
.get(), tree
));
5829 TEST_F(LayerTreeHostCommonTest
, ScrollCompensationWithRounding
) {
5830 // This test verifies that a scrolling layer that gets snapped to
5831 // integer coordinates doesn't move a fixed position child.
5838 FakeImplProxy proxy
;
5839 TestSharedBitmapManager shared_bitmap_manager
;
5840 TestTaskGraphRunner task_graph_runner
;
5841 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5842 &task_graph_runner
);
5843 host_impl
.CreatePendingTree();
5844 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
5845 scoped_ptr
<LayerImpl
> container
=
5846 LayerImpl::Create(host_impl
.active_tree(), 2);
5847 LayerImpl
* container_layer
= container
.get();
5848 scoped_ptr
<LayerImpl
> scroller
=
5849 LayerImpl::Create(host_impl
.active_tree(), 3);
5850 LayerImpl
* scroll_layer
= scroller
.get();
5851 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
5852 LayerImpl
* fixed_layer
= fixed
.get();
5854 container
->SetIsContainerForFixedPositionLayers(true);
5856 LayerPositionConstraint constraint
;
5857 constraint
.set_is_fixed_position(true);
5858 fixed
->SetPositionConstraint(constraint
);
5860 scroller
->SetScrollClipLayer(container
->id());
5862 gfx::Transform identity_transform
;
5863 gfx::Transform container_transform
;
5864 container_transform
.Translate3d(10.0, 20.0, 0.0);
5865 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
5867 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
5868 gfx::PointF(), gfx::Size(50, 50), true, false,
5870 SetLayerPropertiesForTesting(container
.get(), container_transform
,
5871 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5872 true, false, false);
5873 SetLayerPropertiesForTesting(scroller
.get(), identity_transform
,
5874 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5875 true, false, false);
5876 SetLayerPropertiesForTesting(fixed
.get(), identity_transform
, gfx::Point3F(),
5877 gfx::PointF(), gfx::Size(50, 50), true, false,
5880 scroller
->AddChild(fixed
.Pass());
5881 container
->AddChild(scroller
.Pass());
5882 root
->AddChild(container
.Pass());
5884 // Rounded to integers already.
5886 gfx::Vector2dF
scroll_delta(3.0, 5.0);
5887 scroll_layer
->SetScrollDelta(scroll_delta
);
5889 LayerImplList render_surface_layer_list
;
5890 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5891 root
.get(), root
->bounds(), &render_surface_layer_list
);
5892 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5894 EXPECT_TRANSFORMATION_MATRIX_EQ(
5895 container_layer
->draw_properties().screen_space_transform
,
5896 fixed_layer
->draw_properties().screen_space_transform
);
5898 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5900 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
5901 .screen_space_transform
.To2dTranslation(),
5902 container_offset
- scroll_delta
);
5905 // Scroll delta requiring rounding.
5907 gfx::Vector2dF
scroll_delta(4.1f
, 8.1f
);
5908 scroll_layer
->SetScrollDelta(scroll_delta
);
5910 gfx::Vector2dF
rounded_scroll_delta(4.f
, 8.f
);
5912 LayerImplList render_surface_layer_list
;
5913 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5914 root
.get(), root
->bounds(), &render_surface_layer_list
);
5915 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5917 EXPECT_TRANSFORMATION_MATRIX_EQ(
5918 container_layer
->draw_properties().screen_space_transform
,
5919 fixed_layer
->draw_properties().screen_space_transform
);
5921 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5923 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
5924 .screen_space_transform
.To2dTranslation(),
5925 container_offset
- rounded_scroll_delta
);
5928 // Scale is applied earlier in the tree.
5930 gfx::Transform scaled_container_transform
= container_transform
;
5931 scaled_container_transform
.Scale3d(3.0, 3.0, 1.0);
5932 container_layer
->SetTransform(scaled_container_transform
);
5934 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
5935 scroll_layer
->SetScrollDelta(scroll_delta
);
5937 LayerImplList render_surface_layer_list
;
5938 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5939 root
.get(), root
->bounds(), &render_surface_layer_list
);
5940 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5942 EXPECT_TRANSFORMATION_MATRIX_EQ(
5943 container_layer
->draw_properties().screen_space_transform
,
5944 fixed_layer
->draw_properties().screen_space_transform
);
5946 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5949 container_layer
->SetTransform(container_transform
);
5952 // Scale is applied on the scroll layer itself.
5954 gfx::Transform scale_transform
;
5955 scale_transform
.Scale3d(3.0, 3.0, 1.0);
5956 scroll_layer
->SetTransform(scale_transform
);
5958 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
5959 scroll_layer
->SetScrollDelta(scroll_delta
);
5961 LayerImplList render_surface_layer_list
;
5962 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5963 root
.get(), root
->bounds(), &render_surface_layer_list
);
5964 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5967 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5970 scroll_layer
->SetTransform(identity_transform
);
5974 TEST_F(LayerTreeHostCommonTest
,
5975 ScrollCompensationMainScrollOffsetFractionalPart
) {
5976 // This test verifies that a scrolling layer that has fractional scroll offset
5977 // from main doesn't move a fixed position child.
5984 FakeImplProxy proxy
;
5985 TestSharedBitmapManager shared_bitmap_manager
;
5986 TestTaskGraphRunner task_graph_runner
;
5987 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5988 &task_graph_runner
);
5989 host_impl
.CreatePendingTree();
5990 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
5991 scoped_ptr
<LayerImpl
> container
=
5992 LayerImpl::Create(host_impl
.active_tree(), 2);
5993 LayerImpl
* container_layer
= container
.get();
5994 scoped_ptr
<LayerImpl
> scroller
=
5995 LayerImpl::Create(host_impl
.active_tree(), 3);
5996 LayerImpl
* scroll_layer
= scroller
.get();
5997 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
5998 LayerImpl
* fixed_layer
= fixed
.get();
6000 container
->SetIsContainerForFixedPositionLayers(true);
6002 LayerPositionConstraint constraint
;
6003 constraint
.set_is_fixed_position(true);
6004 fixed
->SetPositionConstraint(constraint
);
6006 scroller
->SetScrollClipLayer(container
->id());
6008 gfx::Transform identity_transform
;
6009 gfx::Transform container_transform
;
6010 container_transform
.Translate3d(10.0, 20.0, 0.0);
6011 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
6013 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
6014 gfx::PointF(), gfx::Size(50, 50), true, false,
6016 SetLayerPropertiesForTesting(container
.get(), container_transform
,
6017 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6018 true, false, false);
6019 SetLayerPropertiesForTesting(scroller
.get(), identity_transform
,
6020 gfx::Point3F(), gfx::PointF(0.0, 0.0),
6021 gfx::Size(30, 30), true, false, false);
6023 gfx::ScrollOffset
scroll_offset(3.3, 4.2);
6024 gfx::Vector2dF
main_scroll_fractional_part(0.3f
, 0.2f
);
6025 gfx::Vector2dF
scroll_delta(0.1f
, 0.4f
);
6026 // Blink only uses the integer part of the scroll_offset for fixed
6028 SetLayerPropertiesForTesting(fixed
.get(), identity_transform
, gfx::Point3F(),
6029 gfx::PointF(3.0f
, 4.0f
), gfx::Size(50, 50), true,
6031 scroll_layer
->PushScrollOffsetFromMainThread(scroll_offset
);
6032 scroll_layer
->SetScrollDelta(scroll_delta
);
6033 scroll_layer
->SetScrollCompensationAdjustment(main_scroll_fractional_part
);
6035 scroller
->AddChild(fixed
.Pass());
6036 container
->AddChild(scroller
.Pass());
6037 root
->AddChild(container
.Pass());
6039 LayerImplList render_surface_layer_list
;
6040 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6041 root
.get(), root
->bounds(), &render_surface_layer_list
);
6042 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6044 EXPECT_TRANSFORMATION_MATRIX_EQ(
6045 container_layer
->draw_properties().screen_space_transform
,
6046 fixed_layer
->draw_properties().screen_space_transform
);
6048 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
6051 gfx::ScrollOffset effective_scroll_offset
=
6052 ScrollOffsetWithDelta(scroll_offset
, scroll_delta
);
6053 gfx::Vector2d rounded_effective_scroll_offset
=
6054 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset
));
6056 scroll_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
6057 container_offset
- rounded_effective_scroll_offset
);
6060 TEST_F(LayerTreeHostCommonTest
,
6061 ScrollSnappingWithAnimatedScreenSpaceTransform
) {
6062 // This test verifies that a scrolling layer whose screen space transform is
6063 // animating doesn't get snapped to integer coordinates.
6071 LayerImpl
* root
= root_layer();
6072 LayerImpl
* animated_layer
= AddChildToRoot
<FakePictureLayerImpl
>();
6073 LayerImpl
* surface
= AddChild
<LayerImpl
>(animated_layer
);
6074 LayerImpl
* container
= AddChild
<LayerImpl
>(surface
);
6075 LayerImpl
* scroller
= AddChild
<LayerImpl
>(container
);
6076 scroller
->SetScrollClipLayer(container
->id());
6077 scroller
->SetDrawsContent(true);
6079 gfx::Transform identity_transform
;
6080 gfx::Transform start_scale
;
6081 start_scale
.Scale(1.5f
, 1.5f
);
6082 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
6083 gfx::PointF(), gfx::Size(50, 50), true, false,
6085 SetLayerPropertiesForTesting(animated_layer
, start_scale
, gfx::Point3F(),
6086 gfx::PointF(), gfx::Size(50, 50), true, false,
6088 SetLayerPropertiesForTesting(surface
, identity_transform
, gfx::Point3F(),
6089 gfx::PointF(), gfx::Size(50, 50), true, false,
6091 SetLayerPropertiesForTesting(container
, identity_transform
, gfx::Point3F(),
6092 gfx::PointF(), gfx::Size(50, 50), true, false,
6094 SetLayerPropertiesForTesting(scroller
, identity_transform
, gfx::Point3F(),
6095 gfx::PointF(), gfx::Size(100, 100), true, false,
6098 gfx::Transform end_scale
;
6099 end_scale
.Scale(2.f
, 2.f
);
6100 TransformOperations start_operations
;
6101 start_operations
.AppendMatrix(start_scale
);
6102 TransformOperations end_operations
;
6103 end_operations
.AppendMatrix(end_scale
);
6104 AddAnimatedTransformToLayer(animated_layer
, 1.0, start_operations
,
6107 gfx::Vector2dF
scroll_delta(5.f
, 9.f
);
6108 scroller
->SetScrollDelta(scroll_delta
);
6110 ExecuteCalculateDrawProperties(root
);
6112 gfx::Vector2dF
expected_draw_transform_translation(-7.5f
, -13.5f
);
6113 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation
,
6114 scroller
->draw_transform().To2dTranslation());
6117 class AnimationScaleFactorTrackingLayerImpl
: public LayerImpl
{
6119 static scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> Create(
6120 LayerTreeImpl
* tree_impl
,
6122 return make_scoped_ptr(
6123 new AnimationScaleFactorTrackingLayerImpl(tree_impl
, id
));
6126 ~AnimationScaleFactorTrackingLayerImpl() override
{}
6129 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl
* tree_impl
,
6131 : LayerImpl(tree_impl
, id
) {
6132 SetDrawsContent(true);
6136 TEST_F(LayerTreeHostCommonTest
, MaximumAnimationScaleFactor
) {
6137 FakeImplProxy proxy
;
6138 TestSharedBitmapManager shared_bitmap_manager
;
6139 TestTaskGraphRunner task_graph_runner
;
6140 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
6141 &task_graph_runner
);
6142 gfx::Transform identity_matrix
;
6143 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_parent
=
6144 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 1);
6145 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> parent
=
6146 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 2);
6147 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> child
=
6148 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 3);
6149 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_child
=
6150 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 4);
6152 AnimationScaleFactorTrackingLayerImpl
* parent_raw
= parent
.get();
6153 AnimationScaleFactorTrackingLayerImpl
* child_raw
= child
.get();
6154 AnimationScaleFactorTrackingLayerImpl
* grand_child_raw
= grand_child
.get();
6156 child
->AddChild(grand_child
.Pass());
6157 parent
->AddChild(child
.Pass());
6158 grand_parent
->AddChild(parent
.Pass());
6160 SetLayerPropertiesForTesting(grand_parent
.get(), identity_matrix
,
6161 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6163 SetLayerPropertiesForTesting(parent_raw
, identity_matrix
, gfx::Point3F(),
6164 gfx::PointF(), gfx::Size(1, 2), true, false,
6166 SetLayerPropertiesForTesting(child_raw
, identity_matrix
, gfx::Point3F(),
6167 gfx::PointF(), gfx::Size(1, 2), true, false,
6170 SetLayerPropertiesForTesting(grand_child_raw
, identity_matrix
, gfx::Point3F(),
6171 gfx::PointF(), gfx::Size(1, 2), true, false,
6174 ExecuteCalculateDrawProperties(grand_parent
.get());
6176 // No layers have animations.
6178 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6180 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6181 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6183 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6185 TransformOperations translation
;
6186 translation
.AppendTranslate(1.f
, 2.f
, 3.f
);
6188 AddAnimatedTransformToLayer(
6189 parent_raw
, 1.0, TransformOperations(), translation
);
6191 // No layers have scale-affecting animations.
6193 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6195 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6196 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6198 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6200 TransformOperations scale
;
6201 scale
.AppendScale(5.f
, 4.f
, 3.f
);
6203 AddAnimatedTransformToLayer(child_raw
, 1.0, TransformOperations(), scale
);
6204 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6205 ExecuteCalculateDrawProperties(grand_parent
.get());
6207 // Only |child| has a scale-affecting animation.
6209 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6211 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6212 EXPECT_EQ(5.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6214 5.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6216 AddAnimatedTransformToLayer(
6217 grand_parent
.get(), 1.0, TransformOperations(), scale
);
6218 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6219 ExecuteCalculateDrawProperties(grand_parent
.get());
6221 // |grand_parent| and |child| have scale-affecting animations.
6223 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6225 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6226 // We don't support combining animated scales from two nodes; 0.f means
6227 // that the maximum scale could not be computed.
6228 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6230 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6232 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
6233 parent_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6234 ExecuteCalculateDrawProperties(grand_parent
.get());
6236 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
6238 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6240 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6241 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6243 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6245 grand_parent
->layer_animation_controller()->AbortAnimations(
6246 Animation::TRANSFORM
);
6247 parent_raw
->layer_animation_controller()->AbortAnimations(
6248 Animation::TRANSFORM
);
6249 child_raw
->layer_animation_controller()->AbortAnimations(
6250 Animation::TRANSFORM
);
6252 TransformOperations perspective
;
6253 perspective
.AppendPerspective(10.f
);
6255 AddAnimatedTransformToLayer(
6256 child_raw
, 1.0, TransformOperations(), perspective
);
6257 ExecuteCalculateDrawProperties(grand_parent
.get());
6259 // |child| has a scale-affecting animation but computing the maximum of this
6260 // animation is not supported.
6262 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6264 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6265 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6267 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6269 child_raw
->layer_animation_controller()->AbortAnimations(
6270 Animation::TRANSFORM
);
6272 gfx::Transform scale_matrix
;
6273 scale_matrix
.Scale(1.f
, 2.f
);
6274 grand_parent
->SetTransform(scale_matrix
);
6275 parent_raw
->SetTransform(scale_matrix
);
6276 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6277 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
6278 ExecuteCalculateDrawProperties(grand_parent
.get());
6280 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
6281 // animation with maximum scale 5.f.
6283 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6285 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6287 child_raw
->draw_properties().maximum_animation_contents_scale
);
6290 grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6292 gfx::Transform perspective_matrix
;
6293 perspective_matrix
.ApplyPerspectiveDepth(2.f
);
6294 child_raw
->SetTransform(perspective_matrix
);
6295 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6296 ExecuteCalculateDrawProperties(grand_parent
.get());
6298 // |child| has a transform that's neither a translation nor a scale.
6300 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6302 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6303 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6305 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6307 parent_raw
->SetTransform(perspective_matrix
);
6308 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6309 ExecuteCalculateDrawProperties(grand_parent
.get());
6311 // |parent| and |child| have transforms that are neither translations nor
6314 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6316 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6317 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6319 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6321 parent_raw
->SetTransform(identity_matrix
);
6322 child_raw
->SetTransform(identity_matrix
);
6323 grand_parent
->SetTransform(perspective_matrix
);
6324 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6326 ExecuteCalculateDrawProperties(grand_parent
.get());
6328 // |grand_parent| has a transform that's neither a translation nor a scale.
6330 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6332 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6333 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6335 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6338 static int membership_id(LayerImpl
* layer
) {
6339 return layer
->draw_properties().last_drawn_render_surface_layer_list_id
;
6342 static void GatherDrawnLayers(LayerImplList
* rsll
,
6343 std::set
<LayerImpl
*>* drawn_layers
) {
6344 for (LayerIterator it
= LayerIterator::Begin(rsll
),
6345 end
= LayerIterator::End(rsll
);
6347 LayerImpl
* layer
= *it
;
6348 if (it
.represents_itself())
6349 drawn_layers
->insert(layer
);
6351 if (!it
.represents_contributing_render_surface())
6354 if (layer
->mask_layer())
6355 drawn_layers
->insert(layer
->mask_layer());
6356 if (layer
->replica_layer() && layer
->replica_layer()->mask_layer())
6357 drawn_layers
->insert(layer
->replica_layer()->mask_layer());
6361 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceLayerListMembership
) {
6362 FakeImplProxy proxy
;
6363 TestSharedBitmapManager shared_bitmap_manager
;
6364 TestTaskGraphRunner task_graph_runner
;
6365 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
6366 &task_graph_runner
);
6367 gfx::Transform identity_matrix
;
6369 scoped_ptr
<LayerImpl
> grand_parent
=
6370 LayerImpl::Create(host_impl
.active_tree(), 1);
6371 scoped_ptr
<LayerImpl
> parent
= LayerImpl::Create(host_impl
.active_tree(), 3);
6372 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 5);
6373 scoped_ptr
<LayerImpl
> grand_child1
=
6374 LayerImpl::Create(host_impl
.active_tree(), 7);
6375 scoped_ptr
<LayerImpl
> grand_child2
=
6376 LayerImpl::Create(host_impl
.active_tree(), 9);
6378 LayerImpl
* grand_parent_raw
= grand_parent
.get();
6379 LayerImpl
* parent_raw
= parent
.get();
6380 LayerImpl
* child_raw
= child
.get();
6381 LayerImpl
* grand_child1_raw
= grand_child1
.get();
6382 LayerImpl
* grand_child2_raw
= grand_child2
.get();
6384 child
->AddChild(grand_child1
.Pass());
6385 child
->AddChild(grand_child2
.Pass());
6386 parent
->AddChild(child
.Pass());
6387 grand_parent
->AddChild(parent
.Pass());
6389 SetLayerPropertiesForTesting(grand_parent_raw
, identity_matrix
,
6390 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6392 SetLayerPropertiesForTesting(parent_raw
, identity_matrix
, gfx::Point3F(),
6393 gfx::PointF(), gfx::Size(1, 2), true, false,
6396 SetLayerPropertiesForTesting(child_raw
, identity_matrix
, gfx::Point3F(),
6397 gfx::PointF(), gfx::Size(1, 2), true, false,
6400 SetLayerPropertiesForTesting(grand_child1_raw
, identity_matrix
,
6401 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6402 true, false, false);
6404 SetLayerPropertiesForTesting(grand_child2_raw
, identity_matrix
,
6405 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6406 true, false, false);
6408 // Start with nothing being drawn.
6409 ExecuteCalculateDrawProperties(grand_parent_raw
);
6410 int member_id
= render_surface_layer_list_count();
6412 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6413 EXPECT_NE(member_id
, membership_id(parent_raw
));
6414 EXPECT_NE(member_id
, membership_id(child_raw
));
6415 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6416 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6418 std::set
<LayerImpl
*> expected
;
6419 std::set
<LayerImpl
*> actual
;
6420 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6421 EXPECT_EQ(expected
, actual
);
6423 // If we force render surface, but none of the layers are in the layer list,
6424 // then this layer should not appear in RSLL.
6425 grand_child1_raw
->SetHasRenderSurface(true);
6426 grand_child1_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6428 ExecuteCalculateDrawProperties(grand_parent_raw
);
6429 member_id
= render_surface_layer_list_count();
6431 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6432 EXPECT_NE(member_id
, membership_id(parent_raw
));
6433 EXPECT_NE(member_id
, membership_id(child_raw
));
6434 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6435 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6439 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6440 EXPECT_EQ(expected
, actual
);
6442 // However, if we say that this layer also draws content, it will appear in
6444 grand_child1_raw
->SetDrawsContent(true);
6446 ExecuteCalculateDrawProperties(grand_parent_raw
);
6447 member_id
= render_surface_layer_list_count();
6449 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6450 EXPECT_NE(member_id
, membership_id(parent_raw
));
6451 EXPECT_NE(member_id
, membership_id(child_raw
));
6452 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
6453 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6456 expected
.insert(grand_child1_raw
);
6459 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6460 EXPECT_EQ(expected
, actual
);
6462 // Now child is forced to have a render surface, and one if its children draws
6464 grand_child1_raw
->SetDrawsContent(false);
6465 grand_child1_raw
->SetHasRenderSurface(false);
6466 grand_child1_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6467 child_raw
->SetHasRenderSurface(true);
6468 grand_child2_raw
->SetDrawsContent(true);
6470 ExecuteCalculateDrawProperties(grand_parent_raw
);
6471 member_id
= render_surface_layer_list_count();
6473 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6474 EXPECT_NE(member_id
, membership_id(parent_raw
));
6475 EXPECT_NE(member_id
, membership_id(child_raw
));
6476 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6477 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6480 expected
.insert(grand_child2_raw
);
6483 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6484 EXPECT_EQ(expected
, actual
);
6486 // Add a mask layer to child.
6487 child_raw
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6).Pass());
6488 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6490 ExecuteCalculateDrawProperties(grand_parent_raw
);
6491 member_id
= render_surface_layer_list_count();
6493 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6494 EXPECT_NE(member_id
, membership_id(parent_raw
));
6495 EXPECT_NE(member_id
, membership_id(child_raw
));
6496 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
6497 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6498 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6501 expected
.insert(grand_child2_raw
);
6502 expected
.insert(child_raw
->mask_layer());
6505 expected
.insert(grand_child2_raw
);
6506 expected
.insert(child_raw
->mask_layer());
6509 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6510 EXPECT_EQ(expected
, actual
);
6512 // Add replica mask layer.
6513 scoped_ptr
<LayerImpl
> replica_layer
=
6514 LayerImpl::Create(host_impl
.active_tree(), 20);
6515 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 21));
6516 child_raw
->SetReplicaLayer(replica_layer
.Pass());
6518 ExecuteCalculateDrawProperties(grand_parent_raw
);
6519 member_id
= render_surface_layer_list_count();
6521 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6522 EXPECT_NE(member_id
, membership_id(parent_raw
));
6523 EXPECT_NE(member_id
, membership_id(child_raw
));
6524 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
6525 EXPECT_EQ(member_id
, membership_id(child_raw
->replica_layer()->mask_layer()));
6526 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6527 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6530 expected
.insert(grand_child2_raw
);
6531 expected
.insert(child_raw
->mask_layer());
6532 expected
.insert(child_raw
->replica_layer()->mask_layer());
6535 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6536 EXPECT_EQ(expected
, actual
);
6538 child_raw
->TakeReplicaLayer();
6540 // With nothing drawing, we should have no layers.
6541 grand_child2_raw
->SetDrawsContent(false);
6543 ExecuteCalculateDrawProperties(grand_parent_raw
);
6544 member_id
= render_surface_layer_list_count();
6546 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6547 EXPECT_NE(member_id
, membership_id(parent_raw
));
6548 EXPECT_NE(member_id
, membership_id(child_raw
));
6549 EXPECT_NE(member_id
, membership_id(child_raw
->mask_layer()));
6550 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6551 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6555 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6556 EXPECT_EQ(expected
, actual
);
6558 // Child itself draws means that we should have the child and the mask in the
6560 child_raw
->SetDrawsContent(true);
6562 ExecuteCalculateDrawProperties(grand_parent_raw
);
6563 member_id
= render_surface_layer_list_count();
6565 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6566 EXPECT_NE(member_id
, membership_id(parent_raw
));
6567 EXPECT_EQ(member_id
, membership_id(child_raw
));
6568 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
6569 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6570 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6573 expected
.insert(child_raw
);
6574 expected
.insert(child_raw
->mask_layer());
6576 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6577 EXPECT_EQ(expected
, actual
);
6579 child_raw
->TakeMaskLayer();
6580 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6582 // Now everyone's a member!
6583 grand_parent_raw
->SetDrawsContent(true);
6584 parent_raw
->SetDrawsContent(true);
6585 child_raw
->SetDrawsContent(true);
6586 grand_child1_raw
->SetDrawsContent(true);
6587 grand_child2_raw
->SetDrawsContent(true);
6589 ExecuteCalculateDrawProperties(grand_parent_raw
);
6590 member_id
= render_surface_layer_list_count();
6592 EXPECT_EQ(member_id
, membership_id(grand_parent_raw
));
6593 EXPECT_EQ(member_id
, membership_id(parent_raw
));
6594 EXPECT_EQ(member_id
, membership_id(child_raw
));
6595 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
6596 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6599 expected
.insert(grand_parent_raw
);
6600 expected
.insert(parent_raw
);
6601 expected
.insert(child_raw
);
6602 expected
.insert(grand_child1_raw
);
6603 expected
.insert(grand_child2_raw
);
6606 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6607 EXPECT_EQ(expected
, actual
);
6610 TEST_F(LayerTreeHostCommonTest
, DrawPropertyScales
) {
6611 FakeImplProxy proxy
;
6612 TestSharedBitmapManager shared_bitmap_manager
;
6613 TestTaskGraphRunner task_graph_runner
;
6614 LayerTreeSettings settings
;
6615 settings
.layer_transforms_should_scale_layer_contents
= true;
6616 FakeLayerTreeHostImpl
host_impl(settings
, &proxy
, &shared_bitmap_manager
,
6617 &task_graph_runner
);
6619 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
6620 LayerImpl
* root_layer
= root
.get();
6621 scoped_ptr
<LayerImpl
> child1
= LayerImpl::Create(host_impl
.active_tree(), 2);
6622 LayerImpl
* child1_layer
= child1
.get();
6623 scoped_ptr
<LayerImpl
> child2
= LayerImpl::Create(host_impl
.active_tree(), 3);
6624 LayerImpl
* child2_layer
= child2
.get();
6626 root
->AddChild(child1
.Pass());
6627 root
->AddChild(child2
.Pass());
6628 root
->SetHasRenderSurface(true);
6630 gfx::Transform identity_matrix
, scale_transform_child1
,
6631 scale_transform_child2
;
6632 scale_transform_child1
.Scale(2, 3);
6633 scale_transform_child2
.Scale(4, 5);
6635 SetLayerPropertiesForTesting(root_layer
, identity_matrix
, gfx::Point3F(),
6636 gfx::PointF(), gfx::Size(1, 1), true, false,
6638 SetLayerPropertiesForTesting(child1_layer
, scale_transform_child1
,
6639 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
6642 child1_layer
->SetMaskLayer(
6643 LayerImpl::Create(host_impl
.active_tree(), 4).Pass());
6645 scoped_ptr
<LayerImpl
> replica_layer
=
6646 LayerImpl::Create(host_impl
.active_tree(), 5);
6647 replica_layer
->SetHasRenderSurface(true);
6648 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6));
6649 child1_layer
->SetReplicaLayer(replica_layer
.Pass());
6650 child1_layer
->SetHasRenderSurface(true);
6652 ExecuteCalculateDrawProperties(root_layer
);
6654 TransformOperations scale
;
6655 scale
.AppendScale(5.f
, 8.f
, 3.f
);
6657 AddAnimatedTransformToLayer(child2_layer
, 1.0, TransformOperations(), scale
);
6658 SetLayerPropertiesForTesting(child2_layer
, scale_transform_child2
,
6659 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
6662 ExecuteCalculateDrawProperties(root_layer
);
6664 EXPECT_FLOAT_EQ(1.f
, root_layer
->GetIdealContentsScale());
6665 EXPECT_FLOAT_EQ(3.f
, child1_layer
->GetIdealContentsScale());
6666 EXPECT_FLOAT_EQ(3.f
, child1_layer
->mask_layer()->GetIdealContentsScale());
6667 EXPECT_FLOAT_EQ(5.f
, child2_layer
->GetIdealContentsScale());
6670 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
6672 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
6673 EXPECT_FLOAT_EQ(0.f
,
6674 child1_layer
->mask_layer()
6676 .maximum_animation_contents_scale
);
6677 EXPECT_FLOAT_EQ(0.f
,
6678 child1_layer
->replica_layer()
6681 .maximum_animation_contents_scale
);
6683 8.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
6685 // Changing page-scale would affect ideal_contents_scale and
6686 // maximum_animation_contents_scale.
6688 float page_scale_factor
= 3.f
;
6689 float device_scale_factor
= 1.0f
;
6690 std::vector
<LayerImpl
*> render_surface_layer_list
;
6691 gfx::Size device_viewport_size
=
6692 gfx::Size(root_layer
->bounds().width() * device_scale_factor
,
6693 root_layer
->bounds().height() * device_scale_factor
);
6694 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6695 root_layer
, device_viewport_size
, &render_surface_layer_list
);
6697 inputs
.page_scale_factor
= page_scale_factor
;
6698 inputs
.can_adjust_raster_scales
= true;
6699 inputs
.page_scale_layer
= root_layer
;
6700 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6702 EXPECT_FLOAT_EQ(3.f
, root_layer
->GetIdealContentsScale());
6703 EXPECT_FLOAT_EQ(9.f
, child1_layer
->GetIdealContentsScale());
6704 EXPECT_FLOAT_EQ(9.f
, child1_layer
->mask_layer()->GetIdealContentsScale());
6707 child1_layer
->replica_layer()->mask_layer()->GetIdealContentsScale());
6708 EXPECT_FLOAT_EQ(15.f
, child2_layer
->GetIdealContentsScale());
6711 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
6713 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
6714 EXPECT_FLOAT_EQ(0.f
,
6715 child1_layer
->mask_layer()
6717 .maximum_animation_contents_scale
);
6718 EXPECT_FLOAT_EQ(0.f
,
6719 child1_layer
->replica_layer()
6722 .maximum_animation_contents_scale
);
6724 24.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
6726 // Changing device-scale would affect ideal_contents_scale and
6727 // maximum_animation_contents_scale.
6729 device_scale_factor
= 4.0f
;
6730 inputs
.device_scale_factor
= device_scale_factor
;
6731 inputs
.can_adjust_raster_scales
= true;
6732 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6734 EXPECT_FLOAT_EQ(12.f
, root_layer
->GetIdealContentsScale());
6735 EXPECT_FLOAT_EQ(36.f
, child1_layer
->GetIdealContentsScale());
6736 EXPECT_FLOAT_EQ(36.f
, child1_layer
->mask_layer()->GetIdealContentsScale());
6739 child1_layer
->replica_layer()->mask_layer()->GetIdealContentsScale());
6740 EXPECT_FLOAT_EQ(60.f
, child2_layer
->GetIdealContentsScale());
6743 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
6745 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
6746 EXPECT_FLOAT_EQ(0.f
,
6747 child1_layer
->mask_layer()
6749 .maximum_animation_contents_scale
);
6750 EXPECT_FLOAT_EQ(0.f
,
6751 child1_layer
->replica_layer()
6754 .maximum_animation_contents_scale
);
6756 96.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
6759 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInChildRenderSurface
) {
6760 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6761 SetLayerPropertiesForTesting(root
.get(),
6765 gfx::Size(768 / 2, 3000),
6768 root
->SetIsDrawable(true);
6770 scoped_refptr
<Layer
> clip
= Layer::Create(layer_settings());
6771 SetLayerPropertiesForTesting(clip
.get(),
6775 gfx::Size(768 / 2, 10000),
6778 clip
->SetMasksToBounds(true);
6780 scoped_refptr
<Layer
> content
= Layer::Create(layer_settings());
6781 SetLayerPropertiesForTesting(content
.get(),
6785 gfx::Size(768 / 2, 10000),
6788 content
->SetIsDrawable(true);
6789 content
->SetForceRenderSurface(true);
6791 root
->AddChild(clip
);
6792 clip
->AddChild(content
);
6794 host()->SetRootLayer(root
);
6796 gfx::Size
device_viewport_size(768, 582);
6797 RenderSurfaceLayerList render_surface_layer_list
;
6798 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6799 host()->root_layer(), device_viewport_size
, &render_surface_layer_list
);
6800 inputs
.device_scale_factor
= 2.f
;
6801 inputs
.page_scale_factor
= 1.f
;
6802 inputs
.page_scale_layer
= NULL
;
6803 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6805 // Layers in the root render surface have their visible content rect clipped
6807 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
6808 root
->visible_rect_from_property_trees());
6810 // Layers drawing to a child render surface should still have their visible
6811 // content rect clipped by the viewport.
6812 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
6813 content
->visible_rect_from_property_trees());
6816 TEST_F(LayerTreeHostCommonTest
, BoundsDeltaAffectVisibleContentRect
) {
6817 FakeImplProxy proxy
;
6818 TestSharedBitmapManager shared_bitmap_manager
;
6819 TestTaskGraphRunner task_graph_runner
;
6820 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
6821 &task_graph_runner
);
6823 // Set two layers: the root layer clips it's child,
6824 // the child draws its content.
6826 gfx::Size root_size
= gfx::Size(300, 500);
6828 // Sublayer should be bigger than the root enlarged by bounds_delta.
6829 gfx::Size sublayer_size
= gfx::Size(300, 1000);
6831 // Device viewport accomidated the root and the top controls.
6832 gfx::Size device_viewport_size
= gfx::Size(300, 600);
6833 gfx::Transform identity_matrix
;
6835 host_impl
.SetViewportSize(device_viewport_size
);
6836 host_impl
.active_tree()->SetRootLayer(
6837 LayerImpl::Create(host_impl
.active_tree(), 1));
6839 LayerImpl
* root
= host_impl
.active_tree()->root_layer();
6840 SetLayerPropertiesForTesting(root
,
6848 root
->SetMasksToBounds(true);
6850 root
->AddChild(LayerImpl::Create(host_impl
.active_tree(), 2));
6852 LayerImpl
* sublayer
= root
->child_at(0);
6853 SetLayerPropertiesForTesting(sublayer
,
6861 sublayer
->SetDrawsContent(true);
6863 LayerImplList layer_impl_list
;
6864 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6865 root
, device_viewport_size
, &layer_impl_list
);
6867 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6868 EXPECT_EQ(gfx::Rect(root_size
), sublayer
->visible_layer_rect());
6870 root
->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
6871 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6873 gfx::Rect
affected_by_delta(0, 0, root_size
.width(),
6874 root_size
.height() + 50);
6875 EXPECT_EQ(affected_by_delta
, sublayer
->visible_layer_rect());
6878 TEST_F(LayerTreeHostCommonTest
, NodesAffectedByBoundsDeltaGetUpdated
) {
6879 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6880 scoped_refptr
<Layer
> inner_viewport_container_layer
=
6881 Layer::Create(layer_settings());
6882 scoped_refptr
<Layer
> inner_viewport_scroll_layer
=
6883 Layer::Create(layer_settings());
6884 scoped_refptr
<Layer
> outer_viewport_container_layer
=
6885 Layer::Create(layer_settings());
6886 scoped_refptr
<Layer
> outer_viewport_scroll_layer
=
6887 Layer::Create(layer_settings());
6889 root
->AddChild(inner_viewport_container_layer
);
6890 inner_viewport_container_layer
->AddChild(inner_viewport_scroll_layer
);
6891 inner_viewport_scroll_layer
->AddChild(outer_viewport_container_layer
);
6892 outer_viewport_container_layer
->AddChild(outer_viewport_scroll_layer
);
6894 inner_viewport_scroll_layer
->SetScrollClipLayerId(
6895 inner_viewport_container_layer
->id());
6896 outer_viewport_scroll_layer
->SetScrollClipLayerId(
6897 outer_viewport_container_layer
->id());
6899 inner_viewport_scroll_layer
->SetIsContainerForFixedPositionLayers(true);
6900 outer_viewport_scroll_layer
->SetIsContainerForFixedPositionLayers(true);
6902 host()->SetRootLayer(root
);
6903 host()->RegisterViewportLayers(nullptr, root
, inner_viewport_scroll_layer
,
6904 outer_viewport_scroll_layer
);
6906 scoped_refptr
<Layer
> fixed_to_inner
= Layer::Create(layer_settings());
6907 scoped_refptr
<Layer
> fixed_to_outer
= Layer::Create(layer_settings());
6909 inner_viewport_scroll_layer
->AddChild(fixed_to_inner
);
6910 outer_viewport_scroll_layer
->AddChild(fixed_to_outer
);
6912 LayerPositionConstraint fixed_to_right
;
6913 fixed_to_right
.set_is_fixed_position(true);
6914 fixed_to_right
.set_is_fixed_to_right_edge(true);
6916 fixed_to_inner
->SetPositionConstraint(fixed_to_right
);
6917 fixed_to_outer
->SetPositionConstraint(fixed_to_right
);
6919 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6921 TransformTree
& transform_tree
= host()->property_trees()->transform_tree
;
6922 EXPECT_TRUE(transform_tree
.HasNodesAffectedByInnerViewportBoundsDelta());
6923 EXPECT_TRUE(transform_tree
.HasNodesAffectedByOuterViewportBoundsDelta());
6925 LayerPositionConstraint fixed_to_left
;
6926 fixed_to_left
.set_is_fixed_position(true);
6927 fixed_to_inner
->SetPositionConstraint(fixed_to_left
);
6929 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6930 EXPECT_FALSE(transform_tree
.HasNodesAffectedByInnerViewportBoundsDelta());
6931 EXPECT_TRUE(transform_tree
.HasNodesAffectedByOuterViewportBoundsDelta());
6933 fixed_to_outer
->SetPositionConstraint(fixed_to_left
);
6935 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6936 EXPECT_FALSE(transform_tree
.HasNodesAffectedByInnerViewportBoundsDelta());
6937 EXPECT_FALSE(transform_tree
.HasNodesAffectedByOuterViewportBoundsDelta());
6940 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectForAnimatedLayer
) {
6941 const gfx::Transform identity_matrix
;
6942 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6943 scoped_refptr
<LayerWithForcedDrawsContent
> animated
=
6944 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6946 root
->AddChild(animated
);
6948 host()->SetRootLayer(root
);
6950 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
6951 gfx::PointF(), gfx::Size(100, 100), true, false);
6952 SetLayerPropertiesForTesting(animated
.get(), identity_matrix
, gfx::Point3F(),
6953 gfx::PointF(), gfx::Size(20, 20), true, false);
6955 root
->SetMasksToBounds(true);
6956 root
->SetForceRenderSurface(true);
6957 animated
->SetOpacity(0.f
);
6959 AddOpacityTransitionToController(animated
->layer_animation_controller(), 10.0,
6962 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6964 EXPECT_FALSE(animated
->visible_rect_from_property_trees().IsEmpty());
6967 TEST_F(LayerTreeHostCommonTest
,
6968 VisibleContentRectForAnimatedLayerWithSingularTransform
) {
6969 const gfx::Transform identity_matrix
;
6970 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6971 scoped_refptr
<Layer
> clip
= Layer::Create(layer_settings());
6972 scoped_refptr
<LayerWithForcedDrawsContent
> animated
=
6973 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6974 scoped_refptr
<LayerWithForcedDrawsContent
> surface
=
6975 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6976 scoped_refptr
<LayerWithForcedDrawsContent
> descendant_of_animation
=
6977 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6979 root
->AddChild(clip
);
6980 clip
->AddChild(animated
);
6981 animated
->AddChild(surface
);
6982 surface
->AddChild(descendant_of_animation
);
6984 clip
->SetMasksToBounds(true);
6985 surface
->SetForceRenderSurface(true);
6987 host()->SetRootLayer(root
);
6989 gfx::Transform uninvertible_matrix
;
6990 uninvertible_matrix
.Scale3d(6.f
, 6.f
, 0.f
);
6992 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
6993 gfx::PointF(), gfx::Size(100, 100), true, false);
6994 SetLayerPropertiesForTesting(clip
.get(), identity_matrix
, gfx::Point3F(),
6995 gfx::PointF(), gfx::Size(10, 10), true, false);
6996 SetLayerPropertiesForTesting(animated
.get(), uninvertible_matrix
,
6997 gfx::Point3F(), gfx::PointF(),
6998 gfx::Size(120, 120), true, false);
6999 SetLayerPropertiesForTesting(surface
.get(), identity_matrix
, gfx::Point3F(),
7000 gfx::PointF(), gfx::Size(100, 100), true, false);
7001 SetLayerPropertiesForTesting(descendant_of_animation
.get(), identity_matrix
,
7002 gfx::Point3F(), gfx::PointF(),
7003 gfx::Size(200, 200), true, false);
7005 TransformOperations start_transform_operations
;
7006 start_transform_operations
.AppendMatrix(uninvertible_matrix
);
7007 TransformOperations end_transform_operations
;
7009 AddAnimatedTransformToLayer(animated
.get(), 10.0, start_transform_operations
,
7010 end_transform_operations
);
7012 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7014 // The animated layer has a singular transform and maps to a non-empty rect in
7015 // clipped target space, so is treated as fully visible.
7016 EXPECT_EQ(gfx::Rect(120, 120), animated
->visible_rect_from_property_trees());
7018 // The singular transform on |animated| is flattened when inherited by
7019 // |surface|, and this happens to make it invertible.
7020 EXPECT_EQ(gfx::Rect(2, 2), surface
->visible_rect_from_property_trees());
7021 EXPECT_EQ(gfx::Rect(2, 2),
7022 descendant_of_animation
->visible_rect_from_property_trees());
7024 gfx::Transform zero_matrix
;
7025 zero_matrix
.Scale3d(0.f
, 0.f
, 0.f
);
7026 SetLayerPropertiesForTesting(animated
.get(), zero_matrix
, gfx::Point3F(),
7027 gfx::PointF(), gfx::Size(120, 120), true, false);
7029 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7031 // The animated layer maps to the empty rect in clipped target space, so is
7032 // treated as having an empty visible rect.
7033 EXPECT_EQ(gfx::Rect(), animated
->visible_rect_from_property_trees());
7035 // This time, flattening does not make |animated|'s transform invertible. This
7036 // means the clip cannot be projected into |surface|'s space, so we treat
7037 // |surface| and layers that draw into it as having empty visible rect.
7038 EXPECT_EQ(gfx::Rect(), surface
->visible_rect_from_property_trees());
7039 EXPECT_EQ(gfx::Rect(),
7040 descendant_of_animation
->visible_rect_from_property_trees());
7043 // Verify that having an animated filter (but no current filter, as these
7044 // are mutually exclusive) correctly creates a render surface.
7045 TEST_F(LayerTreeHostCommonTest
, AnimatedFilterCreatesRenderSurface
) {
7046 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7047 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7048 scoped_refptr
<Layer
> grandchild
= Layer::Create(layer_settings());
7049 root
->AddChild(child
);
7050 child
->AddChild(grandchild
);
7052 gfx::Transform identity_transform
;
7053 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7054 gfx::PointF(), gfx::Size(50, 50), true, false);
7055 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7056 gfx::PointF(), gfx::Size(50, 50), true, false);
7057 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7058 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7060 host()->SetRootLayer(root
);
7062 AddAnimatedFilterToLayer(child
.get(), 10.0, 0.1f
, 0.2f
);
7064 ExecuteCalculateDrawProperties(root
.get());
7066 EXPECT_TRUE(root
->render_surface());
7067 EXPECT_TRUE(child
->render_surface());
7068 EXPECT_FALSE(grandchild
->render_surface());
7070 EXPECT_TRUE(root
->filters().IsEmpty());
7071 EXPECT_TRUE(child
->filters().IsEmpty());
7072 EXPECT_TRUE(grandchild
->filters().IsEmpty());
7074 EXPECT_FALSE(root
->FilterIsAnimating());
7075 EXPECT_TRUE(child
->FilterIsAnimating());
7076 EXPECT_FALSE(grandchild
->FilterIsAnimating());
7079 // Verify that having a filter animation with a delayed start time creates a
7081 TEST_F(LayerTreeHostCommonTest
, DelayedFilterAnimationCreatesRenderSurface
) {
7082 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7083 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7084 scoped_refptr
<Layer
> grandchild
= Layer::Create(layer_settings());
7085 root
->AddChild(child
);
7086 child
->AddChild(grandchild
);
7088 gfx::Transform identity_transform
;
7089 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7090 gfx::PointF(), gfx::Size(50, 50), true, false);
7091 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7092 gfx::PointF(), gfx::Size(50, 50), true, false);
7093 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7094 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7096 host()->SetRootLayer(root
);
7098 scoped_ptr
<KeyframedFilterAnimationCurve
> curve(
7099 KeyframedFilterAnimationCurve::Create());
7100 FilterOperations start_filters
;
7101 start_filters
.Append(FilterOperation::CreateBrightnessFilter(0.1f
));
7102 FilterOperations end_filters
;
7103 end_filters
.Append(FilterOperation::CreateBrightnessFilter(0.3f
));
7105 FilterKeyframe::Create(base::TimeDelta(), start_filters
, nullptr));
7106 curve
->AddKeyframe(FilterKeyframe::Create(
7107 base::TimeDelta::FromMilliseconds(100), end_filters
, nullptr));
7108 scoped_ptr
<Animation
> animation
=
7109 Animation::Create(curve
.Pass(), 0, 1, Animation::FILTER
);
7110 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
7111 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7112 child
->layer_animation_controller()->AddAnimation(animation
.Pass());
7114 ExecuteCalculateDrawProperties(root
.get());
7116 EXPECT_TRUE(root
->render_surface());
7117 EXPECT_TRUE(child
->render_surface());
7118 EXPECT_FALSE(grandchild
->render_surface());
7120 EXPECT_TRUE(root
->filters().IsEmpty());
7121 EXPECT_TRUE(child
->filters().IsEmpty());
7122 EXPECT_TRUE(grandchild
->filters().IsEmpty());
7124 EXPECT_FALSE(root
->FilterIsAnimating());
7125 EXPECT_FALSE(root
->HasPotentiallyRunningFilterAnimation());
7126 EXPECT_FALSE(child
->FilterIsAnimating());
7127 EXPECT_TRUE(child
->HasPotentiallyRunningFilterAnimation());
7128 EXPECT_FALSE(grandchild
->FilterIsAnimating());
7129 EXPECT_FALSE(grandchild
->HasPotentiallyRunningFilterAnimation());
7132 // Ensures that the property tree code accounts for offsets between fixed
7133 // position layers and their respective containers.
7134 TEST_F(LayerTreeHostCommonTest
, PropertyTreesAccountForFixedParentOffset
) {
7135 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7136 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7137 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
7138 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7140 root
->AddChild(child
);
7141 child
->AddChild(grandchild
);
7143 gfx::Transform identity_transform
;
7144 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7145 gfx::PointF(), gfx::Size(50, 50), true, false);
7146 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7147 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7149 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7150 gfx::Point3F(), gfx::PointF(-1000, -1000),
7151 gfx::Size(50, 50), true, false);
7153 root
->SetMasksToBounds(true);
7154 root
->SetIsContainerForFixedPositionLayers(true);
7155 LayerPositionConstraint constraint
;
7156 constraint
.set_is_fixed_position(true);
7157 grandchild
->SetPositionConstraint(constraint
);
7159 root
->SetIsContainerForFixedPositionLayers(true);
7161 host()->SetRootLayer(root
);
7163 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7165 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7166 grandchild
->visible_rect_from_property_trees());
7169 // Ensures that the property tree code accounts for offsets between fixed
7170 // position containers and their transform tree parents, when a fixed position
7171 // layer's container is its layer tree parent, but this parent doesn't have its
7172 // own transform tree node.
7173 TEST_F(LayerTreeHostCommonTest
,
7174 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent
) {
7175 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7176 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7177 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
7178 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7180 root
->AddChild(child
);
7181 child
->AddChild(grandchild
);
7183 gfx::Transform identity_transform
;
7184 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7185 gfx::PointF(), gfx::Size(50, 50), true, false);
7186 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7187 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7189 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7190 gfx::Point3F(), gfx::PointF(-1000, -1000),
7191 gfx::Size(50, 50), true, false);
7193 root
->SetMasksToBounds(true);
7194 child
->SetIsContainerForFixedPositionLayers(true);
7195 LayerPositionConstraint constraint
;
7196 constraint
.set_is_fixed_position(true);
7197 grandchild
->SetPositionConstraint(constraint
);
7199 root
->SetIsContainerForFixedPositionLayers(true);
7201 host()->SetRootLayer(root
);
7203 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7205 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7206 grandchild
->visible_rect_from_property_trees());
7209 TEST_F(LayerTreeHostCommonTest
, CombineClipsUsingContentTarget
) {
7210 // In the following layer tree, the layer |box|'s render target is |surface|.
7211 // |surface| also creates a transform node. We want to combine clips for |box|
7212 // in the space of its target (i.e., |surface|), not its target's target. This
7213 // test ensures that happens.
7215 gfx::Transform rotate
;
7217 gfx::Transform identity
;
7219 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7220 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7221 gfx::PointF(), gfx::Size(2500, 1500), true,
7224 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7225 SetLayerPropertiesForTesting(frame_clip
.get(), identity
, gfx::Point3F(),
7226 gfx::PointF(), gfx::Size(2500, 1500), true,
7228 frame_clip
->SetMasksToBounds(true);
7230 scoped_refptr
<Layer
> rotated
= Layer::Create(layer_settings());
7231 SetLayerPropertiesForTesting(rotated
.get(), rotate
,
7232 gfx::Point3F(1250, 250, 0), gfx::PointF(),
7233 gfx::Size(2500, 500), true, false);
7235 scoped_refptr
<Layer
> surface
= Layer::Create(layer_settings());
7236 SetLayerPropertiesForTesting(surface
.get(), rotate
, gfx::Point3F(),
7237 gfx::PointF(), gfx::Size(2500, 500), true,
7239 surface
->SetOpacity(0.5);
7241 scoped_refptr
<LayerWithForcedDrawsContent
> container
=
7242 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7243 SetLayerPropertiesForTesting(container
.get(), identity
, gfx::Point3F(),
7244 gfx::PointF(), gfx::Size(300, 300), true, false);
7246 scoped_refptr
<LayerWithForcedDrawsContent
> box
=
7247 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7248 SetLayerPropertiesForTesting(box
.get(), identity
, gfx::Point3F(),
7249 gfx::PointF(), gfx::Size(100, 100), true, false);
7251 root
->AddChild(frame_clip
);
7252 frame_clip
->AddChild(rotated
);
7253 rotated
->AddChild(surface
);
7254 surface
->AddChild(container
);
7255 surface
->AddChild(box
);
7257 host()->SetRootLayer(root
);
7259 ExecuteCalculateDrawProperties(root
.get());
7262 TEST_F(LayerTreeHostCommonTest
, OnlyApplyFixedPositioningOnce
) {
7263 gfx::Transform identity
;
7264 gfx::Transform translate_z
;
7265 translate_z
.Translate3d(0, 0, 10);
7267 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7268 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7269 gfx::PointF(), gfx::Size(800, 800), true, false);
7270 root
->SetIsContainerForFixedPositionLayers(true);
7272 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7273 SetLayerPropertiesForTesting(frame_clip
.get(), translate_z
, gfx::Point3F(),
7274 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7276 frame_clip
->SetMasksToBounds(true);
7278 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
7279 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7280 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
7281 gfx::PointF(), gfx::Size(1000, 1000), true,
7284 LayerPositionConstraint constraint
;
7285 constraint
.set_is_fixed_position(true);
7286 fixed
->SetPositionConstraint(constraint
);
7288 root
->AddChild(frame_clip
);
7289 frame_clip
->AddChild(fixed
);
7291 host()->SetRootLayer(root
);
7293 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7295 gfx::Rect
expected(0, 0, 100, 100);
7296 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
7299 TEST_F(LayerTreeHostCommonTest
,
7300 PropertyTreesAccountForScrollCompensationAdjustment
) {
7301 gfx::Transform identity
;
7302 gfx::Transform translate_z
;
7303 translate_z
.Translate3d(0, 0, 10);
7305 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7306 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7307 gfx::PointF(), gfx::Size(800, 800), true, false);
7308 root
->SetIsContainerForFixedPositionLayers(true);
7310 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7311 SetLayerPropertiesForTesting(frame_clip
.get(), translate_z
, gfx::Point3F(),
7312 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7314 frame_clip
->SetMasksToBounds(true);
7316 scoped_refptr
<LayerWithForcedDrawsContent
> scroller
=
7317 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7318 SetLayerPropertiesForTesting(scroller
.get(), identity
, gfx::Point3F(),
7319 gfx::PointF(), gfx::Size(1000, 1000), true,
7322 scroller
->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f
, 0.7f
));
7323 scroller
->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7));
7324 scroller
->SetScrollClipLayerId(frame_clip
->id());
7326 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
7327 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7328 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
7329 gfx::PointF(), gfx::Size(50, 50), true, false);
7331 LayerPositionConstraint constraint
;
7332 constraint
.set_is_fixed_position(true);
7333 fixed
->SetPositionConstraint(constraint
);
7335 scoped_refptr
<LayerWithForcedDrawsContent
> fixed_child
=
7336 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7337 SetLayerPropertiesForTesting(fixed_child
.get(), identity
, gfx::Point3F(),
7338 gfx::PointF(), gfx::Size(10, 10), true, false);
7340 fixed_child
->SetPositionConstraint(constraint
);
7342 root
->AddChild(frame_clip
);
7343 frame_clip
->AddChild(scroller
);
7344 scroller
->AddChild(fixed
);
7345 fixed
->AddChild(fixed_child
);
7347 host()->SetRootLayer(root
);
7349 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7351 gfx::Rect
expected(0, 0, 50, 50);
7352 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
7354 expected
= gfx::Rect(0, 0, 10, 10);
7355 EXPECT_EQ(expected
, fixed_child
->visible_rect_from_property_trees());
7358 TEST_F(LayerTreeHostCommonTest
, FixedClipsShouldBeAssociatedWithTheRightNode
) {
7359 gfx::Transform identity
;
7361 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7362 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7363 gfx::PointF(), gfx::Size(800, 800), true, false);
7364 root
->SetIsContainerForFixedPositionLayers(true);
7366 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7367 SetLayerPropertiesForTesting(frame_clip
.get(), identity
, gfx::Point3F(),
7368 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7370 frame_clip
->SetMasksToBounds(true);
7372 scoped_refptr
<LayerWithForcedDrawsContent
> scroller
=
7373 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7374 SetLayerPropertiesForTesting(scroller
.get(), identity
, gfx::Point3F(),
7375 gfx::PointF(), gfx::Size(1000, 1000), true,
7378 scroller
->SetScrollOffset(gfx::ScrollOffset(100, 100));
7379 scroller
->SetScrollClipLayerId(frame_clip
->id());
7381 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
7382 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7383 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
7384 gfx::PointF(100, 100), gfx::Size(50, 50), true,
7387 LayerPositionConstraint constraint
;
7388 constraint
.set_is_fixed_position(true);
7389 fixed
->SetPositionConstraint(constraint
);
7390 fixed
->SetForceRenderSurface(true);
7391 fixed
->SetMasksToBounds(true);
7393 root
->AddChild(frame_clip
);
7394 frame_clip
->AddChild(scroller
);
7395 scroller
->AddChild(fixed
);
7397 host()->SetRootLayer(root
);
7399 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7401 gfx::Rect
expected(0, 0, 50, 50);
7402 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
7405 TEST_F(LayerTreeHostCommonTest
, ChangingAxisAlignmentTriggersRebuild
) {
7406 gfx::Transform identity
;
7407 gfx::Transform translate
;
7408 gfx::Transform rotate
;
7410 translate
.Translate(10, 10);
7413 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7414 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7415 gfx::PointF(), gfx::Size(800, 800), true, false);
7416 root
->SetIsContainerForFixedPositionLayers(true);
7418 host()->SetRootLayer(root
);
7420 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7421 EXPECT_FALSE(host()->property_trees()->needs_rebuild
);
7423 root
->SetTransform(translate
);
7424 EXPECT_FALSE(host()->property_trees()->needs_rebuild
);
7426 root
->SetTransform(rotate
);
7427 EXPECT_TRUE(host()->property_trees()->needs_rebuild
);
7430 TEST_F(LayerTreeHostCommonTest
, ChangeTransformOrigin
) {
7431 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7432 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7433 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7434 root
->AddChild(child
);
7436 host()->SetRootLayer(root
);
7438 gfx::Transform identity_matrix
;
7439 gfx::Transform scale_matrix
;
7440 scale_matrix
.Scale(2.f
, 2.f
);
7441 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
7442 gfx::PointF(), gfx::Size(100, 100), true, false);
7443 SetLayerPropertiesForTesting(child
.get(), scale_matrix
, gfx::Point3F(),
7444 gfx::PointF(), gfx::Size(10, 10), true, false);
7446 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7447 EXPECT_EQ(gfx::Rect(10, 10), child
->visible_rect_from_property_trees());
7449 child
->SetTransformOrigin(gfx::Point3F(10.f
, 10.f
, 10.f
));
7451 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7452 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child
->visible_rect_from_property_trees());
7455 TEST_F(LayerTreeHostCommonTest
, UpdateScrollChildPosition
) {
7456 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7457 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7458 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7459 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7460 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7462 root
->AddChild(scroll_child
);
7463 root
->AddChild(scroll_parent
);
7464 scroll_child
->SetScrollParent(scroll_parent
.get());
7465 scroll_parent
->SetScrollClipLayerId(root
->id());
7467 host()->SetRootLayer(root
);
7469 gfx::Transform identity_transform
;
7470 gfx::Transform scale
;
7471 scale
.Scale(2.f
, 2.f
);
7472 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7473 gfx::PointF(), gfx::Size(50, 50), true, false);
7474 SetLayerPropertiesForTesting(scroll_child
.get(), scale
, gfx::Point3F(),
7475 gfx::PointF(), gfx::Size(40, 40), true, false);
7476 SetLayerPropertiesForTesting(scroll_parent
.get(), identity_transform
,
7477 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7480 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7481 EXPECT_EQ(gfx::Rect(25, 25),
7482 scroll_child
->visible_rect_from_property_trees());
7484 scroll_child
->SetPosition(gfx::PointF(0, -10.f
));
7485 scroll_parent
->SetScrollOffset(gfx::ScrollOffset(0.f
, 10.f
));
7486 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7487 EXPECT_EQ(gfx::Rect(0, 5, 25, 25),
7488 scroll_child
->visible_rect_from_property_trees());
7491 static void CopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {
7494 TEST_F(LayerTreeHostCommonTest
, SkippingSubtreeMain
) {
7495 gfx::Transform identity
;
7496 FakeContentLayerClient client
;
7497 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7498 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7499 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7500 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
7501 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7502 scoped_refptr
<FakePictureLayer
> greatgrandchild(
7503 FakePictureLayer::Create(layer_settings(), &client
));
7504 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7505 gfx::PointF(), gfx::Size(100, 100), true, false);
7506 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7507 gfx::PointF(), gfx::Size(10, 10), true, false);
7508 SetLayerPropertiesForTesting(grandchild
.get(), identity
, gfx::Point3F(),
7509 gfx::PointF(), gfx::Size(10, 10), true, false);
7510 SetLayerPropertiesForTesting(greatgrandchild
.get(), identity
, gfx::Point3F(),
7511 gfx::PointF(), gfx::Size(10, 10), true, false);
7513 root
->AddChild(child
);
7514 child
->AddChild(grandchild
);
7515 grandchild
->AddChild(greatgrandchild
);
7517 host()->SetRootLayer(root
);
7519 // Check the non-skipped case.
7520 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7521 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7523 // Now we will reset the visible rect from property trees for the grandchild,
7524 // and we will configure |child| in several ways that should force the subtree
7525 // to be skipped. The visible content rect for |grandchild| should, therefore,
7527 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7528 gfx::Transform singular
;
7529 singular
.matrix().set(0, 0, 0);
7531 child
->SetTransform(singular
);
7532 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7533 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
7534 child
->SetTransform(identity
);
7536 child
->SetHideLayerAndSubtree(true);
7537 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7538 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
7539 child
->SetHideLayerAndSubtree(false);
7541 gfx::Transform zero_z_scale
;
7542 zero_z_scale
.Scale3d(1, 1, 0);
7543 child
->SetTransform(zero_z_scale
);
7545 // Add a transform animation with a start delay. Now, even though |child| has
7546 // a singular transform, the subtree should still get processed.
7547 int animation_id
= 0;
7548 scoped_ptr
<Animation
> animation
= Animation::Create(
7549 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1.0)).Pass(),
7550 animation_id
, 1, Animation::TRANSFORM
);
7551 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
7552 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7553 child
->AddAnimation(animation
.Pass());
7554 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7555 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7556 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7558 child
->RemoveAnimation(animation_id
);
7559 child
->SetTransform(identity
);
7560 child
->SetOpacity(0.f
);
7561 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7562 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
7564 // Now, even though child has zero opacity, we will configure |grandchild| and
7565 // |greatgrandchild| in several ways that should force the subtree to be
7566 // processed anyhow.
7567 grandchild
->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10)));
7568 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7569 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7570 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7571 grandchild
->SetTouchEventHandlerRegion(Region());
7572 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7573 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
7574 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7576 greatgrandchild
->RequestCopyOfOutput(
7577 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback
)));
7578 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7579 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7580 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7582 // Add an opacity animation with a start delay.
7584 animation
= Animation::Create(
7585 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
7586 animation_id
, 1, Animation::OPACITY
);
7587 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
7588 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7589 child
->AddAnimation(animation
.Pass());
7590 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7591 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7594 TEST_F(LayerTreeHostCommonTest
, SkippingSubtreeImpl
) {
7595 FakeImplProxy proxy
;
7596 TestSharedBitmapManager shared_bitmap_manager
;
7597 TestTaskGraphRunner task_graph_runner
;
7598 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
7599 &task_graph_runner
);
7601 gfx::Transform identity
;
7602 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7603 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 2);
7604 scoped_ptr
<LayerImpl
> grandchild
=
7605 LayerImpl::Create(host_impl
.active_tree(), 3);
7607 scoped_ptr
<FakePictureLayerImpl
> greatgrandchild(
7608 FakePictureLayerImpl::Create(host_impl
.active_tree(), 4));
7610 child
->SetDrawsContent(true);
7611 grandchild
->SetDrawsContent(true);
7612 greatgrandchild
->SetDrawsContent(true);
7614 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7615 gfx::PointF(), gfx::Size(100, 100), true, false,
7617 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7618 gfx::PointF(), gfx::Size(10, 10), true, false,
7620 SetLayerPropertiesForTesting(grandchild
.get(), identity
, gfx::Point3F(),
7621 gfx::PointF(), gfx::Size(10, 10), true, false,
7623 SetLayerPropertiesForTesting(greatgrandchild
.get(), identity
, gfx::Point3F(),
7624 gfx::PointF(), gfx::Size(10, 10), true, false,
7627 LayerImpl
* child_ptr
= child
.get();
7628 LayerImpl
* grandchild_ptr
= grandchild
.get();
7629 LayerImpl
* greatgrandchild_ptr
= greatgrandchild
.get();
7631 grandchild
->AddChild(greatgrandchild
.Pass());
7632 child
->AddChild(grandchild
.Pass());
7633 root
->AddChild(child
.Pass());
7635 // Check the non-skipped case.
7636 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7637 EXPECT_EQ(gfx::Rect(10, 10),
7638 grandchild_ptr
->visible_rect_from_property_trees());
7640 // Now we will reset the visible rect from property trees for the grandchild,
7641 // and we will configure |child| in several ways that should force the subtree
7642 // to be skipped. The visible content rect for |grandchild| should, therefore,
7644 grandchild_ptr
->set_visible_rect_from_property_trees(gfx::Rect());
7645 gfx::Transform singular
;
7646 singular
.matrix().set(0, 0, 0);
7648 child_ptr
->SetTransform(singular
);
7649 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7650 EXPECT_EQ(gfx::Rect(0, 0),
7651 grandchild_ptr
->visible_rect_from_property_trees());
7652 child_ptr
->SetTransform(identity
);
7654 child_ptr
->SetHideLayerAndSubtree(true);
7655 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7656 EXPECT_EQ(gfx::Rect(0, 0),
7657 grandchild_ptr
->visible_rect_from_property_trees());
7658 child_ptr
->SetHideLayerAndSubtree(false);
7660 child_ptr
->SetOpacity(0.f
);
7661 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7662 EXPECT_EQ(gfx::Rect(0, 0),
7663 grandchild_ptr
->visible_rect_from_property_trees());
7665 // Now, even though child has zero opacity, we will configure |grandchild| and
7666 // |greatgrandchild| in several ways that should force the subtree to be
7667 // processed anyhow.
7668 grandchild_ptr
->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10)));
7669 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7670 EXPECT_EQ(gfx::Rect(10, 10),
7671 grandchild_ptr
->visible_rect_from_property_trees());
7672 grandchild_ptr
->set_visible_rect_from_property_trees(gfx::Rect());
7673 grandchild_ptr
->SetTouchEventHandlerRegion(Region());
7674 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7675 EXPECT_EQ(gfx::Rect(0, 0),
7676 grandchild_ptr
->visible_rect_from_property_trees());
7677 grandchild_ptr
->set_visible_rect_from_property_trees(gfx::Rect());
7679 ScopedPtrVector
<CopyOutputRequest
> requests
;
7680 requests
.push_back(CopyOutputRequest::CreateEmptyRequest());
7682 greatgrandchild_ptr
->PassCopyRequests(&requests
);
7683 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7684 EXPECT_EQ(gfx::Rect(10, 10),
7685 grandchild_ptr
->visible_rect_from_property_trees());
7688 TEST_F(LayerTreeHostCommonTest
, SkippingLayer
) {
7689 gfx::Transform identity
;
7690 FakeContentLayerClient client
;
7691 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7692 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7693 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7694 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7695 gfx::PointF(), gfx::Size(100, 100), true, false);
7696 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7697 gfx::PointF(), gfx::Size(10, 10), true, false);
7698 root
->AddChild(child
);
7700 host()->SetRootLayer(root
);
7702 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7703 EXPECT_EQ(gfx::Rect(10, 10), child
->visible_rect_from_property_trees());
7704 child
->set_visible_rect_from_property_trees(gfx::Rect());
7706 child
->SetHideLayerAndSubtree(true);
7707 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7708 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7709 child
->SetHideLayerAndSubtree(false);
7711 child
->SetBounds(gfx::Size());
7712 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7713 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7714 child
->SetBounds(gfx::Size(10, 10));
7716 gfx::Transform rotate
;
7717 child
->SetDoubleSided(false);
7718 rotate
.RotateAboutXAxis(180.f
);
7719 child
->SetTransform(rotate
);
7720 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7721 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7722 child
->SetDoubleSided(true);
7723 child
->SetTransform(identity
);
7725 child
->SetOpacity(0.f
);
7726 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7727 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7730 TEST_F(LayerTreeHostCommonTest
, LayerTreeRebuildTest
) {
7731 // Ensure that the treewalk in LayerTreeHostCommom::
7732 // PreCalculateMetaInformation happens when its required.
7733 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7734 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
7735 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7737 root
->AddChild(parent
);
7738 parent
->AddChild(child
);
7740 child
->SetClipParent(root
.get());
7742 gfx::Transform identity
;
7744 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7745 gfx::PointF(), gfx::Size(100, 100), true, false);
7746 SetLayerPropertiesForTesting(parent
.get(), identity
, gfx::Point3F(),
7747 gfx::PointF(), gfx::Size(100, 100), true, false);
7748 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7749 gfx::PointF(), gfx::Size(100, 100), true, false);
7751 host()->SetRootLayer(root
);
7753 ExecuteCalculateDrawProperties(root
.get());
7754 EXPECT_EQ(parent
->draw_properties().num_unclipped_descendants
, 1u);
7756 // Ensure the dynamic update to input handlers happens.
7757 child
->SetHaveWheelEventHandlers(true);
7758 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_input_handler
);
7759 ExecuteCalculateDrawProperties(root
.get());
7760 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_input_handler
);
7762 child
->SetHaveWheelEventHandlers(false);
7763 EXPECT_FALSE(root
->draw_properties().layer_or_descendant_has_input_handler
);
7764 ExecuteCalculateDrawProperties(root
.get());
7765 EXPECT_FALSE(root
->draw_properties().layer_or_descendant_has_input_handler
);
7767 child
->RequestCopyOfOutput(
7768 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback
)));
7769 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
7770 ExecuteCalculateDrawProperties(root
.get());
7771 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
7774 TEST_F(LayerTreeHostCommonTest
, InputHandlersRecursiveUpdateTest
) {
7775 // Ensure that the treewalk in LayertreeHostCommon::
7776 // PreCalculateMetaInformation updates input handlers correctly.
7777 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7778 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7780 root
->AddChild(child
);
7782 child
->SetHaveWheelEventHandlers(true);
7784 gfx::Transform identity
;
7786 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7787 gfx::PointF(), gfx::Size(100, 100), true, false);
7788 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7789 gfx::PointF(), gfx::Size(100, 100), true, false);
7791 host()->SetRootLayer(root
);
7793 EXPECT_EQ(root
->num_layer_or_descendants_with_input_handler(), 0);
7794 ExecuteCalculateDrawProperties(root
.get());
7795 EXPECT_EQ(root
->num_layer_or_descendants_with_input_handler(), 1);
7796 child
->SetHaveWheelEventHandlers(false);
7797 EXPECT_EQ(root
->num_layer_or_descendants_with_input_handler(), 0);
7800 TEST_F(LayerTreeHostCommonTest
, ResetPropertyTreeIndices
) {
7801 gfx::Transform identity
;
7802 gfx::Transform translate_z
;
7803 translate_z
.Translate3d(0, 0, 10);
7805 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7806 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7807 gfx::PointF(), gfx::Size(800, 800), true, false);
7809 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7810 SetLayerPropertiesForTesting(child
.get(), translate_z
, gfx::Point3F(),
7811 gfx::PointF(), gfx::Size(100, 100), true, false);
7813 root
->AddChild(child
);
7815 host()->SetRootLayer(root
);
7817 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7818 EXPECT_NE(-1, child
->transform_tree_index());
7820 child
->RemoveFromParent();
7822 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7823 EXPECT_EQ(-1, child
->transform_tree_index());
7826 TEST_F(LayerTreeHostCommonTest
, ResetLayerDrawPropertiestest
) {
7827 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7828 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7830 root
->AddChild(child
);
7831 gfx::Transform identity
;
7833 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7834 gfx::PointF(), gfx::Size(100, 100), true, false);
7835 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7836 gfx::PointF(), gfx::Size(100, 100), true, false);
7838 host()->SetRootLayer(root
);
7840 EXPECT_FALSE(root
->layer_or_descendant_is_drawn());
7841 EXPECT_FALSE(root
->visited());
7842 EXPECT_FALSE(root
->sorted_for_recursion());
7843 EXPECT_FALSE(child
->layer_or_descendant_is_drawn());
7844 EXPECT_FALSE(child
->visited());
7845 EXPECT_FALSE(child
->sorted_for_recursion());
7847 root
->set_layer_or_descendant_is_drawn(true);
7848 root
->set_visited(true);
7849 root
->set_sorted_for_recursion(true);
7850 child
->set_layer_or_descendant_is_drawn(true);
7851 child
->set_visited(true);
7852 child
->set_sorted_for_recursion(true);
7854 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root
.get());
7856 EXPECT_FALSE(root
->layer_or_descendant_is_drawn());
7857 EXPECT_FALSE(root
->visited());
7858 EXPECT_FALSE(root
->sorted_for_recursion());
7859 EXPECT_FALSE(child
->layer_or_descendant_is_drawn());
7860 EXPECT_FALSE(child
->visited());
7861 EXPECT_FALSE(child
->sorted_for_recursion());
7864 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceClipsSubtree
) {
7865 // Ensure that a Clip Node is added when a render surface applies clip.
7866 LayerImpl
* root
= root_layer();
7867 LayerImpl
* significant_transform
= AddChildToRoot
<LayerImpl
>();
7868 LayerImpl
* layer_clips_subtree
= AddChild
<LayerImpl
>(significant_transform
);
7869 LayerImpl
* render_surface
= AddChild
<LayerImpl
>(layer_clips_subtree
);
7870 LayerImpl
* test_layer
= AddChild
<LayerImpl
>(render_surface
);
7872 const gfx::Transform identity_matrix
;
7873 // This transform should be a significant one so that a transform node is
7875 gfx::Transform transform1
;
7876 transform1
.RotateAboutYAxis(45);
7877 transform1
.RotateAboutXAxis(30);
7878 // This transform should be a 3d transform as we want the render surface
7879 // to flatten the transform
7880 gfx::Transform transform2
;
7881 transform2
.Translate3d(10, 10, 10);
7883 layer_clips_subtree
->SetMasksToBounds(true);
7884 test_layer
->SetDrawsContent(true);
7886 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
7887 gfx::PointF(), gfx::Size(30, 30), true, false,
7889 SetLayerPropertiesForTesting(significant_transform
, transform1
,
7890 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7891 true, false, false);
7892 SetLayerPropertiesForTesting(layer_clips_subtree
, identity_matrix
,
7893 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7894 true, false, false);
7895 SetLayerPropertiesForTesting(render_surface
, transform2
, gfx::Point3F(),
7896 gfx::PointF(), gfx::Size(30, 30), true, false,
7898 SetLayerPropertiesForTesting(test_layer
, identity_matrix
, gfx::Point3F(),
7899 gfx::PointF(), gfx::Size(30, 30), true, false,
7902 ExecuteCalculateDrawProperties(root
);
7904 TransformTree transform_tree
=
7905 root
->layer_tree_impl()->property_trees()->transform_tree
;
7906 TransformNode
* transform_node
=
7907 transform_tree
.Node(significant_transform
->transform_tree_index());
7908 EXPECT_EQ(transform_node
->owner_id
, significant_transform
->id());
7910 ClipTree clip_tree
= root
->layer_tree_impl()->property_trees()->clip_tree
;
7911 ClipNode
* clip_node
= clip_tree
.Node(render_surface
->clip_tree_index());
7912 EXPECT_TRUE(clip_node
->data
.inherit_parent_target_space_clip
);
7913 EXPECT_EQ(test_layer
->visible_rect_from_property_trees(), gfx::RectF(30, 21));
7916 TEST_F(LayerTreeHostCommonTest
, TransformOfParentClipNodeAncestorOfTarget
) {
7917 // Ensure that when parent clip node's transform is an ancestor of current
7918 // clip node's target, clip is 'projected' from parent space to current
7919 // target space and visible rects are calculated correctly.
7920 LayerImpl
* root
= root_layer();
7921 LayerImpl
* clip_layer
= AddChild
<LayerImpl
>(root
);
7922 LayerImpl
* target_layer
= AddChild
<LayerImpl
>(clip_layer
);
7923 LayerImpl
* test_layer
= AddChild
<LayerImpl
>(target_layer
);
7925 const gfx::Transform identity_matrix
;
7926 gfx::Transform transform
;
7927 transform
.RotateAboutYAxis(45);
7928 clip_layer
->SetMasksToBounds(true);
7929 target_layer
->SetMasksToBounds(true);
7930 test_layer
->SetDrawsContent(true);
7932 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
7933 gfx::PointF(), gfx::Size(30, 30), true, false,
7935 SetLayerPropertiesForTesting(clip_layer
, transform
, gfx::Point3F(),
7936 gfx::PointF(), gfx::Size(30, 30), true, false,
7938 SetLayerPropertiesForTesting(target_layer
, transform
, gfx::Point3F(),
7939 gfx::PointF(), gfx::Size(30, 30), true, false,
7941 SetLayerPropertiesForTesting(test_layer
, identity_matrix
, gfx::Point3F(),
7942 gfx::PointF(), gfx::Size(30, 30), true, false,
7944 ExecuteCalculateDrawProperties(root
);
7946 ClipTree clip_tree
= root
->layer_tree_impl()->property_trees()->clip_tree
;
7947 ClipNode
* clip_node
= clip_tree
.Node(target_layer
->clip_tree_index());
7948 EXPECT_EQ(clip_node
->data
.combined_clip
, gfx::RectF(30, 30));
7949 EXPECT_EQ(test_layer
->visible_rect_from_property_trees(), gfx::RectF(30, 30));
7952 TEST_F(LayerTreeHostCommonTest
,
7953 RenderSurfaceWithUnclippedDescendantsClipsSubtree
) {
7954 // Ensure clip rect is calculated correctly when render surface has unclipped
7956 LayerImpl
* root
= root_layer();
7957 LayerImpl
* clip_parent
= AddChildToRoot
<LayerImpl
>();
7958 LayerImpl
* between_clip_parent_and_child
= AddChild
<LayerImpl
>(clip_parent
);
7959 LayerImpl
* render_surface
=
7960 AddChild
<LayerImpl
>(between_clip_parent_and_child
);
7961 LayerImpl
* test_layer
= AddChild
<LayerImpl
>(render_surface
);
7963 const gfx::Transform identity_matrix
;
7964 gfx::Transform transform
;
7965 transform
.Translate(2.0, 2.0);
7967 test_layer
->SetDrawsContent(true);
7968 render_surface
->SetClipParent(clip_parent
);
7969 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
7970 gfx::PointF(), gfx::Size(30, 30), true, false,
7972 SetLayerPropertiesForTesting(clip_parent
, transform
, gfx::Point3F(),
7973 gfx::PointF(), gfx::Size(30, 30), true, false,
7975 SetLayerPropertiesForTesting(between_clip_parent_and_child
, transform
,
7976 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7977 true, false, false);
7978 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
7979 gfx::PointF(), gfx::Size(30, 30), true, false,
7981 SetLayerPropertiesForTesting(test_layer
, identity_matrix
, gfx::Point3F(),
7982 gfx::PointF(), gfx::Size(30, 30), true, false,
7985 ExecuteCalculateDrawProperties(root
);
7987 EXPECT_EQ(test_layer
->clip_rect(), gfx::RectF(-4, -4, 30, 30));