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() : Layer(), last_device_scale_factor_(0.f
) {}
43 virtual bool DrawsContent() const OVERRIDE
;
44 virtual void CalculateContentsScale(float ideal_contents_scale
,
45 float device_scale_factor
,
46 float page_scale_factor
,
47 float maximum_animation_contents_scale
,
48 bool animating_transform_to_screen
,
49 float* contents_scale_x
,
50 float* contents_scale_y
,
51 gfx::Size
* content_bounds
) OVERRIDE
;
53 float last_device_scale_factor() const { return last_device_scale_factor_
; }
56 virtual ~LayerWithForcedDrawsContent() {}
58 // Parameters from last CalculateContentsScale.
59 float last_device_scale_factor_
;
62 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
64 void LayerWithForcedDrawsContent::CalculateContentsScale(
65 float ideal_contents_scale
,
66 float device_scale_factor
,
67 float page_scale_factor
,
68 float maximum_animation_contents_scale
,
69 bool animating_transform_to_screen
,
70 float* contents_scale_x
,
71 float* contents_scale_y
,
72 gfx::Size
* content_bounds
) {
73 last_device_scale_factor_
= device_scale_factor
;
74 Layer::CalculateContentsScale(ideal_contents_scale
,
77 maximum_animation_contents_scale
,
78 animating_transform_to_screen
,
84 class MockContentLayerClient
: public ContentLayerClient
{
86 MockContentLayerClient() {}
87 virtual ~MockContentLayerClient() {}
88 virtual void PaintContents(
90 const gfx::Rect
& clip
,
92 ContentLayerClient::GraphicsContextStatus gc_status
) OVERRIDE
{}
93 virtual void DidChangeLayerCanUseLCDText() OVERRIDE
{}
94 virtual bool FillsBoundsCompletely() const OVERRIDE
{ return false; }
97 scoped_refptr
<ContentLayer
> CreateDrawableContentLayer(
98 ContentLayerClient
* delegate
) {
99 scoped_refptr
<ContentLayer
> to_return
= ContentLayer::Create(delegate
);
100 to_return
->SetIsDrawable(true);
104 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
106 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
107 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
110 TEST_F(LayerTreeHostCommonTest
, TransformsForNoOpLayer
) {
111 // Sanity check: For layers positioned at zero, with zero size,
112 // and with identity transforms, then the draw transform,
113 // screen space transform, and the hierarchy passed on to children
114 // layers should also be identity transforms.
116 scoped_refptr
<Layer
> parent
= Layer::Create();
117 scoped_refptr
<Layer
> child
= Layer::Create();
118 scoped_refptr
<Layer
> grand_child
= Layer::Create();
119 parent
->AddChild(child
);
120 child
->AddChild(grand_child
);
122 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
123 host
->SetRootLayer(parent
);
125 gfx::Transform identity_matrix
;
126 SetLayerPropertiesForTesting(parent
.get(),
133 SetLayerPropertiesForTesting(child
.get(),
140 SetLayerPropertiesForTesting(grand_child
.get(),
148 ExecuteCalculateDrawProperties(parent
.get());
150 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
151 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
152 child
->screen_space_transform());
153 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
154 grand_child
->draw_transform());
155 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
156 grand_child
->screen_space_transform());
159 TEST_F(LayerTreeHostCommonTest
, DoNotSkipLayersWithHandlers
) {
160 scoped_refptr
<Layer
> parent
= Layer::Create();
161 scoped_refptr
<Layer
> child
= Layer::Create();
162 scoped_refptr
<Layer
> grand_child
= Layer::Create();
163 parent
->AddChild(child
);
164 child
->AddChild(grand_child
);
166 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
167 host
->SetRootLayer(parent
);
169 gfx::Transform identity_matrix
;
170 SetLayerPropertiesForTesting(parent
.get(),
177 SetLayerPropertiesForTesting(child
.get(),
184 // This would have previously caused us to skip our subtree, but this would be
185 // wrong; we need up-to-date draw properties to do hit testing on the layers
187 child
->SetOpacity(0.f
);
188 SetLayerPropertiesForTesting(grand_child
.get(),
195 grand_child
->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
197 ExecuteCalculateDrawProperties(parent
.get());
199 // Check that we've computed draw properties for the subtree rooted at
201 EXPECT_FALSE(child
->draw_transform().IsIdentity());
202 EXPECT_FALSE(grand_child
->draw_transform().IsIdentity());
205 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleLayer
) {
206 gfx::Transform identity_matrix
;
207 scoped_refptr
<Layer
> layer
= Layer::Create();
209 scoped_refptr
<Layer
> root
= Layer::Create();
210 SetLayerPropertiesForTesting(root
.get(),
217 root
->AddChild(layer
);
219 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
220 host
->SetRootLayer(root
);
222 // Case 2: Setting the bounds of the layer should not affect either the draw
223 // transform or the screenspace transform.
224 gfx::Transform translation_to_center
;
225 translation_to_center
.Translate(5.0, 6.0);
226 SetLayerPropertiesForTesting(layer
.get(),
233 ExecuteCalculateDrawProperties(root
.get());
234 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
235 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
236 layer
->screen_space_transform());
238 // Case 3: The anchor point by itself (without a layer transform) should have
239 // no effect on the transforms.
240 SetLayerPropertiesForTesting(layer
.get(),
242 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
247 ExecuteCalculateDrawProperties(root
.get());
248 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
249 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
250 layer
->screen_space_transform());
252 // Case 4: A change in actual position affects both the draw transform and
253 // screen space transform.
254 gfx::Transform position_transform
;
255 position_transform
.Translate(0.f
, 1.2f
);
256 SetLayerPropertiesForTesting(layer
.get(),
258 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
259 gfx::PointF(0.f
, 1.2f
),
263 ExecuteCalculateDrawProperties(root
.get());
264 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
, layer
->draw_transform());
265 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
,
266 layer
->screen_space_transform());
268 // Case 5: In the correct sequence of transforms, the layer transform should
269 // pre-multiply the translation_to_center. This is easily tested by using a
270 // scale transform, because scale and translation are not commutative.
271 gfx::Transform layer_transform
;
272 layer_transform
.Scale3d(2.0, 2.0, 1.0);
273 SetLayerPropertiesForTesting(layer
.get(),
280 ExecuteCalculateDrawProperties(root
.get());
281 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
, layer
->draw_transform());
282 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
,
283 layer
->screen_space_transform());
285 // Case 6: The layer transform should occur with respect to the anchor point.
286 gfx::Transform translation_to_anchor
;
287 translation_to_anchor
.Translate(5.0, 0.0);
288 gfx::Transform expected_result
=
289 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
290 SetLayerPropertiesForTesting(layer
.get(),
292 gfx::Point3F(5.0f
, 0.f
, 0.f
),
297 ExecuteCalculateDrawProperties(root
.get());
298 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
299 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
300 layer
->screen_space_transform());
302 // Case 7: Verify that position pre-multiplies the layer transform. The
303 // current implementation of CalculateDrawProperties does this implicitly, but
304 // it is still worth testing to detect accidental regressions.
305 expected_result
= position_transform
* translation_to_anchor
*
306 layer_transform
* Inverse(translation_to_anchor
);
307 SetLayerPropertiesForTesting(layer
.get(),
309 gfx::Point3F(5.0f
, 0.f
, 0.f
),
310 gfx::PointF(0.f
, 1.2f
),
314 ExecuteCalculateDrawProperties(root
.get());
315 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
316 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
317 layer
->screen_space_transform());
320 TEST_F(LayerTreeHostCommonTest
, TransformsAboutScrollOffset
) {
321 const gfx::Vector2d
kScrollOffset(50, 100);
322 const gfx::Vector2dF
kScrollDelta(2.34f
, 5.67f
);
323 const gfx::Vector2d
kMaxScrollOffset(200, 200);
324 const gfx::PointF
kScrollLayerPosition(-kScrollOffset
.x(),
326 const float kPageScale
= 0.888f
;
327 const float kDeviceScale
= 1.666f
;
330 TestSharedBitmapManager shared_bitmap_manager
;
331 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
333 gfx::Transform identity_matrix
;
334 scoped_ptr
<LayerImpl
> sublayer_scoped_ptr(
335 LayerImpl::Create(host_impl
.active_tree(), 1));
336 LayerImpl
* sublayer
= sublayer_scoped_ptr
.get();
337 sublayer
->SetContentsScale(kPageScale
* kDeviceScale
,
338 kPageScale
* kDeviceScale
);
339 SetLayerPropertiesForTesting(sublayer
,
347 scoped_ptr
<LayerImpl
> scroll_layer_scoped_ptr(
348 LayerImpl::Create(host_impl
.active_tree(), 2));
349 LayerImpl
* scroll_layer
= scroll_layer_scoped_ptr
.get();
350 SetLayerPropertiesForTesting(scroll_layer
,
357 scoped_ptr
<LayerImpl
> clip_layer_scoped_ptr(
358 LayerImpl::Create(host_impl
.active_tree(), 4));
359 LayerImpl
* clip_layer
= clip_layer_scoped_ptr
.get();
361 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
362 clip_layer
->SetBounds(
363 gfx::Size(scroll_layer
->bounds().width() + kMaxScrollOffset
.x(),
364 scroll_layer
->bounds().height() + kMaxScrollOffset
.y()));
365 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
366 scroll_layer
->SetScrollDelta(kScrollDelta
);
367 gfx::Transform impl_transform
;
368 scroll_layer
->AddChild(sublayer_scoped_ptr
.Pass());
369 LayerImpl
* scroll_layer_raw_ptr
= scroll_layer_scoped_ptr
.get();
370 clip_layer
->AddChild(scroll_layer_scoped_ptr
.Pass());
371 scroll_layer_raw_ptr
->SetScrollOffset(kScrollOffset
);
373 scoped_ptr
<LayerImpl
> root(LayerImpl::Create(host_impl
.active_tree(), 3));
374 SetLayerPropertiesForTesting(root
.get(),
381 root
->AddChild(clip_layer_scoped_ptr
.Pass());
383 ExecuteCalculateDrawProperties(
384 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
385 gfx::Transform expected_transform
= identity_matrix
;
386 gfx::PointF sub_layer_screen_position
= kScrollLayerPosition
- kScrollDelta
;
387 sub_layer_screen_position
.Scale(kPageScale
* kDeviceScale
);
388 expected_transform
.Translate(MathUtil::Round(sub_layer_screen_position
.x()),
389 MathUtil::Round(sub_layer_screen_position
.y()));
390 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
391 sublayer
->draw_transform());
392 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
393 sublayer
->screen_space_transform());
395 gfx::Transform arbitrary_translate
;
396 const float kTranslateX
= 10.6f
;
397 const float kTranslateY
= 20.6f
;
398 arbitrary_translate
.Translate(kTranslateX
, kTranslateY
);
399 SetLayerPropertiesForTesting(scroll_layer
,
406 ExecuteCalculateDrawProperties(
407 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
408 expected_transform
.MakeIdentity();
409 expected_transform
.Translate(
410 MathUtil::Round(kTranslateX
* kPageScale
* kDeviceScale
+
411 sub_layer_screen_position
.x()),
412 MathUtil::Round(kTranslateY
* kPageScale
* kDeviceScale
+
413 sub_layer_screen_position
.y()));
414 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
415 sublayer
->draw_transform());
418 TEST_F(LayerTreeHostCommonTest
, TransformsForSimpleHierarchy
) {
419 gfx::Transform identity_matrix
;
420 scoped_refptr
<Layer
> root
= Layer::Create();
421 scoped_refptr
<Layer
> parent
= Layer::Create();
422 scoped_refptr
<Layer
> child
= Layer::Create();
423 scoped_refptr
<Layer
> grand_child
= Layer::Create();
424 root
->AddChild(parent
);
425 parent
->AddChild(child
);
426 child
->AddChild(grand_child
);
428 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
429 host
->SetRootLayer(root
);
431 // One-time setup of root layer
432 SetLayerPropertiesForTesting(root
.get(),
440 // Case 1: parent's anchor point should not affect child or grand_child.
441 SetLayerPropertiesForTesting(parent
.get(),
443 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
448 SetLayerPropertiesForTesting(child
.get(),
455 SetLayerPropertiesForTesting(grand_child
.get(),
462 ExecuteCalculateDrawProperties(root
.get());
463 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
464 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
465 child
->screen_space_transform());
466 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
467 grand_child
->draw_transform());
468 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
469 grand_child
->screen_space_transform());
471 // Case 2: parent's position affects child and grand_child.
472 gfx::Transform parent_position_transform
;
473 parent_position_transform
.Translate(0.f
, 1.2f
);
474 SetLayerPropertiesForTesting(parent
.get(),
476 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
477 gfx::PointF(0.f
, 1.2f
),
481 SetLayerPropertiesForTesting(child
.get(),
488 SetLayerPropertiesForTesting(grand_child
.get(),
495 ExecuteCalculateDrawProperties(root
.get());
496 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
497 child
->draw_transform());
498 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
499 child
->screen_space_transform());
500 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
501 grand_child
->draw_transform());
502 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
503 grand_child
->screen_space_transform());
505 // Case 3: parent's local transform affects child and grandchild
506 gfx::Transform parent_layer_transform
;
507 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
508 gfx::Transform parent_translation_to_anchor
;
509 parent_translation_to_anchor
.Translate(2.5, 3.0);
510 gfx::Transform parent_composite_transform
=
511 parent_translation_to_anchor
* parent_layer_transform
*
512 Inverse(parent_translation_to_anchor
);
513 SetLayerPropertiesForTesting(parent
.get(),
514 parent_layer_transform
,
515 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
520 SetLayerPropertiesForTesting(child
.get(),
527 SetLayerPropertiesForTesting(grand_child
.get(),
534 ExecuteCalculateDrawProperties(root
.get());
535 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
536 child
->draw_transform());
537 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
538 child
->screen_space_transform());
539 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
540 grand_child
->draw_transform());
541 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
542 grand_child
->screen_space_transform());
545 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleRenderSurface
) {
546 scoped_refptr
<Layer
> root
= Layer::Create();
547 scoped_refptr
<Layer
> parent
= Layer::Create();
548 scoped_refptr
<Layer
> child
= Layer::Create();
549 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
550 make_scoped_refptr(new LayerWithForcedDrawsContent());
551 root
->AddChild(parent
);
552 parent
->AddChild(child
);
553 child
->AddChild(grand_child
);
555 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
556 host
->SetRootLayer(root
);
558 // One-time setup of root layer
559 gfx::Transform identity_matrix
;
560 SetLayerPropertiesForTesting(root
.get(),
568 // Child is set up so that a new render surface should be created.
569 child
->SetOpacity(0.5f
);
570 child
->SetForceRenderSurface(true);
572 gfx::Transform parent_layer_transform
;
573 parent_layer_transform
.Scale3d(1.f
, 0.9f
, 1.f
);
574 gfx::Transform parent_translation_to_anchor
;
575 parent_translation_to_anchor
.Translate(25.0, 30.0);
577 gfx::Transform parent_composite_transform
=
578 parent_translation_to_anchor
* parent_layer_transform
*
579 Inverse(parent_translation_to_anchor
);
580 gfx::Vector2dF parent_composite_scale
=
581 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
583 gfx::Transform surface_sublayer_transform
;
584 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
585 parent_composite_scale
.y());
586 gfx::Transform surface_sublayer_composite_transform
=
587 parent_composite_transform
* Inverse(surface_sublayer_transform
);
589 // Child's render surface should not exist yet.
590 ASSERT_FALSE(child
->render_surface());
592 SetLayerPropertiesForTesting(parent
.get(),
593 parent_layer_transform
,
594 gfx::Point3F(25.0f
, 30.0f
, 0.f
),
599 SetLayerPropertiesForTesting(child
.get(),
606 SetLayerPropertiesForTesting(grand_child
.get(),
613 ExecuteCalculateDrawProperties(root
.get());
615 // Render surface should have been created now.
616 ASSERT_TRUE(child
->render_surface());
617 ASSERT_EQ(child
, child
->render_target());
619 // The child layer's draw transform should refer to its new render surface.
620 // The screen-space transform, however, should still refer to the root.
621 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform
,
622 child
->draw_transform());
623 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
624 child
->screen_space_transform());
626 // Because the grand_child is the only drawable content, the child's render
627 // surface will tighten its bounds to the grand_child. The scale at which the
628 // surface's subtree is drawn must be removed from the composite transform.
629 EXPECT_TRANSFORMATION_MATRIX_EQ(
630 surface_sublayer_composite_transform
,
631 child
->render_target()->render_surface()->draw_transform());
633 // The screen space is the same as the target since the child surface draws
635 EXPECT_TRANSFORMATION_MATRIX_EQ(
636 surface_sublayer_composite_transform
,
637 child
->render_target()->render_surface()->screen_space_transform());
640 TEST_F(LayerTreeHostCommonTest
, TransformsForReplica
) {
641 scoped_refptr
<Layer
> root
= Layer::Create();
642 scoped_refptr
<Layer
> parent
= Layer::Create();
643 scoped_refptr
<Layer
> child
= Layer::Create();
644 scoped_refptr
<Layer
> child_replica
= Layer::Create();
645 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
646 make_scoped_refptr(new LayerWithForcedDrawsContent());
647 root
->AddChild(parent
);
648 parent
->AddChild(child
);
649 child
->AddChild(grand_child
);
650 child
->SetReplicaLayer(child_replica
.get());
652 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
653 host
->SetRootLayer(root
);
655 // One-time setup of root layer
656 gfx::Transform identity_matrix
;
657 SetLayerPropertiesForTesting(root
.get(),
665 // Child is set up so that a new render surface should be created.
666 child
->SetOpacity(0.5f
);
668 gfx::Transform parent_layer_transform
;
669 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
670 gfx::Transform parent_translation_to_anchor
;
671 parent_translation_to_anchor
.Translate(2.5, 3.0);
672 gfx::Transform parent_composite_transform
=
673 parent_translation_to_anchor
* parent_layer_transform
*
674 Inverse(parent_translation_to_anchor
);
675 gfx::Transform replica_layer_transform
;
676 replica_layer_transform
.Scale3d(3.0, 3.0, 1.0);
677 gfx::Vector2dF parent_composite_scale
=
678 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
680 gfx::Transform surface_sublayer_transform
;
681 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
682 parent_composite_scale
.y());
683 gfx::Transform replica_composite_transform
=
684 parent_composite_transform
* replica_layer_transform
*
685 Inverse(surface_sublayer_transform
);
687 // Child's render surface should not exist yet.
688 ASSERT_FALSE(child
->render_surface());
690 SetLayerPropertiesForTesting(parent
.get(),
691 parent_layer_transform
,
692 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
697 SetLayerPropertiesForTesting(child
.get(),
704 SetLayerPropertiesForTesting(grand_child
.get(),
707 gfx::PointF(-0.5f
, -0.5f
),
711 SetLayerPropertiesForTesting(child_replica
.get(),
712 replica_layer_transform
,
718 ExecuteCalculateDrawProperties(root
.get());
720 // Render surface should have been created now.
721 ASSERT_TRUE(child
->render_surface());
722 ASSERT_EQ(child
, child
->render_target());
724 EXPECT_TRANSFORMATION_MATRIX_EQ(
725 replica_composite_transform
,
726 child
->render_target()->render_surface()->replica_draw_transform());
727 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform
,
728 child
->render_target()
730 ->replica_screen_space_transform());
733 TEST_F(LayerTreeHostCommonTest
, TransformsForRenderSurfaceHierarchy
) {
734 // This test creates a more complex tree and verifies it all at once. This
735 // covers the following cases:
736 // - layers that are described w.r.t. a render surface: should have draw
737 // transforms described w.r.t. that surface
738 // - A render surface described w.r.t. an ancestor render surface: should
739 // have a draw transform described w.r.t. that ancestor surface
740 // - Replicas of a render surface are described w.r.t. the replica's
741 // transform around its anchor, along with the surface itself.
742 // - Sanity check on recursion: verify transforms of layers described w.r.t.
743 // a render surface that is described w.r.t. an ancestor render surface.
744 // - verifying that each layer has a reference to the correct render surface
745 // and render target values.
747 scoped_refptr
<Layer
> root
= Layer::Create();
748 scoped_refptr
<Layer
> parent
= Layer::Create();
749 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
750 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
751 scoped_refptr
<Layer
> child_of_root
= Layer::Create();
752 scoped_refptr
<Layer
> child_of_rs1
= Layer::Create();
753 scoped_refptr
<Layer
> child_of_rs2
= Layer::Create();
754 scoped_refptr
<Layer
> replica_of_rs1
= Layer::Create();
755 scoped_refptr
<Layer
> replica_of_rs2
= Layer::Create();
756 scoped_refptr
<Layer
> grand_child_of_root
= Layer::Create();
757 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs1
=
758 make_scoped_refptr(new LayerWithForcedDrawsContent());
759 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs2
=
760 make_scoped_refptr(new LayerWithForcedDrawsContent());
761 root
->AddChild(parent
);
762 parent
->AddChild(render_surface1
);
763 parent
->AddChild(child_of_root
);
764 render_surface1
->AddChild(child_of_rs1
);
765 render_surface1
->AddChild(render_surface2
);
766 render_surface2
->AddChild(child_of_rs2
);
767 child_of_root
->AddChild(grand_child_of_root
);
768 child_of_rs1
->AddChild(grand_child_of_rs1
);
769 child_of_rs2
->AddChild(grand_child_of_rs2
);
770 render_surface1
->SetReplicaLayer(replica_of_rs1
.get());
771 render_surface2
->SetReplicaLayer(replica_of_rs2
.get());
773 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
774 host
->SetRootLayer(root
);
776 // In combination with descendant draws content, opacity != 1 forces the layer
777 // to have a new render surface.
778 render_surface1
->SetOpacity(0.5f
);
779 render_surface2
->SetOpacity(0.33f
);
781 // One-time setup of root layer
782 gfx::Transform identity_matrix
;
783 SetLayerPropertiesForTesting(root
.get(),
791 // All layers in the tree are initialized with an anchor at .25 and a size of
792 // (10,10). matrix "A" is the composite layer transform used in all layers,
793 // Matrix "R" is the composite replica transform used in all replica layers.
794 gfx::Transform translation_to_anchor
;
795 translation_to_anchor
.Translate(2.5, 0.0);
796 gfx::Transform layer_transform
;
797 layer_transform
.Translate(1.0, 1.0);
798 gfx::Transform replica_layer_transform
;
799 replica_layer_transform
.Scale3d(-2.0, 5.0, 1.0);
802 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
803 gfx::Transform R
= A
* translation_to_anchor
* replica_layer_transform
*
804 Inverse(translation_to_anchor
);
806 gfx::Vector2dF surface1_parent_transform_scale
=
807 MathUtil::ComputeTransform2dScaleComponents(A
, 1.f
);
808 gfx::Transform surface1_sublayer_transform
;
809 surface1_sublayer_transform
.Scale(surface1_parent_transform_scale
.x(),
810 surface1_parent_transform_scale
.y());
812 // SS1 = transform given to the subtree of render_surface1
813 gfx::Transform SS1
= surface1_sublayer_transform
;
814 // S1 = transform to move from render_surface1 pixels to the layer space of
816 gfx::Transform S1
= Inverse(surface1_sublayer_transform
);
818 gfx::Vector2dF surface2_parent_transform_scale
=
819 MathUtil::ComputeTransform2dScaleComponents(SS1
* A
, 1.f
);
820 gfx::Transform surface2_sublayer_transform
;
821 surface2_sublayer_transform
.Scale(surface2_parent_transform_scale
.x(),
822 surface2_parent_transform_scale
.y());
824 // SS2 = transform given to the subtree of render_surface2
825 gfx::Transform SS2
= surface2_sublayer_transform
;
826 // S2 = transform to move from render_surface2 pixels to the layer space of
828 gfx::Transform S2
= Inverse(surface2_sublayer_transform
);
830 SetLayerPropertiesForTesting(parent
.get(),
832 gfx::Point3F(2.5f
, 0.f
, 0.f
),
837 SetLayerPropertiesForTesting(render_surface1
.get(),
839 gfx::Point3F(2.5f
, 0.f
, 0.f
),
844 SetLayerPropertiesForTesting(render_surface2
.get(),
846 gfx::Point3F(2.5f
, 0.f
, 0.f
),
851 SetLayerPropertiesForTesting(child_of_root
.get(),
853 gfx::Point3F(2.5f
, 0.f
, 0.f
),
858 SetLayerPropertiesForTesting(child_of_rs1
.get(),
860 gfx::Point3F(2.5f
, 0.f
, 0.f
),
865 SetLayerPropertiesForTesting(child_of_rs2
.get(),
867 gfx::Point3F(2.5f
, 0.f
, 0.f
),
872 SetLayerPropertiesForTesting(grand_child_of_root
.get(),
874 gfx::Point3F(2.5f
, 0.f
, 0.f
),
879 SetLayerPropertiesForTesting(grand_child_of_rs1
.get(),
881 gfx::Point3F(2.5f
, 0.f
, 0.f
),
886 SetLayerPropertiesForTesting(grand_child_of_rs2
.get(),
888 gfx::Point3F(2.5f
, 0.f
, 0.f
),
893 SetLayerPropertiesForTesting(replica_of_rs1
.get(),
894 replica_layer_transform
,
895 gfx::Point3F(2.5f
, 0.f
, 0.f
),
900 SetLayerPropertiesForTesting(replica_of_rs2
.get(),
901 replica_layer_transform
,
902 gfx::Point3F(2.5f
, 0.f
, 0.f
),
908 ExecuteCalculateDrawProperties(root
.get());
910 // Only layers that are associated with render surfaces should have an actual
911 // RenderSurface() value.
912 ASSERT_TRUE(root
->render_surface());
913 ASSERT_FALSE(child_of_root
->render_surface());
914 ASSERT_FALSE(grand_child_of_root
->render_surface());
916 ASSERT_TRUE(render_surface1
->render_surface());
917 ASSERT_FALSE(child_of_rs1
->render_surface());
918 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
920 ASSERT_TRUE(render_surface2
->render_surface());
921 ASSERT_FALSE(child_of_rs2
->render_surface());
922 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
924 // Verify all render target accessors
925 EXPECT_EQ(root
, parent
->render_target());
926 EXPECT_EQ(root
, child_of_root
->render_target());
927 EXPECT_EQ(root
, grand_child_of_root
->render_target());
929 EXPECT_EQ(render_surface1
, render_surface1
->render_target());
930 EXPECT_EQ(render_surface1
, child_of_rs1
->render_target());
931 EXPECT_EQ(render_surface1
, grand_child_of_rs1
->render_target());
933 EXPECT_EQ(render_surface2
, render_surface2
->render_target());
934 EXPECT_EQ(render_surface2
, child_of_rs2
->render_target());
935 EXPECT_EQ(render_surface2
, grand_child_of_rs2
->render_target());
937 // Verify layer draw transforms note that draw transforms are described with
938 // respect to the nearest ancestor render surface but screen space transforms
939 // are described with respect to the root.
940 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->draw_transform());
941 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
, child_of_root
->draw_transform());
942 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
943 grand_child_of_root
->draw_transform());
945 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
, render_surface1
->draw_transform());
946 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
, child_of_rs1
->draw_transform());
947 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
* A
,
948 grand_child_of_rs1
->draw_transform());
950 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
, render_surface2
->draw_transform());
951 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
, child_of_rs2
->draw_transform());
952 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
* A
,
953 grand_child_of_rs2
->draw_transform());
955 // Verify layer screen-space transforms
957 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->screen_space_transform());
958 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
959 child_of_root
->screen_space_transform());
960 EXPECT_TRANSFORMATION_MATRIX_EQ(
961 A
* A
* A
, grand_child_of_root
->screen_space_transform());
963 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
964 render_surface1
->screen_space_transform());
965 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
966 child_of_rs1
->screen_space_transform());
967 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
968 grand_child_of_rs1
->screen_space_transform());
970 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
971 render_surface2
->screen_space_transform());
972 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
973 child_of_rs2
->screen_space_transform());
974 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
* A
,
975 grand_child_of_rs2
->screen_space_transform());
977 // Verify render surface transforms.
979 // Draw transform of render surface 1 is described with respect to root.
980 EXPECT_TRANSFORMATION_MATRIX_EQ(
981 A
* A
* S1
, render_surface1
->render_surface()->draw_transform());
982 EXPECT_TRANSFORMATION_MATRIX_EQ(
983 A
* R
* S1
, render_surface1
->render_surface()->replica_draw_transform());
984 EXPECT_TRANSFORMATION_MATRIX_EQ(
985 A
* A
* S1
, render_surface1
->render_surface()->screen_space_transform());
986 EXPECT_TRANSFORMATION_MATRIX_EQ(
988 render_surface1
->render_surface()->replica_screen_space_transform());
989 // Draw transform of render surface 2 is described with respect to render
991 EXPECT_TRANSFORMATION_MATRIX_EQ(
992 SS1
* A
* S2
, render_surface2
->render_surface()->draw_transform());
993 EXPECT_TRANSFORMATION_MATRIX_EQ(
995 render_surface2
->render_surface()->replica_draw_transform());
996 EXPECT_TRANSFORMATION_MATRIX_EQ(
998 render_surface2
->render_surface()->screen_space_transform());
999 EXPECT_TRANSFORMATION_MATRIX_EQ(
1001 render_surface2
->render_surface()->replica_screen_space_transform());
1003 // Sanity check. If these fail there is probably a bug in the test itself. It
1004 // is expected that we correctly set up transforms so that the y-component of
1005 // the screen-space transform encodes the "depth" of the layer in the tree.
1006 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
1007 EXPECT_FLOAT_EQ(2.0,
1008 child_of_root
->screen_space_transform().matrix().get(1, 3));
1010 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
1012 EXPECT_FLOAT_EQ(2.0,
1013 render_surface1
->screen_space_transform().matrix().get(1, 3));
1014 EXPECT_FLOAT_EQ(3.0,
1015 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
1017 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
1019 EXPECT_FLOAT_EQ(3.0,
1020 render_surface2
->screen_space_transform().matrix().get(1, 3));
1021 EXPECT_FLOAT_EQ(4.0,
1022 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
1024 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
1027 TEST_F(LayerTreeHostCommonTest
, TransformsForFlatteningLayer
) {
1028 // For layers that flatten their subtree, there should be an orthographic
1029 // projection (for x and y values) in the middle of the transform sequence.
1030 // Note that the way the code is currently implemented, it is not expected to
1031 // use a canonical orthographic projection.
1033 scoped_refptr
<Layer
> root
= Layer::Create();
1034 scoped_refptr
<Layer
> child
= Layer::Create();
1035 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1036 make_scoped_refptr(new LayerWithForcedDrawsContent());
1038 gfx::Transform rotation_about_y_axis
;
1039 rotation_about_y_axis
.RotateAboutYAxis(30.0);
1041 const gfx::Transform identity_matrix
;
1042 SetLayerPropertiesForTesting(root
.get(),
1046 gfx::Size(100, 100),
1049 SetLayerPropertiesForTesting(child
.get(),
1050 rotation_about_y_axis
,
1056 SetLayerPropertiesForTesting(grand_child
.get(),
1057 rotation_about_y_axis
,
1064 root
->AddChild(child
);
1065 child
->AddChild(grand_child
);
1066 child
->SetForceRenderSurface(true);
1068 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1069 host
->SetRootLayer(root
);
1071 // No layers in this test should preserve 3d.
1072 ASSERT_TRUE(root
->should_flatten_transform());
1073 ASSERT_TRUE(child
->should_flatten_transform());
1074 ASSERT_TRUE(grand_child
->should_flatten_transform());
1076 gfx::Transform expected_child_draw_transform
= rotation_about_y_axis
;
1077 gfx::Transform expected_child_screen_space_transform
= rotation_about_y_axis
;
1078 gfx::Transform expected_grand_child_draw_transform
=
1079 rotation_about_y_axis
; // draws onto child's render surface
1080 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
1081 flattened_rotation_about_y
.FlattenTo2d();
1082 gfx::Transform expected_grand_child_screen_space_transform
=
1083 flattened_rotation_about_y
* rotation_about_y_axis
;
1085 ExecuteCalculateDrawProperties(root
.get());
1087 // The child's draw transform should have been taken by its surface.
1088 ASSERT_TRUE(child
->render_surface());
1089 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform
,
1090 child
->render_surface()->draw_transform());
1091 EXPECT_TRANSFORMATION_MATRIX_EQ(
1092 expected_child_screen_space_transform
,
1093 child
->render_surface()->screen_space_transform());
1094 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1095 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform
,
1096 child
->screen_space_transform());
1097 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform
,
1098 grand_child
->draw_transform());
1099 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform
,
1100 grand_child
->screen_space_transform());
1103 TEST_F(LayerTreeHostCommonTest
, TransformsForDegenerateIntermediateLayer
) {
1104 // A layer that is empty in one axis, but not the other, was accidentally
1105 // skipping a necessary translation. Without that translation, the coordinate
1106 // space of the layer's draw transform is incorrect.
1108 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1109 // but if that layer becomes a render surface, then its draw transform is
1110 // implicitly inherited by the rest of the subtree, which then is positioned
1111 // incorrectly as a result.
1113 scoped_refptr
<Layer
> root
= Layer::Create();
1114 scoped_refptr
<Layer
> child
= Layer::Create();
1115 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1116 make_scoped_refptr(new LayerWithForcedDrawsContent());
1118 // The child height is zero, but has non-zero width that should be accounted
1119 // for while computing draw transforms.
1120 const gfx::Transform identity_matrix
;
1121 SetLayerPropertiesForTesting(root
.get(),
1125 gfx::Size(100, 100),
1128 SetLayerPropertiesForTesting(child
.get(),
1135 SetLayerPropertiesForTesting(grand_child
.get(),
1143 root
->AddChild(child
);
1144 child
->AddChild(grand_child
);
1145 child
->SetForceRenderSurface(true);
1147 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1148 host
->SetRootLayer(root
);
1150 ExecuteCalculateDrawProperties(root
.get());
1152 ASSERT_TRUE(child
->render_surface());
1153 // This is the real test, the rest are sanity checks.
1154 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1155 child
->render_surface()->draw_transform());
1156 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1157 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1158 grand_child
->draw_transform());
1161 TEST_F(LayerTreeHostCommonTest
, TransformAboveRootLayer
) {
1162 // Transformations applied at the root of the tree should be forwarded
1163 // to child layers instead of applied to the root RenderSurface.
1164 const gfx::Transform identity_matrix
;
1165 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
1166 new LayerWithForcedDrawsContent
;
1167 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1168 new LayerWithForcedDrawsContent
;
1169 child
->SetScrollClipLayerId(root
->id());
1170 root
->AddChild(child
);
1172 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1173 host
->SetRootLayer(root
);
1175 SetLayerPropertiesForTesting(root
.get(),
1182 SetLayerPropertiesForTesting(child
.get(),
1190 gfx::Transform translate
;
1191 translate
.Translate(50, 50);
1193 RenderSurfaceLayerList render_surface_layer_list
;
1194 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1195 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1196 inputs
.can_adjust_raster_scales
= true;
1197 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1198 EXPECT_EQ(translate
, root
->draw_properties().target_space_transform
);
1199 EXPECT_EQ(translate
, child
->draw_properties().target_space_transform
);
1200 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1201 EXPECT_EQ(1.f
, root
->last_device_scale_factor());
1202 EXPECT_EQ(1.f
, child
->last_device_scale_factor());
1205 gfx::Transform scale
;
1208 RenderSurfaceLayerList render_surface_layer_list
;
1209 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1210 root
.get(), root
->bounds(), scale
, &render_surface_layer_list
);
1211 inputs
.can_adjust_raster_scales
= true;
1212 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1213 EXPECT_EQ(scale
, root
->draw_properties().target_space_transform
);
1214 EXPECT_EQ(scale
, child
->draw_properties().target_space_transform
);
1215 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1216 EXPECT_EQ(2.f
, root
->last_device_scale_factor());
1217 EXPECT_EQ(2.f
, child
->last_device_scale_factor());
1220 gfx::Transform rotate
;
1223 RenderSurfaceLayerList render_surface_layer_list
;
1224 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1225 root
.get(), root
->bounds(), rotate
, &render_surface_layer_list
);
1226 inputs
.can_adjust_raster_scales
= true;
1227 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1228 EXPECT_EQ(rotate
, root
->draw_properties().target_space_transform
);
1229 EXPECT_EQ(rotate
, child
->draw_properties().target_space_transform
);
1230 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1231 EXPECT_EQ(1.f
, root
->last_device_scale_factor());
1232 EXPECT_EQ(1.f
, child
->last_device_scale_factor());
1235 gfx::Transform composite
;
1236 composite
.ConcatTransform(translate
);
1237 composite
.ConcatTransform(scale
);
1238 composite
.ConcatTransform(rotate
);
1240 RenderSurfaceLayerList render_surface_layer_list
;
1241 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1242 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1243 inputs
.can_adjust_raster_scales
= true;
1244 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1245 EXPECT_EQ(composite
, root
->draw_properties().target_space_transform
);
1246 EXPECT_EQ(composite
, child
->draw_properties().target_space_transform
);
1247 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1250 // Verify it composes correctly with device scale.
1251 float device_scale_factor
= 1.5f
;
1254 RenderSurfaceLayerList render_surface_layer_list
;
1255 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1256 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1257 inputs
.device_scale_factor
= device_scale_factor
;
1258 inputs
.can_adjust_raster_scales
= true;
1259 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1260 gfx::Transform device_scaled_translate
= translate
;
1261 device_scaled_translate
.Scale(device_scale_factor
, device_scale_factor
);
1262 EXPECT_EQ(device_scaled_translate
,
1263 root
->draw_properties().target_space_transform
);
1264 EXPECT_EQ(device_scaled_translate
,
1265 child
->draw_properties().target_space_transform
);
1266 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1267 EXPECT_EQ(device_scale_factor
, root
->last_device_scale_factor());
1268 EXPECT_EQ(device_scale_factor
, child
->last_device_scale_factor());
1271 // Verify it composes correctly with page scale.
1272 float page_scale_factor
= 2.f
;
1275 RenderSurfaceLayerList render_surface_layer_list
;
1276 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1277 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1278 inputs
.page_scale_factor
= page_scale_factor
;
1279 inputs
.page_scale_application_layer
= root
.get();
1280 inputs
.can_adjust_raster_scales
= true;
1281 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1282 gfx::Transform page_scaled_translate
= translate
;
1283 page_scaled_translate
.Scale(page_scale_factor
, page_scale_factor
);
1284 EXPECT_EQ(translate
, root
->draw_properties().target_space_transform
);
1285 EXPECT_EQ(page_scaled_translate
,
1286 child
->draw_properties().target_space_transform
);
1287 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1288 EXPECT_EQ(1.f
, root
->last_device_scale_factor());
1289 EXPECT_EQ(1.f
, child
->last_device_scale_factor());
1292 // Verify that it composes correctly with transforms directly on root layer.
1293 root
->SetTransform(composite
);
1296 RenderSurfaceLayerList render_surface_layer_list
;
1297 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1298 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1299 inputs
.can_adjust_raster_scales
= true;
1300 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1301 gfx::Transform compositeSquared
= composite
;
1302 compositeSquared
.ConcatTransform(composite
);
1303 EXPECT_TRANSFORMATION_MATRIX_EQ(
1304 compositeSquared
, root
->draw_properties().target_space_transform
);
1305 EXPECT_TRANSFORMATION_MATRIX_EQ(
1306 compositeSquared
, child
->draw_properties().target_space_transform
);
1307 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1311 TEST_F(LayerTreeHostCommonTest
,
1312 RenderSurfaceListForRenderSurfaceWithClippedLayer
) {
1313 scoped_refptr
<Layer
> parent
= Layer::Create();
1314 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
1315 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1316 make_scoped_refptr(new LayerWithForcedDrawsContent());
1318 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1319 host
->SetRootLayer(parent
);
1321 const gfx::Transform identity_matrix
;
1322 SetLayerPropertiesForTesting(parent
.get(),
1329 SetLayerPropertiesForTesting(render_surface1
.get(),
1336 SetLayerPropertiesForTesting(child
.get(),
1339 gfx::PointF(30.f
, 30.f
),
1344 parent
->AddChild(render_surface1
);
1345 parent
->SetMasksToBounds(true);
1346 render_surface1
->AddChild(child
);
1347 render_surface1
->SetForceRenderSurface(true);
1349 RenderSurfaceLayerList render_surface_layer_list
;
1350 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1354 &render_surface_layer_list
);
1355 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1357 // The child layer's content is entirely outside the parent's clip rect, so
1358 // the intermediate render surface should not be listed here, even if it was
1359 // forced to be created. Render surfaces without children or visible content
1360 // are unexpected at draw time (e.g. we might try to create a content texture
1362 ASSERT_TRUE(parent
->render_surface());
1363 EXPECT_EQ(1U, render_surface_layer_list
.size());
1366 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceListForTransparentChild
) {
1367 scoped_refptr
<Layer
> parent
= Layer::Create();
1368 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
1369 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1370 make_scoped_refptr(new LayerWithForcedDrawsContent());
1372 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1373 host
->SetRootLayer(parent
);
1375 const gfx::Transform identity_matrix
;
1376 SetLayerPropertiesForTesting(render_surface1
.get(),
1383 SetLayerPropertiesForTesting(child
.get(),
1391 parent
->AddChild(render_surface1
);
1392 render_surface1
->AddChild(child
);
1393 render_surface1
->SetForceRenderSurface(true);
1394 render_surface1
->SetOpacity(0.f
);
1396 RenderSurfaceLayerList render_surface_layer_list
;
1397 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1398 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1399 inputs
.can_adjust_raster_scales
= true;
1400 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1402 // Since the layer is transparent, render_surface1->render_surface() should
1403 // not have gotten added anywhere. Also, the drawable content rect should not
1404 // have been extended by the children.
1405 ASSERT_TRUE(parent
->render_surface());
1406 EXPECT_EQ(0U, parent
->render_surface()->layer_list().size());
1407 EXPECT_EQ(1U, render_surface_layer_list
.size());
1408 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1409 EXPECT_EQ(gfx::Rect(), parent
->drawable_content_rect());
1412 TEST_F(LayerTreeHostCommonTest
, ForceRenderSurface
) {
1413 scoped_refptr
<Layer
> parent
= Layer::Create();
1414 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
1415 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1416 make_scoped_refptr(new LayerWithForcedDrawsContent());
1417 render_surface1
->SetForceRenderSurface(true);
1419 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1420 host
->SetRootLayer(parent
);
1422 const gfx::Transform identity_matrix
;
1423 SetLayerPropertiesForTesting(parent
.get(),
1430 SetLayerPropertiesForTesting(render_surface1
.get(),
1437 SetLayerPropertiesForTesting(child
.get(),
1445 parent
->AddChild(render_surface1
);
1446 render_surface1
->AddChild(child
);
1448 // Sanity check before the actual test
1449 EXPECT_FALSE(parent
->render_surface());
1450 EXPECT_FALSE(render_surface1
->render_surface());
1453 RenderSurfaceLayerList render_surface_layer_list
;
1454 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1455 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1456 inputs
.can_adjust_raster_scales
= true;
1457 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1459 // The root layer always creates a render surface
1460 EXPECT_TRUE(parent
->render_surface());
1461 EXPECT_TRUE(render_surface1
->render_surface());
1462 EXPECT_EQ(2U, render_surface_layer_list
.size());
1466 RenderSurfaceLayerList render_surface_layer_list
;
1467 render_surface1
->SetForceRenderSurface(false);
1468 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1469 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1470 inputs
.can_adjust_raster_scales
= true;
1471 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1472 EXPECT_TRUE(parent
->render_surface());
1473 EXPECT_FALSE(render_surface1
->render_surface());
1474 EXPECT_EQ(1U, render_surface_layer_list
.size());
1478 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsRenderSurfaces
) {
1479 // The entire subtree of layers that are outside the clip rect should be
1480 // culled away, and should not affect the render_surface_layer_list.
1482 // The test tree is set up as follows:
1483 // - all layers except the leaf_nodes are forced to be a new render surface
1484 // that have something to draw.
1485 // - parent is a large container layer.
1486 // - child has masksToBounds=true to cause clipping.
1487 // - grand_child is positioned outside of the child's bounds
1488 // - great_grand_child is also kept outside child's bounds.
1490 // In this configuration, grand_child and great_grand_child are completely
1491 // outside the clip rect, and they should never get scheduled on the list of
1495 const gfx::Transform identity_matrix
;
1496 scoped_refptr
<Layer
> parent
= Layer::Create();
1497 scoped_refptr
<Layer
> child
= Layer::Create();
1498 scoped_refptr
<Layer
> grand_child
= Layer::Create();
1499 scoped_refptr
<Layer
> great_grand_child
= Layer::Create();
1500 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1501 make_scoped_refptr(new LayerWithForcedDrawsContent());
1502 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1503 make_scoped_refptr(new LayerWithForcedDrawsContent());
1504 parent
->AddChild(child
);
1505 child
->AddChild(grand_child
);
1506 grand_child
->AddChild(great_grand_child
);
1508 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1509 host
->SetRootLayer(parent
);
1511 // leaf_node1 ensures that parent and child are kept on the
1512 // render_surface_layer_list, even though grand_child and great_grand_child
1513 // should be clipped.
1514 child
->AddChild(leaf_node1
);
1515 great_grand_child
->AddChild(leaf_node2
);
1517 SetLayerPropertiesForTesting(parent
.get(),
1521 gfx::Size(500, 500),
1524 SetLayerPropertiesForTesting(child
.get(),
1531 SetLayerPropertiesForTesting(grand_child
.get(),
1534 gfx::PointF(45.f
, 45.f
),
1538 SetLayerPropertiesForTesting(great_grand_child
.get(),
1545 SetLayerPropertiesForTesting(leaf_node1
.get(),
1549 gfx::Size(500, 500),
1552 SetLayerPropertiesForTesting(leaf_node2
.get(),
1560 child
->SetMasksToBounds(true);
1561 child
->SetOpacity(0.4f
);
1562 child
->SetForceRenderSurface(true);
1563 grand_child
->SetOpacity(0.5f
);
1564 great_grand_child
->SetOpacity(0.4f
);
1566 RenderSurfaceLayerList render_surface_layer_list
;
1567 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1568 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1569 inputs
.can_adjust_raster_scales
= true;
1570 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1572 ASSERT_EQ(2U, render_surface_layer_list
.size());
1573 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1574 EXPECT_EQ(child
->id(), render_surface_layer_list
.at(1)->id());
1577 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsSurfaceWithoutVisibleContent
) {
1578 // When a render surface has a clip rect, it is used to clip the content rect
1579 // of the surface. When the render surface is animating its transforms, then
1580 // the content rect's position in the clip rect is not defined on the main
1581 // thread, and its content rect should not be clipped.
1583 // The test tree is set up as follows:
1584 // - parent is a container layer that masksToBounds=true to cause clipping.
1585 // - child is a render surface, which has a clip rect set to the bounds of
1587 // - grand_child is a render surface, and the only visible content in child.
1588 // It is positioned outside of the clip rect from parent.
1590 // In this configuration, grand_child should be outside the clipped
1591 // content rect of the child, making grand_child not appear in the
1592 // render_surface_layer_list. However, when we place an animation on the
1593 // child, this clipping should be avoided and we should keep the grand_child
1594 // in the render_surface_layer_list.
1596 const gfx::Transform identity_matrix
;
1597 scoped_refptr
<Layer
> parent
= Layer::Create();
1598 scoped_refptr
<Layer
> child
= Layer::Create();
1599 scoped_refptr
<Layer
> grand_child
= Layer::Create();
1600 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node
=
1601 make_scoped_refptr(new LayerWithForcedDrawsContent());
1602 parent
->AddChild(child
);
1603 child
->AddChild(grand_child
);
1604 grand_child
->AddChild(leaf_node
);
1606 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1607 host
->SetRootLayer(parent
);
1609 SetLayerPropertiesForTesting(parent
.get(),
1613 gfx::Size(100, 100),
1616 SetLayerPropertiesForTesting(child
.get(),
1623 SetLayerPropertiesForTesting(grand_child
.get(),
1626 gfx::PointF(200.f
, 200.f
),
1630 SetLayerPropertiesForTesting(leaf_node
.get(),
1638 parent
->SetMasksToBounds(true);
1639 child
->SetOpacity(0.4f
);
1640 child
->SetForceRenderSurface(true);
1641 grand_child
->SetOpacity(0.4f
);
1642 grand_child
->SetForceRenderSurface(true);
1645 RenderSurfaceLayerList render_surface_layer_list
;
1646 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1647 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1648 inputs
.can_adjust_raster_scales
= true;
1649 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1651 // Without an animation, we should cull child and grand_child from the
1652 // render_surface_layer_list.
1653 ASSERT_EQ(1U, render_surface_layer_list
.size());
1654 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1657 // Now put an animating transform on child.
1658 AddAnimatedTransformToController(
1659 child
->layer_animation_controller(), 10.0, 30, 0);
1662 RenderSurfaceLayerList render_surface_layer_list
;
1663 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1664 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1665 inputs
.can_adjust_raster_scales
= true;
1666 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1668 // With an animating transform, we should keep child and grand_child in the
1669 // render_surface_layer_list.
1670 ASSERT_EQ(3U, render_surface_layer_list
.size());
1671 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1672 EXPECT_EQ(child
->id(), render_surface_layer_list
.at(1)->id());
1673 EXPECT_EQ(grand_child
->id(), render_surface_layer_list
.at(2)->id());
1677 TEST_F(LayerTreeHostCommonTest
, IsClippedIsSetCorrectly
) {
1678 // Layer's IsClipped() property is set to true when:
1679 // - the layer clips its subtree, e.g. masks to bounds,
1680 // - the layer is clipped by an ancestor that contributes to the same
1682 // - a surface is clipped by an ancestor that contributes to the same
1685 // In particular, for a layer that owns a render surface:
1686 // - the render surface inherits any clip from ancestors, and does NOT
1687 // pass that clipped status to the layer itself.
1688 // - but if the layer itself masks to bounds, it is considered clipped
1689 // and propagates the clip to the subtree.
1691 const gfx::Transform identity_matrix
;
1692 scoped_refptr
<Layer
> root
= Layer::Create();
1693 scoped_refptr
<Layer
> parent
= Layer::Create();
1694 scoped_refptr
<Layer
> child1
= Layer::Create();
1695 scoped_refptr
<Layer
> child2
= Layer::Create();
1696 scoped_refptr
<Layer
> grand_child
= Layer::Create();
1697 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1698 make_scoped_refptr(new LayerWithForcedDrawsContent());
1699 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1700 make_scoped_refptr(new LayerWithForcedDrawsContent());
1701 root
->AddChild(parent
);
1702 parent
->AddChild(child1
);
1703 parent
->AddChild(child2
);
1704 child1
->AddChild(grand_child
);
1705 child2
->AddChild(leaf_node2
);
1706 grand_child
->AddChild(leaf_node1
);
1708 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1709 host
->SetRootLayer(root
);
1711 child2
->SetForceRenderSurface(true);
1713 SetLayerPropertiesForTesting(root
.get(),
1717 gfx::Size(100, 100),
1720 SetLayerPropertiesForTesting(parent
.get(),
1724 gfx::Size(100, 100),
1727 SetLayerPropertiesForTesting(child1
.get(),
1731 gfx::Size(100, 100),
1734 SetLayerPropertiesForTesting(child2
.get(),
1738 gfx::Size(100, 100),
1741 SetLayerPropertiesForTesting(grand_child
.get(),
1745 gfx::Size(100, 100),
1748 SetLayerPropertiesForTesting(leaf_node1
.get(),
1752 gfx::Size(100, 100),
1755 SetLayerPropertiesForTesting(leaf_node2
.get(),
1759 gfx::Size(100, 100),
1763 // Case 1: nothing is clipped except the root render surface.
1765 RenderSurfaceLayerList render_surface_layer_list
;
1766 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1767 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1768 inputs
.can_adjust_raster_scales
= true;
1769 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1771 ASSERT_TRUE(root
->render_surface());
1772 ASSERT_TRUE(child2
->render_surface());
1774 EXPECT_FALSE(root
->is_clipped());
1775 EXPECT_TRUE(root
->render_surface()->is_clipped());
1776 EXPECT_FALSE(parent
->is_clipped());
1777 EXPECT_FALSE(child1
->is_clipped());
1778 EXPECT_FALSE(child2
->is_clipped());
1779 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1780 EXPECT_FALSE(grand_child
->is_clipped());
1781 EXPECT_FALSE(leaf_node1
->is_clipped());
1782 EXPECT_FALSE(leaf_node2
->is_clipped());
1785 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1786 // surface are clipped. But layers that contribute to child2's surface are
1787 // not clipped explicitly because child2's surface already accounts for
1790 RenderSurfaceLayerList render_surface_layer_list
;
1791 parent
->SetMasksToBounds(true);
1792 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1793 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1794 inputs
.can_adjust_raster_scales
= true;
1795 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1797 ASSERT_TRUE(root
->render_surface());
1798 ASSERT_TRUE(child2
->render_surface());
1800 EXPECT_FALSE(root
->is_clipped());
1801 EXPECT_TRUE(root
->render_surface()->is_clipped());
1802 EXPECT_TRUE(parent
->is_clipped());
1803 EXPECT_TRUE(child1
->is_clipped());
1804 EXPECT_FALSE(child2
->is_clipped());
1805 EXPECT_TRUE(child2
->render_surface()->is_clipped());
1806 EXPECT_TRUE(grand_child
->is_clipped());
1807 EXPECT_TRUE(leaf_node1
->is_clipped());
1808 EXPECT_FALSE(leaf_node2
->is_clipped());
1811 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1812 // child2's render surface is not clipped.
1814 RenderSurfaceLayerList render_surface_layer_list
;
1815 parent
->SetMasksToBounds(false);
1816 child2
->SetMasksToBounds(true);
1817 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1818 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1819 inputs
.can_adjust_raster_scales
= true;
1820 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1822 ASSERT_TRUE(root
->render_surface());
1823 ASSERT_TRUE(child2
->render_surface());
1825 EXPECT_FALSE(root
->is_clipped());
1826 EXPECT_TRUE(root
->render_surface()->is_clipped());
1827 EXPECT_FALSE(parent
->is_clipped());
1828 EXPECT_FALSE(child1
->is_clipped());
1829 EXPECT_TRUE(child2
->is_clipped());
1830 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1831 EXPECT_FALSE(grand_child
->is_clipped());
1832 EXPECT_FALSE(leaf_node1
->is_clipped());
1833 EXPECT_TRUE(leaf_node2
->is_clipped());
1837 TEST_F(LayerTreeHostCommonTest
, DrawableContentRectForLayers
) {
1838 // Verify that layers get the appropriate DrawableContentRect when their
1839 // parent masksToBounds is true.
1841 // grand_child1 - completely inside the region; DrawableContentRect should
1842 // be the layer rect expressed in target space.
1843 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1844 // will be the intersection of layer bounds and the mask region.
1845 // grand_child3 - partially clipped and masksToBounds; the
1846 // DrawableContentRect will still be the intersection of layer bounds and
1848 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1852 const gfx::Transform identity_matrix
;
1853 scoped_refptr
<Layer
> parent
= Layer::Create();
1854 scoped_refptr
<Layer
> child
= Layer::Create();
1855 scoped_refptr
<Layer
> grand_child1
= Layer::Create();
1856 scoped_refptr
<Layer
> grand_child2
= Layer::Create();
1857 scoped_refptr
<Layer
> grand_child3
= Layer::Create();
1858 scoped_refptr
<Layer
> grand_child4
= Layer::Create();
1860 parent
->AddChild(child
);
1861 child
->AddChild(grand_child1
);
1862 child
->AddChild(grand_child2
);
1863 child
->AddChild(grand_child3
);
1864 child
->AddChild(grand_child4
);
1866 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1867 host
->SetRootLayer(parent
);
1869 SetLayerPropertiesForTesting(parent
.get(),
1873 gfx::Size(500, 500),
1876 SetLayerPropertiesForTesting(child
.get(),
1883 SetLayerPropertiesForTesting(grand_child1
.get(),
1886 gfx::PointF(5.f
, 5.f
),
1890 SetLayerPropertiesForTesting(grand_child2
.get(),
1893 gfx::PointF(15.f
, 15.f
),
1897 SetLayerPropertiesForTesting(grand_child3
.get(),
1900 gfx::PointF(15.f
, 15.f
),
1904 SetLayerPropertiesForTesting(grand_child4
.get(),
1907 gfx::PointF(45.f
, 45.f
),
1912 child
->SetMasksToBounds(true);
1913 grand_child3
->SetMasksToBounds(true);
1915 // Force everyone to be a render surface.
1916 child
->SetOpacity(0.4f
);
1917 grand_child1
->SetOpacity(0.5f
);
1918 grand_child2
->SetOpacity(0.5f
);
1919 grand_child3
->SetOpacity(0.5f
);
1920 grand_child4
->SetOpacity(0.5f
);
1922 RenderSurfaceLayerList render_surface_layer_list
;
1923 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1924 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1925 inputs
.can_adjust_raster_scales
= true;
1926 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1928 EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10),
1929 grand_child1
->drawable_content_rect());
1930 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
1931 grand_child3
->drawable_content_rect());
1932 EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5),
1933 grand_child3
->drawable_content_rect());
1934 EXPECT_TRUE(grand_child4
->drawable_content_rect().IsEmpty());
1937 TEST_F(LayerTreeHostCommonTest
, ClipRectIsPropagatedCorrectlyToSurfaces
) {
1938 // Verify that render surfaces (and their layers) get the appropriate
1939 // clip rects when their parent masksToBounds is true.
1941 // Layers that own render surfaces (at least for now) do not inherit any
1942 // clipping; instead the surface will enforce the clip for the entire subtree.
1943 // They may still have a clip rect of their own layer bounds, however, if
1944 // masksToBounds was true.
1945 const gfx::Transform identity_matrix
;
1946 scoped_refptr
<Layer
> parent
= Layer::Create();
1947 scoped_refptr
<Layer
> child
= Layer::Create();
1948 scoped_refptr
<Layer
> grand_child1
= Layer::Create();
1949 scoped_refptr
<Layer
> grand_child2
= Layer::Create();
1950 scoped_refptr
<Layer
> grand_child3
= Layer::Create();
1951 scoped_refptr
<Layer
> grand_child4
= Layer::Create();
1952 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1953 make_scoped_refptr(new LayerWithForcedDrawsContent());
1954 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1955 make_scoped_refptr(new LayerWithForcedDrawsContent());
1956 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node3
=
1957 make_scoped_refptr(new LayerWithForcedDrawsContent());
1958 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node4
=
1959 make_scoped_refptr(new LayerWithForcedDrawsContent());
1961 parent
->AddChild(child
);
1962 child
->AddChild(grand_child1
);
1963 child
->AddChild(grand_child2
);
1964 child
->AddChild(grand_child3
);
1965 child
->AddChild(grand_child4
);
1967 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
1968 host
->SetRootLayer(parent
);
1970 // the leaf nodes ensure that these grand_children become render surfaces for
1972 grand_child1
->AddChild(leaf_node1
);
1973 grand_child2
->AddChild(leaf_node2
);
1974 grand_child3
->AddChild(leaf_node3
);
1975 grand_child4
->AddChild(leaf_node4
);
1977 SetLayerPropertiesForTesting(parent
.get(),
1981 gfx::Size(500, 500),
1984 SetLayerPropertiesForTesting(child
.get(),
1991 SetLayerPropertiesForTesting(grand_child1
.get(),
1994 gfx::PointF(5.f
, 5.f
),
1998 SetLayerPropertiesForTesting(grand_child2
.get(),
2001 gfx::PointF(15.f
, 15.f
),
2005 SetLayerPropertiesForTesting(grand_child3
.get(),
2008 gfx::PointF(15.f
, 15.f
),
2012 SetLayerPropertiesForTesting(grand_child4
.get(),
2015 gfx::PointF(45.f
, 45.f
),
2019 SetLayerPropertiesForTesting(leaf_node1
.get(),
2026 SetLayerPropertiesForTesting(leaf_node2
.get(),
2033 SetLayerPropertiesForTesting(leaf_node3
.get(),
2040 SetLayerPropertiesForTesting(leaf_node4
.get(),
2048 child
->SetMasksToBounds(true);
2049 grand_child3
->SetMasksToBounds(true);
2050 grand_child4
->SetMasksToBounds(true);
2052 // Force everyone to be a render surface.
2053 child
->SetOpacity(0.4f
);
2054 child
->SetForceRenderSurface(true);
2055 grand_child1
->SetOpacity(0.5f
);
2056 grand_child1
->SetForceRenderSurface(true);
2057 grand_child2
->SetOpacity(0.5f
);
2058 grand_child2
->SetForceRenderSurface(true);
2059 grand_child3
->SetOpacity(0.5f
);
2060 grand_child3
->SetForceRenderSurface(true);
2061 grand_child4
->SetOpacity(0.5f
);
2062 grand_child4
->SetForceRenderSurface(true);
2064 RenderSurfaceLayerList render_surface_layer_list
;
2065 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
2066 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
2067 inputs
.can_adjust_raster_scales
= true;
2068 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
2069 ASSERT_TRUE(grand_child1
->render_surface());
2070 ASSERT_TRUE(grand_child2
->render_surface());
2071 ASSERT_TRUE(grand_child3
->render_surface());
2073 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2075 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
2076 grand_child1
->render_surface()->clip_rect());
2077 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
2078 grand_child2
->render_surface()->clip_rect());
2079 EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20),
2080 grand_child3
->render_surface()->clip_rect());
2083 TEST_F(LayerTreeHostCommonTest
, AnimationsForRenderSurfaceHierarchy
) {
2084 scoped_refptr
<Layer
> parent
= Layer::Create();
2085 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
2086 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
2087 scoped_refptr
<Layer
> child_of_root
= Layer::Create();
2088 scoped_refptr
<Layer
> child_of_rs1
= Layer::Create();
2089 scoped_refptr
<Layer
> child_of_rs2
= Layer::Create();
2090 scoped_refptr
<Layer
> grand_child_of_root
= Layer::Create();
2091 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs1
=
2092 make_scoped_refptr(new LayerWithForcedDrawsContent());
2093 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs2
=
2094 make_scoped_refptr(new LayerWithForcedDrawsContent());
2095 parent
->AddChild(render_surface1
);
2096 parent
->AddChild(child_of_root
);
2097 render_surface1
->AddChild(child_of_rs1
);
2098 render_surface1
->AddChild(render_surface2
);
2099 render_surface2
->AddChild(child_of_rs2
);
2100 child_of_root
->AddChild(grand_child_of_root
);
2101 child_of_rs1
->AddChild(grand_child_of_rs1
);
2102 child_of_rs2
->AddChild(grand_child_of_rs2
);
2104 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
2105 host
->SetRootLayer(parent
);
2107 // Make our render surfaces.
2108 render_surface1
->SetForceRenderSurface(true);
2109 render_surface2
->SetForceRenderSurface(true);
2111 gfx::Transform layer_transform
;
2112 layer_transform
.Translate(1.0, 1.0);
2114 SetLayerPropertiesForTesting(parent
.get(),
2116 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2117 gfx::PointF(2.5f
, 0.f
),
2121 SetLayerPropertiesForTesting(render_surface1
.get(),
2123 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2124 gfx::PointF(2.5f
, 0.f
),
2128 SetLayerPropertiesForTesting(render_surface2
.get(),
2130 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2131 gfx::PointF(2.5f
, 0.f
),
2135 SetLayerPropertiesForTesting(child_of_root
.get(),
2137 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2138 gfx::PointF(2.5f
, 0.f
),
2142 SetLayerPropertiesForTesting(child_of_rs1
.get(),
2144 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2145 gfx::PointF(2.5f
, 0.f
),
2149 SetLayerPropertiesForTesting(child_of_rs2
.get(),
2151 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2152 gfx::PointF(2.5f
, 0.f
),
2156 SetLayerPropertiesForTesting(grand_child_of_root
.get(),
2158 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2159 gfx::PointF(2.5f
, 0.f
),
2163 SetLayerPropertiesForTesting(grand_child_of_rs1
.get(),
2165 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2166 gfx::PointF(2.5f
, 0.f
),
2170 SetLayerPropertiesForTesting(grand_child_of_rs2
.get(),
2172 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2173 gfx::PointF(2.5f
, 0.f
),
2178 // Put an animated opacity on the render surface.
2179 AddOpacityTransitionToController(
2180 render_surface1
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2182 // Also put an animated opacity on a layer without descendants.
2183 AddOpacityTransitionToController(
2184 grand_child_of_root
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2186 // Put a transform animation on the render surface.
2187 AddAnimatedTransformToController(
2188 render_surface2
->layer_animation_controller(), 10.0, 30, 0);
2190 // Also put transform animations on grand_child_of_root, and
2191 // grand_child_of_rs2
2192 AddAnimatedTransformToController(
2193 grand_child_of_root
->layer_animation_controller(), 10.0, 30, 0);
2194 AddAnimatedTransformToController(
2195 grand_child_of_rs2
->layer_animation_controller(), 10.0, 30, 0);
2197 ExecuteCalculateDrawProperties(parent
.get());
2199 // Only layers that are associated with render surfaces should have an actual
2200 // RenderSurface() value.
2201 ASSERT_TRUE(parent
->render_surface());
2202 ASSERT_FALSE(child_of_root
->render_surface());
2203 ASSERT_FALSE(grand_child_of_root
->render_surface());
2205 ASSERT_TRUE(render_surface1
->render_surface());
2206 ASSERT_FALSE(child_of_rs1
->render_surface());
2207 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
2209 ASSERT_TRUE(render_surface2
->render_surface());
2210 ASSERT_FALSE(child_of_rs2
->render_surface());
2211 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
2213 // Verify all render target accessors
2214 EXPECT_EQ(parent
, parent
->render_target());
2215 EXPECT_EQ(parent
, child_of_root
->render_target());
2216 EXPECT_EQ(parent
, grand_child_of_root
->render_target());
2218 EXPECT_EQ(render_surface1
, render_surface1
->render_target());
2219 EXPECT_EQ(render_surface1
, child_of_rs1
->render_target());
2220 EXPECT_EQ(render_surface1
, grand_child_of_rs1
->render_target());
2222 EXPECT_EQ(render_surface2
, render_surface2
->render_target());
2223 EXPECT_EQ(render_surface2
, child_of_rs2
->render_target());
2224 EXPECT_EQ(render_surface2
, grand_child_of_rs2
->render_target());
2226 // Verify draw_opacity_is_animating values
2227 EXPECT_FALSE(parent
->draw_opacity_is_animating());
2228 EXPECT_FALSE(child_of_root
->draw_opacity_is_animating());
2229 EXPECT_TRUE(grand_child_of_root
->draw_opacity_is_animating());
2230 EXPECT_FALSE(render_surface1
->draw_opacity_is_animating());
2231 EXPECT_TRUE(render_surface1
->render_surface()->draw_opacity_is_animating());
2232 EXPECT_FALSE(child_of_rs1
->draw_opacity_is_animating());
2233 EXPECT_FALSE(grand_child_of_rs1
->draw_opacity_is_animating());
2234 EXPECT_FALSE(render_surface2
->draw_opacity_is_animating());
2235 EXPECT_FALSE(render_surface2
->render_surface()->draw_opacity_is_animating());
2236 EXPECT_FALSE(child_of_rs2
->draw_opacity_is_animating());
2237 EXPECT_FALSE(grand_child_of_rs2
->draw_opacity_is_animating());
2239 // Verify draw_transform_is_animating values
2240 EXPECT_FALSE(parent
->draw_transform_is_animating());
2241 EXPECT_FALSE(child_of_root
->draw_transform_is_animating());
2242 EXPECT_TRUE(grand_child_of_root
->draw_transform_is_animating());
2243 EXPECT_FALSE(render_surface1
->draw_transform_is_animating());
2244 EXPECT_FALSE(render_surface1
->render_surface()
2245 ->target_surface_transforms_are_animating());
2246 EXPECT_FALSE(child_of_rs1
->draw_transform_is_animating());
2247 EXPECT_FALSE(grand_child_of_rs1
->draw_transform_is_animating());
2248 EXPECT_FALSE(render_surface2
->draw_transform_is_animating());
2249 EXPECT_TRUE(render_surface2
->render_surface()
2250 ->target_surface_transforms_are_animating());
2251 EXPECT_FALSE(child_of_rs2
->draw_transform_is_animating());
2252 EXPECT_TRUE(grand_child_of_rs2
->draw_transform_is_animating());
2254 // Verify screen_space_transform_is_animating values
2255 EXPECT_FALSE(parent
->screen_space_transform_is_animating());
2256 EXPECT_FALSE(child_of_root
->screen_space_transform_is_animating());
2257 EXPECT_TRUE(grand_child_of_root
->screen_space_transform_is_animating());
2258 EXPECT_FALSE(render_surface1
->screen_space_transform_is_animating());
2259 EXPECT_FALSE(render_surface1
->render_surface()
2260 ->screen_space_transforms_are_animating());
2261 EXPECT_FALSE(child_of_rs1
->screen_space_transform_is_animating());
2262 EXPECT_FALSE(grand_child_of_rs1
->screen_space_transform_is_animating());
2263 EXPECT_TRUE(render_surface2
->screen_space_transform_is_animating());
2264 EXPECT_TRUE(render_surface2
->render_surface()
2265 ->screen_space_transforms_are_animating());
2266 EXPECT_TRUE(child_of_rs2
->screen_space_transform_is_animating());
2267 EXPECT_TRUE(grand_child_of_rs2
->screen_space_transform_is_animating());
2269 // Sanity check. If these fail there is probably a bug in the test itself.
2270 // It is expected that we correctly set up transforms so that the y-component
2271 // of the screen-space transform encodes the "depth" of the layer in the tree.
2272 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
2273 EXPECT_FLOAT_EQ(2.0,
2274 child_of_root
->screen_space_transform().matrix().get(1, 3));
2276 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
2278 EXPECT_FLOAT_EQ(2.0,
2279 render_surface1
->screen_space_transform().matrix().get(1, 3));
2280 EXPECT_FLOAT_EQ(3.0,
2281 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2283 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2285 EXPECT_FLOAT_EQ(3.0,
2286 render_surface2
->screen_space_transform().matrix().get(1, 3));
2287 EXPECT_FLOAT_EQ(4.0,
2288 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2290 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2293 TEST_F(LayerTreeHostCommonTest
, VisibleRectForIdentityTransform
) {
2294 // Test the calculateVisibleRect() function works correctly for identity
2297 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2298 gfx::Transform layer_to_surface_transform
;
2300 // Case 1: Layer is contained within the surface.
2301 gfx::Rect layer_content_rect
= gfx::Rect(10, 10, 30, 30);
2302 gfx::Rect expected
= gfx::Rect(10, 10, 30, 30);
2303 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2304 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2305 EXPECT_RECT_EQ(expected
, actual
);
2307 // Case 2: Layer is outside the surface rect.
2308 layer_content_rect
= gfx::Rect(120, 120, 30, 30);
2309 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2310 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2311 EXPECT_TRUE(actual
.IsEmpty());
2313 // Case 3: Layer is partially overlapping the surface rect.
2314 layer_content_rect
= gfx::Rect(80, 80, 30, 30);
2315 expected
= gfx::Rect(80, 80, 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
, VisibleRectForTranslations
) {
2322 // Test the calculateVisibleRect() function works correctly for scaling
2325 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2326 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2327 gfx::Transform layer_to_surface_transform
;
2329 // Case 1: Layer is contained within the surface.
2330 layer_to_surface_transform
.MakeIdentity();
2331 layer_to_surface_transform
.Translate(10.0, 10.0);
2332 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2333 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2334 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2335 EXPECT_RECT_EQ(expected
, actual
);
2337 // Case 2: Layer is outside the surface rect.
2338 layer_to_surface_transform
.MakeIdentity();
2339 layer_to_surface_transform
.Translate(120.0, 120.0);
2340 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2341 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2342 EXPECT_TRUE(actual
.IsEmpty());
2344 // Case 3: Layer is partially overlapping the surface rect.
2345 layer_to_surface_transform
.MakeIdentity();
2346 layer_to_surface_transform
.Translate(80.0, 80.0);
2347 expected
= gfx::Rect(0, 0, 20, 20);
2348 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2349 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2350 EXPECT_RECT_EQ(expected
, actual
);
2353 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor2DRotations
) {
2354 // Test the calculateVisibleRect() function works correctly for rotations
2355 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2356 // should return the g in the layer's space.
2358 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2359 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2360 gfx::Transform layer_to_surface_transform
;
2362 // Case 1: Layer is contained within the surface.
2363 layer_to_surface_transform
.MakeIdentity();
2364 layer_to_surface_transform
.Translate(50.0, 50.0);
2365 layer_to_surface_transform
.Rotate(45.0);
2366 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2367 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2368 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2369 EXPECT_RECT_EQ(expected
, actual
);
2371 // Case 2: Layer is outside the surface rect.
2372 layer_to_surface_transform
.MakeIdentity();
2373 layer_to_surface_transform
.Translate(-50.0, 0.0);
2374 layer_to_surface_transform
.Rotate(45.0);
2375 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2376 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2377 EXPECT_TRUE(actual
.IsEmpty());
2379 // Case 3: The layer is rotated about its top-left corner. In surface space,
2380 // the layer is oriented diagonally, with the left half outside of the render
2381 // surface. In this case, the g should still be the entire layer
2382 // (remember the g is computed in layer space); both the top-left
2383 // and bottom-right corners of the layer are still visible.
2384 layer_to_surface_transform
.MakeIdentity();
2385 layer_to_surface_transform
.Rotate(45.0);
2386 expected
= gfx::Rect(0, 0, 30, 30);
2387 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2388 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2389 EXPECT_RECT_EQ(expected
, actual
);
2391 // Case 4: The layer is rotated about its top-left corner, and translated
2392 // upwards. In surface space, the layer is oriented diagonally, with only the
2393 // top corner of the surface overlapping the layer. In layer space, the render
2394 // surface overlaps the right side of the layer. The g should be
2395 // the layer's right half.
2396 layer_to_surface_transform
.MakeIdentity();
2397 layer_to_surface_transform
.Translate(0.0, -sqrt(2.0) * 15.0);
2398 layer_to_surface_transform
.Rotate(45.0);
2399 expected
= gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
2400 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2401 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2402 EXPECT_RECT_EQ(expected
, actual
);
2405 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dOrthographicTransform
) {
2406 // Test that the calculateVisibleRect() function works correctly for 3d
2409 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2410 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2411 gfx::Transform layer_to_surface_transform
;
2413 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2414 // degrees, should be fully contained in the render surface.
2415 layer_to_surface_transform
.MakeIdentity();
2416 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2417 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2418 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2419 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2420 EXPECT_RECT_EQ(expected
, actual
);
2422 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2423 // degrees, but shifted to the side so only the right-half the layer would be
2424 // visible on the surface.
2425 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2426 SkMScalar half_width_of_rotated_layer
=
2427 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
2428 layer_to_surface_transform
.MakeIdentity();
2429 layer_to_surface_transform
.Translate(-half_width_of_rotated_layer
, 0.0);
2430 layer_to_surface_transform
.RotateAboutYAxis(45.0); // Rotates about the left
2431 // edge of the layer.
2432 expected
= gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
2433 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2434 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2435 EXPECT_RECT_EQ(expected
, actual
);
2438 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveTransform
) {
2439 // Test the calculateVisibleRect() function works correctly when the layer has
2440 // a perspective projection onto the target surface.
2442 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2443 gfx::Rect layer_content_rect
= gfx::Rect(-50, -50, 200, 200);
2444 gfx::Transform layer_to_surface_transform
;
2446 // Case 1: Even though the layer is twice as large as the surface, due to
2447 // perspective foreshortening, the layer will fit fully in the surface when
2448 // its translated more than the perspective amount.
2449 layer_to_surface_transform
.MakeIdentity();
2451 // The following sequence of transforms applies the perspective about the
2452 // center of the surface.
2453 layer_to_surface_transform
.Translate(50.0, 50.0);
2454 layer_to_surface_transform
.ApplyPerspectiveDepth(9.0);
2455 layer_to_surface_transform
.Translate(-50.0, -50.0);
2457 // This translate places the layer in front of the surface's projection plane.
2458 layer_to_surface_transform
.Translate3d(0.0, 0.0, -27.0);
2460 gfx::Rect expected
= gfx::Rect(-50, -50, 200, 200);
2461 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2462 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2463 EXPECT_RECT_EQ(expected
, actual
);
2465 // Case 2: same projection as before, except that the layer is also translated
2466 // to the side, so that only the right half of the layer should be visible.
2468 // Explanation of expected result: The perspective ratio is (z distance
2469 // between layer and camera origin) / (z distance between projection plane and
2470 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2471 // move a layer by translating -50 units in projected surface units (so that
2472 // only half of it is visible), then we would need to translate by (-36 / 9) *
2473 // -50 == -200 in the layer's units.
2474 layer_to_surface_transform
.Translate3d(-200.0, 0.0, 0.0);
2475 expected
= gfx::Rect(gfx::Point(50, -50),
2476 gfx::Size(100, 200)); // The right half of the layer's
2478 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2479 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2480 EXPECT_RECT_EQ(expected
, actual
);
2483 TEST_F(LayerTreeHostCommonTest
,
2484 VisibleRectFor3dOrthographicIsNotClippedBehindSurface
) {
2485 // There is currently no explicit concept of an orthographic projection plane
2486 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2487 // are technically behind the surface in an orthographic world should not be
2488 // clipped when they are flattened to the surface.
2490 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2491 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2492 gfx::Transform layer_to_surface_transform
;
2494 // This sequence of transforms effectively rotates the layer about the y-axis
2495 // at the center of the layer.
2496 layer_to_surface_transform
.MakeIdentity();
2497 layer_to_surface_transform
.Translate(50.0, 0.0);
2498 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2499 layer_to_surface_transform
.Translate(-50.0, 0.0);
2501 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2502 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2503 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2504 EXPECT_RECT_EQ(expected
, actual
);
2507 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveWhenClippedByW
) {
2508 // Test the calculateVisibleRect() function works correctly when projecting a
2509 // surface onto a layer, but the layer is partially behind the camera (not
2510 // just behind the projection plane). In this case, the cartesian coordinates
2511 // may seem to be valid, but actually they are not. The visible rect needs to
2512 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2513 // converting to cartesian coordinates.
2515 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2516 gfx::Rect layer_content_rect
= gfx::Rect(-10, -1, 20, 2);
2517 gfx::Transform layer_to_surface_transform
;
2519 // The layer is positioned so that the right half of the layer should be in
2520 // front of the camera, while the other half is behind the surface's
2521 // projection plane. The following sequence of transforms applies the
2522 // perspective and rotation about the center of the layer.
2523 layer_to_surface_transform
.MakeIdentity();
2524 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2525 layer_to_surface_transform
.Translate3d(-2.0, 0.0, 1.0);
2526 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2528 // Sanity check that this transform does indeed cause w < 0 when applying the
2529 // transform, otherwise this code is not testing the intended scenario.
2531 MathUtil::MapQuad(layer_to_surface_transform
,
2532 gfx::QuadF(gfx::RectF(layer_content_rect
)),
2534 ASSERT_TRUE(clipped
);
2536 int expected_x_position
= 0;
2537 int expected_width
= 10;
2538 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2539 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2540 EXPECT_EQ(expected_x_position
, actual
.x());
2541 EXPECT_EQ(expected_width
, actual
.width());
2544 TEST_F(LayerTreeHostCommonTest
, VisibleRectForPerspectiveUnprojection
) {
2545 // To determine visible rect in layer space, there needs to be an
2546 // un-projection from surface space to layer space. When the original
2547 // transform was a perspective projection that was clipped, it returns a rect
2548 // that encloses the clipped bounds. Un-projecting this new rect may require
2551 // This sequence of transforms causes one corner of the layer to protrude
2552 // across the w = 0 plane, and should be clipped.
2553 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2554 gfx::Rect layer_content_rect
= gfx::Rect(-10, -10, 20, 20);
2555 gfx::Transform layer_to_surface_transform
;
2556 layer_to_surface_transform
.MakeIdentity();
2557 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2558 layer_to_surface_transform
.Translate3d(0.0, 0.0, -5.0);
2559 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2560 layer_to_surface_transform
.RotateAboutXAxis(80.0);
2562 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2563 // code is not testing the intended scenario.
2565 gfx::RectF clipped_rect
=
2566 MathUtil::MapClippedRect(layer_to_surface_transform
, layer_content_rect
);
2567 MathUtil::ProjectQuad(
2568 Inverse(layer_to_surface_transform
), gfx::QuadF(clipped_rect
), &clipped
);
2569 ASSERT_TRUE(clipped
);
2571 // Only the corner of the layer is not visible on the surface because of being
2572 // clipped. But, the net result of rounding visible region to an axis-aligned
2573 // rect is that the entire layer should still be considered visible.
2574 gfx::Rect expected
= gfx::Rect(-10, -10, 20, 20);
2575 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2576 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2577 EXPECT_RECT_EQ(expected
, actual
);
2580 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsForSimpleLayers
) {
2581 scoped_refptr
<Layer
> root
= Layer::Create();
2582 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2583 make_scoped_refptr(new LayerWithForcedDrawsContent());
2584 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2585 make_scoped_refptr(new LayerWithForcedDrawsContent());
2586 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2587 make_scoped_refptr(new LayerWithForcedDrawsContent());
2588 root
->AddChild(child1
);
2589 root
->AddChild(child2
);
2590 root
->AddChild(child3
);
2592 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
2593 host
->SetRootLayer(root
);
2595 gfx::Transform identity_matrix
;
2596 SetLayerPropertiesForTesting(root
.get(),
2600 gfx::Size(100, 100),
2603 SetLayerPropertiesForTesting(child1
.get(),
2610 SetLayerPropertiesForTesting(child2
.get(),
2613 gfx::PointF(75.f
, 75.f
),
2617 SetLayerPropertiesForTesting(child3
.get(),
2620 gfx::PointF(125.f
, 125.f
),
2625 ExecuteCalculateDrawProperties(root
.get());
2627 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2628 root
->render_surface()->DrawableContentRect());
2629 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2631 // Layers that do not draw content should have empty visible_content_rects.
2632 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2634 // layer visible_content_rects are clipped by their target surface.
2635 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
2636 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_content_rect());
2637 EXPECT_TRUE(child3
->visible_content_rect().IsEmpty());
2639 // layer drawable_content_rects are not clipped.
2640 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->drawable_content_rect());
2641 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2642 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2645 TEST_F(LayerTreeHostCommonTest
,
2646 DrawableAndVisibleContentRectsForLayersClippedByLayer
) {
2647 scoped_refptr
<Layer
> root
= Layer::Create();
2648 scoped_refptr
<Layer
> child
= Layer::Create();
2649 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child1
=
2650 make_scoped_refptr(new LayerWithForcedDrawsContent());
2651 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child2
=
2652 make_scoped_refptr(new LayerWithForcedDrawsContent());
2653 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child3
=
2654 make_scoped_refptr(new LayerWithForcedDrawsContent());
2655 root
->AddChild(child
);
2656 child
->AddChild(grand_child1
);
2657 child
->AddChild(grand_child2
);
2658 child
->AddChild(grand_child3
);
2660 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
2661 host
->SetRootLayer(root
);
2663 gfx::Transform identity_matrix
;
2664 SetLayerPropertiesForTesting(root
.get(),
2668 gfx::Size(100, 100),
2671 SetLayerPropertiesForTesting(child
.get(),
2675 gfx::Size(100, 100),
2678 SetLayerPropertiesForTesting(grand_child1
.get(),
2681 gfx::PointF(5.f
, 5.f
),
2685 SetLayerPropertiesForTesting(grand_child2
.get(),
2688 gfx::PointF(75.f
, 75.f
),
2692 SetLayerPropertiesForTesting(grand_child3
.get(),
2695 gfx::PointF(125.f
, 125.f
),
2700 child
->SetMasksToBounds(true);
2701 ExecuteCalculateDrawProperties(root
.get());
2703 ASSERT_FALSE(child
->render_surface());
2705 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2706 root
->render_surface()->DrawableContentRect());
2707 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2709 // Layers that do not draw content should have empty visible content rects.
2710 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2711 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child
->visible_content_rect());
2713 // All grandchild visible content rects should be clipped by child.
2714 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1
->visible_content_rect());
2715 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2
->visible_content_rect());
2716 EXPECT_TRUE(grand_child3
->visible_content_rect().IsEmpty());
2718 // All grandchild DrawableContentRects should also be clipped by child.
2719 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50),
2720 grand_child1
->drawable_content_rect());
2721 EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25),
2722 grand_child2
->drawable_content_rect());
2723 EXPECT_TRUE(grand_child3
->drawable_content_rect().IsEmpty());
2726 TEST_F(LayerTreeHostCommonTest
,
2727 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface
) {
2728 scoped_refptr
<Layer
> root
= Layer::Create();
2729 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
2730 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2731 make_scoped_refptr(new LayerWithForcedDrawsContent());
2732 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2733 make_scoped_refptr(new LayerWithForcedDrawsContent());
2734 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2735 make_scoped_refptr(new LayerWithForcedDrawsContent());
2736 root
->AddChild(render_surface1
);
2737 render_surface1
->AddChild(child1
);
2738 render_surface1
->AddChild(child2
);
2739 render_surface1
->AddChild(child3
);
2741 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
2742 host
->SetRootLayer(root
);
2744 gfx::Transform identity_matrix
;
2745 SetLayerPropertiesForTesting(root
.get(),
2749 gfx::Size(100, 100),
2752 SetLayerPropertiesForTesting(render_surface1
.get(),
2759 SetLayerPropertiesForTesting(child1
.get(),
2762 gfx::PointF(5.f
, 5.f
),
2766 SetLayerPropertiesForTesting(child2
.get(),
2769 gfx::PointF(75.f
, 75.f
),
2773 SetLayerPropertiesForTesting(child3
.get(),
2776 gfx::PointF(125.f
, 125.f
),
2781 render_surface1
->SetForceRenderSurface(true);
2782 ExecuteCalculateDrawProperties(root
.get());
2784 ASSERT_TRUE(render_surface1
->render_surface());
2786 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
2787 root
->render_surface()->DrawableContentRect());
2788 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2790 // Layers that do not draw content should have empty visible content rects.
2791 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2792 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
2793 render_surface1
->visible_content_rect());
2795 // An unclipped surface grows its DrawableContentRect to include all drawable
2796 // regions of the subtree.
2797 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
2798 render_surface1
->render_surface()->DrawableContentRect());
2800 // All layers that draw content into the unclipped surface are also unclipped.
2801 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
2802 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
2803 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
2805 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2806 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2807 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2810 TEST_F(LayerTreeHostCommonTest
,
2811 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform
) {
2812 scoped_refptr
<Layer
> root
= Layer::Create();
2813 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2814 make_scoped_refptr(new LayerWithForcedDrawsContent());
2815 root
->AddChild(child
);
2817 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
2818 host
->SetRootLayer(root
);
2820 // Case 1: a truly degenerate matrix
2821 gfx::Transform identity_matrix
;
2822 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2823 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2825 SetLayerPropertiesForTesting(root
.get(),
2829 gfx::Size(100, 100),
2832 SetLayerPropertiesForTesting(child
.get(),
2833 uninvertible_matrix
,
2835 gfx::PointF(5.f
, 5.f
),
2840 ExecuteCalculateDrawProperties(root
.get());
2842 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
2843 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2845 // Case 2: a matrix with flattened z, uninvertible and not visible according
2847 uninvertible_matrix
.MakeIdentity();
2848 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2849 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2851 SetLayerPropertiesForTesting(child
.get(),
2852 uninvertible_matrix
,
2854 gfx::PointF(5.f
, 5.f
),
2859 ExecuteCalculateDrawProperties(root
.get());
2861 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
2862 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2864 // Case 3: a matrix with flattened z, also uninvertible and not visible.
2865 uninvertible_matrix
.MakeIdentity();
2866 uninvertible_matrix
.Translate(500.0, 0.0);
2867 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2868 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2870 SetLayerPropertiesForTesting(child
.get(),
2871 uninvertible_matrix
,
2873 gfx::PointF(5.f
, 5.f
),
2878 ExecuteCalculateDrawProperties(root
.get());
2880 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
2881 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2884 TEST_F(LayerTreeHostCommonTest
,
2885 SingularTransformDoesNotPreventClearingDrawProperties
) {
2886 scoped_refptr
<Layer
> root
= Layer::Create();
2887 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2888 make_scoped_refptr(new LayerWithForcedDrawsContent());
2889 root
->AddChild(child
);
2891 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
2892 host
->SetRootLayer(root
);
2894 gfx::Transform identity_matrix
;
2895 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2896 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2898 SetLayerPropertiesForTesting(root
.get(),
2899 uninvertible_matrix
,
2902 gfx::Size(100, 100),
2905 SetLayerPropertiesForTesting(child
.get(),
2908 gfx::PointF(5.f
, 5.f
),
2913 child
->draw_properties().sorted_for_recursion
= true;
2915 TransformOperations start_transform_operations
;
2916 start_transform_operations
.AppendScale(1.f
, 0.f
, 0.f
);
2918 TransformOperations end_transform_operations
;
2919 end_transform_operations
.AppendScale(1.f
, 1.f
, 0.f
);
2921 AddAnimatedTransformToLayer(
2922 root
.get(), 10.0, start_transform_operations
, end_transform_operations
);
2924 EXPECT_TRUE(root
->TransformIsAnimating());
2926 ExecuteCalculateDrawProperties(root
.get());
2928 EXPECT_FALSE(child
->draw_properties().sorted_for_recursion
);
2931 TEST_F(LayerTreeHostCommonTest
,
2932 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties
) {
2933 scoped_refptr
<Layer
> root
= Layer::Create();
2935 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
2936 host
->SetRootLayer(root
);
2938 gfx::Transform identity_matrix
;
2939 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2940 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2942 SetLayerPropertiesForTesting(root
.get(),
2943 uninvertible_matrix
,
2946 gfx::Size(100, 100),
2950 root
->draw_properties().sorted_for_recursion
= true;
2952 EXPECT_FALSE(root
->TransformIsAnimating());
2954 ExecuteCalculateDrawProperties(root
.get());
2956 EXPECT_FALSE(root
->draw_properties().sorted_for_recursion
);
2959 TEST_F(LayerTreeHostCommonTest
,
2960 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface
) {
2961 scoped_refptr
<Layer
> root
= Layer::Create();
2962 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
2963 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2964 make_scoped_refptr(new LayerWithForcedDrawsContent());
2965 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2966 make_scoped_refptr(new LayerWithForcedDrawsContent());
2967 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2968 make_scoped_refptr(new LayerWithForcedDrawsContent());
2969 root
->AddChild(render_surface1
);
2970 render_surface1
->AddChild(child1
);
2971 render_surface1
->AddChild(child2
);
2972 render_surface1
->AddChild(child3
);
2974 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
2975 host
->SetRootLayer(root
);
2977 gfx::Transform identity_matrix
;
2978 SetLayerPropertiesForTesting(root
.get(),
2982 gfx::Size(100, 100),
2985 SetLayerPropertiesForTesting(render_surface1
.get(),
2992 SetLayerPropertiesForTesting(child1
.get(),
2995 gfx::PointF(5.f
, 5.f
),
2999 SetLayerPropertiesForTesting(child2
.get(),
3002 gfx::PointF(75.f
, 75.f
),
3006 SetLayerPropertiesForTesting(child3
.get(),
3009 gfx::PointF(125.f
, 125.f
),
3014 root
->SetMasksToBounds(true);
3015 render_surface1
->SetForceRenderSurface(true);
3016 ExecuteCalculateDrawProperties(root
.get());
3018 ASSERT_TRUE(render_surface1
->render_surface());
3020 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3021 root
->render_surface()->DrawableContentRect());
3022 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3024 // Layers that do not draw content should have empty visible content rects.
3025 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3026 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3027 render_surface1
->visible_content_rect());
3029 // A clipped surface grows its DrawableContentRect to include all drawable
3030 // regions of the subtree, but also gets clamped by the ancestor's clip.
3031 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3032 render_surface1
->render_surface()->DrawableContentRect());
3034 // All layers that draw content into the surface have their visible content
3035 // rect clipped by the surface clip rect.
3036 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3037 EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_content_rect());
3038 EXPECT_TRUE(child3
->visible_content_rect().IsEmpty());
3040 // But the DrawableContentRects are unclipped.
3041 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
3042 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
3043 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
3046 TEST_F(LayerTreeHostCommonTest
,
3047 DrawableAndVisibleContentRectsForSurfaceHierarchy
) {
3048 // Check that clipping does not propagate down surfaces.
3049 scoped_refptr
<Layer
> root
= Layer::Create();
3050 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3051 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
3052 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3053 make_scoped_refptr(new LayerWithForcedDrawsContent());
3054 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3055 make_scoped_refptr(new LayerWithForcedDrawsContent());
3056 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
3057 make_scoped_refptr(new LayerWithForcedDrawsContent());
3058 root
->AddChild(render_surface1
);
3059 render_surface1
->AddChild(render_surface2
);
3060 render_surface2
->AddChild(child1
);
3061 render_surface2
->AddChild(child2
);
3062 render_surface2
->AddChild(child3
);
3064 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3065 host
->SetRootLayer(root
);
3067 gfx::Transform identity_matrix
;
3068 SetLayerPropertiesForTesting(root
.get(),
3072 gfx::Size(100, 100),
3075 SetLayerPropertiesForTesting(render_surface1
.get(),
3082 SetLayerPropertiesForTesting(render_surface2
.get(),
3089 SetLayerPropertiesForTesting(child1
.get(),
3092 gfx::PointF(5.f
, 5.f
),
3096 SetLayerPropertiesForTesting(child2
.get(),
3099 gfx::PointF(75.f
, 75.f
),
3103 SetLayerPropertiesForTesting(child3
.get(),
3106 gfx::PointF(125.f
, 125.f
),
3111 root
->SetMasksToBounds(true);
3112 render_surface1
->SetForceRenderSurface(true);
3113 render_surface2
->SetForceRenderSurface(true);
3114 ExecuteCalculateDrawProperties(root
.get());
3116 ASSERT_TRUE(render_surface1
->render_surface());
3117 ASSERT_TRUE(render_surface2
->render_surface());
3119 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3120 root
->render_surface()->DrawableContentRect());
3121 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3123 // Layers that do not draw content should have empty visible content rects.
3124 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3125 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3126 render_surface1
->visible_content_rect());
3127 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3128 render_surface2
->visible_content_rect());
3130 // A clipped surface grows its DrawableContentRect to include all drawable
3131 // regions of the subtree, but also gets clamped by the ancestor's clip.
3132 EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95),
3133 render_surface1
->render_surface()->DrawableContentRect());
3135 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3136 // is only implicitly clipped by render_surface1's content rect. So,
3137 // render_surface2 grows to enclose all drawable content of its subtree.
3138 EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170),
3139 render_surface2
->render_surface()->DrawableContentRect());
3141 // All layers that draw content into render_surface2 think they are unclipped.
3142 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3143 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
3144 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
3146 // DrawableContentRects are also unclipped.
3147 EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
3148 EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
3149 EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
3152 TEST_F(LayerTreeHostCommonTest
,
3153 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface
) {
3154 // Layers that have non-axis aligned bounds (due to transforms) have an
3155 // expanded, axis-aligned DrawableContentRect and visible content rect.
3157 scoped_refptr
<Layer
> root
= Layer::Create();
3158 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3159 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3160 make_scoped_refptr(new LayerWithForcedDrawsContent());
3161 root
->AddChild(render_surface1
);
3162 render_surface1
->AddChild(child1
);
3164 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3165 host
->SetRootLayer(root
);
3167 gfx::Transform identity_matrix
;
3168 gfx::Transform child_rotation
;
3169 child_rotation
.Rotate(45.0);
3170 SetLayerPropertiesForTesting(root
.get(),
3174 gfx::Size(100, 100),
3177 SetLayerPropertiesForTesting(render_surface1
.get(),
3184 SetLayerPropertiesForTesting(child1
.get(),
3186 gfx::Point3F(25, 25, 0.f
),
3187 gfx::PointF(25.f
, 25.f
),
3192 render_surface1
->SetForceRenderSurface(true);
3193 ExecuteCalculateDrawProperties(root
.get());
3195 ASSERT_TRUE(render_surface1
->render_surface());
3197 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100),
3198 root
->render_surface()->DrawableContentRect());
3199 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3201 // Layers that do not draw content should have empty visible content rects.
3202 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3203 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0),
3204 render_surface1
->visible_content_rect());
3206 // The unclipped surface grows its DrawableContentRect to include all drawable
3207 // regions of the subtree.
3208 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3209 gfx::Rect expected_surface_drawable_content
=
3210 gfx::Rect(50 - diagonal_radius
,
3211 50 - diagonal_radius
,
3212 diagonal_radius
* 2,
3213 diagonal_radius
* 2);
3214 EXPECT_RECT_EQ(expected_surface_drawable_content
,
3215 render_surface1
->render_surface()->DrawableContentRect());
3217 // All layers that draw content into the unclipped surface are also unclipped.
3218 EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3219 EXPECT_RECT_EQ(expected_surface_drawable_content
,
3220 child1
->drawable_content_rect());
3223 TEST_F(LayerTreeHostCommonTest
,
3224 DrawableAndVisibleContentRectsWithTransformOnClippedSurface
) {
3225 // Layers that have non-axis aligned bounds (due to transforms) have an
3226 // expanded, axis-aligned DrawableContentRect and visible content rect.
3228 scoped_refptr
<Layer
> root
= Layer::Create();
3229 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3230 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3231 make_scoped_refptr(new LayerWithForcedDrawsContent());
3232 root
->AddChild(render_surface1
);
3233 render_surface1
->AddChild(child1
);
3235 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3236 host
->SetRootLayer(root
);
3238 gfx::Transform identity_matrix
;
3239 gfx::Transform child_rotation
;
3240 child_rotation
.Rotate(45.0);
3241 SetLayerPropertiesForTesting(root
.get(),
3248 SetLayerPropertiesForTesting(render_surface1
.get(),
3256 SetLayerPropertiesForTesting(child1
.get(),
3258 gfx::Point3F(25, 25, 0.f
),
3259 gfx::PointF(25.f
, 25.f
),
3264 root
->SetMasksToBounds(true);
3265 render_surface1
->SetForceRenderSurface(true);
3266 ExecuteCalculateDrawProperties(root
.get());
3268 ASSERT_TRUE(render_surface1
->render_surface());
3270 // The clipped surface clamps the DrawableContentRect that encloses the
3272 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3273 gfx::Rect unclipped_surface_content
= gfx::Rect(50 - diagonal_radius
,
3274 50 - diagonal_radius
,
3275 diagonal_radius
* 2,
3276 diagonal_radius
* 2);
3277 gfx::Rect expected_surface_drawable_content
=
3278 gfx::IntersectRects(unclipped_surface_content
, gfx::Rect(0, 0, 50, 50));
3279 EXPECT_RECT_EQ(expected_surface_drawable_content
,
3280 render_surface1
->render_surface()->DrawableContentRect());
3282 // On the clipped surface, only a quarter of the child1 is visible, but when
3283 // rotating it back to child1's content space, the actual enclosing rect ends
3284 // up covering the full left half of child1.
3286 // Given the floating point math, this number is a little bit fuzzy.
3287 EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1
->visible_content_rect());
3289 // The child's DrawableContentRect is unclipped.
3290 EXPECT_RECT_EQ(unclipped_surface_content
, child1
->drawable_content_rect());
3293 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsInHighDPI
) {
3294 MockContentLayerClient client
;
3296 scoped_refptr
<Layer
> root
= Layer::Create();
3297 scoped_refptr
<ContentLayer
> render_surface1
=
3298 CreateDrawableContentLayer(&client
);
3299 scoped_refptr
<ContentLayer
> render_surface2
=
3300 CreateDrawableContentLayer(&client
);
3301 scoped_refptr
<ContentLayer
> child1
= CreateDrawableContentLayer(&client
);
3302 scoped_refptr
<ContentLayer
> child2
= CreateDrawableContentLayer(&client
);
3303 scoped_refptr
<ContentLayer
> child3
= CreateDrawableContentLayer(&client
);
3304 root
->AddChild(render_surface1
);
3305 render_surface1
->AddChild(render_surface2
);
3306 render_surface2
->AddChild(child1
);
3307 render_surface2
->AddChild(child2
);
3308 render_surface2
->AddChild(child3
);
3310 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3311 host
->SetRootLayer(root
);
3313 gfx::Transform identity_matrix
;
3314 SetLayerPropertiesForTesting(root
.get(),
3318 gfx::Size(100, 100),
3321 SetLayerPropertiesForTesting(render_surface1
.get(),
3324 gfx::PointF(5.f
, 5.f
),
3328 SetLayerPropertiesForTesting(render_surface2
.get(),
3331 gfx::PointF(5.f
, 5.f
),
3335 SetLayerPropertiesForTesting(child1
.get(),
3338 gfx::PointF(5.f
, 5.f
),
3342 SetLayerPropertiesForTesting(child2
.get(),
3345 gfx::PointF(75.f
, 75.f
),
3349 SetLayerPropertiesForTesting(child3
.get(),
3352 gfx::PointF(125.f
, 125.f
),
3357 float device_scale_factor
= 2.f
;
3359 root
->SetMasksToBounds(true);
3360 render_surface1
->SetForceRenderSurface(true);
3361 render_surface2
->SetForceRenderSurface(true);
3362 ExecuteCalculateDrawProperties(root
.get(), device_scale_factor
);
3364 ASSERT_TRUE(render_surface1
->render_surface());
3365 ASSERT_TRUE(render_surface2
->render_surface());
3367 // drawable_content_rects for all layers and surfaces are scaled by
3368 // device_scale_factor.
3369 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200),
3370 root
->render_surface()->DrawableContentRect());
3371 EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root
->drawable_content_rect());
3372 EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190),
3373 render_surface1
->render_surface()->DrawableContentRect());
3375 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3376 // is only implicitly clipped by render_surface1.
3377 EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350),
3378 render_surface2
->render_surface()->DrawableContentRect());
3380 EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1
->drawable_content_rect());
3381 EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100),
3382 child2
->drawable_content_rect());
3383 EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100),
3384 child3
->drawable_content_rect());
3386 // The root layer does not actually draw content of its own.
3387 EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3389 // All layer visible content rects are expressed in content space of each
3390 // layer, so they are also scaled by the device_scale_factor.
3391 EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8),
3392 render_surface1
->visible_content_rect());
3393 EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26),
3394 render_surface2
->visible_content_rect());
3395 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1
->visible_content_rect());
3396 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2
->visible_content_rect());
3397 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3
->visible_content_rect());
3400 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithoutPreserves3d
) {
3401 // Verify the behavior of back-face culling when there are no preserve-3d
3402 // layers. Note that 3d transforms still apply in this case, but they are
3403 // "flattened" to each parent layer according to current W3C spec.
3405 const gfx::Transform identity_matrix
;
3406 scoped_refptr
<Layer
> parent
= Layer::Create();
3407 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3408 make_scoped_refptr(new LayerWithForcedDrawsContent());
3409 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3410 make_scoped_refptr(new LayerWithForcedDrawsContent());
3411 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3412 make_scoped_refptr(new LayerWithForcedDrawsContent());
3413 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3414 make_scoped_refptr(new LayerWithForcedDrawsContent());
3415 scoped_refptr
<LayerWithForcedDrawsContent
>
3416 front_facing_child_of_front_facing_surface
=
3417 make_scoped_refptr(new LayerWithForcedDrawsContent());
3418 scoped_refptr
<LayerWithForcedDrawsContent
>
3419 back_facing_child_of_front_facing_surface
=
3420 make_scoped_refptr(new LayerWithForcedDrawsContent());
3421 scoped_refptr
<LayerWithForcedDrawsContent
>
3422 front_facing_child_of_back_facing_surface
=
3423 make_scoped_refptr(new LayerWithForcedDrawsContent());
3424 scoped_refptr
<LayerWithForcedDrawsContent
>
3425 back_facing_child_of_back_facing_surface
=
3426 make_scoped_refptr(new LayerWithForcedDrawsContent());
3428 parent
->AddChild(front_facing_child
);
3429 parent
->AddChild(back_facing_child
);
3430 parent
->AddChild(front_facing_surface
);
3431 parent
->AddChild(back_facing_surface
);
3432 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3433 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3434 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3435 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3437 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3438 host
->SetRootLayer(parent
);
3440 // Nothing is double-sided
3441 front_facing_child
->SetDoubleSided(false);
3442 back_facing_child
->SetDoubleSided(false);
3443 front_facing_surface
->SetDoubleSided(false);
3444 back_facing_surface
->SetDoubleSided(false);
3445 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3446 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3447 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3448 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3450 gfx::Transform backface_matrix
;
3451 backface_matrix
.Translate(50.0, 50.0);
3452 backface_matrix
.RotateAboutYAxis(180.0);
3453 backface_matrix
.Translate(-50.0, -50.0);
3455 // Having a descendant and opacity will force these to have render surfaces.
3456 front_facing_surface
->SetOpacity(0.5f
);
3457 back_facing_surface
->SetOpacity(0.5f
);
3459 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3460 // these layers should blindly use their own local transforms to determine
3461 // back-face culling.
3462 SetLayerPropertiesForTesting(parent
.get(),
3466 gfx::Size(100, 100),
3469 SetLayerPropertiesForTesting(front_facing_child
.get(),
3473 gfx::Size(100, 100),
3476 SetLayerPropertiesForTesting(back_facing_child
.get(),
3480 gfx::Size(100, 100),
3483 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3487 gfx::Size(100, 100),
3490 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3494 gfx::Size(100, 100),
3497 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3501 gfx::Size(100, 100),
3504 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3508 gfx::Size(100, 100),
3511 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3515 gfx::Size(100, 100),
3518 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3522 gfx::Size(100, 100),
3526 RenderSurfaceLayerList render_surface_layer_list
;
3527 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3528 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3529 inputs
.can_adjust_raster_scales
= true;
3530 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3532 // Verify which render surfaces were created.
3533 EXPECT_FALSE(front_facing_child
->render_surface());
3534 EXPECT_FALSE(back_facing_child
->render_surface());
3535 EXPECT_TRUE(front_facing_surface
->render_surface());
3536 EXPECT_TRUE(back_facing_surface
->render_surface());
3537 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3538 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3539 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3540 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3542 // Verify the render_surface_layer_list.
3543 ASSERT_EQ(3u, render_surface_layer_list
.size());
3544 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3545 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
3546 // Even though the back facing surface LAYER gets culled, the other
3547 // descendants should still be added, so the SURFACE should not be culled.
3548 EXPECT_EQ(back_facing_surface
->id(), render_surface_layer_list
.at(2)->id());
3550 // Verify root surface's layer list.
3553 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3554 EXPECT_EQ(front_facing_child
->id(),
3555 render_surface_layer_list
.at(0)
3560 EXPECT_EQ(front_facing_surface
->id(),
3561 render_surface_layer_list
.at(0)
3566 EXPECT_EQ(back_facing_surface
->id(),
3567 render_surface_layer_list
.at(0)
3573 // Verify front_facing_surface's layer list.
3576 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3577 EXPECT_EQ(front_facing_surface
->id(),
3578 render_surface_layer_list
.at(1)
3583 EXPECT_EQ(front_facing_child_of_front_facing_surface
->id(),
3584 render_surface_layer_list
.at(1)
3590 // Verify back_facing_surface's layer list; its own layer should be culled
3591 // from the surface list.
3594 render_surface_layer_list
.at(2)->render_surface()->layer_list().size());
3595 EXPECT_EQ(front_facing_child_of_back_facing_surface
->id(),
3596 render_surface_layer_list
.at(2)
3603 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithPreserves3d
) {
3604 // Verify the behavior of back-face culling when preserves-3d transform style
3607 const gfx::Transform identity_matrix
;
3608 scoped_refptr
<Layer
> parent
= Layer::Create();
3609 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3610 make_scoped_refptr(new LayerWithForcedDrawsContent());
3611 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3612 make_scoped_refptr(new LayerWithForcedDrawsContent());
3613 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3614 make_scoped_refptr(new LayerWithForcedDrawsContent());
3615 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3616 make_scoped_refptr(new LayerWithForcedDrawsContent());
3617 scoped_refptr
<LayerWithForcedDrawsContent
>
3618 front_facing_child_of_front_facing_surface
=
3619 make_scoped_refptr(new LayerWithForcedDrawsContent());
3620 scoped_refptr
<LayerWithForcedDrawsContent
>
3621 back_facing_child_of_front_facing_surface
=
3622 make_scoped_refptr(new LayerWithForcedDrawsContent());
3623 scoped_refptr
<LayerWithForcedDrawsContent
>
3624 front_facing_child_of_back_facing_surface
=
3625 make_scoped_refptr(new LayerWithForcedDrawsContent());
3626 scoped_refptr
<LayerWithForcedDrawsContent
>
3627 back_facing_child_of_back_facing_surface
=
3628 make_scoped_refptr(new LayerWithForcedDrawsContent());
3629 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer1
=
3630 make_scoped_refptr(new LayerWithForcedDrawsContent());
3631 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer2
=
3632 make_scoped_refptr(new LayerWithForcedDrawsContent());
3634 parent
->AddChild(front_facing_child
);
3635 parent
->AddChild(back_facing_child
);
3636 parent
->AddChild(front_facing_surface
);
3637 parent
->AddChild(back_facing_surface
);
3638 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3639 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3640 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3641 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3643 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3644 host
->SetRootLayer(parent
);
3646 // Nothing is double-sided
3647 front_facing_child
->SetDoubleSided(false);
3648 back_facing_child
->SetDoubleSided(false);
3649 front_facing_surface
->SetDoubleSided(false);
3650 back_facing_surface
->SetDoubleSided(false);
3651 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3652 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3653 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3654 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3656 gfx::Transform backface_matrix
;
3657 backface_matrix
.Translate(50.0, 50.0);
3658 backface_matrix
.RotateAboutYAxis(180.0);
3659 backface_matrix
.Translate(-50.0, -50.0);
3661 // Opacity will not force creation of render surfaces in this case because of
3662 // the preserve-3d transform style. Instead, an example of when a surface
3663 // would be created with preserve-3d is when there is a replica layer.
3664 front_facing_surface
->SetReplicaLayer(dummy_replica_layer1
.get());
3665 back_facing_surface
->SetReplicaLayer(dummy_replica_layer2
.get());
3667 // Each surface creates its own new 3d rendering context (as defined by W3C
3668 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3669 // rendering context should use the transform with respect to that context.
3670 // This 3d rendering context occurs when (a) parent's transform style is flat
3671 // and (b) the layer's transform style is preserve-3d.
3672 SetLayerPropertiesForTesting(parent
.get(),
3676 gfx::Size(100, 100),
3678 false); // parent transform style is flat.
3679 SetLayerPropertiesForTesting(front_facing_child
.get(),
3683 gfx::Size(100, 100),
3686 SetLayerPropertiesForTesting(back_facing_child
.get(),
3690 gfx::Size(100, 100),
3693 // surface transform style is preserve-3d.
3694 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3698 gfx::Size(100, 100),
3701 // surface transform style is preserve-3d.
3702 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3706 gfx::Size(100, 100),
3709 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3713 gfx::Size(100, 100),
3716 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3720 gfx::Size(100, 100),
3723 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3727 gfx::Size(100, 100),
3730 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3734 gfx::Size(100, 100),
3738 RenderSurfaceLayerList render_surface_layer_list
;
3739 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3740 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3741 inputs
.can_adjust_raster_scales
= true;
3742 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3744 // Verify which render surfaces were created.
3745 EXPECT_FALSE(front_facing_child
->render_surface());
3746 EXPECT_FALSE(back_facing_child
->render_surface());
3747 EXPECT_TRUE(front_facing_surface
->render_surface());
3748 EXPECT_FALSE(back_facing_surface
->render_surface());
3749 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3750 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3751 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3752 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3754 // Verify the render_surface_layer_list. The back-facing surface should be
3756 ASSERT_EQ(2u, render_surface_layer_list
.size());
3757 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3758 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
3760 // Verify root surface's layer list.
3763 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3764 EXPECT_EQ(front_facing_child
->id(),
3765 render_surface_layer_list
.at(0)
3766 ->render_surface()->layer_list().at(0)->id());
3767 EXPECT_EQ(front_facing_surface
->id(),
3768 render_surface_layer_list
.at(0)
3769 ->render_surface()->layer_list().at(1)->id());
3771 // Verify front_facing_surface's layer list.
3774 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3775 EXPECT_EQ(front_facing_surface
->id(),
3776 render_surface_layer_list
.at(1)
3777 ->render_surface()->layer_list().at(0)->id());
3778 EXPECT_EQ(front_facing_child_of_front_facing_surface
->id(),
3779 render_surface_layer_list
.at(1)
3780 ->render_surface()->layer_list().at(1)->id());
3783 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithAnimatingTransforms
) {
3784 // Verify that layers are appropriately culled when their back face is showing
3785 // and they are not double sided, while animations are going on.
3787 // Layers that are animating do not get culled on the main thread, as their
3788 // transforms should be treated as "unknown" so we can not be sure that their
3789 // back face is really showing.
3790 const gfx::Transform identity_matrix
;
3791 scoped_refptr
<Layer
> parent
= Layer::Create();
3792 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
3793 make_scoped_refptr(new LayerWithForcedDrawsContent());
3794 scoped_refptr
<LayerWithForcedDrawsContent
> animating_surface
=
3795 make_scoped_refptr(new LayerWithForcedDrawsContent());
3796 scoped_refptr
<LayerWithForcedDrawsContent
> child_of_animating_surface
=
3797 make_scoped_refptr(new LayerWithForcedDrawsContent());
3798 scoped_refptr
<LayerWithForcedDrawsContent
> animating_child
=
3799 make_scoped_refptr(new LayerWithForcedDrawsContent());
3800 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3801 make_scoped_refptr(new LayerWithForcedDrawsContent());
3803 parent
->AddChild(child
);
3804 parent
->AddChild(animating_surface
);
3805 animating_surface
->AddChild(child_of_animating_surface
);
3806 parent
->AddChild(animating_child
);
3807 parent
->AddChild(child2
);
3809 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3810 host
->SetRootLayer(parent
);
3812 // Nothing is double-sided
3813 child
->SetDoubleSided(false);
3814 child2
->SetDoubleSided(false);
3815 animating_surface
->SetDoubleSided(false);
3816 child_of_animating_surface
->SetDoubleSided(false);
3817 animating_child
->SetDoubleSided(false);
3819 gfx::Transform backface_matrix
;
3820 backface_matrix
.Translate(50.0, 50.0);
3821 backface_matrix
.RotateAboutYAxis(180.0);
3822 backface_matrix
.Translate(-50.0, -50.0);
3824 // Make our render surface.
3825 animating_surface
->SetForceRenderSurface(true);
3827 // Animate the transform on the render surface.
3828 AddAnimatedTransformToController(
3829 animating_surface
->layer_animation_controller(), 10.0, 30, 0);
3830 // This is just an animating layer, not a surface.
3831 AddAnimatedTransformToController(
3832 animating_child
->layer_animation_controller(), 10.0, 30, 0);
3834 SetLayerPropertiesForTesting(parent
.get(),
3838 gfx::Size(100, 100),
3841 SetLayerPropertiesForTesting(child
.get(),
3845 gfx::Size(100, 100),
3848 SetLayerPropertiesForTesting(animating_surface
.get(),
3852 gfx::Size(100, 100),
3855 SetLayerPropertiesForTesting(child_of_animating_surface
.get(),
3859 gfx::Size(100, 100),
3862 SetLayerPropertiesForTesting(animating_child
.get(),
3866 gfx::Size(100, 100),
3869 SetLayerPropertiesForTesting(child2
.get(),
3873 gfx::Size(100, 100),
3877 RenderSurfaceLayerList render_surface_layer_list
;
3878 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3879 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3880 inputs
.can_adjust_raster_scales
= true;
3881 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3883 EXPECT_FALSE(child
->render_surface());
3884 EXPECT_TRUE(animating_surface
->render_surface());
3885 EXPECT_FALSE(child_of_animating_surface
->render_surface());
3886 EXPECT_FALSE(animating_child
->render_surface());
3887 EXPECT_FALSE(child2
->render_surface());
3889 // Verify that the animating_child and child_of_animating_surface were not
3890 // culled, but that child was.
3891 ASSERT_EQ(2u, render_surface_layer_list
.size());
3892 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3893 EXPECT_EQ(animating_surface
->id(), render_surface_layer_list
.at(1)->id());
3895 // The non-animating child be culled from the layer list for the parent render
3899 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3900 EXPECT_EQ(animating_surface
->id(),
3901 render_surface_layer_list
.at(0)
3902 ->render_surface()->layer_list().at(0)->id());
3903 EXPECT_EQ(animating_child
->id(),
3904 render_surface_layer_list
.at(0)
3905 ->render_surface()->layer_list().at(1)->id());
3906 EXPECT_EQ(child2
->id(),
3907 render_surface_layer_list
.at(0)
3908 ->render_surface()->layer_list().at(2)->id());
3912 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3913 EXPECT_EQ(animating_surface
->id(),
3914 render_surface_layer_list
.at(1)
3915 ->render_surface()->layer_list().at(0)->id());
3916 EXPECT_EQ(child_of_animating_surface
->id(),
3917 render_surface_layer_list
.at(1)
3918 ->render_surface()->layer_list().at(1)->id());
3920 EXPECT_FALSE(child2
->visible_content_rect().IsEmpty());
3922 // The animating layers should have a visible content rect that represents the
3923 // area of the front face that is within the viewport.
3924 EXPECT_EQ(animating_child
->visible_content_rect(),
3925 gfx::Rect(animating_child
->content_bounds()));
3926 EXPECT_EQ(animating_surface
->visible_content_rect(),
3927 gfx::Rect(animating_surface
->content_bounds()));
3928 // And layers in the subtree of the animating layer should have valid visible
3929 // content rects also.
3930 EXPECT_EQ(child_of_animating_surface
->visible_content_rect(),
3931 gfx::Rect(child_of_animating_surface
->content_bounds()));
3934 TEST_F(LayerTreeHostCommonTest
,
3935 BackFaceCullingWithPreserves3dForFlatteningSurface
) {
3936 // Verify the behavior of back-face culling for a render surface that is
3937 // created when it flattens its subtree, and its parent has preserves-3d.
3939 const gfx::Transform identity_matrix
;
3940 scoped_refptr
<Layer
> parent
= Layer::Create();
3941 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3942 make_scoped_refptr(new LayerWithForcedDrawsContent());
3943 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3944 make_scoped_refptr(new LayerWithForcedDrawsContent());
3945 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3946 make_scoped_refptr(new LayerWithForcedDrawsContent());
3947 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3948 make_scoped_refptr(new LayerWithForcedDrawsContent());
3950 parent
->AddChild(front_facing_surface
);
3951 parent
->AddChild(back_facing_surface
);
3952 front_facing_surface
->AddChild(child1
);
3953 back_facing_surface
->AddChild(child2
);
3955 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
3956 host
->SetRootLayer(parent
);
3958 // RenderSurfaces are not double-sided
3959 front_facing_surface
->SetDoubleSided(false);
3960 back_facing_surface
->SetDoubleSided(false);
3962 gfx::Transform backface_matrix
;
3963 backface_matrix
.Translate(50.0, 50.0);
3964 backface_matrix
.RotateAboutYAxis(180.0);
3965 backface_matrix
.Translate(-50.0, -50.0);
3967 SetLayerPropertiesForTesting(parent
.get(),
3971 gfx::Size(100, 100),
3973 true); // parent transform style is preserve3d.
3974 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3978 gfx::Size(100, 100),
3980 true); // surface transform style is flat.
3981 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3985 gfx::Size(100, 100),
3987 true); // surface transform style is flat.
3988 SetLayerPropertiesForTesting(child1
.get(),
3992 gfx::Size(100, 100),
3995 SetLayerPropertiesForTesting(child2
.get(),
3999 gfx::Size(100, 100),
4003 front_facing_surface
->Set3dSortingContextId(1);
4004 back_facing_surface
->Set3dSortingContextId(1);
4006 RenderSurfaceLayerList render_surface_layer_list
;
4007 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4008 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4009 inputs
.can_adjust_raster_scales
= true;
4010 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4012 // Verify which render surfaces were created.
4013 EXPECT_TRUE(front_facing_surface
->render_surface());
4015 back_facing_surface
->render_surface()); // because it should be culled
4016 EXPECT_FALSE(child1
->render_surface());
4017 EXPECT_FALSE(child2
->render_surface());
4019 // Verify the render_surface_layer_list. The back-facing surface should be
4021 ASSERT_EQ(2u, render_surface_layer_list
.size());
4022 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
4023 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
4025 // Verify root surface's layer list.
4028 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
4029 EXPECT_EQ(front_facing_surface
->id(),
4030 render_surface_layer_list
.at(0)
4031 ->render_surface()->layer_list().at(0)->id());
4033 // Verify front_facing_surface's layer list.
4036 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
4037 EXPECT_EQ(front_facing_surface
->id(),
4038 render_surface_layer_list
.at(1)
4039 ->render_surface()->layer_list().at(0)->id());
4040 EXPECT_EQ(child1
->id(),
4041 render_surface_layer_list
.at(1)
4042 ->render_surface()->layer_list().at(1)->id());
4045 class NoScaleContentLayer
: public ContentLayer
{
4047 static scoped_refptr
<NoScaleContentLayer
> Create(ContentLayerClient
* client
) {
4048 return make_scoped_refptr(new NoScaleContentLayer(client
));
4051 virtual void CalculateContentsScale(float ideal_contents_scale
,
4052 float device_scale_factor
,
4053 float page_scale_factor
,
4054 float maximum_animation_contents_scale
,
4055 bool animating_transform_to_screen
,
4056 float* contents_scale_x
,
4057 float* contents_scale_y
,
4058 gfx::Size
* content_bounds
) OVERRIDE
{
4059 // Skip over the ContentLayer to the base Layer class.
4060 Layer::CalculateContentsScale(ideal_contents_scale
,
4061 device_scale_factor
,
4063 maximum_animation_contents_scale
,
4064 animating_transform_to_screen
,
4071 explicit NoScaleContentLayer(ContentLayerClient
* client
)
4072 : ContentLayer(client
) {}
4073 virtual ~NoScaleContentLayer() {}
4076 scoped_refptr
<NoScaleContentLayer
> CreateNoScaleDrawableContentLayer(
4077 ContentLayerClient
* delegate
) {
4078 scoped_refptr
<NoScaleContentLayer
> to_return
=
4079 NoScaleContentLayer::Create(delegate
);
4080 to_return
->SetIsDrawable(true);
4084 TEST_F(LayerTreeHostCommonTest
, LayerTransformsInHighDPI
) {
4085 // Verify draw and screen space transforms of layers not in a surface.
4086 MockContentLayerClient delegate
;
4087 gfx::Transform identity_matrix
;
4089 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4090 SetLayerPropertiesForTesting(parent
.get(),
4094 gfx::Size(100, 100),
4098 scoped_refptr
<ContentLayer
> child
= CreateDrawableContentLayer(&delegate
);
4099 SetLayerPropertiesForTesting(child
.get(),
4102 gfx::PointF(2.f
, 2.f
),
4107 scoped_refptr
<ContentLayer
> child_empty
=
4108 CreateDrawableContentLayer(&delegate
);
4109 SetLayerPropertiesForTesting(child_empty
.get(),
4112 gfx::PointF(2.f
, 2.f
),
4117 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4118 CreateNoScaleDrawableContentLayer(&delegate
);
4119 SetLayerPropertiesForTesting(child_no_scale
.get(),
4122 gfx::PointF(2.f
, 2.f
),
4127 parent
->AddChild(child
);
4128 parent
->AddChild(child_empty
);
4129 parent
->AddChild(child_no_scale
);
4131 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
4132 host
->SetRootLayer(parent
);
4134 float device_scale_factor
= 2.5f
;
4135 float page_scale_factor
= 1.f
;
4137 RenderSurfaceLayerList render_surface_layer_list
;
4138 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4139 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4140 inputs
.device_scale_factor
= device_scale_factor
;
4141 inputs
.page_scale_factor
= page_scale_factor
;
4142 inputs
.can_adjust_raster_scales
= true;
4143 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4145 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4146 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, child
);
4147 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4149 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4151 EXPECT_EQ(1u, render_surface_layer_list
.size());
4153 // Verify parent transforms
4154 gfx::Transform expected_parent_transform
;
4155 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4156 parent
->screen_space_transform());
4157 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4158 parent
->draw_transform());
4160 // Verify results of transformed parent rects
4161 gfx::RectF
parent_content_bounds(parent
->content_bounds());
4163 gfx::RectF parent_draw_rect
=
4164 MathUtil::MapClippedRect(parent
->draw_transform(), parent_content_bounds
);
4165 gfx::RectF parent_screen_space_rect
= MathUtil::MapClippedRect(
4166 parent
->screen_space_transform(), parent_content_bounds
);
4168 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
4169 expected_parent_draw_rect
.Scale(device_scale_factor
);
4170 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
4171 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
4173 // Verify child and child_empty transforms. They should match.
4174 gfx::Transform expected_child_transform
;
4175 expected_child_transform
.Translate(
4176 device_scale_factor
* child
->position().x(),
4177 device_scale_factor
* child
->position().y());
4178 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4179 child
->draw_transform());
4180 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4181 child
->screen_space_transform());
4182 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4183 child_empty
->draw_transform());
4184 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4185 child_empty
->screen_space_transform());
4187 // Verify results of transformed child and child_empty rects. They should
4189 gfx::RectF
child_content_bounds(child
->content_bounds());
4191 gfx::RectF child_draw_rect
=
4192 MathUtil::MapClippedRect(child
->draw_transform(), child_content_bounds
);
4193 gfx::RectF child_screen_space_rect
= MathUtil::MapClippedRect(
4194 child
->screen_space_transform(), child_content_bounds
);
4196 gfx::RectF child_empty_draw_rect
= MathUtil::MapClippedRect(
4197 child_empty
->draw_transform(), child_content_bounds
);
4198 gfx::RectF child_empty_screen_space_rect
= MathUtil::MapClippedRect(
4199 child_empty
->screen_space_transform(), child_content_bounds
);
4201 gfx::RectF
expected_child_draw_rect(child
->position(), child
->bounds());
4202 expected_child_draw_rect
.Scale(device_scale_factor
);
4203 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
4204 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
4205 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_draw_rect
);
4206 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_screen_space_rect
);
4208 // Verify child_no_scale transforms
4209 gfx::Transform expected_child_no_scale_transform
= child
->draw_transform();
4210 // All transforms operate on content rects. The child's content rect
4211 // incorporates device scale, but the child_no_scale does not; add it here.
4212 expected_child_no_scale_transform
.Scale(device_scale_factor
,
4213 device_scale_factor
);
4214 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4215 child_no_scale
->draw_transform());
4216 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4217 child_no_scale
->screen_space_transform());
4220 TEST_F(LayerTreeHostCommonTest
, SurfaceLayerTransformsInHighDPI
) {
4221 // Verify draw and screen space transforms of layers in a surface.
4222 MockContentLayerClient delegate
;
4223 gfx::Transform identity_matrix
;
4225 gfx::Transform perspective_matrix
;
4226 perspective_matrix
.ApplyPerspectiveDepth(2.0);
4228 gfx::Transform scale_small_matrix
;
4229 scale_small_matrix
.Scale(SK_MScalar1
/ 10.f
, SK_MScalar1
/ 12.f
);
4231 scoped_refptr
<Layer
> root
= Layer::Create();
4233 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4234 SetLayerPropertiesForTesting(parent
.get(),
4238 gfx::Size(100, 100),
4242 scoped_refptr
<ContentLayer
> perspective_surface
=
4243 CreateDrawableContentLayer(&delegate
);
4244 SetLayerPropertiesForTesting(perspective_surface
.get(),
4245 perspective_matrix
* scale_small_matrix
,
4247 gfx::PointF(2.f
, 2.f
),
4252 scoped_refptr
<ContentLayer
> scale_surface
=
4253 CreateDrawableContentLayer(&delegate
);
4254 SetLayerPropertiesForTesting(scale_surface
.get(),
4257 gfx::PointF(2.f
, 2.f
),
4262 perspective_surface
->SetForceRenderSurface(true);
4263 scale_surface
->SetForceRenderSurface(true);
4265 parent
->AddChild(perspective_surface
);
4266 parent
->AddChild(scale_surface
);
4267 root
->AddChild(parent
);
4269 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
4270 host
->SetRootLayer(root
);
4272 float device_scale_factor
= 2.5f
;
4273 float page_scale_factor
= 3.f
;
4275 RenderSurfaceLayerList render_surface_layer_list
;
4276 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4277 root
.get(), parent
->bounds(), &render_surface_layer_list
);
4278 inputs
.device_scale_factor
= device_scale_factor
;
4279 inputs
.page_scale_factor
= page_scale_factor
;
4280 inputs
.page_scale_application_layer
= root
;
4281 inputs
.can_adjust_raster_scales
= true;
4282 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4284 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4285 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4286 perspective_surface
);
4287 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4290 EXPECT_EQ(3u, render_surface_layer_list
.size());
4292 gfx::Transform expected_parent_draw_transform
;
4293 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform
,
4294 parent
->draw_transform());
4296 // The scaled surface is rendered at its appropriate scale, and drawn 1:1
4298 gfx::Transform expected_scale_surface_draw_transform
;
4299 expected_scale_surface_draw_transform
.Translate(
4300 device_scale_factor
* page_scale_factor
* scale_surface
->position().x(),
4301 device_scale_factor
* page_scale_factor
* scale_surface
->position().y());
4302 EXPECT_TRANSFORMATION_MATRIX_EQ(
4303 expected_scale_surface_draw_transform
,
4304 scale_surface
->render_surface()->draw_transform());
4305 gfx::Transform expected_scale_surface_layer_draw_transform
=
4307 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform
,
4308 scale_surface
->draw_transform());
4310 // The scale for the perspective surface is not known, so it is rendered 1:1
4311 // with the screen, and then scaled during drawing.
4312 gfx::Transform expected_perspective_surface_draw_transform
;
4313 expected_perspective_surface_draw_transform
.Translate(
4314 device_scale_factor
* page_scale_factor
*
4315 perspective_surface
->position().x(),
4316 device_scale_factor
* page_scale_factor
*
4317 perspective_surface
->position().y());
4318 expected_perspective_surface_draw_transform
.PreconcatTransform(
4319 perspective_matrix
);
4320 expected_perspective_surface_draw_transform
.PreconcatTransform(
4321 scale_small_matrix
);
4322 gfx::Transform expected_perspective_surface_layer_draw_transform
;
4323 EXPECT_TRANSFORMATION_MATRIX_EQ(
4324 expected_perspective_surface_draw_transform
,
4325 perspective_surface
->render_surface()->draw_transform());
4326 EXPECT_TRANSFORMATION_MATRIX_EQ(
4327 expected_perspective_surface_layer_draw_transform
,
4328 perspective_surface
->draw_transform());
4331 TEST_F(LayerTreeHostCommonTest
,
4332 LayerTransformsInHighDPIAccurateScaleZeroChildPosition
) {
4333 // Verify draw and screen space transforms of layers not in a surface.
4334 MockContentLayerClient delegate
;
4335 gfx::Transform identity_matrix
;
4337 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4338 SetLayerPropertiesForTesting(parent
.get(),
4342 gfx::Size(133, 133),
4346 scoped_refptr
<ContentLayer
> child
= CreateDrawableContentLayer(&delegate
);
4347 SetLayerPropertiesForTesting(child
.get(),
4355 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4356 CreateNoScaleDrawableContentLayer(&delegate
);
4357 SetLayerPropertiesForTesting(child_no_scale
.get(),
4365 parent
->AddChild(child
);
4366 parent
->AddChild(child_no_scale
);
4368 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
4369 host
->SetRootLayer(parent
);
4371 float device_scale_factor
= 1.7f
;
4372 float page_scale_factor
= 1.f
;
4374 RenderSurfaceLayerList render_surface_layer_list
;
4375 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4376 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4377 inputs
.device_scale_factor
= device_scale_factor
;
4378 inputs
.page_scale_factor
= page_scale_factor
;
4379 inputs
.page_scale_application_layer
= parent
.get();
4380 inputs
.can_adjust_raster_scales
= true;
4381 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4383 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4384 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, child
);
4385 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4387 EXPECT_EQ(1u, render_surface_layer_list
.size());
4389 // Verify parent transforms
4390 gfx::Transform expected_parent_transform
;
4391 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4392 parent
->screen_space_transform());
4393 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4394 parent
->draw_transform());
4396 // Verify results of transformed parent rects
4397 gfx::RectF
parent_content_bounds(parent
->content_bounds());
4399 gfx::RectF parent_draw_rect
=
4400 MathUtil::MapClippedRect(parent
->draw_transform(), parent_content_bounds
);
4401 gfx::RectF parent_screen_space_rect
= MathUtil::MapClippedRect(
4402 parent
->screen_space_transform(), parent_content_bounds
);
4404 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
4405 expected_parent_draw_rect
.Scale(device_scale_factor
);
4406 expected_parent_draw_rect
.set_width(ceil(expected_parent_draw_rect
.width()));
4407 expected_parent_draw_rect
.set_height(
4408 ceil(expected_parent_draw_rect
.height()));
4409 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
4410 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
4412 // Verify child transforms
4413 gfx::Transform expected_child_transform
;
4414 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4415 child
->draw_transform());
4416 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4417 child
->screen_space_transform());
4419 // Verify results of transformed child rects
4420 gfx::RectF
child_content_bounds(child
->content_bounds());
4422 gfx::RectF child_draw_rect
=
4423 MathUtil::MapClippedRect(child
->draw_transform(), child_content_bounds
);
4424 gfx::RectF child_screen_space_rect
= MathUtil::MapClippedRect(
4425 child
->screen_space_transform(), child_content_bounds
);
4427 gfx::RectF
expected_child_draw_rect(child
->bounds());
4428 expected_child_draw_rect
.Scale(device_scale_factor
);
4429 expected_child_draw_rect
.set_width(ceil(expected_child_draw_rect
.width()));
4430 expected_child_draw_rect
.set_height(ceil(expected_child_draw_rect
.height()));
4431 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
4432 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
4434 // Verify child_no_scale transforms
4435 gfx::Transform expected_child_no_scale_transform
= child
->draw_transform();
4436 // All transforms operate on content rects. The child's content rect
4437 // incorporates device scale, but the child_no_scale does not; add it here.
4438 expected_child_no_scale_transform
.Scale(device_scale_factor
,
4439 device_scale_factor
);
4440 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4441 child_no_scale
->draw_transform());
4442 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4443 child_no_scale
->screen_space_transform());
4446 TEST_F(LayerTreeHostCommonTest
, ContentsScale
) {
4447 MockContentLayerClient delegate
;
4448 gfx::Transform identity_matrix
;
4450 gfx::Transform parent_scale_matrix
;
4451 SkMScalar initial_parent_scale
= 1.75;
4452 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4454 gfx::Transform child_scale_matrix
;
4455 SkMScalar initial_child_scale
= 1.25;
4456 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4458 scoped_refptr
<Layer
> root
= Layer::Create();
4459 root
->SetBounds(gfx::Size(100, 100));
4461 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4462 SetLayerPropertiesForTesting(parent
.get(),
4463 parent_scale_matrix
,
4466 gfx::Size(100, 100),
4470 scoped_refptr
<ContentLayer
> child_scale
=
4471 CreateDrawableContentLayer(&delegate
);
4472 SetLayerPropertiesForTesting(child_scale
.get(),
4475 gfx::PointF(2.f
, 2.f
),
4480 scoped_refptr
<ContentLayer
> child_empty
=
4481 CreateDrawableContentLayer(&delegate
);
4482 SetLayerPropertiesForTesting(child_empty
.get(),
4485 gfx::PointF(2.f
, 2.f
),
4490 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4491 CreateNoScaleDrawableContentLayer(&delegate
);
4492 SetLayerPropertiesForTesting(child_no_scale
.get(),
4495 gfx::PointF(12.f
, 12.f
),
4500 root
->AddChild(parent
);
4502 parent
->AddChild(child_scale
);
4503 parent
->AddChild(child_empty
);
4504 parent
->AddChild(child_no_scale
);
4506 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
4507 host
->SetRootLayer(root
);
4509 float device_scale_factor
= 2.5f
;
4510 float page_scale_factor
= 1.f
;
4513 RenderSurfaceLayerList render_surface_layer_list
;
4514 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4515 root
.get(), root
->bounds(), &render_surface_layer_list
);
4516 inputs
.device_scale_factor
= device_scale_factor
;
4517 inputs
.page_scale_factor
= page_scale_factor
;
4518 inputs
.page_scale_application_layer
= root
.get();
4519 inputs
.can_adjust_raster_scales
= true;
4520 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4522 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4523 initial_parent_scale
, parent
);
4524 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4525 initial_parent_scale
* initial_child_scale
,
4527 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4528 initial_parent_scale
* initial_child_scale
,
4530 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4532 // The parent is scaled up and shouldn't need to scale during draw. The
4533 // child that can scale its contents should also not need to scale during
4534 // draw. This shouldn't change if the child has empty bounds. The other
4536 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(0, 0));
4537 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(1, 1));
4538 EXPECT_FLOAT_EQ(1.0, child_scale
->draw_transform().matrix().get(0, 0));
4539 EXPECT_FLOAT_EQ(1.0, child_scale
->draw_transform().matrix().get(1, 1));
4540 EXPECT_FLOAT_EQ(1.0, child_empty
->draw_transform().matrix().get(0, 0));
4541 EXPECT_FLOAT_EQ(1.0, child_empty
->draw_transform().matrix().get(1, 1));
4542 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4543 initial_parent_scale
* initial_child_scale
,
4544 child_no_scale
->draw_transform().matrix().get(0, 0));
4545 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4546 initial_parent_scale
* initial_child_scale
,
4547 child_no_scale
->draw_transform().matrix().get(1, 1));
4550 // If the device_scale_factor or page_scale_factor changes, then it should be
4551 // updated using the initial transform as the raster scale.
4552 device_scale_factor
= 2.25f
;
4553 page_scale_factor
= 1.25f
;
4556 RenderSurfaceLayerList render_surface_layer_list
;
4557 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4558 root
.get(), root
->bounds(), &render_surface_layer_list
);
4559 inputs
.device_scale_factor
= device_scale_factor
;
4560 inputs
.page_scale_factor
= page_scale_factor
;
4561 inputs
.page_scale_application_layer
= root
.get();
4562 inputs
.can_adjust_raster_scales
= true;
4563 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4565 EXPECT_CONTENTS_SCALE_EQ(
4566 device_scale_factor
* page_scale_factor
* initial_parent_scale
, parent
);
4567 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4568 initial_parent_scale
* initial_child_scale
,
4570 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4571 initial_parent_scale
* initial_child_scale
,
4573 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4576 // If the transform changes, we expect the raster scale to be reset to 1.0.
4577 SkMScalar second_child_scale
= 1.75;
4578 child_scale_matrix
.Scale(second_child_scale
/ initial_child_scale
,
4579 second_child_scale
/ initial_child_scale
);
4580 child_scale
->SetTransform(child_scale_matrix
);
4581 child_empty
->SetTransform(child_scale_matrix
);
4584 RenderSurfaceLayerList render_surface_layer_list
;
4585 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4586 root
.get(), root
->bounds(), &render_surface_layer_list
);
4587 inputs
.device_scale_factor
= device_scale_factor
;
4588 inputs
.page_scale_factor
= page_scale_factor
;
4589 inputs
.page_scale_application_layer
= root
.get();
4590 inputs
.can_adjust_raster_scales
= true;
4591 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4593 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4594 initial_parent_scale
,
4596 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4598 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4600 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4603 // If the device_scale_factor or page_scale_factor changes, then it should be
4604 // updated, but still using 1.0 as the raster scale.
4605 device_scale_factor
= 2.75f
;
4606 page_scale_factor
= 1.75f
;
4609 RenderSurfaceLayerList render_surface_layer_list
;
4610 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4611 root
.get(), root
->bounds(), &render_surface_layer_list
);
4612 inputs
.device_scale_factor
= device_scale_factor
;
4613 inputs
.page_scale_factor
= page_scale_factor
;
4614 inputs
.page_scale_application_layer
= root
.get();
4615 inputs
.can_adjust_raster_scales
= true;
4616 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4618 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4619 initial_parent_scale
,
4621 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4623 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4625 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4629 TEST_F(LayerTreeHostCommonTest
,
4630 ContentsScale_LayerTransformsDontAffectContentsScale
) {
4631 MockContentLayerClient delegate
;
4632 gfx::Transform identity_matrix
;
4634 gfx::Transform parent_scale_matrix
;
4635 SkMScalar initial_parent_scale
= 1.75;
4636 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4638 gfx::Transform child_scale_matrix
;
4639 SkMScalar initial_child_scale
= 1.25;
4640 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4642 scoped_refptr
<Layer
> root
= Layer::Create();
4643 root
->SetBounds(gfx::Size(100, 100));
4645 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4646 SetLayerPropertiesForTesting(parent
.get(),
4647 parent_scale_matrix
,
4650 gfx::Size(100, 100),
4654 scoped_refptr
<ContentLayer
> child_scale
=
4655 CreateDrawableContentLayer(&delegate
);
4656 SetLayerPropertiesForTesting(child_scale
.get(),
4659 gfx::PointF(2.f
, 2.f
),
4664 scoped_refptr
<ContentLayer
> child_empty
=
4665 CreateDrawableContentLayer(&delegate
);
4666 SetLayerPropertiesForTesting(child_empty
.get(),
4669 gfx::PointF(2.f
, 2.f
),
4674 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4675 CreateNoScaleDrawableContentLayer(&delegate
);
4676 SetLayerPropertiesForTesting(child_no_scale
.get(),
4679 gfx::PointF(12.f
, 12.f
),
4684 root
->AddChild(parent
);
4686 parent
->AddChild(child_scale
);
4687 parent
->AddChild(child_empty
);
4688 parent
->AddChild(child_no_scale
);
4690 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
4691 host
->SetRootLayer(root
);
4693 RenderSurfaceLayerList render_surface_layer_list
;
4695 float device_scale_factor
= 2.5f
;
4696 float page_scale_factor
= 1.f
;
4698 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4699 root
.get(), root
->bounds(), &render_surface_layer_list
);
4700 inputs
.device_scale_factor
= device_scale_factor
;
4701 inputs
.page_scale_factor
= page_scale_factor
;
4702 inputs
.page_scale_application_layer
= root
.get(),
4703 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4705 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4706 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4708 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4710 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4712 // Since the transform scale does not affect contents scale, it should affect
4713 // the draw transform instead.
4714 EXPECT_FLOAT_EQ(initial_parent_scale
,
4715 parent
->draw_transform().matrix().get(0, 0));
4716 EXPECT_FLOAT_EQ(initial_parent_scale
,
4717 parent
->draw_transform().matrix().get(1, 1));
4718 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4719 child_scale
->draw_transform().matrix().get(0, 0));
4720 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4721 child_scale
->draw_transform().matrix().get(1, 1));
4722 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4723 child_empty
->draw_transform().matrix().get(0, 0));
4724 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4725 child_empty
->draw_transform().matrix().get(1, 1));
4726 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4727 initial_parent_scale
* initial_child_scale
,
4728 child_no_scale
->draw_transform().matrix().get(0, 0));
4729 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4730 initial_parent_scale
* initial_child_scale
,
4731 child_no_scale
->draw_transform().matrix().get(1, 1));
4734 TEST_F(LayerTreeHostCommonTest
, SmallContentsScale
) {
4735 MockContentLayerClient delegate
;
4736 gfx::Transform identity_matrix
;
4738 gfx::Transform parent_scale_matrix
;
4739 SkMScalar initial_parent_scale
= 1.75;
4740 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4742 gfx::Transform child_scale_matrix
;
4743 SkMScalar initial_child_scale
= 0.25;
4744 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4746 scoped_refptr
<Layer
> root
= Layer::Create();
4747 root
->SetBounds(gfx::Size(100, 100));
4749 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4750 SetLayerPropertiesForTesting(parent
.get(),
4751 parent_scale_matrix
,
4754 gfx::Size(100, 100),
4758 scoped_refptr
<ContentLayer
> child_scale
=
4759 CreateDrawableContentLayer(&delegate
);
4760 SetLayerPropertiesForTesting(child_scale
.get(),
4763 gfx::PointF(2.f
, 2.f
),
4768 root
->AddChild(parent
);
4770 parent
->AddChild(child_scale
);
4772 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
4773 host
->SetRootLayer(root
);
4775 float device_scale_factor
= 2.5f
;
4776 float page_scale_factor
= 0.01f
;
4779 RenderSurfaceLayerList render_surface_layer_list
;
4780 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4781 root
.get(), root
->bounds(), &render_surface_layer_list
);
4782 inputs
.device_scale_factor
= device_scale_factor
;
4783 inputs
.page_scale_factor
= page_scale_factor
;
4784 inputs
.page_scale_application_layer
= root
.get();
4785 inputs
.can_adjust_raster_scales
= true;
4786 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4788 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4789 initial_parent_scale
,
4791 // The child's scale is < 1, so we should not save and use that scale
4793 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
* 1,
4797 // When chilld's total scale becomes >= 1, we should save and use that scale
4799 child_scale_matrix
.MakeIdentity();
4800 SkMScalar final_child_scale
= 0.75;
4801 child_scale_matrix
.Scale(final_child_scale
, final_child_scale
);
4802 child_scale
->SetTransform(child_scale_matrix
);
4805 RenderSurfaceLayerList render_surface_layer_list
;
4806 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4807 root
.get(), root
->bounds(), &render_surface_layer_list
);
4808 inputs
.device_scale_factor
= device_scale_factor
;
4809 inputs
.page_scale_factor
= page_scale_factor
;
4810 inputs
.page_scale_application_layer
= root
.get();
4811 inputs
.can_adjust_raster_scales
= true;
4812 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4814 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4815 initial_parent_scale
,
4817 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4818 initial_parent_scale
* final_child_scale
,
4823 TEST_F(LayerTreeHostCommonTest
, ContentsScaleForSurfaces
) {
4824 MockContentLayerClient delegate
;
4825 gfx::Transform identity_matrix
;
4827 gfx::Transform parent_scale_matrix
;
4828 SkMScalar initial_parent_scale
= 2.0;
4829 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4831 gfx::Transform child_scale_matrix
;
4832 SkMScalar initial_child_scale
= 3.0;
4833 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4835 scoped_refptr
<Layer
> root
= Layer::Create();
4836 root
->SetBounds(gfx::Size(100, 100));
4838 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4839 SetLayerPropertiesForTesting(parent
.get(),
4840 parent_scale_matrix
,
4843 gfx::Size(100, 100),
4847 scoped_refptr
<ContentLayer
> surface_scale
=
4848 CreateDrawableContentLayer(&delegate
);
4849 SetLayerPropertiesForTesting(surface_scale
.get(),
4852 gfx::PointF(2.f
, 2.f
),
4857 scoped_refptr
<ContentLayer
> surface_scale_child_scale
=
4858 CreateDrawableContentLayer(&delegate
);
4859 SetLayerPropertiesForTesting(surface_scale_child_scale
.get(),
4867 scoped_refptr
<NoScaleContentLayer
> surface_scale_child_no_scale
=
4868 CreateNoScaleDrawableContentLayer(&delegate
);
4869 SetLayerPropertiesForTesting(surface_scale_child_no_scale
.get(),
4877 scoped_refptr
<NoScaleContentLayer
> surface_no_scale
=
4878 CreateNoScaleDrawableContentLayer(&delegate
);
4879 SetLayerPropertiesForTesting(surface_no_scale
.get(),
4882 gfx::PointF(12.f
, 12.f
),
4887 scoped_refptr
<ContentLayer
> surface_no_scale_child_scale
=
4888 CreateDrawableContentLayer(&delegate
);
4889 SetLayerPropertiesForTesting(surface_no_scale_child_scale
.get(),
4897 scoped_refptr
<NoScaleContentLayer
> surface_no_scale_child_no_scale
=
4898 CreateNoScaleDrawableContentLayer(&delegate
);
4899 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale
.get(),
4907 root
->AddChild(parent
);
4909 parent
->AddChild(surface_scale
);
4910 parent
->AddChild(surface_no_scale
);
4912 surface_scale
->SetForceRenderSurface(true);
4913 surface_scale
->AddChild(surface_scale_child_scale
);
4914 surface_scale
->AddChild(surface_scale_child_no_scale
);
4916 surface_no_scale
->SetForceRenderSurface(true);
4917 surface_no_scale
->AddChild(surface_no_scale_child_scale
);
4918 surface_no_scale
->AddChild(surface_no_scale_child_no_scale
);
4920 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
4921 host
->SetRootLayer(root
);
4923 SkMScalar device_scale_factor
= 5;
4924 SkMScalar page_scale_factor
= 7;
4926 RenderSurfaceLayerList render_surface_layer_list
;
4927 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4928 root
.get(), root
->bounds(), &render_surface_layer_list
);
4929 inputs
.device_scale_factor
= device_scale_factor
;
4930 inputs
.page_scale_factor
= page_scale_factor
;
4931 inputs
.page_scale_application_layer
= root
.get();
4932 inputs
.can_adjust_raster_scales
= true;
4933 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4935 EXPECT_CONTENTS_SCALE_EQ(
4936 device_scale_factor
* page_scale_factor
* initial_parent_scale
, parent
);
4937 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4938 initial_parent_scale
* initial_child_scale
,
4940 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale
);
4941 EXPECT_CONTENTS_SCALE_EQ(
4942 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4943 initial_child_scale
* initial_child_scale
,
4944 surface_scale_child_scale
);
4945 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale
);
4946 EXPECT_CONTENTS_SCALE_EQ(
4947 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4948 initial_child_scale
* initial_child_scale
,
4949 surface_no_scale_child_scale
);
4950 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale
);
4952 // The parent is scaled up and shouldn't need to scale during draw.
4953 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(0, 0));
4954 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(1, 1));
4956 // RenderSurfaces should always be 1:1 with their target.
4959 surface_scale
->render_surface()->draw_transform().matrix().get(0, 0));
4962 surface_scale
->render_surface()->draw_transform().matrix().get(1, 1));
4964 // The surface_scale can apply contents scale so the layer shouldn't need to
4965 // scale during draw.
4966 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(0, 0));
4967 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(1, 1));
4969 // The surface_scale_child_scale can apply contents scale so it shouldn't need
4970 // to scale during draw.
4972 1.0, surface_scale_child_scale
->draw_transform().matrix().get(0, 0));
4974 1.0, surface_scale_child_scale
->draw_transform().matrix().get(1, 1));
4976 // The surface_scale_child_no_scale can not apply contents scale, so it needs
4977 // to be scaled during draw.
4979 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4980 initial_child_scale
* initial_child_scale
,
4981 surface_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
4983 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4984 initial_child_scale
* initial_child_scale
,
4985 surface_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
4987 // RenderSurfaces should always be 1:1 with their target.
4990 surface_no_scale
->render_surface()->draw_transform().matrix().get(0, 0));
4993 surface_no_scale
->render_surface()->draw_transform().matrix().get(1, 1));
4995 // The surface_no_scale layer can not apply contents scale, so it needs to be
4996 // scaled during draw.
4997 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4998 initial_parent_scale
* initial_child_scale
,
4999 surface_no_scale
->draw_transform().matrix().get(0, 0));
5000 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
5001 initial_parent_scale
* initial_child_scale
,
5002 surface_no_scale
->draw_transform().matrix().get(1, 1));
5004 // The surface_scale_child_scale can apply contents scale so it shouldn't need
5005 // to scale during draw.
5007 1.0, surface_no_scale_child_scale
->draw_transform().matrix().get(0, 0));
5009 1.0, surface_no_scale_child_scale
->draw_transform().matrix().get(1, 1));
5011 // The surface_scale_child_no_scale can not apply contents scale, so it needs
5012 // to be scaled during draw.
5014 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5015 initial_child_scale
* initial_child_scale
,
5016 surface_no_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5018 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5019 initial_child_scale
* initial_child_scale
,
5020 surface_no_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5023 TEST_F(LayerTreeHostCommonTest
,
5024 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale
) {
5025 MockContentLayerClient delegate
;
5026 gfx::Transform identity_matrix
;
5028 gfx::Transform parent_scale_matrix
;
5029 SkMScalar initial_parent_scale
= 2.0;
5030 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
5032 gfx::Transform child_scale_matrix
;
5033 SkMScalar initial_child_scale
= 3.0;
5034 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
5036 scoped_refptr
<Layer
> root
= Layer::Create();
5037 root
->SetBounds(gfx::Size(100, 100));
5039 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
5040 SetLayerPropertiesForTesting(parent
.get(),
5041 parent_scale_matrix
,
5044 gfx::Size(100, 100),
5048 scoped_refptr
<ContentLayer
> surface_scale
=
5049 CreateDrawableContentLayer(&delegate
);
5050 SetLayerPropertiesForTesting(surface_scale
.get(),
5053 gfx::PointF(2.f
, 2.f
),
5058 scoped_refptr
<ContentLayer
> surface_scale_child_scale
=
5059 CreateDrawableContentLayer(&delegate
);
5060 SetLayerPropertiesForTesting(surface_scale_child_scale
.get(),
5068 scoped_refptr
<NoScaleContentLayer
> surface_scale_child_no_scale
=
5069 CreateNoScaleDrawableContentLayer(&delegate
);
5070 SetLayerPropertiesForTesting(surface_scale_child_no_scale
.get(),
5078 scoped_refptr
<NoScaleContentLayer
> surface_no_scale
=
5079 CreateNoScaleDrawableContentLayer(&delegate
);
5080 SetLayerPropertiesForTesting(surface_no_scale
.get(),
5083 gfx::PointF(12.f
, 12.f
),
5088 scoped_refptr
<ContentLayer
> surface_no_scale_child_scale
=
5089 CreateDrawableContentLayer(&delegate
);
5090 SetLayerPropertiesForTesting(surface_no_scale_child_scale
.get(),
5098 scoped_refptr
<NoScaleContentLayer
> surface_no_scale_child_no_scale
=
5099 CreateNoScaleDrawableContentLayer(&delegate
);
5100 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale
.get(),
5108 root
->AddChild(parent
);
5110 parent
->AddChild(surface_scale
);
5111 parent
->AddChild(surface_no_scale
);
5113 surface_scale
->SetForceRenderSurface(true);
5114 surface_scale
->AddChild(surface_scale_child_scale
);
5115 surface_scale
->AddChild(surface_scale_child_no_scale
);
5117 surface_no_scale
->SetForceRenderSurface(true);
5118 surface_no_scale
->AddChild(surface_no_scale_child_scale
);
5119 surface_no_scale
->AddChild(surface_no_scale_child_no_scale
);
5121 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5122 host
->SetRootLayer(root
);
5124 RenderSurfaceLayerList render_surface_layer_list
;
5126 SkMScalar device_scale_factor
= 5.0;
5127 SkMScalar page_scale_factor
= 7.0;
5128 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5129 root
.get(), root
->bounds(), &render_surface_layer_list
);
5130 inputs
.device_scale_factor
= device_scale_factor
;
5131 inputs
.page_scale_factor
= page_scale_factor
;
5132 inputs
.page_scale_application_layer
= root
.get();
5133 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5135 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5137 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5139 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_no_scale
);
5140 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5141 surface_scale_child_scale
);
5142 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_scale_child_no_scale
);
5143 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5144 surface_no_scale_child_scale
);
5145 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_no_scale_child_no_scale
);
5147 // The parent is scaled up during draw, since its contents are not scaled by
5148 // the transform hierarchy.
5149 EXPECT_FLOAT_EQ(initial_parent_scale
,
5150 parent
->draw_transform().matrix().get(0, 0));
5151 EXPECT_FLOAT_EQ(initial_parent_scale
,
5152 parent
->draw_transform().matrix().get(1, 1));
5154 // The child surface is scaled up during draw since its subtree is not scaled
5155 // by the transform hierarchy.
5157 initial_parent_scale
* initial_child_scale
,
5158 surface_scale
->render_surface()->draw_transform().matrix().get(0, 0));
5160 initial_parent_scale
* initial_child_scale
,
5161 surface_scale
->render_surface()->draw_transform().matrix().get(1, 1));
5163 // The surface_scale's RenderSurface is scaled during draw, so the layer does
5164 // not need to be scaled when drawing into its surface.
5165 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(0, 0));
5166 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(1, 1));
5168 // The surface_scale_child_scale is scaled when drawing into its surface,
5169 // since its content bounds are not scaled by the transform hierarchy.
5171 initial_child_scale
,
5172 surface_scale_child_scale
->draw_transform().matrix().get(0, 0));
5174 initial_child_scale
,
5175 surface_scale_child_scale
->draw_transform().matrix().get(1, 1));
5177 // The surface_scale_child_no_scale has a fixed contents scale of 1, so it
5178 // needs to be scaled by the device and page scale factors, along with the
5179 // transform hierarchy.
5181 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5182 surface_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5184 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5185 surface_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5187 // The child surface is scaled up during draw since its subtree is not scaled
5188 // by the transform hierarchy.
5190 initial_parent_scale
* initial_child_scale
,
5191 surface_no_scale
->render_surface()->draw_transform().matrix().get(0, 0));
5193 initial_parent_scale
* initial_child_scale
,
5194 surface_no_scale
->render_surface()->draw_transform().matrix().get(1, 1));
5196 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
5197 // be scaled by the device and page scale factors. Its surface is already
5198 // scaled by the transform hierarchy so those don't need to scale the layer's
5200 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
,
5201 surface_no_scale
->draw_transform().matrix().get(0, 0));
5202 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
,
5203 surface_no_scale
->draw_transform().matrix().get(1, 1));
5205 // The surface_no_scale_child_scale has its contents scaled by the page and
5206 // device scale factors, but needs to be scaled by the transform hierarchy
5209 initial_child_scale
,
5210 surface_no_scale_child_scale
->draw_transform().matrix().get(0, 0));
5212 initial_child_scale
,
5213 surface_no_scale_child_scale
->draw_transform().matrix().get(1, 1));
5215 // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it
5216 // needs to be scaled by the device and page scale factors. It also needs to
5217 // be scaled by any transform heirarchy below its target surface.
5219 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5220 surface_no_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5222 device_scale_factor
* page_scale_factor
* initial_child_scale
,
5223 surface_no_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5226 TEST_F(LayerTreeHostCommonTest
, ContentsScaleForAnimatingLayer
) {
5227 MockContentLayerClient delegate
;
5228 gfx::Transform identity_matrix
;
5230 gfx::Transform parent_scale_matrix
;
5231 SkMScalar initial_parent_scale
= 1.75;
5232 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
5234 gfx::Transform child_scale_matrix
;
5235 SkMScalar initial_child_scale
= 1.25;
5236 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
5238 scoped_refptr
<Layer
> root
= Layer::Create();
5239 root
->SetBounds(gfx::Size(100, 100));
5241 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
5242 SetLayerPropertiesForTesting(parent
.get(),
5243 parent_scale_matrix
,
5246 gfx::Size(100, 100),
5250 scoped_refptr
<ContentLayer
> child_scale
=
5251 CreateDrawableContentLayer(&delegate
);
5252 SetLayerPropertiesForTesting(child_scale
.get(),
5255 gfx::PointF(2.f
, 2.f
),
5260 root
->AddChild(parent
);
5262 parent
->AddChild(child_scale
);
5264 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5265 host
->SetRootLayer(root
);
5267 // Now put an animating transform on child.
5268 int animation_id
= AddAnimatedTransformToController(
5269 child_scale
->layer_animation_controller(), 10.0, 30, 0);
5272 RenderSurfaceLayerList render_surface_layer_list
;
5273 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5274 root
.get(), root
->bounds(), &render_surface_layer_list
);
5275 inputs
.can_adjust_raster_scales
= true;
5276 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5278 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale
, parent
);
5279 // The layers with animating transforms should not compute a contents scale
5280 // other than 1 until they finish animating.
5281 EXPECT_CONTENTS_SCALE_EQ(1, child_scale
);
5284 // Remove the animation, now it can save a raster scale.
5285 child_scale
->layer_animation_controller()->RemoveAnimation(animation_id
);
5288 RenderSurfaceLayerList render_surface_layer_list
;
5289 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5290 root
.get(), root
->bounds(), &render_surface_layer_list
);
5291 inputs
.can_adjust_raster_scales
= true;
5292 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5294 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale
, parent
);
5295 // The layers with animating transforms should not compute a contents scale
5296 // other than 1 until they finish animating.
5297 EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale
* initial_child_scale
,
5302 TEST_F(LayerTreeHostCommonTest
,
5303 ChangeInContentBoundsOrScaleTriggersPushProperties
) {
5304 MockContentLayerClient delegate
;
5305 scoped_refptr
<Layer
> root
= Layer::Create();
5306 scoped_refptr
<Layer
> child
= CreateDrawableContentLayer(&delegate
);
5307 root
->AddChild(child
);
5309 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5310 host
->SetRootLayer(root
);
5312 gfx::Transform identity_matrix
;
5313 SetLayerPropertiesForTesting(root
.get(),
5317 gfx::Size(100, 100),
5320 SetLayerPropertiesForTesting(child
.get(),
5324 gfx::Size(100, 100),
5328 root
->reset_needs_push_properties_for_testing();
5329 child
->reset_needs_push_properties_for_testing();
5331 // This will change both layers' content bounds.
5332 ExecuteCalculateDrawProperties(root
.get());
5333 EXPECT_TRUE(root
->needs_push_properties());
5334 EXPECT_TRUE(child
->needs_push_properties());
5336 root
->reset_needs_push_properties_for_testing();
5337 child
->reset_needs_push_properties_for_testing();
5339 // This will change only the child layer's contents scale and content bounds,
5340 // since the root layer is not a ContentsScalingLayer.
5341 ExecuteCalculateDrawProperties(root
.get(), 2.f
);
5342 EXPECT_FALSE(root
->needs_push_properties());
5343 EXPECT_TRUE(child
->needs_push_properties());
5345 root
->reset_needs_push_properties_for_testing();
5346 child
->reset_needs_push_properties_for_testing();
5348 // This will not change either layer's contents scale or content bounds.
5349 ExecuteCalculateDrawProperties(root
.get(), 2.f
);
5350 EXPECT_FALSE(root
->needs_push_properties());
5351 EXPECT_FALSE(child
->needs_push_properties());
5354 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceTransformsInHighDPI
) {
5355 MockContentLayerClient delegate
;
5356 gfx::Transform identity_matrix
;
5358 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
5359 SetLayerPropertiesForTesting(parent
.get(),
5367 scoped_refptr
<ContentLayer
> child
= CreateDrawableContentLayer(&delegate
);
5368 SetLayerPropertiesForTesting(child
.get(),
5371 gfx::PointF(2.f
, 2.f
),
5376 gfx::Transform replica_transform
;
5377 replica_transform
.Scale(1.0, -1.0);
5378 scoped_refptr
<ContentLayer
> replica
= CreateDrawableContentLayer(&delegate
);
5379 SetLayerPropertiesForTesting(replica
.get(),
5382 gfx::PointF(2.f
, 2.f
),
5387 // This layer should end up in the same surface as child, with the same draw
5388 // and screen space transforms.
5389 scoped_refptr
<ContentLayer
> duplicate_child_non_owner
=
5390 CreateDrawableContentLayer(&delegate
);
5391 SetLayerPropertiesForTesting(duplicate_child_non_owner
.get(),
5399 parent
->AddChild(child
);
5400 child
->AddChild(duplicate_child_non_owner
);
5401 child
->SetReplicaLayer(replica
.get());
5403 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5404 host
->SetRootLayer(parent
);
5406 RenderSurfaceLayerList render_surface_layer_list
;
5408 float device_scale_factor
= 1.5f
;
5409 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5410 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
5411 inputs
.device_scale_factor
= device_scale_factor
;
5412 inputs
.can_adjust_raster_scales
= true;
5413 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5415 // We should have two render surfaces. The root's render surface and child's
5416 // render surface (it needs one because it has a replica layer).
5417 EXPECT_EQ(2u, render_surface_layer_list
.size());
5419 gfx::Transform expected_parent_transform
;
5420 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
5421 parent
->screen_space_transform());
5422 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
5423 parent
->draw_transform());
5425 gfx::Transform expected_draw_transform
;
5426 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform
,
5427 child
->draw_transform());
5429 gfx::Transform expected_screen_space_transform
;
5430 expected_screen_space_transform
.Translate(
5431 device_scale_factor
* child
->position().x(),
5432 device_scale_factor
* child
->position().y());
5433 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform
,
5434 child
->screen_space_transform());
5436 gfx::Transform expected_duplicate_child_draw_transform
=
5437 child
->draw_transform();
5438 EXPECT_TRANSFORMATION_MATRIX_EQ(child
->draw_transform(),
5439 duplicate_child_non_owner
->draw_transform());
5440 EXPECT_TRANSFORMATION_MATRIX_EQ(
5441 child
->screen_space_transform(),
5442 duplicate_child_non_owner
->screen_space_transform());
5443 EXPECT_RECT_EQ(child
->drawable_content_rect(),
5444 duplicate_child_non_owner
->drawable_content_rect());
5445 EXPECT_EQ(child
->content_bounds(),
5446 duplicate_child_non_owner
->content_bounds());
5448 gfx::Transform expected_render_surface_draw_transform
;
5449 expected_render_surface_draw_transform
.Translate(
5450 device_scale_factor
* child
->position().x(),
5451 device_scale_factor
* child
->position().y());
5452 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform
,
5453 child
->render_surface()->draw_transform());
5455 gfx::Transform expected_surface_draw_transform
;
5456 expected_surface_draw_transform
.Translate(device_scale_factor
* 2.f
,
5457 device_scale_factor
* 2.f
);
5458 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform
,
5459 child
->render_surface()->draw_transform());
5461 gfx::Transform expected_surface_screen_space_transform
;
5462 expected_surface_screen_space_transform
.Translate(device_scale_factor
* 2.f
,
5463 device_scale_factor
* 2.f
);
5464 EXPECT_TRANSFORMATION_MATRIX_EQ(
5465 expected_surface_screen_space_transform
,
5466 child
->render_surface()->screen_space_transform());
5468 gfx::Transform expected_replica_draw_transform
;
5469 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
5470 expected_replica_draw_transform
.matrix().set(0, 3, 6.0);
5471 expected_replica_draw_transform
.matrix().set(1, 3, 6.0);
5472 EXPECT_TRANSFORMATION_MATRIX_EQ(
5473 expected_replica_draw_transform
,
5474 child
->render_surface()->replica_draw_transform());
5476 gfx::Transform expected_replica_screen_space_transform
;
5477 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
5478 expected_replica_screen_space_transform
.matrix().set(0, 3, 6.0);
5479 expected_replica_screen_space_transform
.matrix().set(1, 3, 6.0);
5480 EXPECT_TRANSFORMATION_MATRIX_EQ(
5481 expected_replica_screen_space_transform
,
5482 child
->render_surface()->replica_screen_space_transform());
5483 EXPECT_TRANSFORMATION_MATRIX_EQ(
5484 expected_replica_screen_space_transform
,
5485 child
->render_surface()->replica_screen_space_transform());
5488 TEST_F(LayerTreeHostCommonTest
,
5489 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition
) {
5490 MockContentLayerClient delegate
;
5491 gfx::Transform identity_matrix
;
5493 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
5494 SetLayerPropertiesForTesting(parent
.get(),
5502 scoped_refptr
<ContentLayer
> child
= CreateDrawableContentLayer(&delegate
);
5503 SetLayerPropertiesForTesting(child
.get(),
5511 gfx::Transform replica_transform
;
5512 replica_transform
.Scale(1.0, -1.0);
5513 scoped_refptr
<ContentLayer
> replica
= CreateDrawableContentLayer(&delegate
);
5514 SetLayerPropertiesForTesting(replica
.get(),
5522 // This layer should end up in the same surface as child, with the same draw
5523 // and screen space transforms.
5524 scoped_refptr
<ContentLayer
> duplicate_child_non_owner
=
5525 CreateDrawableContentLayer(&delegate
);
5526 SetLayerPropertiesForTesting(duplicate_child_non_owner
.get(),
5534 parent
->AddChild(child
);
5535 child
->AddChild(duplicate_child_non_owner
);
5536 child
->SetReplicaLayer(replica
.get());
5538 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5539 host
->SetRootLayer(parent
);
5541 float device_scale_factor
= 1.7f
;
5543 RenderSurfaceLayerList render_surface_layer_list
;
5544 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5545 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
5546 inputs
.device_scale_factor
= device_scale_factor
;
5547 inputs
.can_adjust_raster_scales
= true;
5548 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5550 // We should have two render surfaces. The root's render surface and child's
5551 // render surface (it needs one because it has a replica layer).
5552 EXPECT_EQ(2u, render_surface_layer_list
.size());
5554 gfx::Transform identity_transform
;
5556 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5557 parent
->screen_space_transform());
5558 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
, parent
->draw_transform());
5559 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
, child
->draw_transform());
5560 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5561 child
->screen_space_transform());
5562 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5563 duplicate_child_non_owner
->draw_transform());
5564 EXPECT_TRANSFORMATION_MATRIX_EQ(
5565 identity_transform
, duplicate_child_non_owner
->screen_space_transform());
5566 EXPECT_RECT_EQ(child
->drawable_content_rect(),
5567 duplicate_child_non_owner
->drawable_content_rect());
5568 EXPECT_EQ(child
->content_bounds(),
5569 duplicate_child_non_owner
->content_bounds());
5571 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5572 child
->render_surface()->draw_transform());
5573 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5574 child
->render_surface()->draw_transform());
5575 EXPECT_TRANSFORMATION_MATRIX_EQ(
5576 identity_transform
, child
->render_surface()->screen_space_transform());
5578 gfx::Transform expected_replica_draw_transform
;
5579 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
5580 EXPECT_TRANSFORMATION_MATRIX_EQ(
5581 expected_replica_draw_transform
,
5582 child
->render_surface()->replica_draw_transform());
5584 gfx::Transform expected_replica_screen_space_transform
;
5585 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
5586 EXPECT_TRANSFORMATION_MATRIX_EQ(
5587 expected_replica_screen_space_transform
,
5588 child
->render_surface()->replica_screen_space_transform());
5591 TEST_F(LayerTreeHostCommonTest
, SubtreeSearch
) {
5592 scoped_refptr
<Layer
> root
= Layer::Create();
5593 scoped_refptr
<Layer
> child
= Layer::Create();
5594 scoped_refptr
<Layer
> grand_child
= Layer::Create();
5595 scoped_refptr
<Layer
> mask_layer
= Layer::Create();
5596 scoped_refptr
<Layer
> replica_layer
= Layer::Create();
5598 grand_child
->SetReplicaLayer(replica_layer
.get());
5599 child
->AddChild(grand_child
.get());
5600 child
->SetMaskLayer(mask_layer
.get());
5601 root
->AddChild(child
.get());
5603 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5604 host
->SetRootLayer(root
);
5606 int nonexistent_id
= -1;
5608 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), root
->id()));
5610 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), child
->id()));
5613 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), grand_child
->id()));
5616 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), mask_layer
->id()));
5619 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), replica_layer
->id()));
5621 0, LayerTreeHostCommon::FindLayerInSubtree(root
.get(), nonexistent_id
));
5624 TEST_F(LayerTreeHostCommonTest
, TransparentChildRenderSurfaceCreation
) {
5625 scoped_refptr
<Layer
> root
= Layer::Create();
5626 scoped_refptr
<Layer
> child
= Layer::Create();
5627 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
5628 make_scoped_refptr(new LayerWithForcedDrawsContent());
5630 const gfx::Transform identity_matrix
;
5631 SetLayerPropertiesForTesting(root
.get(),
5635 gfx::Size(100, 100),
5638 SetLayerPropertiesForTesting(child
.get(),
5645 SetLayerPropertiesForTesting(grand_child
.get(),
5653 root
->AddChild(child
);
5654 child
->AddChild(grand_child
);
5655 child
->SetOpacity(0.5f
);
5657 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5658 host
->SetRootLayer(root
);
5660 ExecuteCalculateDrawProperties(root
.get());
5662 EXPECT_FALSE(child
->render_surface());
5665 TEST_F(LayerTreeHostCommonTest
, OpacityAnimatingOnPendingTree
) {
5666 FakeImplProxy proxy
;
5667 TestSharedBitmapManager shared_bitmap_manager
;
5668 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5669 host_impl
.CreatePendingTree();
5670 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
5672 const gfx::Transform identity_matrix
;
5673 SetLayerPropertiesForTesting(root
.get(),
5677 gfx::Size(100, 100),
5680 root
->SetDrawsContent(true);
5682 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
5683 SetLayerPropertiesForTesting(child
.get(),
5690 child
->SetDrawsContent(true);
5691 child
->SetOpacity(0.0f
);
5693 // Add opacity animation.
5694 AddOpacityTransitionToController(
5695 child
->layer_animation_controller(), 10.0, 0.0f
, 1.0f
, false);
5697 root
->AddChild(child
.Pass());
5699 LayerImplList render_surface_layer_list
;
5700 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5701 root
.get(), root
->bounds(), &render_surface_layer_list
);
5702 inputs
.can_adjust_raster_scales
= true;
5703 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5705 // We should have one render surface and two layers. The child
5706 // layer should be included even though it is transparent.
5707 ASSERT_EQ(1u, render_surface_layer_list
.size());
5708 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5711 typedef std::tr1::tuple
<bool, bool> LCDTextTestParam
;
5713 : public LayerTreeHostCommonTestBase
,
5714 public testing::TestWithParam
<LCDTextTestParam
> {
5716 virtual void SetUp() {
5717 can_use_lcd_text_
= std::tr1::get
<0>(GetParam());
5719 root_
= Layer::Create();
5720 child_
= Layer::Create();
5721 grand_child_
= Layer::Create();
5722 child_
->AddChild(grand_child_
.get());
5723 root_
->AddChild(child_
.get());
5725 gfx::Transform identity_matrix
;
5726 SetLayerPropertiesForTesting(root_
.get(),
5733 SetLayerPropertiesForTesting(child_
.get(),
5740 SetLayerPropertiesForTesting(grand_child_
.get(),
5748 child_
->SetForceRenderSurface(std::tr1::get
<1>(GetParam()));
5750 host_
= FakeLayerTreeHost::Create();
5751 host_
->SetRootLayer(root_
);
5754 bool can_use_lcd_text_
;
5755 scoped_ptr
<FakeLayerTreeHost
> host_
;
5756 scoped_refptr
<Layer
> root_
;
5757 scoped_refptr
<Layer
> child_
;
5758 scoped_refptr
<Layer
> grand_child_
;
5761 TEST_P(LCDTextTest
, CanUseLCDText
) {
5762 // Case 1: Identity transform.
5763 gfx::Transform identity_matrix
;
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_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5768 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5770 // Case 2: Integral translation.
5771 gfx::Transform integral_translation
;
5772 integral_translation
.Translate(1.0, 2.0);
5773 child_
->SetTransform(integral_translation
);
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_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5778 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5780 // Case 3: Non-integral translation.
5781 gfx::Transform non_integral_translation
;
5782 non_integral_translation
.Translate(1.5, 2.5);
5783 child_
->SetTransform(non_integral_translation
);
5784 ExecuteCalculateDrawProperties(
5785 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5786 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5787 EXPECT_FALSE(child_
->can_use_lcd_text());
5788 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5790 // Case 4: Rotation.
5791 gfx::Transform rotation
;
5792 rotation
.Rotate(10.0);
5793 child_
->SetTransform(rotation
);
5794 ExecuteCalculateDrawProperties(
5795 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5796 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5797 EXPECT_FALSE(child_
->can_use_lcd_text());
5798 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5801 gfx::Transform scale
;
5802 scale
.Scale(2.0, 2.0);
5803 child_
->SetTransform(scale
);
5804 ExecuteCalculateDrawProperties(
5805 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5806 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5807 EXPECT_FALSE(child_
->can_use_lcd_text());
5808 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5811 gfx::Transform skew
;
5813 child_
->SetTransform(skew
);
5814 ExecuteCalculateDrawProperties(
5815 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5816 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5817 EXPECT_FALSE(child_
->can_use_lcd_text());
5818 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5820 // Case 7: Translucent.
5821 child_
->SetTransform(identity_matrix
);
5822 child_
->SetOpacity(0.5f
);
5823 ExecuteCalculateDrawProperties(
5824 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5825 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5826 EXPECT_FALSE(child_
->can_use_lcd_text());
5827 EXPECT_FALSE(grand_child_
->can_use_lcd_text());
5829 // Case 8: Sanity check: restore transform and opacity.
5830 child_
->SetTransform(identity_matrix
);
5831 child_
->SetOpacity(1.f
);
5832 ExecuteCalculateDrawProperties(
5833 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5834 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5835 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5836 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5839 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimation
) {
5840 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
5841 ExecuteCalculateDrawProperties(
5842 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5843 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5844 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5845 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5847 // Add opacity animation.
5848 child_
->SetOpacity(0.9f
);
5849 AddOpacityTransitionToController(
5850 child_
->layer_animation_controller(), 10.0, 0.9f
, 0.1f
, false);
5852 ExecuteCalculateDrawProperties(
5853 root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
);
5854 // Text AA should not be adjusted while animation is active.
5855 // Make sure LCD text AA setting remains unchanged.
5856 EXPECT_EQ(can_use_lcd_text_
, root_
->can_use_lcd_text());
5857 EXPECT_EQ(can_use_lcd_text_
, child_
->can_use_lcd_text());
5858 EXPECT_EQ(can_use_lcd_text_
, grand_child_
->can_use_lcd_text());
5861 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest
,
5863 testing::Combine(testing::Bool(), testing::Bool()));
5865 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayer
) {
5866 FakeImplProxy proxy
;
5867 TestSharedBitmapManager shared_bitmap_manager
;
5868 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5869 host_impl
.CreatePendingTree();
5870 const gfx::Transform identity_matrix
;
5872 scoped_refptr
<Layer
> root
= Layer::Create();
5873 SetLayerPropertiesForTesting(root
.get(),
5880 root
->SetIsDrawable(true);
5882 scoped_refptr
<Layer
> child
= Layer::Create();
5883 SetLayerPropertiesForTesting(child
.get(),
5890 child
->SetIsDrawable(true);
5892 scoped_refptr
<Layer
> grand_child
= Layer::Create();
5893 SetLayerPropertiesForTesting(grand_child
.get(),
5900 grand_child
->SetIsDrawable(true);
5901 grand_child
->SetHideLayerAndSubtree(true);
5903 child
->AddChild(grand_child
);
5904 root
->AddChild(child
);
5906 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
5907 host
->SetRootLayer(root
);
5909 RenderSurfaceLayerList render_surface_layer_list
;
5910 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5911 root
.get(), root
->bounds(), &render_surface_layer_list
);
5912 inputs
.can_adjust_raster_scales
= true;
5913 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5915 // We should have one render surface and two layers. The grand child has
5917 ASSERT_EQ(1u, render_surface_layer_list
.size());
5918 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5919 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
5920 EXPECT_EQ(child
->id(), root
->render_surface()->layer_list().at(1)->id());
5923 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayerImpl
) {
5924 FakeImplProxy proxy
;
5925 TestSharedBitmapManager shared_bitmap_manager
;
5926 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5927 host_impl
.CreatePendingTree();
5928 const gfx::Transform identity_matrix
;
5930 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
5931 SetLayerPropertiesForTesting(root
.get(),
5938 root
->SetDrawsContent(true);
5940 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
5941 SetLayerPropertiesForTesting(child
.get(),
5948 child
->SetDrawsContent(true);
5950 scoped_ptr
<LayerImpl
> grand_child
=
5951 LayerImpl::Create(host_impl
.pending_tree(), 3);
5952 SetLayerPropertiesForTesting(grand_child
.get(),
5959 grand_child
->SetDrawsContent(true);
5960 grand_child
->SetHideLayerAndSubtree(true);
5962 child
->AddChild(grand_child
.Pass());
5963 root
->AddChild(child
.Pass());
5965 LayerImplList render_surface_layer_list
;
5966 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5967 root
.get(), root
->bounds(), &render_surface_layer_list
);
5968 inputs
.can_adjust_raster_scales
= true;
5969 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5971 // We should have one render surface and two layers. The grand child has
5973 ASSERT_EQ(1u, render_surface_layer_list
.size());
5974 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5975 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
5976 EXPECT_EQ(2, root
->render_surface()->layer_list().at(1)->id());
5979 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayers
) {
5980 FakeImplProxy proxy
;
5981 TestSharedBitmapManager shared_bitmap_manager
;
5982 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5983 host_impl
.CreatePendingTree();
5984 const gfx::Transform identity_matrix
;
5986 scoped_refptr
<Layer
> root
= Layer::Create();
5987 SetLayerPropertiesForTesting(root
.get(),
5994 root
->SetIsDrawable(true);
5996 scoped_refptr
<Layer
> child
= Layer::Create();
5997 SetLayerPropertiesForTesting(child
.get(),
6004 child
->SetIsDrawable(true);
6005 child
->SetHideLayerAndSubtree(true);
6007 scoped_refptr
<Layer
> grand_child
= Layer::Create();
6008 SetLayerPropertiesForTesting(grand_child
.get(),
6015 grand_child
->SetIsDrawable(true);
6017 child
->AddChild(grand_child
);
6018 root
->AddChild(child
);
6020 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6021 host
->SetRootLayer(root
);
6023 RenderSurfaceLayerList render_surface_layer_list
;
6024 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6025 root
.get(), root
->bounds(), &render_surface_layer_list
);
6026 inputs
.can_adjust_raster_scales
= true;
6027 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6029 // We should have one render surface and one layers. The child has
6030 // hidden itself and the grand child.
6031 ASSERT_EQ(1u, render_surface_layer_list
.size());
6032 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
6033 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6036 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayersImpl
) {
6037 FakeImplProxy proxy
;
6038 TestSharedBitmapManager shared_bitmap_manager
;
6039 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6040 host_impl
.CreatePendingTree();
6041 const gfx::Transform identity_matrix
;
6043 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
6044 SetLayerPropertiesForTesting(root
.get(),
6051 root
->SetDrawsContent(true);
6053 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
6054 SetLayerPropertiesForTesting(child
.get(),
6061 child
->SetDrawsContent(true);
6062 child
->SetHideLayerAndSubtree(true);
6064 scoped_ptr
<LayerImpl
> grand_child
=
6065 LayerImpl::Create(host_impl
.pending_tree(), 3);
6066 SetLayerPropertiesForTesting(grand_child
.get(),
6073 grand_child
->SetDrawsContent(true);
6075 child
->AddChild(grand_child
.Pass());
6076 root
->AddChild(child
.Pass());
6078 LayerImplList render_surface_layer_list
;
6079 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6080 root
.get(), root
->bounds(), &render_surface_layer_list
);
6081 inputs
.can_adjust_raster_scales
= true;
6082 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6084 // We should have one render surface and one layers. The child has
6085 // hidden itself and the grand child.
6086 ASSERT_EQ(1u, render_surface_layer_list
.size());
6087 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
6088 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
6091 void EmptyCopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {}
6093 TEST_F(LayerTreeHostCommonTest
, SubtreeHiddenWithCopyRequest
) {
6094 FakeImplProxy proxy
;
6095 TestSharedBitmapManager shared_bitmap_manager
;
6096 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6097 host_impl
.CreatePendingTree();
6098 const gfx::Transform identity_matrix
;
6100 scoped_refptr
<Layer
> root
= Layer::Create();
6101 SetLayerPropertiesForTesting(root
.get(),
6108 root
->SetIsDrawable(true);
6110 scoped_refptr
<Layer
> copy_grand_parent
= Layer::Create();
6111 SetLayerPropertiesForTesting(copy_grand_parent
.get(),
6118 copy_grand_parent
->SetIsDrawable(true);
6120 scoped_refptr
<Layer
> copy_parent
= Layer::Create();
6121 SetLayerPropertiesForTesting(copy_parent
.get(),
6128 copy_parent
->SetIsDrawable(true);
6129 copy_parent
->SetForceRenderSurface(true);
6131 scoped_refptr
<Layer
> copy_layer
= Layer::Create();
6132 SetLayerPropertiesForTesting(copy_layer
.get(),
6139 copy_layer
->SetIsDrawable(true);
6141 scoped_refptr
<Layer
> copy_child
= Layer::Create();
6142 SetLayerPropertiesForTesting(copy_child
.get(),
6149 copy_child
->SetIsDrawable(true);
6151 scoped_refptr
<Layer
> copy_grand_parent_sibling_before
= Layer::Create();
6152 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before
.get(),
6159 copy_grand_parent_sibling_before
->SetIsDrawable(true);
6161 scoped_refptr
<Layer
> copy_grand_parent_sibling_after
= Layer::Create();
6162 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after
.get(),
6169 copy_grand_parent_sibling_after
->SetIsDrawable(true);
6171 copy_layer
->AddChild(copy_child
);
6172 copy_parent
->AddChild(copy_layer
);
6173 copy_grand_parent
->AddChild(copy_parent
);
6174 root
->AddChild(copy_grand_parent_sibling_before
);
6175 root
->AddChild(copy_grand_parent
);
6176 root
->AddChild(copy_grand_parent_sibling_after
);
6178 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6179 host
->SetRootLayer(root
);
6181 // Hide the copy_grand_parent and its subtree. But make a copy request in that
6182 // hidden subtree on copy_layer.
6183 copy_grand_parent
->SetHideLayerAndSubtree(true);
6184 copy_grand_parent_sibling_before
->SetHideLayerAndSubtree(true);
6185 copy_grand_parent_sibling_after
->SetHideLayerAndSubtree(true);
6186 copy_layer
->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6187 base::Bind(&EmptyCopyOutputCallback
)));
6188 EXPECT_TRUE(copy_layer
->HasCopyRequest());
6190 RenderSurfaceLayerList render_surface_layer_list
;
6191 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6192 root
.get(), root
->bounds(), &render_surface_layer_list
);
6193 inputs
.can_adjust_raster_scales
= true;
6194 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6196 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
6197 EXPECT_TRUE(copy_grand_parent
->draw_properties().
6198 layer_or_descendant_has_copy_request
);
6199 EXPECT_TRUE(copy_parent
->draw_properties().
6200 layer_or_descendant_has_copy_request
);
6201 EXPECT_TRUE(copy_layer
->draw_properties().
6202 layer_or_descendant_has_copy_request
);
6203 EXPECT_FALSE(copy_child
->draw_properties().
6204 layer_or_descendant_has_copy_request
);
6205 EXPECT_FALSE(copy_grand_parent_sibling_before
->draw_properties().
6206 layer_or_descendant_has_copy_request
);
6207 EXPECT_FALSE(copy_grand_parent_sibling_after
->draw_properties().
6208 layer_or_descendant_has_copy_request
);
6210 // We should have three render surfaces, one for the root, one for the parent
6211 // since it owns a surface, and one for the copy_layer.
6212 ASSERT_EQ(3u, render_surface_layer_list
.size());
6213 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
6214 EXPECT_EQ(copy_parent
->id(), render_surface_layer_list
.at(1)->id());
6215 EXPECT_EQ(copy_layer
->id(), render_surface_layer_list
.at(2)->id());
6217 // The root render surface should have 2 contributing layers. The
6218 // copy_grand_parent is hidden along with its siblings, but the copy_parent
6219 // will appear since something in its subtree needs to be drawn for a copy
6221 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
6222 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6223 EXPECT_EQ(copy_parent
->id(),
6224 root
->render_surface()->layer_list().at(1)->id());
6226 // Nothing actually draws into the copy parent, so only the copy_layer will
6227 // appear in its list, since it needs to be drawn for the copy request.
6228 ASSERT_EQ(1u, copy_parent
->render_surface()->layer_list().size());
6229 EXPECT_EQ(copy_layer
->id(),
6230 copy_parent
->render_surface()->layer_list().at(0)->id());
6232 // The copy_layer's render surface should have two contributing layers.
6233 ASSERT_EQ(2u, copy_layer
->render_surface()->layer_list().size());
6234 EXPECT_EQ(copy_layer
->id(),
6235 copy_layer
->render_surface()->layer_list().at(0)->id());
6236 EXPECT_EQ(copy_child
->id(),
6237 copy_layer
->render_surface()->layer_list().at(1)->id());
6240 TEST_F(LayerTreeHostCommonTest
, ClippedOutCopyRequest
) {
6241 FakeImplProxy proxy
;
6242 TestSharedBitmapManager shared_bitmap_manager
;
6243 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6244 host_impl
.CreatePendingTree();
6245 const gfx::Transform identity_matrix
;
6247 scoped_refptr
<Layer
> root
= Layer::Create();
6248 SetLayerPropertiesForTesting(root
.get(),
6255 root
->SetIsDrawable(true);
6257 scoped_refptr
<Layer
> copy_parent
= Layer::Create();
6258 SetLayerPropertiesForTesting(copy_parent
.get(),
6265 copy_parent
->SetIsDrawable(true);
6266 copy_parent
->SetMasksToBounds(true);
6268 scoped_refptr
<Layer
> copy_layer
= Layer::Create();
6269 SetLayerPropertiesForTesting(copy_layer
.get(),
6276 copy_layer
->SetIsDrawable(true);
6278 scoped_refptr
<Layer
> copy_child
= Layer::Create();
6279 SetLayerPropertiesForTesting(copy_child
.get(),
6286 copy_child
->SetIsDrawable(true);
6288 copy_layer
->AddChild(copy_child
);
6289 copy_parent
->AddChild(copy_layer
);
6290 root
->AddChild(copy_parent
);
6292 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6293 host
->SetRootLayer(root
);
6295 copy_layer
->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6296 base::Bind(&EmptyCopyOutputCallback
)));
6297 EXPECT_TRUE(copy_layer
->HasCopyRequest());
6299 RenderSurfaceLayerList render_surface_layer_list
;
6300 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6301 root
.get(), root
->bounds(), &render_surface_layer_list
);
6302 inputs
.can_adjust_raster_scales
= true;
6303 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6305 // We should have one render surface, as the others are clipped out.
6306 ASSERT_EQ(1u, render_surface_layer_list
.size());
6307 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
6309 // The root render surface should only have 1 contributing layer, since the
6310 // other layers are empty/clipped away.
6311 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
6312 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6315 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInsideSurface
) {
6316 FakeImplProxy proxy
;
6317 TestSharedBitmapManager shared_bitmap_manager
;
6318 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6319 host_impl
.CreatePendingTree();
6320 const gfx::Transform identity_matrix
;
6322 scoped_refptr
<Layer
> root
= Layer::Create();
6323 SetLayerPropertiesForTesting(root
.get(),
6330 root
->SetIsDrawable(true);
6332 // The surface is moved slightly outside of the viewport.
6333 scoped_refptr
<Layer
> surface
= Layer::Create();
6334 SetLayerPropertiesForTesting(surface
.get(),
6337 gfx::PointF(-10, -20),
6341 surface
->SetForceRenderSurface(true);
6343 scoped_refptr
<Layer
> surface_child
= Layer::Create();
6344 SetLayerPropertiesForTesting(surface_child
.get(),
6351 surface_child
->SetIsDrawable(true);
6353 surface
->AddChild(surface_child
);
6354 root
->AddChild(surface
);
6356 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6357 host
->SetRootLayer(root
);
6359 RenderSurfaceLayerList render_surface_layer_list
;
6360 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6361 root
.get(), root
->bounds(), &render_surface_layer_list
);
6362 inputs
.can_adjust_raster_scales
= true;
6363 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6365 // The visible_content_rect for the |surface_child| should not be clipped by
6367 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
6368 surface_child
->visible_content_rect().ToString());
6371 TEST_F(LayerTreeHostCommonTest
, TransformedClipParent
) {
6372 // Ensure that a transform between the layer and its render surface is not a
6373 // problem. Constructs the following layer tree.
6375 // root (a render surface)
6377 // + clip_parent (scaled)
6378 // + intervening_clipping_layer
6381 // The render surface should be resized correctly and the clip child should
6382 // inherit the right clip rect.
6383 scoped_refptr
<Layer
> root
= Layer::Create();
6384 scoped_refptr
<Layer
> render_surface
= Layer::Create();
6385 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6386 scoped_refptr
<Layer
> intervening
= Layer::Create();
6387 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6388 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6390 root
->AddChild(render_surface
);
6391 render_surface
->AddChild(clip_parent
);
6392 clip_parent
->AddChild(intervening
);
6393 intervening
->AddChild(clip_child
);
6395 clip_child
->SetClipParent(clip_parent
.get());
6397 intervening
->SetMasksToBounds(true);
6398 clip_parent
->SetMasksToBounds(true);
6400 render_surface
->SetForceRenderSurface(true);
6402 gfx::Transform scale_transform
;
6403 scale_transform
.Scale(2, 2);
6405 gfx::Transform identity_transform
;
6407 SetLayerPropertiesForTesting(root
.get(),
6414 SetLayerPropertiesForTesting(render_surface
.get(),
6421 SetLayerPropertiesForTesting(clip_parent
.get(),
6424 gfx::PointF(1.f
, 1.f
),
6428 SetLayerPropertiesForTesting(intervening
.get(),
6431 gfx::PointF(1.f
, 1.f
),
6435 SetLayerPropertiesForTesting(clip_child
.get(),
6438 gfx::PointF(1.f
, 1.f
),
6443 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6444 host
->SetRootLayer(root
);
6446 ExecuteCalculateDrawProperties(root
.get());
6448 ASSERT_TRUE(root
->render_surface());
6449 ASSERT_TRUE(render_surface
->render_surface());
6451 // Ensure that we've inherited our clip parent's clip and weren't affected
6452 // by the intervening clip layer.
6453 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
6454 clip_parent
->clip_rect().ToString());
6455 ASSERT_EQ(clip_parent
->clip_rect().ToString(),
6456 clip_child
->clip_rect().ToString());
6457 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
6458 intervening
->clip_rect().ToString());
6460 // Ensure that the render surface reports a content rect that has been grown
6461 // to accomodate for the clip child.
6462 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
6463 render_surface
->render_surface()->content_rect().ToString());
6465 // The above check implies the two below, but they nicely demonstrate that
6466 // we've grown, despite the intervening layer's clip.
6467 ASSERT_TRUE(clip_parent
->clip_rect().Contains(
6468 render_surface
->render_surface()->content_rect()));
6469 ASSERT_FALSE(intervening
->clip_rect().Contains(
6470 render_surface
->render_surface()->content_rect()));
6473 TEST_F(LayerTreeHostCommonTest
, ClipParentWithInterveningRenderSurface
) {
6474 // Ensure that intervening render surfaces are not a problem in the basic
6475 // case. In the following tree, both render surfaces should be resized to
6476 // accomodate for the clip child, despite an intervening clip.
6478 // root (a render surface)
6479 // + clip_parent (masks to bounds)
6480 // + render_surface1 (sets opacity)
6481 // + intervening (masks to bounds)
6482 // + render_surface2 (also sets opacity)
6485 scoped_refptr
<Layer
> root
= Layer::Create();
6486 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6487 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
6488 scoped_refptr
<Layer
> intervening
= Layer::Create();
6489 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
6490 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6491 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6493 root
->AddChild(clip_parent
);
6494 clip_parent
->AddChild(render_surface1
);
6495 render_surface1
->AddChild(intervening
);
6496 intervening
->AddChild(render_surface2
);
6497 render_surface2
->AddChild(clip_child
);
6499 clip_child
->SetClipParent(clip_parent
.get());
6501 intervening
->SetMasksToBounds(true);
6502 clip_parent
->SetMasksToBounds(true);
6504 render_surface1
->SetForceRenderSurface(true);
6505 render_surface2
->SetForceRenderSurface(true);
6507 gfx::Transform translation_transform
;
6508 translation_transform
.Translate(2, 2);
6510 gfx::Transform identity_transform
;
6511 SetLayerPropertiesForTesting(root
.get(),
6518 SetLayerPropertiesForTesting(clip_parent
.get(),
6519 translation_transform
,
6521 gfx::PointF(1.f
, 1.f
),
6525 SetLayerPropertiesForTesting(render_surface1
.get(),
6532 SetLayerPropertiesForTesting(intervening
.get(),
6535 gfx::PointF(1.f
, 1.f
),
6539 SetLayerPropertiesForTesting(render_surface2
.get(),
6546 SetLayerPropertiesForTesting(clip_child
.get(),
6549 gfx::PointF(-10.f
, -10.f
),
6554 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6555 host
->SetRootLayer(root
);
6557 ExecuteCalculateDrawProperties(root
.get());
6559 EXPECT_TRUE(root
->render_surface());
6560 EXPECT_TRUE(render_surface1
->render_surface());
6561 EXPECT_TRUE(render_surface2
->render_surface());
6563 // Since the render surfaces could have expanded, they should not clip (their
6564 // bounds would no longer be reliable). We should resort to layer clipping
6566 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6567 render_surface1
->render_surface()->clip_rect().ToString());
6568 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6569 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6570 render_surface2
->render_surface()->clip_rect().ToString());
6571 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
6573 // NB: clip rects are in target space.
6574 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6575 render_surface1
->clip_rect().ToString());
6576 EXPECT_TRUE(render_surface1
->is_clipped());
6578 // This value is inherited from the clipping ancestor layer, 'intervening'.
6579 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6580 render_surface2
->clip_rect().ToString());
6581 EXPECT_TRUE(render_surface2
->is_clipped());
6583 // The content rects of both render surfaces should both have expanded to
6584 // contain the clip child.
6585 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6586 render_surface1
->render_surface()->content_rect().ToString());
6587 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6588 render_surface2
->render_surface()->content_rect().ToString());
6590 // The clip child should have inherited the clip parent's clip (projected to
6591 // the right space, of course), and should have the correctly sized visible
6593 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6594 clip_child
->clip_rect().ToString());
6595 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
6596 clip_child
->visible_content_rect().ToString());
6597 EXPECT_TRUE(clip_child
->is_clipped());
6600 TEST_F(LayerTreeHostCommonTest
, ClipParentScrolledInterveningLayer
) {
6601 // Ensure that intervening render surfaces are not a problem, even if there
6602 // is a scroll involved. Note, we do _not_ have to consider any other sort
6605 // root (a render surface)
6606 // + clip_parent (masks to bounds)
6607 // + render_surface1 (sets opacity)
6608 // + intervening (masks to bounds AND scrolls)
6609 // + render_surface2 (also sets opacity)
6612 scoped_refptr
<Layer
> root
= Layer::Create();
6613 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6614 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
6615 scoped_refptr
<Layer
> intervening
= Layer::Create();
6616 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
6617 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6618 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6620 root
->AddChild(clip_parent
);
6621 clip_parent
->AddChild(render_surface1
);
6622 render_surface1
->AddChild(intervening
);
6623 intervening
->AddChild(render_surface2
);
6624 render_surface2
->AddChild(clip_child
);
6626 clip_child
->SetClipParent(clip_parent
.get());
6628 intervening
->SetMasksToBounds(true);
6629 clip_parent
->SetMasksToBounds(true);
6630 intervening
->SetScrollClipLayerId(clip_parent
->id());
6631 intervening
->SetScrollOffset(gfx::Vector2d(3, 3));
6633 render_surface1
->SetForceRenderSurface(true);
6634 render_surface2
->SetForceRenderSurface(true);
6636 gfx::Transform translation_transform
;
6637 translation_transform
.Translate(2, 2);
6639 gfx::Transform identity_transform
;
6640 SetLayerPropertiesForTesting(root
.get(),
6647 SetLayerPropertiesForTesting(clip_parent
.get(),
6648 translation_transform
,
6650 gfx::PointF(1.f
, 1.f
),
6654 SetLayerPropertiesForTesting(render_surface1
.get(),
6661 SetLayerPropertiesForTesting(intervening
.get(),
6664 gfx::PointF(1.f
, 1.f
),
6668 SetLayerPropertiesForTesting(render_surface2
.get(),
6675 SetLayerPropertiesForTesting(clip_child
.get(),
6678 gfx::PointF(-10.f
, -10.f
),
6683 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6684 host
->SetRootLayer(root
);
6686 ExecuteCalculateDrawProperties(root
.get());
6688 EXPECT_TRUE(root
->render_surface());
6689 EXPECT_TRUE(render_surface1
->render_surface());
6690 EXPECT_TRUE(render_surface2
->render_surface());
6692 // Since the render surfaces could have expanded, they should not clip (their
6693 // bounds would no longer be reliable). We should resort to layer clipping
6695 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6696 render_surface1
->render_surface()->clip_rect().ToString());
6697 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6698 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6699 render_surface2
->render_surface()->clip_rect().ToString());
6700 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
6702 // NB: clip rects are in target space.
6703 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6704 render_surface1
->clip_rect().ToString());
6705 EXPECT_TRUE(render_surface1
->is_clipped());
6707 // This value is inherited from the clipping ancestor layer, 'intervening'.
6708 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
6709 render_surface2
->clip_rect().ToString());
6710 EXPECT_TRUE(render_surface2
->is_clipped());
6712 // The content rects of both render surfaces should both have expanded to
6713 // contain the clip child.
6714 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6715 render_surface1
->render_surface()->content_rect().ToString());
6716 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6717 render_surface2
->render_surface()->content_rect().ToString());
6719 // The clip child should have inherited the clip parent's clip (projected to
6720 // the right space, of course), and should have the correctly sized visible
6722 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6723 clip_child
->clip_rect().ToString());
6724 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
6725 clip_child
->visible_content_rect().ToString());
6726 EXPECT_TRUE(clip_child
->is_clipped());
6729 TEST_F(LayerTreeHostCommonTest
, DescendantsOfClipChildren
) {
6730 // Ensures that descendants of the clip child inherit the correct clip.
6732 // root (a render surface)
6733 // + clip_parent (masks to bounds)
6734 // + intervening (masks to bounds)
6738 scoped_refptr
<Layer
> root
= Layer::Create();
6739 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6740 scoped_refptr
<Layer
> intervening
= Layer::Create();
6741 scoped_refptr
<Layer
> clip_child
= Layer::Create();
6742 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
6743 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6745 root
->AddChild(clip_parent
);
6746 clip_parent
->AddChild(intervening
);
6747 intervening
->AddChild(clip_child
);
6748 clip_child
->AddChild(child
);
6750 clip_child
->SetClipParent(clip_parent
.get());
6752 intervening
->SetMasksToBounds(true);
6753 clip_parent
->SetMasksToBounds(true);
6755 gfx::Transform identity_transform
;
6756 SetLayerPropertiesForTesting(root
.get(),
6763 SetLayerPropertiesForTesting(clip_parent
.get(),
6770 SetLayerPropertiesForTesting(intervening
.get(),
6777 SetLayerPropertiesForTesting(clip_child
.get(),
6784 SetLayerPropertiesForTesting(child
.get(),
6792 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6793 host
->SetRootLayer(root
);
6795 ExecuteCalculateDrawProperties(root
.get());
6797 EXPECT_TRUE(root
->render_surface());
6799 // Neither the clip child nor its descendant should have inherited the clip
6800 // from |intervening|.
6801 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6802 clip_child
->clip_rect().ToString());
6803 EXPECT_TRUE(clip_child
->is_clipped());
6804 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6805 child
->visible_content_rect().ToString());
6806 EXPECT_TRUE(child
->is_clipped());
6809 TEST_F(LayerTreeHostCommonTest
,
6810 SurfacesShouldBeUnaffectedByNonDescendantClipChildren
) {
6811 // Ensures that non-descendant clip children in the tree do not affect
6814 // root (a render surface)
6815 // + clip_parent (masks to bounds)
6816 // + render_surface1
6818 // + render_surface2
6821 // In this example render_surface2 should be unaffected by clip_child.
6822 scoped_refptr
<Layer
> root
= Layer::Create();
6823 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6824 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
6825 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6826 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6827 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
6828 scoped_refptr
<LayerWithForcedDrawsContent
> non_clip_child
=
6829 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6831 root
->AddChild(clip_parent
);
6832 clip_parent
->AddChild(render_surface1
);
6833 render_surface1
->AddChild(clip_child
);
6834 clip_parent
->AddChild(render_surface2
);
6835 render_surface2
->AddChild(non_clip_child
);
6837 clip_child
->SetClipParent(clip_parent
.get());
6839 clip_parent
->SetMasksToBounds(true);
6840 render_surface1
->SetMasksToBounds(true);
6842 gfx::Transform identity_transform
;
6843 SetLayerPropertiesForTesting(root
.get(),
6850 SetLayerPropertiesForTesting(clip_parent
.get(),
6857 SetLayerPropertiesForTesting(render_surface1
.get(),
6864 SetLayerPropertiesForTesting(render_surface2
.get(),
6871 SetLayerPropertiesForTesting(clip_child
.get(),
6878 SetLayerPropertiesForTesting(non_clip_child
.get(),
6886 render_surface1
->SetForceRenderSurface(true);
6887 render_surface2
->SetForceRenderSurface(true);
6889 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
6890 host
->SetRootLayer(root
);
6892 ExecuteCalculateDrawProperties(root
.get());
6894 EXPECT_TRUE(root
->render_surface());
6895 EXPECT_TRUE(render_surface1
->render_surface());
6896 EXPECT_TRUE(render_surface2
->render_surface());
6898 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6899 render_surface1
->clip_rect().ToString());
6900 EXPECT_TRUE(render_surface1
->is_clipped());
6902 // The render surface should not clip (it has unclipped descendants), instead
6903 // it should rely on layer clipping.
6904 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6905 render_surface1
->render_surface()->clip_rect().ToString());
6906 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6908 // That said, it should have grown to accomodate the unclipped descendant.
6909 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
6910 render_surface1
->render_surface()->content_rect().ToString());
6912 // This render surface should clip. It has no unclipped descendants.
6913 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6914 render_surface2
->clip_rect().ToString());
6915 EXPECT_TRUE(render_surface2
->render_surface()->is_clipped());
6917 // It also shouldn't have grown to accomodate the clip child.
6918 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6919 render_surface2
->render_surface()->content_rect().ToString());
6921 // Sanity check our num_unclipped_descendants values.
6922 EXPECT_EQ(1, render_surface1
->num_unclipped_descendants());
6923 EXPECT_EQ(0, render_surface2
->num_unclipped_descendants());
6926 TEST_F(LayerTreeHostCommonTest
, CanRenderToSeparateSurface
) {
6927 FakeImplProxy proxy
;
6928 TestSharedBitmapManager shared_bitmap_manager
;
6929 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6930 scoped_ptr
<LayerImpl
> root
=
6931 LayerImpl::Create(host_impl
.active_tree(), 12345);
6932 scoped_ptr
<LayerImpl
> child1
=
6933 LayerImpl::Create(host_impl
.active_tree(), 123456);
6934 scoped_ptr
<LayerImpl
> child2
=
6935 LayerImpl::Create(host_impl
.active_tree(), 1234567);
6936 scoped_ptr
<LayerImpl
> child3
=
6937 LayerImpl::Create(host_impl
.active_tree(), 12345678);
6939 gfx::Transform identity_matrix
;
6940 gfx::Point3F transform_origin
;
6941 gfx::PointF position
;
6942 gfx::Size
bounds(100, 100);
6943 SetLayerPropertiesForTesting(root
.get(),
6950 root
->SetDrawsContent(true);
6952 // This layer structure normally forces render surface due to preserves3d
6954 SetLayerPropertiesForTesting(child1
.get(),
6961 child1
->SetDrawsContent(true);
6962 SetLayerPropertiesForTesting(child2
.get(),
6969 child2
->SetDrawsContent(true);
6970 SetLayerPropertiesForTesting(child3
.get(),
6977 child3
->SetDrawsContent(true);
6979 child2
->Set3dSortingContextId(1);
6980 child3
->Set3dSortingContextId(1);
6982 child2
->AddChild(child3
.Pass());
6983 child1
->AddChild(child2
.Pass());
6984 root
->AddChild(child1
.Pass());
6987 LayerImplList render_surface_layer_list
;
6988 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6989 root
.get(), root
->bounds(), &render_surface_layer_list
);
6990 inputs
.can_render_to_separate_surface
= true;
6991 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6993 EXPECT_EQ(2u, render_surface_layer_list
.size());
6997 LayerImplList render_surface_layer_list
;
6998 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6999 root
.get(), root
->bounds(), &render_surface_layer_list
);
7000 inputs
.can_render_to_separate_surface
= false;
7001 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7003 EXPECT_EQ(1u, render_surface_layer_list
.size());
7007 TEST_F(LayerTreeHostCommonTest
, DoNotIncludeBackfaceInvisibleSurfaces
) {
7008 scoped_refptr
<Layer
> root
= Layer::Create();
7009 scoped_refptr
<Layer
> render_surface
= Layer::Create();
7010 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7011 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7013 root
->AddChild(render_surface
);
7014 render_surface
->AddChild(child
);
7016 gfx::Transform identity_transform
;
7017 SetLayerPropertiesForTesting(root
.get(),
7024 SetLayerPropertiesForTesting(render_surface
.get(),
7031 SetLayerPropertiesForTesting(child
.get(),
7039 root
->SetShouldFlattenTransform(false);
7040 root
->Set3dSortingContextId(1);
7041 render_surface
->SetDoubleSided(false);
7042 render_surface
->SetForceRenderSurface(true);
7044 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
7045 host
->SetRootLayer(root
);
7047 ExecuteCalculateDrawProperties(root
.get());
7049 EXPECT_EQ(2u, render_surface_layer_list()->size());
7051 render_surface_layer_list()->at(0)
7052 ->render_surface()->layer_list().size());
7054 render_surface_layer_list()->at(1)
7055 ->render_surface()->layer_list().size());
7057 gfx::Transform rotation_transform
= identity_transform
;
7058 rotation_transform
.RotateAboutXAxis(180.0);
7060 render_surface
->SetTransform(rotation_transform
);
7062 ExecuteCalculateDrawProperties(root
.get());
7064 EXPECT_EQ(1u, render_surface_layer_list()->size());
7066 render_surface_layer_list()->at(0)
7067 ->render_surface()->layer_list().size());
7070 TEST_F(LayerTreeHostCommonTest
, ClippedByScrollParent
) {
7071 // Checks that the simple case (being clipped by a scroll parent that would
7072 // have been processed before you anyhow) results in the right clips.
7075 // + scroll_parent_border
7076 // | + scroll_parent_clip
7077 // | + scroll_parent
7080 scoped_refptr
<Layer
> root
= Layer::Create();
7081 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7082 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7083 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7084 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7085 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7086 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7088 root
->AddChild(scroll_child
);
7090 root
->AddChild(scroll_parent_border
);
7091 scroll_parent_border
->AddChild(scroll_parent_clip
);
7092 scroll_parent_clip
->AddChild(scroll_parent
);
7094 scroll_parent_clip
->SetMasksToBounds(true);
7096 scroll_child
->SetScrollParent(scroll_parent
.get());
7098 gfx::Transform identity_transform
;
7099 SetLayerPropertiesForTesting(root
.get(),
7106 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7113 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7120 SetLayerPropertiesForTesting(scroll_parent
.get(),
7127 SetLayerPropertiesForTesting(scroll_child
.get(),
7135 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
7136 host
->SetRootLayer(root
);
7138 ExecuteCalculateDrawProperties(root
.get());
7140 EXPECT_TRUE(root
->render_surface());
7142 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7143 scroll_child
->clip_rect().ToString());
7144 EXPECT_TRUE(scroll_child
->is_clipped());
7147 TEST_F(LayerTreeHostCommonTest
, SingularTransformSubtreesDoNotDraw
) {
7148 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
7149 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7150 scoped_refptr
<LayerWithForcedDrawsContent
> parent
=
7151 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7152 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7153 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7155 root
->AddChild(parent
);
7156 parent
->AddChild(child
);
7158 gfx::Transform identity_transform
;
7159 SetLayerPropertiesForTesting(root
.get(),
7166 root
->SetForceRenderSurface(true);
7167 SetLayerPropertiesForTesting(parent
.get(),
7174 parent
->SetForceRenderSurface(true);
7175 SetLayerPropertiesForTesting(child
.get(),
7182 child
->SetForceRenderSurface(true);
7184 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
7185 host
->SetRootLayer(root
);
7187 ExecuteCalculateDrawProperties(root
.get());
7189 EXPECT_EQ(3u, render_surface_layer_list()->size());
7191 gfx::Transform singular_transform
;
7192 singular_transform
.Scale3d(
7193 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
7195 child
->SetTransform(singular_transform
);
7197 ExecuteCalculateDrawProperties(root
.get());
7199 EXPECT_EQ(2u, render_surface_layer_list()->size());
7201 // Ensure that the entire subtree under a layer with singular transform does
7202 // not get rendered.
7203 parent
->SetTransform(singular_transform
);
7204 child
->SetTransform(identity_transform
);
7206 ExecuteCalculateDrawProperties(root
.get());
7208 EXPECT_EQ(1u, render_surface_layer_list()->size());
7211 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollParent
) {
7212 // Checks that clipping by a scroll parent that follows you in paint order
7213 // still results in correct clipping.
7217 // + scroll_parent_border
7218 // + scroll_parent_clip
7221 scoped_refptr
<Layer
> root
= Layer::Create();
7222 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7223 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7224 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7225 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7226 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7227 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7229 root
->AddChild(scroll_parent_border
);
7230 scroll_parent_border
->AddChild(scroll_parent_clip
);
7231 scroll_parent_clip
->AddChild(scroll_parent
);
7233 root
->AddChild(scroll_child
);
7235 scroll_parent_clip
->SetMasksToBounds(true);
7237 scroll_child
->SetScrollParent(scroll_parent
.get());
7239 gfx::Transform identity_transform
;
7240 SetLayerPropertiesForTesting(root
.get(),
7247 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7254 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7261 SetLayerPropertiesForTesting(scroll_parent
.get(),
7268 SetLayerPropertiesForTesting(scroll_child
.get(),
7276 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
7277 host
->SetRootLayer(root
);
7279 ExecuteCalculateDrawProperties(root
.get());
7281 EXPECT_TRUE(root
->render_surface());
7283 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7284 scroll_child
->clip_rect().ToString());
7285 EXPECT_TRUE(scroll_child
->is_clipped());
7288 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollGrandparent
) {
7289 // Checks that clipping by a scroll parent and scroll grandparent that follow
7290 // you in paint order still results in correct clipping.
7294 // + scroll_parent_border
7295 // | + scroll_parent_clip
7296 // | + scroll_parent
7297 // + scroll_grandparent_border
7298 // + scroll_grandparent_clip
7299 // + scroll_grandparent
7301 scoped_refptr
<Layer
> root
= Layer::Create();
7302 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7303 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7304 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7305 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7307 scoped_refptr
<Layer
> scroll_grandparent_border
= Layer::Create();
7308 scoped_refptr
<Layer
> scroll_grandparent_clip
= Layer::Create();
7309 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_grandparent
=
7310 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7312 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7313 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7315 root
->AddChild(scroll_child
);
7317 root
->AddChild(scroll_parent_border
);
7318 scroll_parent_border
->AddChild(scroll_parent_clip
);
7319 scroll_parent_clip
->AddChild(scroll_parent
);
7321 root
->AddChild(scroll_grandparent_border
);
7322 scroll_grandparent_border
->AddChild(scroll_grandparent_clip
);
7323 scroll_grandparent_clip
->AddChild(scroll_grandparent
);
7325 scroll_parent_clip
->SetMasksToBounds(true);
7326 scroll_grandparent_clip
->SetMasksToBounds(true);
7328 scroll_child
->SetScrollParent(scroll_parent
.get());
7329 scroll_parent_border
->SetScrollParent(scroll_grandparent
.get());
7331 gfx::Transform identity_transform
;
7332 SetLayerPropertiesForTesting(root
.get(),
7339 SetLayerPropertiesForTesting(scroll_grandparent_border
.get(),
7346 SetLayerPropertiesForTesting(scroll_grandparent_clip
.get(),
7353 SetLayerPropertiesForTesting(scroll_grandparent
.get(),
7360 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7367 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7374 SetLayerPropertiesForTesting(scroll_parent
.get(),
7381 SetLayerPropertiesForTesting(scroll_child
.get(),
7389 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
7390 host
->SetRootLayer(root
);
7392 ExecuteCalculateDrawProperties(root
.get());
7394 EXPECT_TRUE(root
->render_surface());
7396 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7397 scroll_child
->clip_rect().ToString());
7398 EXPECT_TRUE(scroll_child
->is_clipped());
7400 // Despite the fact that we visited the above layers out of order to get the
7401 // correct clip, the layer lists should be unaffected.
7402 EXPECT_EQ(3u, root
->render_surface()->layer_list().size());
7403 EXPECT_EQ(scroll_child
.get(),
7404 root
->render_surface()->layer_list().at(0));
7405 EXPECT_EQ(scroll_parent
.get(),
7406 root
->render_surface()->layer_list().at(1));
7407 EXPECT_EQ(scroll_grandparent
.get(),
7408 root
->render_surface()->layer_list().at(2));
7411 TEST_F(LayerTreeHostCommonTest
, OutOfOrderClippingRequiresRSLLSorting
) {
7412 // Ensures that even if we visit layers out of order, we still produce a
7413 // correctly ordered render surface layer list.
7416 // + scroll_parent_border
7417 // + scroll_parent_clip
7419 // + render_surface1
7420 // + scroll_grandparent_border
7421 // + scroll_grandparent_clip
7422 // + scroll_grandparent
7423 // + render_surface2
7425 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
7426 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7428 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7429 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7430 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7431 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7432 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface1
=
7433 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7435 scoped_refptr
<Layer
> scroll_grandparent_border
= Layer::Create();
7436 scoped_refptr
<Layer
> scroll_grandparent_clip
= Layer::Create();
7437 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_grandparent
=
7438 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7439 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface2
=
7440 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7442 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7443 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7445 root
->AddChild(scroll_child
);
7447 root
->AddChild(scroll_parent_border
);
7448 scroll_parent_border
->AddChild(scroll_parent_clip
);
7449 scroll_parent_clip
->AddChild(scroll_parent
);
7450 scroll_parent
->AddChild(render_surface2
);
7452 root
->AddChild(scroll_grandparent_border
);
7453 scroll_grandparent_border
->AddChild(scroll_grandparent_clip
);
7454 scroll_grandparent_clip
->AddChild(scroll_grandparent
);
7455 scroll_grandparent
->AddChild(render_surface1
);
7457 scroll_parent_clip
->SetMasksToBounds(true);
7458 scroll_grandparent_clip
->SetMasksToBounds(true);
7460 scroll_child
->SetScrollParent(scroll_parent
.get());
7461 scroll_parent_border
->SetScrollParent(scroll_grandparent
.get());
7463 render_surface1
->SetForceRenderSurface(true);
7464 render_surface2
->SetForceRenderSurface(true);
7466 gfx::Transform identity_transform
;
7467 SetLayerPropertiesForTesting(root
.get(),
7474 SetLayerPropertiesForTesting(scroll_grandparent_border
.get(),
7481 SetLayerPropertiesForTesting(scroll_grandparent_clip
.get(),
7488 SetLayerPropertiesForTesting(scroll_grandparent
.get(),
7495 SetLayerPropertiesForTesting(render_surface1
.get(),
7502 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7509 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7516 SetLayerPropertiesForTesting(scroll_parent
.get(),
7523 SetLayerPropertiesForTesting(render_surface2
.get(),
7530 SetLayerPropertiesForTesting(scroll_child
.get(),
7538 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
7539 host
->SetRootLayer(root
);
7541 RenderSurfaceLayerList render_surface_layer_list
;
7542 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
7546 &render_surface_layer_list
);
7548 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7550 EXPECT_TRUE(root
->render_surface());
7552 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7553 scroll_child
->clip_rect().ToString());
7554 EXPECT_TRUE(scroll_child
->is_clipped());
7556 // Despite the fact that we had to process the layers out of order to get the
7557 // right clip, our render_surface_layer_list's order should be unaffected.
7558 EXPECT_EQ(3u, render_surface_layer_list
.size());
7559 EXPECT_EQ(root
.get(), render_surface_layer_list
.at(0));
7560 EXPECT_EQ(render_surface2
.get(), render_surface_layer_list
.at(1));
7561 EXPECT_EQ(render_surface1
.get(), render_surface_layer_list
.at(2));
7562 EXPECT_TRUE(render_surface_layer_list
.at(0)->render_surface());
7563 EXPECT_TRUE(render_surface_layer_list
.at(1)->render_surface());
7564 EXPECT_TRUE(render_surface_layer_list
.at(2)->render_surface());
7567 TEST_F(LayerTreeHostCommonTest
, DoNotClobberSorting
) {
7568 // We rearrange layer list contributions if we have to visit children out of
7569 // order, but it should be a 'stable' rearrangement. That is, the layer list
7570 // additions for a single layer should not be reordered, though their position
7571 // wrt to the contributions due to a sibling may vary.
7577 // + scroll_parent_border
7578 // + scroll_parent_clip
7581 FakeImplProxy proxy
;
7582 TestSharedBitmapManager shared_bitmap_manager
;
7583 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7584 host_impl
.CreatePendingTree();
7585 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7586 scoped_ptr
<LayerImpl
> scroll_parent_border
=
7587 LayerImpl::Create(host_impl
.active_tree(), 2);
7588 scoped_ptr
<LayerImpl
> scroll_parent_clip
=
7589 LayerImpl::Create(host_impl
.active_tree(), 3);
7590 scoped_ptr
<LayerImpl
> scroll_parent
=
7591 LayerImpl::Create(host_impl
.active_tree(), 4);
7592 scoped_ptr
<LayerImpl
> scroll_child
=
7593 LayerImpl::Create(host_impl
.active_tree(), 5);
7594 scoped_ptr
<LayerImpl
> bottom_content
=
7595 LayerImpl::Create(host_impl
.active_tree(), 6);
7596 scoped_ptr
<LayerImpl
> top_content
=
7597 LayerImpl::Create(host_impl
.active_tree(), 7);
7599 scroll_parent_clip
->SetMasksToBounds(true);
7601 scroll_child
->SetScrollParent(scroll_parent
.get());
7602 scoped_ptr
<std::set
<LayerImpl
*> > scroll_children(new std::set
<LayerImpl
*>);
7603 scroll_children
->insert(scroll_child
.get());
7604 scroll_parent
->SetScrollChildren(scroll_children
.release());
7606 scroll_child
->SetDrawsContent(true);
7607 scroll_parent
->SetDrawsContent(true);
7608 top_content
->SetDrawsContent(true);
7609 bottom_content
->SetDrawsContent(true);
7611 gfx::Transform identity_transform
;
7612 gfx::Transform top_transform
;
7613 top_transform
.Translate3d(0.0, 0.0, 5.0);
7614 gfx::Transform bottom_transform
;
7615 bottom_transform
.Translate3d(0.0, 0.0, 3.0);
7617 SetLayerPropertiesForTesting(root
.get(),
7624 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7631 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7638 SetLayerPropertiesForTesting(scroll_parent
.get(),
7645 SetLayerPropertiesForTesting(scroll_child
.get(),
7652 SetLayerPropertiesForTesting(top_content
.get(),
7659 SetLayerPropertiesForTesting(bottom_content
.get(),
7667 scroll_child
->SetShouldFlattenTransform(false);
7668 scroll_child
->Set3dSortingContextId(1);
7670 scroll_child
->AddChild(top_content
.Pass());
7671 scroll_child
->AddChild(bottom_content
.Pass());
7672 root
->AddChild(scroll_child
.Pass());
7674 scroll_parent_clip
->AddChild(scroll_parent
.Pass());
7675 scroll_parent_border
->AddChild(scroll_parent_clip
.Pass());
7676 root
->AddChild(scroll_parent_border
.Pass());
7678 LayerImplList render_surface_layer_list
;
7679 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7680 root
.get(), root
->bounds(), &render_surface_layer_list
);
7682 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7684 EXPECT_TRUE(root
->render_surface());
7686 // If we don't sort by depth and let the layers get added in the order they
7687 // would normally be visited in, then layers 6 and 7 will be out of order. In
7688 // other words, although we've had to shift 5, 6, and 7 to appear before 4
7689 // in the list (because of the scroll parent relationship), this should not
7690 // have an effect on the the order of 5, 6, and 7 (which had been reordered
7691 // due to layer sorting).
7692 EXPECT_EQ(4u, root
->render_surface()->layer_list().size());
7693 EXPECT_EQ(5, root
->render_surface()->layer_list().at(0)->id());
7694 EXPECT_EQ(6, root
->render_surface()->layer_list().at(1)->id());
7695 EXPECT_EQ(7, root
->render_surface()->layer_list().at(2)->id());
7696 EXPECT_EQ(4, root
->render_surface()->layer_list().at(3)->id());
7699 TEST_F(LayerTreeHostCommonTest
, ScrollCompensationWithRounding
) {
7700 // This test verifies that a scrolling layer that gets snapped to
7701 // integer coordinates doesn't move a fixed position child.
7708 FakeImplProxy proxy
;
7709 TestSharedBitmapManager shared_bitmap_manager
;
7710 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7711 host_impl
.CreatePendingTree();
7712 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7713 scoped_ptr
<LayerImpl
> container
=
7714 LayerImpl::Create(host_impl
.active_tree(), 2);
7715 LayerImpl
* container_layer
= container
.get();
7716 scoped_ptr
<LayerImpl
> scroller
=
7717 LayerImpl::Create(host_impl
.active_tree(), 3);
7718 LayerImpl
* scroll_layer
= scroller
.get();
7719 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
7720 LayerImpl
* fixed_layer
= fixed
.get();
7722 container
->SetIsContainerForFixedPositionLayers(true);
7724 LayerPositionConstraint constraint
;
7725 constraint
.set_is_fixed_position(true);
7726 fixed
->SetPositionConstraint(constraint
);
7728 scroller
->SetScrollClipLayer(container
->id());
7730 gfx::Transform identity_transform
;
7731 gfx::Transform container_transform
;
7732 container_transform
.Translate3d(10.0, 20.0, 0.0);
7733 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
7735 SetLayerPropertiesForTesting(root
.get(),
7742 SetLayerPropertiesForTesting(container
.get(),
7743 container_transform
,
7749 SetLayerPropertiesForTesting(scroller
.get(),
7756 SetLayerPropertiesForTesting(fixed
.get(),
7764 scroller
->AddChild(fixed
.Pass());
7765 container
->AddChild(scroller
.Pass());
7766 root
->AddChild(container
.Pass());
7768 // Rounded to integers already.
7770 gfx::Vector2dF
scroll_delta(3.0, 5.0);
7771 scroll_layer
->SetScrollDelta(scroll_delta
);
7773 LayerImplList render_surface_layer_list
;
7774 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7775 root
.get(), root
->bounds(), &render_surface_layer_list
);
7776 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7778 EXPECT_TRANSFORMATION_MATRIX_EQ(
7779 container_layer
->draw_properties().screen_space_transform
,
7780 fixed_layer
->draw_properties().screen_space_transform
);
7782 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7784 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
7785 .screen_space_transform
.To2dTranslation(),
7786 container_offset
- scroll_delta
);
7789 // Scroll delta requiring rounding.
7791 gfx::Vector2dF
scroll_delta(4.1f
, 8.1f
);
7792 scroll_layer
->SetScrollDelta(scroll_delta
);
7794 gfx::Vector2dF
rounded_scroll_delta(4.f
, 8.f
);
7796 LayerImplList render_surface_layer_list
;
7797 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7798 root
.get(), root
->bounds(), &render_surface_layer_list
);
7799 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7801 EXPECT_TRANSFORMATION_MATRIX_EQ(
7802 container_layer
->draw_properties().screen_space_transform
,
7803 fixed_layer
->draw_properties().screen_space_transform
);
7805 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7807 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
7808 .screen_space_transform
.To2dTranslation(),
7809 container_offset
- rounded_scroll_delta
);
7812 // Scale is applied earlier in the tree.
7814 gfx::Transform scaled_container_transform
= container_transform
;
7815 scaled_container_transform
.Scale3d(3.0, 3.0, 1.0);
7816 container_layer
->SetTransform(scaled_container_transform
);
7818 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
7819 scroll_layer
->SetScrollDelta(scroll_delta
);
7821 LayerImplList render_surface_layer_list
;
7822 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7823 root
.get(), root
->bounds(), &render_surface_layer_list
);
7824 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7826 EXPECT_TRANSFORMATION_MATRIX_EQ(
7827 container_layer
->draw_properties().screen_space_transform
,
7828 fixed_layer
->draw_properties().screen_space_transform
);
7830 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7833 container_layer
->SetTransform(container_transform
);
7836 // Scale is applied on the scroll layer itself.
7838 gfx::Transform scale_transform
;
7839 scale_transform
.Scale3d(3.0, 3.0, 1.0);
7840 scroll_layer
->SetTransform(scale_transform
);
7842 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
7843 scroll_layer
->SetScrollDelta(scroll_delta
);
7845 LayerImplList render_surface_layer_list
;
7846 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7847 root
.get(), root
->bounds(), &render_surface_layer_list
);
7848 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7851 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7854 scroll_layer
->SetTransform(identity_transform
);
7858 class AnimationScaleFactorTrackingLayerImpl
: public LayerImpl
{
7860 static scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> Create(
7861 LayerTreeImpl
* tree_impl
,
7863 return make_scoped_ptr(
7864 new AnimationScaleFactorTrackingLayerImpl(tree_impl
, id
));
7867 virtual ~AnimationScaleFactorTrackingLayerImpl() {}
7870 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl
* tree_impl
,
7872 : LayerImpl(tree_impl
, id
) {
7873 SetDrawsContent(true);
7877 TEST_F(LayerTreeHostCommonTest
, MaximumAnimationScaleFactor
) {
7878 FakeImplProxy proxy
;
7879 TestSharedBitmapManager shared_bitmap_manager
;
7880 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7881 gfx::Transform identity_matrix
;
7882 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_parent
=
7883 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 1);
7884 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> parent
=
7885 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 2);
7886 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> child
=
7887 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 3);
7888 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_child
=
7889 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 4);
7891 AnimationScaleFactorTrackingLayerImpl
* parent_raw
= parent
.get();
7892 AnimationScaleFactorTrackingLayerImpl
* child_raw
= child
.get();
7893 AnimationScaleFactorTrackingLayerImpl
* grand_child_raw
= grand_child
.get();
7895 child
->AddChild(grand_child
.PassAs
<LayerImpl
>());
7896 parent
->AddChild(child
.PassAs
<LayerImpl
>());
7897 grand_parent
->AddChild(parent
.PassAs
<LayerImpl
>());
7899 SetLayerPropertiesForTesting(grand_parent
.get(),
7906 SetLayerPropertiesForTesting(parent_raw
,
7913 SetLayerPropertiesForTesting(child_raw
,
7920 SetLayerPropertiesForTesting(grand_child_raw
,
7928 ExecuteCalculateDrawProperties(grand_parent
.get());
7930 // No layers have animations.
7932 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7934 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7935 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7937 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7939 TransformOperations translation
;
7940 translation
.AppendTranslate(1.f
, 2.f
, 3.f
);
7942 AddAnimatedTransformToLayer(
7943 parent_raw
, 1.0, TransformOperations(), translation
);
7945 // No layers have scale-affecting animations.
7947 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7949 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7950 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7952 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7954 TransformOperations scale
;
7955 scale
.AppendScale(5.f
, 4.f
, 3.f
);
7957 AddAnimatedTransformToLayer(child_raw
, 1.0, TransformOperations(), scale
);
7958 ExecuteCalculateDrawProperties(grand_parent
.get());
7960 // Only |child| has a scale-affecting animation.
7962 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7964 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7965 EXPECT_EQ(5.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7967 5.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7969 AddAnimatedTransformToLayer(
7970 grand_parent
.get(), 1.0, TransformOperations(), scale
);
7971 ExecuteCalculateDrawProperties(grand_parent
.get());
7973 // |grand_parent| and |child| have scale-affecting animations.
7975 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7977 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7978 // We don't support combining animated scales from two nodes; 0.f means
7979 // that the maximum scale could not be computed.
7980 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7982 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7984 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
7985 ExecuteCalculateDrawProperties(grand_parent
.get());
7987 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
7989 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7991 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7992 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7994 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7996 grand_parent
->layer_animation_controller()->AbortAnimations(
7997 Animation::Transform
);
7998 parent_raw
->layer_animation_controller()->AbortAnimations(
7999 Animation::Transform
);
8000 child_raw
->layer_animation_controller()->AbortAnimations(
8001 Animation::Transform
);
8003 TransformOperations perspective
;
8004 perspective
.AppendPerspective(10.f
);
8006 AddAnimatedTransformToLayer(
8007 child_raw
, 1.0, TransformOperations(), perspective
);
8008 ExecuteCalculateDrawProperties(grand_parent
.get());
8010 // |child| has a scale-affecting animation but computing the maximum of this
8011 // animation is not supported.
8013 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8015 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8016 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8018 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8020 child_raw
->layer_animation_controller()->AbortAnimations(
8021 Animation::Transform
);
8023 gfx::Transform scale_matrix
;
8024 scale_matrix
.Scale(1.f
, 2.f
);
8025 grand_parent
->SetTransform(scale_matrix
);
8026 parent_raw
->SetTransform(scale_matrix
);
8027 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
8028 ExecuteCalculateDrawProperties(grand_parent
.get());
8030 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
8031 // animation with maximum scale 5.f.
8033 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8035 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8037 child_raw
->draw_properties().maximum_animation_contents_scale
);
8040 grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8042 gfx::Transform perspective_matrix
;
8043 perspective_matrix
.ApplyPerspectiveDepth(2.f
);
8044 child_raw
->SetTransform(perspective_matrix
);
8045 ExecuteCalculateDrawProperties(grand_parent
.get());
8047 // |child| has a transform that's neither a translation nor a scale.
8049 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8051 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8052 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8054 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8056 parent_raw
->SetTransform(perspective_matrix
);
8057 ExecuteCalculateDrawProperties(grand_parent
.get());
8059 // |parent| and |child| have transforms that are neither translations nor
8062 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8064 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8065 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8067 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8069 parent_raw
->SetTransform(identity_matrix
);
8070 child_raw
->SetTransform(identity_matrix
);
8071 grand_parent
->SetTransform(perspective_matrix
);
8073 ExecuteCalculateDrawProperties(grand_parent
.get());
8075 // |grand_parent| has a transform that's neither a translation nor a scale.
8077 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8079 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8080 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8082 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8085 static int membership_id(LayerImpl
* layer
) {
8086 return layer
->draw_properties().last_drawn_render_surface_layer_list_id
;
8089 static void GatherDrawnLayers(LayerImplList
* rsll
,
8090 std::set
<LayerImpl
*>* drawn_layers
) {
8091 for (LayerIterator
<LayerImpl
> it
= LayerIterator
<LayerImpl
>::Begin(rsll
),
8092 end
= LayerIterator
<LayerImpl
>::End(rsll
);
8095 LayerImpl
* layer
= *it
;
8096 if (it
.represents_itself())
8097 drawn_layers
->insert(layer
);
8099 if (!it
.represents_contributing_render_surface())
8102 if (layer
->mask_layer())
8103 drawn_layers
->insert(layer
->mask_layer());
8104 if (layer
->replica_layer() && layer
->replica_layer()->mask_layer())
8105 drawn_layers
->insert(layer
->replica_layer()->mask_layer());
8109 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceLayerListMembership
) {
8110 FakeImplProxy proxy
;
8111 TestSharedBitmapManager shared_bitmap_manager
;
8112 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
8113 gfx::Transform identity_matrix
;
8115 scoped_ptr
<LayerImpl
> grand_parent
=
8116 LayerImpl::Create(host_impl
.active_tree(), 1);
8117 scoped_ptr
<LayerImpl
> parent
= LayerImpl::Create(host_impl
.active_tree(), 3);
8118 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 5);
8119 scoped_ptr
<LayerImpl
> grand_child1
=
8120 LayerImpl::Create(host_impl
.active_tree(), 7);
8121 scoped_ptr
<LayerImpl
> grand_child2
=
8122 LayerImpl::Create(host_impl
.active_tree(), 9);
8124 LayerImpl
* grand_parent_raw
= grand_parent
.get();
8125 LayerImpl
* parent_raw
= parent
.get();
8126 LayerImpl
* child_raw
= child
.get();
8127 LayerImpl
* grand_child1_raw
= grand_child1
.get();
8128 LayerImpl
* grand_child2_raw
= grand_child2
.get();
8130 child
->AddChild(grand_child1
.Pass());
8131 child
->AddChild(grand_child2
.Pass());
8132 parent
->AddChild(child
.Pass());
8133 grand_parent
->AddChild(parent
.Pass());
8135 SetLayerPropertiesForTesting(grand_parent_raw
,
8142 SetLayerPropertiesForTesting(parent_raw
,
8149 SetLayerPropertiesForTesting(child_raw
,
8156 SetLayerPropertiesForTesting(grand_child1_raw
,
8163 SetLayerPropertiesForTesting(grand_child2_raw
,
8171 // Start with nothing being drawn.
8172 ExecuteCalculateDrawProperties(grand_parent_raw
);
8173 int member_id
= render_surface_layer_list_count();
8175 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8176 EXPECT_NE(member_id
, membership_id(parent_raw
));
8177 EXPECT_NE(member_id
, membership_id(child_raw
));
8178 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8179 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8181 std::set
<LayerImpl
*> expected
;
8182 std::set
<LayerImpl
*> actual
;
8183 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8184 EXPECT_EQ(expected
, actual
);
8186 // If we force render surface, but none of the layers are in the layer list,
8187 // then this layer should not appear in RSLL.
8188 grand_child1_raw
->SetForceRenderSurface(true);
8190 ExecuteCalculateDrawProperties(grand_parent_raw
);
8191 member_id
= render_surface_layer_list_count();
8193 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8194 EXPECT_NE(member_id
, membership_id(parent_raw
));
8195 EXPECT_NE(member_id
, membership_id(child_raw
));
8196 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8197 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8201 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8202 EXPECT_EQ(expected
, actual
);
8204 // However, if we say that this layer also draws content, it will appear in
8206 grand_child1_raw
->SetDrawsContent(true);
8208 ExecuteCalculateDrawProperties(grand_parent_raw
);
8209 member_id
= render_surface_layer_list_count();
8211 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8212 EXPECT_NE(member_id
, membership_id(parent_raw
));
8213 EXPECT_NE(member_id
, membership_id(child_raw
));
8214 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
8215 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8218 expected
.insert(grand_child1_raw
);
8221 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8222 EXPECT_EQ(expected
, actual
);
8224 // Now child is forced to have a render surface, and one if its children draws
8226 grand_child1_raw
->SetDrawsContent(false);
8227 grand_child1_raw
->SetForceRenderSurface(false);
8228 child_raw
->SetForceRenderSurface(true);
8229 grand_child2_raw
->SetDrawsContent(true);
8231 ExecuteCalculateDrawProperties(grand_parent_raw
);
8232 member_id
= render_surface_layer_list_count();
8234 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8235 EXPECT_NE(member_id
, membership_id(parent_raw
));
8236 EXPECT_NE(member_id
, membership_id(child_raw
));
8237 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8238 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8241 expected
.insert(grand_child2_raw
);
8244 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8245 EXPECT_EQ(expected
, actual
);
8247 // Add a mask layer to child.
8248 child_raw
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6).Pass());
8250 ExecuteCalculateDrawProperties(grand_parent_raw
);
8251 member_id
= render_surface_layer_list_count();
8253 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8254 EXPECT_NE(member_id
, membership_id(parent_raw
));
8255 EXPECT_NE(member_id
, membership_id(child_raw
));
8256 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8257 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8258 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8261 expected
.insert(grand_child2_raw
);
8262 expected
.insert(child_raw
->mask_layer());
8265 expected
.insert(grand_child2_raw
);
8266 expected
.insert(child_raw
->mask_layer());
8269 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8270 EXPECT_EQ(expected
, actual
);
8272 // Add replica mask layer.
8273 scoped_ptr
<LayerImpl
> replica_layer
=
8274 LayerImpl::Create(host_impl
.active_tree(), 20);
8275 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 21));
8276 child_raw
->SetReplicaLayer(replica_layer
.Pass());
8278 ExecuteCalculateDrawProperties(grand_parent_raw
);
8279 member_id
= render_surface_layer_list_count();
8281 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8282 EXPECT_NE(member_id
, membership_id(parent_raw
));
8283 EXPECT_NE(member_id
, membership_id(child_raw
));
8284 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8285 EXPECT_EQ(member_id
, membership_id(child_raw
->replica_layer()->mask_layer()));
8286 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8287 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8290 expected
.insert(grand_child2_raw
);
8291 expected
.insert(child_raw
->mask_layer());
8292 expected
.insert(child_raw
->replica_layer()->mask_layer());
8295 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8296 EXPECT_EQ(expected
, actual
);
8298 child_raw
->TakeReplicaLayer();
8300 // With nothing drawing, we should have no layers.
8301 grand_child2_raw
->SetDrawsContent(false);
8303 ExecuteCalculateDrawProperties(grand_parent_raw
);
8304 member_id
= render_surface_layer_list_count();
8306 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8307 EXPECT_NE(member_id
, membership_id(parent_raw
));
8308 EXPECT_NE(member_id
, membership_id(child_raw
));
8309 EXPECT_NE(member_id
, membership_id(child_raw
->mask_layer()));
8310 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8311 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8315 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8316 EXPECT_EQ(expected
, actual
);
8318 // Child itself draws means that we should have the child and the mask in the
8320 child_raw
->SetDrawsContent(true);
8322 ExecuteCalculateDrawProperties(grand_parent_raw
);
8323 member_id
= render_surface_layer_list_count();
8325 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8326 EXPECT_NE(member_id
, membership_id(parent_raw
));
8327 EXPECT_EQ(member_id
, membership_id(child_raw
));
8328 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8329 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8330 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8333 expected
.insert(child_raw
);
8334 expected
.insert(child_raw
->mask_layer());
8336 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8337 EXPECT_EQ(expected
, actual
);
8339 child_raw
->TakeMaskLayer();
8341 // Now everyone's a member!
8342 grand_parent_raw
->SetDrawsContent(true);
8343 parent_raw
->SetDrawsContent(true);
8344 child_raw
->SetDrawsContent(true);
8345 grand_child1_raw
->SetDrawsContent(true);
8346 grand_child2_raw
->SetDrawsContent(true);
8348 ExecuteCalculateDrawProperties(grand_parent_raw
);
8349 member_id
= render_surface_layer_list_count();
8351 EXPECT_EQ(member_id
, membership_id(grand_parent_raw
));
8352 EXPECT_EQ(member_id
, membership_id(parent_raw
));
8353 EXPECT_EQ(member_id
, membership_id(child_raw
));
8354 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
8355 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8358 expected
.insert(grand_parent_raw
);
8359 expected
.insert(parent_raw
);
8360 expected
.insert(child_raw
);
8361 expected
.insert(grand_child1_raw
);
8362 expected
.insert(grand_child2_raw
);
8365 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8366 EXPECT_EQ(expected
, actual
);
8369 TEST_F(LayerTreeHostCommonTest
, DrawPropertyScales
) {
8370 FakeImplProxy proxy
;
8371 TestSharedBitmapManager shared_bitmap_manager
;
8372 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
8374 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
8375 LayerImpl
* root_layer
= root
.get();
8376 scoped_ptr
<LayerImpl
> child1
= LayerImpl::Create(host_impl
.active_tree(), 2);
8377 LayerImpl
* child1_layer
= child1
.get();
8378 scoped_ptr
<LayerImpl
> child2
= LayerImpl::Create(host_impl
.active_tree(), 3);
8379 LayerImpl
* child2_layer
= child2
.get();
8381 root
->AddChild(child1
.Pass());
8382 root
->AddChild(child2
.Pass());
8384 gfx::Transform identity_matrix
, scale_transform_child1
,
8385 scale_transform_child2
;
8386 scale_transform_child1
.Scale(2, 3);
8387 scale_transform_child2
.Scale(4, 5);
8389 SetLayerPropertiesForTesting(root_layer
,
8396 SetLayerPropertiesForTesting(child1_layer
,
8397 scale_transform_child1
,
8404 child1_layer
->SetMaskLayer(
8405 LayerImpl::Create(host_impl
.active_tree(), 4).Pass());
8407 scoped_ptr
<LayerImpl
> replica_layer
=
8408 LayerImpl::Create(host_impl
.active_tree(), 5);
8409 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6));
8410 child1_layer
->SetReplicaLayer(replica_layer
.Pass());
8412 ExecuteCalculateDrawProperties(root_layer
);
8414 TransformOperations scale
;
8415 scale
.AppendScale(5.f
, 8.f
, 3.f
);
8417 AddAnimatedTransformToLayer(child2_layer
, 1.0, TransformOperations(), scale
);
8418 SetLayerPropertiesForTesting(child2_layer
,
8419 scale_transform_child2
,
8426 ExecuteCalculateDrawProperties(root_layer
);
8428 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().ideal_contents_scale
);
8429 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8431 3.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8432 EXPECT_FLOAT_EQ(3.f
,
8433 child1_layer
->replica_layer()
8436 .ideal_contents_scale
);
8437 EXPECT_FLOAT_EQ(5.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8440 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8442 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8443 EXPECT_FLOAT_EQ(0.f
,
8444 child1_layer
->mask_layer()
8446 .maximum_animation_contents_scale
);
8447 EXPECT_FLOAT_EQ(0.f
,
8448 child1_layer
->replica_layer()
8451 .maximum_animation_contents_scale
);
8453 8.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8455 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8456 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().page_scale_factor
);
8458 1.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8459 EXPECT_FLOAT_EQ(1.f
,
8460 child1_layer
->replica_layer()
8463 .page_scale_factor
);
8464 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().page_scale_factor
);
8466 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().device_scale_factor
);
8467 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().device_scale_factor
);
8469 1.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8470 EXPECT_FLOAT_EQ(1.f
,
8471 child1_layer
->replica_layer()
8474 .device_scale_factor
);
8475 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().device_scale_factor
);
8477 // Changing page-scale would affect ideal_contents_scale and
8478 // maximum_animation_contents_scale.
8480 float page_scale_factor
= 3.f
;
8481 float device_scale_factor
= 1.0f
;
8482 std::vector
<LayerImpl
*> render_surface_layer_list
;
8483 gfx::Size device_viewport_size
=
8484 gfx::Size(root_layer
->bounds().width() * device_scale_factor
,
8485 root_layer
->bounds().height() * device_scale_factor
);
8486 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
8487 root_layer
, device_viewport_size
, &render_surface_layer_list
);
8489 inputs
.page_scale_factor
= page_scale_factor
;
8490 inputs
.can_adjust_raster_scales
= true;
8491 inputs
.page_scale_application_layer
= root_layer
;
8492 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8494 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().ideal_contents_scale
);
8495 EXPECT_FLOAT_EQ(9.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8497 9.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8498 EXPECT_FLOAT_EQ(9.f
,
8499 child1_layer
->replica_layer()
8502 .ideal_contents_scale
);
8503 EXPECT_FLOAT_EQ(15.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8506 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8508 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8509 EXPECT_FLOAT_EQ(0.f
,
8510 child1_layer
->mask_layer()
8512 .maximum_animation_contents_scale
);
8513 EXPECT_FLOAT_EQ(0.f
,
8514 child1_layer
->replica_layer()
8517 .maximum_animation_contents_scale
);
8519 24.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8521 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8522 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().page_scale_factor
);
8524 3.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8525 EXPECT_FLOAT_EQ(3.f
,
8526 child1_layer
->replica_layer()
8529 .page_scale_factor
);
8530 EXPECT_FLOAT_EQ(3.f
, child2_layer
->draw_properties().page_scale_factor
);
8532 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().device_scale_factor
);
8533 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().device_scale_factor
);
8535 1.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8536 EXPECT_FLOAT_EQ(1.f
,
8537 child1_layer
->replica_layer()
8540 .device_scale_factor
);
8541 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().device_scale_factor
);
8543 // Changing device-scale would affect ideal_contents_scale and
8544 // maximum_animation_contents_scale.
8546 device_scale_factor
= 4.0f
;
8547 inputs
.device_scale_factor
= device_scale_factor
;
8548 inputs
.can_adjust_raster_scales
= true;
8549 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8551 EXPECT_FLOAT_EQ(4.f
, root_layer
->draw_properties().ideal_contents_scale
);
8552 EXPECT_FLOAT_EQ(36.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8554 36.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8555 EXPECT_FLOAT_EQ(36.f
,
8556 child1_layer
->replica_layer()
8559 .ideal_contents_scale
);
8560 EXPECT_FLOAT_EQ(60.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8563 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8565 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8566 EXPECT_FLOAT_EQ(0.f
,
8567 child1_layer
->mask_layer()
8569 .maximum_animation_contents_scale
);
8570 EXPECT_FLOAT_EQ(0.f
,
8571 child1_layer
->replica_layer()
8574 .maximum_animation_contents_scale
);
8576 96.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8578 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8579 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().page_scale_factor
);
8581 3.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8582 EXPECT_FLOAT_EQ(3.f
,
8583 child1_layer
->replica_layer()
8586 .page_scale_factor
);
8587 EXPECT_FLOAT_EQ(3.f
, child2_layer
->draw_properties().page_scale_factor
);
8589 EXPECT_FLOAT_EQ(4.f
, root_layer
->draw_properties().device_scale_factor
);
8590 EXPECT_FLOAT_EQ(4.f
, child1_layer
->draw_properties().device_scale_factor
);
8592 4.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8593 EXPECT_FLOAT_EQ(4.f
,
8594 child1_layer
->replica_layer()
8597 .device_scale_factor
);
8598 EXPECT_FLOAT_EQ(4.f
, child2_layer
->draw_properties().device_scale_factor
);