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"
9 #include "cc/animation/layer_animation_controller.h"
10 #include "cc/animation/transform_operations.h"
11 #include "cc/base/math_util.h"
12 #include "cc/layers/content_layer.h"
13 #include "cc/layers/content_layer_client.h"
14 #include "cc/layers/layer.h"
15 #include "cc/layers/layer_client.h"
16 #include "cc/layers/layer_impl.h"
17 #include "cc/layers/layer_iterator.h"
18 #include "cc/layers/render_surface.h"
19 #include "cc/layers/render_surface_impl.h"
20 #include "cc/output/copy_output_request.h"
21 #include "cc/output/copy_output_result.h"
22 #include "cc/test/animation_test_common.h"
23 #include "cc/test/fake_impl_proxy.h"
24 #include "cc/test/fake_layer_tree_host.h"
25 #include "cc/test/fake_layer_tree_host_impl.h"
26 #include "cc/test/geometry_test_utils.h"
27 #include "cc/test/layer_tree_host_common_test.h"
28 #include "cc/trees/layer_tree_impl.h"
29 #include "cc/trees/proxy.h"
30 #include "cc/trees/single_thread_proxy.h"
31 #include "testing/gmock/include/gmock/gmock.h"
32 #include "testing/gtest/include/gtest/gtest.h"
33 #include "ui/gfx/quad_f.h"
34 #include "ui/gfx/transform.h"
39 class LayerWithForcedDrawsContent
: public Layer
{
41 LayerWithForcedDrawsContent() {}
43 virtual bool DrawsContent() const OVERRIDE
;
46 virtual ~LayerWithForcedDrawsContent() {}
49 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
51 class MockContentLayerClient
: public ContentLayerClient
{
53 MockContentLayerClient() {}
54 virtual ~MockContentLayerClient() {}
55 virtual void PaintContents(
57 const gfx::Rect
& clip
,
59 ContentLayerClient::GraphicsContextStatus gc_status
) OVERRIDE
{}
60 virtual void DidChangeLayerCanUseLCDText() OVERRIDE
{}
61 virtual bool FillsBoundsCompletely() const OVERRIDE
{ return false; }
64 scoped_refptr
<ContentLayer
> CreateDrawableContentLayer(
65 ContentLayerClient
* delegate
) {
66 scoped_refptr
<ContentLayer
> to_return
= ContentLayer::Create(delegate
);
67 to_return
->SetIsDrawable(true);
71 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
73 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
74 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
77 TEST_F(LayerTreeHostCommonTest
, TransformsForNoOpLayer
) {
78 // Sanity check: For layers positioned at zero, with zero size,
79 // and with identity transforms, then the draw transform,
80 // screen space transform, and the hierarchy passed on to children
81 // layers should also be identity transforms.
83 scoped_refptr
<Layer
> parent
= Layer::Create();
84 scoped_refptr
<Layer
> child
= Layer::Create();
85 scoped_refptr
<Layer
> grand_child
= Layer::Create();
86 parent
->AddChild(child
);
87 child
->AddChild(grand_child
);
89 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
90 host
->SetRootLayer(parent
);
92 gfx::Transform identity_matrix
;
93 SetLayerPropertiesForTesting(parent
.get(),
100 SetLayerPropertiesForTesting(child
.get(),
107 SetLayerPropertiesForTesting(grand_child
.get(),
115 ExecuteCalculateDrawProperties(parent
.get());
117 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
118 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
119 child
->screen_space_transform());
120 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
121 grand_child
->draw_transform());
122 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
123 grand_child
->screen_space_transform());
126 TEST_F(LayerTreeHostCommonTest
, DoNotSkipLayersWithHandlers
) {
127 scoped_refptr
<Layer
> parent
= Layer::Create();
128 scoped_refptr
<Layer
> child
= Layer::Create();
129 scoped_refptr
<Layer
> grand_child
= Layer::Create();
130 parent
->AddChild(child
);
131 child
->AddChild(grand_child
);
133 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
134 host
->SetRootLayer(parent
);
136 gfx::Transform identity_matrix
;
137 SetLayerPropertiesForTesting(parent
.get(),
144 SetLayerPropertiesForTesting(child
.get(),
151 // This would have previously caused us to skip our subtree, but this would be
152 // wrong; we need up-to-date draw properties to do hit testing on the layers
154 child
->SetOpacity(0.f
);
155 SetLayerPropertiesForTesting(grand_child
.get(),
162 grand_child
->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
164 ExecuteCalculateDrawProperties(parent
.get());
166 // Check that we've computed draw properties for the subtree rooted at
168 EXPECT_FALSE(child
->draw_transform().IsIdentity());
169 EXPECT_FALSE(grand_child
->draw_transform().IsIdentity());
172 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleLayer
) {
173 gfx::Transform identity_matrix
;
174 scoped_refptr
<Layer
> layer
= Layer::Create();
176 scoped_refptr
<Layer
> root
= Layer::Create();
177 SetLayerPropertiesForTesting(root
.get(),
184 root
->AddChild(layer
);
186 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
187 host
->SetRootLayer(root
);
189 // Case 2: Setting the bounds of the layer should not affect either the draw
190 // transform or the screenspace transform.
191 gfx::Transform translation_to_center
;
192 translation_to_center
.Translate(5.0, 6.0);
193 SetLayerPropertiesForTesting(layer
.get(),
200 ExecuteCalculateDrawProperties(root
.get());
201 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
202 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
203 layer
->screen_space_transform());
205 // Case 3: The anchor point by itself (without a layer transform) should have
206 // no effect on the transforms.
207 SetLayerPropertiesForTesting(layer
.get(),
209 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
214 ExecuteCalculateDrawProperties(root
.get());
215 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
216 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
217 layer
->screen_space_transform());
219 // Case 4: A change in actual position affects both the draw transform and
220 // screen space transform.
221 gfx::Transform position_transform
;
222 position_transform
.Translate(0.f
, 1.2f
);
223 SetLayerPropertiesForTesting(layer
.get(),
225 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
226 gfx::PointF(0.f
, 1.2f
),
230 ExecuteCalculateDrawProperties(root
.get());
231 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
, layer
->draw_transform());
232 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
,
233 layer
->screen_space_transform());
235 // Case 5: In the correct sequence of transforms, the layer transform should
236 // pre-multiply the translation_to_center. This is easily tested by using a
237 // scale transform, because scale and translation are not commutative.
238 gfx::Transform layer_transform
;
239 layer_transform
.Scale3d(2.0, 2.0, 1.0);
240 SetLayerPropertiesForTesting(layer
.get(),
247 ExecuteCalculateDrawProperties(root
.get());
248 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
, layer
->draw_transform());
249 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
,
250 layer
->screen_space_transform());
252 // Case 6: The layer transform should occur with respect to the anchor point.
253 gfx::Transform translation_to_anchor
;
254 translation_to_anchor
.Translate(5.0, 0.0);
255 gfx::Transform expected_result
=
256 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
257 SetLayerPropertiesForTesting(layer
.get(),
259 gfx::Point3F(5.0f
, 0.f
, 0.f
),
264 ExecuteCalculateDrawProperties(root
.get());
265 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
266 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
267 layer
->screen_space_transform());
269 // Case 7: Verify that position pre-multiplies the layer transform. The
270 // current implementation of CalculateDrawProperties does this implicitly, but
271 // it is still worth testing to detect accidental regressions.
272 expected_result
= position_transform
* translation_to_anchor
*
273 layer_transform
* Inverse(translation_to_anchor
);
274 SetLayerPropertiesForTesting(layer
.get(),
276 gfx::Point3F(5.0f
, 0.f
, 0.f
),
277 gfx::PointF(0.f
, 1.2f
),
281 ExecuteCalculateDrawProperties(root
.get());
282 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
283 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
284 layer
->screen_space_transform());
287 TEST_F(LayerTreeHostCommonTest
, TransformsAboutScrollOffset
) {
288 const gfx::Vector2d
kScrollOffset(50, 100);
289 const gfx::Vector2dF
kScrollDelta(2.34f
, 5.67f
);
290 const gfx::Vector2d
kMaxScrollOffset(200, 200);
291 const gfx::PointF
kScrollLayerPosition(-kScrollOffset
.x(),
293 const float kPageScale
= 0.888f
;
294 const float kDeviceScale
= 1.666f
;
297 TestSharedBitmapManager shared_bitmap_manager
;
298 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
300 gfx::Transform identity_matrix
;
301 scoped_ptr
<LayerImpl
> sublayer_scoped_ptr(
302 LayerImpl::Create(host_impl
.active_tree(), 1));
303 LayerImpl
* sublayer
= sublayer_scoped_ptr
.get();
304 sublayer
->SetContentsScale(kPageScale
* kDeviceScale
,
305 kPageScale
* kDeviceScale
);
306 SetLayerPropertiesForTesting(sublayer
,
314 scoped_ptr
<LayerImpl
> scroll_layer_scoped_ptr(
315 LayerImpl::Create(host_impl
.active_tree(), 2));
316 LayerImpl
* scroll_layer
= scroll_layer_scoped_ptr
.get();
317 SetLayerPropertiesForTesting(scroll_layer
,
324 scoped_ptr
<LayerImpl
> clip_layer_scoped_ptr(
325 LayerImpl::Create(host_impl
.active_tree(), 4));
326 LayerImpl
* clip_layer
= clip_layer_scoped_ptr
.get();
328 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
329 clip_layer
->SetBounds(
330 gfx::Size(scroll_layer
->bounds().width() + kMaxScrollOffset
.x(),
331 scroll_layer
->bounds().height() + kMaxScrollOffset
.y()));
332 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
333 scroll_layer
->SetScrollDelta(kScrollDelta
);
334 gfx::Transform impl_transform
;
335 scroll_layer
->AddChild(sublayer_scoped_ptr
.Pass());
336 LayerImpl
* scroll_layer_raw_ptr
= scroll_layer_scoped_ptr
.get();
337 clip_layer
->AddChild(scroll_layer_scoped_ptr
.Pass());
338 scroll_layer_raw_ptr
->SetScrollOffset(kScrollOffset
);
340 scoped_ptr
<LayerImpl
> root(LayerImpl::Create(host_impl
.active_tree(), 3));
341 SetLayerPropertiesForTesting(root
.get(),
348 root
->AddChild(clip_layer_scoped_ptr
.Pass());
350 ExecuteCalculateDrawProperties(
351 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
352 gfx::Transform expected_transform
= identity_matrix
;
353 gfx::PointF sub_layer_screen_position
= kScrollLayerPosition
- kScrollDelta
;
354 sub_layer_screen_position
.Scale(kPageScale
* kDeviceScale
);
355 expected_transform
.Translate(MathUtil::Round(sub_layer_screen_position
.x()),
356 MathUtil::Round(sub_layer_screen_position
.y()));
357 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
358 sublayer
->draw_transform());
359 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
360 sublayer
->screen_space_transform());
362 gfx::Transform arbitrary_translate
;
363 const float kTranslateX
= 10.6f
;
364 const float kTranslateY
= 20.6f
;
365 arbitrary_translate
.Translate(kTranslateX
, kTranslateY
);
366 SetLayerPropertiesForTesting(scroll_layer
,
373 ExecuteCalculateDrawProperties(
374 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
375 expected_transform
.MakeIdentity();
376 expected_transform
.Translate(
377 MathUtil::Round(kTranslateX
* kPageScale
* kDeviceScale
+
378 sub_layer_screen_position
.x()),
379 MathUtil::Round(kTranslateY
* kPageScale
* kDeviceScale
+
380 sub_layer_screen_position
.y()));
381 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
382 sublayer
->draw_transform());
385 TEST_F(LayerTreeHostCommonTest
, TransformsForSimpleHierarchy
) {
386 gfx::Transform identity_matrix
;
387 scoped_refptr
<Layer
> root
= Layer::Create();
388 scoped_refptr
<Layer
> parent
= Layer::Create();
389 scoped_refptr
<Layer
> child
= Layer::Create();
390 scoped_refptr
<Layer
> grand_child
= Layer::Create();
391 root
->AddChild(parent
);
392 parent
->AddChild(child
);
393 child
->AddChild(grand_child
);
395 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
396 host
->SetRootLayer(root
);
398 // One-time setup of root layer
399 SetLayerPropertiesForTesting(root
.get(),
407 // Case 1: parent's anchor point should not affect child or grand_child.
408 SetLayerPropertiesForTesting(parent
.get(),
410 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
415 SetLayerPropertiesForTesting(child
.get(),
422 SetLayerPropertiesForTesting(grand_child
.get(),
429 ExecuteCalculateDrawProperties(root
.get());
430 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
431 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
432 child
->screen_space_transform());
433 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
434 grand_child
->draw_transform());
435 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
436 grand_child
->screen_space_transform());
438 // Case 2: parent's position affects child and grand_child.
439 gfx::Transform parent_position_transform
;
440 parent_position_transform
.Translate(0.f
, 1.2f
);
441 SetLayerPropertiesForTesting(parent
.get(),
443 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
444 gfx::PointF(0.f
, 1.2f
),
448 SetLayerPropertiesForTesting(child
.get(),
455 SetLayerPropertiesForTesting(grand_child
.get(),
462 ExecuteCalculateDrawProperties(root
.get());
463 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
464 child
->draw_transform());
465 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
466 child
->screen_space_transform());
467 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
468 grand_child
->draw_transform());
469 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
470 grand_child
->screen_space_transform());
472 // Case 3: parent's local transform affects child and grandchild
473 gfx::Transform parent_layer_transform
;
474 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
475 gfx::Transform parent_translation_to_anchor
;
476 parent_translation_to_anchor
.Translate(2.5, 3.0);
477 gfx::Transform parent_composite_transform
=
478 parent_translation_to_anchor
* parent_layer_transform
*
479 Inverse(parent_translation_to_anchor
);
480 SetLayerPropertiesForTesting(parent
.get(),
481 parent_layer_transform
,
482 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
487 SetLayerPropertiesForTesting(child
.get(),
494 SetLayerPropertiesForTesting(grand_child
.get(),
501 ExecuteCalculateDrawProperties(root
.get());
502 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
503 child
->draw_transform());
504 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
505 child
->screen_space_transform());
506 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
507 grand_child
->draw_transform());
508 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
509 grand_child
->screen_space_transform());
512 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleRenderSurface
) {
513 scoped_refptr
<Layer
> root
= Layer::Create();
514 scoped_refptr
<Layer
> parent
= Layer::Create();
515 scoped_refptr
<Layer
> child
= Layer::Create();
516 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
517 make_scoped_refptr(new LayerWithForcedDrawsContent());
518 root
->AddChild(parent
);
519 parent
->AddChild(child
);
520 child
->AddChild(grand_child
);
522 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
523 host
->SetRootLayer(root
);
525 // One-time setup of root layer
526 gfx::Transform identity_matrix
;
527 SetLayerPropertiesForTesting(root
.get(),
535 // Child is set up so that a new render surface should be created.
536 child
->SetOpacity(0.5f
);
537 child
->SetForceRenderSurface(true);
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 // Child's render surface should not exist yet.
557 ASSERT_FALSE(child
->render_surface());
559 SetLayerPropertiesForTesting(parent
.get(),
560 parent_layer_transform
,
561 gfx::Point3F(25.0f
, 30.0f
, 0.f
),
566 SetLayerPropertiesForTesting(child
.get(),
573 SetLayerPropertiesForTesting(grand_child
.get(),
580 ExecuteCalculateDrawProperties(root
.get());
582 // Render surface should have been created now.
583 ASSERT_TRUE(child
->render_surface());
584 ASSERT_EQ(child
, child
->render_target());
586 // The child layer's draw transform should refer to its new render surface.
587 // The screen-space transform, however, should still refer to the root.
588 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform
,
589 child
->draw_transform());
590 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
591 child
->screen_space_transform());
593 // Because the grand_child is the only drawable content, the child's render
594 // surface will tighten its bounds to the grand_child. The scale at which the
595 // surface's subtree is drawn must be removed from the composite transform.
596 EXPECT_TRANSFORMATION_MATRIX_EQ(
597 surface_sublayer_composite_transform
,
598 child
->render_target()->render_surface()->draw_transform());
600 // The screen space is the same as the target since the child surface draws
602 EXPECT_TRANSFORMATION_MATRIX_EQ(
603 surface_sublayer_composite_transform
,
604 child
->render_target()->render_surface()->screen_space_transform());
607 TEST_F(LayerTreeHostCommonTest
, TransformsForReplica
) {
608 scoped_refptr
<Layer
> root
= Layer::Create();
609 scoped_refptr
<Layer
> parent
= Layer::Create();
610 scoped_refptr
<Layer
> child
= Layer::Create();
611 scoped_refptr
<Layer
> child_replica
= Layer::Create();
612 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
613 make_scoped_refptr(new LayerWithForcedDrawsContent());
614 root
->AddChild(parent
);
615 parent
->AddChild(child
);
616 child
->AddChild(grand_child
);
617 child
->SetReplicaLayer(child_replica
.get());
619 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
620 host
->SetRootLayer(root
);
622 // One-time setup of root layer
623 gfx::Transform identity_matrix
;
624 SetLayerPropertiesForTesting(root
.get(),
632 // Child is set up so that a new render surface should be created.
633 child
->SetOpacity(0.5f
);
635 gfx::Transform parent_layer_transform
;
636 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
637 gfx::Transform parent_translation_to_anchor
;
638 parent_translation_to_anchor
.Translate(2.5, 3.0);
639 gfx::Transform parent_composite_transform
=
640 parent_translation_to_anchor
* parent_layer_transform
*
641 Inverse(parent_translation_to_anchor
);
642 gfx::Transform replica_layer_transform
;
643 replica_layer_transform
.Scale3d(3.0, 3.0, 1.0);
644 gfx::Vector2dF parent_composite_scale
=
645 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
647 gfx::Transform surface_sublayer_transform
;
648 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
649 parent_composite_scale
.y());
650 gfx::Transform replica_composite_transform
=
651 parent_composite_transform
* replica_layer_transform
*
652 Inverse(surface_sublayer_transform
);
654 // Child's render surface should not exist yet.
655 ASSERT_FALSE(child
->render_surface());
657 SetLayerPropertiesForTesting(parent
.get(),
658 parent_layer_transform
,
659 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
664 SetLayerPropertiesForTesting(child
.get(),
671 SetLayerPropertiesForTesting(grand_child
.get(),
674 gfx::PointF(-0.5f
, -0.5f
),
678 SetLayerPropertiesForTesting(child_replica
.get(),
679 replica_layer_transform
,
685 ExecuteCalculateDrawProperties(root
.get());
687 // Render surface should have been created now.
688 ASSERT_TRUE(child
->render_surface());
689 ASSERT_EQ(child
, child
->render_target());
691 EXPECT_TRANSFORMATION_MATRIX_EQ(
692 replica_composite_transform
,
693 child
->render_target()->render_surface()->replica_draw_transform());
694 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform
,
695 child
->render_target()
697 ->replica_screen_space_transform());
700 TEST_F(LayerTreeHostCommonTest
, TransformsForRenderSurfaceHierarchy
) {
701 // This test creates a more complex tree and verifies it all at once. This
702 // covers the following cases:
703 // - layers that are described w.r.t. a render surface: should have draw
704 // transforms described w.r.t. that surface
705 // - A render surface described w.r.t. an ancestor render surface: should
706 // have a draw transform described w.r.t. that ancestor surface
707 // - Replicas of a render surface are described w.r.t. the replica's
708 // transform around its anchor, along with the surface itself.
709 // - Sanity check on recursion: verify transforms of layers described w.r.t.
710 // a render surface that is described w.r.t. an ancestor render surface.
711 // - verifying that each layer has a reference to the correct render surface
712 // and render target values.
714 scoped_refptr
<Layer
> root
= Layer::Create();
715 scoped_refptr
<Layer
> parent
= Layer::Create();
716 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
717 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
718 scoped_refptr
<Layer
> child_of_root
= Layer::Create();
719 scoped_refptr
<Layer
> child_of_rs1
= Layer::Create();
720 scoped_refptr
<Layer
> child_of_rs2
= Layer::Create();
721 scoped_refptr
<Layer
> replica_of_rs1
= Layer::Create();
722 scoped_refptr
<Layer
> replica_of_rs2
= Layer::Create();
723 scoped_refptr
<Layer
> grand_child_of_root
= Layer::Create();
724 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs1
=
725 make_scoped_refptr(new LayerWithForcedDrawsContent());
726 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs2
=
727 make_scoped_refptr(new LayerWithForcedDrawsContent());
728 root
->AddChild(parent
);
729 parent
->AddChild(render_surface1
);
730 parent
->AddChild(child_of_root
);
731 render_surface1
->AddChild(child_of_rs1
);
732 render_surface1
->AddChild(render_surface2
);
733 render_surface2
->AddChild(child_of_rs2
);
734 child_of_root
->AddChild(grand_child_of_root
);
735 child_of_rs1
->AddChild(grand_child_of_rs1
);
736 child_of_rs2
->AddChild(grand_child_of_rs2
);
737 render_surface1
->SetReplicaLayer(replica_of_rs1
.get());
738 render_surface2
->SetReplicaLayer(replica_of_rs2
.get());
740 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
741 host
->SetRootLayer(root
);
743 // In combination with descendant draws content, opacity != 1 forces the layer
744 // to have a new render surface.
745 render_surface1
->SetOpacity(0.5f
);
746 render_surface2
->SetOpacity(0.33f
);
748 // One-time setup of root layer
749 gfx::Transform identity_matrix
;
750 SetLayerPropertiesForTesting(root
.get(),
758 // All layers in the tree are initialized with an anchor at .25 and a size of
759 // (10,10). matrix "A" is the composite layer transform used in all layers,
760 // Matrix "R" is the composite replica transform used in all replica layers.
761 gfx::Transform translation_to_anchor
;
762 translation_to_anchor
.Translate(2.5, 0.0);
763 gfx::Transform layer_transform
;
764 layer_transform
.Translate(1.0, 1.0);
765 gfx::Transform replica_layer_transform
;
766 replica_layer_transform
.Scale3d(-2.0, 5.0, 1.0);
769 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
770 gfx::Transform R
= A
* translation_to_anchor
* replica_layer_transform
*
771 Inverse(translation_to_anchor
);
773 gfx::Vector2dF surface1_parent_transform_scale
=
774 MathUtil::ComputeTransform2dScaleComponents(A
, 1.f
);
775 gfx::Transform surface1_sublayer_transform
;
776 surface1_sublayer_transform
.Scale(surface1_parent_transform_scale
.x(),
777 surface1_parent_transform_scale
.y());
779 // SS1 = transform given to the subtree of render_surface1
780 gfx::Transform SS1
= surface1_sublayer_transform
;
781 // S1 = transform to move from render_surface1 pixels to the layer space of
783 gfx::Transform S1
= Inverse(surface1_sublayer_transform
);
785 gfx::Vector2dF surface2_parent_transform_scale
=
786 MathUtil::ComputeTransform2dScaleComponents(SS1
* A
, 1.f
);
787 gfx::Transform surface2_sublayer_transform
;
788 surface2_sublayer_transform
.Scale(surface2_parent_transform_scale
.x(),
789 surface2_parent_transform_scale
.y());
791 // SS2 = transform given to the subtree of render_surface2
792 gfx::Transform SS2
= surface2_sublayer_transform
;
793 // S2 = transform to move from render_surface2 pixels to the layer space of
795 gfx::Transform S2
= Inverse(surface2_sublayer_transform
);
797 SetLayerPropertiesForTesting(parent
.get(),
799 gfx::Point3F(2.5f
, 0.f
, 0.f
),
804 SetLayerPropertiesForTesting(render_surface1
.get(),
806 gfx::Point3F(2.5f
, 0.f
, 0.f
),
811 SetLayerPropertiesForTesting(render_surface2
.get(),
813 gfx::Point3F(2.5f
, 0.f
, 0.f
),
818 SetLayerPropertiesForTesting(child_of_root
.get(),
820 gfx::Point3F(2.5f
, 0.f
, 0.f
),
825 SetLayerPropertiesForTesting(child_of_rs1
.get(),
827 gfx::Point3F(2.5f
, 0.f
, 0.f
),
832 SetLayerPropertiesForTesting(child_of_rs2
.get(),
834 gfx::Point3F(2.5f
, 0.f
, 0.f
),
839 SetLayerPropertiesForTesting(grand_child_of_root
.get(),
841 gfx::Point3F(2.5f
, 0.f
, 0.f
),
846 SetLayerPropertiesForTesting(grand_child_of_rs1
.get(),
848 gfx::Point3F(2.5f
, 0.f
, 0.f
),
853 SetLayerPropertiesForTesting(grand_child_of_rs2
.get(),
855 gfx::Point3F(2.5f
, 0.f
, 0.f
),
860 SetLayerPropertiesForTesting(replica_of_rs1
.get(),
861 replica_layer_transform
,
862 gfx::Point3F(2.5f
, 0.f
, 0.f
),
867 SetLayerPropertiesForTesting(replica_of_rs2
.get(),
868 replica_layer_transform
,
869 gfx::Point3F(2.5f
, 0.f
, 0.f
),
875 ExecuteCalculateDrawProperties(root
.get());
877 // Only layers that are associated with render surfaces should have an actual
878 // RenderSurface() value.
879 ASSERT_TRUE(root
->render_surface());
880 ASSERT_FALSE(child_of_root
->render_surface());
881 ASSERT_FALSE(grand_child_of_root
->render_surface());
883 ASSERT_TRUE(render_surface1
->render_surface());
884 ASSERT_FALSE(child_of_rs1
->render_surface());
885 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
887 ASSERT_TRUE(render_surface2
->render_surface());
888 ASSERT_FALSE(child_of_rs2
->render_surface());
889 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
891 // Verify all render target accessors
892 EXPECT_EQ(root
, parent
->render_target());
893 EXPECT_EQ(root
, child_of_root
->render_target());
894 EXPECT_EQ(root
, grand_child_of_root
->render_target());
896 EXPECT_EQ(render_surface1
, render_surface1
->render_target());
897 EXPECT_EQ(render_surface1
, child_of_rs1
->render_target());
898 EXPECT_EQ(render_surface1
, grand_child_of_rs1
->render_target());
900 EXPECT_EQ(render_surface2
, render_surface2
->render_target());
901 EXPECT_EQ(render_surface2
, child_of_rs2
->render_target());
902 EXPECT_EQ(render_surface2
, grand_child_of_rs2
->render_target());
904 // Verify layer draw transforms note that draw transforms are described with
905 // respect to the nearest ancestor render surface but screen space transforms
906 // are described with respect to the root.
907 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->draw_transform());
908 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
, child_of_root
->draw_transform());
909 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
910 grand_child_of_root
->draw_transform());
912 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
, render_surface1
->draw_transform());
913 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
, child_of_rs1
->draw_transform());
914 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
* A
,
915 grand_child_of_rs1
->draw_transform());
917 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
, render_surface2
->draw_transform());
918 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
, child_of_rs2
->draw_transform());
919 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
* A
,
920 grand_child_of_rs2
->draw_transform());
922 // Verify layer screen-space transforms
924 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->screen_space_transform());
925 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
926 child_of_root
->screen_space_transform());
927 EXPECT_TRANSFORMATION_MATRIX_EQ(
928 A
* A
* A
, grand_child_of_root
->screen_space_transform());
930 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
931 render_surface1
->screen_space_transform());
932 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
933 child_of_rs1
->screen_space_transform());
934 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
935 grand_child_of_rs1
->screen_space_transform());
937 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
938 render_surface2
->screen_space_transform());
939 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
940 child_of_rs2
->screen_space_transform());
941 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
* A
,
942 grand_child_of_rs2
->screen_space_transform());
944 // Verify render surface transforms.
946 // Draw transform of render surface 1 is described with respect to root.
947 EXPECT_TRANSFORMATION_MATRIX_EQ(
948 A
* A
* S1
, render_surface1
->render_surface()->draw_transform());
949 EXPECT_TRANSFORMATION_MATRIX_EQ(
950 A
* R
* S1
, render_surface1
->render_surface()->replica_draw_transform());
951 EXPECT_TRANSFORMATION_MATRIX_EQ(
952 A
* A
* S1
, render_surface1
->render_surface()->screen_space_transform());
953 EXPECT_TRANSFORMATION_MATRIX_EQ(
955 render_surface1
->render_surface()->replica_screen_space_transform());
956 // Draw transform of render surface 2 is described with respect to render
958 EXPECT_TRANSFORMATION_MATRIX_EQ(
959 SS1
* A
* S2
, render_surface2
->render_surface()->draw_transform());
960 EXPECT_TRANSFORMATION_MATRIX_EQ(
962 render_surface2
->render_surface()->replica_draw_transform());
963 EXPECT_TRANSFORMATION_MATRIX_EQ(
965 render_surface2
->render_surface()->screen_space_transform());
966 EXPECT_TRANSFORMATION_MATRIX_EQ(
968 render_surface2
->render_surface()->replica_screen_space_transform());
970 // Sanity check. If these fail there is probably a bug in the test itself. It
971 // is expected that we correctly set up transforms so that the y-component of
972 // the screen-space transform encodes the "depth" of the layer in the tree.
973 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
975 child_of_root
->screen_space_transform().matrix().get(1, 3));
977 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
980 render_surface1
->screen_space_transform().matrix().get(1, 3));
982 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
984 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
987 render_surface2
->screen_space_transform().matrix().get(1, 3));
989 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
991 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
994 TEST_F(LayerTreeHostCommonTest
, TransformsForFlatteningLayer
) {
995 // For layers that flatten their subtree, there should be an orthographic
996 // projection (for x and y values) in the middle of the transform sequence.
997 // Note that the way the code is currently implemented, it is not expected to
998 // use a canonical orthographic projection.
1000 scoped_refptr
<Layer
> root
= Layer::Create();
1001 scoped_refptr
<Layer
> child
= Layer::Create();
1002 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1003 make_scoped_refptr(new LayerWithForcedDrawsContent());
1005 gfx::Transform rotation_about_y_axis
;
1006 rotation_about_y_axis
.RotateAboutYAxis(30.0);
1008 const gfx::Transform identity_matrix
;
1009 SetLayerPropertiesForTesting(root
.get(),
1013 gfx::Size(100, 100),
1016 SetLayerPropertiesForTesting(child
.get(),
1017 rotation_about_y_axis
,
1023 SetLayerPropertiesForTesting(grand_child
.get(),
1024 rotation_about_y_axis
,
1031 root
->AddChild(child
);
1032 child
->AddChild(grand_child
);
1033 child
->SetForceRenderSurface(true);
1035 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1036 host
->SetRootLayer(root
);
1038 // No layers in this test should preserve 3d.
1039 ASSERT_TRUE(root
->should_flatten_transform());
1040 ASSERT_TRUE(child
->should_flatten_transform());
1041 ASSERT_TRUE(grand_child
->should_flatten_transform());
1043 gfx::Transform expected_child_draw_transform
= rotation_about_y_axis
;
1044 gfx::Transform expected_child_screen_space_transform
= rotation_about_y_axis
;
1045 gfx::Transform expected_grand_child_draw_transform
=
1046 rotation_about_y_axis
; // draws onto child's render surface
1047 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
1048 flattened_rotation_about_y
.FlattenTo2d();
1049 gfx::Transform expected_grand_child_screen_space_transform
=
1050 flattened_rotation_about_y
* rotation_about_y_axis
;
1052 ExecuteCalculateDrawProperties(root
.get());
1054 // The child's draw transform should have been taken by its surface.
1055 ASSERT_TRUE(child
->render_surface());
1056 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform
,
1057 child
->render_surface()->draw_transform());
1058 EXPECT_TRANSFORMATION_MATRIX_EQ(
1059 expected_child_screen_space_transform
,
1060 child
->render_surface()->screen_space_transform());
1061 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1062 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform
,
1063 child
->screen_space_transform());
1064 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform
,
1065 grand_child
->draw_transform());
1066 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform
,
1067 grand_child
->screen_space_transform());
1070 TEST_F(LayerTreeHostCommonTest
, TransformsForDegenerateIntermediateLayer
) {
1071 // A layer that is empty in one axis, but not the other, was accidentally
1072 // skipping a necessary translation. Without that translation, the coordinate
1073 // space of the layer's draw transform is incorrect.
1075 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1076 // but if that layer becomes a render surface, then its draw transform is
1077 // implicitly inherited by the rest of the subtree, which then is positioned
1078 // incorrectly as a result.
1080 scoped_refptr
<Layer
> root
= Layer::Create();
1081 scoped_refptr
<Layer
> child
= Layer::Create();
1082 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1083 make_scoped_refptr(new LayerWithForcedDrawsContent());
1085 // The child height is zero, but has non-zero width that should be accounted
1086 // for while computing draw transforms.
1087 const gfx::Transform identity_matrix
;
1088 SetLayerPropertiesForTesting(root
.get(),
1092 gfx::Size(100, 100),
1095 SetLayerPropertiesForTesting(child
.get(),
1102 SetLayerPropertiesForTesting(grand_child
.get(),
1110 root
->AddChild(child
);
1111 child
->AddChild(grand_child
);
1112 child
->SetForceRenderSurface(true);
1114 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1115 host
->SetRootLayer(root
);
1117 ExecuteCalculateDrawProperties(root
.get());
1119 ASSERT_TRUE(child
->render_surface());
1120 // This is the real test, the rest are sanity checks.
1121 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1122 child
->render_surface()->draw_transform());
1123 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1124 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1125 grand_child
->draw_transform());
1128 TEST_F(LayerTreeHostCommonTest
, TransformAboveRootLayer
) {
1129 // Transformations applied at the root of the tree should be forwarded
1130 // to child layers instead of applied to the root RenderSurface.
1131 const gfx::Transform identity_matrix
;
1132 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
1133 new LayerWithForcedDrawsContent
;
1134 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1135 new LayerWithForcedDrawsContent
;
1136 child
->SetScrollClipLayerId(root
->id());
1137 root
->AddChild(child
);
1139 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1140 host
->SetRootLayer(root
);
1142 SetLayerPropertiesForTesting(root
.get(),
1149 SetLayerPropertiesForTesting(child
.get(),
1157 gfx::Transform translate
;
1158 translate
.Translate(50, 50);
1160 RenderSurfaceLayerList render_surface_layer_list
;
1161 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1162 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1163 inputs
.can_adjust_raster_scales
= true;
1164 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1165 EXPECT_EQ(translate
, root
->draw_properties().target_space_transform
);
1166 EXPECT_EQ(translate
, child
->draw_properties().target_space_transform
);
1167 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1168 EXPECT_EQ(1.f
, root
->draw_properties().device_scale_factor
);
1169 EXPECT_EQ(1.f
, child
->draw_properties().device_scale_factor
);
1172 gfx::Transform scale
;
1175 RenderSurfaceLayerList render_surface_layer_list
;
1176 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1177 root
.get(), root
->bounds(), scale
, &render_surface_layer_list
);
1178 inputs
.can_adjust_raster_scales
= true;
1179 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1180 EXPECT_EQ(scale
, root
->draw_properties().target_space_transform
);
1181 EXPECT_EQ(scale
, child
->draw_properties().target_space_transform
);
1182 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1183 EXPECT_EQ(2.f
, root
->draw_properties().device_scale_factor
);
1184 EXPECT_EQ(2.f
, child
->draw_properties().device_scale_factor
);
1187 gfx::Transform rotate
;
1190 RenderSurfaceLayerList render_surface_layer_list
;
1191 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1192 root
.get(), root
->bounds(), rotate
, &render_surface_layer_list
);
1193 inputs
.can_adjust_raster_scales
= true;
1194 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1195 EXPECT_EQ(rotate
, root
->draw_properties().target_space_transform
);
1196 EXPECT_EQ(rotate
, child
->draw_properties().target_space_transform
);
1197 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1198 EXPECT_EQ(1.f
, root
->draw_properties().device_scale_factor
);
1199 EXPECT_EQ(1.f
, child
->draw_properties().device_scale_factor
);
1202 gfx::Transform composite
;
1203 composite
.ConcatTransform(translate
);
1204 composite
.ConcatTransform(scale
);
1205 composite
.ConcatTransform(rotate
);
1207 RenderSurfaceLayerList render_surface_layer_list
;
1208 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1209 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1210 inputs
.can_adjust_raster_scales
= true;
1211 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1212 EXPECT_EQ(composite
, root
->draw_properties().target_space_transform
);
1213 EXPECT_EQ(composite
, child
->draw_properties().target_space_transform
);
1214 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1217 // Verify it composes correctly with device scale.
1218 float device_scale_factor
= 1.5f
;
1221 RenderSurfaceLayerList render_surface_layer_list
;
1222 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1223 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1224 inputs
.device_scale_factor
= device_scale_factor
;
1225 inputs
.can_adjust_raster_scales
= true;
1226 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1227 gfx::Transform device_scaled_translate
= translate
;
1228 device_scaled_translate
.Scale(device_scale_factor
, device_scale_factor
);
1229 EXPECT_EQ(device_scaled_translate
,
1230 root
->draw_properties().target_space_transform
);
1231 EXPECT_EQ(device_scaled_translate
,
1232 child
->draw_properties().target_space_transform
);
1233 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1234 EXPECT_EQ(device_scale_factor
, root
->draw_properties().device_scale_factor
);
1235 EXPECT_EQ(device_scale_factor
,
1236 child
->draw_properties().device_scale_factor
);
1239 // Verify it composes correctly with page scale.
1240 float page_scale_factor
= 2.f
;
1243 RenderSurfaceLayerList render_surface_layer_list
;
1244 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1245 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1246 inputs
.page_scale_factor
= page_scale_factor
;
1247 inputs
.page_scale_application_layer
= root
.get();
1248 inputs
.can_adjust_raster_scales
= true;
1249 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1250 gfx::Transform page_scaled_translate
= translate
;
1251 page_scaled_translate
.Scale(page_scale_factor
, page_scale_factor
);
1252 EXPECT_EQ(translate
, root
->draw_properties().target_space_transform
);
1253 EXPECT_EQ(page_scaled_translate
,
1254 child
->draw_properties().target_space_transform
);
1255 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1256 EXPECT_EQ(1.f
, root
->draw_properties().device_scale_factor
);
1257 EXPECT_EQ(1.f
, child
->draw_properties().device_scale_factor
);
1260 // Verify that it composes correctly with transforms directly on root layer.
1261 root
->SetTransform(composite
);
1264 RenderSurfaceLayerList render_surface_layer_list
;
1265 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1266 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1267 inputs
.can_adjust_raster_scales
= true;
1268 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1269 gfx::Transform compositeSquared
= composite
;
1270 compositeSquared
.ConcatTransform(composite
);
1271 EXPECT_TRANSFORMATION_MATRIX_EQ(
1272 compositeSquared
, root
->draw_properties().target_space_transform
);
1273 EXPECT_TRANSFORMATION_MATRIX_EQ(
1274 compositeSquared
, child
->draw_properties().target_space_transform
);
1275 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1279 TEST_F(LayerTreeHostCommonTest
,
1280 RenderSurfaceListForRenderSurfaceWithClippedLayer
) {
1281 scoped_refptr
<Layer
> parent
= Layer::Create();
1282 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
1283 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1284 make_scoped_refptr(new LayerWithForcedDrawsContent());
1286 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1287 host
->SetRootLayer(parent
);
1289 const gfx::Transform identity_matrix
;
1290 SetLayerPropertiesForTesting(parent
.get(),
1297 SetLayerPropertiesForTesting(render_surface1
.get(),
1304 SetLayerPropertiesForTesting(child
.get(),
1307 gfx::PointF(30.f
, 30.f
),
1312 parent
->AddChild(render_surface1
);
1313 parent
->SetMasksToBounds(true);
1314 render_surface1
->AddChild(child
);
1315 render_surface1
->SetForceRenderSurface(true);
1317 RenderSurfaceLayerList render_surface_layer_list
;
1318 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1322 &render_surface_layer_list
);
1323 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1325 // The child layer's content is entirely outside the parent's clip rect, so
1326 // the intermediate render surface should not be listed here, even if it was
1327 // forced to be created. Render surfaces without children or visible content
1328 // are unexpected at draw time (e.g. we might try to create a content texture
1330 ASSERT_TRUE(parent
->render_surface());
1331 EXPECT_EQ(1U, render_surface_layer_list
.size());
1334 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceListForTransparentChild
) {
1335 scoped_refptr
<Layer
> parent
= Layer::Create();
1336 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
1337 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1338 make_scoped_refptr(new LayerWithForcedDrawsContent());
1340 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1341 host
->SetRootLayer(parent
);
1343 const gfx::Transform identity_matrix
;
1344 SetLayerPropertiesForTesting(render_surface1
.get(),
1351 SetLayerPropertiesForTesting(child
.get(),
1359 parent
->AddChild(render_surface1
);
1360 render_surface1
->AddChild(child
);
1361 render_surface1
->SetForceRenderSurface(true);
1362 render_surface1
->SetOpacity(0.f
);
1364 RenderSurfaceLayerList render_surface_layer_list
;
1365 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1366 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1367 inputs
.can_adjust_raster_scales
= true;
1368 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1370 // Since the layer is transparent, render_surface1->render_surface() should
1371 // not have gotten added anywhere. Also, the drawable content rect should not
1372 // have been extended by the children.
1373 ASSERT_TRUE(parent
->render_surface());
1374 EXPECT_EQ(0U, parent
->render_surface()->layer_list().size());
1375 EXPECT_EQ(1U, render_surface_layer_list
.size());
1376 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1377 EXPECT_EQ(gfx::Rect(), parent
->drawable_content_rect());
1380 TEST_F(LayerTreeHostCommonTest
, ForceRenderSurface
) {
1381 scoped_refptr
<Layer
> parent
= Layer::Create();
1382 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
1383 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1384 make_scoped_refptr(new LayerWithForcedDrawsContent());
1385 render_surface1
->SetForceRenderSurface(true);
1387 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1388 host
->SetRootLayer(parent
);
1390 const gfx::Transform identity_matrix
;
1391 SetLayerPropertiesForTesting(parent
.get(),
1398 SetLayerPropertiesForTesting(render_surface1
.get(),
1405 SetLayerPropertiesForTesting(child
.get(),
1413 parent
->AddChild(render_surface1
);
1414 render_surface1
->AddChild(child
);
1416 // Sanity check before the actual test
1417 EXPECT_FALSE(parent
->render_surface());
1418 EXPECT_FALSE(render_surface1
->render_surface());
1421 RenderSurfaceLayerList render_surface_layer_list
;
1422 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1423 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1424 inputs
.can_adjust_raster_scales
= true;
1425 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1427 // The root layer always creates a render surface
1428 EXPECT_TRUE(parent
->render_surface());
1429 EXPECT_TRUE(render_surface1
->render_surface());
1430 EXPECT_EQ(2U, render_surface_layer_list
.size());
1434 RenderSurfaceLayerList render_surface_layer_list
;
1435 render_surface1
->SetForceRenderSurface(false);
1436 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1437 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1438 inputs
.can_adjust_raster_scales
= true;
1439 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1440 EXPECT_TRUE(parent
->render_surface());
1441 EXPECT_FALSE(render_surface1
->render_surface());
1442 EXPECT_EQ(1U, render_surface_layer_list
.size());
1446 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsRenderSurfaces
) {
1447 // The entire subtree of layers that are outside the clip rect should be
1448 // culled away, and should not affect the render_surface_layer_list.
1450 // The test tree is set up as follows:
1451 // - all layers except the leaf_nodes are forced to be a new render surface
1452 // that have something to draw.
1453 // - parent is a large container layer.
1454 // - child has masksToBounds=true to cause clipping.
1455 // - grand_child is positioned outside of the child's bounds
1456 // - great_grand_child is also kept outside child's bounds.
1458 // In this configuration, grand_child and great_grand_child are completely
1459 // outside the clip rect, and they should never get scheduled on the list of
1463 const gfx::Transform identity_matrix
;
1464 scoped_refptr
<Layer
> parent
= Layer::Create();
1465 scoped_refptr
<Layer
> child
= Layer::Create();
1466 scoped_refptr
<Layer
> grand_child
= Layer::Create();
1467 scoped_refptr
<Layer
> great_grand_child
= Layer::Create();
1468 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1469 make_scoped_refptr(new LayerWithForcedDrawsContent());
1470 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1471 make_scoped_refptr(new LayerWithForcedDrawsContent());
1472 parent
->AddChild(child
);
1473 child
->AddChild(grand_child
);
1474 grand_child
->AddChild(great_grand_child
);
1476 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1477 host
->SetRootLayer(parent
);
1479 // leaf_node1 ensures that parent and child are kept on the
1480 // render_surface_layer_list, even though grand_child and great_grand_child
1481 // should be clipped.
1482 child
->AddChild(leaf_node1
);
1483 great_grand_child
->AddChild(leaf_node2
);
1485 SetLayerPropertiesForTesting(parent
.get(),
1489 gfx::Size(500, 500),
1492 SetLayerPropertiesForTesting(child
.get(),
1499 SetLayerPropertiesForTesting(grand_child
.get(),
1502 gfx::PointF(45.f
, 45.f
),
1506 SetLayerPropertiesForTesting(great_grand_child
.get(),
1513 SetLayerPropertiesForTesting(leaf_node1
.get(),
1517 gfx::Size(500, 500),
1520 SetLayerPropertiesForTesting(leaf_node2
.get(),
1528 child
->SetMasksToBounds(true);
1529 child
->SetOpacity(0.4f
);
1530 child
->SetForceRenderSurface(true);
1531 grand_child
->SetOpacity(0.5f
);
1532 great_grand_child
->SetOpacity(0.4f
);
1534 RenderSurfaceLayerList render_surface_layer_list
;
1535 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1536 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1537 inputs
.can_adjust_raster_scales
= true;
1538 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1540 ASSERT_EQ(2U, render_surface_layer_list
.size());
1541 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1542 EXPECT_EQ(child
->id(), render_surface_layer_list
.at(1)->id());
1545 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsSurfaceWithoutVisibleContent
) {
1546 // When a render surface has a clip rect, it is used to clip the content rect
1547 // of the surface. When the render surface is animating its transforms, then
1548 // the content rect's position in the clip rect is not defined on the main
1549 // thread, and its content rect should not be clipped.
1551 // The test tree is set up as follows:
1552 // - parent is a container layer that masksToBounds=true to cause clipping.
1553 // - child is a render surface, which has a clip rect set to the bounds of
1555 // - grand_child is a render surface, and the only visible content in child.
1556 // It is positioned outside of the clip rect from parent.
1558 // In this configuration, grand_child should be outside the clipped
1559 // content rect of the child, making grand_child not appear in the
1560 // render_surface_layer_list. However, when we place an animation on the
1561 // child, this clipping should be avoided and we should keep the grand_child
1562 // in the render_surface_layer_list.
1564 const gfx::Transform identity_matrix
;
1565 scoped_refptr
<Layer
> parent
= Layer::Create();
1566 scoped_refptr
<Layer
> child
= Layer::Create();
1567 scoped_refptr
<Layer
> grand_child
= Layer::Create();
1568 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node
=
1569 make_scoped_refptr(new LayerWithForcedDrawsContent());
1570 parent
->AddChild(child
);
1571 child
->AddChild(grand_child
);
1572 grand_child
->AddChild(leaf_node
);
1574 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1575 host
->SetRootLayer(parent
);
1577 SetLayerPropertiesForTesting(parent
.get(),
1581 gfx::Size(100, 100),
1584 SetLayerPropertiesForTesting(child
.get(),
1591 SetLayerPropertiesForTesting(grand_child
.get(),
1594 gfx::PointF(200.f
, 200.f
),
1598 SetLayerPropertiesForTesting(leaf_node
.get(),
1606 parent
->SetMasksToBounds(true);
1607 child
->SetOpacity(0.4f
);
1608 child
->SetForceRenderSurface(true);
1609 grand_child
->SetOpacity(0.4f
);
1610 grand_child
->SetForceRenderSurface(true);
1613 RenderSurfaceLayerList render_surface_layer_list
;
1614 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1615 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1616 inputs
.can_adjust_raster_scales
= true;
1617 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1619 // Without an animation, we should cull child and grand_child from the
1620 // render_surface_layer_list.
1621 ASSERT_EQ(1U, render_surface_layer_list
.size());
1622 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1625 // Now put an animating transform on child.
1626 AddAnimatedTransformToController(
1627 child
->layer_animation_controller(), 10.0, 30, 0);
1630 RenderSurfaceLayerList render_surface_layer_list
;
1631 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1632 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1633 inputs
.can_adjust_raster_scales
= true;
1634 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1636 // With an animating transform, we should keep child and grand_child in the
1637 // render_surface_layer_list.
1638 ASSERT_EQ(3U, render_surface_layer_list
.size());
1639 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1640 EXPECT_EQ(child
->id(), render_surface_layer_list
.at(1)->id());
1641 EXPECT_EQ(grand_child
->id(), render_surface_layer_list
.at(2)->id());
1645 TEST_F(LayerTreeHostCommonTest
, IsClippedIsSetCorrectly
) {
1646 // Layer's IsClipped() property is set to true when:
1647 // - the layer clips its subtree, e.g. masks to bounds,
1648 // - the layer is clipped by an ancestor that contributes to the same
1650 // - a surface is clipped by an ancestor that contributes to the same
1653 // In particular, for a layer that owns a render surface:
1654 // - the render surface inherits any clip from ancestors, and does NOT
1655 // pass that clipped status to the layer itself.
1656 // - but if the layer itself masks to bounds, it is considered clipped
1657 // and propagates the clip to the subtree.
1659 const gfx::Transform identity_matrix
;
1660 scoped_refptr
<Layer
> root
= Layer::Create();
1661 scoped_refptr
<Layer
> parent
= Layer::Create();
1662 scoped_refptr
<Layer
> child1
= Layer::Create();
1663 scoped_refptr
<Layer
> child2
= Layer::Create();
1664 scoped_refptr
<Layer
> grand_child
= Layer::Create();
1665 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1666 make_scoped_refptr(new LayerWithForcedDrawsContent());
1667 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1668 make_scoped_refptr(new LayerWithForcedDrawsContent());
1669 root
->AddChild(parent
);
1670 parent
->AddChild(child1
);
1671 parent
->AddChild(child2
);
1672 child1
->AddChild(grand_child
);
1673 child2
->AddChild(leaf_node2
);
1674 grand_child
->AddChild(leaf_node1
);
1676 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1677 host
->SetRootLayer(root
);
1679 child2
->SetForceRenderSurface(true);
1681 SetLayerPropertiesForTesting(root
.get(),
1685 gfx::Size(100, 100),
1688 SetLayerPropertiesForTesting(parent
.get(),
1692 gfx::Size(100, 100),
1695 SetLayerPropertiesForTesting(child1
.get(),
1699 gfx::Size(100, 100),
1702 SetLayerPropertiesForTesting(child2
.get(),
1706 gfx::Size(100, 100),
1709 SetLayerPropertiesForTesting(grand_child
.get(),
1713 gfx::Size(100, 100),
1716 SetLayerPropertiesForTesting(leaf_node1
.get(),
1720 gfx::Size(100, 100),
1723 SetLayerPropertiesForTesting(leaf_node2
.get(),
1727 gfx::Size(100, 100),
1731 // Case 1: nothing is clipped except the root render surface.
1733 RenderSurfaceLayerList render_surface_layer_list
;
1734 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1735 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1736 inputs
.can_adjust_raster_scales
= true;
1737 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1739 ASSERT_TRUE(root
->render_surface());
1740 ASSERT_TRUE(child2
->render_surface());
1742 EXPECT_FALSE(root
->is_clipped());
1743 EXPECT_TRUE(root
->render_surface()->is_clipped());
1744 EXPECT_FALSE(parent
->is_clipped());
1745 EXPECT_FALSE(child1
->is_clipped());
1746 EXPECT_FALSE(child2
->is_clipped());
1747 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1748 EXPECT_FALSE(grand_child
->is_clipped());
1749 EXPECT_FALSE(leaf_node1
->is_clipped());
1750 EXPECT_FALSE(leaf_node2
->is_clipped());
1753 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1754 // surface are clipped. But layers that contribute to child2's surface are
1755 // not clipped explicitly because child2's surface already accounts for
1758 RenderSurfaceLayerList render_surface_layer_list
;
1759 parent
->SetMasksToBounds(true);
1760 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1761 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1762 inputs
.can_adjust_raster_scales
= true;
1763 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1765 ASSERT_TRUE(root
->render_surface());
1766 ASSERT_TRUE(child2
->render_surface());
1768 EXPECT_FALSE(root
->is_clipped());
1769 EXPECT_TRUE(root
->render_surface()->is_clipped());
1770 EXPECT_TRUE(parent
->is_clipped());
1771 EXPECT_TRUE(child1
->is_clipped());
1772 EXPECT_FALSE(child2
->is_clipped());
1773 EXPECT_TRUE(child2
->render_surface()->is_clipped());
1774 EXPECT_TRUE(grand_child
->is_clipped());
1775 EXPECT_TRUE(leaf_node1
->is_clipped());
1776 EXPECT_FALSE(leaf_node2
->is_clipped());
1779 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1780 // child2's render surface is not clipped.
1782 RenderSurfaceLayerList render_surface_layer_list
;
1783 parent
->SetMasksToBounds(false);
1784 child2
->SetMasksToBounds(true);
1785 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1786 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1787 inputs
.can_adjust_raster_scales
= true;
1788 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1790 ASSERT_TRUE(root
->render_surface());
1791 ASSERT_TRUE(child2
->render_surface());
1793 EXPECT_FALSE(root
->is_clipped());
1794 EXPECT_TRUE(root
->render_surface()->is_clipped());
1795 EXPECT_FALSE(parent
->is_clipped());
1796 EXPECT_FALSE(child1
->is_clipped());
1797 EXPECT_TRUE(child2
->is_clipped());
1798 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1799 EXPECT_FALSE(grand_child
->is_clipped());
1800 EXPECT_FALSE(leaf_node1
->is_clipped());
1801 EXPECT_TRUE(leaf_node2
->is_clipped());
1805 TEST_F(LayerTreeHostCommonTest
, DrawableContentRectForLayers
) {
1806 // Verify that layers get the appropriate DrawableContentRect when their
1807 // parent masksToBounds is true.
1809 // grand_child1 - completely inside the region; DrawableContentRect should
1810 // be the layer rect expressed in target space.
1811 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1812 // will be the intersection of layer bounds and the mask region.
1813 // grand_child3 - partially clipped and masksToBounds; the
1814 // DrawableContentRect will still be the intersection of layer bounds and
1816 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1820 const gfx::Transform identity_matrix
;
1821 scoped_refptr
<Layer
> parent
= Layer::Create();
1822 scoped_refptr
<Layer
> child
= Layer::Create();
1823 scoped_refptr
<Layer
> grand_child1
= Layer::Create();
1824 scoped_refptr
<Layer
> grand_child2
= Layer::Create();
1825 scoped_refptr
<Layer
> grand_child3
= Layer::Create();
1826 scoped_refptr
<Layer
> grand_child4
= Layer::Create();
1828 parent
->AddChild(child
);
1829 child
->AddChild(grand_child1
);
1830 child
->AddChild(grand_child2
);
1831 child
->AddChild(grand_child3
);
1832 child
->AddChild(grand_child4
);
1834 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1835 host
->SetRootLayer(parent
);
1837 SetLayerPropertiesForTesting(parent
.get(),
1841 gfx::Size(500, 500),
1844 SetLayerPropertiesForTesting(child
.get(),
1851 SetLayerPropertiesForTesting(grand_child1
.get(),
1854 gfx::PointF(5.f
, 5.f
),
1858 SetLayerPropertiesForTesting(grand_child2
.get(),
1861 gfx::PointF(15.f
, 15.f
),
1865 SetLayerPropertiesForTesting(grand_child3
.get(),
1868 gfx::PointF(15.f
, 15.f
),
1872 SetLayerPropertiesForTesting(grand_child4
.get(),
1875 gfx::PointF(45.f
, 45.f
),
1880 child
->SetMasksToBounds(true);
1881 grand_child3
->SetMasksToBounds(true);
1883 // Force everyone to be a render surface.
1884 child
->SetOpacity(0.4f
);
1885 grand_child1
->SetOpacity(0.5f
);
1886 grand_child2
->SetOpacity(0.5f
);
1887 grand_child3
->SetOpacity(0.5f
);
1888 grand_child4
->SetOpacity(0.5f
);
1890 RenderSurfaceLayerList render_surface_layer_list
;
1891 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1892 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1893 inputs
.can_adjust_raster_scales
= true;
1894 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1896 EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10),
1897 grand_child1
->drawable_content_rect());
1898 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
1899 grand_child3
->drawable_content_rect());
1900 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
1901 grand_child3
->drawable_content_rect());
1902 EXPECT_TRUE(grand_child4
->drawable_content_rect().IsEmpty());
1905 TEST_F(LayerTreeHostCommonTest
, ClipRectIsPropagatedCorrectlyToSurfaces
) {
1906 // Verify that render surfaces (and their layers) get the appropriate
1907 // clip rects when their parent masksToBounds is true.
1909 // Layers that own render surfaces (at least for now) do not inherit any
1910 // clipping; instead the surface will enforce the clip for the entire subtree.
1911 // They may still have a clip rect of their own layer bounds, however, if
1912 // masksToBounds was true.
1913 const gfx::Transform identity_matrix
;
1914 scoped_refptr
<Layer
> parent
= Layer::Create();
1915 scoped_refptr
<Layer
> child
= Layer::Create();
1916 scoped_refptr
<Layer
> grand_child1
= Layer::Create();
1917 scoped_refptr
<Layer
> grand_child2
= Layer::Create();
1918 scoped_refptr
<Layer
> grand_child3
= Layer::Create();
1919 scoped_refptr
<Layer
> grand_child4
= Layer::Create();
1920 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1921 make_scoped_refptr(new LayerWithForcedDrawsContent());
1922 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1923 make_scoped_refptr(new LayerWithForcedDrawsContent());
1924 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node3
=
1925 make_scoped_refptr(new LayerWithForcedDrawsContent());
1926 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node4
=
1927 make_scoped_refptr(new LayerWithForcedDrawsContent());
1929 parent
->AddChild(child
);
1930 child
->AddChild(grand_child1
);
1931 child
->AddChild(grand_child2
);
1932 child
->AddChild(grand_child3
);
1933 child
->AddChild(grand_child4
);
1935 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1936 host
->SetRootLayer(parent
);
1938 // the leaf nodes ensure that these grand_children become render surfaces for
1940 grand_child1
->AddChild(leaf_node1
);
1941 grand_child2
->AddChild(leaf_node2
);
1942 grand_child3
->AddChild(leaf_node3
);
1943 grand_child4
->AddChild(leaf_node4
);
1945 SetLayerPropertiesForTesting(parent
.get(),
1949 gfx::Size(500, 500),
1952 SetLayerPropertiesForTesting(child
.get(),
1959 SetLayerPropertiesForTesting(grand_child1
.get(),
1962 gfx::PointF(5.f
, 5.f
),
1966 SetLayerPropertiesForTesting(grand_child2
.get(),
1969 gfx::PointF(15.f
, 15.f
),
1973 SetLayerPropertiesForTesting(grand_child3
.get(),
1976 gfx::PointF(15.f
, 15.f
),
1980 SetLayerPropertiesForTesting(grand_child4
.get(),
1983 gfx::PointF(45.f
, 45.f
),
1987 SetLayerPropertiesForTesting(leaf_node1
.get(),
1994 SetLayerPropertiesForTesting(leaf_node2
.get(),
2001 SetLayerPropertiesForTesting(leaf_node3
.get(),
2008 SetLayerPropertiesForTesting(leaf_node4
.get(),
2016 child
->SetMasksToBounds(true);
2017 grand_child3
->SetMasksToBounds(true);
2018 grand_child4
->SetMasksToBounds(true);
2020 // Force everyone to be a render surface.
2021 child
->SetOpacity(0.4f
);
2022 child
->SetForceRenderSurface(true);
2023 grand_child1
->SetOpacity(0.5f
);
2024 grand_child1
->SetForceRenderSurface(true);
2025 grand_child2
->SetOpacity(0.5f
);
2026 grand_child2
->SetForceRenderSurface(true);
2027 grand_child3
->SetOpacity(0.5f
);
2028 grand_child3
->SetForceRenderSurface(true);
2029 grand_child4
->SetOpacity(0.5f
);
2030 grand_child4
->SetForceRenderSurface(true);
2032 RenderSurfaceLayerList render_surface_layer_list
;
2033 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
2034 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
2035 inputs
.can_adjust_raster_scales
= true;
2036 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
2037 ASSERT_TRUE(grand_child1
->render_surface());
2038 ASSERT_TRUE(grand_child2
->render_surface());
2039 ASSERT_TRUE(grand_child3
->render_surface());
2041 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2043 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
2044 grand_child1
->render_surface()->clip_rect());
2045 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
2046 grand_child2
->render_surface()->clip_rect());
2047 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
2048 grand_child3
->render_surface()->clip_rect());
2051 TEST_F(LayerTreeHostCommonTest
, AnimationsForRenderSurfaceHierarchy
) {
2052 scoped_refptr
<Layer
> parent
= Layer::Create();
2053 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
2054 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
2055 scoped_refptr
<Layer
> child_of_root
= Layer::Create();
2056 scoped_refptr
<Layer
> child_of_rs1
= Layer::Create();
2057 scoped_refptr
<Layer
> child_of_rs2
= Layer::Create();
2058 scoped_refptr
<Layer
> grand_child_of_root
= Layer::Create();
2059 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs1
=
2060 make_scoped_refptr(new LayerWithForcedDrawsContent());
2061 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs2
=
2062 make_scoped_refptr(new LayerWithForcedDrawsContent());
2063 parent
->AddChild(render_surface1
);
2064 parent
->AddChild(child_of_root
);
2065 render_surface1
->AddChild(child_of_rs1
);
2066 render_surface1
->AddChild(render_surface2
);
2067 render_surface2
->AddChild(child_of_rs2
);
2068 child_of_root
->AddChild(grand_child_of_root
);
2069 child_of_rs1
->AddChild(grand_child_of_rs1
);
2070 child_of_rs2
->AddChild(grand_child_of_rs2
);
2072 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
2073 host
->SetRootLayer(parent
);
2075 // Make our render surfaces.
2076 render_surface1
->SetForceRenderSurface(true);
2077 render_surface2
->SetForceRenderSurface(true);
2079 gfx::Transform layer_transform
;
2080 layer_transform
.Translate(1.0, 1.0);
2082 SetLayerPropertiesForTesting(parent
.get(),
2084 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2085 gfx::PointF(2.5f
, 0.f
),
2089 SetLayerPropertiesForTesting(render_surface1
.get(),
2091 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2092 gfx::PointF(2.5f
, 0.f
),
2096 SetLayerPropertiesForTesting(render_surface2
.get(),
2098 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2099 gfx::PointF(2.5f
, 0.f
),
2103 SetLayerPropertiesForTesting(child_of_root
.get(),
2105 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2106 gfx::PointF(2.5f
, 0.f
),
2110 SetLayerPropertiesForTesting(child_of_rs1
.get(),
2112 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2113 gfx::PointF(2.5f
, 0.f
),
2117 SetLayerPropertiesForTesting(child_of_rs2
.get(),
2119 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2120 gfx::PointF(2.5f
, 0.f
),
2124 SetLayerPropertiesForTesting(grand_child_of_root
.get(),
2126 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2127 gfx::PointF(2.5f
, 0.f
),
2131 SetLayerPropertiesForTesting(grand_child_of_rs1
.get(),
2133 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2134 gfx::PointF(2.5f
, 0.f
),
2138 SetLayerPropertiesForTesting(grand_child_of_rs2
.get(),
2140 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2141 gfx::PointF(2.5f
, 0.f
),
2146 // Put an animated opacity on the render surface.
2147 AddOpacityTransitionToController(
2148 render_surface1
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2150 // Also put an animated opacity on a layer without descendants.
2151 AddOpacityTransitionToController(
2152 grand_child_of_root
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2154 // Put a transform animation on the render surface.
2155 AddAnimatedTransformToController(
2156 render_surface2
->layer_animation_controller(), 10.0, 30, 0);
2158 // Also put transform animations on grand_child_of_root, and
2159 // grand_child_of_rs2
2160 AddAnimatedTransformToController(
2161 grand_child_of_root
->layer_animation_controller(), 10.0, 30, 0);
2162 AddAnimatedTransformToController(
2163 grand_child_of_rs2
->layer_animation_controller(), 10.0, 30, 0);
2165 ExecuteCalculateDrawProperties(parent
.get());
2167 // Only layers that are associated with render surfaces should have an actual
2168 // RenderSurface() value.
2169 ASSERT_TRUE(parent
->render_surface());
2170 ASSERT_FALSE(child_of_root
->render_surface());
2171 ASSERT_FALSE(grand_child_of_root
->render_surface());
2173 ASSERT_TRUE(render_surface1
->render_surface());
2174 ASSERT_FALSE(child_of_rs1
->render_surface());
2175 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
2177 ASSERT_TRUE(render_surface2
->render_surface());
2178 ASSERT_FALSE(child_of_rs2
->render_surface());
2179 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
2181 // Verify all render target accessors
2182 EXPECT_EQ(parent
, parent
->render_target());
2183 EXPECT_EQ(parent
, child_of_root
->render_target());
2184 EXPECT_EQ(parent
, grand_child_of_root
->render_target());
2186 EXPECT_EQ(render_surface1
, render_surface1
->render_target());
2187 EXPECT_EQ(render_surface1
, child_of_rs1
->render_target());
2188 EXPECT_EQ(render_surface1
, grand_child_of_rs1
->render_target());
2190 EXPECT_EQ(render_surface2
, render_surface2
->render_target());
2191 EXPECT_EQ(render_surface2
, child_of_rs2
->render_target());
2192 EXPECT_EQ(render_surface2
, grand_child_of_rs2
->render_target());
2194 // Verify draw_opacity_is_animating values
2195 EXPECT_FALSE(parent
->draw_opacity_is_animating());
2196 EXPECT_FALSE(child_of_root
->draw_opacity_is_animating());
2197 EXPECT_TRUE(grand_child_of_root
->draw_opacity_is_animating());
2198 EXPECT_FALSE(render_surface1
->draw_opacity_is_animating());
2199 EXPECT_TRUE(render_surface1
->render_surface()->draw_opacity_is_animating());
2200 EXPECT_FALSE(child_of_rs1
->draw_opacity_is_animating());
2201 EXPECT_FALSE(grand_child_of_rs1
->draw_opacity_is_animating());
2202 EXPECT_FALSE(render_surface2
->draw_opacity_is_animating());
2203 EXPECT_FALSE(render_surface2
->render_surface()->draw_opacity_is_animating());
2204 EXPECT_FALSE(child_of_rs2
->draw_opacity_is_animating());
2205 EXPECT_FALSE(grand_child_of_rs2
->draw_opacity_is_animating());
2207 // Verify draw_transform_is_animating values
2208 EXPECT_FALSE(parent
->draw_transform_is_animating());
2209 EXPECT_FALSE(child_of_root
->draw_transform_is_animating());
2210 EXPECT_TRUE(grand_child_of_root
->draw_transform_is_animating());
2211 EXPECT_FALSE(render_surface1
->draw_transform_is_animating());
2212 EXPECT_FALSE(render_surface1
->render_surface()
2213 ->target_surface_transforms_are_animating());
2214 EXPECT_FALSE(child_of_rs1
->draw_transform_is_animating());
2215 EXPECT_FALSE(grand_child_of_rs1
->draw_transform_is_animating());
2216 EXPECT_FALSE(render_surface2
->draw_transform_is_animating());
2217 EXPECT_TRUE(render_surface2
->render_surface()
2218 ->target_surface_transforms_are_animating());
2219 EXPECT_FALSE(child_of_rs2
->draw_transform_is_animating());
2220 EXPECT_TRUE(grand_child_of_rs2
->draw_transform_is_animating());
2222 // Verify screen_space_transform_is_animating values
2223 EXPECT_FALSE(parent
->screen_space_transform_is_animating());
2224 EXPECT_FALSE(child_of_root
->screen_space_transform_is_animating());
2225 EXPECT_TRUE(grand_child_of_root
->screen_space_transform_is_animating());
2226 EXPECT_FALSE(render_surface1
->screen_space_transform_is_animating());
2227 EXPECT_FALSE(render_surface1
->render_surface()
2228 ->screen_space_transforms_are_animating());
2229 EXPECT_FALSE(child_of_rs1
->screen_space_transform_is_animating());
2230 EXPECT_FALSE(grand_child_of_rs1
->screen_space_transform_is_animating());
2231 EXPECT_TRUE(render_surface2
->screen_space_transform_is_animating());
2232 EXPECT_TRUE(render_surface2
->render_surface()
2233 ->screen_space_transforms_are_animating());
2234 EXPECT_TRUE(child_of_rs2
->screen_space_transform_is_animating());
2235 EXPECT_TRUE(grand_child_of_rs2
->screen_space_transform_is_animating());
2237 // Sanity check. If these fail there is probably a bug in the test itself.
2238 // It is expected that we correctly set up transforms so that the y-component
2239 // of the screen-space transform encodes the "depth" of the layer in the tree.
2240 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
2241 EXPECT_FLOAT_EQ(2.0,
2242 child_of_root
->screen_space_transform().matrix().get(1, 3));
2244 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
2246 EXPECT_FLOAT_EQ(2.0,
2247 render_surface1
->screen_space_transform().matrix().get(1, 3));
2248 EXPECT_FLOAT_EQ(3.0,
2249 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2251 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2253 EXPECT_FLOAT_EQ(3.0,
2254 render_surface2
->screen_space_transform().matrix().get(1, 3));
2255 EXPECT_FLOAT_EQ(4.0,
2256 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2258 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2261 TEST_F(LayerTreeHostCommonTest
, VisibleRectForIdentityTransform
) {
2262 // Test the calculateVisibleRect() function works correctly for identity
2265 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2266 gfx::Transform layer_to_surface_transform
;
2268 // Case 1: Layer is contained within the surface.
2269 gfx::Rect layer_content_rect
= gfx::Rect(10, 10, 30, 30);
2270 gfx::Rect expected
= gfx::Rect(10, 10, 30, 30);
2271 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2272 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2273 EXPECT_RECT_EQ(expected
, actual
);
2275 // Case 2: Layer is outside the surface rect.
2276 layer_content_rect
= gfx::Rect(120, 120, 30, 30);
2277 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2278 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2279 EXPECT_TRUE(actual
.IsEmpty());
2281 // Case 3: Layer is partially overlapping the surface rect.
2282 layer_content_rect
= gfx::Rect(80, 80, 30, 30);
2283 expected
= gfx::Rect(80, 80, 20, 20);
2284 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2285 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2286 EXPECT_RECT_EQ(expected
, actual
);
2289 TEST_F(LayerTreeHostCommonTest
, VisibleRectForTranslations
) {
2290 // Test the calculateVisibleRect() function works correctly for scaling
2293 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2294 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2295 gfx::Transform layer_to_surface_transform
;
2297 // Case 1: Layer is contained within the surface.
2298 layer_to_surface_transform
.MakeIdentity();
2299 layer_to_surface_transform
.Translate(10.0, 10.0);
2300 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2301 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2302 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2303 EXPECT_RECT_EQ(expected
, actual
);
2305 // Case 2: Layer is outside the surface rect.
2306 layer_to_surface_transform
.MakeIdentity();
2307 layer_to_surface_transform
.Translate(120.0, 120.0);
2308 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2309 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2310 EXPECT_TRUE(actual
.IsEmpty());
2312 // Case 3: Layer is partially overlapping the surface rect.
2313 layer_to_surface_transform
.MakeIdentity();
2314 layer_to_surface_transform
.Translate(80.0, 80.0);
2315 expected
= gfx::Rect(0, 0, 20, 20);
2316 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2317 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2318 EXPECT_RECT_EQ(expected
, actual
);
2321 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor2DRotations
) {
2322 // Test the calculateVisibleRect() function works correctly for rotations
2323 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2324 // should return the g in the layer's space.
2326 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2327 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2328 gfx::Transform layer_to_surface_transform
;
2330 // Case 1: Layer is contained within the surface.
2331 layer_to_surface_transform
.MakeIdentity();
2332 layer_to_surface_transform
.Translate(50.0, 50.0);
2333 layer_to_surface_transform
.Rotate(45.0);
2334 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2335 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2336 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2337 EXPECT_RECT_EQ(expected
, actual
);
2339 // Case 2: Layer is outside the surface rect.
2340 layer_to_surface_transform
.MakeIdentity();
2341 layer_to_surface_transform
.Translate(-50.0, 0.0);
2342 layer_to_surface_transform
.Rotate(45.0);
2343 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2344 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2345 EXPECT_TRUE(actual
.IsEmpty());
2347 // Case 3: The layer is rotated about its top-left corner. In surface space,
2348 // the layer is oriented diagonally, with the left half outside of the render
2349 // surface. In this case, the g should still be the entire layer
2350 // (remember the g is computed in layer space); both the top-left
2351 // and bottom-right corners of the layer are still visible.
2352 layer_to_surface_transform
.MakeIdentity();
2353 layer_to_surface_transform
.Rotate(45.0);
2354 expected
= gfx::Rect(0, 0, 30, 30);
2355 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2356 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2357 EXPECT_RECT_EQ(expected
, actual
);
2359 // Case 4: The layer is rotated about its top-left corner, and translated
2360 // upwards. In surface space, the layer is oriented diagonally, with only the
2361 // top corner of the surface overlapping the layer. In layer space, the render
2362 // surface overlaps the right side of the layer. The g should be
2363 // the layer's right half.
2364 layer_to_surface_transform
.MakeIdentity();
2365 layer_to_surface_transform
.Translate(0.0, -sqrt(2.0) * 15.0);
2366 layer_to_surface_transform
.Rotate(45.0);
2367 expected
= gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
2368 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2369 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2370 EXPECT_RECT_EQ(expected
, actual
);
2373 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dOrthographicTransform
) {
2374 // Test that the calculateVisibleRect() function works correctly for 3d
2377 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2378 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2379 gfx::Transform layer_to_surface_transform
;
2381 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2382 // degrees, should be fully contained in the render surface.
2383 layer_to_surface_transform
.MakeIdentity();
2384 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2385 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2386 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2387 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2388 EXPECT_RECT_EQ(expected
, actual
);
2390 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2391 // degrees, but shifted to the side so only the right-half the layer would be
2392 // visible on the surface.
2393 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2394 SkMScalar half_width_of_rotated_layer
=
2395 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
2396 layer_to_surface_transform
.MakeIdentity();
2397 layer_to_surface_transform
.Translate(-half_width_of_rotated_layer
, 0.0);
2398 layer_to_surface_transform
.RotateAboutYAxis(45.0); // Rotates about the left
2399 // edge of the layer.
2400 expected
= gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
2401 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2402 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2403 EXPECT_RECT_EQ(expected
, actual
);
2406 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveTransform
) {
2407 // Test the calculateVisibleRect() function works correctly when the layer has
2408 // a perspective projection onto the target surface.
2410 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2411 gfx::Rect layer_content_rect
= gfx::Rect(-50, -50, 200, 200);
2412 gfx::Transform layer_to_surface_transform
;
2414 // Case 1: Even though the layer is twice as large as the surface, due to
2415 // perspective foreshortening, the layer will fit fully in the surface when
2416 // its translated more than the perspective amount.
2417 layer_to_surface_transform
.MakeIdentity();
2419 // The following sequence of transforms applies the perspective about the
2420 // center of the surface.
2421 layer_to_surface_transform
.Translate(50.0, 50.0);
2422 layer_to_surface_transform
.ApplyPerspectiveDepth(9.0);
2423 layer_to_surface_transform
.Translate(-50.0, -50.0);
2425 // This translate places the layer in front of the surface's projection plane.
2426 layer_to_surface_transform
.Translate3d(0.0, 0.0, -27.0);
2428 gfx::Rect expected
= gfx::Rect(-50, -50, 200, 200);
2429 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2430 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2431 EXPECT_RECT_EQ(expected
, actual
);
2433 // Case 2: same projection as before, except that the layer is also translated
2434 // to the side, so that only the right half of the layer should be visible.
2436 // Explanation of expected result: The perspective ratio is (z distance
2437 // between layer and camera origin) / (z distance between projection plane and
2438 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2439 // move a layer by translating -50 units in projected surface units (so that
2440 // only half of it is visible), then we would need to translate by (-36 / 9) *
2441 // -50 == -200 in the layer's units.
2442 layer_to_surface_transform
.Translate3d(-200.0, 0.0, 0.0);
2443 expected
= gfx::Rect(gfx::Point(50, -50),
2444 gfx::Size(100, 200)); // The right half of the layer's
2446 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2447 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2448 EXPECT_RECT_EQ(expected
, actual
);
2451 TEST_F(LayerTreeHostCommonTest
,
2452 VisibleRectFor3dOrthographicIsNotClippedBehindSurface
) {
2453 // There is currently no explicit concept of an orthographic projection plane
2454 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2455 // are technically behind the surface in an orthographic world should not be
2456 // clipped when they are flattened to the surface.
2458 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2459 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2460 gfx::Transform layer_to_surface_transform
;
2462 // This sequence of transforms effectively rotates the layer about the y-axis
2463 // at the center of the layer.
2464 layer_to_surface_transform
.MakeIdentity();
2465 layer_to_surface_transform
.Translate(50.0, 0.0);
2466 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2467 layer_to_surface_transform
.Translate(-50.0, 0.0);
2469 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2470 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2471 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2472 EXPECT_RECT_EQ(expected
, actual
);
2475 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveWhenClippedByW
) {
2476 // Test the calculateVisibleRect() function works correctly when projecting a
2477 // surface onto a layer, but the layer is partially behind the camera (not
2478 // just behind the projection plane). In this case, the cartesian coordinates
2479 // may seem to be valid, but actually they are not. The visible rect needs to
2480 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2481 // converting to cartesian coordinates.
2483 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2484 gfx::Rect layer_content_rect
= gfx::Rect(-10, -1, 20, 2);
2485 gfx::Transform layer_to_surface_transform
;
2487 // The layer is positioned so that the right half of the layer should be in
2488 // front of the camera, while the other half is behind the surface's
2489 // projection plane. The following sequence of transforms applies the
2490 // perspective and rotation about the center of the layer.
2491 layer_to_surface_transform
.MakeIdentity();
2492 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2493 layer_to_surface_transform
.Translate3d(-2.0, 0.0, 1.0);
2494 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2496 // Sanity check that this transform does indeed cause w < 0 when applying the
2497 // transform, otherwise this code is not testing the intended scenario.
2499 MathUtil::MapQuad(layer_to_surface_transform
,
2500 gfx::QuadF(gfx::RectF(layer_content_rect
)),
2502 ASSERT_TRUE(clipped
);
2504 int expected_x_position
= 0;
2505 int expected_width
= 10;
2506 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2507 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2508 EXPECT_EQ(expected_x_position
, actual
.x());
2509 EXPECT_EQ(expected_width
, actual
.width());
2512 TEST_F(LayerTreeHostCommonTest
, VisibleRectForPerspectiveUnprojection
) {
2513 // To determine visible rect in layer space, there needs to be an
2514 // un-projection from surface space to layer space. When the original
2515 // transform was a perspective projection that was clipped, it returns a rect
2516 // that encloses the clipped bounds. Un-projecting this new rect may require
2519 // This sequence of transforms causes one corner of the layer to protrude
2520 // across the w = 0 plane, and should be clipped.
2521 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2522 gfx::Rect layer_content_rect
= gfx::Rect(-10, -10, 20, 20);
2523 gfx::Transform layer_to_surface_transform
;
2524 layer_to_surface_transform
.MakeIdentity();
2525 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2526 layer_to_surface_transform
.Translate3d(0.0, 0.0, -5.0);
2527 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2528 layer_to_surface_transform
.RotateAboutXAxis(80.0);
2530 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2531 // code is not testing the intended scenario.
2533 gfx::RectF clipped_rect
=
2534 MathUtil::MapClippedRect(layer_to_surface_transform
, layer_content_rect
);
2535 MathUtil::ProjectQuad(
2536 Inverse(layer_to_surface_transform
), gfx::QuadF(clipped_rect
), &clipped
);
2537 ASSERT_TRUE(clipped
);
2539 // Only the corner of the layer is not visible on the surface because of being
2540 // clipped. But, the net result of rounding visible region to an axis-aligned
2541 // rect is that the entire layer should still be considered visible.
2542 gfx::Rect expected
= gfx::Rect(-10, -10, 20, 20);
2543 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2544 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2545 EXPECT_RECT_EQ(expected
, actual
);
2548 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsForSimpleLayers
) {
2549 scoped_refptr
<Layer
> root
= Layer::Create();
2550 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2551 make_scoped_refptr(new LayerWithForcedDrawsContent());
2552 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2553 make_scoped_refptr(new LayerWithForcedDrawsContent());
2554 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2555 make_scoped_refptr(new LayerWithForcedDrawsContent());
2556 root
->AddChild(child1
);
2557 root
->AddChild(child2
);
2558 root
->AddChild(child3
);
2560 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
2561 host
->SetRootLayer(root
);
2563 gfx::Transform identity_matrix
;
2564 SetLayerPropertiesForTesting(root
.get(),
2568 gfx::Size(100, 100),
2571 SetLayerPropertiesForTesting(child1
.get(),
2578 SetLayerPropertiesForTesting(child2
.get(),
2581 gfx::PointF(75.f
, 75.f
),
2585 SetLayerPropertiesForTesting(child3
.get(),
2588 gfx::PointF(125.f
, 125.f
),
2593 ExecuteCalculateDrawProperties(root
.get());
2595 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2596 root
->render_surface()->DrawableContentRect());
2597 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2599 // Layers that do not draw content should have empty visible_content_rects.
2600 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2602 // layer visible_content_rects are clipped by their target surface.
2603 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
2604 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_content_rect());
2605 EXPECT_TRUE(child3
->visible_content_rect().IsEmpty());
2607 // layer drawable_content_rects are not clipped.
2608 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->drawable_content_rect());
2609 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2610 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2613 TEST_F(LayerTreeHostCommonTest
,
2614 DrawableAndVisibleContentRectsForLayersClippedByLayer
) {
2615 scoped_refptr
<Layer
> root
= Layer::Create();
2616 scoped_refptr
<Layer
> child
= Layer::Create();
2617 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child1
=
2618 make_scoped_refptr(new LayerWithForcedDrawsContent());
2619 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child2
=
2620 make_scoped_refptr(new LayerWithForcedDrawsContent());
2621 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child3
=
2622 make_scoped_refptr(new LayerWithForcedDrawsContent());
2623 root
->AddChild(child
);
2624 child
->AddChild(grand_child1
);
2625 child
->AddChild(grand_child2
);
2626 child
->AddChild(grand_child3
);
2628 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
2629 host
->SetRootLayer(root
);
2631 gfx::Transform identity_matrix
;
2632 SetLayerPropertiesForTesting(root
.get(),
2636 gfx::Size(100, 100),
2639 SetLayerPropertiesForTesting(child
.get(),
2643 gfx::Size(100, 100),
2646 SetLayerPropertiesForTesting(grand_child1
.get(),
2649 gfx::PointF(5.f
, 5.f
),
2653 SetLayerPropertiesForTesting(grand_child2
.get(),
2656 gfx::PointF(75.f
, 75.f
),
2660 SetLayerPropertiesForTesting(grand_child3
.get(),
2663 gfx::PointF(125.f
, 125.f
),
2668 child
->SetMasksToBounds(true);
2669 ExecuteCalculateDrawProperties(root
.get());
2671 ASSERT_FALSE(child
->render_surface());
2673 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2674 root
->render_surface()->DrawableContentRect());
2675 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2677 // Layers that do not draw content should have empty visible content rects.
2678 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2679 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child
->visible_content_rect());
2681 // All grandchild visible content rects should be clipped by child.
2682 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1
->visible_content_rect());
2683 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2
->visible_content_rect());
2684 EXPECT_TRUE(grand_child3
->visible_content_rect().IsEmpty());
2686 // All grandchild DrawableContentRects should also be clipped by child.
2687 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50),
2688 grand_child1
->drawable_content_rect());
2689 EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25),
2690 grand_child2
->drawable_content_rect());
2691 EXPECT_TRUE(grand_child3
->drawable_content_rect().IsEmpty());
2694 TEST_F(LayerTreeHostCommonTest
,
2695 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface
) {
2696 scoped_refptr
<Layer
> root
= Layer::Create();
2697 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
2698 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2699 make_scoped_refptr(new LayerWithForcedDrawsContent());
2700 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2701 make_scoped_refptr(new LayerWithForcedDrawsContent());
2702 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2703 make_scoped_refptr(new LayerWithForcedDrawsContent());
2704 root
->AddChild(render_surface1
);
2705 render_surface1
->AddChild(child1
);
2706 render_surface1
->AddChild(child2
);
2707 render_surface1
->AddChild(child3
);
2709 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
2710 host
->SetRootLayer(root
);
2712 gfx::Transform identity_matrix
;
2713 SetLayerPropertiesForTesting(root
.get(),
2717 gfx::Size(100, 100),
2720 SetLayerPropertiesForTesting(render_surface1
.get(),
2727 SetLayerPropertiesForTesting(child1
.get(),
2730 gfx::PointF(5.f
, 5.f
),
2734 SetLayerPropertiesForTesting(child2
.get(),
2737 gfx::PointF(75.f
, 75.f
),
2741 SetLayerPropertiesForTesting(child3
.get(),
2744 gfx::PointF(125.f
, 125.f
),
2749 render_surface1
->SetForceRenderSurface(true);
2750 ExecuteCalculateDrawProperties(root
.get());
2752 ASSERT_TRUE(render_surface1
->render_surface());
2754 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2755 root
->render_surface()->DrawableContentRect());
2756 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2758 // Layers that do not draw content should have empty visible content rects.
2759 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2760 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
2761 render_surface1
->visible_content_rect());
2763 // An unclipped surface grows its DrawableContentRect to include all drawable
2764 // regions of the subtree.
2765 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
2766 render_surface1
->render_surface()->DrawableContentRect());
2768 // All layers that draw content into the unclipped surface are also unclipped.
2769 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
2770 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
2771 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
2773 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2774 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2775 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2778 TEST_F(LayerTreeHostCommonTest
,
2779 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform
) {
2780 scoped_refptr
<Layer
> root
= Layer::Create();
2781 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2782 make_scoped_refptr(new LayerWithForcedDrawsContent());
2783 root
->AddChild(child
);
2785 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
2786 host
->SetRootLayer(root
);
2788 // Case 1: a truly degenerate matrix
2789 gfx::Transform identity_matrix
;
2790 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2791 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2793 SetLayerPropertiesForTesting(root
.get(),
2797 gfx::Size(100, 100),
2800 SetLayerPropertiesForTesting(child
.get(),
2801 uninvertible_matrix
,
2803 gfx::PointF(5.f
, 5.f
),
2808 ExecuteCalculateDrawProperties(root
.get());
2810 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
2811 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2813 // Case 2: a matrix with flattened z, uninvertible and not visible according
2815 uninvertible_matrix
.MakeIdentity();
2816 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2817 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2819 SetLayerPropertiesForTesting(child
.get(),
2820 uninvertible_matrix
,
2822 gfx::PointF(5.f
, 5.f
),
2827 ExecuteCalculateDrawProperties(root
.get());
2829 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
2830 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2832 // Case 3: a matrix with flattened z, also uninvertible and not visible.
2833 uninvertible_matrix
.MakeIdentity();
2834 uninvertible_matrix
.Translate(500.0, 0.0);
2835 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2836 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2838 SetLayerPropertiesForTesting(child
.get(),
2839 uninvertible_matrix
,
2841 gfx::PointF(5.f
, 5.f
),
2846 ExecuteCalculateDrawProperties(root
.get());
2848 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
2849 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2852 TEST_F(LayerTreeHostCommonTest
,
2853 SingularTransformDoesNotPreventClearingDrawProperties
) {
2854 scoped_refptr
<Layer
> root
= Layer::Create();
2855 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2856 make_scoped_refptr(new LayerWithForcedDrawsContent());
2857 root
->AddChild(child
);
2859 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
2860 host
->SetRootLayer(root
);
2862 gfx::Transform identity_matrix
;
2863 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2864 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2866 SetLayerPropertiesForTesting(root
.get(),
2867 uninvertible_matrix
,
2870 gfx::Size(100, 100),
2873 SetLayerPropertiesForTesting(child
.get(),
2876 gfx::PointF(5.f
, 5.f
),
2881 child
->draw_properties().sorted_for_recursion
= true;
2883 TransformOperations start_transform_operations
;
2884 start_transform_operations
.AppendScale(1.f
, 0.f
, 0.f
);
2886 TransformOperations end_transform_operations
;
2887 end_transform_operations
.AppendScale(1.f
, 1.f
, 0.f
);
2889 AddAnimatedTransformToLayer(
2890 root
.get(), 10.0, start_transform_operations
, end_transform_operations
);
2892 EXPECT_TRUE(root
->TransformIsAnimating());
2894 ExecuteCalculateDrawProperties(root
.get());
2896 EXPECT_FALSE(child
->draw_properties().sorted_for_recursion
);
2899 TEST_F(LayerTreeHostCommonTest
,
2900 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties
) {
2901 scoped_refptr
<Layer
> root
= Layer::Create();
2903 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
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
->draw_properties().sorted_for_recursion
= true;
2920 EXPECT_FALSE(root
->TransformIsAnimating());
2922 ExecuteCalculateDrawProperties(root
.get());
2924 EXPECT_FALSE(root
->draw_properties().sorted_for_recursion
);
2927 TEST_F(LayerTreeHostCommonTest
,
2928 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface
) {
2929 scoped_refptr
<Layer
> root
= Layer::Create();
2930 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
2931 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2932 make_scoped_refptr(new LayerWithForcedDrawsContent());
2933 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2934 make_scoped_refptr(new LayerWithForcedDrawsContent());
2935 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2936 make_scoped_refptr(new LayerWithForcedDrawsContent());
2937 root
->AddChild(render_surface1
);
2938 render_surface1
->AddChild(child1
);
2939 render_surface1
->AddChild(child2
);
2940 render_surface1
->AddChild(child3
);
2942 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
2943 host
->SetRootLayer(root
);
2945 gfx::Transform identity_matrix
;
2946 SetLayerPropertiesForTesting(root
.get(),
2950 gfx::Size(100, 100),
2953 SetLayerPropertiesForTesting(render_surface1
.get(),
2960 SetLayerPropertiesForTesting(child1
.get(),
2963 gfx::PointF(5.f
, 5.f
),
2967 SetLayerPropertiesForTesting(child2
.get(),
2970 gfx::PointF(75.f
, 75.f
),
2974 SetLayerPropertiesForTesting(child3
.get(),
2977 gfx::PointF(125.f
, 125.f
),
2982 root
->SetMasksToBounds(true);
2983 render_surface1
->SetForceRenderSurface(true);
2984 ExecuteCalculateDrawProperties(root
.get());
2986 ASSERT_TRUE(render_surface1
->render_surface());
2988 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2989 root
->render_surface()->DrawableContentRect());
2990 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2992 // Layers that do not draw content should have empty visible content rects.
2993 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2994 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
2995 render_surface1
->visible_content_rect());
2997 // A clipped surface grows its DrawableContentRect to include all drawable
2998 // regions of the subtree, but also gets clamped by the ancestor's clip.
2999 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3000 render_surface1
->render_surface()->DrawableContentRect());
3002 // All layers that draw content into the surface have their visible content
3003 // rect clipped by the surface clip rect.
3004 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3005 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_content_rect());
3006 EXPECT_TRUE(child3
->visible_content_rect().IsEmpty());
3008 // But the DrawableContentRects are unclipped.
3009 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
3010 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
3011 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
3014 TEST_F(LayerTreeHostCommonTest
,
3015 DrawableAndVisibleContentRectsForSurfaceHierarchy
) {
3016 // Check that clipping does not propagate down surfaces.
3017 scoped_refptr
<Layer
> root
= Layer::Create();
3018 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3019 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
3020 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3021 make_scoped_refptr(new LayerWithForcedDrawsContent());
3022 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3023 make_scoped_refptr(new LayerWithForcedDrawsContent());
3024 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
3025 make_scoped_refptr(new LayerWithForcedDrawsContent());
3026 root
->AddChild(render_surface1
);
3027 render_surface1
->AddChild(render_surface2
);
3028 render_surface2
->AddChild(child1
);
3029 render_surface2
->AddChild(child2
);
3030 render_surface2
->AddChild(child3
);
3032 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3033 host
->SetRootLayer(root
);
3035 gfx::Transform identity_matrix
;
3036 SetLayerPropertiesForTesting(root
.get(),
3040 gfx::Size(100, 100),
3043 SetLayerPropertiesForTesting(render_surface1
.get(),
3050 SetLayerPropertiesForTesting(render_surface2
.get(),
3057 SetLayerPropertiesForTesting(child1
.get(),
3060 gfx::PointF(5.f
, 5.f
),
3064 SetLayerPropertiesForTesting(child2
.get(),
3067 gfx::PointF(75.f
, 75.f
),
3071 SetLayerPropertiesForTesting(child3
.get(),
3074 gfx::PointF(125.f
, 125.f
),
3079 root
->SetMasksToBounds(true);
3080 render_surface1
->SetForceRenderSurface(true);
3081 render_surface2
->SetForceRenderSurface(true);
3082 ExecuteCalculateDrawProperties(root
.get());
3084 ASSERT_TRUE(render_surface1
->render_surface());
3085 ASSERT_TRUE(render_surface2
->render_surface());
3087 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3088 root
->render_surface()->DrawableContentRect());
3089 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3091 // Layers that do not draw content should have empty visible content rects.
3092 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3093 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3094 render_surface1
->visible_content_rect());
3095 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3096 render_surface2
->visible_content_rect());
3098 // A clipped surface grows its DrawableContentRect to include all drawable
3099 // regions of the subtree, but also gets clamped by the ancestor's clip.
3100 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3101 render_surface1
->render_surface()->DrawableContentRect());
3103 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3104 // is only implicitly clipped by render_surface1's content rect. So,
3105 // render_surface2 grows to enclose all drawable content of its subtree.
3106 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
3107 render_surface2
->render_surface()->DrawableContentRect());
3109 // All layers that draw content into render_surface2 think they are unclipped.
3110 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3111 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
3112 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
3114 // DrawableContentRects are also unclipped.
3115 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
3116 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
3117 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
3120 TEST_F(LayerTreeHostCommonTest
,
3121 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface
) {
3122 // Layers that have non-axis aligned bounds (due to transforms) have an
3123 // expanded, axis-aligned DrawableContentRect and visible content rect.
3125 scoped_refptr
<Layer
> root
= Layer::Create();
3126 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3127 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3128 make_scoped_refptr(new LayerWithForcedDrawsContent());
3129 root
->AddChild(render_surface1
);
3130 render_surface1
->AddChild(child1
);
3132 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3133 host
->SetRootLayer(root
);
3135 gfx::Transform identity_matrix
;
3136 gfx::Transform child_rotation
;
3137 child_rotation
.Rotate(45.0);
3138 SetLayerPropertiesForTesting(root
.get(),
3142 gfx::Size(100, 100),
3145 SetLayerPropertiesForTesting(render_surface1
.get(),
3152 SetLayerPropertiesForTesting(child1
.get(),
3154 gfx::Point3F(25, 25, 0.f
),
3155 gfx::PointF(25.f
, 25.f
),
3160 render_surface1
->SetForceRenderSurface(true);
3161 ExecuteCalculateDrawProperties(root
.get());
3163 ASSERT_TRUE(render_surface1
->render_surface());
3165 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3166 root
->render_surface()->DrawableContentRect());
3167 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3169 // Layers that do not draw content should have empty visible content rects.
3170 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3171 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3172 render_surface1
->visible_content_rect());
3174 // The unclipped surface grows its DrawableContentRect to include all drawable
3175 // regions of the subtree.
3176 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3177 gfx::Rect expected_surface_drawable_content
=
3178 gfx::Rect(50 - diagonal_radius
,
3179 50 - diagonal_radius
,
3180 diagonal_radius
* 2,
3181 diagonal_radius
* 2);
3182 EXPECT_RECT_EQ(expected_surface_drawable_content
,
3183 render_surface1
->render_surface()->DrawableContentRect());
3185 // All layers that draw content into the unclipped surface are also unclipped.
3186 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3187 EXPECT_RECT_EQ(expected_surface_drawable_content
,
3188 child1
->drawable_content_rect());
3191 TEST_F(LayerTreeHostCommonTest
,
3192 DrawableAndVisibleContentRectsWithTransformOnClippedSurface
) {
3193 // Layers that have non-axis aligned bounds (due to transforms) have an
3194 // expanded, axis-aligned DrawableContentRect and visible content rect.
3196 scoped_refptr
<Layer
> root
= Layer::Create();
3197 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3198 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3199 make_scoped_refptr(new LayerWithForcedDrawsContent());
3200 root
->AddChild(render_surface1
);
3201 render_surface1
->AddChild(child1
);
3203 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3204 host
->SetRootLayer(root
);
3206 gfx::Transform identity_matrix
;
3207 gfx::Transform child_rotation
;
3208 child_rotation
.Rotate(45.0);
3209 SetLayerPropertiesForTesting(root
.get(),
3216 SetLayerPropertiesForTesting(render_surface1
.get(),
3224 SetLayerPropertiesForTesting(child1
.get(),
3226 gfx::Point3F(25, 25, 0.f
),
3227 gfx::PointF(25.f
, 25.f
),
3232 root
->SetMasksToBounds(true);
3233 render_surface1
->SetForceRenderSurface(true);
3234 ExecuteCalculateDrawProperties(root
.get());
3236 ASSERT_TRUE(render_surface1
->render_surface());
3238 // The clipped surface clamps the DrawableContentRect that encloses the
3240 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3241 gfx::Rect unclipped_surface_content
= gfx::Rect(50 - diagonal_radius
,
3242 50 - diagonal_radius
,
3243 diagonal_radius
* 2,
3244 diagonal_radius
* 2);
3245 gfx::Rect expected_surface_drawable_content
=
3246 gfx::IntersectRects(unclipped_surface_content
, gfx::Rect(0, 0, 50, 50));
3247 EXPECT_RECT_EQ(expected_surface_drawable_content
,
3248 render_surface1
->render_surface()->DrawableContentRect());
3250 // On the clipped surface, only a quarter of the child1 is visible, but when
3251 // rotating it back to child1's content space, the actual enclosing rect ends
3252 // up covering the full left half of child1.
3254 // Given the floating point math, this number is a little bit fuzzy.
3255 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1
->visible_content_rect());
3257 // The child's DrawableContentRect is unclipped.
3258 EXPECT_RECT_EQ(unclipped_surface_content
, child1
->drawable_content_rect());
3261 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsInHighDPI
) {
3262 MockContentLayerClient client
;
3264 scoped_refptr
<Layer
> root
= Layer::Create();
3265 scoped_refptr
<ContentLayer
> render_surface1
=
3266 CreateDrawableContentLayer(&client
);
3267 scoped_refptr
<ContentLayer
> render_surface2
=
3268 CreateDrawableContentLayer(&client
);
3269 scoped_refptr
<ContentLayer
> child1
= CreateDrawableContentLayer(&client
);
3270 scoped_refptr
<ContentLayer
> child2
= CreateDrawableContentLayer(&client
);
3271 scoped_refptr
<ContentLayer
> child3
= CreateDrawableContentLayer(&client
);
3272 root
->AddChild(render_surface1
);
3273 render_surface1
->AddChild(render_surface2
);
3274 render_surface2
->AddChild(child1
);
3275 render_surface2
->AddChild(child2
);
3276 render_surface2
->AddChild(child3
);
3278 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3279 host
->SetRootLayer(root
);
3281 gfx::Transform identity_matrix
;
3282 SetLayerPropertiesForTesting(root
.get(),
3286 gfx::Size(100, 100),
3289 SetLayerPropertiesForTesting(render_surface1
.get(),
3292 gfx::PointF(5.f
, 5.f
),
3296 SetLayerPropertiesForTesting(render_surface2
.get(),
3299 gfx::PointF(5.f
, 5.f
),
3303 SetLayerPropertiesForTesting(child1
.get(),
3306 gfx::PointF(5.f
, 5.f
),
3310 SetLayerPropertiesForTesting(child2
.get(),
3313 gfx::PointF(75.f
, 75.f
),
3317 SetLayerPropertiesForTesting(child3
.get(),
3320 gfx::PointF(125.f
, 125.f
),
3325 float device_scale_factor
= 2.f
;
3327 root
->SetMasksToBounds(true);
3328 render_surface1
->SetForceRenderSurface(true);
3329 render_surface2
->SetForceRenderSurface(true);
3330 ExecuteCalculateDrawProperties(root
.get(), device_scale_factor
);
3332 ASSERT_TRUE(render_surface1
->render_surface());
3333 ASSERT_TRUE(render_surface2
->render_surface());
3335 // drawable_content_rects for all layers and surfaces are scaled by
3336 // device_scale_factor.
3337 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200),
3338 root
->render_surface()->DrawableContentRect());
3339 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root
->drawable_content_rect());
3340 EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190),
3341 render_surface1
->render_surface()->DrawableContentRect());
3343 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3344 // is only implicitly clipped by render_surface1.
3345 EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350),
3346 render_surface2
->render_surface()->DrawableContentRect());
3348 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1
->drawable_content_rect());
3349 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100),
3350 child2
->drawable_content_rect());
3351 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100),
3352 child3
->drawable_content_rect());
3354 // The root layer does not actually draw content of its own.
3355 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3357 // All layer visible content rects are expressed in content space of each
3358 // layer, so they are also scaled by the device_scale_factor.
3359 EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8),
3360 render_surface1
->visible_content_rect());
3361 EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26),
3362 render_surface2
->visible_content_rect());
3363 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1
->visible_content_rect());
3364 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2
->visible_content_rect());
3365 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3
->visible_content_rect());
3368 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithoutPreserves3d
) {
3369 // Verify the behavior of back-face culling when there are no preserve-3d
3370 // layers. Note that 3d transforms still apply in this case, but they are
3371 // "flattened" to each parent layer according to current W3C spec.
3373 const gfx::Transform identity_matrix
;
3374 scoped_refptr
<Layer
> parent
= Layer::Create();
3375 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3376 make_scoped_refptr(new LayerWithForcedDrawsContent());
3377 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3378 make_scoped_refptr(new LayerWithForcedDrawsContent());
3379 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3380 make_scoped_refptr(new LayerWithForcedDrawsContent());
3381 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3382 make_scoped_refptr(new LayerWithForcedDrawsContent());
3383 scoped_refptr
<LayerWithForcedDrawsContent
>
3384 front_facing_child_of_front_facing_surface
=
3385 make_scoped_refptr(new LayerWithForcedDrawsContent());
3386 scoped_refptr
<LayerWithForcedDrawsContent
>
3387 back_facing_child_of_front_facing_surface
=
3388 make_scoped_refptr(new LayerWithForcedDrawsContent());
3389 scoped_refptr
<LayerWithForcedDrawsContent
>
3390 front_facing_child_of_back_facing_surface
=
3391 make_scoped_refptr(new LayerWithForcedDrawsContent());
3392 scoped_refptr
<LayerWithForcedDrawsContent
>
3393 back_facing_child_of_back_facing_surface
=
3394 make_scoped_refptr(new LayerWithForcedDrawsContent());
3396 parent
->AddChild(front_facing_child
);
3397 parent
->AddChild(back_facing_child
);
3398 parent
->AddChild(front_facing_surface
);
3399 parent
->AddChild(back_facing_surface
);
3400 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3401 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3402 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3403 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3405 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3406 host
->SetRootLayer(parent
);
3408 // Nothing is double-sided
3409 front_facing_child
->SetDoubleSided(false);
3410 back_facing_child
->SetDoubleSided(false);
3411 front_facing_surface
->SetDoubleSided(false);
3412 back_facing_surface
->SetDoubleSided(false);
3413 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3414 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3415 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3416 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3418 gfx::Transform backface_matrix
;
3419 backface_matrix
.Translate(50.0, 50.0);
3420 backface_matrix
.RotateAboutYAxis(180.0);
3421 backface_matrix
.Translate(-50.0, -50.0);
3423 // Having a descendant and opacity will force these to have render surfaces.
3424 front_facing_surface
->SetOpacity(0.5f
);
3425 back_facing_surface
->SetOpacity(0.5f
);
3427 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3428 // these layers should blindly use their own local transforms to determine
3429 // back-face culling.
3430 SetLayerPropertiesForTesting(parent
.get(),
3434 gfx::Size(100, 100),
3437 SetLayerPropertiesForTesting(front_facing_child
.get(),
3441 gfx::Size(100, 100),
3444 SetLayerPropertiesForTesting(back_facing_child
.get(),
3448 gfx::Size(100, 100),
3451 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3455 gfx::Size(100, 100),
3458 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3462 gfx::Size(100, 100),
3465 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3469 gfx::Size(100, 100),
3472 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3476 gfx::Size(100, 100),
3479 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3483 gfx::Size(100, 100),
3486 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3490 gfx::Size(100, 100),
3494 RenderSurfaceLayerList render_surface_layer_list
;
3495 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3496 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3497 inputs
.can_adjust_raster_scales
= true;
3498 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3500 // Verify which render surfaces were created.
3501 EXPECT_FALSE(front_facing_child
->render_surface());
3502 EXPECT_FALSE(back_facing_child
->render_surface());
3503 EXPECT_TRUE(front_facing_surface
->render_surface());
3504 EXPECT_TRUE(back_facing_surface
->render_surface());
3505 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3506 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3507 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3508 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3510 // Verify the render_surface_layer_list.
3511 ASSERT_EQ(3u, render_surface_layer_list
.size());
3512 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3513 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
3514 // Even though the back facing surface LAYER gets culled, the other
3515 // descendants should still be added, so the SURFACE should not be culled.
3516 EXPECT_EQ(back_facing_surface
->id(), render_surface_layer_list
.at(2)->id());
3518 // Verify root surface's layer list.
3521 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3522 EXPECT_EQ(front_facing_child
->id(),
3523 render_surface_layer_list
.at(0)
3528 EXPECT_EQ(front_facing_surface
->id(),
3529 render_surface_layer_list
.at(0)
3534 EXPECT_EQ(back_facing_surface
->id(),
3535 render_surface_layer_list
.at(0)
3541 // Verify front_facing_surface's layer list.
3544 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3545 EXPECT_EQ(front_facing_surface
->id(),
3546 render_surface_layer_list
.at(1)
3551 EXPECT_EQ(front_facing_child_of_front_facing_surface
->id(),
3552 render_surface_layer_list
.at(1)
3558 // Verify back_facing_surface's layer list; its own layer should be culled
3559 // from the surface list.
3562 render_surface_layer_list
.at(2)->render_surface()->layer_list().size());
3563 EXPECT_EQ(front_facing_child_of_back_facing_surface
->id(),
3564 render_surface_layer_list
.at(2)
3571 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithPreserves3d
) {
3572 // Verify the behavior of back-face culling when preserves-3d transform style
3575 const gfx::Transform identity_matrix
;
3576 scoped_refptr
<Layer
> parent
= Layer::Create();
3577 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3578 make_scoped_refptr(new LayerWithForcedDrawsContent());
3579 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3580 make_scoped_refptr(new LayerWithForcedDrawsContent());
3581 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3582 make_scoped_refptr(new LayerWithForcedDrawsContent());
3583 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3584 make_scoped_refptr(new LayerWithForcedDrawsContent());
3585 scoped_refptr
<LayerWithForcedDrawsContent
>
3586 front_facing_child_of_front_facing_surface
=
3587 make_scoped_refptr(new LayerWithForcedDrawsContent());
3588 scoped_refptr
<LayerWithForcedDrawsContent
>
3589 back_facing_child_of_front_facing_surface
=
3590 make_scoped_refptr(new LayerWithForcedDrawsContent());
3591 scoped_refptr
<LayerWithForcedDrawsContent
>
3592 front_facing_child_of_back_facing_surface
=
3593 make_scoped_refptr(new LayerWithForcedDrawsContent());
3594 scoped_refptr
<LayerWithForcedDrawsContent
>
3595 back_facing_child_of_back_facing_surface
=
3596 make_scoped_refptr(new LayerWithForcedDrawsContent());
3597 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer1
=
3598 make_scoped_refptr(new LayerWithForcedDrawsContent());
3599 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer2
=
3600 make_scoped_refptr(new LayerWithForcedDrawsContent());
3602 parent
->AddChild(front_facing_child
);
3603 parent
->AddChild(back_facing_child
);
3604 parent
->AddChild(front_facing_surface
);
3605 parent
->AddChild(back_facing_surface
);
3606 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3607 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3608 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3609 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3611 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3612 host
->SetRootLayer(parent
);
3614 // Nothing is double-sided
3615 front_facing_child
->SetDoubleSided(false);
3616 back_facing_child
->SetDoubleSided(false);
3617 front_facing_surface
->SetDoubleSided(false);
3618 back_facing_surface
->SetDoubleSided(false);
3619 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3620 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3621 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3622 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3624 gfx::Transform backface_matrix
;
3625 backface_matrix
.Translate(50.0, 50.0);
3626 backface_matrix
.RotateAboutYAxis(180.0);
3627 backface_matrix
.Translate(-50.0, -50.0);
3629 // Opacity will not force creation of render surfaces in this case because of
3630 // the preserve-3d transform style. Instead, an example of when a surface
3631 // would be created with preserve-3d is when there is a replica layer.
3632 front_facing_surface
->SetReplicaLayer(dummy_replica_layer1
.get());
3633 back_facing_surface
->SetReplicaLayer(dummy_replica_layer2
.get());
3635 // Each surface creates its own new 3d rendering context (as defined by W3C
3636 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3637 // rendering context should use the transform with respect to that context.
3638 // This 3d rendering context occurs when (a) parent's transform style is flat
3639 // and (b) the layer's transform style is preserve-3d.
3640 SetLayerPropertiesForTesting(parent
.get(),
3644 gfx::Size(100, 100),
3646 false); // parent transform style is flat.
3647 SetLayerPropertiesForTesting(front_facing_child
.get(),
3651 gfx::Size(100, 100),
3654 SetLayerPropertiesForTesting(back_facing_child
.get(),
3658 gfx::Size(100, 100),
3661 // surface transform style is preserve-3d.
3662 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3666 gfx::Size(100, 100),
3669 // surface transform style is preserve-3d.
3670 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3674 gfx::Size(100, 100),
3677 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3681 gfx::Size(100, 100),
3684 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3688 gfx::Size(100, 100),
3691 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3695 gfx::Size(100, 100),
3698 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3702 gfx::Size(100, 100),
3706 RenderSurfaceLayerList render_surface_layer_list
;
3707 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3708 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3709 inputs
.can_adjust_raster_scales
= true;
3710 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3712 // Verify which render surfaces were created.
3713 EXPECT_FALSE(front_facing_child
->render_surface());
3714 EXPECT_FALSE(back_facing_child
->render_surface());
3715 EXPECT_TRUE(front_facing_surface
->render_surface());
3716 EXPECT_FALSE(back_facing_surface
->render_surface());
3717 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3718 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3719 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3720 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3722 // Verify the render_surface_layer_list. The back-facing surface should be
3724 ASSERT_EQ(2u, render_surface_layer_list
.size());
3725 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3726 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
3728 // Verify root surface's layer list.
3731 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3732 EXPECT_EQ(front_facing_child
->id(),
3733 render_surface_layer_list
.at(0)
3734 ->render_surface()->layer_list().at(0)->id());
3735 EXPECT_EQ(front_facing_surface
->id(),
3736 render_surface_layer_list
.at(0)
3737 ->render_surface()->layer_list().at(1)->id());
3739 // Verify front_facing_surface's layer list.
3742 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3743 EXPECT_EQ(front_facing_surface
->id(),
3744 render_surface_layer_list
.at(1)
3745 ->render_surface()->layer_list().at(0)->id());
3746 EXPECT_EQ(front_facing_child_of_front_facing_surface
->id(),
3747 render_surface_layer_list
.at(1)
3748 ->render_surface()->layer_list().at(1)->id());
3751 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithAnimatingTransforms
) {
3752 // Verify that layers are appropriately culled when their back face is showing
3753 // and they are not double sided, while animations are going on.
3755 // Layers that are animating do not get culled on the main thread, as their
3756 // transforms should be treated as "unknown" so we can not be sure that their
3757 // back face is really showing.
3758 const gfx::Transform identity_matrix
;
3759 scoped_refptr
<Layer
> parent
= Layer::Create();
3760 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
3761 make_scoped_refptr(new LayerWithForcedDrawsContent());
3762 scoped_refptr
<LayerWithForcedDrawsContent
> animating_surface
=
3763 make_scoped_refptr(new LayerWithForcedDrawsContent());
3764 scoped_refptr
<LayerWithForcedDrawsContent
> child_of_animating_surface
=
3765 make_scoped_refptr(new LayerWithForcedDrawsContent());
3766 scoped_refptr
<LayerWithForcedDrawsContent
> animating_child
=
3767 make_scoped_refptr(new LayerWithForcedDrawsContent());
3768 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3769 make_scoped_refptr(new LayerWithForcedDrawsContent());
3771 parent
->AddChild(child
);
3772 parent
->AddChild(animating_surface
);
3773 animating_surface
->AddChild(child_of_animating_surface
);
3774 parent
->AddChild(animating_child
);
3775 parent
->AddChild(child2
);
3777 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3778 host
->SetRootLayer(parent
);
3780 // Nothing is double-sided
3781 child
->SetDoubleSided(false);
3782 child2
->SetDoubleSided(false);
3783 animating_surface
->SetDoubleSided(false);
3784 child_of_animating_surface
->SetDoubleSided(false);
3785 animating_child
->SetDoubleSided(false);
3787 gfx::Transform backface_matrix
;
3788 backface_matrix
.Translate(50.0, 50.0);
3789 backface_matrix
.RotateAboutYAxis(180.0);
3790 backface_matrix
.Translate(-50.0, -50.0);
3792 // Make our render surface.
3793 animating_surface
->SetForceRenderSurface(true);
3795 // Animate the transform on the render surface.
3796 AddAnimatedTransformToController(
3797 animating_surface
->layer_animation_controller(), 10.0, 30, 0);
3798 // This is just an animating layer, not a surface.
3799 AddAnimatedTransformToController(
3800 animating_child
->layer_animation_controller(), 10.0, 30, 0);
3802 SetLayerPropertiesForTesting(parent
.get(),
3806 gfx::Size(100, 100),
3809 SetLayerPropertiesForTesting(child
.get(),
3813 gfx::Size(100, 100),
3816 SetLayerPropertiesForTesting(animating_surface
.get(),
3820 gfx::Size(100, 100),
3823 SetLayerPropertiesForTesting(child_of_animating_surface
.get(),
3827 gfx::Size(100, 100),
3830 SetLayerPropertiesForTesting(animating_child
.get(),
3834 gfx::Size(100, 100),
3837 SetLayerPropertiesForTesting(child2
.get(),
3841 gfx::Size(100, 100),
3845 RenderSurfaceLayerList render_surface_layer_list
;
3846 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3847 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3848 inputs
.can_adjust_raster_scales
= true;
3849 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3851 EXPECT_FALSE(child
->render_surface());
3852 EXPECT_TRUE(animating_surface
->render_surface());
3853 EXPECT_FALSE(child_of_animating_surface
->render_surface());
3854 EXPECT_FALSE(animating_child
->render_surface());
3855 EXPECT_FALSE(child2
->render_surface());
3857 // Verify that the animating_child and child_of_animating_surface were not
3858 // culled, but that child was.
3859 ASSERT_EQ(2u, render_surface_layer_list
.size());
3860 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3861 EXPECT_EQ(animating_surface
->id(), render_surface_layer_list
.at(1)->id());
3863 // The non-animating child be culled from the layer list for the parent render
3867 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3868 EXPECT_EQ(animating_surface
->id(),
3869 render_surface_layer_list
.at(0)
3870 ->render_surface()->layer_list().at(0)->id());
3871 EXPECT_EQ(animating_child
->id(),
3872 render_surface_layer_list
.at(0)
3873 ->render_surface()->layer_list().at(1)->id());
3874 EXPECT_EQ(child2
->id(),
3875 render_surface_layer_list
.at(0)
3876 ->render_surface()->layer_list().at(2)->id());
3880 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3881 EXPECT_EQ(animating_surface
->id(),
3882 render_surface_layer_list
.at(1)
3883 ->render_surface()->layer_list().at(0)->id());
3884 EXPECT_EQ(child_of_animating_surface
->id(),
3885 render_surface_layer_list
.at(1)
3886 ->render_surface()->layer_list().at(1)->id());
3888 EXPECT_FALSE(child2
->visible_content_rect().IsEmpty());
3890 // The animating layers should have a visible content rect that represents the
3891 // area of the front face that is within the viewport.
3892 EXPECT_EQ(animating_child
->visible_content_rect(),
3893 gfx::Rect(animating_child
->content_bounds()));
3894 EXPECT_EQ(animating_surface
->visible_content_rect(),
3895 gfx::Rect(animating_surface
->content_bounds()));
3896 // And layers in the subtree of the animating layer should have valid visible
3897 // content rects also.
3898 EXPECT_EQ(child_of_animating_surface
->visible_content_rect(),
3899 gfx::Rect(child_of_animating_surface
->content_bounds()));
3902 TEST_F(LayerTreeHostCommonTest
,
3903 BackFaceCullingWithPreserves3dForFlatteningSurface
) {
3904 // Verify the behavior of back-face culling for a render surface that is
3905 // created when it flattens its subtree, and its parent has preserves-3d.
3907 const gfx::Transform identity_matrix
;
3908 scoped_refptr
<Layer
> parent
= Layer::Create();
3909 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3910 make_scoped_refptr(new LayerWithForcedDrawsContent());
3911 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3912 make_scoped_refptr(new LayerWithForcedDrawsContent());
3913 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3914 make_scoped_refptr(new LayerWithForcedDrawsContent());
3915 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3916 make_scoped_refptr(new LayerWithForcedDrawsContent());
3918 parent
->AddChild(front_facing_surface
);
3919 parent
->AddChild(back_facing_surface
);
3920 front_facing_surface
->AddChild(child1
);
3921 back_facing_surface
->AddChild(child2
);
3923 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3924 host
->SetRootLayer(parent
);
3926 // RenderSurfaces are not double-sided
3927 front_facing_surface
->SetDoubleSided(false);
3928 back_facing_surface
->SetDoubleSided(false);
3930 gfx::Transform backface_matrix
;
3931 backface_matrix
.Translate(50.0, 50.0);
3932 backface_matrix
.RotateAboutYAxis(180.0);
3933 backface_matrix
.Translate(-50.0, -50.0);
3935 SetLayerPropertiesForTesting(parent
.get(),
3939 gfx::Size(100, 100),
3941 true); // parent transform style is preserve3d.
3942 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3946 gfx::Size(100, 100),
3948 true); // surface transform style is flat.
3949 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3953 gfx::Size(100, 100),
3955 true); // surface transform style is flat.
3956 SetLayerPropertiesForTesting(child1
.get(),
3960 gfx::Size(100, 100),
3963 SetLayerPropertiesForTesting(child2
.get(),
3967 gfx::Size(100, 100),
3971 front_facing_surface
->Set3dSortingContextId(1);
3972 back_facing_surface
->Set3dSortingContextId(1);
3974 RenderSurfaceLayerList render_surface_layer_list
;
3975 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3976 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3977 inputs
.can_adjust_raster_scales
= true;
3978 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3980 // Verify which render surfaces were created.
3981 EXPECT_TRUE(front_facing_surface
->render_surface());
3983 back_facing_surface
->render_surface()); // because it should be culled
3984 EXPECT_FALSE(child1
->render_surface());
3985 EXPECT_FALSE(child2
->render_surface());
3987 // Verify the render_surface_layer_list. The back-facing surface should be
3989 ASSERT_EQ(2u, render_surface_layer_list
.size());
3990 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3991 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
3993 // Verify root surface's layer list.
3996 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3997 EXPECT_EQ(front_facing_surface
->id(),
3998 render_surface_layer_list
.at(0)
3999 ->render_surface()->layer_list().at(0)->id());
4001 // Verify front_facing_surface's layer list.
4004 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
4005 EXPECT_EQ(front_facing_surface
->id(),
4006 render_surface_layer_list
.at(1)
4007 ->render_surface()->layer_list().at(0)->id());
4008 EXPECT_EQ(child1
->id(),
4009 render_surface_layer_list
.at(1)
4010 ->render_surface()->layer_list().at(1)->id());
4013 class NoScaleContentLayer
: public ContentLayer
{
4015 static scoped_refptr
<NoScaleContentLayer
> Create(ContentLayerClient
* client
) {
4016 return make_scoped_refptr(new NoScaleContentLayer(client
));
4019 virtual void CalculateContentsScale(float ideal_contents_scale
,
4020 float* contents_scale_x
,
4021 float* contents_scale_y
,
4022 gfx::Size
* content_bounds
) OVERRIDE
{
4023 // Skip over the ContentLayer to the base Layer class.
4024 Layer::CalculateContentsScale(ideal_contents_scale
,
4031 explicit NoScaleContentLayer(ContentLayerClient
* client
)
4032 : ContentLayer(client
) {}
4033 virtual ~NoScaleContentLayer() {}
4036 scoped_refptr
<NoScaleContentLayer
> CreateNoScaleDrawableContentLayer(
4037 ContentLayerClient
* delegate
) {
4038 scoped_refptr
<NoScaleContentLayer
> to_return
=
4039 NoScaleContentLayer::Create(delegate
);
4040 to_return
->SetIsDrawable(true);
4044 TEST_F(LayerTreeHostCommonTest
, LayerTransformsInHighDPI
) {
4045 // Verify draw and screen space transforms of layers not in a surface.
4046 MockContentLayerClient delegate
;
4047 gfx::Transform identity_matrix
;
4049 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4050 SetLayerPropertiesForTesting(parent
.get(),
4054 gfx::Size(100, 100),
4058 scoped_refptr
<ContentLayer
> child
= CreateDrawableContentLayer(&delegate
);
4059 SetLayerPropertiesForTesting(child
.get(),
4062 gfx::PointF(2.f
, 2.f
),
4067 scoped_refptr
<ContentLayer
> child_empty
=
4068 CreateDrawableContentLayer(&delegate
);
4069 SetLayerPropertiesForTesting(child_empty
.get(),
4072 gfx::PointF(2.f
, 2.f
),
4077 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4078 CreateNoScaleDrawableContentLayer(&delegate
);
4079 SetLayerPropertiesForTesting(child_no_scale
.get(),
4082 gfx::PointF(2.f
, 2.f
),
4087 parent
->AddChild(child
);
4088 parent
->AddChild(child_empty
);
4089 parent
->AddChild(child_no_scale
);
4091 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
4092 host
->SetRootLayer(parent
);
4094 float device_scale_factor
= 2.5f
;
4095 float page_scale_factor
= 1.f
;
4097 RenderSurfaceLayerList render_surface_layer_list
;
4098 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4099 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4100 inputs
.device_scale_factor
= device_scale_factor
;
4101 inputs
.page_scale_factor
= page_scale_factor
;
4102 inputs
.can_adjust_raster_scales
= true;
4103 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4105 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4106 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, child
);
4107 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4109 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4111 EXPECT_EQ(1u, render_surface_layer_list
.size());
4113 // Verify parent transforms
4114 gfx::Transform expected_parent_transform
;
4115 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4116 parent
->screen_space_transform());
4117 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4118 parent
->draw_transform());
4120 // Verify results of transformed parent rects
4121 gfx::RectF
parent_content_bounds(parent
->content_bounds());
4123 gfx::RectF parent_draw_rect
=
4124 MathUtil::MapClippedRect(parent
->draw_transform(), parent_content_bounds
);
4125 gfx::RectF parent_screen_space_rect
= MathUtil::MapClippedRect(
4126 parent
->screen_space_transform(), parent_content_bounds
);
4128 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
4129 expected_parent_draw_rect
.Scale(device_scale_factor
);
4130 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
4131 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
4133 // Verify child and child_empty transforms. They should match.
4134 gfx::Transform expected_child_transform
;
4135 expected_child_transform
.Translate(
4136 device_scale_factor
* child
->position().x(),
4137 device_scale_factor
* child
->position().y());
4138 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4139 child
->draw_transform());
4140 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4141 child
->screen_space_transform());
4142 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4143 child_empty
->draw_transform());
4144 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4145 child_empty
->screen_space_transform());
4147 // Verify results of transformed child and child_empty rects. They should
4149 gfx::RectF
child_content_bounds(child
->content_bounds());
4151 gfx::RectF child_draw_rect
=
4152 MathUtil::MapClippedRect(child
->draw_transform(), child_content_bounds
);
4153 gfx::RectF child_screen_space_rect
= MathUtil::MapClippedRect(
4154 child
->screen_space_transform(), child_content_bounds
);
4156 gfx::RectF child_empty_draw_rect
= MathUtil::MapClippedRect(
4157 child_empty
->draw_transform(), child_content_bounds
);
4158 gfx::RectF child_empty_screen_space_rect
= MathUtil::MapClippedRect(
4159 child_empty
->screen_space_transform(), child_content_bounds
);
4161 gfx::RectF
expected_child_draw_rect(child
->position(), child
->bounds());
4162 expected_child_draw_rect
.Scale(device_scale_factor
);
4163 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
4164 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
4165 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_draw_rect
);
4166 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_screen_space_rect
);
4168 // Verify child_no_scale transforms
4169 gfx::Transform expected_child_no_scale_transform
= child
->draw_transform();
4170 // All transforms operate on content rects. The child's content rect
4171 // incorporates device scale, but the child_no_scale does not; add it here.
4172 expected_child_no_scale_transform
.Scale(device_scale_factor
,
4173 device_scale_factor
);
4174 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4175 child_no_scale
->draw_transform());
4176 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4177 child_no_scale
->screen_space_transform());
4180 TEST_F(LayerTreeHostCommonTest
, SurfaceLayerTransformsInHighDPI
) {
4181 // Verify draw and screen space transforms of layers in a surface.
4182 MockContentLayerClient delegate
;
4183 gfx::Transform identity_matrix
;
4185 gfx::Transform perspective_matrix
;
4186 perspective_matrix
.ApplyPerspectiveDepth(2.0);
4188 gfx::Transform scale_small_matrix
;
4189 scale_small_matrix
.Scale(SK_MScalar1
/ 10.f
, SK_MScalar1
/ 12.f
);
4191 scoped_refptr
<Layer
> root
= Layer::Create();
4193 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4194 SetLayerPropertiesForTesting(parent
.get(),
4198 gfx::Size(100, 100),
4202 scoped_refptr
<ContentLayer
> perspective_surface
=
4203 CreateDrawableContentLayer(&delegate
);
4204 SetLayerPropertiesForTesting(perspective_surface
.get(),
4205 perspective_matrix
* scale_small_matrix
,
4207 gfx::PointF(2.f
, 2.f
),
4212 scoped_refptr
<ContentLayer
> scale_surface
=
4213 CreateDrawableContentLayer(&delegate
);
4214 SetLayerPropertiesForTesting(scale_surface
.get(),
4217 gfx::PointF(2.f
, 2.f
),
4222 perspective_surface
->SetForceRenderSurface(true);
4223 scale_surface
->SetForceRenderSurface(true);
4225 parent
->AddChild(perspective_surface
);
4226 parent
->AddChild(scale_surface
);
4227 root
->AddChild(parent
);
4229 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
4230 host
->SetRootLayer(root
);
4232 float device_scale_factor
= 2.5f
;
4233 float page_scale_factor
= 3.f
;
4235 RenderSurfaceLayerList render_surface_layer_list
;
4236 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4237 root
.get(), parent
->bounds(), &render_surface_layer_list
);
4238 inputs
.device_scale_factor
= device_scale_factor
;
4239 inputs
.page_scale_factor
= page_scale_factor
;
4240 inputs
.page_scale_application_layer
= root
;
4241 inputs
.can_adjust_raster_scales
= true;
4242 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4244 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4245 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4246 perspective_surface
);
4247 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4250 EXPECT_EQ(3u, render_surface_layer_list
.size());
4252 gfx::Transform expected_parent_draw_transform
;
4253 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform
,
4254 parent
->draw_transform());
4256 // The scaled surface is rendered at its appropriate scale, and drawn 1:1
4258 gfx::Transform expected_scale_surface_draw_transform
;
4259 expected_scale_surface_draw_transform
.Translate(
4260 device_scale_factor
* page_scale_factor
* scale_surface
->position().x(),
4261 device_scale_factor
* page_scale_factor
* scale_surface
->position().y());
4262 EXPECT_TRANSFORMATION_MATRIX_EQ(
4263 expected_scale_surface_draw_transform
,
4264 scale_surface
->render_surface()->draw_transform());
4265 gfx::Transform expected_scale_surface_layer_draw_transform
=
4267 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform
,
4268 scale_surface
->draw_transform());
4270 // The scale for the perspective surface is not known, so it is rendered 1:1
4271 // with the screen, and then scaled during drawing.
4272 gfx::Transform expected_perspective_surface_draw_transform
;
4273 expected_perspective_surface_draw_transform
.Translate(
4274 device_scale_factor
* page_scale_factor
*
4275 perspective_surface
->position().x(),
4276 device_scale_factor
* page_scale_factor
*
4277 perspective_surface
->position().y());
4278 expected_perspective_surface_draw_transform
.PreconcatTransform(
4279 perspective_matrix
);
4280 expected_perspective_surface_draw_transform
.PreconcatTransform(
4281 scale_small_matrix
);
4282 gfx::Transform expected_perspective_surface_layer_draw_transform
;
4283 EXPECT_TRANSFORMATION_MATRIX_EQ(
4284 expected_perspective_surface_draw_transform
,
4285 perspective_surface
->render_surface()->draw_transform());
4286 EXPECT_TRANSFORMATION_MATRIX_EQ(
4287 expected_perspective_surface_layer_draw_transform
,
4288 perspective_surface
->draw_transform());
4291 TEST_F(LayerTreeHostCommonTest
,
4292 LayerTransformsInHighDPIAccurateScaleZeroChildPosition
) {
4293 // Verify draw and screen space transforms of layers not in a surface.
4294 MockContentLayerClient delegate
;
4295 gfx::Transform identity_matrix
;
4297 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4298 SetLayerPropertiesForTesting(parent
.get(),
4302 gfx::Size(133, 133),
4306 scoped_refptr
<ContentLayer
> child
= CreateDrawableContentLayer(&delegate
);
4307 SetLayerPropertiesForTesting(child
.get(),
4315 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4316 CreateNoScaleDrawableContentLayer(&delegate
);
4317 SetLayerPropertiesForTesting(child_no_scale
.get(),
4325 parent
->AddChild(child
);
4326 parent
->AddChild(child_no_scale
);
4328 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
4329 host
->SetRootLayer(parent
);
4331 float device_scale_factor
= 1.7f
;
4332 float page_scale_factor
= 1.f
;
4334 RenderSurfaceLayerList render_surface_layer_list
;
4335 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4336 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4337 inputs
.device_scale_factor
= device_scale_factor
;
4338 inputs
.page_scale_factor
= page_scale_factor
;
4339 inputs
.page_scale_application_layer
= parent
.get();
4340 inputs
.can_adjust_raster_scales
= true;
4341 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4343 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4344 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, child
);
4345 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4347 EXPECT_EQ(1u, render_surface_layer_list
.size());
4349 // Verify parent transforms
4350 gfx::Transform expected_parent_transform
;
4351 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4352 parent
->screen_space_transform());
4353 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4354 parent
->draw_transform());
4356 // Verify results of transformed parent rects
4357 gfx::RectF
parent_content_bounds(parent
->content_bounds());
4359 gfx::RectF parent_draw_rect
=
4360 MathUtil::MapClippedRect(parent
->draw_transform(), parent_content_bounds
);
4361 gfx::RectF parent_screen_space_rect
= MathUtil::MapClippedRect(
4362 parent
->screen_space_transform(), parent_content_bounds
);
4364 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
4365 expected_parent_draw_rect
.Scale(device_scale_factor
);
4366 expected_parent_draw_rect
.set_width(ceil(expected_parent_draw_rect
.width()));
4367 expected_parent_draw_rect
.set_height(
4368 ceil(expected_parent_draw_rect
.height()));
4369 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
4370 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
4372 // Verify child transforms
4373 gfx::Transform expected_child_transform
;
4374 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4375 child
->draw_transform());
4376 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4377 child
->screen_space_transform());
4379 // Verify results of transformed child rects
4380 gfx::RectF
child_content_bounds(child
->content_bounds());
4382 gfx::RectF child_draw_rect
=
4383 MathUtil::MapClippedRect(child
->draw_transform(), child_content_bounds
);
4384 gfx::RectF child_screen_space_rect
= MathUtil::MapClippedRect(
4385 child
->screen_space_transform(), child_content_bounds
);
4387 gfx::RectF
expected_child_draw_rect(child
->bounds());
4388 expected_child_draw_rect
.Scale(device_scale_factor
);
4389 expected_child_draw_rect
.set_width(ceil(expected_child_draw_rect
.width()));
4390 expected_child_draw_rect
.set_height(ceil(expected_child_draw_rect
.height()));
4391 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
4392 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
4394 // Verify child_no_scale transforms
4395 gfx::Transform expected_child_no_scale_transform
= child
->draw_transform();
4396 // All transforms operate on content rects. The child's content rect
4397 // incorporates device scale, but the child_no_scale does not; add it here.
4398 expected_child_no_scale_transform
.Scale(device_scale_factor
,
4399 device_scale_factor
);
4400 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4401 child_no_scale
->draw_transform());
4402 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4403 child_no_scale
->screen_space_transform());
4406 TEST_F(LayerTreeHostCommonTest
, ContentsScale
) {
4407 MockContentLayerClient delegate
;
4408 gfx::Transform identity_matrix
;
4410 gfx::Transform parent_scale_matrix
;
4411 SkMScalar initial_parent_scale
= 1.75;
4412 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4414 gfx::Transform child_scale_matrix
;
4415 SkMScalar initial_child_scale
= 1.25;
4416 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4418 scoped_refptr
<Layer
> root
= Layer::Create();
4419 root
->SetBounds(gfx::Size(100, 100));
4421 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4422 SetLayerPropertiesForTesting(parent
.get(),
4423 parent_scale_matrix
,
4426 gfx::Size(100, 100),
4430 scoped_refptr
<ContentLayer
> child_scale
=
4431 CreateDrawableContentLayer(&delegate
);
4432 SetLayerPropertiesForTesting(child_scale
.get(),
4435 gfx::PointF(2.f
, 2.f
),
4440 scoped_refptr
<ContentLayer
> child_empty
=
4441 CreateDrawableContentLayer(&delegate
);
4442 SetLayerPropertiesForTesting(child_empty
.get(),
4445 gfx::PointF(2.f
, 2.f
),
4450 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4451 CreateNoScaleDrawableContentLayer(&delegate
);
4452 SetLayerPropertiesForTesting(child_no_scale
.get(),
4455 gfx::PointF(12.f
, 12.f
),
4460 root
->AddChild(parent
);
4462 parent
->AddChild(child_scale
);
4463 parent
->AddChild(child_empty
);
4464 parent
->AddChild(child_no_scale
);
4466 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
4467 host
->SetRootLayer(root
);
4469 float device_scale_factor
= 2.5f
;
4470 float page_scale_factor
= 1.f
;
4473 RenderSurfaceLayerList render_surface_layer_list
;
4474 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4475 root
.get(), root
->bounds(), &render_surface_layer_list
);
4476 inputs
.device_scale_factor
= device_scale_factor
;
4477 inputs
.page_scale_factor
= page_scale_factor
;
4478 inputs
.page_scale_application_layer
= root
.get();
4479 inputs
.can_adjust_raster_scales
= true;
4480 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4482 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4483 initial_parent_scale
, parent
);
4484 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4485 initial_parent_scale
* initial_child_scale
,
4487 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4488 initial_parent_scale
* initial_child_scale
,
4490 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4492 // The parent is scaled up and shouldn't need to scale during draw. The
4493 // child that can scale its contents should also not need to scale during
4494 // draw. This shouldn't change if the child has empty bounds. The other
4496 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(0, 0));
4497 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(1, 1));
4498 EXPECT_FLOAT_EQ(1.0, child_scale
->draw_transform().matrix().get(0, 0));
4499 EXPECT_FLOAT_EQ(1.0, child_scale
->draw_transform().matrix().get(1, 1));
4500 EXPECT_FLOAT_EQ(1.0, child_empty
->draw_transform().matrix().get(0, 0));
4501 EXPECT_FLOAT_EQ(1.0, child_empty
->draw_transform().matrix().get(1, 1));
4502 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4503 initial_parent_scale
* initial_child_scale
,
4504 child_no_scale
->draw_transform().matrix().get(0, 0));
4505 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4506 initial_parent_scale
* initial_child_scale
,
4507 child_no_scale
->draw_transform().matrix().get(1, 1));
4510 // If the device_scale_factor or page_scale_factor changes, then it should be
4511 // updated using the initial transform as the raster scale.
4512 device_scale_factor
= 2.25f
;
4513 page_scale_factor
= 1.25f
;
4516 RenderSurfaceLayerList render_surface_layer_list
;
4517 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4518 root
.get(), root
->bounds(), &render_surface_layer_list
);
4519 inputs
.device_scale_factor
= device_scale_factor
;
4520 inputs
.page_scale_factor
= page_scale_factor
;
4521 inputs
.page_scale_application_layer
= root
.get();
4522 inputs
.can_adjust_raster_scales
= true;
4523 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4525 EXPECT_CONTENTS_SCALE_EQ(
4526 device_scale_factor
* page_scale_factor
* initial_parent_scale
, parent
);
4527 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4528 initial_parent_scale
* initial_child_scale
,
4530 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4531 initial_parent_scale
* initial_child_scale
,
4533 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4536 // If the transform changes, we expect the raster scale to be reset to 1.0.
4537 SkMScalar second_child_scale
= 1.75;
4538 child_scale_matrix
.Scale(second_child_scale
/ initial_child_scale
,
4539 second_child_scale
/ initial_child_scale
);
4540 child_scale
->SetTransform(child_scale_matrix
);
4541 child_empty
->SetTransform(child_scale_matrix
);
4544 RenderSurfaceLayerList render_surface_layer_list
;
4545 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4546 root
.get(), root
->bounds(), &render_surface_layer_list
);
4547 inputs
.device_scale_factor
= device_scale_factor
;
4548 inputs
.page_scale_factor
= page_scale_factor
;
4549 inputs
.page_scale_application_layer
= root
.get();
4550 inputs
.can_adjust_raster_scales
= true;
4551 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4553 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4554 initial_parent_scale
,
4556 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4558 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4560 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4563 // If the device_scale_factor or page_scale_factor changes, then it should be
4564 // updated, but still using 1.0 as the raster scale.
4565 device_scale_factor
= 2.75f
;
4566 page_scale_factor
= 1.75f
;
4569 RenderSurfaceLayerList render_surface_layer_list
;
4570 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4571 root
.get(), root
->bounds(), &render_surface_layer_list
);
4572 inputs
.device_scale_factor
= device_scale_factor
;
4573 inputs
.page_scale_factor
= page_scale_factor
;
4574 inputs
.page_scale_application_layer
= root
.get();
4575 inputs
.can_adjust_raster_scales
= true;
4576 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4578 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4579 initial_parent_scale
,
4581 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4583 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4585 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4589 TEST_F(LayerTreeHostCommonTest
,
4590 ContentsScale_LayerTransformsDontAffectContentsScale
) {
4591 MockContentLayerClient delegate
;
4592 gfx::Transform identity_matrix
;
4594 gfx::Transform parent_scale_matrix
;
4595 SkMScalar initial_parent_scale
= 1.75;
4596 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4598 gfx::Transform child_scale_matrix
;
4599 SkMScalar initial_child_scale
= 1.25;
4600 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4602 scoped_refptr
<Layer
> root
= Layer::Create();
4603 root
->SetBounds(gfx::Size(100, 100));
4605 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4606 SetLayerPropertiesForTesting(parent
.get(),
4607 parent_scale_matrix
,
4610 gfx::Size(100, 100),
4614 scoped_refptr
<ContentLayer
> child_scale
=
4615 CreateDrawableContentLayer(&delegate
);
4616 SetLayerPropertiesForTesting(child_scale
.get(),
4619 gfx::PointF(2.f
, 2.f
),
4624 scoped_refptr
<ContentLayer
> child_empty
=
4625 CreateDrawableContentLayer(&delegate
);
4626 SetLayerPropertiesForTesting(child_empty
.get(),
4629 gfx::PointF(2.f
, 2.f
),
4634 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4635 CreateNoScaleDrawableContentLayer(&delegate
);
4636 SetLayerPropertiesForTesting(child_no_scale
.get(),
4639 gfx::PointF(12.f
, 12.f
),
4644 root
->AddChild(parent
);
4646 parent
->AddChild(child_scale
);
4647 parent
->AddChild(child_empty
);
4648 parent
->AddChild(child_no_scale
);
4650 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
4651 host
->SetRootLayer(root
);
4653 RenderSurfaceLayerList render_surface_layer_list
;
4655 float device_scale_factor
= 2.5f
;
4656 float page_scale_factor
= 1.f
;
4658 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4659 root
.get(), root
->bounds(), &render_surface_layer_list
);
4660 inputs
.device_scale_factor
= device_scale_factor
;
4661 inputs
.page_scale_factor
= page_scale_factor
;
4662 inputs
.page_scale_application_layer
= root
.get(),
4663 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4665 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4666 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4668 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4670 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4672 // Since the transform scale does not affect contents scale, it should affect
4673 // the draw transform instead.
4674 EXPECT_FLOAT_EQ(initial_parent_scale
,
4675 parent
->draw_transform().matrix().get(0, 0));
4676 EXPECT_FLOAT_EQ(initial_parent_scale
,
4677 parent
->draw_transform().matrix().get(1, 1));
4678 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4679 child_scale
->draw_transform().matrix().get(0, 0));
4680 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4681 child_scale
->draw_transform().matrix().get(1, 1));
4682 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4683 child_empty
->draw_transform().matrix().get(0, 0));
4684 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4685 child_empty
->draw_transform().matrix().get(1, 1));
4686 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4687 initial_parent_scale
* initial_child_scale
,
4688 child_no_scale
->draw_transform().matrix().get(0, 0));
4689 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4690 initial_parent_scale
* initial_child_scale
,
4691 child_no_scale
->draw_transform().matrix().get(1, 1));
4694 TEST_F(LayerTreeHostCommonTest
, SmallContentsScale
) {
4695 MockContentLayerClient delegate
;
4696 gfx::Transform identity_matrix
;
4698 gfx::Transform parent_scale_matrix
;
4699 SkMScalar initial_parent_scale
= 1.75;
4700 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4702 gfx::Transform child_scale_matrix
;
4703 SkMScalar initial_child_scale
= 0.25;
4704 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4706 scoped_refptr
<Layer
> root
= Layer::Create();
4707 root
->SetBounds(gfx::Size(100, 100));
4709 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4710 SetLayerPropertiesForTesting(parent
.get(),
4711 parent_scale_matrix
,
4714 gfx::Size(100, 100),
4718 scoped_refptr
<ContentLayer
> child_scale
=
4719 CreateDrawableContentLayer(&delegate
);
4720 SetLayerPropertiesForTesting(child_scale
.get(),
4723 gfx::PointF(2.f
, 2.f
),
4728 root
->AddChild(parent
);
4730 parent
->AddChild(child_scale
);
4732 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
4733 host
->SetRootLayer(root
);
4735 float device_scale_factor
= 2.5f
;
4736 float page_scale_factor
= 0.01f
;
4739 RenderSurfaceLayerList render_surface_layer_list
;
4740 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4741 root
.get(), root
->bounds(), &render_surface_layer_list
);
4742 inputs
.device_scale_factor
= device_scale_factor
;
4743 inputs
.page_scale_factor
= page_scale_factor
;
4744 inputs
.page_scale_application_layer
= root
.get();
4745 inputs
.can_adjust_raster_scales
= true;
4746 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4748 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4749 initial_parent_scale
,
4751 // The child's scale is < 1, so we should not save and use that scale
4753 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
* 1,
4757 // When chilld's total scale becomes >= 1, we should save and use that scale
4759 child_scale_matrix
.MakeIdentity();
4760 SkMScalar final_child_scale
= 0.75;
4761 child_scale_matrix
.Scale(final_child_scale
, final_child_scale
);
4762 child_scale
->SetTransform(child_scale_matrix
);
4765 RenderSurfaceLayerList render_surface_layer_list
;
4766 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4767 root
.get(), root
->bounds(), &render_surface_layer_list
);
4768 inputs
.device_scale_factor
= device_scale_factor
;
4769 inputs
.page_scale_factor
= page_scale_factor
;
4770 inputs
.page_scale_application_layer
= root
.get();
4771 inputs
.can_adjust_raster_scales
= true;
4772 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4774 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4775 initial_parent_scale
,
4777 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4778 initial_parent_scale
* final_child_scale
,
4783 TEST_F(LayerTreeHostCommonTest
, ContentsScaleForSurfaces
) {
4784 MockContentLayerClient delegate
;
4785 gfx::Transform identity_matrix
;
4787 gfx::Transform parent_scale_matrix
;
4788 SkMScalar initial_parent_scale
= 2.0;
4789 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4791 gfx::Transform child_scale_matrix
;
4792 SkMScalar initial_child_scale
= 3.0;
4793 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4795 scoped_refptr
<Layer
> root
= Layer::Create();
4796 root
->SetBounds(gfx::Size(100, 100));
4798 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4799 SetLayerPropertiesForTesting(parent
.get(),
4800 parent_scale_matrix
,
4803 gfx::Size(100, 100),
4807 scoped_refptr
<ContentLayer
> surface_scale
=
4808 CreateDrawableContentLayer(&delegate
);
4809 SetLayerPropertiesForTesting(surface_scale
.get(),
4812 gfx::PointF(2.f
, 2.f
),
4817 scoped_refptr
<ContentLayer
> surface_scale_child_scale
=
4818 CreateDrawableContentLayer(&delegate
);
4819 SetLayerPropertiesForTesting(surface_scale_child_scale
.get(),
4827 scoped_refptr
<NoScaleContentLayer
> surface_scale_child_no_scale
=
4828 CreateNoScaleDrawableContentLayer(&delegate
);
4829 SetLayerPropertiesForTesting(surface_scale_child_no_scale
.get(),
4837 scoped_refptr
<NoScaleContentLayer
> surface_no_scale
=
4838 CreateNoScaleDrawableContentLayer(&delegate
);
4839 SetLayerPropertiesForTesting(surface_no_scale
.get(),
4842 gfx::PointF(12.f
, 12.f
),
4847 scoped_refptr
<ContentLayer
> surface_no_scale_child_scale
=
4848 CreateDrawableContentLayer(&delegate
);
4849 SetLayerPropertiesForTesting(surface_no_scale_child_scale
.get(),
4857 scoped_refptr
<NoScaleContentLayer
> surface_no_scale_child_no_scale
=
4858 CreateNoScaleDrawableContentLayer(&delegate
);
4859 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale
.get(),
4867 root
->AddChild(parent
);
4869 parent
->AddChild(surface_scale
);
4870 parent
->AddChild(surface_no_scale
);
4872 surface_scale
->SetForceRenderSurface(true);
4873 surface_scale
->AddChild(surface_scale_child_scale
);
4874 surface_scale
->AddChild(surface_scale_child_no_scale
);
4876 surface_no_scale
->SetForceRenderSurface(true);
4877 surface_no_scale
->AddChild(surface_no_scale_child_scale
);
4878 surface_no_scale
->AddChild(surface_no_scale_child_no_scale
);
4880 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
4881 host
->SetRootLayer(root
);
4883 SkMScalar device_scale_factor
= 5;
4884 SkMScalar page_scale_factor
= 7;
4886 RenderSurfaceLayerList render_surface_layer_list
;
4887 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4888 root
.get(), root
->bounds(), &render_surface_layer_list
);
4889 inputs
.device_scale_factor
= device_scale_factor
;
4890 inputs
.page_scale_factor
= page_scale_factor
;
4891 inputs
.page_scale_application_layer
= root
.get();
4892 inputs
.can_adjust_raster_scales
= true;
4893 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4895 EXPECT_CONTENTS_SCALE_EQ(
4896 device_scale_factor
* page_scale_factor
* initial_parent_scale
, parent
);
4897 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4898 initial_parent_scale
* initial_child_scale
,
4900 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale
);
4901 EXPECT_CONTENTS_SCALE_EQ(
4902 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4903 initial_child_scale
* initial_child_scale
,
4904 surface_scale_child_scale
);
4905 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale
);
4906 EXPECT_CONTENTS_SCALE_EQ(
4907 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4908 initial_child_scale
* initial_child_scale
,
4909 surface_no_scale_child_scale
);
4910 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale
);
4912 // The parent is scaled up and shouldn't need to scale during draw.
4913 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(0, 0));
4914 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(1, 1));
4916 // RenderSurfaces should always be 1:1 with their target.
4919 surface_scale
->render_surface()->draw_transform().matrix().get(0, 0));
4922 surface_scale
->render_surface()->draw_transform().matrix().get(1, 1));
4924 // The surface_scale can apply contents scale so the layer shouldn't need to
4925 // scale during draw.
4926 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(0, 0));
4927 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(1, 1));
4929 // The surface_scale_child_scale can apply contents scale so it shouldn't need
4930 // to scale during draw.
4932 1.0, surface_scale_child_scale
->draw_transform().matrix().get(0, 0));
4934 1.0, surface_scale_child_scale
->draw_transform().matrix().get(1, 1));
4936 // The surface_scale_child_no_scale can not apply contents scale, so it needs
4937 // to be scaled during draw.
4939 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4940 initial_child_scale
* initial_child_scale
,
4941 surface_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
4943 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4944 initial_child_scale
* initial_child_scale
,
4945 surface_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
4947 // RenderSurfaces should always be 1:1 with their target.
4950 surface_no_scale
->render_surface()->draw_transform().matrix().get(0, 0));
4953 surface_no_scale
->render_surface()->draw_transform().matrix().get(1, 1));
4955 // The surface_no_scale layer can not apply contents scale, so it needs to be
4956 // scaled during draw.
4957 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4958 initial_parent_scale
* initial_child_scale
,
4959 surface_no_scale
->draw_transform().matrix().get(0, 0));
4960 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4961 initial_parent_scale
* initial_child_scale
,
4962 surface_no_scale
->draw_transform().matrix().get(1, 1));
4964 // The surface_scale_child_scale can apply contents scale so it shouldn't need
4965 // to scale during draw.
4967 1.0, surface_no_scale_child_scale
->draw_transform().matrix().get(0, 0));
4969 1.0, surface_no_scale_child_scale
->draw_transform().matrix().get(1, 1));
4971 // The surface_scale_child_no_scale can not apply contents scale, so it needs
4972 // to be scaled during draw.
4974 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4975 initial_child_scale
* initial_child_scale
,
4976 surface_no_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
4978 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4979 initial_child_scale
* initial_child_scale
,
4980 surface_no_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
4983 TEST_F(LayerTreeHostCommonTest
,
4984 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale
) {
4985 MockContentLayerClient delegate
;
4986 gfx::Transform identity_matrix
;
4988 gfx::Transform parent_scale_matrix
;
4989 SkMScalar initial_parent_scale
= 2.0;
4990 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4992 gfx::Transform child_scale_matrix
;
4993 SkMScalar initial_child_scale
= 3.0;
4994 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4996 scoped_refptr
<Layer
> root
= Layer::Create();
4997 root
->SetBounds(gfx::Size(100, 100));
4999 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
5000 SetLayerPropertiesForTesting(parent
.get(),
5001 parent_scale_matrix
,
5004 gfx::Size(100, 100),
5008 scoped_refptr
<ContentLayer
> surface_scale
=
5009 CreateDrawableContentLayer(&delegate
);
5010 SetLayerPropertiesForTesting(surface_scale
.get(),
5013 gfx::PointF(2.f
, 2.f
),
5018 scoped_refptr
<ContentLayer
> surface_scale_child_scale
=
5019 CreateDrawableContentLayer(&delegate
);
5020 SetLayerPropertiesForTesting(surface_scale_child_scale
.get(),
5028 scoped_refptr
<NoScaleContentLayer
> surface_scale_child_no_scale
=
5029 CreateNoScaleDrawableContentLayer(&delegate
);
5030 SetLayerPropertiesForTesting(surface_scale_child_no_scale
.get(),
5038 scoped_refptr
<NoScaleContentLayer
> surface_no_scale
=
5039 CreateNoScaleDrawableContentLayer(&delegate
);
5040 SetLayerPropertiesForTesting(surface_no_scale
.get(),
5043 gfx::PointF(12.f
, 12.f
),
5048 scoped_refptr
<ContentLayer
> surface_no_scale_child_scale
=
5049 CreateDrawableContentLayer(&delegate
);
5050 SetLayerPropertiesForTesting(surface_no_scale_child_scale
.get(),
5058 scoped_refptr
<NoScaleContentLayer
> surface_no_scale_child_no_scale
=
5059 CreateNoScaleDrawableContentLayer(&delegate
);
5060 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale
.get(),
5068 root
->AddChild(parent
);
5070 parent
->AddChild(surface_scale
);
5071 parent
->AddChild(surface_no_scale
);
5073 surface_scale
->SetForceRenderSurface(true);
5074 surface_scale
->AddChild(surface_scale_child_scale
);
5075 surface_scale
->AddChild(surface_scale_child_no_scale
);
5077 surface_no_scale
->SetForceRenderSurface(true);
5078 surface_no_scale
->AddChild(surface_no_scale_child_scale
);
5079 surface_no_scale
->AddChild(surface_no_scale_child_no_scale
);
5081 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5082 host
->SetRootLayer(root
);
5084 RenderSurfaceLayerList render_surface_layer_list
;
5086 SkMScalar device_scale_factor
= 5.0;
5087 SkMScalar page_scale_factor
= 7.0;
5088 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5089 root
.get(), root
->bounds(), &render_surface_layer_list
);
5090 inputs
.device_scale_factor
= device_scale_factor
;
5091 inputs
.page_scale_factor
= page_scale_factor
;
5092 inputs
.page_scale_application_layer
= root
.get();
5093 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5095 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5097 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5099 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_no_scale
);
5100 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5101 surface_scale_child_scale
);
5102 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_scale_child_no_scale
);
5103 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5104 surface_no_scale_child_scale
);
5105 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_no_scale_child_no_scale
);
5107 // The parent is scaled up during draw, since its contents are not scaled by
5108 // the transform hierarchy.
5109 EXPECT_FLOAT_EQ(initial_parent_scale
,
5110 parent
->draw_transform().matrix().get(0, 0));
5111 EXPECT_FLOAT_EQ(initial_parent_scale
,
5112 parent
->draw_transform().matrix().get(1, 1));
5114 // The child surface is scaled up during draw since its subtree is not scaled
5115 // by the transform hierarchy.
5117 initial_parent_scale
* initial_child_scale
,
5118 surface_scale
->render_surface()->draw_transform().matrix().get(0, 0));
5120 initial_parent_scale
* initial_child_scale
,
5121 surface_scale
->render_surface()->draw_transform().matrix().get(1, 1));
5123 // The surface_scale's RenderSurface is scaled during draw, so the layer does
5124 // not need to be scaled when drawing into its surface.
5125 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(0, 0));
5126 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(1, 1));
5128 // The surface_scale_child_scale is scaled when drawing into its surface,
5129 // since its content bounds are not scaled by the transform hierarchy.
5131 initial_child_scale
,
5132 surface_scale_child_scale
->draw_transform().matrix().get(0, 0));
5134 initial_child_scale
,
5135 surface_scale_child_scale
->draw_transform().matrix().get(1, 1));
5137 // The surface_scale_child_no_scale has a fixed contents scale of 1, so it
5138 // needs to be scaled by the device and page scale factors, along with the
5139 // transform hierarchy.
5141 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5142 surface_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5144 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5145 surface_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5147 // The child surface is scaled up during draw since its subtree is not scaled
5148 // by the transform hierarchy.
5150 initial_parent_scale
* initial_child_scale
,
5151 surface_no_scale
->render_surface()->draw_transform().matrix().get(0, 0));
5153 initial_parent_scale
* initial_child_scale
,
5154 surface_no_scale
->render_surface()->draw_transform().matrix().get(1, 1));
5156 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
5157 // be scaled by the device and page scale factors. Its surface is already
5158 // scaled by the transform hierarchy so those don't need to scale the layer's
5160 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
,
5161 surface_no_scale
->draw_transform().matrix().get(0, 0));
5162 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
,
5163 surface_no_scale
->draw_transform().matrix().get(1, 1));
5165 // The surface_no_scale_child_scale has its contents scaled by the page and
5166 // device scale factors, but needs to be scaled by the transform hierarchy
5169 initial_child_scale
,
5170 surface_no_scale_child_scale
->draw_transform().matrix().get(0, 0));
5172 initial_child_scale
,
5173 surface_no_scale_child_scale
->draw_transform().matrix().get(1, 1));
5175 // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it
5176 // needs to be scaled by the device and page scale factors. It also needs to
5177 // be scaled by any transform heirarchy below its target surface.
5179 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5180 surface_no_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5182 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5183 surface_no_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5186 TEST_F(LayerTreeHostCommonTest
, ContentsScaleForAnimatingLayer
) {
5187 MockContentLayerClient delegate
;
5188 gfx::Transform identity_matrix
;
5190 gfx::Transform parent_scale_matrix
;
5191 SkMScalar initial_parent_scale
= 1.75;
5192 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
5194 gfx::Transform child_scale_matrix
;
5195 SkMScalar initial_child_scale
= 1.25;
5196 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
5198 scoped_refptr
<Layer
> root
= Layer::Create();
5199 root
->SetBounds(gfx::Size(100, 100));
5201 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
5202 SetLayerPropertiesForTesting(parent
.get(),
5203 parent_scale_matrix
,
5206 gfx::Size(100, 100),
5210 scoped_refptr
<ContentLayer
> child_scale
=
5211 CreateDrawableContentLayer(&delegate
);
5212 SetLayerPropertiesForTesting(child_scale
.get(),
5215 gfx::PointF(2.f
, 2.f
),
5220 root
->AddChild(parent
);
5222 parent
->AddChild(child_scale
);
5224 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5225 host
->SetRootLayer(root
);
5227 // Now put an animating transform on child.
5228 int animation_id
= AddAnimatedTransformToController(
5229 child_scale
->layer_animation_controller(), 10.0, 30, 0);
5232 RenderSurfaceLayerList render_surface_layer_list
;
5233 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5234 root
.get(), root
->bounds(), &render_surface_layer_list
);
5235 inputs
.can_adjust_raster_scales
= true;
5236 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5238 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale
, parent
);
5239 // The layers with animating transforms should not compute a contents scale
5240 // other than 1 until they finish animating.
5241 EXPECT_CONTENTS_SCALE_EQ(1, child_scale
);
5244 // Remove the animation, now it can save a raster scale.
5245 child_scale
->layer_animation_controller()->RemoveAnimation(animation_id
);
5248 RenderSurfaceLayerList render_surface_layer_list
;
5249 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5250 root
.get(), root
->bounds(), &render_surface_layer_list
);
5251 inputs
.can_adjust_raster_scales
= true;
5252 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5254 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale
, parent
);
5255 // The layers with animating transforms should not compute a contents scale
5256 // other than 1 until they finish animating.
5257 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale
* initial_child_scale
,
5262 TEST_F(LayerTreeHostCommonTest
,
5263 ChangeInContentBoundsOrScaleTriggersPushProperties
) {
5264 MockContentLayerClient delegate
;
5265 scoped_refptr
<Layer
> root
= Layer::Create();
5266 scoped_refptr
<Layer
> child
= CreateDrawableContentLayer(&delegate
);
5267 root
->AddChild(child
);
5269 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5270 host
->SetRootLayer(root
);
5272 gfx::Transform identity_matrix
;
5273 SetLayerPropertiesForTesting(root
.get(),
5277 gfx::Size(100, 100),
5280 SetLayerPropertiesForTesting(child
.get(),
5284 gfx::Size(100, 100),
5288 root
->reset_needs_push_properties_for_testing();
5289 child
->reset_needs_push_properties_for_testing();
5291 // This will change both layers' content bounds.
5292 ExecuteCalculateDrawProperties(root
.get());
5293 EXPECT_TRUE(root
->needs_push_properties());
5294 EXPECT_TRUE(child
->needs_push_properties());
5296 root
->reset_needs_push_properties_for_testing();
5297 child
->reset_needs_push_properties_for_testing();
5299 // This will change only the child layer's contents scale and content bounds,
5300 // since the root layer is not a ContentsScalingLayer.
5301 ExecuteCalculateDrawProperties(root
.get(), 2.f
);
5302 EXPECT_FALSE(root
->needs_push_properties());
5303 EXPECT_TRUE(child
->needs_push_properties());
5305 root
->reset_needs_push_properties_for_testing();
5306 child
->reset_needs_push_properties_for_testing();
5308 // This will not change either layer's contents scale or content bounds.
5309 ExecuteCalculateDrawProperties(root
.get(), 2.f
);
5310 EXPECT_FALSE(root
->needs_push_properties());
5311 EXPECT_FALSE(child
->needs_push_properties());
5314 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceTransformsInHighDPI
) {
5315 MockContentLayerClient delegate
;
5316 gfx::Transform identity_matrix
;
5318 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
5319 SetLayerPropertiesForTesting(parent
.get(),
5327 scoped_refptr
<ContentLayer
> child
= CreateDrawableContentLayer(&delegate
);
5328 SetLayerPropertiesForTesting(child
.get(),
5331 gfx::PointF(2.f
, 2.f
),
5336 gfx::Transform replica_transform
;
5337 replica_transform
.Scale(1.0, -1.0);
5338 scoped_refptr
<ContentLayer
> replica
= CreateDrawableContentLayer(&delegate
);
5339 SetLayerPropertiesForTesting(replica
.get(),
5342 gfx::PointF(2.f
, 2.f
),
5347 // This layer should end up in the same surface as child, with the same draw
5348 // and screen space transforms.
5349 scoped_refptr
<ContentLayer
> duplicate_child_non_owner
=
5350 CreateDrawableContentLayer(&delegate
);
5351 SetLayerPropertiesForTesting(duplicate_child_non_owner
.get(),
5359 parent
->AddChild(child
);
5360 child
->AddChild(duplicate_child_non_owner
);
5361 child
->SetReplicaLayer(replica
.get());
5363 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5364 host
->SetRootLayer(parent
);
5366 RenderSurfaceLayerList render_surface_layer_list
;
5368 float device_scale_factor
= 1.5f
;
5369 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5370 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
5371 inputs
.device_scale_factor
= device_scale_factor
;
5372 inputs
.can_adjust_raster_scales
= true;
5373 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5375 // We should have two render surfaces. The root's render surface and child's
5376 // render surface (it needs one because it has a replica layer).
5377 EXPECT_EQ(2u, render_surface_layer_list
.size());
5379 gfx::Transform expected_parent_transform
;
5380 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
5381 parent
->screen_space_transform());
5382 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
5383 parent
->draw_transform());
5385 gfx::Transform expected_draw_transform
;
5386 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform
,
5387 child
->draw_transform());
5389 gfx::Transform expected_screen_space_transform
;
5390 expected_screen_space_transform
.Translate(
5391 device_scale_factor
* child
->position().x(),
5392 device_scale_factor
* child
->position().y());
5393 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform
,
5394 child
->screen_space_transform());
5396 gfx::Transform expected_duplicate_child_draw_transform
=
5397 child
->draw_transform();
5398 EXPECT_TRANSFORMATION_MATRIX_EQ(child
->draw_transform(),
5399 duplicate_child_non_owner
->draw_transform());
5400 EXPECT_TRANSFORMATION_MATRIX_EQ(
5401 child
->screen_space_transform(),
5402 duplicate_child_non_owner
->screen_space_transform());
5403 EXPECT_RECT_EQ(child
->drawable_content_rect(),
5404 duplicate_child_non_owner
->drawable_content_rect());
5405 EXPECT_EQ(child
->content_bounds(),
5406 duplicate_child_non_owner
->content_bounds());
5408 gfx::Transform expected_render_surface_draw_transform
;
5409 expected_render_surface_draw_transform
.Translate(
5410 device_scale_factor
* child
->position().x(),
5411 device_scale_factor
* child
->position().y());
5412 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform
,
5413 child
->render_surface()->draw_transform());
5415 gfx::Transform expected_surface_draw_transform
;
5416 expected_surface_draw_transform
.Translate(device_scale_factor
* 2.f
,
5417 device_scale_factor
* 2.f
);
5418 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform
,
5419 child
->render_surface()->draw_transform());
5421 gfx::Transform expected_surface_screen_space_transform
;
5422 expected_surface_screen_space_transform
.Translate(device_scale_factor
* 2.f
,
5423 device_scale_factor
* 2.f
);
5424 EXPECT_TRANSFORMATION_MATRIX_EQ(
5425 expected_surface_screen_space_transform
,
5426 child
->render_surface()->screen_space_transform());
5428 gfx::Transform expected_replica_draw_transform
;
5429 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
5430 expected_replica_draw_transform
.matrix().set(0, 3, 6.0);
5431 expected_replica_draw_transform
.matrix().set(1, 3, 6.0);
5432 EXPECT_TRANSFORMATION_MATRIX_EQ(
5433 expected_replica_draw_transform
,
5434 child
->render_surface()->replica_draw_transform());
5436 gfx::Transform expected_replica_screen_space_transform
;
5437 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
5438 expected_replica_screen_space_transform
.matrix().set(0, 3, 6.0);
5439 expected_replica_screen_space_transform
.matrix().set(1, 3, 6.0);
5440 EXPECT_TRANSFORMATION_MATRIX_EQ(
5441 expected_replica_screen_space_transform
,
5442 child
->render_surface()->replica_screen_space_transform());
5443 EXPECT_TRANSFORMATION_MATRIX_EQ(
5444 expected_replica_screen_space_transform
,
5445 child
->render_surface()->replica_screen_space_transform());
5448 TEST_F(LayerTreeHostCommonTest
,
5449 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition
) {
5450 MockContentLayerClient delegate
;
5451 gfx::Transform identity_matrix
;
5453 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
5454 SetLayerPropertiesForTesting(parent
.get(),
5462 scoped_refptr
<ContentLayer
> child
= CreateDrawableContentLayer(&delegate
);
5463 SetLayerPropertiesForTesting(child
.get(),
5471 gfx::Transform replica_transform
;
5472 replica_transform
.Scale(1.0, -1.0);
5473 scoped_refptr
<ContentLayer
> replica
= CreateDrawableContentLayer(&delegate
);
5474 SetLayerPropertiesForTesting(replica
.get(),
5482 // This layer should end up in the same surface as child, with the same draw
5483 // and screen space transforms.
5484 scoped_refptr
<ContentLayer
> duplicate_child_non_owner
=
5485 CreateDrawableContentLayer(&delegate
);
5486 SetLayerPropertiesForTesting(duplicate_child_non_owner
.get(),
5494 parent
->AddChild(child
);
5495 child
->AddChild(duplicate_child_non_owner
);
5496 child
->SetReplicaLayer(replica
.get());
5498 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5499 host
->SetRootLayer(parent
);
5501 float device_scale_factor
= 1.7f
;
5503 RenderSurfaceLayerList render_surface_layer_list
;
5504 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5505 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
5506 inputs
.device_scale_factor
= device_scale_factor
;
5507 inputs
.can_adjust_raster_scales
= true;
5508 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5510 // We should have two render surfaces. The root's render surface and child's
5511 // render surface (it needs one because it has a replica layer).
5512 EXPECT_EQ(2u, render_surface_layer_list
.size());
5514 gfx::Transform identity_transform
;
5516 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5517 parent
->screen_space_transform());
5518 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
, parent
->draw_transform());
5519 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
, child
->draw_transform());
5520 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5521 child
->screen_space_transform());
5522 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5523 duplicate_child_non_owner
->draw_transform());
5524 EXPECT_TRANSFORMATION_MATRIX_EQ(
5525 identity_transform
, duplicate_child_non_owner
->screen_space_transform());
5526 EXPECT_RECT_EQ(child
->drawable_content_rect(),
5527 duplicate_child_non_owner
->drawable_content_rect());
5528 EXPECT_EQ(child
->content_bounds(),
5529 duplicate_child_non_owner
->content_bounds());
5531 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5532 child
->render_surface()->draw_transform());
5533 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5534 child
->render_surface()->draw_transform());
5535 EXPECT_TRANSFORMATION_MATRIX_EQ(
5536 identity_transform
, child
->render_surface()->screen_space_transform());
5538 gfx::Transform expected_replica_draw_transform
;
5539 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
5540 EXPECT_TRANSFORMATION_MATRIX_EQ(
5541 expected_replica_draw_transform
,
5542 child
->render_surface()->replica_draw_transform());
5544 gfx::Transform expected_replica_screen_space_transform
;
5545 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
5546 EXPECT_TRANSFORMATION_MATRIX_EQ(
5547 expected_replica_screen_space_transform
,
5548 child
->render_surface()->replica_screen_space_transform());
5551 TEST_F(LayerTreeHostCommonTest
, SubtreeSearch
) {
5552 scoped_refptr
<Layer
> root
= Layer::Create();
5553 scoped_refptr
<Layer
> child
= Layer::Create();
5554 scoped_refptr
<Layer
> grand_child
= Layer::Create();
5555 scoped_refptr
<Layer
> mask_layer
= Layer::Create();
5556 scoped_refptr
<Layer
> replica_layer
= Layer::Create();
5558 grand_child
->SetReplicaLayer(replica_layer
.get());
5559 child
->AddChild(grand_child
.get());
5560 child
->SetMaskLayer(mask_layer
.get());
5561 root
->AddChild(child
.get());
5563 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5564 host
->SetRootLayer(root
);
5566 int nonexistent_id
= -1;
5568 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), root
->id()));
5570 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), child
->id()));
5573 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), grand_child
->id()));
5576 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), mask_layer
->id()));
5579 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), replica_layer
->id()));
5581 0, LayerTreeHostCommon::FindLayerInSubtree(root
.get(), nonexistent_id
));
5584 TEST_F(LayerTreeHostCommonTest
, TransparentChildRenderSurfaceCreation
) {
5585 scoped_refptr
<Layer
> root
= Layer::Create();
5586 scoped_refptr
<Layer
> child
= Layer::Create();
5587 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
5588 make_scoped_refptr(new LayerWithForcedDrawsContent());
5590 const gfx::Transform identity_matrix
;
5591 SetLayerPropertiesForTesting(root
.get(),
5595 gfx::Size(100, 100),
5598 SetLayerPropertiesForTesting(child
.get(),
5605 SetLayerPropertiesForTesting(grand_child
.get(),
5613 root
->AddChild(child
);
5614 child
->AddChild(grand_child
);
5615 child
->SetOpacity(0.5f
);
5617 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5618 host
->SetRootLayer(root
);
5620 ExecuteCalculateDrawProperties(root
.get());
5622 EXPECT_FALSE(child
->render_surface());
5625 TEST_F(LayerTreeHostCommonTest
, OpacityAnimatingOnPendingTree
) {
5626 FakeImplProxy proxy
;
5627 TestSharedBitmapManager shared_bitmap_manager
;
5628 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5629 host_impl
.CreatePendingTree();
5630 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
5632 const gfx::Transform identity_matrix
;
5633 SetLayerPropertiesForTesting(root
.get(),
5637 gfx::Size(100, 100),
5640 root
->SetDrawsContent(true);
5642 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
5643 SetLayerPropertiesForTesting(child
.get(),
5650 child
->SetDrawsContent(true);
5651 child
->SetOpacity(0.0f
);
5653 // Add opacity animation.
5654 AddOpacityTransitionToController(
5655 child
->layer_animation_controller(), 10.0, 0.0f
, 1.0f
, false);
5657 root
->AddChild(child
.Pass());
5659 LayerImplList render_surface_layer_list
;
5660 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5661 root
.get(), root
->bounds(), &render_surface_layer_list
);
5662 inputs
.can_adjust_raster_scales
= true;
5663 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5665 // We should have one render surface and two layers. The child
5666 // layer should be included even though it is transparent.
5667 ASSERT_EQ(1u, render_surface_layer_list
.size());
5668 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5671 typedef std::tr1::tuple
<bool, bool> LCDTextTestParam
;
5673 : public LayerTreeHostCommonTestBase
,
5674 public testing::TestWithParam
<LCDTextTestParam
> {
5676 virtual void SetUp() {
5677 can_use_lcd_text_
= std::tr1::get
<0>(GetParam());
5679 root_
= Layer::Create();
5680 child_
= Layer::Create();
5681 grand_child_
= Layer::Create();
5682 child_
->AddChild(grand_child_
.get());
5683 root_
->AddChild(child_
.get());
5685 gfx::Transform identity_matrix
;
5686 SetLayerPropertiesForTesting(root_
.get(),
5693 SetLayerPropertiesForTesting(child_
.get(),
5700 SetLayerPropertiesForTesting(grand_child_
.get(),
5708 child_
->SetForceRenderSurface(std::tr1::get
<1>(GetParam()));
5710 host_
= FakeLayerTreeHost::Create();
5711 host_
->SetRootLayer(root_
);
5714 bool can_use_lcd_text_
;
5715 scoped_ptr
<FakeLayerTreeHost
> host_
;
5716 scoped_refptr
<Layer
> root_
;
5717 scoped_refptr
<Layer
> child_
;
5718 scoped_refptr
<Layer
> grand_child_
;
5721 TEST_P(LCDTextTest
, CanUseLCDText
) {
5722 // Case 1: Identity transform.
5723 gfx::Transform identity_matrix
;
5724 ExecuteCalculateDrawProperties(
5725 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5726 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5727 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5728 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5730 // Case 2: Integral translation.
5731 gfx::Transform integral_translation
;
5732 integral_translation
.Translate(1.0, 2.0);
5733 child_
->SetTransform(integral_translation
);
5734 ExecuteCalculateDrawProperties(
5735 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5736 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5737 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5738 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5740 // Case 3: Non-integral translation.
5741 gfx::Transform non_integral_translation
;
5742 non_integral_translation
.Translate(1.5, 2.5);
5743 child_
->SetTransform(non_integral_translation
);
5744 ExecuteCalculateDrawProperties(
5745 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5746 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5747 EXPECT_FALSE(child_
->can_use_lcd_text());
5748 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5750 // Case 4: Rotation.
5751 gfx::Transform rotation
;
5752 rotation
.Rotate(10.0);
5753 child_
->SetTransform(rotation
);
5754 ExecuteCalculateDrawProperties(
5755 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5756 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5757 EXPECT_FALSE(child_
->can_use_lcd_text());
5758 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5761 gfx::Transform scale
;
5762 scale
.Scale(2.0, 2.0);
5763 child_
->SetTransform(scale
);
5764 ExecuteCalculateDrawProperties(
5765 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5766 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5767 EXPECT_FALSE(child_
->can_use_lcd_text());
5768 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5771 gfx::Transform skew
;
5773 child_
->SetTransform(skew
);
5774 ExecuteCalculateDrawProperties(
5775 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5776 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5777 EXPECT_FALSE(child_
->can_use_lcd_text());
5778 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5780 // Case 7: Translucent.
5781 child_
->SetTransform(identity_matrix
);
5782 child_
->SetOpacity(0.5f
);
5783 ExecuteCalculateDrawProperties(
5784 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5785 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5786 EXPECT_FALSE(child_
->can_use_lcd_text());
5787 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5789 // Case 8: Sanity check: restore transform and opacity.
5790 child_
->SetTransform(identity_matrix
);
5791 child_
->SetOpacity(1.f
);
5792 ExecuteCalculateDrawProperties(
5793 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5794 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5795 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5796 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5799 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimation
) {
5800 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
5801 ExecuteCalculateDrawProperties(
5802 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5803 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5804 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5805 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5807 // Add opacity animation.
5808 child_
->SetOpacity(0.9f
);
5809 AddOpacityTransitionToController(
5810 child_
->layer_animation_controller(), 10.0, 0.9f
, 0.1f
, false);
5812 ExecuteCalculateDrawProperties(
5813 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5814 // Text AA should not be adjusted while animation is active.
5815 // Make sure LCD text AA setting remains unchanged.
5816 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5817 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5818 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5821 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest
,
5823 testing::Combine(testing::Bool(), testing::Bool()));
5825 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayer
) {
5826 FakeImplProxy proxy
;
5827 TestSharedBitmapManager shared_bitmap_manager
;
5828 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5829 host_impl
.CreatePendingTree();
5830 const gfx::Transform identity_matrix
;
5832 scoped_refptr
<Layer
> root
= Layer::Create();
5833 SetLayerPropertiesForTesting(root
.get(),
5840 root
->SetIsDrawable(true);
5842 scoped_refptr
<Layer
> child
= Layer::Create();
5843 SetLayerPropertiesForTesting(child
.get(),
5850 child
->SetIsDrawable(true);
5852 scoped_refptr
<Layer
> grand_child
= Layer::Create();
5853 SetLayerPropertiesForTesting(grand_child
.get(),
5860 grand_child
->SetIsDrawable(true);
5861 grand_child
->SetHideLayerAndSubtree(true);
5863 child
->AddChild(grand_child
);
5864 root
->AddChild(child
);
5866 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5867 host
->SetRootLayer(root
);
5869 RenderSurfaceLayerList render_surface_layer_list
;
5870 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5871 root
.get(), root
->bounds(), &render_surface_layer_list
);
5872 inputs
.can_adjust_raster_scales
= true;
5873 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5875 // We should have one render surface and two layers. The grand child has
5877 ASSERT_EQ(1u, render_surface_layer_list
.size());
5878 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5879 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
5880 EXPECT_EQ(child
->id(), root
->render_surface()->layer_list().at(1)->id());
5883 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayerImpl
) {
5884 FakeImplProxy proxy
;
5885 TestSharedBitmapManager shared_bitmap_manager
;
5886 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5887 host_impl
.CreatePendingTree();
5888 const gfx::Transform identity_matrix
;
5890 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
5891 SetLayerPropertiesForTesting(root
.get(),
5898 root
->SetDrawsContent(true);
5900 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
5901 SetLayerPropertiesForTesting(child
.get(),
5908 child
->SetDrawsContent(true);
5910 scoped_ptr
<LayerImpl
> grand_child
=
5911 LayerImpl::Create(host_impl
.pending_tree(), 3);
5912 SetLayerPropertiesForTesting(grand_child
.get(),
5919 grand_child
->SetDrawsContent(true);
5920 grand_child
->SetHideLayerAndSubtree(true);
5922 child
->AddChild(grand_child
.Pass());
5923 root
->AddChild(child
.Pass());
5925 LayerImplList render_surface_layer_list
;
5926 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5927 root
.get(), root
->bounds(), &render_surface_layer_list
);
5928 inputs
.can_adjust_raster_scales
= true;
5929 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5931 // We should have one render surface and two layers. The grand child has
5933 ASSERT_EQ(1u, render_surface_layer_list
.size());
5934 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5935 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
5936 EXPECT_EQ(2, root
->render_surface()->layer_list().at(1)->id());
5939 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayers
) {
5940 FakeImplProxy proxy
;
5941 TestSharedBitmapManager shared_bitmap_manager
;
5942 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5943 host_impl
.CreatePendingTree();
5944 const gfx::Transform identity_matrix
;
5946 scoped_refptr
<Layer
> root
= Layer::Create();
5947 SetLayerPropertiesForTesting(root
.get(),
5954 root
->SetIsDrawable(true);
5956 scoped_refptr
<Layer
> child
= Layer::Create();
5957 SetLayerPropertiesForTesting(child
.get(),
5964 child
->SetIsDrawable(true);
5965 child
->SetHideLayerAndSubtree(true);
5967 scoped_refptr
<Layer
> grand_child
= Layer::Create();
5968 SetLayerPropertiesForTesting(grand_child
.get(),
5975 grand_child
->SetIsDrawable(true);
5977 child
->AddChild(grand_child
);
5978 root
->AddChild(child
);
5980 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5981 host
->SetRootLayer(root
);
5983 RenderSurfaceLayerList render_surface_layer_list
;
5984 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5985 root
.get(), root
->bounds(), &render_surface_layer_list
);
5986 inputs
.can_adjust_raster_scales
= true;
5987 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5989 // We should have one render surface and one layers. The child has
5990 // hidden itself and the grand child.
5991 ASSERT_EQ(1u, render_surface_layer_list
.size());
5992 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
5993 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
5996 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayersImpl
) {
5997 FakeImplProxy proxy
;
5998 TestSharedBitmapManager shared_bitmap_manager
;
5999 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6000 host_impl
.CreatePendingTree();
6001 const gfx::Transform identity_matrix
;
6003 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
6004 SetLayerPropertiesForTesting(root
.get(),
6011 root
->SetDrawsContent(true);
6013 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
6014 SetLayerPropertiesForTesting(child
.get(),
6021 child
->SetDrawsContent(true);
6022 child
->SetHideLayerAndSubtree(true);
6024 scoped_ptr
<LayerImpl
> grand_child
=
6025 LayerImpl::Create(host_impl
.pending_tree(), 3);
6026 SetLayerPropertiesForTesting(grand_child
.get(),
6033 grand_child
->SetDrawsContent(true);
6035 child
->AddChild(grand_child
.Pass());
6036 root
->AddChild(child
.Pass());
6038 LayerImplList render_surface_layer_list
;
6039 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6040 root
.get(), root
->bounds(), &render_surface_layer_list
);
6041 inputs
.can_adjust_raster_scales
= true;
6042 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6044 // We should have one render surface and one layers. The child has
6045 // hidden itself and the grand child.
6046 ASSERT_EQ(1u, render_surface_layer_list
.size());
6047 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
6048 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
6051 void EmptyCopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {}
6053 TEST_F(LayerTreeHostCommonTest
, SubtreeHiddenWithCopyRequest
) {
6054 FakeImplProxy proxy
;
6055 TestSharedBitmapManager shared_bitmap_manager
;
6056 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6057 host_impl
.CreatePendingTree();
6058 const gfx::Transform identity_matrix
;
6060 scoped_refptr
<Layer
> root
= Layer::Create();
6061 SetLayerPropertiesForTesting(root
.get(),
6068 root
->SetIsDrawable(true);
6070 scoped_refptr
<Layer
> copy_grand_parent
= Layer::Create();
6071 SetLayerPropertiesForTesting(copy_grand_parent
.get(),
6078 copy_grand_parent
->SetIsDrawable(true);
6080 scoped_refptr
<Layer
> copy_parent
= Layer::Create();
6081 SetLayerPropertiesForTesting(copy_parent
.get(),
6088 copy_parent
->SetIsDrawable(true);
6089 copy_parent
->SetForceRenderSurface(true);
6091 scoped_refptr
<Layer
> copy_layer
= Layer::Create();
6092 SetLayerPropertiesForTesting(copy_layer
.get(),
6099 copy_layer
->SetIsDrawable(true);
6101 scoped_refptr
<Layer
> copy_child
= Layer::Create();
6102 SetLayerPropertiesForTesting(copy_child
.get(),
6109 copy_child
->SetIsDrawable(true);
6111 scoped_refptr
<Layer
> copy_grand_parent_sibling_before
= Layer::Create();
6112 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before
.get(),
6119 copy_grand_parent_sibling_before
->SetIsDrawable(true);
6121 scoped_refptr
<Layer
> copy_grand_parent_sibling_after
= Layer::Create();
6122 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after
.get(),
6129 copy_grand_parent_sibling_after
->SetIsDrawable(true);
6131 copy_layer
->AddChild(copy_child
);
6132 copy_parent
->AddChild(copy_layer
);
6133 copy_grand_parent
->AddChild(copy_parent
);
6134 root
->AddChild(copy_grand_parent_sibling_before
);
6135 root
->AddChild(copy_grand_parent
);
6136 root
->AddChild(copy_grand_parent_sibling_after
);
6138 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6139 host
->SetRootLayer(root
);
6141 // Hide the copy_grand_parent and its subtree. But make a copy request in that
6142 // hidden subtree on copy_layer.
6143 copy_grand_parent
->SetHideLayerAndSubtree(true);
6144 copy_grand_parent_sibling_before
->SetHideLayerAndSubtree(true);
6145 copy_grand_parent_sibling_after
->SetHideLayerAndSubtree(true);
6146 copy_layer
->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6147 base::Bind(&EmptyCopyOutputCallback
)));
6148 EXPECT_TRUE(copy_layer
->HasCopyRequest());
6150 RenderSurfaceLayerList render_surface_layer_list
;
6151 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6152 root
.get(), root
->bounds(), &render_surface_layer_list
);
6153 inputs
.can_adjust_raster_scales
= true;
6154 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6156 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
6157 EXPECT_TRUE(copy_grand_parent
->draw_properties().
6158 layer_or_descendant_has_copy_request
);
6159 EXPECT_TRUE(copy_parent
->draw_properties().
6160 layer_or_descendant_has_copy_request
);
6161 EXPECT_TRUE(copy_layer
->draw_properties().
6162 layer_or_descendant_has_copy_request
);
6163 EXPECT_FALSE(copy_child
->draw_properties().
6164 layer_or_descendant_has_copy_request
);
6165 EXPECT_FALSE(copy_grand_parent_sibling_before
->draw_properties().
6166 layer_or_descendant_has_copy_request
);
6167 EXPECT_FALSE(copy_grand_parent_sibling_after
->draw_properties().
6168 layer_or_descendant_has_copy_request
);
6170 // We should have three render surfaces, one for the root, one for the parent
6171 // since it owns a surface, and one for the copy_layer.
6172 ASSERT_EQ(3u, render_surface_layer_list
.size());
6173 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
6174 EXPECT_EQ(copy_parent
->id(), render_surface_layer_list
.at(1)->id());
6175 EXPECT_EQ(copy_layer
->id(), render_surface_layer_list
.at(2)->id());
6177 // The root render surface should have 2 contributing layers. The
6178 // copy_grand_parent is hidden along with its siblings, but the copy_parent
6179 // will appear since something in its subtree needs to be drawn for a copy
6181 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
6182 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6183 EXPECT_EQ(copy_parent
->id(),
6184 root
->render_surface()->layer_list().at(1)->id());
6186 // Nothing actually draws into the copy parent, so only the copy_layer will
6187 // appear in its list, since it needs to be drawn for the copy request.
6188 ASSERT_EQ(1u, copy_parent
->render_surface()->layer_list().size());
6189 EXPECT_EQ(copy_layer
->id(),
6190 copy_parent
->render_surface()->layer_list().at(0)->id());
6192 // The copy_layer's render surface should have two contributing layers.
6193 ASSERT_EQ(2u, copy_layer
->render_surface()->layer_list().size());
6194 EXPECT_EQ(copy_layer
->id(),
6195 copy_layer
->render_surface()->layer_list().at(0)->id());
6196 EXPECT_EQ(copy_child
->id(),
6197 copy_layer
->render_surface()->layer_list().at(1)->id());
6200 TEST_F(LayerTreeHostCommonTest
, ClippedOutCopyRequest
) {
6201 FakeImplProxy proxy
;
6202 TestSharedBitmapManager shared_bitmap_manager
;
6203 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6204 host_impl
.CreatePendingTree();
6205 const gfx::Transform identity_matrix
;
6207 scoped_refptr
<Layer
> root
= Layer::Create();
6208 SetLayerPropertiesForTesting(root
.get(),
6215 root
->SetIsDrawable(true);
6217 scoped_refptr
<Layer
> copy_parent
= Layer::Create();
6218 SetLayerPropertiesForTesting(copy_parent
.get(),
6225 copy_parent
->SetIsDrawable(true);
6226 copy_parent
->SetMasksToBounds(true);
6228 scoped_refptr
<Layer
> copy_layer
= Layer::Create();
6229 SetLayerPropertiesForTesting(copy_layer
.get(),
6236 copy_layer
->SetIsDrawable(true);
6238 scoped_refptr
<Layer
> copy_child
= Layer::Create();
6239 SetLayerPropertiesForTesting(copy_child
.get(),
6246 copy_child
->SetIsDrawable(true);
6248 copy_layer
->AddChild(copy_child
);
6249 copy_parent
->AddChild(copy_layer
);
6250 root
->AddChild(copy_parent
);
6252 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6253 host
->SetRootLayer(root
);
6255 copy_layer
->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6256 base::Bind(&EmptyCopyOutputCallback
)));
6257 EXPECT_TRUE(copy_layer
->HasCopyRequest());
6259 RenderSurfaceLayerList render_surface_layer_list
;
6260 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6261 root
.get(), root
->bounds(), &render_surface_layer_list
);
6262 inputs
.can_adjust_raster_scales
= true;
6263 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6265 // We should have one render surface, as the others are clipped out.
6266 ASSERT_EQ(1u, render_surface_layer_list
.size());
6267 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
6269 // The root render surface should only have 1 contributing layer, since the
6270 // other layers are empty/clipped away.
6271 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
6272 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6275 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInsideSurface
) {
6276 FakeImplProxy proxy
;
6277 TestSharedBitmapManager shared_bitmap_manager
;
6278 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6279 host_impl
.CreatePendingTree();
6280 const gfx::Transform identity_matrix
;
6282 scoped_refptr
<Layer
> root
= Layer::Create();
6283 SetLayerPropertiesForTesting(root
.get(),
6290 root
->SetIsDrawable(true);
6292 // The surface is moved slightly outside of the viewport.
6293 scoped_refptr
<Layer
> surface
= Layer::Create();
6294 SetLayerPropertiesForTesting(surface
.get(),
6297 gfx::PointF(-10, -20),
6301 surface
->SetForceRenderSurface(true);
6303 scoped_refptr
<Layer
> surface_child
= Layer::Create();
6304 SetLayerPropertiesForTesting(surface_child
.get(),
6311 surface_child
->SetIsDrawable(true);
6313 surface
->AddChild(surface_child
);
6314 root
->AddChild(surface
);
6316 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6317 host
->SetRootLayer(root
);
6319 RenderSurfaceLayerList render_surface_layer_list
;
6320 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6321 root
.get(), root
->bounds(), &render_surface_layer_list
);
6322 inputs
.can_adjust_raster_scales
= true;
6323 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6325 // The visible_content_rect for the |surface_child| should not be clipped by
6327 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
6328 surface_child
->visible_content_rect().ToString());
6331 TEST_F(LayerTreeHostCommonTest
, TransformedClipParent
) {
6332 // Ensure that a transform between the layer and its render surface is not a
6333 // problem. Constructs the following layer tree.
6335 // root (a render surface)
6337 // + clip_parent (scaled)
6338 // + intervening_clipping_layer
6341 // The render surface should be resized correctly and the clip child should
6342 // inherit the right clip rect.
6343 scoped_refptr
<Layer
> root
= Layer::Create();
6344 scoped_refptr
<Layer
> render_surface
= Layer::Create();
6345 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6346 scoped_refptr
<Layer
> intervening
= Layer::Create();
6347 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6348 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6350 root
->AddChild(render_surface
);
6351 render_surface
->AddChild(clip_parent
);
6352 clip_parent
->AddChild(intervening
);
6353 intervening
->AddChild(clip_child
);
6355 clip_child
->SetClipParent(clip_parent
.get());
6357 intervening
->SetMasksToBounds(true);
6358 clip_parent
->SetMasksToBounds(true);
6360 render_surface
->SetForceRenderSurface(true);
6362 gfx::Transform scale_transform
;
6363 scale_transform
.Scale(2, 2);
6365 gfx::Transform identity_transform
;
6367 SetLayerPropertiesForTesting(root
.get(),
6374 SetLayerPropertiesForTesting(render_surface
.get(),
6381 SetLayerPropertiesForTesting(clip_parent
.get(),
6384 gfx::PointF(1.f
, 1.f
),
6388 SetLayerPropertiesForTesting(intervening
.get(),
6391 gfx::PointF(1.f
, 1.f
),
6395 SetLayerPropertiesForTesting(clip_child
.get(),
6398 gfx::PointF(1.f
, 1.f
),
6403 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6404 host
->SetRootLayer(root
);
6406 ExecuteCalculateDrawProperties(root
.get());
6408 ASSERT_TRUE(root
->render_surface());
6409 ASSERT_TRUE(render_surface
->render_surface());
6411 // Ensure that we've inherited our clip parent's clip and weren't affected
6412 // by the intervening clip layer.
6413 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
6414 clip_parent
->clip_rect().ToString());
6415 ASSERT_EQ(clip_parent
->clip_rect().ToString(),
6416 clip_child
->clip_rect().ToString());
6417 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
6418 intervening
->clip_rect().ToString());
6420 // Ensure that the render surface reports a content rect that has been grown
6421 // to accomodate for the clip child.
6422 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
6423 render_surface
->render_surface()->content_rect().ToString());
6425 // The above check implies the two below, but they nicely demonstrate that
6426 // we've grown, despite the intervening layer's clip.
6427 ASSERT_TRUE(clip_parent
->clip_rect().Contains(
6428 render_surface
->render_surface()->content_rect()));
6429 ASSERT_FALSE(intervening
->clip_rect().Contains(
6430 render_surface
->render_surface()->content_rect()));
6433 TEST_F(LayerTreeHostCommonTest
, ClipParentWithInterveningRenderSurface
) {
6434 // Ensure that intervening render surfaces are not a problem in the basic
6435 // case. In the following tree, both render surfaces should be resized to
6436 // accomodate for the clip child, despite an intervening clip.
6438 // root (a render surface)
6439 // + clip_parent (masks to bounds)
6440 // + render_surface1 (sets opacity)
6441 // + intervening (masks to bounds)
6442 // + render_surface2 (also sets opacity)
6445 scoped_refptr
<Layer
> root
= Layer::Create();
6446 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6447 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
6448 scoped_refptr
<Layer
> intervening
= Layer::Create();
6449 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
6450 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6451 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6453 root
->AddChild(clip_parent
);
6454 clip_parent
->AddChild(render_surface1
);
6455 render_surface1
->AddChild(intervening
);
6456 intervening
->AddChild(render_surface2
);
6457 render_surface2
->AddChild(clip_child
);
6459 clip_child
->SetClipParent(clip_parent
.get());
6461 intervening
->SetMasksToBounds(true);
6462 clip_parent
->SetMasksToBounds(true);
6464 render_surface1
->SetForceRenderSurface(true);
6465 render_surface2
->SetForceRenderSurface(true);
6467 gfx::Transform translation_transform
;
6468 translation_transform
.Translate(2, 2);
6470 gfx::Transform identity_transform
;
6471 SetLayerPropertiesForTesting(root
.get(),
6478 SetLayerPropertiesForTesting(clip_parent
.get(),
6479 translation_transform
,
6481 gfx::PointF(1.f
, 1.f
),
6485 SetLayerPropertiesForTesting(render_surface1
.get(),
6492 SetLayerPropertiesForTesting(intervening
.get(),
6495 gfx::PointF(1.f
, 1.f
),
6499 SetLayerPropertiesForTesting(render_surface2
.get(),
6506 SetLayerPropertiesForTesting(clip_child
.get(),
6509 gfx::PointF(-10.f
, -10.f
),
6514 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6515 host
->SetRootLayer(root
);
6517 ExecuteCalculateDrawProperties(root
.get());
6519 EXPECT_TRUE(root
->render_surface());
6520 EXPECT_TRUE(render_surface1
->render_surface());
6521 EXPECT_TRUE(render_surface2
->render_surface());
6523 // Since the render surfaces could have expanded, they should not clip (their
6524 // bounds would no longer be reliable). We should resort to layer clipping
6526 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6527 render_surface1
->render_surface()->clip_rect().ToString());
6528 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6529 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6530 render_surface2
->render_surface()->clip_rect().ToString());
6531 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
6533 // NB: clip rects are in target space.
6534 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6535 render_surface1
->clip_rect().ToString());
6536 EXPECT_TRUE(render_surface1
->is_clipped());
6538 // This value is inherited from the clipping ancestor layer, 'intervening'.
6539 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6540 render_surface2
->clip_rect().ToString());
6541 EXPECT_TRUE(render_surface2
->is_clipped());
6543 // The content rects of both render surfaces should both have expanded to
6544 // contain the clip child.
6545 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6546 render_surface1
->render_surface()->content_rect().ToString());
6547 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6548 render_surface2
->render_surface()->content_rect().ToString());
6550 // The clip child should have inherited the clip parent's clip (projected to
6551 // the right space, of course), and should have the correctly sized visible
6553 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6554 clip_child
->clip_rect().ToString());
6555 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
6556 clip_child
->visible_content_rect().ToString());
6557 EXPECT_TRUE(clip_child
->is_clipped());
6560 TEST_F(LayerTreeHostCommonTest
, ClipParentScrolledInterveningLayer
) {
6561 // Ensure that intervening render surfaces are not a problem, even if there
6562 // is a scroll involved. Note, we do _not_ have to consider any other sort
6565 // root (a render surface)
6566 // + clip_parent (masks to bounds)
6567 // + render_surface1 (sets opacity)
6568 // + intervening (masks to bounds AND scrolls)
6569 // + render_surface2 (also sets opacity)
6572 scoped_refptr
<Layer
> root
= Layer::Create();
6573 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6574 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
6575 scoped_refptr
<Layer
> intervening
= Layer::Create();
6576 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
6577 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6578 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6580 root
->AddChild(clip_parent
);
6581 clip_parent
->AddChild(render_surface1
);
6582 render_surface1
->AddChild(intervening
);
6583 intervening
->AddChild(render_surface2
);
6584 render_surface2
->AddChild(clip_child
);
6586 clip_child
->SetClipParent(clip_parent
.get());
6588 intervening
->SetMasksToBounds(true);
6589 clip_parent
->SetMasksToBounds(true);
6590 intervening
->SetScrollClipLayerId(clip_parent
->id());
6591 intervening
->SetScrollOffset(gfx::Vector2d(3, 3));
6593 render_surface1
->SetForceRenderSurface(true);
6594 render_surface2
->SetForceRenderSurface(true);
6596 gfx::Transform translation_transform
;
6597 translation_transform
.Translate(2, 2);
6599 gfx::Transform identity_transform
;
6600 SetLayerPropertiesForTesting(root
.get(),
6607 SetLayerPropertiesForTesting(clip_parent
.get(),
6608 translation_transform
,
6610 gfx::PointF(1.f
, 1.f
),
6614 SetLayerPropertiesForTesting(render_surface1
.get(),
6621 SetLayerPropertiesForTesting(intervening
.get(),
6624 gfx::PointF(1.f
, 1.f
),
6628 SetLayerPropertiesForTesting(render_surface2
.get(),
6635 SetLayerPropertiesForTesting(clip_child
.get(),
6638 gfx::PointF(-10.f
, -10.f
),
6643 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6644 host
->SetRootLayer(root
);
6646 ExecuteCalculateDrawProperties(root
.get());
6648 EXPECT_TRUE(root
->render_surface());
6649 EXPECT_TRUE(render_surface1
->render_surface());
6650 EXPECT_TRUE(render_surface2
->render_surface());
6652 // Since the render surfaces could have expanded, they should not clip (their
6653 // bounds would no longer be reliable). We should resort to layer clipping
6655 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6656 render_surface1
->render_surface()->clip_rect().ToString());
6657 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6658 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6659 render_surface2
->render_surface()->clip_rect().ToString());
6660 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
6662 // NB: clip rects are in target space.
6663 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6664 render_surface1
->clip_rect().ToString());
6665 EXPECT_TRUE(render_surface1
->is_clipped());
6667 // This value is inherited from the clipping ancestor layer, 'intervening'.
6668 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
6669 render_surface2
->clip_rect().ToString());
6670 EXPECT_TRUE(render_surface2
->is_clipped());
6672 // The content rects of both render surfaces should both have expanded to
6673 // contain the clip child.
6674 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6675 render_surface1
->render_surface()->content_rect().ToString());
6676 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6677 render_surface2
->render_surface()->content_rect().ToString());
6679 // The clip child should have inherited the clip parent's clip (projected to
6680 // the right space, of course), and should have the correctly sized visible
6682 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6683 clip_child
->clip_rect().ToString());
6684 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
6685 clip_child
->visible_content_rect().ToString());
6686 EXPECT_TRUE(clip_child
->is_clipped());
6689 TEST_F(LayerTreeHostCommonTest
, DescendantsOfClipChildren
) {
6690 // Ensures that descendants of the clip child inherit the correct clip.
6692 // root (a render surface)
6693 // + clip_parent (masks to bounds)
6694 // + intervening (masks to bounds)
6698 scoped_refptr
<Layer
> root
= Layer::Create();
6699 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6700 scoped_refptr
<Layer
> intervening
= Layer::Create();
6701 scoped_refptr
<Layer
> clip_child
= Layer::Create();
6702 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
6703 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6705 root
->AddChild(clip_parent
);
6706 clip_parent
->AddChild(intervening
);
6707 intervening
->AddChild(clip_child
);
6708 clip_child
->AddChild(child
);
6710 clip_child
->SetClipParent(clip_parent
.get());
6712 intervening
->SetMasksToBounds(true);
6713 clip_parent
->SetMasksToBounds(true);
6715 gfx::Transform identity_transform
;
6716 SetLayerPropertiesForTesting(root
.get(),
6723 SetLayerPropertiesForTesting(clip_parent
.get(),
6730 SetLayerPropertiesForTesting(intervening
.get(),
6737 SetLayerPropertiesForTesting(clip_child
.get(),
6744 SetLayerPropertiesForTesting(child
.get(),
6752 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6753 host
->SetRootLayer(root
);
6755 ExecuteCalculateDrawProperties(root
.get());
6757 EXPECT_TRUE(root
->render_surface());
6759 // Neither the clip child nor its descendant should have inherited the clip
6760 // from |intervening|.
6761 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6762 clip_child
->clip_rect().ToString());
6763 EXPECT_TRUE(clip_child
->is_clipped());
6764 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6765 child
->visible_content_rect().ToString());
6766 EXPECT_TRUE(child
->is_clipped());
6769 TEST_F(LayerTreeHostCommonTest
,
6770 SurfacesShouldBeUnaffectedByNonDescendantClipChildren
) {
6771 // Ensures that non-descendant clip children in the tree do not affect
6774 // root (a render surface)
6775 // + clip_parent (masks to bounds)
6776 // + render_surface1
6778 // + render_surface2
6781 // In this example render_surface2 should be unaffected by clip_child.
6782 scoped_refptr
<Layer
> root
= Layer::Create();
6783 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6784 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
6785 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6786 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6787 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
6788 scoped_refptr
<LayerWithForcedDrawsContent
> non_clip_child
=
6789 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6791 root
->AddChild(clip_parent
);
6792 clip_parent
->AddChild(render_surface1
);
6793 render_surface1
->AddChild(clip_child
);
6794 clip_parent
->AddChild(render_surface2
);
6795 render_surface2
->AddChild(non_clip_child
);
6797 clip_child
->SetClipParent(clip_parent
.get());
6799 clip_parent
->SetMasksToBounds(true);
6800 render_surface1
->SetMasksToBounds(true);
6802 gfx::Transform identity_transform
;
6803 SetLayerPropertiesForTesting(root
.get(),
6810 SetLayerPropertiesForTesting(clip_parent
.get(),
6817 SetLayerPropertiesForTesting(render_surface1
.get(),
6824 SetLayerPropertiesForTesting(render_surface2
.get(),
6831 SetLayerPropertiesForTesting(clip_child
.get(),
6838 SetLayerPropertiesForTesting(non_clip_child
.get(),
6846 render_surface1
->SetForceRenderSurface(true);
6847 render_surface2
->SetForceRenderSurface(true);
6849 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6850 host
->SetRootLayer(root
);
6852 ExecuteCalculateDrawProperties(root
.get());
6854 EXPECT_TRUE(root
->render_surface());
6855 EXPECT_TRUE(render_surface1
->render_surface());
6856 EXPECT_TRUE(render_surface2
->render_surface());
6858 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6859 render_surface1
->clip_rect().ToString());
6860 EXPECT_TRUE(render_surface1
->is_clipped());
6862 // The render surface should not clip (it has unclipped descendants), instead
6863 // it should rely on layer clipping.
6864 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6865 render_surface1
->render_surface()->clip_rect().ToString());
6866 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6868 // That said, it should have grown to accomodate the unclipped descendant.
6869 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
6870 render_surface1
->render_surface()->content_rect().ToString());
6872 // This render surface should clip. It has no unclipped descendants.
6873 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6874 render_surface2
->clip_rect().ToString());
6875 EXPECT_TRUE(render_surface2
->render_surface()->is_clipped());
6877 // It also shouldn't have grown to accomodate the clip child.
6878 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6879 render_surface2
->render_surface()->content_rect().ToString());
6881 // Sanity check our num_unclipped_descendants values.
6882 EXPECT_EQ(1, render_surface1
->num_unclipped_descendants());
6883 EXPECT_EQ(0, render_surface2
->num_unclipped_descendants());
6886 TEST_F(LayerTreeHostCommonTest
, CanRenderToSeparateSurface
) {
6887 FakeImplProxy proxy
;
6888 TestSharedBitmapManager shared_bitmap_manager
;
6889 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6890 scoped_ptr
<LayerImpl
> root
=
6891 LayerImpl::Create(host_impl
.active_tree(), 12345);
6892 scoped_ptr
<LayerImpl
> child1
=
6893 LayerImpl::Create(host_impl
.active_tree(), 123456);
6894 scoped_ptr
<LayerImpl
> child2
=
6895 LayerImpl::Create(host_impl
.active_tree(), 1234567);
6896 scoped_ptr
<LayerImpl
> child3
=
6897 LayerImpl::Create(host_impl
.active_tree(), 12345678);
6899 gfx::Transform identity_matrix
;
6900 gfx::Point3F transform_origin
;
6901 gfx::PointF position
;
6902 gfx::Size
bounds(100, 100);
6903 SetLayerPropertiesForTesting(root
.get(),
6910 root
->SetDrawsContent(true);
6912 // This layer structure normally forces render surface due to preserves3d
6914 SetLayerPropertiesForTesting(child1
.get(),
6921 child1
->SetDrawsContent(true);
6922 SetLayerPropertiesForTesting(child2
.get(),
6929 child2
->SetDrawsContent(true);
6930 SetLayerPropertiesForTesting(child3
.get(),
6937 child3
->SetDrawsContent(true);
6939 child2
->Set3dSortingContextId(1);
6940 child3
->Set3dSortingContextId(1);
6942 child2
->AddChild(child3
.Pass());
6943 child1
->AddChild(child2
.Pass());
6944 root
->AddChild(child1
.Pass());
6947 LayerImplList render_surface_layer_list
;
6948 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6949 root
.get(), root
->bounds(), &render_surface_layer_list
);
6950 inputs
.can_render_to_separate_surface
= true;
6951 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6953 EXPECT_EQ(2u, render_surface_layer_list
.size());
6957 LayerImplList render_surface_layer_list
;
6958 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6959 root
.get(), root
->bounds(), &render_surface_layer_list
);
6960 inputs
.can_render_to_separate_surface
= false;
6961 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6963 EXPECT_EQ(1u, render_surface_layer_list
.size());
6967 TEST_F(LayerTreeHostCommonTest
, DoNotIncludeBackfaceInvisibleSurfaces
) {
6968 scoped_refptr
<Layer
> root
= Layer::Create();
6969 scoped_refptr
<Layer
> render_surface
= Layer::Create();
6970 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
6971 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6973 root
->AddChild(render_surface
);
6974 render_surface
->AddChild(child
);
6976 gfx::Transform identity_transform
;
6977 SetLayerPropertiesForTesting(root
.get(),
6984 SetLayerPropertiesForTesting(render_surface
.get(),
6991 SetLayerPropertiesForTesting(child
.get(),
6999 root
->SetShouldFlattenTransform(false);
7000 root
->Set3dSortingContextId(1);
7001 render_surface
->SetDoubleSided(false);
7002 render_surface
->SetForceRenderSurface(true);
7004 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
7005 host
->SetRootLayer(root
);
7007 ExecuteCalculateDrawProperties(root
.get());
7009 EXPECT_EQ(2u, render_surface_layer_list()->size());
7011 render_surface_layer_list()->at(0)
7012 ->render_surface()->layer_list().size());
7014 render_surface_layer_list()->at(1)
7015 ->render_surface()->layer_list().size());
7017 gfx::Transform rotation_transform
= identity_transform
;
7018 rotation_transform
.RotateAboutXAxis(180.0);
7020 render_surface
->SetTransform(rotation_transform
);
7022 ExecuteCalculateDrawProperties(root
.get());
7024 EXPECT_EQ(1u, render_surface_layer_list()->size());
7026 render_surface_layer_list()->at(0)
7027 ->render_surface()->layer_list().size());
7030 TEST_F(LayerTreeHostCommonTest
, ClippedByScrollParent
) {
7031 // Checks that the simple case (being clipped by a scroll parent that would
7032 // have been processed before you anyhow) results in the right clips.
7035 // + scroll_parent_border
7036 // | + scroll_parent_clip
7037 // | + scroll_parent
7040 scoped_refptr
<Layer
> root
= Layer::Create();
7041 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7042 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7043 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7044 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7045 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7046 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7048 root
->AddChild(scroll_child
);
7050 root
->AddChild(scroll_parent_border
);
7051 scroll_parent_border
->AddChild(scroll_parent_clip
);
7052 scroll_parent_clip
->AddChild(scroll_parent
);
7054 scroll_parent_clip
->SetMasksToBounds(true);
7056 scroll_child
->SetScrollParent(scroll_parent
.get());
7058 gfx::Transform identity_transform
;
7059 SetLayerPropertiesForTesting(root
.get(),
7066 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7073 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7080 SetLayerPropertiesForTesting(scroll_parent
.get(),
7087 SetLayerPropertiesForTesting(scroll_child
.get(),
7095 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
7096 host
->SetRootLayer(root
);
7098 ExecuteCalculateDrawProperties(root
.get());
7100 EXPECT_TRUE(root
->render_surface());
7102 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7103 scroll_child
->clip_rect().ToString());
7104 EXPECT_TRUE(scroll_child
->is_clipped());
7107 TEST_F(LayerTreeHostCommonTest
, SingularTransformSubtreesDoNotDraw
) {
7108 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
7109 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7110 scoped_refptr
<LayerWithForcedDrawsContent
> parent
=
7111 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7112 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7113 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7115 root
->AddChild(parent
);
7116 parent
->AddChild(child
);
7118 gfx::Transform identity_transform
;
7119 SetLayerPropertiesForTesting(root
.get(),
7126 root
->SetForceRenderSurface(true);
7127 SetLayerPropertiesForTesting(parent
.get(),
7134 parent
->SetForceRenderSurface(true);
7135 SetLayerPropertiesForTesting(child
.get(),
7142 child
->SetForceRenderSurface(true);
7144 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
7145 host
->SetRootLayer(root
);
7147 ExecuteCalculateDrawProperties(root
.get());
7149 EXPECT_EQ(3u, render_surface_layer_list()->size());
7151 gfx::Transform singular_transform
;
7152 singular_transform
.Scale3d(
7153 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
7155 child
->SetTransform(singular_transform
);
7157 ExecuteCalculateDrawProperties(root
.get());
7159 EXPECT_EQ(2u, render_surface_layer_list()->size());
7161 // Ensure that the entire subtree under a layer with singular transform does
7162 // not get rendered.
7163 parent
->SetTransform(singular_transform
);
7164 child
->SetTransform(identity_transform
);
7166 ExecuteCalculateDrawProperties(root
.get());
7168 EXPECT_EQ(1u, render_surface_layer_list()->size());
7171 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollParent
) {
7172 // Checks that clipping by a scroll parent that follows you in paint order
7173 // still results in correct clipping.
7177 // + scroll_parent_border
7178 // + scroll_parent_clip
7181 scoped_refptr
<Layer
> root
= Layer::Create();
7182 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7183 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7184 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7185 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7186 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7187 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7189 root
->AddChild(scroll_parent_border
);
7190 scroll_parent_border
->AddChild(scroll_parent_clip
);
7191 scroll_parent_clip
->AddChild(scroll_parent
);
7193 root
->AddChild(scroll_child
);
7195 scroll_parent_clip
->SetMasksToBounds(true);
7197 scroll_child
->SetScrollParent(scroll_parent
.get());
7199 gfx::Transform identity_transform
;
7200 SetLayerPropertiesForTesting(root
.get(),
7207 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7214 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7221 SetLayerPropertiesForTesting(scroll_parent
.get(),
7228 SetLayerPropertiesForTesting(scroll_child
.get(),
7236 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
7237 host
->SetRootLayer(root
);
7239 ExecuteCalculateDrawProperties(root
.get());
7241 EXPECT_TRUE(root
->render_surface());
7243 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7244 scroll_child
->clip_rect().ToString());
7245 EXPECT_TRUE(scroll_child
->is_clipped());
7248 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollGrandparent
) {
7249 // Checks that clipping by a scroll parent and scroll grandparent that follow
7250 // you in paint order still results in correct clipping.
7254 // + scroll_parent_border
7255 // | + scroll_parent_clip
7256 // | + scroll_parent
7257 // + scroll_grandparent_border
7258 // + scroll_grandparent_clip
7259 // + scroll_grandparent
7261 scoped_refptr
<Layer
> root
= Layer::Create();
7262 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7263 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7264 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7265 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7267 scoped_refptr
<Layer
> scroll_grandparent_border
= Layer::Create();
7268 scoped_refptr
<Layer
> scroll_grandparent_clip
= Layer::Create();
7269 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_grandparent
=
7270 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7272 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7273 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7275 root
->AddChild(scroll_child
);
7277 root
->AddChild(scroll_parent_border
);
7278 scroll_parent_border
->AddChild(scroll_parent_clip
);
7279 scroll_parent_clip
->AddChild(scroll_parent
);
7281 root
->AddChild(scroll_grandparent_border
);
7282 scroll_grandparent_border
->AddChild(scroll_grandparent_clip
);
7283 scroll_grandparent_clip
->AddChild(scroll_grandparent
);
7285 scroll_parent_clip
->SetMasksToBounds(true);
7286 scroll_grandparent_clip
->SetMasksToBounds(true);
7288 scroll_child
->SetScrollParent(scroll_parent
.get());
7289 scroll_parent_border
->SetScrollParent(scroll_grandparent
.get());
7291 gfx::Transform identity_transform
;
7292 SetLayerPropertiesForTesting(root
.get(),
7299 SetLayerPropertiesForTesting(scroll_grandparent_border
.get(),
7306 SetLayerPropertiesForTesting(scroll_grandparent_clip
.get(),
7313 SetLayerPropertiesForTesting(scroll_grandparent
.get(),
7320 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7327 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7334 SetLayerPropertiesForTesting(scroll_parent
.get(),
7341 SetLayerPropertiesForTesting(scroll_child
.get(),
7349 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
7350 host
->SetRootLayer(root
);
7352 ExecuteCalculateDrawProperties(root
.get());
7354 EXPECT_TRUE(root
->render_surface());
7356 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7357 scroll_child
->clip_rect().ToString());
7358 EXPECT_TRUE(scroll_child
->is_clipped());
7360 // Despite the fact that we visited the above layers out of order to get the
7361 // correct clip, the layer lists should be unaffected.
7362 EXPECT_EQ(3u, root
->render_surface()->layer_list().size());
7363 EXPECT_EQ(scroll_child
.get(),
7364 root
->render_surface()->layer_list().at(0));
7365 EXPECT_EQ(scroll_parent
.get(),
7366 root
->render_surface()->layer_list().at(1));
7367 EXPECT_EQ(scroll_grandparent
.get(),
7368 root
->render_surface()->layer_list().at(2));
7371 TEST_F(LayerTreeHostCommonTest
, OutOfOrderClippingRequiresRSLLSorting
) {
7372 // Ensures that even if we visit layers out of order, we still produce a
7373 // correctly ordered render surface layer list.
7376 // + scroll_parent_border
7377 // + scroll_parent_clip
7379 // + render_surface1
7380 // + scroll_grandparent_border
7381 // + scroll_grandparent_clip
7382 // + scroll_grandparent
7383 // + render_surface2
7385 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
7386 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7388 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7389 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7390 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7391 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7392 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface1
=
7393 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7395 scoped_refptr
<Layer
> scroll_grandparent_border
= Layer::Create();
7396 scoped_refptr
<Layer
> scroll_grandparent_clip
= Layer::Create();
7397 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_grandparent
=
7398 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7399 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface2
=
7400 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7402 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7403 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7405 root
->AddChild(scroll_child
);
7407 root
->AddChild(scroll_parent_border
);
7408 scroll_parent_border
->AddChild(scroll_parent_clip
);
7409 scroll_parent_clip
->AddChild(scroll_parent
);
7410 scroll_parent
->AddChild(render_surface2
);
7412 root
->AddChild(scroll_grandparent_border
);
7413 scroll_grandparent_border
->AddChild(scroll_grandparent_clip
);
7414 scroll_grandparent_clip
->AddChild(scroll_grandparent
);
7415 scroll_grandparent
->AddChild(render_surface1
);
7417 scroll_parent_clip
->SetMasksToBounds(true);
7418 scroll_grandparent_clip
->SetMasksToBounds(true);
7420 scroll_child
->SetScrollParent(scroll_parent
.get());
7421 scroll_parent_border
->SetScrollParent(scroll_grandparent
.get());
7423 render_surface1
->SetForceRenderSurface(true);
7424 render_surface2
->SetForceRenderSurface(true);
7426 gfx::Transform identity_transform
;
7427 SetLayerPropertiesForTesting(root
.get(),
7434 SetLayerPropertiesForTesting(scroll_grandparent_border
.get(),
7441 SetLayerPropertiesForTesting(scroll_grandparent_clip
.get(),
7448 SetLayerPropertiesForTesting(scroll_grandparent
.get(),
7455 SetLayerPropertiesForTesting(render_surface1
.get(),
7462 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7469 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7476 SetLayerPropertiesForTesting(scroll_parent
.get(),
7483 SetLayerPropertiesForTesting(render_surface2
.get(),
7490 SetLayerPropertiesForTesting(scroll_child
.get(),
7498 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
7499 host
->SetRootLayer(root
);
7501 RenderSurfaceLayerList render_surface_layer_list
;
7502 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
7506 &render_surface_layer_list
);
7508 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7510 EXPECT_TRUE(root
->render_surface());
7512 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7513 scroll_child
->clip_rect().ToString());
7514 EXPECT_TRUE(scroll_child
->is_clipped());
7516 // Despite the fact that we had to process the layers out of order to get the
7517 // right clip, our render_surface_layer_list's order should be unaffected.
7518 EXPECT_EQ(3u, render_surface_layer_list
.size());
7519 EXPECT_EQ(root
.get(), render_surface_layer_list
.at(0));
7520 EXPECT_EQ(render_surface2
.get(), render_surface_layer_list
.at(1));
7521 EXPECT_EQ(render_surface1
.get(), render_surface_layer_list
.at(2));
7522 EXPECT_TRUE(render_surface_layer_list
.at(0)->render_surface());
7523 EXPECT_TRUE(render_surface_layer_list
.at(1)->render_surface());
7524 EXPECT_TRUE(render_surface_layer_list
.at(2)->render_surface());
7527 TEST_F(LayerTreeHostCommonTest
, DoNotClobberSorting
) {
7528 // We rearrange layer list contributions if we have to visit children out of
7529 // order, but it should be a 'stable' rearrangement. That is, the layer list
7530 // additions for a single layer should not be reordered, though their position
7531 // wrt to the contributions due to a sibling may vary.
7537 // + scroll_parent_border
7538 // + scroll_parent_clip
7541 FakeImplProxy proxy
;
7542 TestSharedBitmapManager shared_bitmap_manager
;
7543 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7544 host_impl
.CreatePendingTree();
7545 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7546 scoped_ptr
<LayerImpl
> scroll_parent_border
=
7547 LayerImpl::Create(host_impl
.active_tree(), 2);
7548 scoped_ptr
<LayerImpl
> scroll_parent_clip
=
7549 LayerImpl::Create(host_impl
.active_tree(), 3);
7550 scoped_ptr
<LayerImpl
> scroll_parent
=
7551 LayerImpl::Create(host_impl
.active_tree(), 4);
7552 scoped_ptr
<LayerImpl
> scroll_child
=
7553 LayerImpl::Create(host_impl
.active_tree(), 5);
7554 scoped_ptr
<LayerImpl
> bottom_content
=
7555 LayerImpl::Create(host_impl
.active_tree(), 6);
7556 scoped_ptr
<LayerImpl
> top_content
=
7557 LayerImpl::Create(host_impl
.active_tree(), 7);
7559 scroll_parent_clip
->SetMasksToBounds(true);
7561 scroll_child
->SetScrollParent(scroll_parent
.get());
7562 scoped_ptr
<std::set
<LayerImpl
*> > scroll_children(new std::set
<LayerImpl
*>);
7563 scroll_children
->insert(scroll_child
.get());
7564 scroll_parent
->SetScrollChildren(scroll_children
.release());
7566 scroll_child
->SetDrawsContent(true);
7567 scroll_parent
->SetDrawsContent(true);
7568 top_content
->SetDrawsContent(true);
7569 bottom_content
->SetDrawsContent(true);
7571 gfx::Transform identity_transform
;
7572 gfx::Transform top_transform
;
7573 top_transform
.Translate3d(0.0, 0.0, 5.0);
7574 gfx::Transform bottom_transform
;
7575 bottom_transform
.Translate3d(0.0, 0.0, 3.0);
7577 SetLayerPropertiesForTesting(root
.get(),
7584 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7591 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7598 SetLayerPropertiesForTesting(scroll_parent
.get(),
7605 SetLayerPropertiesForTesting(scroll_child
.get(),
7612 SetLayerPropertiesForTesting(top_content
.get(),
7619 SetLayerPropertiesForTesting(bottom_content
.get(),
7627 scroll_child
->SetShouldFlattenTransform(false);
7628 scroll_child
->Set3dSortingContextId(1);
7630 scroll_child
->AddChild(top_content
.Pass());
7631 scroll_child
->AddChild(bottom_content
.Pass());
7632 root
->AddChild(scroll_child
.Pass());
7634 scroll_parent_clip
->AddChild(scroll_parent
.Pass());
7635 scroll_parent_border
->AddChild(scroll_parent_clip
.Pass());
7636 root
->AddChild(scroll_parent_border
.Pass());
7638 LayerImplList render_surface_layer_list
;
7639 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7640 root
.get(), root
->bounds(), &render_surface_layer_list
);
7642 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7644 EXPECT_TRUE(root
->render_surface());
7646 // If we don't sort by depth and let the layers get added in the order they
7647 // would normally be visited in, then layers 6 and 7 will be out of order. In
7648 // other words, although we've had to shift 5, 6, and 7 to appear before 4
7649 // in the list (because of the scroll parent relationship), this should not
7650 // have an effect on the the order of 5, 6, and 7 (which had been reordered
7651 // due to layer sorting).
7652 EXPECT_EQ(4u, root
->render_surface()->layer_list().size());
7653 EXPECT_EQ(5, root
->render_surface()->layer_list().at(0)->id());
7654 EXPECT_EQ(6, root
->render_surface()->layer_list().at(1)->id());
7655 EXPECT_EQ(7, root
->render_surface()->layer_list().at(2)->id());
7656 EXPECT_EQ(4, root
->render_surface()->layer_list().at(3)->id());
7659 TEST_F(LayerTreeHostCommonTest
, ScrollCompensationWithRounding
) {
7660 // This test verifies that a scrolling layer that gets snapped to
7661 // integer coordinates doesn't move a fixed position child.
7668 FakeImplProxy proxy
;
7669 TestSharedBitmapManager shared_bitmap_manager
;
7670 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7671 host_impl
.CreatePendingTree();
7672 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7673 scoped_ptr
<LayerImpl
> container
=
7674 LayerImpl::Create(host_impl
.active_tree(), 2);
7675 LayerImpl
* container_layer
= container
.get();
7676 scoped_ptr
<LayerImpl
> scroller
=
7677 LayerImpl::Create(host_impl
.active_tree(), 3);
7678 LayerImpl
* scroll_layer
= scroller
.get();
7679 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
7680 LayerImpl
* fixed_layer
= fixed
.get();
7682 container
->SetIsContainerForFixedPositionLayers(true);
7684 LayerPositionConstraint constraint
;
7685 constraint
.set_is_fixed_position(true);
7686 fixed
->SetPositionConstraint(constraint
);
7688 scroller
->SetScrollClipLayer(container
->id());
7690 gfx::Transform identity_transform
;
7691 gfx::Transform container_transform
;
7692 container_transform
.Translate3d(10.0, 20.0, 0.0);
7693 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
7695 SetLayerPropertiesForTesting(root
.get(),
7702 SetLayerPropertiesForTesting(container
.get(),
7703 container_transform
,
7709 SetLayerPropertiesForTesting(scroller
.get(),
7716 SetLayerPropertiesForTesting(fixed
.get(),
7724 scroller
->AddChild(fixed
.Pass());
7725 container
->AddChild(scroller
.Pass());
7726 root
->AddChild(container
.Pass());
7728 // Rounded to integers already.
7730 gfx::Vector2dF
scroll_delta(3.0, 5.0);
7731 scroll_layer
->SetScrollDelta(scroll_delta
);
7733 LayerImplList render_surface_layer_list
;
7734 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7735 root
.get(), root
->bounds(), &render_surface_layer_list
);
7736 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7738 EXPECT_TRANSFORMATION_MATRIX_EQ(
7739 container_layer
->draw_properties().screen_space_transform
,
7740 fixed_layer
->draw_properties().screen_space_transform
);
7742 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7744 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
7745 .screen_space_transform
.To2dTranslation(),
7746 container_offset
- scroll_delta
);
7749 // Scroll delta requiring rounding.
7751 gfx::Vector2dF
scroll_delta(4.1f
, 8.1f
);
7752 scroll_layer
->SetScrollDelta(scroll_delta
);
7754 gfx::Vector2dF
rounded_scroll_delta(4.f
, 8.f
);
7756 LayerImplList render_surface_layer_list
;
7757 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7758 root
.get(), root
->bounds(), &render_surface_layer_list
);
7759 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7761 EXPECT_TRANSFORMATION_MATRIX_EQ(
7762 container_layer
->draw_properties().screen_space_transform
,
7763 fixed_layer
->draw_properties().screen_space_transform
);
7765 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7767 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
7768 .screen_space_transform
.To2dTranslation(),
7769 container_offset
- rounded_scroll_delta
);
7772 // Scale is applied earlier in the tree.
7774 gfx::Transform scaled_container_transform
= container_transform
;
7775 scaled_container_transform
.Scale3d(3.0, 3.0, 1.0);
7776 container_layer
->SetTransform(scaled_container_transform
);
7778 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
7779 scroll_layer
->SetScrollDelta(scroll_delta
);
7781 LayerImplList render_surface_layer_list
;
7782 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7783 root
.get(), root
->bounds(), &render_surface_layer_list
);
7784 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7786 EXPECT_TRANSFORMATION_MATRIX_EQ(
7787 container_layer
->draw_properties().screen_space_transform
,
7788 fixed_layer
->draw_properties().screen_space_transform
);
7790 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7793 container_layer
->SetTransform(container_transform
);
7796 // Scale is applied on the scroll layer itself.
7798 gfx::Transform scale_transform
;
7799 scale_transform
.Scale3d(3.0, 3.0, 1.0);
7800 scroll_layer
->SetTransform(scale_transform
);
7802 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
7803 scroll_layer
->SetScrollDelta(scroll_delta
);
7805 LayerImplList render_surface_layer_list
;
7806 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7807 root
.get(), root
->bounds(), &render_surface_layer_list
);
7808 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7811 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7814 scroll_layer
->SetTransform(identity_transform
);
7818 class AnimationScaleFactorTrackingLayerImpl
: public LayerImpl
{
7820 static scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> Create(
7821 LayerTreeImpl
* tree_impl
,
7823 return make_scoped_ptr(
7824 new AnimationScaleFactorTrackingLayerImpl(tree_impl
, id
));
7827 virtual ~AnimationScaleFactorTrackingLayerImpl() {}
7830 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl
* tree_impl
,
7832 : LayerImpl(tree_impl
, id
) {
7833 SetDrawsContent(true);
7837 TEST_F(LayerTreeHostCommonTest
, MaximumAnimationScaleFactor
) {
7838 FakeImplProxy proxy
;
7839 TestSharedBitmapManager shared_bitmap_manager
;
7840 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7841 gfx::Transform identity_matrix
;
7842 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_parent
=
7843 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 1);
7844 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> parent
=
7845 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 2);
7846 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> child
=
7847 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 3);
7848 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_child
=
7849 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 4);
7851 AnimationScaleFactorTrackingLayerImpl
* parent_raw
= parent
.get();
7852 AnimationScaleFactorTrackingLayerImpl
* child_raw
= child
.get();
7853 AnimationScaleFactorTrackingLayerImpl
* grand_child_raw
= grand_child
.get();
7855 child
->AddChild(grand_child
.PassAs
<LayerImpl
>());
7856 parent
->AddChild(child
.PassAs
<LayerImpl
>());
7857 grand_parent
->AddChild(parent
.PassAs
<LayerImpl
>());
7859 SetLayerPropertiesForTesting(grand_parent
.get(),
7866 SetLayerPropertiesForTesting(parent_raw
,
7873 SetLayerPropertiesForTesting(child_raw
,
7880 SetLayerPropertiesForTesting(grand_child_raw
,
7888 ExecuteCalculateDrawProperties(grand_parent
.get());
7890 // No layers have animations.
7892 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7894 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7895 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7897 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7899 TransformOperations translation
;
7900 translation
.AppendTranslate(1.f
, 2.f
, 3.f
);
7902 AddAnimatedTransformToLayer(
7903 parent_raw
, 1.0, TransformOperations(), translation
);
7905 // No layers have scale-affecting animations.
7907 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7909 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7910 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7912 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7914 TransformOperations scale
;
7915 scale
.AppendScale(5.f
, 4.f
, 3.f
);
7917 AddAnimatedTransformToLayer(child_raw
, 1.0, TransformOperations(), scale
);
7918 ExecuteCalculateDrawProperties(grand_parent
.get());
7920 // Only |child| has a scale-affecting animation.
7922 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7924 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7925 EXPECT_EQ(5.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7927 5.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7929 AddAnimatedTransformToLayer(
7930 grand_parent
.get(), 1.0, TransformOperations(), scale
);
7931 ExecuteCalculateDrawProperties(grand_parent
.get());
7933 // |grand_parent| and |child| have scale-affecting animations.
7935 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7937 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7938 // We don't support combining animated scales from two nodes; 0.f means
7939 // that the maximum scale could not be computed.
7940 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7942 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7944 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
7945 ExecuteCalculateDrawProperties(grand_parent
.get());
7947 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
7949 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7951 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7952 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7954 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7956 grand_parent
->layer_animation_controller()->AbortAnimations(
7957 Animation::Transform
);
7958 parent_raw
->layer_animation_controller()->AbortAnimations(
7959 Animation::Transform
);
7960 child_raw
->layer_animation_controller()->AbortAnimations(
7961 Animation::Transform
);
7963 TransformOperations perspective
;
7964 perspective
.AppendPerspective(10.f
);
7966 AddAnimatedTransformToLayer(
7967 child_raw
, 1.0, TransformOperations(), perspective
);
7968 ExecuteCalculateDrawProperties(grand_parent
.get());
7970 // |child| has a scale-affecting animation but computing the maximum of this
7971 // animation is not supported.
7973 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7975 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7976 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7978 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7980 child_raw
->layer_animation_controller()->AbortAnimations(
7981 Animation::Transform
);
7983 gfx::Transform scale_matrix
;
7984 scale_matrix
.Scale(1.f
, 2.f
);
7985 grand_parent
->SetTransform(scale_matrix
);
7986 parent_raw
->SetTransform(scale_matrix
);
7987 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
7988 ExecuteCalculateDrawProperties(grand_parent
.get());
7990 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
7991 // animation with maximum scale 5.f.
7993 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7995 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7997 child_raw
->draw_properties().maximum_animation_contents_scale
);
8000 grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8002 gfx::Transform perspective_matrix
;
8003 perspective_matrix
.ApplyPerspectiveDepth(2.f
);
8004 child_raw
->SetTransform(perspective_matrix
);
8005 ExecuteCalculateDrawProperties(grand_parent
.get());
8007 // |child| has a transform that's neither a translation nor a scale.
8009 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8011 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8012 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8014 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8016 parent_raw
->SetTransform(perspective_matrix
);
8017 ExecuteCalculateDrawProperties(grand_parent
.get());
8019 // |parent| and |child| have transforms that are neither translations nor
8022 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8024 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8025 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8027 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8029 parent_raw
->SetTransform(identity_matrix
);
8030 child_raw
->SetTransform(identity_matrix
);
8031 grand_parent
->SetTransform(perspective_matrix
);
8033 ExecuteCalculateDrawProperties(grand_parent
.get());
8035 // |grand_parent| has a transform that's neither a translation nor a scale.
8037 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8039 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8040 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8042 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8045 static int membership_id(LayerImpl
* layer
) {
8046 return layer
->draw_properties().last_drawn_render_surface_layer_list_id
;
8049 static void GatherDrawnLayers(LayerImplList
* rsll
,
8050 std::set
<LayerImpl
*>* drawn_layers
) {
8051 for (LayerIterator
<LayerImpl
> it
= LayerIterator
<LayerImpl
>::Begin(rsll
),
8052 end
= LayerIterator
<LayerImpl
>::End(rsll
);
8055 LayerImpl
* layer
= *it
;
8056 if (it
.represents_itself())
8057 drawn_layers
->insert(layer
);
8059 if (!it
.represents_contributing_render_surface())
8062 if (layer
->mask_layer())
8063 drawn_layers
->insert(layer
->mask_layer());
8064 if (layer
->replica_layer() && layer
->replica_layer()->mask_layer())
8065 drawn_layers
->insert(layer
->replica_layer()->mask_layer());
8069 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceLayerListMembership
) {
8070 FakeImplProxy proxy
;
8071 TestSharedBitmapManager shared_bitmap_manager
;
8072 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
8073 gfx::Transform identity_matrix
;
8075 scoped_ptr
<LayerImpl
> grand_parent
=
8076 LayerImpl::Create(host_impl
.active_tree(), 1);
8077 scoped_ptr
<LayerImpl
> parent
= LayerImpl::Create(host_impl
.active_tree(), 3);
8078 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 5);
8079 scoped_ptr
<LayerImpl
> grand_child1
=
8080 LayerImpl::Create(host_impl
.active_tree(), 7);
8081 scoped_ptr
<LayerImpl
> grand_child2
=
8082 LayerImpl::Create(host_impl
.active_tree(), 9);
8084 LayerImpl
* grand_parent_raw
= grand_parent
.get();
8085 LayerImpl
* parent_raw
= parent
.get();
8086 LayerImpl
* child_raw
= child
.get();
8087 LayerImpl
* grand_child1_raw
= grand_child1
.get();
8088 LayerImpl
* grand_child2_raw
= grand_child2
.get();
8090 child
->AddChild(grand_child1
.Pass());
8091 child
->AddChild(grand_child2
.Pass());
8092 parent
->AddChild(child
.Pass());
8093 grand_parent
->AddChild(parent
.Pass());
8095 SetLayerPropertiesForTesting(grand_parent_raw
,
8102 SetLayerPropertiesForTesting(parent_raw
,
8109 SetLayerPropertiesForTesting(child_raw
,
8116 SetLayerPropertiesForTesting(grand_child1_raw
,
8123 SetLayerPropertiesForTesting(grand_child2_raw
,
8131 // Start with nothing being drawn.
8132 ExecuteCalculateDrawProperties(grand_parent_raw
);
8133 int member_id
= render_surface_layer_list_count();
8135 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8136 EXPECT_NE(member_id
, membership_id(parent_raw
));
8137 EXPECT_NE(member_id
, membership_id(child_raw
));
8138 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8139 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8141 std::set
<LayerImpl
*> expected
;
8142 std::set
<LayerImpl
*> actual
;
8143 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8144 EXPECT_EQ(expected
, actual
);
8146 // If we force render surface, but none of the layers are in the layer list,
8147 // then this layer should not appear in RSLL.
8148 grand_child1_raw
->SetForceRenderSurface(true);
8150 ExecuteCalculateDrawProperties(grand_parent_raw
);
8151 member_id
= render_surface_layer_list_count();
8153 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8154 EXPECT_NE(member_id
, membership_id(parent_raw
));
8155 EXPECT_NE(member_id
, membership_id(child_raw
));
8156 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8157 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8161 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8162 EXPECT_EQ(expected
, actual
);
8164 // However, if we say that this layer also draws content, it will appear in
8166 grand_child1_raw
->SetDrawsContent(true);
8168 ExecuteCalculateDrawProperties(grand_parent_raw
);
8169 member_id
= render_surface_layer_list_count();
8171 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8172 EXPECT_NE(member_id
, membership_id(parent_raw
));
8173 EXPECT_NE(member_id
, membership_id(child_raw
));
8174 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
8175 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8178 expected
.insert(grand_child1_raw
);
8181 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8182 EXPECT_EQ(expected
, actual
);
8184 // Now child is forced to have a render surface, and one if its children draws
8186 grand_child1_raw
->SetDrawsContent(false);
8187 grand_child1_raw
->SetForceRenderSurface(false);
8188 child_raw
->SetForceRenderSurface(true);
8189 grand_child2_raw
->SetDrawsContent(true);
8191 ExecuteCalculateDrawProperties(grand_parent_raw
);
8192 member_id
= render_surface_layer_list_count();
8194 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8195 EXPECT_NE(member_id
, membership_id(parent_raw
));
8196 EXPECT_NE(member_id
, membership_id(child_raw
));
8197 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8198 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8201 expected
.insert(grand_child2_raw
);
8204 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8205 EXPECT_EQ(expected
, actual
);
8207 // Add a mask layer to child.
8208 child_raw
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6).Pass());
8210 ExecuteCalculateDrawProperties(grand_parent_raw
);
8211 member_id
= render_surface_layer_list_count();
8213 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8214 EXPECT_NE(member_id
, membership_id(parent_raw
));
8215 EXPECT_NE(member_id
, membership_id(child_raw
));
8216 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8217 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8218 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8221 expected
.insert(grand_child2_raw
);
8222 expected
.insert(child_raw
->mask_layer());
8225 expected
.insert(grand_child2_raw
);
8226 expected
.insert(child_raw
->mask_layer());
8229 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8230 EXPECT_EQ(expected
, actual
);
8232 // Add replica mask layer.
8233 scoped_ptr
<LayerImpl
> replica_layer
=
8234 LayerImpl::Create(host_impl
.active_tree(), 20);
8235 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 21));
8236 child_raw
->SetReplicaLayer(replica_layer
.Pass());
8238 ExecuteCalculateDrawProperties(grand_parent_raw
);
8239 member_id
= render_surface_layer_list_count();
8241 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8242 EXPECT_NE(member_id
, membership_id(parent_raw
));
8243 EXPECT_NE(member_id
, membership_id(child_raw
));
8244 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8245 EXPECT_EQ(member_id
, membership_id(child_raw
->replica_layer()->mask_layer()));
8246 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8247 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8250 expected
.insert(grand_child2_raw
);
8251 expected
.insert(child_raw
->mask_layer());
8252 expected
.insert(child_raw
->replica_layer()->mask_layer());
8255 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8256 EXPECT_EQ(expected
, actual
);
8258 child_raw
->TakeReplicaLayer();
8260 // With nothing drawing, we should have no layers.
8261 grand_child2_raw
->SetDrawsContent(false);
8263 ExecuteCalculateDrawProperties(grand_parent_raw
);
8264 member_id
= render_surface_layer_list_count();
8266 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8267 EXPECT_NE(member_id
, membership_id(parent_raw
));
8268 EXPECT_NE(member_id
, membership_id(child_raw
));
8269 EXPECT_NE(member_id
, membership_id(child_raw
->mask_layer()));
8270 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8271 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8275 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8276 EXPECT_EQ(expected
, actual
);
8278 // Child itself draws means that we should have the child and the mask in the
8280 child_raw
->SetDrawsContent(true);
8282 ExecuteCalculateDrawProperties(grand_parent_raw
);
8283 member_id
= render_surface_layer_list_count();
8285 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8286 EXPECT_NE(member_id
, membership_id(parent_raw
));
8287 EXPECT_EQ(member_id
, membership_id(child_raw
));
8288 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8289 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8290 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8293 expected
.insert(child_raw
);
8294 expected
.insert(child_raw
->mask_layer());
8296 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8297 EXPECT_EQ(expected
, actual
);
8299 child_raw
->TakeMaskLayer();
8301 // Now everyone's a member!
8302 grand_parent_raw
->SetDrawsContent(true);
8303 parent_raw
->SetDrawsContent(true);
8304 child_raw
->SetDrawsContent(true);
8305 grand_child1_raw
->SetDrawsContent(true);
8306 grand_child2_raw
->SetDrawsContent(true);
8308 ExecuteCalculateDrawProperties(grand_parent_raw
);
8309 member_id
= render_surface_layer_list_count();
8311 EXPECT_EQ(member_id
, membership_id(grand_parent_raw
));
8312 EXPECT_EQ(member_id
, membership_id(parent_raw
));
8313 EXPECT_EQ(member_id
, membership_id(child_raw
));
8314 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
8315 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8318 expected
.insert(grand_parent_raw
);
8319 expected
.insert(parent_raw
);
8320 expected
.insert(child_raw
);
8321 expected
.insert(grand_child1_raw
);
8322 expected
.insert(grand_child2_raw
);
8325 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8326 EXPECT_EQ(expected
, actual
);
8329 TEST_F(LayerTreeHostCommonTest
, DrawPropertyScales
) {
8330 FakeImplProxy proxy
;
8331 TestSharedBitmapManager shared_bitmap_manager
;
8332 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
8334 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
8335 LayerImpl
* root_layer
= root
.get();
8336 scoped_ptr
<LayerImpl
> child1
= LayerImpl::Create(host_impl
.active_tree(), 2);
8337 LayerImpl
* child1_layer
= child1
.get();
8338 scoped_ptr
<LayerImpl
> child2
= LayerImpl::Create(host_impl
.active_tree(), 3);
8339 LayerImpl
* child2_layer
= child2
.get();
8341 root
->AddChild(child1
.Pass());
8342 root
->AddChild(child2
.Pass());
8344 gfx::Transform identity_matrix
, scale_transform_child1
,
8345 scale_transform_child2
;
8346 scale_transform_child1
.Scale(2, 3);
8347 scale_transform_child2
.Scale(4, 5);
8349 SetLayerPropertiesForTesting(root_layer
,
8356 SetLayerPropertiesForTesting(child1_layer
,
8357 scale_transform_child1
,
8364 child1_layer
->SetMaskLayer(
8365 LayerImpl::Create(host_impl
.active_tree(), 4).Pass());
8367 scoped_ptr
<LayerImpl
> replica_layer
=
8368 LayerImpl::Create(host_impl
.active_tree(), 5);
8369 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6));
8370 child1_layer
->SetReplicaLayer(replica_layer
.Pass());
8372 ExecuteCalculateDrawProperties(root_layer
);
8374 TransformOperations scale
;
8375 scale
.AppendScale(5.f
, 8.f
, 3.f
);
8377 AddAnimatedTransformToLayer(child2_layer
, 1.0, TransformOperations(), scale
);
8378 SetLayerPropertiesForTesting(child2_layer
,
8379 scale_transform_child2
,
8386 ExecuteCalculateDrawProperties(root_layer
);
8388 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().ideal_contents_scale
);
8389 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8391 3.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8392 EXPECT_FLOAT_EQ(3.f
,
8393 child1_layer
->replica_layer()
8396 .ideal_contents_scale
);
8397 EXPECT_FLOAT_EQ(5.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8400 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8402 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8403 EXPECT_FLOAT_EQ(0.f
,
8404 child1_layer
->mask_layer()
8406 .maximum_animation_contents_scale
);
8407 EXPECT_FLOAT_EQ(0.f
,
8408 child1_layer
->replica_layer()
8411 .maximum_animation_contents_scale
);
8413 8.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8415 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8416 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().page_scale_factor
);
8418 1.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8419 EXPECT_FLOAT_EQ(1.f
,
8420 child1_layer
->replica_layer()
8423 .page_scale_factor
);
8424 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().page_scale_factor
);
8426 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().device_scale_factor
);
8427 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().device_scale_factor
);
8429 1.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8430 EXPECT_FLOAT_EQ(1.f
,
8431 child1_layer
->replica_layer()
8434 .device_scale_factor
);
8435 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().device_scale_factor
);
8437 // Changing page-scale would affect ideal_contents_scale and
8438 // maximum_animation_contents_scale.
8440 float page_scale_factor
= 3.f
;
8441 float device_scale_factor
= 1.0f
;
8442 std::vector
<LayerImpl
*> render_surface_layer_list
;
8443 gfx::Size device_viewport_size
=
8444 gfx::Size(root_layer
->bounds().width() * device_scale_factor
,
8445 root_layer
->bounds().height() * device_scale_factor
);
8446 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
8447 root_layer
, device_viewport_size
, &render_surface_layer_list
);
8449 inputs
.page_scale_factor
= page_scale_factor
;
8450 inputs
.can_adjust_raster_scales
= true;
8451 inputs
.page_scale_application_layer
= root_layer
;
8452 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8454 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().ideal_contents_scale
);
8455 EXPECT_FLOAT_EQ(9.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8457 9.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8458 EXPECT_FLOAT_EQ(9.f
,
8459 child1_layer
->replica_layer()
8462 .ideal_contents_scale
);
8463 EXPECT_FLOAT_EQ(15.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8466 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8468 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8469 EXPECT_FLOAT_EQ(0.f
,
8470 child1_layer
->mask_layer()
8472 .maximum_animation_contents_scale
);
8473 EXPECT_FLOAT_EQ(0.f
,
8474 child1_layer
->replica_layer()
8477 .maximum_animation_contents_scale
);
8479 24.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8481 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8482 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().page_scale_factor
);
8484 3.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8485 EXPECT_FLOAT_EQ(3.f
,
8486 child1_layer
->replica_layer()
8489 .page_scale_factor
);
8490 EXPECT_FLOAT_EQ(3.f
, child2_layer
->draw_properties().page_scale_factor
);
8492 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().device_scale_factor
);
8493 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().device_scale_factor
);
8495 1.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8496 EXPECT_FLOAT_EQ(1.f
,
8497 child1_layer
->replica_layer()
8500 .device_scale_factor
);
8501 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().device_scale_factor
);
8503 // Changing device-scale would affect ideal_contents_scale and
8504 // maximum_animation_contents_scale.
8506 device_scale_factor
= 4.0f
;
8507 inputs
.device_scale_factor
= device_scale_factor
;
8508 inputs
.can_adjust_raster_scales
= true;
8509 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8511 EXPECT_FLOAT_EQ(4.f
, root_layer
->draw_properties().ideal_contents_scale
);
8512 EXPECT_FLOAT_EQ(36.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8514 36.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8515 EXPECT_FLOAT_EQ(36.f
,
8516 child1_layer
->replica_layer()
8519 .ideal_contents_scale
);
8520 EXPECT_FLOAT_EQ(60.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8523 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8525 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8526 EXPECT_FLOAT_EQ(0.f
,
8527 child1_layer
->mask_layer()
8529 .maximum_animation_contents_scale
);
8530 EXPECT_FLOAT_EQ(0.f
,
8531 child1_layer
->replica_layer()
8534 .maximum_animation_contents_scale
);
8536 96.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8538 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8539 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().page_scale_factor
);
8541 3.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8542 EXPECT_FLOAT_EQ(3.f
,
8543 child1_layer
->replica_layer()
8546 .page_scale_factor
);
8547 EXPECT_FLOAT_EQ(3.f
, child2_layer
->draw_properties().page_scale_factor
);
8549 EXPECT_FLOAT_EQ(4.f
, root_layer
->draw_properties().device_scale_factor
);
8550 EXPECT_FLOAT_EQ(4.f
, child1_layer
->draw_properties().device_scale_factor
);
8552 4.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8553 EXPECT_FLOAT_EQ(4.f
,
8554 child1_layer
->replica_layer()
8557 .device_scale_factor
);
8558 EXPECT_FLOAT_EQ(4.f
, child2_layer
->draw_properties().device_scale_factor
);