1 //// Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/trees/layer_tree_host_common.h"
10 #include "cc/animation/keyframed_animation_curve.h"
11 #include "cc/animation/layer_animation_controller.h"
12 #include "cc/animation/transform_operations.h"
13 #include "cc/base/math_util.h"
14 #include "cc/layers/content_layer_client.h"
15 #include "cc/layers/layer.h"
16 #include "cc/layers/layer_client.h"
17 #include "cc/layers/layer_impl.h"
18 #include "cc/layers/layer_iterator.h"
19 #include "cc/layers/render_surface_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_content_layer_client.h"
24 #include "cc/test/fake_impl_proxy.h"
25 #include "cc/test/fake_layer_tree_host.h"
26 #include "cc/test/fake_layer_tree_host_impl.h"
27 #include "cc/test/fake_output_surface.h"
28 #include "cc/test/fake_picture_layer.h"
29 #include "cc/test/fake_picture_layer_impl.h"
30 #include "cc/test/geometry_test_utils.h"
31 #include "cc/test/layer_tree_host_common_test.h"
32 #include "cc/test/test_task_graph_runner.h"
33 #include "cc/trees/draw_property_utils.h"
34 #include "cc/trees/layer_tree_impl.h"
35 #include "cc/trees/proxy.h"
36 #include "cc/trees/single_thread_proxy.h"
37 #include "testing/gmock/include/gmock/gmock.h"
38 #include "testing/gtest/include/gtest/gtest.h"
39 #include "ui/gfx/geometry/quad_f.h"
40 #include "ui/gfx/geometry/vector2d_conversions.h"
41 #include "ui/gfx/transform.h"
46 class LayerWithForcedDrawsContent
: public Layer
{
48 explicit LayerWithForcedDrawsContent(const LayerSettings
& settings
)
51 bool DrawsContent() const override
;
54 ~LayerWithForcedDrawsContent() override
{}
57 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
59 class MockContentLayerClient
: public ContentLayerClient
{
61 MockContentLayerClient() {}
62 ~MockContentLayerClient() override
{}
63 void PaintContents(SkCanvas
* canvas
,
64 const gfx::Rect
& clip
,
65 PaintingControlSetting picture_control
) override
{}
66 scoped_refptr
<DisplayItemList
> PaintContentsToDisplayList(
67 const gfx::Rect
& clip
,
68 PaintingControlSetting picture_control
) override
{
72 bool FillsBoundsCompletely() const override
{ return false; }
73 size_t GetApproximateUnsharedMemoryUsage() const override
{ return 0; }
76 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
78 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
79 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
82 #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
84 EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \
87 class LayerTreeSettingsScaleContent
: public LayerTreeSettings
{
89 LayerTreeSettingsScaleContent() {
90 layer_transforms_should_scale_layer_contents
= true;
94 class LayerTreeHostCommonScalingTest
: public LayerTreeHostCommonTest
{
96 LayerTreeHostCommonScalingTest()
97 : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {}
100 TEST_F(LayerTreeHostCommonTest
, TransformsForNoOpLayer
) {
101 // Sanity check: For layers positioned at zero, with zero size,
102 // and with identity transforms, then the draw transform,
103 // screen space transform, and the hierarchy passed on to children
104 // layers should also be identity transforms.
106 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
107 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
108 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
109 parent
->AddChild(child
);
110 child
->AddChild(grand_child
);
112 host()->SetRootLayer(parent
);
114 gfx::Transform identity_matrix
;
115 SetLayerPropertiesForTesting(parent
.get(),
122 SetLayerPropertiesForTesting(child
.get(),
129 SetLayerPropertiesForTesting(grand_child
.get(),
137 ExecuteCalculateDrawProperties(parent
.get());
139 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
140 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
141 child
->screen_space_transform());
142 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
143 grand_child
->draw_transform());
144 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
145 grand_child
->screen_space_transform());
148 TEST_F(LayerTreeHostCommonTest
, DoNotSkipLayersWithHandlers
) {
149 LayerImpl
* parent
= root_layer();
150 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
151 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
153 gfx::Transform identity_matrix
;
154 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
155 gfx::PointF(), gfx::Size(100, 100), true, false,
157 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
158 gfx::PointF(10, 10), gfx::Size(100, 100), true,
160 // This would have previously caused us to skip our subtree, but this would be
161 // wrong; we need up-to-date draw properties to do hit testing on the layers
163 child
->SetOpacity(0.f
);
164 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
165 gfx::PointF(10, 10), gfx::Size(100, 100), true,
167 grand_child
->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
169 ExecuteCalculateDrawProperties(parent
);
171 // Check that we've computed draw properties for the subtree rooted at
173 EXPECT_FALSE(child
->draw_transform().IsIdentity());
174 EXPECT_FALSE(grand_child
->draw_transform().IsIdentity());
177 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleLayer
) {
178 gfx::Transform identity_matrix
;
179 scoped_refptr
<Layer
> layer
= Layer::Create(layer_settings());
181 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
182 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
183 gfx::PointF(), gfx::Size(1, 2), true, false);
184 root
->AddChild(layer
);
186 host()->SetRootLayer(root
);
188 TransformTree
& tree
= host()->property_trees()->transform_tree
;
190 // Case 2: Setting the bounds of the layer should not affect either the draw
191 // transform or the screenspace transform.
192 gfx::Transform translation_to_center
;
193 translation_to_center
.Translate(5.0, 6.0);
194 SetLayerPropertiesForTesting(layer
.get(), identity_matrix
, gfx::Point3F(),
195 gfx::PointF(), gfx::Size(10, 12), true, false);
196 ExecuteCalculateDrawProperties(root
.get());
197 EXPECT_TRANSFORMATION_MATRIX_EQ(
198 identity_matrix
, DrawTransformFromPropertyTrees(layer
.get(), tree
));
199 EXPECT_TRANSFORMATION_MATRIX_EQ(
201 ScreenSpaceTransformFromPropertyTrees(layer
.get(), tree
));
203 // Case 3: The anchor point by itself (without a layer transform) should have
204 // no effect on the transforms.
205 SetLayerPropertiesForTesting(layer
.get(), identity_matrix
,
206 gfx::Point3F(2.5f
, 3.0f
, 0.f
), gfx::PointF(),
207 gfx::Size(10, 12), true, false);
208 ExecuteCalculateDrawProperties(root
.get());
209 EXPECT_TRANSFORMATION_MATRIX_EQ(
210 identity_matrix
, DrawTransformFromPropertyTrees(layer
.get(), tree
));
211 EXPECT_TRANSFORMATION_MATRIX_EQ(
213 ScreenSpaceTransformFromPropertyTrees(layer
.get(), tree
));
215 // Case 4: A change in actual position affects both the draw transform and
216 // screen space transform.
217 gfx::Transform position_transform
;
218 position_transform
.Translate(0.f
, 1.2f
);
219 SetLayerPropertiesForTesting(
220 layer
.get(), identity_matrix
, gfx::Point3F(2.5f
, 3.0f
, 0.f
),
221 gfx::PointF(0.f
, 1.2f
), gfx::Size(10, 12), true, false);
222 ExecuteCalculateDrawProperties(root
.get());
223 EXPECT_TRANSFORMATION_MATRIX_EQ(
224 position_transform
, DrawTransformFromPropertyTrees(layer
.get(), tree
));
225 EXPECT_TRANSFORMATION_MATRIX_EQ(
227 ScreenSpaceTransformFromPropertyTrees(layer
.get(), tree
));
229 // Case 5: In the correct sequence of transforms, the layer transform should
230 // pre-multiply the translation_to_center. This is easily tested by using a
231 // scale transform, because scale and translation are not commutative.
232 gfx::Transform layer_transform
;
233 layer_transform
.Scale3d(2.0, 2.0, 1.0);
234 SetLayerPropertiesForTesting(layer
.get(), layer_transform
, gfx::Point3F(),
235 gfx::PointF(), gfx::Size(10, 12), true, false);
236 ExecuteCalculateDrawProperties(root
.get());
237 EXPECT_TRANSFORMATION_MATRIX_EQ(
238 layer_transform
, DrawTransformFromPropertyTrees(layer
.get(), tree
));
239 EXPECT_TRANSFORMATION_MATRIX_EQ(
241 ScreenSpaceTransformFromPropertyTrees(layer
.get(), tree
));
243 // Case 6: The layer transform should occur with respect to the anchor point.
244 gfx::Transform translation_to_anchor
;
245 translation_to_anchor
.Translate(5.0, 0.0);
246 gfx::Transform expected_result
=
247 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
248 SetLayerPropertiesForTesting(layer
.get(), layer_transform
,
249 gfx::Point3F(5.0f
, 0.f
, 0.f
), gfx::PointF(),
250 gfx::Size(10, 12), true, false);
251 ExecuteCalculateDrawProperties(root
.get());
252 EXPECT_TRANSFORMATION_MATRIX_EQ(
253 expected_result
, DrawTransformFromPropertyTrees(layer
.get(), tree
));
254 EXPECT_TRANSFORMATION_MATRIX_EQ(
256 ScreenSpaceTransformFromPropertyTrees(layer
.get(), tree
));
258 // Case 7: Verify that position pre-multiplies the layer transform. The
259 // current implementation of CalculateDrawProperties does this implicitly, but
260 // it is still worth testing to detect accidental regressions.
261 expected_result
= position_transform
* translation_to_anchor
*
262 layer_transform
* Inverse(translation_to_anchor
);
263 SetLayerPropertiesForTesting(
264 layer
.get(), layer_transform
, gfx::Point3F(5.0f
, 0.f
, 0.f
),
265 gfx::PointF(0.f
, 1.2f
), gfx::Size(10, 12), true, false);
266 ExecuteCalculateDrawProperties(root
.get());
267 EXPECT_TRANSFORMATION_MATRIX_EQ(
268 expected_result
, DrawTransformFromPropertyTrees(layer
.get(), tree
));
269 EXPECT_TRANSFORMATION_MATRIX_EQ(
271 ScreenSpaceTransformFromPropertyTrees(layer
.get(), tree
));
274 TEST_F(LayerTreeHostCommonTest
, TransformsAboutScrollOffset
) {
275 const gfx::ScrollOffset
kScrollOffset(50, 100);
276 const gfx::Vector2dF
kScrollDelta(2.34f
, 5.67f
);
277 const gfx::Vector2d
kMaxScrollOffset(200, 200);
278 const gfx::PointF
kScrollLayerPosition(-kScrollOffset
.x(),
280 const float kPageScale
= 0.888f
;
281 const float kDeviceScale
= 1.666f
;
284 TestSharedBitmapManager shared_bitmap_manager
;
285 TestTaskGraphRunner task_graph_runner
;
286 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
289 gfx::Transform identity_matrix
;
290 scoped_ptr
<LayerImpl
> sublayer_scoped_ptr(
291 LayerImpl::Create(host_impl
.active_tree(), 1));
292 LayerImpl
* sublayer
= sublayer_scoped_ptr
.get();
293 SetLayerPropertiesForTesting(sublayer
, identity_matrix
, gfx::Point3F(),
294 gfx::PointF(), gfx::Size(500, 500), true, false,
297 scoped_ptr
<LayerImpl
> scroll_layer_scoped_ptr(
298 LayerImpl::Create(host_impl
.active_tree(), 2));
299 LayerImpl
* scroll_layer
= scroll_layer_scoped_ptr
.get();
300 SetLayerPropertiesForTesting(scroll_layer
, identity_matrix
, gfx::Point3F(),
301 gfx::PointF(), gfx::Size(10, 20), true, false,
303 scoped_ptr
<LayerImpl
> clip_layer_scoped_ptr(
304 LayerImpl::Create(host_impl
.active_tree(), 4));
305 LayerImpl
* clip_layer
= clip_layer_scoped_ptr
.get();
307 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
308 clip_layer
->SetBounds(
309 gfx::Size(scroll_layer
->bounds().width() + kMaxScrollOffset
.x(),
310 scroll_layer
->bounds().height() + kMaxScrollOffset
.y()));
311 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
312 scroll_layer
->SetScrollDelta(kScrollDelta
);
313 gfx::Transform impl_transform
;
314 scroll_layer
->AddChild(sublayer_scoped_ptr
.Pass());
315 LayerImpl
* scroll_layer_raw_ptr
= scroll_layer_scoped_ptr
.get();
316 clip_layer
->AddChild(scroll_layer_scoped_ptr
.Pass());
317 scroll_layer_raw_ptr
->PushScrollOffsetFromMainThread(kScrollOffset
);
319 scoped_ptr
<LayerImpl
> root(LayerImpl::Create(host_impl
.active_tree(), 3));
320 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
321 gfx::PointF(), gfx::Size(3, 4), true, false,
323 root
->AddChild(clip_layer_scoped_ptr
.Pass());
324 root
->SetHasRenderSurface(true);
326 ExecuteCalculateDrawProperties(
327 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
328 gfx::Transform expected_transform
= identity_matrix
;
329 gfx::PointF sub_layer_screen_position
= kScrollLayerPosition
- kScrollDelta
;
330 expected_transform
.Translate(MathUtil::Round(sub_layer_screen_position
.x() *
331 kPageScale
* kDeviceScale
),
332 MathUtil::Round(sub_layer_screen_position
.y() *
333 kPageScale
* kDeviceScale
));
334 expected_transform
.Scale(kPageScale
* kDeviceScale
,
335 kPageScale
* kDeviceScale
);
336 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
337 sublayer
->draw_transform());
338 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
339 sublayer
->screen_space_transform());
341 gfx::Transform arbitrary_translate
;
342 const float kTranslateX
= 10.6f
;
343 const float kTranslateY
= 20.6f
;
344 arbitrary_translate
.Translate(kTranslateX
, kTranslateY
);
345 SetLayerPropertiesForTesting(scroll_layer
, arbitrary_translate
,
346 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
348 ExecuteCalculateDrawProperties(
349 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
350 expected_transform
.MakeIdentity();
351 expected_transform
.Translate(
352 MathUtil::Round(kTranslateX
* kPageScale
* kDeviceScale
+
353 sub_layer_screen_position
.x() * kPageScale
*
355 MathUtil::Round(kTranslateY
* kPageScale
* kDeviceScale
+
356 sub_layer_screen_position
.y() * kPageScale
*
358 expected_transform
.Scale(kPageScale
* kDeviceScale
,
359 kPageScale
* kDeviceScale
);
360 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
361 sublayer
->draw_transform());
364 TEST_F(LayerTreeHostCommonTest
, TransformsForSimpleHierarchy
) {
365 gfx::Transform identity_matrix
;
366 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
367 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
368 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
369 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
370 root
->AddChild(parent
);
371 parent
->AddChild(child
);
372 child
->AddChild(grand_child
);
374 host()->SetRootLayer(root
);
376 // One-time setup of root layer
377 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
378 gfx::PointF(), gfx::Size(1, 2), true, false);
380 TransformTree
& tree
= host()->property_trees()->transform_tree
;
382 // Case 1: parent's anchor point should not affect child or grand_child.
383 SetLayerPropertiesForTesting(parent
.get(), identity_matrix
,
384 gfx::Point3F(2.5f
, 3.0f
, 0.f
), gfx::PointF(),
385 gfx::Size(10, 12), true, false);
386 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
387 gfx::PointF(), gfx::Size(16, 18), true, false);
388 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
389 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78),
391 ExecuteCalculateDrawProperties(root
.get());
393 EXPECT_TRANSFORMATION_MATRIX_EQ(
394 identity_matrix
, DrawTransformFromPropertyTrees(child
.get(), tree
));
395 EXPECT_TRANSFORMATION_MATRIX_EQ(
397 ScreenSpaceTransformFromPropertyTrees(child
.get(), tree
));
398 EXPECT_TRANSFORMATION_MATRIX_EQ(
399 identity_matrix
, DrawTransformFromPropertyTrees(grand_child
.get(), tree
));
400 EXPECT_TRANSFORMATION_MATRIX_EQ(
402 ScreenSpaceTransformFromPropertyTrees(grand_child
.get(), tree
));
404 // Case 2: parent's position affects child and grand_child.
405 gfx::Transform parent_position_transform
;
406 parent_position_transform
.Translate(0.f
, 1.2f
);
407 SetLayerPropertiesForTesting(
408 parent
.get(), identity_matrix
, gfx::Point3F(2.5f
, 3.0f
, 0.f
),
409 gfx::PointF(0.f
, 1.2f
), gfx::Size(10, 12), true, false);
410 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
411 gfx::PointF(), gfx::Size(16, 18), true, false);
412 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
413 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78),
415 ExecuteCalculateDrawProperties(root
.get());
416 EXPECT_TRANSFORMATION_MATRIX_EQ(
417 parent_position_transform
,
418 DrawTransformFromPropertyTrees(child
.get(), tree
));
419 EXPECT_TRANSFORMATION_MATRIX_EQ(
420 parent_position_transform
,
421 ScreenSpaceTransformFromPropertyTrees(child
.get(), tree
));
422 EXPECT_TRANSFORMATION_MATRIX_EQ(
423 parent_position_transform
,
424 DrawTransformFromPropertyTrees(grand_child
.get(), tree
));
425 EXPECT_TRANSFORMATION_MATRIX_EQ(
426 parent_position_transform
,
427 ScreenSpaceTransformFromPropertyTrees(grand_child
.get(), tree
));
429 // Case 3: parent's local transform affects child and grandchild
430 gfx::Transform parent_layer_transform
;
431 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
432 gfx::Transform parent_translation_to_anchor
;
433 parent_translation_to_anchor
.Translate(2.5, 3.0);
434 gfx::Transform parent_composite_transform
=
435 parent_translation_to_anchor
* parent_layer_transform
*
436 Inverse(parent_translation_to_anchor
);
437 SetLayerPropertiesForTesting(parent
.get(), parent_layer_transform
,
438 gfx::Point3F(2.5f
, 3.0f
, 0.f
), gfx::PointF(),
439 gfx::Size(10, 12), true, false);
440 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
441 gfx::PointF(), gfx::Size(16, 18), true, false);
442 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
443 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78),
445 ExecuteCalculateDrawProperties(root
.get());
446 EXPECT_TRANSFORMATION_MATRIX_EQ(
447 parent_composite_transform
,
448 DrawTransformFromPropertyTrees(child
.get(), tree
));
449 EXPECT_TRANSFORMATION_MATRIX_EQ(
450 parent_composite_transform
,
451 ScreenSpaceTransformFromPropertyTrees(child
.get(), tree
));
452 EXPECT_TRANSFORMATION_MATRIX_EQ(
453 parent_composite_transform
,
454 DrawTransformFromPropertyTrees(grand_child
.get(), tree
));
455 EXPECT_TRANSFORMATION_MATRIX_EQ(
456 parent_composite_transform
,
457 ScreenSpaceTransformFromPropertyTrees(grand_child
.get(), tree
));
460 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleRenderSurface
) {
461 LayerImpl
* root
= root_layer();
462 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
463 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
464 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
465 grand_child
->SetDrawsContent(true);
467 gfx::Transform identity_matrix
;
468 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
469 gfx::PointF(), gfx::Size(1, 2), true, false,
472 // Child is set up so that a new render surface should be created.
473 child
->SetOpacity(0.5f
);
475 gfx::Transform parent_layer_transform
;
476 parent_layer_transform
.Scale3d(1.f
, 0.9f
, 1.f
);
477 gfx::Transform parent_translation_to_anchor
;
478 parent_translation_to_anchor
.Translate(25.0, 30.0);
480 gfx::Transform parent_composite_transform
=
481 parent_translation_to_anchor
* parent_layer_transform
*
482 Inverse(parent_translation_to_anchor
);
483 gfx::Vector2dF parent_composite_scale
=
484 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
486 gfx::Transform surface_sublayer_transform
;
487 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
488 parent_composite_scale
.y());
489 gfx::Transform surface_sublayer_composite_transform
=
490 parent_composite_transform
* Inverse(surface_sublayer_transform
);
492 SetLayerPropertiesForTesting(parent
, parent_layer_transform
,
493 gfx::Point3F(25.0f
, 30.0f
, 0.f
), gfx::PointF(),
494 gfx::Size(100, 120), true, false, false);
495 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
496 gfx::PointF(), gfx::Size(16, 18), true, false,
498 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
499 gfx::PointF(), gfx::Size(8, 10), true, false,
501 ExecuteCalculateDrawProperties(root
);
503 // Render surface should have been created now.
504 ASSERT_TRUE(child
->render_surface());
505 ASSERT_EQ(child
, child
->render_target());
507 // The child layer's draw transform should refer to its new render surface.
508 // The screen-space transform, however, should still refer to the root.
509 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform
,
510 child
->draw_transform());
511 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
512 child
->screen_space_transform());
514 // Because the grand_child is the only drawable content, the child's render
515 // surface will tighten its bounds to the grand_child. The scale at which the
516 // surface's subtree is drawn must be removed from the composite transform.
517 EXPECT_TRANSFORMATION_MATRIX_EQ(
518 surface_sublayer_composite_transform
,
519 child
->render_target()->render_surface()->draw_transform());
521 // The screen space is the same as the target since the child surface draws
523 EXPECT_TRANSFORMATION_MATRIX_EQ(
524 surface_sublayer_composite_transform
,
525 child
->render_target()->render_surface()->screen_space_transform());
528 TEST_F(LayerTreeHostCommonTest
, TransformsForReplica
) {
529 LayerImpl
* root
= root_layer();
530 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
531 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
532 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
533 grand_child
->SetDrawsContent(true);
534 scoped_ptr
<LayerImpl
> child_replica
=
535 LayerImpl::Create(host_impl()->active_tree(), 100);
537 // One-time setup of root layer
538 gfx::Transform identity_matrix
;
539 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
540 gfx::PointF(), gfx::Size(1, 2), true, false,
543 // Child is set up so that a new render surface should be created.
544 child
->SetOpacity(0.5f
);
546 gfx::Transform parent_layer_transform
;
547 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
548 gfx::Transform parent_translation_to_anchor
;
549 parent_translation_to_anchor
.Translate(2.5, 3.0);
550 gfx::Transform parent_composite_transform
=
551 parent_translation_to_anchor
* parent_layer_transform
*
552 Inverse(parent_translation_to_anchor
);
553 gfx::Transform replica_layer_transform
;
554 replica_layer_transform
.Scale3d(3.0, 3.0, 1.0);
555 gfx::Vector2dF parent_composite_scale
=
556 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
558 gfx::Transform surface_sublayer_transform
;
559 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
560 parent_composite_scale
.y());
561 gfx::Transform replica_composite_transform
=
562 parent_composite_transform
* replica_layer_transform
*
563 Inverse(surface_sublayer_transform
);
564 child_replica
->SetDrawsContent(true);
565 // Child's render surface should not exist yet.
566 ASSERT_FALSE(child
->render_surface());
568 SetLayerPropertiesForTesting(parent
, parent_layer_transform
,
569 gfx::Point3F(2.5f
, 3.0f
, 0.f
), gfx::PointF(),
570 gfx::Size(10, 12), true, false, false);
571 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
572 gfx::PointF(), gfx::Size(16, 18), true, false,
574 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
575 gfx::PointF(-0.5f
, -0.5f
), gfx::Size(1, 1), true,
577 SetLayerPropertiesForTesting(child_replica
.get(), replica_layer_transform
,
578 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
580 child
->SetReplicaLayer(child_replica
.Pass());
582 ExecuteCalculateDrawProperties(root
);
584 // Render surface should have been created now.
585 ASSERT_TRUE(child
->render_surface());
586 ASSERT_EQ(child
, child
->render_target());
588 EXPECT_TRANSFORMATION_MATRIX_EQ(
589 replica_composite_transform
,
590 child
->render_target()->render_surface()->replica_draw_transform());
591 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform
,
592 child
->render_target()
594 ->replica_screen_space_transform());
597 TEST_F(LayerTreeHostCommonTest
, TransformsForRenderSurfaceHierarchy
) {
598 // This test creates a more complex tree and verifies it all at once. This
599 // covers the following cases:
600 // - layers that are described w.r.t. a render surface: should have draw
601 // transforms described w.r.t. that surface
602 // - A render surface described w.r.t. an ancestor render surface: should
603 // have a draw transform described w.r.t. that ancestor surface
604 // - Replicas of a render surface are described w.r.t. the replica's
605 // transform around its anchor, along with the surface itself.
606 // - Sanity check on recursion: verify transforms of layers described w.r.t.
607 // a render surface that is described w.r.t. an ancestor render surface.
608 // - verifying that each layer has a reference to the correct render surface
609 // and render target values.
611 LayerImpl
* root
= root_layer();
612 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
613 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(parent
);
614 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(render_surface1
);
615 LayerImpl
* child_of_root
= AddChild
<LayerImpl
>(parent
);
616 LayerImpl
* child_of_rs1
= AddChild
<LayerImpl
>(render_surface1
);
617 LayerImpl
* child_of_rs2
= AddChild
<LayerImpl
>(render_surface2
);
618 LayerImpl
* grand_child_of_root
= AddChild
<LayerImpl
>(child_of_root
);
619 LayerImpl
* grand_child_of_rs1
= AddChild
<LayerImpl
>(child_of_rs1
);
620 grand_child_of_rs1
->SetDrawsContent(true);
621 LayerImpl
* grand_child_of_rs2
= AddChild
<LayerImpl
>(child_of_rs2
);
622 grand_child_of_rs2
->SetDrawsContent(true);
624 scoped_ptr
<LayerImpl
> replica_of_rs1
=
625 LayerImpl::Create(host_impl()->active_tree(), 101);
626 scoped_ptr
<LayerImpl
> replica_of_rs2
=
627 LayerImpl::Create(host_impl()->active_tree(), 102);
629 // In combination with descendant draws content, opacity != 1 forces the layer
630 // to have a new render surface.
631 render_surface1
->SetOpacity(0.5f
);
632 render_surface2
->SetOpacity(0.33f
);
634 // One-time setup of root layer
635 gfx::Transform identity_matrix
;
636 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
637 gfx::PointF(), gfx::Size(1, 2), true, false,
640 // All layers in the tree are initialized with an anchor at .25 and a size of
641 // (10,10). matrix "A" is the composite layer transform used in all layers,
642 // Matrix "R" is the composite replica transform used in all replica layers.
643 gfx::Transform translation_to_anchor
;
644 translation_to_anchor
.Translate(2.5, 0.0);
645 gfx::Transform layer_transform
;
646 layer_transform
.Translate(1.0, 1.0);
647 gfx::Transform replica_layer_transform
;
648 replica_layer_transform
.Scale3d(-2.0, 5.0, 1.0);
651 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
652 gfx::Transform R
= A
* translation_to_anchor
* replica_layer_transform
*
653 Inverse(translation_to_anchor
);
655 gfx::Vector2dF surface1_parent_transform_scale
=
656 MathUtil::ComputeTransform2dScaleComponents(A
, 1.f
);
657 gfx::Transform surface1_sublayer_transform
;
658 surface1_sublayer_transform
.Scale(surface1_parent_transform_scale
.x(),
659 surface1_parent_transform_scale
.y());
661 // SS1 = transform given to the subtree of render_surface1
662 gfx::Transform SS1
= surface1_sublayer_transform
;
663 // S1 = transform to move from render_surface1 pixels to the layer space of
665 gfx::Transform S1
= Inverse(surface1_sublayer_transform
);
667 gfx::Vector2dF surface2_parent_transform_scale
=
668 MathUtil::ComputeTransform2dScaleComponents(SS1
* A
, 1.f
);
669 gfx::Transform surface2_sublayer_transform
;
670 surface2_sublayer_transform
.Scale(surface2_parent_transform_scale
.x(),
671 surface2_parent_transform_scale
.y());
673 // SS2 = transform given to the subtree of render_surface2
674 gfx::Transform SS2
= surface2_sublayer_transform
;
675 // S2 = transform to move from render_surface2 pixels to the layer space of
677 gfx::Transform S2
= Inverse(surface2_sublayer_transform
);
679 SetLayerPropertiesForTesting(parent
, layer_transform
,
680 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
681 gfx::Size(10, 10), true, false, false);
682 SetLayerPropertiesForTesting(render_surface1
, layer_transform
,
683 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
684 gfx::Size(10, 10), true, false, true);
685 SetLayerPropertiesForTesting(render_surface2
, layer_transform
,
686 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
687 gfx::Size(10, 10), true, false, true);
688 SetLayerPropertiesForTesting(child_of_root
, layer_transform
,
689 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
690 gfx::Size(10, 10), true, false, false);
691 SetLayerPropertiesForTesting(child_of_rs1
, layer_transform
,
692 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
693 gfx::Size(10, 10), true, false, false);
694 SetLayerPropertiesForTesting(child_of_rs2
, layer_transform
,
695 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
696 gfx::Size(10, 10), true, false, false);
697 SetLayerPropertiesForTesting(grand_child_of_root
, layer_transform
,
698 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
699 gfx::Size(10, 10), true, false, false);
700 SetLayerPropertiesForTesting(grand_child_of_rs1
, layer_transform
,
701 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
702 gfx::Size(10, 10), true, false, false);
703 SetLayerPropertiesForTesting(grand_child_of_rs2
, layer_transform
,
704 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
705 gfx::Size(10, 10), true, false, false);
706 SetLayerPropertiesForTesting(replica_of_rs1
.get(), replica_layer_transform
,
707 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
708 gfx::Size(), true, false, false);
709 SetLayerPropertiesForTesting(replica_of_rs2
.get(), replica_layer_transform
,
710 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
711 gfx::Size(), true, false, false);
713 render_surface1
->SetReplicaLayer(replica_of_rs1
.Pass());
714 render_surface2
->SetReplicaLayer(replica_of_rs2
.Pass());
715 ExecuteCalculateDrawProperties(root
);
717 // Only layers that are associated with render surfaces should have an actual
718 // RenderSurface() value.
719 ASSERT_TRUE(root
->render_surface());
720 ASSERT_FALSE(child_of_root
->render_surface());
721 ASSERT_FALSE(grand_child_of_root
->render_surface());
723 ASSERT_TRUE(render_surface1
->render_surface());
724 ASSERT_FALSE(child_of_rs1
->render_surface());
725 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
727 ASSERT_TRUE(render_surface2
->render_surface());
728 ASSERT_FALSE(child_of_rs2
->render_surface());
729 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
731 // Verify all render target accessors
732 EXPECT_EQ(root
, parent
->render_target());
733 EXPECT_EQ(root
, child_of_root
->render_target());
734 EXPECT_EQ(root
, grand_child_of_root
->render_target());
736 EXPECT_EQ(render_surface1
, render_surface1
->render_target());
737 EXPECT_EQ(render_surface1
, child_of_rs1
->render_target());
738 EXPECT_EQ(render_surface1
, grand_child_of_rs1
->render_target());
740 EXPECT_EQ(render_surface2
, render_surface2
->render_target());
741 EXPECT_EQ(render_surface2
, child_of_rs2
->render_target());
742 EXPECT_EQ(render_surface2
, grand_child_of_rs2
->render_target());
744 // Verify layer draw transforms note that draw transforms are described with
745 // respect to the nearest ancestor render surface but screen space transforms
746 // are described with respect to the root.
747 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->draw_transform());
748 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
, child_of_root
->draw_transform());
749 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
750 grand_child_of_root
->draw_transform());
752 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
, render_surface1
->draw_transform());
753 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
, child_of_rs1
->draw_transform());
754 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
* A
,
755 grand_child_of_rs1
->draw_transform());
757 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
, render_surface2
->draw_transform());
758 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
, child_of_rs2
->draw_transform());
759 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
* A
,
760 grand_child_of_rs2
->draw_transform());
762 // Verify layer screen-space transforms
764 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->screen_space_transform());
765 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
766 child_of_root
->screen_space_transform());
767 EXPECT_TRANSFORMATION_MATRIX_EQ(
768 A
* A
* A
, grand_child_of_root
->screen_space_transform());
770 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
771 render_surface1
->screen_space_transform());
772 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
773 child_of_rs1
->screen_space_transform());
774 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
775 grand_child_of_rs1
->screen_space_transform());
777 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
778 render_surface2
->screen_space_transform());
779 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
780 child_of_rs2
->screen_space_transform());
781 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
* A
,
782 grand_child_of_rs2
->screen_space_transform());
784 // Verify render surface transforms.
786 // Draw transform of render surface 1 is described with respect to root.
787 EXPECT_TRANSFORMATION_MATRIX_EQ(
788 A
* A
* S1
, render_surface1
->render_surface()->draw_transform());
789 EXPECT_TRANSFORMATION_MATRIX_EQ(
790 A
* R
* S1
, render_surface1
->render_surface()->replica_draw_transform());
791 EXPECT_TRANSFORMATION_MATRIX_EQ(
792 A
* A
* S1
, render_surface1
->render_surface()->screen_space_transform());
793 EXPECT_TRANSFORMATION_MATRIX_EQ(
795 render_surface1
->render_surface()->replica_screen_space_transform());
796 // Draw transform of render surface 2 is described with respect to render
798 EXPECT_TRANSFORMATION_MATRIX_EQ(
799 SS1
* A
* S2
, render_surface2
->render_surface()->draw_transform());
800 EXPECT_TRANSFORMATION_MATRIX_EQ(
802 render_surface2
->render_surface()->replica_draw_transform());
803 EXPECT_TRANSFORMATION_MATRIX_EQ(
805 render_surface2
->render_surface()->screen_space_transform());
806 EXPECT_TRANSFORMATION_MATRIX_EQ(
808 render_surface2
->render_surface()->replica_screen_space_transform());
810 // Sanity check. If these fail there is probably a bug in the test itself. It
811 // is expected that we correctly set up transforms so that the y-component of
812 // the screen-space transform encodes the "depth" of the layer in the tree.
813 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
815 child_of_root
->screen_space_transform().matrix().get(1, 3));
817 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
820 render_surface1
->screen_space_transform().matrix().get(1, 3));
822 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
824 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
827 render_surface2
->screen_space_transform().matrix().get(1, 3));
829 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
831 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
834 TEST_F(LayerTreeHostCommonTest
, TransformsForFlatteningLayer
) {
835 // For layers that flatten their subtree, there should be an orthographic
836 // projection (for x and y values) in the middle of the transform sequence.
837 // Note that the way the code is currently implemented, it is not expected to
838 // use a canonical orthographic projection.
840 LayerImpl
* root
= root_layer();
841 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
842 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
843 grand_child
->SetDrawsContent(true);
844 LayerImpl
* great_grand_child
= AddChild
<LayerImpl
>(grand_child
);
845 great_grand_child
->SetDrawsContent(true);
847 gfx::Transform rotation_about_y_axis
;
848 rotation_about_y_axis
.RotateAboutYAxis(30.0);
850 const gfx::Transform identity_matrix
;
851 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
852 gfx::PointF(), gfx::Size(100, 100), true, false,
854 SetLayerPropertiesForTesting(child
, rotation_about_y_axis
, gfx::Point3F(),
855 gfx::PointF(), gfx::Size(10, 10), true, false,
857 SetLayerPropertiesForTesting(grand_child
, rotation_about_y_axis
,
858 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
860 SetLayerPropertiesForTesting(great_grand_child
, identity_matrix
,
861 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
864 // No layers in this test should preserve 3d.
865 ASSERT_TRUE(root
->should_flatten_transform());
866 ASSERT_TRUE(child
->should_flatten_transform());
867 ASSERT_TRUE(grand_child
->should_flatten_transform());
868 ASSERT_TRUE(great_grand_child
->should_flatten_transform());
870 gfx::Transform expected_child_draw_transform
= rotation_about_y_axis
;
871 gfx::Transform expected_child_screen_space_transform
= rotation_about_y_axis
;
872 gfx::Transform expected_grand_child_draw_transform
=
873 rotation_about_y_axis
; // draws onto child's render surface
874 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
875 flattened_rotation_about_y
.FlattenTo2d();
876 gfx::Transform expected_grand_child_screen_space_transform
=
877 flattened_rotation_about_y
* rotation_about_y_axis
;
878 gfx::Transform expected_great_grand_child_draw_transform
=
879 flattened_rotation_about_y
;
880 gfx::Transform expected_great_grand_child_screen_space_transform
=
881 flattened_rotation_about_y
* flattened_rotation_about_y
;
883 ExecuteCalculateDrawProperties(root
);
885 // The child's draw transform should have been taken by its surface.
886 ASSERT_TRUE(child
->render_surface());
887 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform
,
888 child
->render_surface()->draw_transform());
889 EXPECT_TRANSFORMATION_MATRIX_EQ(
890 expected_child_screen_space_transform
,
891 child
->render_surface()->screen_space_transform());
892 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
893 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform
,
894 child
->screen_space_transform());
895 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform
,
896 grand_child
->draw_transform());
897 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform
,
898 grand_child
->screen_space_transform());
899 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform
,
900 great_grand_child
->draw_transform());
901 EXPECT_TRANSFORMATION_MATRIX_EQ(
902 expected_great_grand_child_screen_space_transform
,
903 great_grand_child
->screen_space_transform());
906 TEST_F(LayerTreeHostCommonTest
, LayerFullyContainedWithinClipInTargetSpace
) {
907 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
908 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
909 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
910 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
912 gfx::Transform child_transform
;
913 child_transform
.Translate(50.0, 50.0);
914 child_transform
.RotateAboutZAxis(30.0);
916 gfx::Transform grand_child_transform
;
917 grand_child_transform
.RotateAboutYAxis(90.0);
919 const gfx::Transform identity_matrix
;
920 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
921 gfx::PointF(), gfx::Size(200, 200), true, false);
922 SetLayerPropertiesForTesting(child
.get(), child_transform
, gfx::Point3F(),
923 gfx::PointF(), gfx::Size(10, 10), true, false);
924 SetLayerPropertiesForTesting(grand_child
.get(), grand_child_transform
,
925 gfx::Point3F(), gfx::PointF(),
926 gfx::Size(100, 100), true, false);
928 root
->AddChild(child
);
929 child
->AddChild(grand_child
);
930 grand_child
->SetShouldFlattenTransform(false);
932 host()->SetRootLayer(root
);
934 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
936 // Mapping grand_child's bounds to target space produces a non-empty rect
937 // that is fully contained within the target's bounds, so grand_child should
938 // be considered fully visible.
939 EXPECT_EQ(gfx::Rect(grand_child
->bounds()),
940 grand_child
->visible_rect_from_property_trees());
943 TEST_F(LayerTreeHostCommonTest
, TransformsForDegenerateIntermediateLayer
) {
944 // A layer that is empty in one axis, but not the other, was accidentally
945 // skipping a necessary translation. Without that translation, the coordinate
946 // space of the layer's draw transform is incorrect.
948 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
949 // but if that layer becomes a render surface, then its draw transform is
950 // implicitly inherited by the rest of the subtree, which then is positioned
951 // incorrectly as a result.
953 LayerImpl
* root
= root_layer();
954 LayerImpl
* child
= AddChild
<LayerImpl
>(root
);
955 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
956 grand_child
->SetDrawsContent(true);
958 // The child height is zero, but has non-zero width that should be accounted
959 // for while computing draw transforms.
960 const gfx::Transform identity_matrix
;
961 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
962 gfx::PointF(), gfx::Size(100, 100), true, false,
964 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
965 gfx::PointF(), gfx::Size(10, 0), true, false,
967 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
968 gfx::PointF(), gfx::Size(10, 10), true, false,
971 ExecuteCalculateDrawProperties(root
);
973 ASSERT_TRUE(child
->has_render_surface());
974 // This is the real test, the rest are sanity checks.
975 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
976 child
->render_surface()->draw_transform());
977 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
978 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
979 grand_child
->draw_transform());
982 TEST_F(LayerTreeHostCommonTest
, TransformAboveRootLayer
) {
983 // Transformations applied at the root of the tree should be forwarded
984 // to child layers instead of applied to the root RenderSurface.
985 const gfx::Transform identity_matrix
;
986 LayerImpl
* root
= root_layer();
987 root
->SetDrawsContent(true);
988 LayerImpl
* child
= AddChild
<LayerImpl
>(root
);
989 child
->SetDrawsContent(true);
991 child
->SetScrollClipLayer(root
->id());
993 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
994 gfx::PointF(), gfx::Size(20, 20), true, false,
996 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
997 gfx::PointF(), gfx::Size(20, 20), true, false,
1000 gfx::Transform translate
;
1001 translate
.Translate(50, 50);
1003 LayerImplList render_surface_layer_list_impl
;
1004 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1005 root
, root
->bounds(), translate
, &render_surface_layer_list_impl
);
1006 inputs
.property_trees
->needs_rebuild
= true;
1007 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1008 EXPECT_EQ(translate
, root
->draw_properties().target_space_transform
);
1009 EXPECT_EQ(translate
, child
->draw_properties().target_space_transform
);
1010 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1013 gfx::Transform scale
;
1016 LayerImplList render_surface_layer_list_impl
;
1017 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1018 root
, root
->bounds(), scale
, &render_surface_layer_list_impl
);
1019 inputs
.property_trees
->needs_rebuild
= true;
1020 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1021 EXPECT_EQ(scale
, root
->draw_properties().target_space_transform
);
1022 EXPECT_EQ(scale
, child
->draw_properties().target_space_transform
);
1023 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1026 gfx::Transform rotate
;
1029 LayerImplList render_surface_layer_list_impl
;
1030 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1031 root
, root
->bounds(), rotate
, &render_surface_layer_list_impl
);
1032 inputs
.property_trees
->needs_rebuild
= true;
1033 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1034 EXPECT_EQ(rotate
, root
->draw_properties().target_space_transform
);
1035 EXPECT_EQ(rotate
, child
->draw_properties().target_space_transform
);
1036 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1039 gfx::Transform composite
;
1040 composite
.ConcatTransform(translate
);
1041 composite
.ConcatTransform(scale
);
1042 composite
.ConcatTransform(rotate
);
1044 LayerImplList render_surface_layer_list_impl
;
1045 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1046 root
, root
->bounds(), composite
, &render_surface_layer_list_impl
);
1047 inputs
.property_trees
->needs_rebuild
= true;
1048 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1049 EXPECT_EQ(composite
, root
->draw_properties().target_space_transform
);
1050 EXPECT_EQ(composite
, child
->draw_properties().target_space_transform
);
1051 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1054 // Verify it composes correctly with device scale.
1055 float device_scale_factor
= 1.5f
;
1058 LayerImplList render_surface_layer_list_impl
;
1059 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1060 root
, root
->bounds(), translate
, &render_surface_layer_list_impl
);
1061 inputs
.device_scale_factor
= device_scale_factor
;
1062 inputs
.property_trees
->needs_rebuild
= true;
1063 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1064 gfx::Transform device_scaled_translate
= translate
;
1065 device_scaled_translate
.Scale(device_scale_factor
, device_scale_factor
);
1066 EXPECT_EQ(device_scaled_translate
,
1067 root
->draw_properties().target_space_transform
);
1068 EXPECT_EQ(device_scaled_translate
,
1069 child
->draw_properties().target_space_transform
);
1070 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1073 // Verify it composes correctly with page scale.
1074 float page_scale_factor
= 2.f
;
1077 LayerImplList render_surface_layer_list_impl
;
1078 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1079 root
, root
->bounds(), translate
, &render_surface_layer_list_impl
);
1080 inputs
.page_scale_factor
= page_scale_factor
;
1081 inputs
.page_scale_layer
= root
;
1082 inputs
.property_trees
->needs_rebuild
= true;
1083 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1084 gfx::Transform page_scaled_translate
= translate
;
1085 page_scaled_translate
.Scale(page_scale_factor
, page_scale_factor
);
1086 EXPECT_EQ(page_scaled_translate
,
1087 root
->draw_properties().target_space_transform
);
1088 EXPECT_EQ(page_scaled_translate
,
1089 child
->draw_properties().target_space_transform
);
1090 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1093 // Verify that it composes correctly with transforms directly on root layer.
1094 root
->SetTransform(composite
);
1097 LayerImplList render_surface_layer_list_impl
;
1098 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1099 root
, root
->bounds(), composite
, &render_surface_layer_list_impl
);
1100 inputs
.property_trees
->needs_rebuild
= true;
1101 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1102 gfx::Transform compositeSquared
= composite
;
1103 compositeSquared
.ConcatTransform(composite
);
1104 EXPECT_TRANSFORMATION_MATRIX_EQ(
1105 compositeSquared
, root
->draw_properties().target_space_transform
);
1106 EXPECT_TRANSFORMATION_MATRIX_EQ(
1107 compositeSquared
, child
->draw_properties().target_space_transform
);
1108 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1112 TEST_F(LayerTreeHostCommonTest
,
1113 RenderSurfaceListForRenderSurfaceWithClippedLayer
) {
1114 LayerImpl
* parent
= root_layer();
1115 parent
->SetMasksToBounds(true);
1116 LayerImpl
* render_surface1
= AddChildToRoot
<LayerImpl
>();
1117 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface1
);
1118 child
->SetDrawsContent(true);
1120 const gfx::Transform identity_matrix
;
1121 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1122 gfx::PointF(), gfx::Size(10, 10), true, false,
1124 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
1125 gfx::PointF(), gfx::Size(10, 10), true, false,
1127 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1128 gfx::PointF(30.f
, 30.f
), gfx::Size(10, 10), true,
1131 ExecuteCalculateDrawProperties(parent
);
1133 // The child layer's content is entirely outside the parent's clip rect, so
1134 // the intermediate render surface should not be listed here, even if it was
1135 // forced to be created. Render surfaces without children or visible content
1136 // are unexpected at draw time (e.g. we might try to create a content texture
1138 ASSERT_TRUE(parent
->render_surface());
1139 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
1142 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceListForTransparentChild
) {
1143 LayerImpl
* parent
= root_layer();
1144 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(parent
);
1145 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface1
);
1146 child
->SetDrawsContent(true);
1148 const gfx::Transform identity_matrix
;
1149 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
1150 gfx::PointF(), gfx::Size(10, 10), true, false,
1152 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1153 gfx::PointF(), gfx::Size(10, 10), true, false,
1155 render_surface1
->SetOpacity(0.f
);
1157 LayerImplList render_surface_layer_list
;
1158 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1159 parent
, parent
->bounds(), &render_surface_layer_list
);
1160 inputs
.can_adjust_raster_scales
= true;
1161 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1163 // Since the layer is transparent, render_surface1->render_surface() should
1164 // not have gotten added anywhere. Also, the drawable content rect should not
1165 // have been extended by the children.
1166 ASSERT_TRUE(parent
->render_surface());
1167 EXPECT_EQ(0U, parent
->render_surface()->layer_list().size());
1168 EXPECT_EQ(1U, render_surface_layer_list
.size());
1169 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1170 EXPECT_EQ(gfx::Rect(), parent
->drawable_content_rect());
1173 TEST_F(LayerTreeHostCommonTest
,
1174 RenderSurfaceListForTransparentChildWithBackgroundFilter
) {
1175 LayerImpl
* parent
= root_layer();
1176 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(parent
);
1177 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface1
);
1178 child
->SetDrawsContent(true);
1180 const gfx::Transform identity_matrix
;
1181 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1182 gfx::PointF(), gfx::Size(10, 10), true, false,
1184 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
1185 gfx::PointF(), gfx::Size(10, 10), true, false,
1187 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1188 gfx::PointF(), gfx::Size(10, 10), true, false,
1190 render_surface1
->SetOpacity(0.f
);
1191 FilterOperations filters
;
1192 filters
.Append(FilterOperation::CreateBlurFilter(1.5f
));
1193 render_surface1
->SetBackgroundFilters(filters
);
1195 LayerImplList render_surface_layer_list
;
1196 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1197 parent
, parent
->bounds(), &render_surface_layer_list
);
1198 inputs
.can_adjust_raster_scales
= true;
1199 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1201 // The layer is fully transparent, but has a background filter, so it
1202 // shouldn't be skipped.
1203 ASSERT_TRUE(parent
->render_surface());
1204 EXPECT_EQ(1U, parent
->render_surface()->layer_list().size());
1205 EXPECT_EQ(2U, render_surface_layer_list
.size());
1206 EXPECT_EQ(gfx::Rect(0, 0, 10, 10), parent
->drawable_content_rect());
1209 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceForBlendMode
) {
1210 LayerImpl
* parent
= root_layer();
1211 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
1212 child
->SetDrawsContent(true);
1214 const gfx::Transform identity_matrix
;
1215 const SkXfermode::Mode blend_mode
= SkXfermode::kMultiply_Mode
;
1216 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1217 gfx::PointF(), gfx::Size(10, 10), true, false,
1219 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1220 gfx::PointF(), gfx::Size(10, 10), true, false,
1223 child
->SetBlendMode(blend_mode
);
1224 child
->SetOpacity(0.5f
);
1226 ExecuteCalculateDrawProperties(parent
);
1228 // Since the child layer has a blend mode other than normal, it should get
1229 // its own render surface. Also, layer's draw_properties should contain the
1230 // default blend mode, since the render surface becomes responsible for
1231 // applying the blend mode.
1232 ASSERT_TRUE(child
->render_surface());
1233 EXPECT_EQ(1.0f
, child
->draw_opacity());
1234 EXPECT_EQ(0.5f
, child
->render_surface()->draw_opacity());
1235 EXPECT_EQ(SkXfermode::kSrcOver_Mode
, child
->draw_blend_mode());
1238 TEST_F(LayerTreeHostCommonTest
, ForceRenderSurface
) {
1239 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1240 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
1241 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1242 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1243 render_surface1
->SetForceRenderSurface(true);
1245 host()->SetRootLayer(parent
);
1247 const gfx::Transform identity_matrix
;
1248 SetLayerPropertiesForTesting(parent
.get(),
1255 SetLayerPropertiesForTesting(render_surface1
.get(),
1262 SetLayerPropertiesForTesting(child
.get(),
1270 parent
->AddChild(render_surface1
);
1271 render_surface1
->AddChild(child
);
1273 // Sanity check before the actual test
1274 EXPECT_FALSE(parent
->has_render_surface());
1275 EXPECT_FALSE(render_surface1
->has_render_surface());
1278 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(parent
.get(),
1280 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1282 // The root layer always creates a render surface
1283 EXPECT_TRUE(parent
->has_render_surface());
1284 EXPECT_TRUE(render_surface1
->has_render_surface());
1288 render_surface1
->SetForceRenderSurface(false);
1289 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(parent
.get(),
1291 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1292 EXPECT_TRUE(parent
->has_render_surface());
1293 EXPECT_FALSE(render_surface1
->has_render_surface());
1297 TEST_F(LayerTreeHostCommonTest
, RenderSurfacesFlattenScreenSpaceTransform
) {
1298 // Render surfaces act as a flattening point for their subtree, so should
1299 // always flatten the target-to-screen space transform seen by descendants.
1301 LayerImpl
* root
= root_layer();
1302 LayerImpl
* parent
= AddChild
<LayerImpl
>(root
);
1303 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
1304 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
1306 child
->SetDrawsContent(true);
1307 grand_child
->SetDrawsContent(true);
1309 gfx::Transform rotation_about_y_axis
;
1310 rotation_about_y_axis
.RotateAboutYAxis(30.0);
1311 // Make |parent| have a render surface.
1312 parent
->SetOpacity(0.9f
);
1314 const gfx::Transform identity_matrix
;
1315 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
1316 gfx::PointF(), gfx::Size(100, 100), true, false,
1318 SetLayerPropertiesForTesting(parent
, rotation_about_y_axis
, gfx::Point3F(),
1319 gfx::PointF(), gfx::Size(10, 10), true, false,
1321 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1322 gfx::PointF(), gfx::Size(10, 10), true, false,
1324 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
1325 gfx::PointF(), gfx::Size(10, 10), true, false,
1328 grand_child
->SetShouldFlattenTransform(false);
1330 // Only grand_child should preserve 3d.
1331 EXPECT_TRUE(root
->should_flatten_transform());
1332 EXPECT_TRUE(parent
->should_flatten_transform());
1333 EXPECT_TRUE(child
->should_flatten_transform());
1334 EXPECT_FALSE(grand_child
->should_flatten_transform());
1336 gfx::Transform expected_child_draw_transform
= identity_matrix
;
1337 gfx::Transform expected_grand_child_draw_transform
= identity_matrix
;
1339 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
1340 flattened_rotation_about_y
.FlattenTo2d();
1342 ExecuteCalculateDrawProperties(root
);
1344 EXPECT_TRUE(parent
->render_surface());
1345 EXPECT_FALSE(child
->render_surface());
1346 EXPECT_FALSE(grand_child
->render_surface());
1348 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1349 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1350 grand_child
->draw_transform());
1352 // The screen-space transform inherited by |child| and |grand_child| should
1353 // have been flattened at their render target. In particular, the fact that
1354 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1355 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y
,
1356 child
->screen_space_transform());
1357 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y
,
1358 grand_child
->screen_space_transform());
1361 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsRenderSurfaces
) {
1362 // The entire subtree of layers that are outside the clip rect should be
1363 // culled away, and should not affect the render_surface_layer_list.
1365 // The test tree is set up as follows:
1366 // - all layers except the leaf_nodes are forced to be a new render surface
1367 // that have something to draw.
1368 // - parent is a large container layer.
1369 // - child has masksToBounds=true to cause clipping.
1370 // - grand_child is positioned outside of the child's bounds
1371 // - great_grand_child is also kept outside child's bounds.
1373 // In this configuration, grand_child and great_grand_child are completely
1374 // outside the clip rect, and they should never get scheduled on the list of
1377 LayerImpl
* parent
= root_layer();
1378 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
1379 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
1380 LayerImpl
* great_grand_child
= AddChild
<LayerImpl
>(grand_child
);
1382 // leaf_node1 ensures that parent and child are kept on the
1383 // render_surface_layer_list, even though grand_child and great_grand_child
1384 // should be clipped.
1385 LayerImpl
* leaf_node1
= AddChild
<LayerImpl
>(child
);
1386 leaf_node1
->SetDrawsContent(true);
1387 LayerImpl
* leaf_node2
= AddChild
<LayerImpl
>(great_grand_child
);
1388 leaf_node2
->SetDrawsContent(true);
1390 const gfx::Transform identity_matrix
;
1392 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1393 gfx::PointF(), gfx::Size(500, 500), true, false,
1395 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1396 gfx::PointF(), gfx::Size(20, 20), true, false,
1398 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
1399 gfx::PointF(45.f
, 45.f
), gfx::Size(10, 10), true,
1401 SetLayerPropertiesForTesting(great_grand_child
, identity_matrix
,
1402 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1403 true, false, false);
1404 SetLayerPropertiesForTesting(leaf_node1
, identity_matrix
, gfx::Point3F(),
1405 gfx::PointF(), gfx::Size(500, 500), true, false,
1407 SetLayerPropertiesForTesting(leaf_node2
, identity_matrix
, gfx::Point3F(),
1408 gfx::PointF(), gfx::Size(20, 20), true, false,
1411 child
->SetMasksToBounds(true);
1412 child
->SetOpacity(0.4f
);
1413 grand_child
->SetOpacity(0.5f
);
1414 great_grand_child
->SetOpacity(0.4f
);
1416 ExecuteCalculateDrawProperties(parent
);
1418 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
1419 EXPECT_EQ(parent
->id(), render_surface_layer_list_impl()->at(0)->id());
1420 EXPECT_EQ(child
->id(), render_surface_layer_list_impl()->at(1)->id());
1423 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsSurfaceWithoutVisibleContent
) {
1424 // When a render surface has a clip rect, it is used to clip the content rect
1427 // The test tree is set up as follows:
1428 // - parent is a container layer that masksToBounds=true to cause clipping.
1429 // - child is a render surface, which has a clip rect set to the bounds of
1431 // - grand_child is a render surface, and the only visible content in child.
1432 // It is positioned outside of the clip rect from parent.
1434 // In this configuration, grand_child should be outside the clipped
1435 // content rect of the child, making grand_child not appear in the
1436 // render_surface_layer_list.
1438 LayerImpl
* parent
= root_layer();
1439 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
1440 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
1441 LayerImpl
* leaf_node
= AddChild
<LayerImpl
>(grand_child
);
1442 leaf_node
->SetDrawsContent(true);
1444 const gfx::Transform identity_matrix
;
1446 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1447 gfx::PointF(), gfx::Size(100, 100), true, false,
1449 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1450 gfx::PointF(), gfx::Size(20, 20), true, false,
1452 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
1453 gfx::PointF(200.f
, 200.f
), gfx::Size(10, 10),
1455 SetLayerPropertiesForTesting(leaf_node
, identity_matrix
, gfx::Point3F(),
1456 gfx::PointF(), gfx::Size(10, 10), true, false,
1459 parent
->SetMasksToBounds(true);
1460 child
->SetOpacity(0.4f
);
1461 grand_child
->SetOpacity(0.4f
);
1463 ExecuteCalculateDrawProperties(parent
);
1465 // We should cull child and grand_child from the
1466 // render_surface_layer_list.
1467 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
1468 EXPECT_EQ(parent
->id(), render_surface_layer_list_impl()->at(0)->id());
1471 TEST_F(LayerTreeHostCommonTest
, IsClippedIsSetCorrectly
) {
1472 // Layer's IsClipped() property is set to true when:
1473 // - the layer clips its subtree, e.g. masks to bounds,
1474 // - the layer is clipped by an ancestor that contributes to the same
1476 // - a surface is clipped by an ancestor that contributes to the same
1479 // In particular, for a layer that owns a render surface:
1480 // - the render surface inherits any clip from ancestors, and does NOT
1481 // pass that clipped status to the layer itself.
1482 // - but if the layer itself masks to bounds, it is considered clipped
1483 // and propagates the clip to the subtree.
1485 const gfx::Transform identity_matrix
;
1486 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1487 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1488 scoped_refptr
<Layer
> child1
= Layer::Create(layer_settings());
1489 scoped_refptr
<Layer
> child2
= Layer::Create(layer_settings());
1490 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
1491 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1492 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1493 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1494 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1495 root
->AddChild(parent
);
1496 parent
->AddChild(child1
);
1497 parent
->AddChild(child2
);
1498 child1
->AddChild(grand_child
);
1499 child2
->AddChild(leaf_node2
);
1500 grand_child
->AddChild(leaf_node1
);
1502 host()->SetRootLayer(root
);
1504 child2
->SetForceRenderSurface(true);
1506 SetLayerPropertiesForTesting(root
.get(),
1510 gfx::Size(100, 100),
1513 SetLayerPropertiesForTesting(parent
.get(),
1517 gfx::Size(100, 100),
1520 SetLayerPropertiesForTesting(child1
.get(),
1524 gfx::Size(100, 100),
1527 SetLayerPropertiesForTesting(child2
.get(),
1531 gfx::Size(100, 100),
1534 SetLayerPropertiesForTesting(grand_child
.get(),
1538 gfx::Size(100, 100),
1541 SetLayerPropertiesForTesting(leaf_node1
.get(),
1545 gfx::Size(100, 100),
1548 SetLayerPropertiesForTesting(leaf_node2
.get(),
1552 gfx::Size(100, 100),
1556 // Case 1: nothing is clipped except the root render surface.
1558 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(root
.get(),
1560 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1562 ASSERT_TRUE(root
->has_render_surface());
1563 ASSERT_TRUE(child2
->has_render_surface());
1565 EXPECT_FALSE(root
->is_clipped());
1566 EXPECT_FALSE(parent
->is_clipped());
1567 EXPECT_FALSE(child1
->is_clipped());
1568 EXPECT_FALSE(child2
->is_clipped());
1569 EXPECT_FALSE(grand_child
->is_clipped());
1570 EXPECT_FALSE(leaf_node1
->is_clipped());
1571 EXPECT_FALSE(leaf_node2
->is_clipped());
1574 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1575 // surface are clipped. But layers that contribute to child2's surface are
1576 // not clipped explicitly because child2's surface already accounts for
1579 parent
->SetMasksToBounds(true);
1580 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(root
.get(),
1582 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1584 ASSERT_TRUE(root
->has_render_surface());
1585 ASSERT_TRUE(child2
->has_render_surface());
1587 EXPECT_FALSE(root
->is_clipped());
1588 EXPECT_TRUE(parent
->is_clipped());
1589 EXPECT_TRUE(child1
->is_clipped());
1590 EXPECT_FALSE(child2
->is_clipped());
1591 EXPECT_TRUE(grand_child
->is_clipped());
1592 EXPECT_TRUE(leaf_node1
->is_clipped());
1593 EXPECT_FALSE(leaf_node2
->is_clipped());
1596 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1597 // child2's render surface is not clipped.
1599 parent
->SetMasksToBounds(false);
1600 child2
->SetMasksToBounds(true);
1601 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(root
.get(),
1603 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1605 ASSERT_TRUE(root
->has_render_surface());
1606 ASSERT_TRUE(child2
->has_render_surface());
1608 EXPECT_FALSE(root
->is_clipped());
1609 EXPECT_FALSE(parent
->is_clipped());
1610 EXPECT_FALSE(child1
->is_clipped());
1611 EXPECT_TRUE(child2
->is_clipped());
1612 EXPECT_FALSE(grand_child
->is_clipped());
1613 EXPECT_FALSE(leaf_node1
->is_clipped());
1614 EXPECT_TRUE(leaf_node2
->is_clipped());
1618 TEST_F(LayerTreeHostCommonTest
, IsClippedIsSetCorrectlyLayerImpl
) {
1619 // This is identical to the IsClippedIsSetCorrectly test,
1620 // but tests render surfaces instead of the layers.
1622 const gfx::Transform identity_matrix
;
1623 LayerImpl
* root
= root_layer();
1624 LayerImpl
* parent
= AddChild
<LayerImpl
>(root
);
1625 LayerImpl
* child1
= AddChild
<LayerImpl
>(parent
);
1626 LayerImpl
* child2
= AddChild
<LayerImpl
>(parent
);
1627 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child1
);
1628 LayerImpl
* leaf_node1
= AddChild
<LayerImpl
>(grand_child
);
1629 leaf_node1
->SetDrawsContent(true);
1630 LayerImpl
* leaf_node2
= AddChild
<LayerImpl
>(child2
);
1631 leaf_node2
->SetDrawsContent(true);
1633 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
1634 gfx::PointF(), gfx::Size(100, 100), true, false,
1636 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1637 gfx::PointF(), gfx::Size(100, 100), true, false,
1639 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
1640 gfx::PointF(), gfx::Size(100, 100), true, false,
1642 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
1643 gfx::PointF(), gfx::Size(100, 100), true, false,
1645 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
1646 gfx::PointF(), gfx::Size(100, 100), true, false,
1648 SetLayerPropertiesForTesting(leaf_node1
, identity_matrix
, gfx::Point3F(),
1649 gfx::PointF(), gfx::Size(100, 100), true, false,
1651 SetLayerPropertiesForTesting(leaf_node2
, identity_matrix
, gfx::Point3F(),
1652 gfx::PointF(), gfx::Size(100, 100), true, false,
1655 // Case 1: nothing is clipped except the root render surface.
1657 ExecuteCalculateDrawProperties(root
);
1659 ASSERT_TRUE(root
->render_surface());
1660 ASSERT_TRUE(child2
->render_surface());
1662 EXPECT_FALSE(root
->is_clipped());
1663 EXPECT_TRUE(root
->render_surface()->is_clipped());
1664 EXPECT_FALSE(parent
->is_clipped());
1665 EXPECT_FALSE(child1
->is_clipped());
1666 EXPECT_FALSE(child2
->is_clipped());
1667 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1668 EXPECT_FALSE(grand_child
->is_clipped());
1669 EXPECT_FALSE(leaf_node1
->is_clipped());
1670 EXPECT_FALSE(leaf_node2
->is_clipped());
1673 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1674 // surface are clipped. But layers that contribute to child2's surface are
1675 // not clipped explicitly because child2's surface already accounts for
1678 parent
->SetMasksToBounds(true);
1680 parent
->set_is_clipped(true);
1681 child1
->set_is_clipped(true);
1682 grand_child
->set_is_clipped(true);
1683 leaf_node1
->set_is_clipped(true);
1684 host_impl()->active_tree()->property_trees()->needs_rebuild
= true;
1686 ExecuteCalculateDrawProperties(root
);
1688 ASSERT_TRUE(root
->render_surface());
1689 ASSERT_TRUE(child2
->render_surface());
1691 EXPECT_TRUE(root
->render_surface()->is_clipped());
1692 EXPECT_TRUE(child2
->render_surface()->is_clipped());
1694 parent
->SetMasksToBounds(false);
1695 parent
->set_is_clipped(false);
1696 child1
->set_is_clipped(false);
1697 grand_child
->set_is_clipped(false);
1698 leaf_node1
->set_is_clipped(false);
1701 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1702 // child2's render surface is not clipped.
1704 child2
->SetMasksToBounds(true);
1705 child2
->set_is_clipped(true);
1706 leaf_node2
->set_is_clipped(true);
1707 host_impl()->active_tree()->property_trees()->needs_rebuild
= true;
1709 ExecuteCalculateDrawProperties(root
);
1711 ASSERT_TRUE(root
->render_surface());
1712 ASSERT_TRUE(child2
->render_surface());
1714 EXPECT_FALSE(root
->is_clipped());
1715 EXPECT_TRUE(root
->render_surface()->is_clipped());
1716 EXPECT_FALSE(parent
->is_clipped());
1717 EXPECT_FALSE(child1
->is_clipped());
1718 EXPECT_TRUE(child2
->is_clipped());
1719 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1720 EXPECT_FALSE(grand_child
->is_clipped());
1721 EXPECT_FALSE(leaf_node1
->is_clipped());
1722 EXPECT_TRUE(leaf_node2
->is_clipped());
1726 TEST_F(LayerTreeHostCommonTest
, DrawableContentRectForLayers
) {
1727 // Verify that layers get the appropriate DrawableContentRect when their
1728 // parent masksToBounds is true.
1730 // grand_child1 - completely inside the region; DrawableContentRect should
1731 // be the layer rect expressed in target space.
1732 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1733 // will be the intersection of layer bounds and the mask region.
1734 // grand_child3 - partially clipped and masksToBounds; the
1735 // DrawableContentRect will still be the intersection of layer bounds and
1737 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1740 const gfx::Transform identity_matrix
;
1741 LayerImpl
* parent
= root_layer();
1742 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
1743 LayerImpl
* grand_child1
= AddChild
<LayerImpl
>(child
);
1744 LayerImpl
* grand_child2
= AddChild
<LayerImpl
>(child
);
1745 LayerImpl
* grand_child3
= AddChild
<LayerImpl
>(child
);
1746 LayerImpl
* grand_child4
= AddChild
<LayerImpl
>(child
);
1748 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1749 gfx::PointF(), gfx::Size(500, 500), true, false,
1751 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1752 gfx::PointF(), gfx::Size(20, 20), true, false,
1754 SetLayerPropertiesForTesting(grand_child1
, identity_matrix
, gfx::Point3F(),
1755 gfx::PointF(5.f
, 5.f
), gfx::Size(10, 10), true,
1757 SetLayerPropertiesForTesting(grand_child2
, identity_matrix
, gfx::Point3F(),
1758 gfx::PointF(15.f
, 15.f
), gfx::Size(10, 10), true,
1760 SetLayerPropertiesForTesting(grand_child3
, identity_matrix
, gfx::Point3F(),
1761 gfx::PointF(15.f
, 15.f
), gfx::Size(10, 10), true,
1763 SetLayerPropertiesForTesting(grand_child4
, identity_matrix
, gfx::Point3F(),
1764 gfx::PointF(45.f
, 45.f
), gfx::Size(10, 10), true,
1767 child
->SetMasksToBounds(true);
1768 grand_child3
->SetMasksToBounds(true);
1770 // Force child to be a render surface.
1771 child
->SetOpacity(0.4f
);
1773 ExecuteCalculateDrawProperties(parent
);
1775 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1
->drawable_content_rect());
1776 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3
->drawable_content_rect());
1777 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3
->drawable_content_rect());
1778 EXPECT_TRUE(grand_child4
->drawable_content_rect().IsEmpty());
1781 TEST_F(LayerTreeHostCommonTest
, ClipRectIsPropagatedCorrectlyToSurfaces
) {
1782 // Verify that render surfaces (and their layers) get the appropriate
1783 // clip rects when their parent masksToBounds is true.
1785 // Layers that own render surfaces (at least for now) do not inherit any
1786 // clipping; instead the surface will enforce the clip for the entire subtree.
1787 // They may still have a clip rect of their own layer bounds, however, if
1788 // masksToBounds was true.
1789 LayerImpl
* parent
= root_layer();
1790 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
1791 LayerImpl
* grand_child1
= AddChild
<LayerImpl
>(child
);
1792 LayerImpl
* grand_child2
= AddChild
<LayerImpl
>(child
);
1793 LayerImpl
* grand_child3
= AddChild
<LayerImpl
>(child
);
1794 LayerImpl
* grand_child4
= AddChild
<LayerImpl
>(child
);
1795 // the leaf nodes ensure that these grand_children become render surfaces for
1797 LayerImpl
* leaf_node1
= AddChild
<LayerImpl
>(grand_child1
);
1798 leaf_node1
->SetDrawsContent(true);
1799 LayerImpl
* leaf_node2
= AddChild
<LayerImpl
>(grand_child2
);
1800 leaf_node2
->SetDrawsContent(true);
1801 LayerImpl
* leaf_node3
= AddChild
<LayerImpl
>(grand_child3
);
1802 leaf_node3
->SetDrawsContent(true);
1803 LayerImpl
* leaf_node4
= AddChild
<LayerImpl
>(grand_child4
);
1804 leaf_node4
->SetDrawsContent(true);
1806 const gfx::Transform identity_matrix
;
1808 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1809 gfx::PointF(), gfx::Size(500, 500), true, false,
1811 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1812 gfx::PointF(), gfx::Size(20, 20), true, false,
1814 SetLayerPropertiesForTesting(grand_child1
, identity_matrix
, gfx::Point3F(),
1815 gfx::PointF(5.f
, 5.f
), gfx::Size(10, 10), true,
1817 SetLayerPropertiesForTesting(grand_child2
, identity_matrix
, gfx::Point3F(),
1818 gfx::PointF(15.f
, 15.f
), gfx::Size(10, 10), true,
1820 SetLayerPropertiesForTesting(grand_child3
, identity_matrix
, gfx::Point3F(),
1821 gfx::PointF(15.f
, 15.f
), gfx::Size(10, 10), true,
1823 SetLayerPropertiesForTesting(grand_child4
, identity_matrix
, gfx::Point3F(),
1824 gfx::PointF(45.f
, 45.f
), gfx::Size(10, 10), true,
1826 SetLayerPropertiesForTesting(leaf_node1
, identity_matrix
, gfx::Point3F(),
1827 gfx::PointF(), gfx::Size(10, 10), true, false,
1829 SetLayerPropertiesForTesting(leaf_node2
, identity_matrix
, gfx::Point3F(),
1830 gfx::PointF(), gfx::Size(10, 10), true, false,
1832 SetLayerPropertiesForTesting(leaf_node3
, identity_matrix
, gfx::Point3F(),
1833 gfx::PointF(), gfx::Size(10, 10), true, false,
1835 SetLayerPropertiesForTesting(leaf_node4
, identity_matrix
, gfx::Point3F(),
1836 gfx::PointF(), gfx::Size(10, 10), true, false,
1839 child
->SetMasksToBounds(true);
1840 grand_child3
->SetMasksToBounds(true);
1841 grand_child4
->SetMasksToBounds(true);
1843 // Force everyone to be a render surface.
1844 child
->SetOpacity(0.4f
);
1845 grand_child1
->SetOpacity(0.5f
);
1846 grand_child2
->SetOpacity(0.5f
);
1847 grand_child3
->SetOpacity(0.5f
);
1848 grand_child4
->SetOpacity(0.5f
);
1850 ExecuteCalculateDrawProperties(parent
);
1852 ASSERT_TRUE(grand_child1
->render_surface());
1853 ASSERT_TRUE(grand_child2
->render_surface());
1854 ASSERT_TRUE(grand_child3
->render_surface());
1856 // Surfaces are clipped by their parent, but un-affected by the owning layer's
1858 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1859 grand_child1
->render_surface()->clip_rect());
1860 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1861 grand_child2
->render_surface()->clip_rect());
1862 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1863 grand_child3
->render_surface()->clip_rect());
1866 TEST_F(LayerTreeHostCommonTest
, AnimationsForRenderSurfaceHierarchy
) {
1867 LayerImpl
* parent
= root_layer();
1868 LayerImpl
* render_surface1
= AddChildToRoot
<LayerImpl
>();
1869 LayerImpl
* child_of_rs1
= AddChild
<LayerImpl
>(render_surface1
);
1870 LayerImpl
* grand_child_of_rs1
= AddChild
<LayerImpl
>(child_of_rs1
);
1871 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(render_surface1
);
1872 LayerImpl
* child_of_rs2
= AddChild
<LayerImpl
>(render_surface2
);
1873 LayerImpl
* grand_child_of_rs2
= AddChild
<LayerImpl
>(child_of_rs2
);
1874 LayerImpl
* child_of_root
= AddChildToRoot
<LayerImpl
>();
1875 LayerImpl
* grand_child_of_root
= AddChild
<LayerImpl
>(child_of_root
);
1877 grand_child_of_rs1
->SetDrawsContent(true);
1878 grand_child_of_rs2
->SetDrawsContent(true);
1880 gfx::Transform layer_transform
;
1881 layer_transform
.Translate(1.0, 1.0);
1883 SetLayerPropertiesForTesting(
1884 parent
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1885 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, true);
1886 SetLayerPropertiesForTesting(
1887 render_surface1
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1888 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, true);
1889 SetLayerPropertiesForTesting(
1890 render_surface2
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1891 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, true);
1892 SetLayerPropertiesForTesting(
1893 child_of_root
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1894 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1895 SetLayerPropertiesForTesting(
1896 child_of_rs1
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1897 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1898 SetLayerPropertiesForTesting(
1899 child_of_rs2
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1900 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1901 SetLayerPropertiesForTesting(
1902 grand_child_of_root
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1903 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1904 SetLayerPropertiesForTesting(
1905 grand_child_of_rs1
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1906 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1907 SetLayerPropertiesForTesting(
1908 grand_child_of_rs2
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1909 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1911 // Put an animated opacity on the render surface.
1912 AddOpacityTransitionToController(
1913 render_surface1
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
1915 // Also put an animated opacity on a layer without descendants.
1916 AddOpacityTransitionToController(
1917 grand_child_of_root
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
1919 // Put a transform animation on the render surface.
1920 AddAnimatedTransformToController(
1921 render_surface2
->layer_animation_controller(), 10.0, 30, 0);
1923 // Also put transform animations on grand_child_of_root, and
1924 // grand_child_of_rs2
1925 AddAnimatedTransformToController(
1926 grand_child_of_root
->layer_animation_controller(), 10.0, 30, 0);
1927 AddAnimatedTransformToController(
1928 grand_child_of_rs2
->layer_animation_controller(), 10.0, 30, 0);
1930 ExecuteCalculateDrawProperties(parent
);
1932 // Only layers that are associated with render surfaces should have an actual
1933 // RenderSurface() value.
1934 ASSERT_TRUE(parent
->render_surface());
1935 ASSERT_FALSE(child_of_root
->render_surface());
1936 ASSERT_FALSE(grand_child_of_root
->render_surface());
1938 ASSERT_TRUE(render_surface1
->render_surface());
1939 ASSERT_FALSE(child_of_rs1
->render_surface());
1940 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
1942 ASSERT_TRUE(render_surface2
->render_surface());
1943 ASSERT_FALSE(child_of_rs2
->render_surface());
1944 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
1946 // Verify all render target accessors
1947 EXPECT_EQ(parent
, parent
->render_target());
1948 EXPECT_EQ(parent
, child_of_root
->render_target());
1949 EXPECT_EQ(parent
, grand_child_of_root
->render_target());
1951 EXPECT_EQ(render_surface1
, render_surface1
->render_target());
1952 EXPECT_EQ(render_surface1
, child_of_rs1
->render_target());
1953 EXPECT_EQ(render_surface1
, grand_child_of_rs1
->render_target());
1955 EXPECT_EQ(render_surface2
, render_surface2
->render_target());
1956 EXPECT_EQ(render_surface2
, child_of_rs2
->render_target());
1957 EXPECT_EQ(render_surface2
, grand_child_of_rs2
->render_target());
1959 // Verify screen_space_transform_is_animating values
1960 EXPECT_FALSE(parent
->screen_space_transform_is_animating());
1961 EXPECT_FALSE(child_of_root
->screen_space_transform_is_animating());
1962 EXPECT_TRUE(grand_child_of_root
->screen_space_transform_is_animating());
1963 EXPECT_FALSE(render_surface1
->screen_space_transform_is_animating());
1964 EXPECT_FALSE(child_of_rs1
->screen_space_transform_is_animating());
1965 EXPECT_FALSE(grand_child_of_rs1
->screen_space_transform_is_animating());
1966 EXPECT_TRUE(render_surface2
->screen_space_transform_is_animating());
1967 EXPECT_TRUE(child_of_rs2
->screen_space_transform_is_animating());
1968 EXPECT_TRUE(grand_child_of_rs2
->screen_space_transform_is_animating());
1970 // Sanity check. If these fail there is probably a bug in the test itself.
1971 // It is expected that we correctly set up transforms so that the y-component
1972 // of the screen-space transform encodes the "depth" of the layer in the tree.
1973 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
1974 EXPECT_FLOAT_EQ(2.0,
1975 child_of_root
->screen_space_transform().matrix().get(1, 3));
1977 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
1979 EXPECT_FLOAT_EQ(2.0,
1980 render_surface1
->screen_space_transform().matrix().get(1, 3));
1981 EXPECT_FLOAT_EQ(3.0,
1982 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
1984 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
1986 EXPECT_FLOAT_EQ(3.0,
1987 render_surface2
->screen_space_transform().matrix().get(1, 3));
1988 EXPECT_FLOAT_EQ(4.0,
1989 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
1991 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
1994 TEST_F(LayerTreeHostCommonTest
,
1995 ScreenSpaceTransformIsAnimatingWithDelayedAnimation
) {
1996 LayerImpl
* parent
= root_layer();
1997 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
1998 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
1999 LayerImpl
* great_grand_child
= AddChild
<LayerImpl
>(grand_child
);
2001 parent
->SetDrawsContent(true);
2002 child
->SetDrawsContent(true);
2003 grand_child
->SetDrawsContent(true);
2004 great_grand_child
->SetDrawsContent(true);
2006 gfx::Transform identity
;
2008 SetLayerPropertiesForTesting(parent
, identity
, gfx::Point3F(), gfx::PointF(),
2009 gfx::Size(10, 10), true, false, true);
2010 SetLayerPropertiesForTesting(child
, identity
, gfx::Point3F(), gfx::PointF(),
2011 gfx::Size(10, 10), true, false, false);
2012 SetLayerPropertiesForTesting(grand_child
, identity
, gfx::Point3F(),
2013 gfx::PointF(), gfx::Size(10, 10), true, false,
2015 SetLayerPropertiesForTesting(great_grand_child
, identity
, gfx::Point3F(),
2016 gfx::PointF(), gfx::Size(10, 10), true, false,
2019 // Add a transform animation with a start delay to |grand_child|.
2020 scoped_ptr
<Animation
> animation
= Animation::Create(
2021 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1.0)).Pass(), 0, 1,
2022 Animation::TRANSFORM
);
2023 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
2024 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
2025 grand_child
->layer_animation_controller()->AddAnimation(animation
.Pass());
2027 ExecuteCalculateDrawProperties(parent
);
2029 EXPECT_FALSE(parent
->screen_space_transform_is_animating());
2030 EXPECT_FALSE(child
->screen_space_transform_is_animating());
2032 EXPECT_FALSE(grand_child
->TransformIsAnimating());
2033 EXPECT_TRUE(grand_child
->HasPotentiallyRunningTransformAnimation());
2034 EXPECT_TRUE(grand_child
->screen_space_transform_is_animating());
2035 EXPECT_TRUE(great_grand_child
->screen_space_transform_is_animating());
2038 TEST_F(LayerTreeHostCommonTest
, VisibleRectForIdentityTransform
) {
2039 // Test the calculateVisibleRect() function works correctly for identity
2042 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2043 gfx::Transform layer_to_surface_transform
;
2045 // Case 1: Layer is contained within the surface.
2046 gfx::Rect layer_content_rect
= gfx::Rect(10, 10, 30, 30);
2047 gfx::Rect expected
= gfx::Rect(10, 10, 30, 30);
2048 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2049 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2050 EXPECT_EQ(expected
, actual
);
2052 // Case 2: Layer is outside the surface rect.
2053 layer_content_rect
= gfx::Rect(120, 120, 30, 30);
2054 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2055 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2056 EXPECT_TRUE(actual
.IsEmpty());
2058 // Case 3: Layer is partially overlapping the surface rect.
2059 layer_content_rect
= gfx::Rect(80, 80, 30, 30);
2060 expected
= gfx::Rect(80, 80, 20, 20);
2061 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2062 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2063 EXPECT_EQ(expected
, actual
);
2066 TEST_F(LayerTreeHostCommonTest
, VisibleRectForTranslations
) {
2067 // Test the calculateVisibleRect() function works correctly for scaling
2070 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2071 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2072 gfx::Transform layer_to_surface_transform
;
2074 // Case 1: Layer is contained within the surface.
2075 layer_to_surface_transform
.MakeIdentity();
2076 layer_to_surface_transform
.Translate(10.0, 10.0);
2077 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2078 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2079 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2080 EXPECT_EQ(expected
, actual
);
2082 // Case 2: Layer is outside the surface rect.
2083 layer_to_surface_transform
.MakeIdentity();
2084 layer_to_surface_transform
.Translate(120.0, 120.0);
2085 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2086 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2087 EXPECT_TRUE(actual
.IsEmpty());
2089 // Case 3: Layer is partially overlapping the surface rect.
2090 layer_to_surface_transform
.MakeIdentity();
2091 layer_to_surface_transform
.Translate(80.0, 80.0);
2092 expected
= gfx::Rect(0, 0, 20, 20);
2093 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2094 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2095 EXPECT_EQ(expected
, actual
);
2098 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor2DRotations
) {
2099 // Test the calculateVisibleRect() function works correctly for rotations
2100 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2101 // should return the g in the layer's space.
2103 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2104 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2105 gfx::Transform layer_to_surface_transform
;
2107 // Case 1: Layer is contained within the surface.
2108 layer_to_surface_transform
.MakeIdentity();
2109 layer_to_surface_transform
.Translate(50.0, 50.0);
2110 layer_to_surface_transform
.Rotate(45.0);
2111 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2112 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2113 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2114 EXPECT_EQ(expected
, actual
);
2116 // Case 2: Layer is outside the surface rect.
2117 layer_to_surface_transform
.MakeIdentity();
2118 layer_to_surface_transform
.Translate(-50.0, 0.0);
2119 layer_to_surface_transform
.Rotate(45.0);
2120 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2121 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2122 EXPECT_TRUE(actual
.IsEmpty());
2124 // Case 3: The layer is rotated about its top-left corner. In surface space,
2125 // the layer is oriented diagonally, with the left half outside of the render
2126 // surface. In this case, the g should still be the entire layer
2127 // (remember the g is computed in layer space); both the top-left
2128 // and bottom-right corners of the layer are still visible.
2129 layer_to_surface_transform
.MakeIdentity();
2130 layer_to_surface_transform
.Rotate(45.0);
2131 expected
= gfx::Rect(0, 0, 30, 30);
2132 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2133 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2134 EXPECT_EQ(expected
, actual
);
2136 // Case 4: The layer is rotated about its top-left corner, and translated
2137 // upwards. In surface space, the layer is oriented diagonally, with only the
2138 // top corner of the surface overlapping the layer. In layer space, the render
2139 // surface overlaps the right side of the layer. The g should be
2140 // the layer's right half.
2141 layer_to_surface_transform
.MakeIdentity();
2142 layer_to_surface_transform
.Translate(0.0, -sqrt(2.0) * 15.0);
2143 layer_to_surface_transform
.Rotate(45.0);
2144 expected
= gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
2145 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2146 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2147 EXPECT_EQ(expected
, actual
);
2150 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dOrthographicTransform
) {
2151 // Test that the calculateVisibleRect() function works correctly for 3d
2154 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2155 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2156 gfx::Transform layer_to_surface_transform
;
2158 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2159 // degrees, should be fully contained in the render surface.
2160 layer_to_surface_transform
.MakeIdentity();
2161 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2162 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2163 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2164 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2165 EXPECT_EQ(expected
, actual
);
2167 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2168 // degrees, but shifted to the side so only the right-half the layer would be
2169 // visible on the surface.
2170 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2171 SkMScalar half_width_of_rotated_layer
=
2172 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
2173 layer_to_surface_transform
.MakeIdentity();
2174 layer_to_surface_transform
.Translate(-half_width_of_rotated_layer
, 0.0);
2175 layer_to_surface_transform
.RotateAboutYAxis(45.0); // Rotates about the left
2176 // edge of the layer.
2177 expected
= gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
2178 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2179 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2180 EXPECT_EQ(expected
, actual
);
2183 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveTransform
) {
2184 // Test the calculateVisibleRect() function works correctly when the layer has
2185 // a perspective projection onto the target surface.
2187 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2188 gfx::Rect layer_content_rect
= gfx::Rect(-50, -50, 200, 200);
2189 gfx::Transform layer_to_surface_transform
;
2191 // Case 1: Even though the layer is twice as large as the surface, due to
2192 // perspective foreshortening, the layer will fit fully in the surface when
2193 // its translated more than the perspective amount.
2194 layer_to_surface_transform
.MakeIdentity();
2196 // The following sequence of transforms applies the perspective about the
2197 // center of the surface.
2198 layer_to_surface_transform
.Translate(50.0, 50.0);
2199 layer_to_surface_transform
.ApplyPerspectiveDepth(9.0);
2200 layer_to_surface_transform
.Translate(-50.0, -50.0);
2202 // This translate places the layer in front of the surface's projection plane.
2203 layer_to_surface_transform
.Translate3d(0.0, 0.0, -27.0);
2205 gfx::Rect expected
= gfx::Rect(-50, -50, 200, 200);
2206 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2207 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2208 EXPECT_EQ(expected
, actual
);
2210 // Case 2: same projection as before, except that the layer is also translated
2211 // to the side, so that only the right half of the layer should be visible.
2213 // Explanation of expected result: The perspective ratio is (z distance
2214 // between layer and camera origin) / (z distance between projection plane and
2215 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2216 // move a layer by translating -50 units in projected surface units (so that
2217 // only half of it is visible), then we would need to translate by (-36 / 9) *
2218 // -50 == -200 in the layer's units.
2219 layer_to_surface_transform
.Translate3d(-200.0, 0.0, 0.0);
2220 expected
= gfx::Rect(gfx::Point(50, -50),
2221 gfx::Size(100, 200)); // The right half of the layer's
2223 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2224 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2225 EXPECT_EQ(expected
, actual
);
2228 TEST_F(LayerTreeHostCommonTest
,
2229 VisibleRectFor3dOrthographicIsNotClippedBehindSurface
) {
2230 // There is currently no explicit concept of an orthographic projection plane
2231 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2232 // are technically behind the surface in an orthographic world should not be
2233 // clipped when they are flattened to the surface.
2235 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2236 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2237 gfx::Transform layer_to_surface_transform
;
2239 // This sequence of transforms effectively rotates the layer about the y-axis
2240 // at the center of the layer.
2241 layer_to_surface_transform
.MakeIdentity();
2242 layer_to_surface_transform
.Translate(50.0, 0.0);
2243 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2244 layer_to_surface_transform
.Translate(-50.0, 0.0);
2246 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2247 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2248 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2249 EXPECT_EQ(expected
, actual
);
2252 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveWhenClippedByW
) {
2253 // Test the calculateVisibleRect() function works correctly when projecting a
2254 // surface onto a layer, but the layer is partially behind the camera (not
2255 // just behind the projection plane). In this case, the cartesian coordinates
2256 // may seem to be valid, but actually they are not. The visible rect needs to
2257 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2258 // converting to cartesian coordinates.
2260 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2261 gfx::Rect layer_content_rect
= gfx::Rect(-10, -1, 20, 2);
2262 gfx::Transform layer_to_surface_transform
;
2264 // The layer is positioned so that the right half of the layer should be in
2265 // front of the camera, while the other half is behind the surface's
2266 // projection plane. The following sequence of transforms applies the
2267 // perspective and rotation about the center of the layer.
2268 layer_to_surface_transform
.MakeIdentity();
2269 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2270 layer_to_surface_transform
.Translate3d(-2.0, 0.0, 1.0);
2271 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2273 // Sanity check that this transform does indeed cause w < 0 when applying the
2274 // transform, otherwise this code is not testing the intended scenario.
2276 MathUtil::MapQuad(layer_to_surface_transform
,
2277 gfx::QuadF(gfx::RectF(layer_content_rect
)),
2279 ASSERT_TRUE(clipped
);
2281 int expected_x_position
= 0;
2282 int expected_width
= 10;
2283 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2284 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2285 EXPECT_EQ(expected_x_position
, actual
.x());
2286 EXPECT_EQ(expected_width
, actual
.width());
2289 TEST_F(LayerTreeHostCommonTest
, VisibleRectForPerspectiveUnprojection
) {
2290 // To determine visible rect in layer space, there needs to be an
2291 // un-projection from surface space to layer space. When the original
2292 // transform was a perspective projection that was clipped, it returns a rect
2293 // that encloses the clipped bounds. Un-projecting this new rect may require
2296 // This sequence of transforms causes one corner of the layer to protrude
2297 // across the w = 0 plane, and should be clipped.
2298 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2299 gfx::Rect layer_content_rect
= gfx::Rect(-10, -10, 20, 20);
2300 gfx::Transform layer_to_surface_transform
;
2301 layer_to_surface_transform
.MakeIdentity();
2302 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2303 layer_to_surface_transform
.Translate3d(0.0, 0.0, -5.0);
2304 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2305 layer_to_surface_transform
.RotateAboutXAxis(80.0);
2307 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2308 // code is not testing the intended scenario.
2310 gfx::RectF clipped_rect
=
2311 MathUtil::MapClippedRect(layer_to_surface_transform
, layer_content_rect
);
2312 MathUtil::ProjectQuad(
2313 Inverse(layer_to_surface_transform
), gfx::QuadF(clipped_rect
), &clipped
);
2314 ASSERT_TRUE(clipped
);
2316 // Only the corner of the layer is not visible on the surface because of being
2317 // clipped. But, the net result of rounding visible region to an axis-aligned
2318 // rect is that the entire layer should still be considered visible.
2319 gfx::Rect expected
= gfx::Rect(-10, -10, 20, 20);
2320 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2321 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2322 EXPECT_EQ(expected
, actual
);
2325 TEST_F(LayerTreeHostCommonTest
,
2326 VisibleRectsForPositionedRootLayerClippedByViewport
) {
2327 LayerImpl
* root
= root_layer();
2328 root
->SetDrawsContent(true);
2330 gfx::Transform identity_matrix
;
2331 // Root layer is positioned at (60, 70). The default device viewport size
2332 // is (0, 0, 100x100) in target space. So the root layer's visible rect
2333 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space.
2334 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2335 gfx::PointF(60, 70), gfx::Size(100, 100), true,
2337 ExecuteCalculateDrawProperties(root
);
2339 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2340 root
->render_surface()->DrawableContentRect());
2341 // In target space, not clipped.
2342 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root
->drawable_content_rect());
2343 // In layer space, clipped.
2344 EXPECT_EQ(gfx::Rect(0, 0, 40, 30), root
->visible_layer_rect());
2347 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsForSimpleLayers
) {
2348 LayerImpl
* root
= root_layer();
2349 LayerImpl
* child1_layer
= AddChildToRoot
<LayerImpl
>();
2350 child1_layer
->SetDrawsContent(true);
2351 LayerImpl
* child2_layer
= AddChildToRoot
<LayerImpl
>();
2352 child2_layer
->SetDrawsContent(true);
2353 LayerImpl
* child3_layer
= AddChildToRoot
<LayerImpl
>();
2354 child3_layer
->SetDrawsContent(true);
2356 gfx::Transform identity_matrix
;
2357 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2358 gfx::PointF(), gfx::Size(100, 100), true, false,
2360 SetLayerPropertiesForTesting(child1_layer
, identity_matrix
, gfx::Point3F(),
2361 gfx::PointF(), gfx::Size(50, 50), true, false,
2363 SetLayerPropertiesForTesting(child2_layer
, identity_matrix
, gfx::Point3F(),
2364 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2366 SetLayerPropertiesForTesting(child3_layer
, identity_matrix
, gfx::Point3F(),
2367 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2368 true, false, false);
2370 ExecuteCalculateDrawProperties(root
);
2372 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2373 root
->render_surface()->DrawableContentRect());
2374 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2376 // Layers that do not draw content should have empty visible_layer_rects.
2377 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2379 // layer visible_layer_rects are clipped by their target surface.
2380 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer
->visible_layer_rect());
2381 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer
->visible_layer_rect());
2382 EXPECT_TRUE(child3_layer
->visible_layer_rect().IsEmpty());
2384 // layer drawable_content_rects are not clipped.
2385 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer
->drawable_content_rect());
2386 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer
->drawable_content_rect());
2387 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer
->drawable_content_rect());
2390 TEST_F(LayerTreeHostCommonTest
,
2391 DrawableAndVisibleContentRectsForLayersClippedByLayer
) {
2392 LayerImpl
* root
= root_layer();
2393 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
2394 LayerImpl
* grand_child1
= AddChild
<LayerImpl
>(child
);
2395 grand_child1
->SetDrawsContent(true);
2396 LayerImpl
* grand_child2
= AddChild
<LayerImpl
>(child
);
2397 grand_child2
->SetDrawsContent(true);
2398 LayerImpl
* grand_child3
= AddChild
<LayerImpl
>(child
);
2399 grand_child3
->SetDrawsContent(true);
2401 gfx::Transform identity_matrix
;
2402 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2403 gfx::PointF(), gfx::Size(100, 100), true, false,
2405 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
2406 gfx::PointF(), gfx::Size(100, 100), true, false,
2408 SetLayerPropertiesForTesting(grand_child1
, identity_matrix
, gfx::Point3F(),
2409 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2411 SetLayerPropertiesForTesting(grand_child2
, identity_matrix
, gfx::Point3F(),
2412 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2414 SetLayerPropertiesForTesting(grand_child3
, identity_matrix
, gfx::Point3F(),
2415 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2416 true, false, false);
2418 child
->SetMasksToBounds(true);
2419 ExecuteCalculateDrawProperties(root
);
2421 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2422 root
->render_surface()->DrawableContentRect());
2423 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2425 // Layers that do not draw content should have empty visible content rects.
2426 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2427 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child
->visible_layer_rect());
2429 // All grandchild visible content rects should be clipped by child.
2430 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1
->visible_layer_rect());
2431 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2
->visible_layer_rect());
2432 EXPECT_TRUE(grand_child3
->visible_layer_rect().IsEmpty());
2434 // All grandchild DrawableContentRects should also be clipped by child.
2435 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1
->drawable_content_rect());
2436 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2
->drawable_content_rect());
2437 EXPECT_TRUE(grand_child3
->drawable_content_rect().IsEmpty());
2440 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectWithClippingAndScaling
) {
2441 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2442 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
2443 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
2444 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2445 root
->AddChild(child
);
2446 child
->AddChild(grand_child
);
2448 host()->SetRootLayer(root
);
2450 gfx::Transform identity_matrix
;
2451 gfx::Transform child_scale_matrix
;
2452 child_scale_matrix
.Scale(0.25f
, 0.25f
);
2453 gfx::Transform grand_child_scale_matrix
;
2454 grand_child_scale_matrix
.Scale(0.246f
, 0.246f
);
2455 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2456 gfx::PointF(), gfx::Size(100, 100), true, false);
2457 SetLayerPropertiesForTesting(child
.get(), child_scale_matrix
, gfx::Point3F(),
2458 gfx::PointF(), gfx::Size(10, 10), true, false);
2459 SetLayerPropertiesForTesting(grand_child
.get(), grand_child_scale_matrix
,
2460 gfx::Point3F(), gfx::PointF(),
2461 gfx::Size(100, 100), true, false);
2463 child
->SetMasksToBounds(true);
2464 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
2466 // The visible rect is expanded to integer coordinates in target space before
2467 // being projected back to layer space, where it is once again expanded to
2468 // integer coordinates.
2469 EXPECT_EQ(gfx::Rect(49, 49), grand_child
->visible_rect_from_property_trees());
2472 TEST_F(LayerTreeHostCommonTest
,
2473 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface
) {
2474 LayerImpl
* root
= root_layer();
2475 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
2476 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
2477 child1
->SetDrawsContent(true);
2478 LayerImpl
* child2
= AddChild
<LayerImpl
>(render_surface
);
2479 child2
->SetDrawsContent(true);
2480 LayerImpl
* child3
= AddChild
<LayerImpl
>(render_surface
);
2481 child3
->SetDrawsContent(true);
2483 gfx::Transform identity_matrix
;
2484 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2485 gfx::PointF(), gfx::Size(100, 100), true, false,
2487 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
2488 gfx::PointF(), gfx::Size(3, 4), true, false,
2490 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
2491 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2493 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
2494 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2496 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
2497 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2498 true, false, false);
2500 ExecuteCalculateDrawProperties(root
);
2502 ASSERT_TRUE(render_surface
->render_surface());
2504 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2505 root
->render_surface()->DrawableContentRect());
2506 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2508 // Layers that do not draw content should have empty visible content rects.
2509 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2510 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface
->visible_layer_rect());
2512 // An unclipped surface grows its DrawableContentRect to include all drawable
2513 // regions of the subtree.
2514 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2515 render_surface
->render_surface()->DrawableContentRect());
2517 // All layers that draw content into the unclipped surface are also unclipped.
2518 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
2519 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_layer_rect());
2520 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_layer_rect());
2522 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2523 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2524 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2527 TEST_F(LayerTreeHostCommonTest
,
2528 VisibleContentRectsForClippedSurfaceWithEmptyClip
) {
2529 LayerImpl
* root
= root_layer();
2530 LayerImpl
* child1
= AddChild
<LayerImpl
>(root
);
2531 LayerImpl
* child2
= AddChild
<LayerImpl
>(root
);
2532 LayerImpl
* child3
= AddChild
<LayerImpl
>(root
);
2533 child1
->SetDrawsContent(true);
2534 child2
->SetDrawsContent(true);
2535 child3
->SetDrawsContent(true);
2537 gfx::Transform identity_matrix
;
2538 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2539 gfx::PointF(), gfx::Size(100, 100), true, false,
2541 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
2542 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2544 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
2545 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2547 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
2548 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2549 true, false, false);
2551 LayerImplList render_surface_layer_list_impl
;
2552 // Now set the root render surface an empty clip.
2553 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
2554 root
, gfx::Size(), &render_surface_layer_list_impl
);
2556 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
2557 ASSERT_TRUE(root
->render_surface());
2558 EXPECT_FALSE(root
->is_clipped());
2561 EXPECT_EQ(empty
, root
->render_surface()->clip_rect());
2562 EXPECT_TRUE(root
->render_surface()->is_clipped());
2564 // Visible content rect calculation will check if the target surface is
2565 // clipped or not. An empty clip rect does not indicate the render surface
2567 EXPECT_EQ(empty
, child1
->visible_layer_rect());
2568 EXPECT_EQ(empty
, child2
->visible_layer_rect());
2569 EXPECT_EQ(empty
, child3
->visible_layer_rect());
2572 TEST_F(LayerTreeHostCommonTest
,
2573 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform
) {
2574 LayerImpl
* root
= root_layer();
2575 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
2576 child
->SetDrawsContent(true);
2578 // Case 1: a truly degenerate matrix
2579 gfx::Transform identity_matrix
;
2580 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2581 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2583 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2584 gfx::PointF(), gfx::Size(100, 100), true, false,
2586 SetLayerPropertiesForTesting(child
, uninvertible_matrix
, gfx::Point3F(),
2587 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2590 ExecuteCalculateDrawProperties(root
);
2592 EXPECT_TRUE(child
->visible_layer_rect().IsEmpty());
2593 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2595 // Case 2: a matrix with flattened z, uninvertible and not visible according
2597 uninvertible_matrix
.MakeIdentity();
2598 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2599 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2601 SetLayerPropertiesForTesting(child
, uninvertible_matrix
, gfx::Point3F(),
2602 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2605 ExecuteCalculateDrawProperties(root
);
2607 EXPECT_TRUE(child
->visible_layer_rect().IsEmpty());
2608 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2610 // Case 3: a matrix with flattened z, also uninvertible and not visible.
2611 uninvertible_matrix
.MakeIdentity();
2612 uninvertible_matrix
.Translate(500.0, 0.0);
2613 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2614 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2616 SetLayerPropertiesForTesting(child
, uninvertible_matrix
, gfx::Point3F(),
2617 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2620 ExecuteCalculateDrawProperties(root
);
2622 EXPECT_TRUE(child
->visible_layer_rect().IsEmpty());
2623 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2626 TEST_F(LayerTreeHostCommonTest
,
2627 VisibleContentRectForLayerWithUninvertibleDrawTransform
) {
2628 LayerImpl
* root
= root_layer();
2629 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
2630 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
2631 child
->SetDrawsContent(true);
2632 grand_child
->SetDrawsContent(true);
2634 gfx::Transform identity_matrix
;
2636 gfx::Transform perspective
;
2637 perspective
.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
2639 gfx::Transform rotation
;
2640 rotation
.RotateAboutYAxis(45.0);
2642 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2643 gfx::PointF(), gfx::Size(100, 100), true, false,
2645 SetLayerPropertiesForTesting(child
, perspective
, gfx::Point3F(),
2646 gfx::PointF(10.f
, 10.f
), gfx::Size(100, 100),
2647 false, true, false);
2648 SetLayerPropertiesForTesting(grand_child
, rotation
, gfx::Point3F(),
2649 gfx::PointF(), gfx::Size(100, 100), false, true,
2652 ExecuteCalculateDrawProperties(root
);
2654 // Though all layers have invertible transforms, matrix multiplication using
2655 // floating-point math makes the draw transform uninvertible.
2656 EXPECT_FALSE(grand_child
->draw_transform().IsInvertible());
2658 // CalcDrawProps only skips a subtree when a layer's own transform is
2659 // uninvertible, not when its draw transform is invertible, since CDP makes
2660 // skipping decisions before computing a layer's draw transform. Property
2661 // trees make skipping decisions after computing draw transforms, so could be
2662 // made to skip layers with an uninvertible draw transform (once CDP is
2664 EXPECT_EQ(gfx::Rect(grand_child
->bounds()),
2665 grand_child
->visible_layer_rect());
2668 TEST_F(LayerTreeHostCommonTest
,
2669 OcclusionForLayerWithUninvertibleDrawTransform
) {
2670 FakeImplProxy proxy
;
2671 TestSharedBitmapManager shared_bitmap_manager
;
2672 TestTaskGraphRunner task_graph_runner
;
2673 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
2674 &task_graph_runner
);
2675 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
2676 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 2);
2677 scoped_ptr
<LayerImpl
> grand_child
=
2678 LayerImpl::Create(host_impl
.active_tree(), 3);
2679 scoped_ptr
<LayerImpl
> occluding_child
=
2680 LayerImpl::Create(host_impl
.active_tree(), 4);
2681 child
->SetDrawsContent(true);
2682 grand_child
->SetDrawsContent(true);
2683 occluding_child
->SetDrawsContent(true);
2684 occluding_child
->SetContentsOpaque(true);
2686 gfx::Transform identity_matrix
;
2687 gfx::Transform perspective
;
2688 perspective
.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
2690 gfx::Transform rotation
;
2691 rotation
.RotateAboutYAxis(45.0);
2693 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2694 gfx::PointF(), gfx::Size(1000, 1000), true,
2696 SetLayerPropertiesForTesting(child
.get(), perspective
, gfx::Point3F(),
2697 gfx::PointF(10.f
, 10.f
), gfx::Size(300, 300),
2698 false, true, false);
2699 SetLayerPropertiesForTesting(grand_child
.get(), rotation
, gfx::Point3F(),
2700 gfx::PointF(), gfx::Size(200, 200), false, true,
2702 SetLayerPropertiesForTesting(occluding_child
.get(), identity_matrix
,
2703 gfx::Point3F(), gfx::PointF(),
2704 gfx::Size(200, 200), false, false, false);
2706 host_impl
.SetViewportSize(root
->bounds());
2708 child
->AddChild(grand_child
.Pass());
2709 root
->AddChild(child
.Pass());
2710 root
->AddChild(occluding_child
.Pass());
2711 host_impl
.active_tree()->SetRootLayer(root
.Pass());
2712 host_impl
.InitializeRenderer(FakeOutputSurface::Create3d());
2713 bool update_lcd_text
= false;
2714 host_impl
.active_tree()->UpdateDrawProperties(update_lcd_text
);
2716 LayerImpl
* grand_child_ptr
=
2717 host_impl
.active_tree()->root_layer()->children()[0]->children()[0];
2719 // Though all layers have invertible transforms, matrix multiplication using
2720 // floating-point math makes the draw transform uninvertible.
2721 EXPECT_FALSE(grand_child_ptr
->draw_transform().IsInvertible());
2723 // Since |grand_child| has an uninvertible draw transform, it is treated as
2724 // unoccluded (even though |occluding_child| comes later in draw order, and
2725 // hence potentially occludes it).
2726 gfx::Rect layer_bounds
= gfx::Rect(grand_child_ptr
->bounds());
2729 grand_child_ptr
->draw_properties()
2730 .occlusion_in_content_space
.GetUnoccludedContentRect(layer_bounds
));
2733 TEST_F(LayerTreeHostCommonTest
,
2734 SingularTransformDoesNotPreventClearingDrawProperties
) {
2735 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2736 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2737 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2738 root
->AddChild(child
);
2740 host()->SetRootLayer(root
);
2742 gfx::Transform identity_matrix
;
2743 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2744 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2746 SetLayerPropertiesForTesting(root
.get(),
2747 uninvertible_matrix
,
2750 gfx::Size(100, 100),
2753 SetLayerPropertiesForTesting(child
.get(),
2756 gfx::PointF(5.f
, 5.f
),
2761 child
->set_sorted_for_recursion(true);
2763 TransformOperations start_transform_operations
;
2764 start_transform_operations
.AppendScale(1.f
, 0.f
, 0.f
);
2766 TransformOperations end_transform_operations
;
2767 end_transform_operations
.AppendScale(1.f
, 1.f
, 0.f
);
2769 AddAnimatedTransformToLayer(
2770 root
.get(), 10.0, start_transform_operations
, end_transform_operations
);
2772 EXPECT_TRUE(root
->TransformIsAnimating());
2774 ExecuteCalculateDrawProperties(root
.get());
2776 EXPECT_FALSE(child
->sorted_for_recursion());
2779 TEST_F(LayerTreeHostCommonTest
,
2780 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties
) {
2781 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2783 host()->SetRootLayer(root
);
2785 gfx::Transform identity_matrix
;
2786 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2787 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2789 SetLayerPropertiesForTesting(root
.get(),
2790 uninvertible_matrix
,
2793 gfx::Size(100, 100),
2797 root
->set_sorted_for_recursion(true);
2799 EXPECT_FALSE(root
->TransformIsAnimating());
2801 ExecuteCalculateDrawProperties(root
.get());
2803 EXPECT_FALSE(root
->sorted_for_recursion());
2806 TEST_F(LayerTreeHostCommonTest
,
2807 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface
) {
2808 LayerImpl
* root
= root_layer();
2809 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
2810 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
2811 child1
->SetDrawsContent(true);
2812 LayerImpl
* child2
= AddChild
<LayerImpl
>(render_surface
);
2813 child2
->SetDrawsContent(true);
2814 LayerImpl
* child3
= AddChild
<LayerImpl
>(render_surface
);
2815 child3
->SetDrawsContent(true);
2817 gfx::Transform identity_matrix
;
2818 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2819 gfx::PointF(), gfx::Size(100, 100), true, false,
2821 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
2822 gfx::PointF(), gfx::Size(3, 4), true, false,
2824 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
2825 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2827 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
2828 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2830 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
2831 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2832 true, false, false);
2834 root
->SetMasksToBounds(true);
2836 ExecuteCalculateDrawProperties(root
);
2838 ASSERT_TRUE(render_surface
->render_surface());
2840 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2841 root
->render_surface()->DrawableContentRect());
2842 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2844 // Layers that do not draw content should have empty visible content rects.
2845 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2846 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface
->visible_layer_rect());
2848 // A clipped surface grows its DrawableContentRect to include all drawable
2849 // regions of the subtree, but also gets clamped by the ancestor's clip.
2850 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
2851 render_surface
->render_surface()->DrawableContentRect());
2853 // All layers that draw content into the surface have their visible content
2854 // rect clipped by the surface clip rect.
2855 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
2856 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_layer_rect());
2857 EXPECT_TRUE(child3
->visible_layer_rect().IsEmpty());
2859 // But the DrawableContentRects are unclipped.
2860 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2861 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2862 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2865 TEST_F(LayerTreeHostCommonTest
,
2866 DrawableAndVisibleContentRectsForSurfaceHierarchy
) {
2867 // Check that clipping does not propagate down surfaces.
2868 LayerImpl
* root
= root_layer();
2869 LayerImpl
* render_surface1
= AddChildToRoot
<LayerImpl
>();
2870 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(render_surface1
);
2871 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface2
);
2872 child1
->SetDrawsContent(true);
2873 LayerImpl
* child2
= AddChild
<LayerImpl
>(render_surface2
);
2874 child2
->SetDrawsContent(true);
2875 LayerImpl
* child3
= AddChild
<LayerImpl
>(render_surface2
);
2876 child3
->SetDrawsContent(true);
2878 gfx::Transform identity_matrix
;
2879 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2880 gfx::PointF(), gfx::Size(100, 100), true, false,
2882 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
2883 gfx::PointF(), gfx::Size(3, 4), true, false,
2885 SetLayerPropertiesForTesting(render_surface2
, identity_matrix
, gfx::Point3F(),
2886 gfx::PointF(), gfx::Size(7, 13), true, false,
2888 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
2889 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2891 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
2892 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2894 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
2895 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2896 true, false, false);
2898 root
->SetMasksToBounds(true);
2900 ExecuteCalculateDrawProperties(root
);
2902 ASSERT_TRUE(render_surface1
->render_surface());
2903 ASSERT_TRUE(render_surface2
->render_surface());
2905 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2906 root
->render_surface()->DrawableContentRect());
2907 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2909 // Layers that do not draw content should have empty visible content rects.
2910 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2911 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_layer_rect());
2912 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2
->visible_layer_rect());
2914 // A clipped surface grows its DrawableContentRect to include all drawable
2915 // regions of the subtree, but also gets clamped by the ancestor's clip.
2916 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
2917 render_surface1
->render_surface()->DrawableContentRect());
2919 // render_surface1 lives in the "unclipped universe" of render_surface1, and
2920 // is only implicitly clipped by render_surface1's content rect. So,
2921 // render_surface2 grows to enclose all drawable content of its subtree.
2922 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2923 render_surface2
->render_surface()->DrawableContentRect());
2925 // All layers that draw content into render_surface2 think they are unclipped.
2926 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
2927 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_layer_rect());
2928 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_layer_rect());
2930 // DrawableContentRects are also unclipped.
2931 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2932 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2933 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2936 TEST_F(LayerTreeHostCommonTest
,
2937 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface
) {
2938 // Layers that have non-axis aligned bounds (due to transforms) have an
2939 // expanded, axis-aligned DrawableContentRect and visible content rect.
2940 LayerImpl
* root
= root_layer();
2941 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
2942 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
2943 child1
->SetDrawsContent(true);
2945 gfx::Transform identity_matrix
;
2946 gfx::Transform child_rotation
;
2947 child_rotation
.Rotate(45.0);
2948 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2949 gfx::PointF(), gfx::Size(100, 100), true, false,
2951 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
2952 gfx::PointF(), gfx::Size(3, 4), true, false,
2954 SetLayerPropertiesForTesting(
2955 child1
, child_rotation
, gfx::Point3F(25, 25, 0.f
),
2956 gfx::PointF(25.f
, 25.f
), gfx::Size(50, 50), true, false, false);
2958 ExecuteCalculateDrawProperties(root
);
2960 ASSERT_TRUE(render_surface
->render_surface());
2962 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2963 root
->render_surface()->DrawableContentRect());
2964 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2966 // Layers that do not draw content should have empty visible content rects.
2967 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2968 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface
->visible_layer_rect());
2970 // The unclipped surface grows its DrawableContentRect to include all drawable
2971 // regions of the subtree.
2972 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
2973 gfx::Rect expected_surface_drawable_content
=
2974 gfx::Rect(50 - diagonal_radius
,
2975 50 - diagonal_radius
,
2976 diagonal_radius
* 2,
2977 diagonal_radius
* 2);
2978 EXPECT_EQ(expected_surface_drawable_content
,
2979 render_surface
->render_surface()->DrawableContentRect());
2981 // All layers that draw content into the unclipped surface are also unclipped.
2982 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
2983 EXPECT_EQ(expected_surface_drawable_content
, child1
->drawable_content_rect());
2986 TEST_F(LayerTreeHostCommonTest
,
2987 DrawableAndVisibleContentRectsWithTransformOnClippedSurface
) {
2988 // Layers that have non-axis aligned bounds (due to transforms) have an
2989 // expanded, axis-aligned DrawableContentRect and visible content rect.
2990 LayerImpl
* root
= root_layer();
2991 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
2992 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
2993 child1
->SetDrawsContent(true);
2995 gfx::Transform identity_matrix
;
2996 gfx::Transform child_rotation
;
2997 child_rotation
.Rotate(45.0);
2998 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2999 gfx::PointF(), gfx::Size(50, 50), true, false,
3001 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
3002 gfx::PointF(), gfx::Size(3, 4), true, false,
3005 SetLayerPropertiesForTesting(
3006 child1
, child_rotation
, gfx::Point3F(25, 25, 0.f
),
3007 gfx::PointF(25.f
, 25.f
), gfx::Size(50, 50), true, false, false);
3009 root
->SetMasksToBounds(true);
3011 ExecuteCalculateDrawProperties(root
);
3013 ASSERT_TRUE(render_surface
->render_surface());
3015 // The clipped surface clamps the DrawableContentRect that encloses the
3017 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3018 gfx::Rect unclipped_surface_content
= gfx::Rect(50 - diagonal_radius
,
3019 50 - diagonal_radius
,
3020 diagonal_radius
* 2,
3021 diagonal_radius
* 2);
3022 gfx::Rect expected_surface_drawable_content
=
3023 gfx::IntersectRects(unclipped_surface_content
, gfx::Rect(0, 0, 50, 50));
3024 EXPECT_EQ(expected_surface_drawable_content
,
3025 render_surface
->render_surface()->DrawableContentRect());
3027 // On the clipped surface, only a quarter of the child1 is visible, but when
3028 // rotating it back to child1's content space, the actual enclosing rect ends
3029 // up covering the full left half of child1.
3031 // Given the floating point math, this number is a little bit fuzzy.
3032 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1
->visible_layer_rect());
3034 // The child's DrawableContentRect is unclipped.
3035 EXPECT_EQ(unclipped_surface_content
, child1
->drawable_content_rect());
3038 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsInHighDPI
) {
3039 LayerImpl
* root
= root_layer();
3040 FakePictureLayerImpl
* render_surface1
=
3041 AddChildToRoot
<FakePictureLayerImpl
>();
3042 render_surface1
->SetDrawsContent(true);
3043 FakePictureLayerImpl
* render_surface2
=
3044 AddChild
<FakePictureLayerImpl
>(render_surface1
);
3045 render_surface2
->SetDrawsContent(true);
3046 FakePictureLayerImpl
* child1
=
3047 AddChild
<FakePictureLayerImpl
>(render_surface2
);
3048 child1
->SetDrawsContent(true);
3049 FakePictureLayerImpl
* child2
=
3050 AddChild
<FakePictureLayerImpl
>(render_surface2
);
3051 child2
->SetDrawsContent(true);
3052 FakePictureLayerImpl
* child3
=
3053 AddChild
<FakePictureLayerImpl
>(render_surface2
);
3054 child3
->SetDrawsContent(true);
3056 gfx::Transform identity_matrix
;
3057 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
3058 gfx::PointF(), gfx::Size(100, 100), true, false,
3060 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
3061 gfx::PointF(5.f
, 5.f
), gfx::Size(3, 4), true,
3063 SetLayerPropertiesForTesting(render_surface2
, identity_matrix
, gfx::Point3F(),
3064 gfx::PointF(5.f
, 5.f
), gfx::Size(7, 13), true,
3066 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
3067 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
3069 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
3070 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
3072 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
3073 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
3074 true, false, false);
3076 float device_scale_factor
= 2.f
;
3078 root
->SetMasksToBounds(true);
3080 ExecuteCalculateDrawProperties(root
, device_scale_factor
);
3082 ASSERT_TRUE(render_surface1
->render_surface());
3083 ASSERT_TRUE(render_surface2
->render_surface());
3085 // drawable_content_rects for all layers and surfaces are scaled by
3086 // device_scale_factor.
3087 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
3088 root
->render_surface()->DrawableContentRect());
3089 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root
->drawable_content_rect());
3090 EXPECT_EQ(gfx::Rect(10, 10, 190, 190),
3091 render_surface1
->render_surface()->DrawableContentRect());
3093 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3094 // is only implicitly clipped by render_surface1.
3095 EXPECT_EQ(gfx::Rect(10, 10, 350, 350),
3096 render_surface2
->render_surface()->DrawableContentRect());
3098 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1
->drawable_content_rect());
3099 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2
->drawable_content_rect());
3100 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3
->drawable_content_rect());
3102 // The root layer does not actually draw content of its own.
3103 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
3105 // All layer visible content rects are not expressed in content space of each
3106 // layer, so they are not scaled by the device_scale_factor.
3107 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1
->visible_layer_rect());
3108 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2
->visible_layer_rect());
3109 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
3110 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_layer_rect());
3111 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_layer_rect());
3114 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithoutPreserves3d
) {
3115 // Verify the behavior of back-face culling when there are no preserve-3d
3116 // layers. Note that 3d transforms still apply in this case, but they are
3117 // "flattened" to each parent layer according to current W3C spec.
3119 const gfx::Transform identity_matrix
;
3120 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3121 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3122 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3123 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3124 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3125 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3126 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3127 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3128 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3129 scoped_refptr
<LayerWithForcedDrawsContent
>
3130 front_facing_child_of_front_facing_surface
=
3131 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3132 scoped_refptr
<LayerWithForcedDrawsContent
>
3133 back_facing_child_of_front_facing_surface
=
3134 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3135 scoped_refptr
<LayerWithForcedDrawsContent
>
3136 front_facing_child_of_back_facing_surface
=
3137 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3138 scoped_refptr
<LayerWithForcedDrawsContent
>
3139 back_facing_child_of_back_facing_surface
=
3140 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3142 parent
->AddChild(front_facing_child
);
3143 parent
->AddChild(back_facing_child
);
3144 parent
->AddChild(front_facing_surface
);
3145 parent
->AddChild(back_facing_surface
);
3146 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3147 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3148 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3149 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3151 host()->SetRootLayer(parent
);
3153 // Nothing is double-sided
3154 front_facing_child
->SetDoubleSided(false);
3155 back_facing_child
->SetDoubleSided(false);
3156 front_facing_surface
->SetDoubleSided(false);
3157 back_facing_surface
->SetDoubleSided(false);
3158 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3159 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3160 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3161 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3163 gfx::Transform backface_matrix
;
3164 backface_matrix
.Translate(50.0, 50.0);
3165 backface_matrix
.RotateAboutYAxis(180.0);
3166 backface_matrix
.Translate(-50.0, -50.0);
3168 // Having a descendant and opacity will force these to have render surfaces.
3169 front_facing_surface
->SetOpacity(0.5f
);
3170 back_facing_surface
->SetOpacity(0.5f
);
3172 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3173 // these layers should blindly use their own local transforms to determine
3174 // back-face culling.
3175 SetLayerPropertiesForTesting(parent
.get(),
3179 gfx::Size(100, 100),
3182 SetLayerPropertiesForTesting(front_facing_child
.get(),
3186 gfx::Size(100, 100),
3189 SetLayerPropertiesForTesting(back_facing_child
.get(),
3193 gfx::Size(100, 100),
3196 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3200 gfx::Size(100, 100),
3203 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3207 gfx::Size(100, 100),
3210 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3214 gfx::Size(100, 100),
3217 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3221 gfx::Size(100, 100),
3224 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3228 gfx::Size(100, 100),
3231 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3235 gfx::Size(100, 100),
3239 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3241 // Verify which render surfaces were created.
3242 EXPECT_FALSE(front_facing_child
->has_render_surface());
3243 EXPECT_FALSE(back_facing_child
->has_render_surface());
3244 EXPECT_TRUE(front_facing_surface
->has_render_surface());
3245 EXPECT_TRUE(back_facing_surface
->has_render_surface());
3247 front_facing_child_of_front_facing_surface
->has_render_surface());
3248 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->has_render_surface());
3249 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->has_render_surface());
3250 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->has_render_surface());
3252 EXPECT_EQ(4u, update_layer_list().size());
3253 EXPECT_TRUE(UpdateLayerListContains(front_facing_child
->id()));
3254 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface
->id()));
3255 EXPECT_TRUE(UpdateLayerListContains(
3256 front_facing_child_of_front_facing_surface
->id()));
3258 UpdateLayerListContains(front_facing_child_of_back_facing_surface
->id()));
3261 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithPreserves3d
) {
3262 // Verify the behavior of back-face culling when preserves-3d transform style
3265 const gfx::Transform identity_matrix
;
3266 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3267 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3268 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3269 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3270 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3271 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3272 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3273 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3274 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3275 scoped_refptr
<LayerWithForcedDrawsContent
>
3276 front_facing_child_of_front_facing_surface
=
3277 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3278 scoped_refptr
<LayerWithForcedDrawsContent
>
3279 back_facing_child_of_front_facing_surface
=
3280 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3281 scoped_refptr
<LayerWithForcedDrawsContent
>
3282 front_facing_child_of_back_facing_surface
=
3283 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3284 scoped_refptr
<LayerWithForcedDrawsContent
>
3285 back_facing_child_of_back_facing_surface
=
3286 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3287 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer1
=
3288 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3289 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer2
=
3290 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3292 parent
->AddChild(front_facing_child
);
3293 parent
->AddChild(back_facing_child
);
3294 parent
->AddChild(front_facing_surface
);
3295 parent
->AddChild(back_facing_surface
);
3296 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3297 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3298 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3299 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3301 host()->SetRootLayer(parent
);
3303 // Nothing is double-sided
3304 front_facing_child
->SetDoubleSided(false);
3305 back_facing_child
->SetDoubleSided(false);
3306 front_facing_surface
->SetDoubleSided(false);
3307 back_facing_surface
->SetDoubleSided(false);
3308 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3309 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3310 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3311 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3313 gfx::Transform backface_matrix
;
3314 backface_matrix
.Translate(50.0, 50.0);
3315 backface_matrix
.RotateAboutYAxis(180.0);
3316 backface_matrix
.Translate(-50.0, -50.0);
3318 // Opacity will not force creation of render surfaces in this case because of
3319 // the preserve-3d transform style. Instead, an example of when a surface
3320 // would be created with preserve-3d is when there is a replica layer.
3321 front_facing_surface
->SetReplicaLayer(dummy_replica_layer1
.get());
3322 back_facing_surface
->SetReplicaLayer(dummy_replica_layer2
.get());
3324 // Each surface creates its own new 3d rendering context (as defined by W3C
3325 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3326 // rendering context should use the transform with respect to that context.
3327 // This 3d rendering context occurs when (a) parent's transform style is flat
3328 // and (b) the layer's transform style is preserve-3d.
3329 SetLayerPropertiesForTesting(parent
.get(),
3333 gfx::Size(100, 100),
3335 false); // parent transform style is flat.
3336 SetLayerPropertiesForTesting(front_facing_child
.get(),
3340 gfx::Size(100, 100),
3343 SetLayerPropertiesForTesting(back_facing_child
.get(),
3347 gfx::Size(100, 100),
3350 // surface transform style is preserve-3d.
3351 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3355 gfx::Size(100, 100),
3358 // surface transform style is preserve-3d.
3359 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3363 gfx::Size(100, 100),
3366 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3370 gfx::Size(100, 100),
3373 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3377 gfx::Size(100, 100),
3380 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3384 gfx::Size(100, 100),
3387 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3391 gfx::Size(100, 100),
3395 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3397 // Verify which render surfaces were created and used.
3398 EXPECT_FALSE(front_facing_child
->has_render_surface());
3399 EXPECT_FALSE(back_facing_child
->has_render_surface());
3400 EXPECT_TRUE(front_facing_surface
->has_render_surface());
3401 EXPECT_NE(back_facing_surface
->render_target(), back_facing_surface
);
3402 // We expect that a has_render_surface was created but not used.
3403 EXPECT_TRUE(back_facing_surface
->has_render_surface());
3405 front_facing_child_of_front_facing_surface
->has_render_surface());
3406 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->has_render_surface());
3407 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->has_render_surface());
3408 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->has_render_surface());
3410 EXPECT_EQ(3u, update_layer_list().size());
3412 EXPECT_TRUE(UpdateLayerListContains(front_facing_child
->id()));
3413 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface
->id()));
3414 EXPECT_TRUE(UpdateLayerListContains(
3415 front_facing_child_of_front_facing_surface
->id()));
3418 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithAnimatingTransforms
) {
3419 // Verify that layers are appropriately culled when their back face is showing
3420 // and they are not double sided, while animations are going on.
3422 // Layers that are animating do not get culled on the main thread, as their
3423 // transforms should be treated as "unknown" so we can not be sure that their
3424 // back face is really showing.
3425 const gfx::Transform identity_matrix
;
3426 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3427 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
3428 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3429 scoped_refptr
<LayerWithForcedDrawsContent
> animating_surface
=
3430 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3431 scoped_refptr
<LayerWithForcedDrawsContent
> child_of_animating_surface
=
3432 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3433 scoped_refptr
<LayerWithForcedDrawsContent
> animating_child
=
3434 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3435 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3436 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3438 parent
->AddChild(child
);
3439 parent
->AddChild(animating_surface
);
3440 animating_surface
->AddChild(child_of_animating_surface
);
3441 parent
->AddChild(animating_child
);
3442 parent
->AddChild(child2
);
3444 host()->SetRootLayer(parent
);
3446 // Nothing is double-sided
3447 child
->SetDoubleSided(false);
3448 child2
->SetDoubleSided(false);
3449 animating_surface
->SetDoubleSided(false);
3450 child_of_animating_surface
->SetDoubleSided(false);
3451 animating_child
->SetDoubleSided(false);
3453 gfx::Transform backface_matrix
;
3454 backface_matrix
.Translate(50.0, 50.0);
3455 backface_matrix
.RotateAboutYAxis(180.0);
3456 backface_matrix
.Translate(-50.0, -50.0);
3458 // Make our render surface.
3459 animating_surface
->SetForceRenderSurface(true);
3461 // Animate the transform on the render surface.
3462 AddAnimatedTransformToController(
3463 animating_surface
->layer_animation_controller(), 10.0, 30, 0);
3464 // This is just an animating layer, not a surface.
3465 AddAnimatedTransformToController(
3466 animating_child
->layer_animation_controller(), 10.0, 30, 0);
3468 SetLayerPropertiesForTesting(parent
.get(),
3472 gfx::Size(100, 100),
3475 SetLayerPropertiesForTesting(child
.get(),
3479 gfx::Size(100, 100),
3482 SetLayerPropertiesForTesting(animating_surface
.get(),
3486 gfx::Size(100, 100),
3489 SetLayerPropertiesForTesting(child_of_animating_surface
.get(),
3493 gfx::Size(100, 100),
3496 SetLayerPropertiesForTesting(animating_child
.get(),
3500 gfx::Size(100, 100),
3503 SetLayerPropertiesForTesting(child2
.get(),
3507 gfx::Size(100, 100),
3511 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(parent
.get(),
3513 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3515 EXPECT_FALSE(child
->has_render_surface());
3516 EXPECT_TRUE(animating_surface
->has_render_surface());
3517 EXPECT_FALSE(child_of_animating_surface
->has_render_surface());
3518 EXPECT_FALSE(animating_child
->has_render_surface());
3519 EXPECT_FALSE(child2
->has_render_surface());
3521 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3523 EXPECT_EQ(4u, update_layer_list().size());
3525 // The non-animating child be culled from the layer list for the parent render
3527 EXPECT_TRUE(UpdateLayerListContains(animating_surface
->id()));
3528 EXPECT_TRUE(UpdateLayerListContains(animating_child
->id()));
3529 EXPECT_TRUE(UpdateLayerListContains(child2
->id()));
3530 EXPECT_TRUE(UpdateLayerListContains(child_of_animating_surface
->id()));
3532 EXPECT_FALSE(child2
->visible_rect_from_property_trees().IsEmpty());
3534 // The animating layers should have a visible content rect that represents the
3535 // area of the front face that is within the viewport.
3536 EXPECT_EQ(animating_child
->visible_rect_from_property_trees(),
3537 gfx::Rect(animating_child
->bounds()));
3538 EXPECT_EQ(animating_surface
->visible_rect_from_property_trees(),
3539 gfx::Rect(animating_surface
->bounds()));
3540 // And layers in the subtree of the animating layer should have valid visible
3541 // content rects also.
3542 EXPECT_EQ(child_of_animating_surface
->visible_rect_from_property_trees(),
3543 gfx::Rect(child_of_animating_surface
->bounds()));
3546 TEST_F(LayerTreeHostCommonTest
,
3547 BackFaceCullingWithPreserves3dForFlatteningSurface
) {
3548 // Verify the behavior of back-face culling for a render surface that is
3549 // created when it flattens its subtree, and its parent has preserves-3d.
3551 const gfx::Transform identity_matrix
;
3552 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3553 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3554 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3555 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3556 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3557 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3558 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3559 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3560 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3562 parent
->AddChild(front_facing_surface
);
3563 parent
->AddChild(back_facing_surface
);
3564 front_facing_surface
->AddChild(child1
);
3565 back_facing_surface
->AddChild(child2
);
3567 host()->SetRootLayer(parent
);
3569 // RenderSurfaces are not double-sided
3570 front_facing_surface
->SetDoubleSided(false);
3571 back_facing_surface
->SetDoubleSided(false);
3573 gfx::Transform backface_matrix
;
3574 backface_matrix
.Translate(50.0, 50.0);
3575 backface_matrix
.RotateAboutYAxis(180.0);
3576 backface_matrix
.Translate(-50.0, -50.0);
3578 SetLayerPropertiesForTesting(parent
.get(),
3582 gfx::Size(100, 100),
3584 true); // parent transform style is preserve3d.
3585 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3589 gfx::Size(100, 100),
3591 true); // surface transform style is flat.
3592 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3596 gfx::Size(100, 100),
3598 true); // surface transform style is flat.
3599 SetLayerPropertiesForTesting(child1
.get(),
3603 gfx::Size(100, 100),
3606 SetLayerPropertiesForTesting(child2
.get(),
3610 gfx::Size(100, 100),
3614 front_facing_surface
->Set3dSortingContextId(1);
3615 back_facing_surface
->Set3dSortingContextId(1);
3617 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3619 // Verify which render surfaces were created and used.
3620 EXPECT_TRUE(front_facing_surface
->has_render_surface());
3622 // We expect the render surface to have been created, but remain unused.
3623 EXPECT_TRUE(back_facing_surface
->has_render_surface());
3624 EXPECT_NE(back_facing_surface
->render_target(),
3625 back_facing_surface
); // because it should be culled
3626 EXPECT_FALSE(child1
->has_render_surface());
3627 EXPECT_FALSE(child2
->has_render_surface());
3629 EXPECT_EQ(2u, update_layer_list().size());
3630 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface
->id()));
3631 EXPECT_TRUE(UpdateLayerListContains(child1
->id()));
3634 TEST_F(LayerTreeHostCommonScalingTest
, LayerTransformsInHighDPI
) {
3635 // Verify draw and screen space transforms of layers not in a surface.
3636 gfx::Transform identity_matrix
;
3638 LayerImpl
* parent
= root_layer();
3639 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
3640 gfx::PointF(), gfx::Size(100, 100), false, true,
3643 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
3644 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
3645 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3648 LayerImpl
* child_empty
= AddChildToRoot
<LayerImpl
>();
3649 SetLayerPropertiesForTesting(child_empty
, identity_matrix
, gfx::Point3F(),
3650 gfx::PointF(2.f
, 2.f
), gfx::Size(), false, true,
3653 float device_scale_factor
= 2.5f
;
3654 gfx::Size
viewport_size(100, 100);
3655 ExecuteCalculateDrawProperties(parent
, device_scale_factor
);
3657 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
, parent
);
3658 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
, child
);
3659 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
, child_empty
);
3661 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
3663 // Verify parent transforms
3664 gfx::Transform expected_parent_transform
;
3665 expected_parent_transform
.Scale(device_scale_factor
, device_scale_factor
);
3666 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
3667 parent
->screen_space_transform());
3668 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
3669 parent
->draw_transform());
3671 // Verify results of transformed parent rects
3672 gfx::RectF
parent_bounds(parent
->bounds());
3674 gfx::RectF parent_draw_rect
=
3675 MathUtil::MapClippedRect(parent
->draw_transform(), parent_bounds
);
3676 gfx::RectF parent_screen_space_rect
=
3677 MathUtil::MapClippedRect(parent
->screen_space_transform(), parent_bounds
);
3679 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
3680 expected_parent_draw_rect
.Scale(device_scale_factor
);
3681 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
3682 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
3684 // Verify child and child_empty transforms. They should match.
3685 gfx::Transform expected_child_transform
;
3686 expected_child_transform
.Scale(device_scale_factor
, device_scale_factor
);
3687 expected_child_transform
.Translate(child
->position().x(),
3688 child
->position().y());
3689 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3690 child
->draw_transform());
3691 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3692 child
->screen_space_transform());
3693 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3694 child_empty
->draw_transform());
3695 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3696 child_empty
->screen_space_transform());
3698 // Verify results of transformed child and child_empty rects. They should
3700 gfx::RectF
child_bounds(child
->bounds());
3702 gfx::RectF child_draw_rect
=
3703 MathUtil::MapClippedRect(child
->draw_transform(), child_bounds
);
3704 gfx::RectF child_screen_space_rect
=
3705 MathUtil::MapClippedRect(child
->screen_space_transform(), child_bounds
);
3707 gfx::RectF child_empty_draw_rect
=
3708 MathUtil::MapClippedRect(child_empty
->draw_transform(), child_bounds
);
3709 gfx::RectF child_empty_screen_space_rect
= MathUtil::MapClippedRect(
3710 child_empty
->screen_space_transform(), child_bounds
);
3712 gfx::RectF
expected_child_draw_rect(child
->position(), child
->bounds());
3713 expected_child_draw_rect
.Scale(device_scale_factor
);
3714 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
3715 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
3716 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_draw_rect
);
3717 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_screen_space_rect
);
3720 TEST_F(LayerTreeHostCommonScalingTest
, SurfaceLayerTransformsInHighDPI
) {
3721 // Verify draw and screen space transforms of layers in a surface.
3722 gfx::Transform identity_matrix
;
3723 gfx::Transform perspective_matrix
;
3724 perspective_matrix
.ApplyPerspectiveDepth(2.0);
3726 gfx::Transform scale_small_matrix
;
3727 scale_small_matrix
.Scale(SK_MScalar1
/ 10.f
, SK_MScalar1
/ 12.f
);
3729 LayerImpl
* root
= root_layer();
3730 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
3731 gfx::PointF(), gfx::Size(100, 100), false, true,
3733 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
3734 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
3735 gfx::PointF(), gfx::Size(100, 100), false, true,
3738 LayerImpl
* perspective_surface
= AddChild
<LayerImpl
>(parent
);
3739 SetLayerPropertiesForTesting(perspective_surface
,
3740 perspective_matrix
* scale_small_matrix
,
3741 gfx::Point3F(), gfx::PointF(2.f
, 2.f
),
3742 gfx::Size(10, 10), false, true, true);
3743 perspective_surface
->SetDrawsContent(true);
3745 LayerImpl
* scale_surface
= AddChild
<LayerImpl
>(parent
);
3746 SetLayerPropertiesForTesting(scale_surface
, scale_small_matrix
,
3747 gfx::Point3F(), gfx::PointF(2.f
, 2.f
),
3748 gfx::Size(10, 10), false, true, true);
3749 scale_surface
->SetDrawsContent(true);
3751 float device_scale_factor
= 2.5f
;
3752 float page_scale_factor
= 3.f
;
3753 ExecuteCalculateDrawProperties(root
, device_scale_factor
, page_scale_factor
,
3756 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
3757 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
,
3758 perspective_surface
);
3759 // Ideal scale is the max 2d scale component of the combined transform up to
3760 // the nearest render target. Here this includes the layer transform as well
3761 // as the device and page scale factors.
3762 gfx::Transform transform
= scale_small_matrix
;
3763 transform
.Scale(device_scale_factor
* page_scale_factor
,
3764 device_scale_factor
* page_scale_factor
);
3765 gfx::Vector2dF scales
=
3766 MathUtil::ComputeTransform2dScaleComponents(transform
, 0.f
);
3767 float max_2d_scale
= std::max(scales
.x(), scales
.y());
3768 EXPECT_IDEAL_SCALE_EQ(max_2d_scale
, scale_surface
);
3770 // The ideal scale will draw 1:1 with its render target space along
3771 // the larger-scale axis.
3772 gfx::Vector2dF target_space_transform_scales
=
3773 MathUtil::ComputeTransform2dScaleComponents(
3774 scale_surface
->draw_properties().target_space_transform
, 0.f
);
3775 EXPECT_FLOAT_EQ(max_2d_scale
,
3776 std::max(target_space_transform_scales
.x(),
3777 target_space_transform_scales
.y()));
3779 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
3781 gfx::Transform expected_parent_draw_transform
;
3782 expected_parent_draw_transform
.Scale(device_scale_factor
* page_scale_factor
,
3783 device_scale_factor
* page_scale_factor
);
3784 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform
,
3785 parent
->draw_transform());
3787 // The scale for the perspective surface is not known, so it is rendered 1:1
3788 // with the screen, and then scaled during drawing.
3789 gfx::Transform expected_perspective_surface_draw_transform
;
3790 expected_perspective_surface_draw_transform
.Translate(
3791 device_scale_factor
* page_scale_factor
*
3792 perspective_surface
->position().x(),
3793 device_scale_factor
* page_scale_factor
*
3794 perspective_surface
->position().y());
3795 expected_perspective_surface_draw_transform
.PreconcatTransform(
3796 perspective_matrix
);
3797 expected_perspective_surface_draw_transform
.PreconcatTransform(
3798 scale_small_matrix
);
3799 gfx::Transform expected_perspective_surface_layer_draw_transform
;
3800 expected_perspective_surface_layer_draw_transform
.Scale(
3801 device_scale_factor
* page_scale_factor
,
3802 device_scale_factor
* page_scale_factor
);
3803 EXPECT_TRANSFORMATION_MATRIX_EQ(
3804 expected_perspective_surface_draw_transform
,
3805 perspective_surface
->render_surface()->draw_transform());
3806 EXPECT_TRANSFORMATION_MATRIX_EQ(
3807 expected_perspective_surface_layer_draw_transform
,
3808 perspective_surface
->draw_transform());
3811 TEST_F(LayerTreeHostCommonScalingTest
, SmallIdealScale
) {
3812 gfx::Transform parent_scale_matrix
;
3813 SkMScalar initial_parent_scale
= 1.75;
3814 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
3816 gfx::Transform child_scale_matrix
;
3817 SkMScalar initial_child_scale
= 0.25;
3818 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
3820 LayerImpl
* root
= root_layer();
3821 root
->SetBounds(gfx::Size(100, 100));
3823 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
3824 SetLayerPropertiesForTesting(parent
, parent_scale_matrix
, gfx::Point3F(),
3825 gfx::PointF(), gfx::Size(100, 100), false, true,
3828 LayerImpl
* child_scale
= AddChild
<LayerImpl
>(parent
);
3829 SetLayerPropertiesForTesting(child_scale
, child_scale_matrix
, gfx::Point3F(),
3830 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3833 float device_scale_factor
= 2.5f
;
3834 float page_scale_factor
= 0.01f
;
3837 ExecuteCalculateDrawProperties(root
, device_scale_factor
, page_scale_factor
,
3840 // The ideal scale is able to go below 1.
3841 float expected_ideal_scale
=
3842 device_scale_factor
* page_scale_factor
* initial_parent_scale
;
3843 EXPECT_LT(expected_ideal_scale
, 1.f
);
3844 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, parent
);
3846 expected_ideal_scale
= device_scale_factor
* page_scale_factor
*
3847 initial_parent_scale
* initial_child_scale
;
3848 EXPECT_LT(expected_ideal_scale
, 1.f
);
3849 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, child_scale
);
3853 TEST_F(LayerTreeHostCommonScalingTest
, IdealScaleForAnimatingLayer
) {
3854 gfx::Transform parent_scale_matrix
;
3855 SkMScalar initial_parent_scale
= 1.75;
3856 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
3858 gfx::Transform child_scale_matrix
;
3859 SkMScalar initial_child_scale
= 1.25;
3860 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
3862 LayerImpl
* root
= root_layer();
3863 root
->SetBounds(gfx::Size(100, 100));
3865 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
3866 SetLayerPropertiesForTesting(parent
, parent_scale_matrix
, gfx::Point3F(),
3867 gfx::PointF(), gfx::Size(100, 100), false, true,
3870 LayerImpl
* child_scale
= AddChild
<LayerImpl
>(parent
);
3871 SetLayerPropertiesForTesting(child_scale
, child_scale_matrix
, gfx::Point3F(),
3872 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3876 ExecuteCalculateDrawProperties(root
);
3878 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale
, parent
);
3879 // Animating layers compute ideal scale in the same way as when
3881 EXPECT_IDEAL_SCALE_EQ(initial_child_scale
* initial_parent_scale
,
3886 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceTransformsInHighDPI
) {
3887 gfx::Transform identity_matrix
;
3889 LayerImpl
* parent
= root_layer();
3890 parent
->SetDrawsContent(true);
3891 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
3892 gfx::PointF(), gfx::Size(30, 30), false, true,
3895 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
3896 child
->SetDrawsContent(true);
3897 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
3898 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3901 gfx::Transform replica_transform
;
3902 replica_transform
.Scale(1.0, -1.0);
3904 scoped_ptr
<LayerImpl
> replica
=
3905 LayerImpl::Create(host_impl()->active_tree(), 7);
3906 SetLayerPropertiesForTesting(replica
.get(), replica_transform
, gfx::Point3F(),
3907 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3909 child
->SetReplicaLayer(replica
.Pass());
3911 // This layer should end up in the same surface as child, with the same draw
3912 // and screen space transforms.
3913 LayerImpl
* duplicate_child_non_owner
= AddChild
<LayerImpl
>(child
);
3914 duplicate_child_non_owner
->SetDrawsContent(true);
3915 SetLayerPropertiesForTesting(duplicate_child_non_owner
, identity_matrix
,
3916 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
3917 false, true, false);
3919 float device_scale_factor
= 1.5f
;
3920 ExecuteCalculateDrawProperties(parent
, device_scale_factor
);
3922 // We should have two render surfaces. The root's render surface and child's
3923 // render surface (it needs one because it has a replica layer).
3924 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
3926 gfx::Transform expected_parent_transform
;
3927 expected_parent_transform
.Scale(device_scale_factor
, device_scale_factor
);
3928 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
3929 parent
->screen_space_transform());
3930 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
3931 parent
->draw_transform());
3933 gfx::Transform expected_draw_transform
;
3934 expected_draw_transform
.Scale(device_scale_factor
, device_scale_factor
);
3935 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform
,
3936 child
->draw_transform());
3938 gfx::Transform expected_screen_space_transform
;
3939 expected_screen_space_transform
.Scale(device_scale_factor
,
3940 device_scale_factor
);
3941 expected_screen_space_transform
.Translate(child
->position().x(),
3942 child
->position().y());
3943 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform
,
3944 child
->screen_space_transform());
3946 gfx::Transform expected_duplicate_child_draw_transform
=
3947 child
->draw_transform();
3948 EXPECT_TRANSFORMATION_MATRIX_EQ(child
->draw_transform(),
3949 duplicate_child_non_owner
->draw_transform());
3950 EXPECT_TRANSFORMATION_MATRIX_EQ(
3951 child
->screen_space_transform(),
3952 duplicate_child_non_owner
->screen_space_transform());
3953 EXPECT_EQ(child
->drawable_content_rect(),
3954 duplicate_child_non_owner
->drawable_content_rect());
3955 EXPECT_EQ(child
->bounds(), duplicate_child_non_owner
->bounds());
3957 gfx::Transform expected_render_surface_draw_transform
;
3958 expected_render_surface_draw_transform
.Translate(
3959 device_scale_factor
* child
->position().x(),
3960 device_scale_factor
* child
->position().y());
3961 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform
,
3962 child
->render_surface()->draw_transform());
3964 gfx::Transform expected_surface_draw_transform
;
3965 expected_surface_draw_transform
.Translate(device_scale_factor
* 2.f
,
3966 device_scale_factor
* 2.f
);
3967 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform
,
3968 child
->render_surface()->draw_transform());
3970 gfx::Transform expected_surface_screen_space_transform
;
3971 expected_surface_screen_space_transform
.Translate(device_scale_factor
* 2.f
,
3972 device_scale_factor
* 2.f
);
3973 EXPECT_TRANSFORMATION_MATRIX_EQ(
3974 expected_surface_screen_space_transform
,
3975 child
->render_surface()->screen_space_transform());
3977 gfx::Transform expected_replica_draw_transform
;
3978 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
3979 expected_replica_draw_transform
.matrix().set(0, 3, 6.0);
3980 expected_replica_draw_transform
.matrix().set(1, 3, 6.0);
3981 EXPECT_TRANSFORMATION_MATRIX_EQ(
3982 expected_replica_draw_transform
,
3983 child
->render_surface()->replica_draw_transform());
3985 gfx::Transform expected_replica_screen_space_transform
;
3986 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
3987 expected_replica_screen_space_transform
.matrix().set(0, 3, 6.0);
3988 expected_replica_screen_space_transform
.matrix().set(1, 3, 6.0);
3989 EXPECT_TRANSFORMATION_MATRIX_EQ(
3990 expected_replica_screen_space_transform
,
3991 child
->render_surface()->replica_screen_space_transform());
3992 EXPECT_TRANSFORMATION_MATRIX_EQ(
3993 expected_replica_screen_space_transform
,
3994 child
->render_surface()->replica_screen_space_transform());
3997 TEST_F(LayerTreeHostCommonTest
,
3998 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition
) {
3999 gfx::Transform identity_matrix
;
4001 LayerImpl
* parent
= root_layer();
4002 parent
->SetDrawsContent(true);
4003 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
4004 gfx::PointF(), gfx::Size(33, 31), false, true,
4007 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
4008 child
->SetDrawsContent(true);
4009 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
4010 gfx::PointF(), gfx::Size(13, 11), false, true,
4013 gfx::Transform replica_transform
;
4014 replica_transform
.Scale(1.0, -1.0);
4015 scoped_ptr
<LayerImpl
> replica
=
4016 LayerImpl::Create(host_impl()->active_tree(), 7);
4017 SetLayerPropertiesForTesting(replica
.get(), replica_transform
, gfx::Point3F(),
4018 gfx::PointF(), gfx::Size(13, 11), false, true,
4020 child
->SetReplicaLayer(replica
.Pass());
4022 float device_scale_factor
= 1.7f
;
4023 ExecuteCalculateDrawProperties(parent
, device_scale_factor
);
4025 // We should have two render surfaces. The root's render surface and child's
4026 // render surface (it needs one because it has a replica layer).
4027 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
4029 gfx::Transform identity_transform
;
4030 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
4031 child
->render_surface()->draw_transform());
4032 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
4033 child
->render_surface()->draw_transform());
4034 EXPECT_TRANSFORMATION_MATRIX_EQ(
4035 identity_transform
, child
->render_surface()->screen_space_transform());
4037 gfx::Transform expected_replica_draw_transform
;
4038 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
4039 EXPECT_TRANSFORMATION_MATRIX_EQ(
4040 expected_replica_draw_transform
,
4041 child
->render_surface()->replica_draw_transform());
4043 gfx::Transform expected_replica_screen_space_transform
;
4044 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
4045 EXPECT_TRANSFORMATION_MATRIX_EQ(
4046 expected_replica_screen_space_transform
,
4047 child
->render_surface()->replica_screen_space_transform());
4050 TEST_F(LayerTreeHostCommonTest
, SubtreeSearch
) {
4051 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4052 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
4053 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
4054 scoped_refptr
<Layer
> mask_layer
= Layer::Create(layer_settings());
4055 scoped_refptr
<Layer
> replica_layer
= Layer::Create(layer_settings());
4057 grand_child
->SetReplicaLayer(replica_layer
.get());
4058 child
->AddChild(grand_child
.get());
4059 child
->SetMaskLayer(mask_layer
.get());
4060 root
->AddChild(child
.get());
4062 host()->SetRootLayer(root
);
4064 int nonexistent_id
= -1;
4065 EXPECT_EQ(root
.get(),
4066 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), root
->id()));
4067 EXPECT_EQ(child
.get(),
4068 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), child
->id()));
4071 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), grand_child
->id()));
4074 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), mask_layer
->id()));
4076 replica_layer
.get(),
4077 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), replica_layer
->id()));
4079 0, LayerTreeHostCommon::FindLayerInSubtree(root
.get(), nonexistent_id
));
4082 TEST_F(LayerTreeHostCommonTest
, TransparentChildRenderSurfaceCreation
) {
4083 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4084 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
4085 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
4086 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4088 const gfx::Transform identity_matrix
;
4089 SetLayerPropertiesForTesting(root
.get(),
4093 gfx::Size(100, 100),
4096 SetLayerPropertiesForTesting(child
.get(),
4103 SetLayerPropertiesForTesting(grand_child
.get(),
4111 root
->AddChild(child
);
4112 child
->AddChild(grand_child
);
4113 child
->SetOpacity(0.5f
);
4115 host()->SetRootLayer(root
);
4117 ExecuteCalculateDrawProperties(root
.get());
4119 EXPECT_FALSE(child
->has_render_surface());
4122 TEST_F(LayerTreeHostCommonTest
, OpacityAnimatingOnPendingTree
) {
4123 FakeImplProxy proxy
;
4124 TestSharedBitmapManager shared_bitmap_manager
;
4125 TestTaskGraphRunner task_graph_runner
;
4126 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4127 &task_graph_runner
);
4128 host_impl
.CreatePendingTree();
4129 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4131 const gfx::Transform identity_matrix
;
4132 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4133 gfx::PointF(), gfx::Size(100, 100), true, false,
4135 root
->SetDrawsContent(true);
4137 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
4138 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
4139 gfx::PointF(), gfx::Size(50, 50), true, false,
4141 child
->SetDrawsContent(true);
4142 child
->SetOpacity(0.0f
);
4144 // Add opacity animation.
4145 AddOpacityTransitionToController(
4146 child
->layer_animation_controller(), 10.0, 0.0f
, 1.0f
, false);
4148 root
->AddChild(child
.Pass());
4149 root
->SetHasRenderSurface(true);
4151 LayerImplList render_surface_layer_list
;
4152 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4153 root
.get(), root
->bounds(), &render_surface_layer_list
);
4154 inputs
.can_adjust_raster_scales
= true;
4155 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4157 // We should have one render surface and two layers. The child
4158 // layer should be included even though it is transparent.
4159 ASSERT_EQ(1u, render_surface_layer_list
.size());
4160 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
4163 using LCDTextTestParam
= std::tr1::tuple
<bool, bool, bool>;
4164 class LCDTextTest
: public LayerTreeHostCommonTestBase
,
4165 public testing::TestWithParam
<LCDTextTestParam
> {
4168 : LayerTreeHostCommonTestBase(LayerTreeSettings()),
4169 host_impl_(&proxy_
, &shared_bitmap_manager_
, &task_graph_runner_
),
4172 grand_child_(nullptr) {}
4175 void SetUp() override
{
4176 can_use_lcd_text_
= std::tr1::get
<0>(GetParam());
4177 layers_always_allowed_lcd_text_
= std::tr1::get
<1>(GetParam());
4179 scoped_ptr
<LayerImpl
> root_ptr
=
4180 LayerImpl::Create(host_impl_
.active_tree(), 1);
4181 scoped_ptr
<LayerImpl
> child_ptr
=
4182 LayerImpl::Create(host_impl_
.active_tree(), 2);
4183 scoped_ptr
<LayerImpl
> grand_child_ptr
=
4184 LayerImpl::Create(host_impl_
.active_tree(), 3);
4186 // Stash raw pointers to look at later.
4187 root_
= root_ptr
.get();
4188 child_
= child_ptr
.get();
4189 grand_child_
= grand_child_ptr
.get();
4191 child_
->AddChild(grand_child_ptr
.Pass());
4192 root_
->AddChild(child_ptr
.Pass());
4193 host_impl_
.active_tree()->SetRootLayer(root_ptr
.Pass());
4195 root_
->SetContentsOpaque(true);
4196 child_
->SetContentsOpaque(true);
4197 grand_child_
->SetContentsOpaque(true);
4199 root_
->SetDrawsContent(true);
4200 child_
->SetDrawsContent(true);
4201 grand_child_
->SetDrawsContent(true);
4203 gfx::Transform identity_matrix
;
4204 SetLayerPropertiesForTesting(root_
, identity_matrix
, gfx::Point3F(),
4205 gfx::PointF(), gfx::Size(1, 1), true, false,
4207 SetLayerPropertiesForTesting(child_
, identity_matrix
, gfx::Point3F(),
4208 gfx::PointF(), gfx::Size(1, 1), true, false,
4209 std::tr1::get
<2>(GetParam()));
4210 SetLayerPropertiesForTesting(grand_child_
, identity_matrix
, gfx::Point3F(),
4211 gfx::PointF(), gfx::Size(1, 1), true, false,
4215 bool can_use_lcd_text_
;
4216 bool layers_always_allowed_lcd_text_
;
4218 FakeImplProxy proxy_
;
4219 TestSharedBitmapManager shared_bitmap_manager_
;
4220 TestTaskGraphRunner task_graph_runner_
;
4221 FakeLayerTreeHostImpl host_impl_
;
4225 LayerImpl
* grand_child_
;
4228 TEST_P(LCDTextTest
, CanUseLCDText
) {
4229 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
4230 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
4232 // Case 1: Identity transform.
4233 gfx::Transform identity_matrix
;
4234 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4235 layers_always_allowed_lcd_text_
);
4236 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4237 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4238 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4240 // Case 2: Integral translation.
4241 gfx::Transform integral_translation
;
4242 integral_translation
.Translate(1.0, 2.0);
4243 child_
->SetTransform(integral_translation
);
4244 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4245 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4246 layers_always_allowed_lcd_text_
);
4247 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4248 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4249 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4251 // Case 3: Non-integral translation.
4252 gfx::Transform non_integral_translation
;
4253 non_integral_translation
.Translate(1.5, 2.5);
4254 child_
->SetTransform(non_integral_translation
);
4255 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4256 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4257 layers_always_allowed_lcd_text_
);
4258 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4259 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4260 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4262 // Case 4: Rotation.
4263 gfx::Transform rotation
;
4264 rotation
.Rotate(10.0);
4265 child_
->SetTransform(rotation
);
4266 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4267 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4268 layers_always_allowed_lcd_text_
);
4269 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4270 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4271 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4274 gfx::Transform scale
;
4275 scale
.Scale(2.0, 2.0);
4276 child_
->SetTransform(scale
);
4277 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4278 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4279 layers_always_allowed_lcd_text_
);
4280 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4281 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4282 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4285 gfx::Transform skew
;
4287 child_
->SetTransform(skew
);
4288 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4289 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4290 layers_always_allowed_lcd_text_
);
4291 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4292 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4293 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4295 // Case 7: Translucent.
4296 child_
->SetTransform(identity_matrix
);
4297 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4298 child_
->SetOpacity(0.5f
);
4299 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4300 layers_always_allowed_lcd_text_
);
4301 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4302 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4303 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4305 // Case 8: Sanity check: restore transform and opacity.
4306 child_
->SetTransform(identity_matrix
);
4307 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4308 child_
->SetOpacity(1.f
);
4309 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4310 layers_always_allowed_lcd_text_
);
4311 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4312 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4313 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4315 // Case 9: Non-opaque content.
4316 child_
->SetContentsOpaque(false);
4317 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4318 layers_always_allowed_lcd_text_
);
4319 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4320 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4321 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4323 // Case 10: Sanity check: restore content opaqueness.
4324 child_
->SetContentsOpaque(true);
4325 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4326 layers_always_allowed_lcd_text_
);
4327 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4328 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4329 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4332 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimation
) {
4333 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
4334 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
4336 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
4337 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4338 layers_always_allowed_lcd_text_
);
4339 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4340 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4341 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4343 // Add opacity animation.
4344 child_
->SetOpacity(0.9f
);
4345 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4346 AddOpacityTransitionToController(
4347 child_
->layer_animation_controller(), 10.0, 0.9f
, 0.1f
, false);
4349 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4350 layers_always_allowed_lcd_text_
);
4351 // Text LCD should be adjusted while animation is active.
4352 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4353 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4354 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4357 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimationContentsOpaque
) {
4358 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
4359 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
4361 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
4362 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4363 layers_always_allowed_lcd_text_
);
4364 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4365 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4366 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4368 // Mark contents non-opaque within the first animation frame.
4369 child_
->SetContentsOpaque(false);
4370 AddOpacityTransitionToController(child_
->layer_animation_controller(), 10.0,
4373 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4374 layers_always_allowed_lcd_text_
);
4375 // LCD text should be disabled for non-opaque layers even during animations.
4376 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4377 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4378 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4381 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest
,
4383 testing::Combine(testing::Bool(),
4387 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayerImpl
) {
4388 FakeImplProxy proxy
;
4389 TestSharedBitmapManager shared_bitmap_manager
;
4390 TestTaskGraphRunner task_graph_runner
;
4391 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4392 &task_graph_runner
);
4393 host_impl
.CreatePendingTree();
4394 const gfx::Transform identity_matrix
;
4396 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4397 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4398 gfx::PointF(), gfx::Size(50, 50), true, false,
4400 root
->SetDrawsContent(true);
4402 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
4403 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
4404 gfx::PointF(), gfx::Size(40, 40), true, false,
4406 child
->SetDrawsContent(true);
4408 scoped_ptr
<LayerImpl
> grand_child
=
4409 LayerImpl::Create(host_impl
.pending_tree(), 3);
4410 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
4411 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4412 true, false, false);
4413 grand_child
->SetDrawsContent(true);
4414 grand_child
->SetHideLayerAndSubtree(true);
4416 child
->AddChild(grand_child
.Pass());
4417 root
->AddChild(child
.Pass());
4418 root
->SetHasRenderSurface(true);
4420 LayerImplList render_surface_layer_list
;
4421 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4422 root
.get(), root
->bounds(), &render_surface_layer_list
);
4423 inputs
.can_adjust_raster_scales
= true;
4424 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4426 // We should have one render surface and two layers. The grand child has
4428 ASSERT_EQ(1u, render_surface_layer_list
.size());
4429 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
4430 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
4431 EXPECT_EQ(2, root
->render_surface()->layer_list().at(1)->id());
4434 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayersImpl
) {
4435 FakeImplProxy proxy
;
4436 TestSharedBitmapManager shared_bitmap_manager
;
4437 TestTaskGraphRunner task_graph_runner
;
4438 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4439 &task_graph_runner
);
4440 host_impl
.CreatePendingTree();
4441 const gfx::Transform identity_matrix
;
4443 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4444 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4445 gfx::PointF(), gfx::Size(50, 50), true, false,
4447 root
->SetDrawsContent(true);
4449 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
4450 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
4451 gfx::PointF(), gfx::Size(40, 40), true, false,
4453 child
->SetDrawsContent(true);
4454 child
->SetHideLayerAndSubtree(true);
4456 scoped_ptr
<LayerImpl
> grand_child
=
4457 LayerImpl::Create(host_impl
.pending_tree(), 3);
4458 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
4459 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4460 true, false, false);
4461 grand_child
->SetDrawsContent(true);
4463 child
->AddChild(grand_child
.Pass());
4464 root
->AddChild(child
.Pass());
4466 LayerImplList render_surface_layer_list
;
4467 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4468 root
.get(), root
->bounds(), &render_surface_layer_list
);
4469 inputs
.can_adjust_raster_scales
= true;
4470 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4472 // We should have one render surface and one layers. The child has
4473 // hidden itself and the grand child.
4474 ASSERT_EQ(1u, render_surface_layer_list
.size());
4475 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
4476 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
4479 void EmptyCopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {}
4481 TEST_F(LayerTreeHostCommonTest
, SubtreeHiddenWithCopyRequest
) {
4482 FakeImplProxy proxy
;
4483 TestSharedBitmapManager shared_bitmap_manager
;
4484 TestTaskGraphRunner task_graph_runner
;
4485 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4486 &task_graph_runner
);
4487 host_impl
.CreatePendingTree();
4488 const gfx::Transform identity_matrix
;
4490 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4491 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4492 gfx::PointF(), gfx::Size(50, 50), true, false,
4494 root
->SetDrawsContent(true);
4496 scoped_ptr
<LayerImpl
> copy_grand_parent
=
4497 LayerImpl::Create(host_impl
.pending_tree(), 2);
4498 SetLayerPropertiesForTesting(copy_grand_parent
.get(), identity_matrix
,
4499 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
4500 true, false, false);
4501 copy_grand_parent
->SetDrawsContent(true);
4502 LayerImpl
* copy_grand_parent_layer
= copy_grand_parent
.get();
4504 scoped_ptr
<LayerImpl
> copy_parent
=
4505 LayerImpl::Create(host_impl
.pending_tree(), 3);
4506 SetLayerPropertiesForTesting(copy_parent
.get(), identity_matrix
,
4507 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4509 copy_parent
->SetDrawsContent(true);
4510 LayerImpl
* copy_parent_layer
= copy_parent
.get();
4512 scoped_ptr
<LayerImpl
> copy_request
=
4513 LayerImpl::Create(host_impl
.pending_tree(), 4);
4514 SetLayerPropertiesForTesting(copy_request
.get(), identity_matrix
,
4515 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4517 copy_request
->SetDrawsContent(true);
4518 LayerImpl
* copy_layer
= copy_request
.get();
4520 scoped_ptr
<LayerImpl
> copy_child
=
4521 LayerImpl::Create(host_impl
.pending_tree(), 5);
4522 SetLayerPropertiesForTesting(copy_child
.get(), identity_matrix
,
4523 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4524 true, false, false);
4525 copy_child
->SetDrawsContent(true);
4526 LayerImpl
* copy_child_layer
= copy_child
.get();
4528 scoped_ptr
<LayerImpl
> copy_grand_parent_sibling_before
=
4529 LayerImpl::Create(host_impl
.pending_tree(), 6);
4530 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before
.get(),
4531 identity_matrix
, gfx::Point3F(), gfx::PointF(),
4532 gfx::Size(40, 40), true, false, false);
4533 copy_grand_parent_sibling_before
->SetDrawsContent(true);
4534 LayerImpl
* copy_grand_parent_sibling_before_layer
=
4535 copy_grand_parent_sibling_before
.get();
4537 scoped_ptr
<LayerImpl
> copy_grand_parent_sibling_after
=
4538 LayerImpl::Create(host_impl
.pending_tree(), 7);
4539 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after
.get(),
4540 identity_matrix
, gfx::Point3F(), gfx::PointF(),
4541 gfx::Size(40, 40), true, false, false);
4542 copy_grand_parent_sibling_after
->SetDrawsContent(true);
4543 LayerImpl
* copy_grand_parent_sibling_after_layer
=
4544 copy_grand_parent_sibling_after
.get();
4546 copy_request
->AddChild(copy_child
.Pass());
4547 copy_parent
->AddChild(copy_request
.Pass());
4548 copy_grand_parent
->AddChild(copy_parent
.Pass());
4549 root
->AddChild(copy_grand_parent_sibling_before
.Pass());
4550 root
->AddChild(copy_grand_parent
.Pass());
4551 root
->AddChild(copy_grand_parent_sibling_after
.Pass());
4553 // Hide the copy_grand_parent and its subtree. But make a copy request in that
4554 // hidden subtree on copy_layer.
4555 copy_grand_parent_layer
->SetHideLayerAndSubtree(true);
4556 copy_grand_parent_sibling_before_layer
->SetHideLayerAndSubtree(true);
4557 copy_grand_parent_sibling_after_layer
->SetHideLayerAndSubtree(true);
4559 ScopedPtrVector
<CopyOutputRequest
> copy_requests
;
4560 copy_requests
.push_back(
4561 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback
)));
4562 copy_layer
->PassCopyRequests(©_requests
);
4563 EXPECT_TRUE(copy_layer
->HasCopyRequest());
4565 LayerImplList render_surface_layer_list
;
4566 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4567 root
.get(), root
->bounds(), &render_surface_layer_list
);
4568 inputs
.can_adjust_raster_scales
= true;
4569 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4571 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
4572 EXPECT_TRUE(copy_grand_parent_layer
->draw_properties()
4573 .layer_or_descendant_has_copy_request
);
4574 EXPECT_TRUE(copy_parent_layer
->draw_properties()
4575 .layer_or_descendant_has_copy_request
);
4577 copy_layer
->draw_properties().layer_or_descendant_has_copy_request
);
4579 copy_child_layer
->draw_properties().layer_or_descendant_has_copy_request
);
4580 EXPECT_FALSE(copy_grand_parent_sibling_before_layer
->draw_properties()
4581 .layer_or_descendant_has_copy_request
);
4582 EXPECT_FALSE(copy_grand_parent_sibling_after_layer
->draw_properties()
4583 .layer_or_descendant_has_copy_request
);
4585 // We should have three render surfaces, one for the root, one for the parent
4586 // since it owns a surface, and one for the copy_layer.
4587 ASSERT_EQ(3u, render_surface_layer_list
.size());
4588 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
4589 EXPECT_EQ(copy_parent_layer
->id(), render_surface_layer_list
.at(1)->id());
4590 EXPECT_EQ(copy_layer
->id(), render_surface_layer_list
.at(2)->id());
4592 // The root render surface should have 2 contributing layers. The
4593 // copy_grand_parent is hidden along with its siblings, but the copy_parent
4594 // will appear since something in its subtree needs to be drawn for a copy
4596 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
4597 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
4598 EXPECT_EQ(copy_parent_layer
->id(),
4599 root
->render_surface()->layer_list().at(1)->id());
4601 // Nothing actually draws into the copy parent, so only the copy_layer will
4602 // appear in its list, since it needs to be drawn for the copy request.
4603 ASSERT_EQ(1u, copy_parent_layer
->render_surface()->layer_list().size());
4604 EXPECT_EQ(copy_layer
->id(),
4605 copy_parent_layer
->render_surface()->layer_list().at(0)->id());
4607 // The copy_layer's render surface should have two contributing layers.
4608 ASSERT_EQ(2u, copy_layer
->render_surface()->layer_list().size());
4609 EXPECT_EQ(copy_layer
->id(),
4610 copy_layer
->render_surface()->layer_list().at(0)->id());
4611 EXPECT_EQ(copy_child_layer
->id(),
4612 copy_layer
->render_surface()->layer_list().at(1)->id());
4615 TEST_F(LayerTreeHostCommonTest
, ClippedOutCopyRequest
) {
4616 FakeImplProxy proxy
;
4617 TestSharedBitmapManager shared_bitmap_manager
;
4618 TestTaskGraphRunner task_graph_runner
;
4619 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4620 &task_graph_runner
);
4621 host_impl
.CreatePendingTree();
4622 const gfx::Transform identity_matrix
;
4624 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4625 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4626 gfx::PointF(), gfx::Size(50, 50), true, false,
4628 root
->SetDrawsContent(true);
4630 scoped_ptr
<LayerImpl
> copy_parent
=
4631 LayerImpl::Create(host_impl
.pending_tree(), 2);
4632 SetLayerPropertiesForTesting(copy_parent
.get(), identity_matrix
,
4633 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
4635 copy_parent
->SetDrawsContent(true);
4636 copy_parent
->SetMasksToBounds(true);
4638 scoped_ptr
<LayerImpl
> copy_layer
=
4639 LayerImpl::Create(host_impl
.pending_tree(), 3);
4640 SetLayerPropertiesForTesting(copy_layer
.get(), identity_matrix
,
4641 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4643 copy_layer
->SetDrawsContent(true);
4645 scoped_ptr
<LayerImpl
> copy_child
=
4646 LayerImpl::Create(host_impl
.pending_tree(), 4);
4647 SetLayerPropertiesForTesting(copy_child
.get(), identity_matrix
,
4648 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4649 true, false, false);
4650 copy_child
->SetDrawsContent(true);
4652 ScopedPtrVector
<CopyOutputRequest
> copy_requests
;
4653 copy_requests
.push_back(
4654 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback
)));
4655 copy_layer
->PassCopyRequests(©_requests
);
4656 EXPECT_TRUE(copy_layer
->HasCopyRequest());
4658 copy_layer
->AddChild(copy_child
.Pass());
4659 copy_parent
->AddChild(copy_layer
.Pass());
4660 root
->AddChild(copy_parent
.Pass());
4662 LayerImplList render_surface_layer_list
;
4663 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4664 root
.get(), root
->bounds(), &render_surface_layer_list
);
4665 inputs
.can_adjust_raster_scales
= true;
4666 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4668 // We should have one render surface, as the others are clipped out.
4669 ASSERT_EQ(1u, render_surface_layer_list
.size());
4670 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
4672 // The root render surface should only have 1 contributing layer, since the
4673 // other layers are empty/clipped away.
4674 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
4675 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
4678 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInsideSurface
) {
4679 FakeImplProxy proxy
;
4680 TestSharedBitmapManager shared_bitmap_manager
;
4681 TestTaskGraphRunner task_graph_runner
;
4682 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4683 &task_graph_runner
);
4684 host_impl
.CreatePendingTree();
4685 const gfx::Transform identity_matrix
;
4687 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4688 SetLayerPropertiesForTesting(root
.get(),
4695 root
->SetIsDrawable(true);
4697 // The surface is moved slightly outside of the viewport.
4698 scoped_refptr
<Layer
> surface
= Layer::Create(layer_settings());
4699 SetLayerPropertiesForTesting(surface
.get(),
4702 gfx::PointF(-10, -20),
4706 surface
->SetForceRenderSurface(true);
4708 scoped_refptr
<Layer
> surface_child
= Layer::Create(layer_settings());
4709 SetLayerPropertiesForTesting(surface_child
.get(),
4716 surface_child
->SetIsDrawable(true);
4718 surface
->AddChild(surface_child
);
4719 root
->AddChild(surface
);
4721 host()->SetRootLayer(root
);
4723 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(root
.get(),
4725 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4727 // The visible_layer_rect for the |surface_child| should not be clipped by
4729 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
4730 surface_child
->visible_rect_from_property_trees().ToString());
4733 TEST_F(LayerTreeHostCommonTest
, TransformedClipParent
) {
4734 // Ensure that a transform between the layer and its render surface is not a
4735 // problem. Constructs the following layer tree.
4737 // root (a render surface)
4739 // + clip_parent (scaled)
4740 // + intervening_clipping_layer
4743 // The render surface should be resized correctly and the clip child should
4744 // inherit the right clip rect.
4745 LayerImpl
* root
= root_layer();
4746 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
4747 LayerImpl
* clip_parent
= AddChild
<LayerImpl
>(render_surface
);
4748 LayerImpl
* intervening
= AddChild
<LayerImpl
>(clip_parent
);
4749 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(intervening
);
4750 clip_child
->SetDrawsContent(true);
4751 clip_child
->SetClipParent(clip_parent
);
4752 scoped_ptr
<std::set
<LayerImpl
*>> clip_children(new std::set
<LayerImpl
*>);
4753 clip_children
->insert(clip_child
);
4754 clip_parent
->SetClipChildren(clip_children
.release());
4756 intervening
->SetMasksToBounds(true);
4757 clip_parent
->SetMasksToBounds(true);
4759 gfx::Transform scale_transform
;
4760 scale_transform
.Scale(2, 2);
4762 gfx::Transform identity_transform
;
4764 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
4765 gfx::PointF(), gfx::Size(50, 50), true, false,
4767 SetLayerPropertiesForTesting(render_surface
, identity_transform
,
4768 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4770 SetLayerPropertiesForTesting(clip_parent
, scale_transform
, gfx::Point3F(),
4771 gfx::PointF(1.f
, 1.f
), gfx::Size(10, 10), true,
4773 SetLayerPropertiesForTesting(intervening
, identity_transform
, gfx::Point3F(),
4774 gfx::PointF(1.f
, 1.f
), gfx::Size(5, 5), true,
4776 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
4777 gfx::PointF(1.f
, 1.f
), gfx::Size(10, 10), true,
4780 ExecuteCalculateDrawProperties(root
);
4782 ASSERT_TRUE(root
->render_surface());
4783 ASSERT_TRUE(render_surface
->render_surface());
4785 // Ensure that we've inherited our clip parent's clip and weren't affected
4786 // by the intervening clip layer.
4787 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
4788 clip_parent
->clip_rect().ToString());
4789 ASSERT_EQ(clip_parent
->clip_rect().ToString(),
4790 clip_child
->clip_rect().ToString());
4791 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
4792 intervening
->clip_rect().ToString());
4794 // Ensure that the render surface reports a content rect that has been grown
4795 // to accomodate for the clip child.
4796 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
4797 render_surface
->render_surface()->content_rect().ToString());
4799 // The above check implies the two below, but they nicely demonstrate that
4800 // we've grown, despite the intervening layer's clip.
4801 ASSERT_TRUE(clip_parent
->clip_rect().Contains(
4802 render_surface
->render_surface()->content_rect()));
4803 ASSERT_FALSE(intervening
->clip_rect().Contains(
4804 render_surface
->render_surface()->content_rect()));
4807 TEST_F(LayerTreeHostCommonTest
, ClipParentWithInterveningRenderSurface
) {
4808 // Ensure that intervening render surfaces are not a problem in the basic
4809 // case. In the following tree, both render surfaces should be resized to
4810 // accomodate for the clip child, despite an intervening clip.
4812 // root (a render surface)
4813 // + clip_parent (masks to bounds)
4814 // + render_surface1 (sets opacity)
4815 // + intervening (masks to bounds)
4816 // + render_surface2 (also sets opacity)
4819 LayerImpl
* root
= root_layer();
4820 LayerImpl
* clip_parent
= AddChildToRoot
<LayerImpl
>();
4821 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(clip_parent
);
4822 LayerImpl
* intervening
= AddChild
<LayerImpl
>(render_surface1
);
4823 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(intervening
);
4824 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(render_surface2
);
4825 clip_child
->SetDrawsContent(true);
4827 clip_child
->SetClipParent(clip_parent
);
4829 intervening
->SetMasksToBounds(true);
4830 clip_parent
->SetMasksToBounds(true);
4832 gfx::Transform translation_transform
;
4833 translation_transform
.Translate(2, 2);
4835 gfx::Transform identity_transform
;
4836 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
4837 gfx::PointF(), gfx::Size(50, 50), true, false,
4839 SetLayerPropertiesForTesting(clip_parent
, translation_transform
,
4840 gfx::Point3F(), gfx::PointF(1.f
, 1.f
),
4841 gfx::Size(40, 40), true, false, false);
4842 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
4843 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4845 SetLayerPropertiesForTesting(intervening
, identity_transform
, gfx::Point3F(),
4846 gfx::PointF(1.f
, 1.f
), gfx::Size(5, 5), true,
4848 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
4849 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4851 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
4852 gfx::PointF(-10.f
, -10.f
), gfx::Size(60, 60),
4853 true, false, false);
4855 ExecuteCalculateDrawProperties(root
);
4857 EXPECT_TRUE(root
->render_surface());
4858 EXPECT_TRUE(render_surface1
->render_surface());
4859 EXPECT_TRUE(render_surface2
->render_surface());
4861 // Since the render surfaces could have expanded, they should not clip (their
4862 // bounds would no longer be reliable). We should resort to layer clipping
4864 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4865 render_surface1
->render_surface()->clip_rect().ToString());
4866 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
4867 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4868 render_surface2
->render_surface()->clip_rect().ToString());
4869 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
4871 // NB: clip rects are in target space.
4872 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4873 render_surface1
->clip_rect().ToString());
4874 EXPECT_TRUE(render_surface1
->is_clipped());
4876 // This value is inherited from the clipping ancestor layer, 'intervening'.
4877 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
4878 render_surface2
->clip_rect().ToString());
4879 EXPECT_TRUE(render_surface2
->is_clipped());
4881 // The content rects of both render surfaces should both have expanded to
4882 // contain the clip child.
4883 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4884 render_surface1
->render_surface()->content_rect().ToString());
4885 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
4886 render_surface2
->render_surface()->content_rect().ToString());
4888 // The clip child should have inherited the clip parent's clip (projected to
4889 // the right space, of course), and should have the correctly sized visible
4891 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
4892 clip_child
->clip_rect().ToString());
4893 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
4894 clip_child
->visible_layer_rect().ToString());
4895 EXPECT_TRUE(clip_child
->is_clipped());
4898 TEST_F(LayerTreeHostCommonTest
, ClipParentScrolledInterveningLayer
) {
4899 // Ensure that intervening render surfaces are not a problem, even if there
4900 // is a scroll involved. Note, we do _not_ have to consider any other sort
4903 // root (a render surface)
4904 // + clip_parent (masks to bounds)
4905 // + render_surface1 (sets opacity)
4906 // + intervening (masks to bounds AND scrolls)
4907 // + render_surface2 (also sets opacity)
4910 LayerImpl
* root
= root_layer();
4911 LayerImpl
* clip_parent
= AddChildToRoot
<LayerImpl
>();
4912 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(clip_parent
);
4913 LayerImpl
* intervening
= AddChild
<LayerImpl
>(render_surface1
);
4914 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(intervening
);
4915 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(render_surface2
);
4916 clip_child
->SetDrawsContent(true);
4918 clip_child
->SetClipParent(clip_parent
);
4920 intervening
->SetMasksToBounds(true);
4921 clip_parent
->SetMasksToBounds(true);
4922 intervening
->SetScrollClipLayer(clip_parent
->id());
4923 intervening
->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
4925 gfx::Transform translation_transform
;
4926 translation_transform
.Translate(2, 2);
4928 gfx::Transform identity_transform
;
4929 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
4930 gfx::PointF(), gfx::Size(50, 50), true, false,
4932 SetLayerPropertiesForTesting(clip_parent
, translation_transform
,
4933 gfx::Point3F(), gfx::PointF(1.f
, 1.f
),
4934 gfx::Size(40, 40), true, false, false);
4935 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
4936 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4938 SetLayerPropertiesForTesting(intervening
, identity_transform
, gfx::Point3F(),
4939 gfx::PointF(1.f
, 1.f
), gfx::Size(5, 5), true,
4941 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
4942 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4944 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
4945 gfx::PointF(-10.f
, -10.f
), gfx::Size(60, 60),
4946 true, false, false);
4948 ExecuteCalculateDrawProperties(root
);
4950 EXPECT_TRUE(root
->render_surface());
4951 EXPECT_TRUE(render_surface1
->render_surface());
4952 EXPECT_TRUE(render_surface2
->render_surface());
4954 // Since the render surfaces could have expanded, they should not clip (their
4955 // bounds would no longer be reliable). We should resort to layer clipping
4957 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4958 render_surface1
->render_surface()->clip_rect().ToString());
4959 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
4960 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4961 render_surface2
->render_surface()->clip_rect().ToString());
4962 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
4964 // NB: clip rects are in target space.
4965 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4966 render_surface1
->clip_rect().ToString());
4967 EXPECT_TRUE(render_surface1
->is_clipped());
4969 // This value is inherited from the clipping ancestor layer, 'intervening'.
4970 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
4971 render_surface2
->clip_rect().ToString());
4972 EXPECT_TRUE(render_surface2
->is_clipped());
4974 // The content rects of both render surfaces should both have expanded to
4975 // contain the clip child.
4976 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4977 render_surface1
->render_surface()->content_rect().ToString());
4978 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
4979 render_surface2
->render_surface()->content_rect().ToString());
4981 // The clip child should have inherited the clip parent's clip (projected to
4982 // the right space, of course), and should have the correctly sized visible
4984 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
4985 clip_child
->clip_rect().ToString());
4986 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
4987 clip_child
->visible_layer_rect().ToString());
4988 EXPECT_TRUE(clip_child
->is_clipped());
4991 TEST_F(LayerTreeHostCommonTest
, DescendantsOfClipChildren
) {
4992 // Ensures that descendants of the clip child inherit the correct clip.
4994 // root (a render surface)
4995 // + clip_parent (masks to bounds)
4996 // + intervening (masks to bounds)
5000 LayerImpl
* root
= root_layer();
5001 LayerImpl
* clip_parent
= AddChild
<LayerImpl
>(root
);
5002 LayerImpl
* intervening
= AddChild
<LayerImpl
>(clip_parent
);
5003 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(intervening
);
5004 LayerImpl
* child
= AddChild
<LayerImpl
>(clip_child
);
5005 child
->SetDrawsContent(true);
5007 clip_child
->SetClipParent(clip_parent
);
5008 scoped_ptr
<std::set
<LayerImpl
*>> clip_children(new std::set
<LayerImpl
*>);
5009 clip_children
->insert(clip_child
);
5010 clip_parent
->SetClipChildren(clip_children
.release());
5012 intervening
->SetMasksToBounds(true);
5013 clip_parent
->SetMasksToBounds(true);
5015 gfx::Transform identity_transform
;
5016 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5017 gfx::PointF(), gfx::Size(50, 50), true, false,
5019 SetLayerPropertiesForTesting(clip_parent
, identity_transform
, gfx::Point3F(),
5020 gfx::PointF(), gfx::Size(40, 40), true, false,
5022 SetLayerPropertiesForTesting(intervening
, identity_transform
, gfx::Point3F(),
5023 gfx::PointF(), gfx::Size(5, 5), true, false,
5025 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
5026 gfx::PointF(), gfx::Size(60, 60), true, false,
5028 SetLayerPropertiesForTesting(child
, identity_transform
, gfx::Point3F(),
5029 gfx::PointF(), gfx::Size(60, 60), true, false,
5032 ExecuteCalculateDrawProperties(root
);
5034 EXPECT_TRUE(root
->render_surface());
5036 // Neither the clip child nor its descendant should have inherited the clip
5037 // from |intervening|.
5038 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5039 clip_child
->clip_rect().ToString());
5040 EXPECT_TRUE(clip_child
->is_clipped());
5041 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5042 child
->visible_layer_rect().ToString());
5043 EXPECT_TRUE(child
->is_clipped());
5046 TEST_F(LayerTreeHostCommonTest
,
5047 SurfacesShouldBeUnaffectedByNonDescendantClipChildren
) {
5048 // Ensures that non-descendant clip children in the tree do not affect
5051 // root (a render surface)
5052 // + clip_parent (masks to bounds)
5053 // + render_surface1
5055 // + render_surface2
5058 // In this example render_surface2 should be unaffected by clip_child.
5059 LayerImpl
* root
= root_layer();
5060 LayerImpl
* clip_parent
= AddChildToRoot
<LayerImpl
>();
5061 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(clip_parent
);
5062 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(render_surface1
);
5063 clip_child
->SetDrawsContent(true);
5064 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(clip_parent
);
5065 LayerImpl
* non_clip_child
= AddChild
<LayerImpl
>(render_surface2
);
5066 non_clip_child
->SetDrawsContent(true);
5068 clip_child
->SetClipParent(clip_parent
);
5069 scoped_ptr
<std::set
<LayerImpl
*>> clip_children(new std::set
<LayerImpl
*>);
5070 clip_children
->insert(clip_child
);
5071 clip_parent
->SetClipChildren(clip_children
.release());
5073 clip_parent
->SetMasksToBounds(true);
5074 render_surface1
->SetMasksToBounds(true);
5076 gfx::Transform identity_transform
;
5077 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5078 gfx::PointF(), gfx::Size(15, 15), true, false,
5080 SetLayerPropertiesForTesting(clip_parent
, identity_transform
, gfx::Point3F(),
5081 gfx::PointF(), gfx::Size(10, 10), true, false,
5083 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
5084 gfx::Point3F(), gfx::PointF(5, 5),
5085 gfx::Size(5, 5), true, false, true);
5086 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
5087 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
5089 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
5090 gfx::PointF(-1, 1), gfx::Size(10, 10), true,
5092 SetLayerPropertiesForTesting(non_clip_child
, identity_transform
,
5093 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
5094 true, false, false);
5096 ExecuteCalculateDrawProperties(root
);
5098 EXPECT_TRUE(root
->render_surface());
5099 EXPECT_TRUE(render_surface1
->render_surface());
5100 EXPECT_TRUE(render_surface2
->render_surface());
5102 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5103 render_surface1
->clip_rect().ToString());
5104 EXPECT_TRUE(render_surface1
->is_clipped());
5106 // The render surface should not clip (it has unclipped descendants), instead
5107 // it should rely on layer clipping.
5108 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5109 render_surface1
->render_surface()->clip_rect().ToString());
5110 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
5112 // That said, it should have grown to accomodate the unclipped descendant.
5113 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
5114 render_surface1
->render_surface()->content_rect().ToString());
5116 // This render surface should clip. It has no unclipped descendants.
5117 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5118 render_surface2
->clip_rect().ToString());
5119 EXPECT_TRUE(render_surface2
->render_surface()->is_clipped());
5121 // It also shouldn't have grown to accomodate the clip child.
5122 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5123 render_surface2
->render_surface()->content_rect().ToString());
5125 // Sanity check our num_unclipped_descendants values.
5126 EXPECT_EQ(1u, render_surface1
->num_unclipped_descendants());
5127 EXPECT_EQ(0u, render_surface2
->num_unclipped_descendants());
5130 TEST_F(LayerTreeHostCommonTest
, CanRenderToSeparateSurface
) {
5131 FakeImplProxy proxy
;
5132 TestSharedBitmapManager shared_bitmap_manager
;
5133 TestTaskGraphRunner task_graph_runner
;
5134 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5135 &task_graph_runner
);
5136 scoped_ptr
<LayerImpl
> root
=
5137 LayerImpl::Create(host_impl
.active_tree(), 12345);
5138 scoped_ptr
<LayerImpl
> child1
=
5139 LayerImpl::Create(host_impl
.active_tree(), 123456);
5140 scoped_ptr
<LayerImpl
> child2
=
5141 LayerImpl::Create(host_impl
.active_tree(), 1234567);
5142 scoped_ptr
<LayerImpl
> child3
=
5143 LayerImpl::Create(host_impl
.active_tree(), 12345678);
5145 gfx::Transform identity_matrix
;
5146 gfx::Point3F transform_origin
;
5147 gfx::PointF position
;
5148 gfx::Size
bounds(100, 100);
5149 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
5150 position
, bounds
, true, false, true);
5151 root
->SetDrawsContent(true);
5153 // This layer structure normally forces render surface due to preserves3d
5155 SetLayerPropertiesForTesting(child1
.get(), identity_matrix
, transform_origin
,
5156 position
, bounds
, false, true, true);
5157 child1
->SetDrawsContent(true);
5158 SetLayerPropertiesForTesting(child2
.get(), identity_matrix
, transform_origin
,
5159 position
, bounds
, true, false, false);
5160 child2
->SetDrawsContent(true);
5161 SetLayerPropertiesForTesting(child3
.get(), identity_matrix
, transform_origin
,
5162 position
, bounds
, true, false, false);
5163 child3
->SetDrawsContent(true);
5165 child2
->Set3dSortingContextId(1);
5166 child3
->Set3dSortingContextId(1);
5168 child2
->AddChild(child3
.Pass());
5169 child1
->AddChild(child2
.Pass());
5170 root
->AddChild(child1
.Pass());
5173 LayerImplList render_surface_layer_list
;
5174 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root
.get());
5175 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5176 root
.get(), root
->bounds(), &render_surface_layer_list
);
5177 inputs
.can_render_to_separate_surface
= true;
5178 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5180 EXPECT_EQ(2u, render_surface_layer_list
.size());
5182 int count_represents_target_render_surface
= 0;
5183 int count_represents_contributing_render_surface
= 0;
5184 int count_represents_itself
= 0;
5185 LayerIterator end
= LayerIterator::End(&render_surface_layer_list
);
5186 for (LayerIterator it
= LayerIterator::Begin(&render_surface_layer_list
);
5188 if (it
.represents_target_render_surface())
5189 count_represents_target_render_surface
++;
5190 if (it
.represents_contributing_render_surface())
5191 count_represents_contributing_render_surface
++;
5192 if (it
.represents_itself())
5193 count_represents_itself
++;
5196 // Two render surfaces.
5197 EXPECT_EQ(2, count_represents_target_render_surface
);
5198 // Second render surface contributes to root render surface.
5199 EXPECT_EQ(1, count_represents_contributing_render_surface
);
5200 // All 4 layers represent itself.
5201 EXPECT_EQ(4, count_represents_itself
);
5205 LayerImplList render_surface_layer_list
;
5206 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5207 root
.get(), root
->bounds(), &render_surface_layer_list
);
5208 inputs
.can_render_to_separate_surface
= false;
5209 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5211 EXPECT_EQ(1u, render_surface_layer_list
.size());
5213 int count_represents_target_render_surface
= 0;
5214 int count_represents_contributing_render_surface
= 0;
5215 int count_represents_itself
= 0;
5216 LayerIterator end
= LayerIterator::End(&render_surface_layer_list
);
5217 for (LayerIterator it
= LayerIterator::Begin(&render_surface_layer_list
);
5219 if (it
.represents_target_render_surface())
5220 count_represents_target_render_surface
++;
5221 if (it
.represents_contributing_render_surface())
5222 count_represents_contributing_render_surface
++;
5223 if (it
.represents_itself())
5224 count_represents_itself
++;
5227 // Only root layer has a render surface.
5228 EXPECT_EQ(1, count_represents_target_render_surface
);
5229 // No layer contributes a render surface to root render surface.
5230 EXPECT_EQ(0, count_represents_contributing_render_surface
);
5231 // All 4 layers represent itself.
5232 EXPECT_EQ(4, count_represents_itself
);
5236 TEST_F(LayerTreeHostCommonTest
, DoNotIncludeBackfaceInvisibleSurfaces
) {
5237 LayerImpl
* root
= root_layer();
5238 LayerImpl
* render_surface
= AddChild
<LayerImpl
>(root
);
5239 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface
);
5240 child
->SetDrawsContent(true);
5242 gfx::Transform identity_transform
;
5243 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5244 gfx::PointF(), gfx::Size(50, 50), true, false,
5246 SetLayerPropertiesForTesting(render_surface
, identity_transform
,
5247 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5249 SetLayerPropertiesForTesting(child
, identity_transform
, gfx::Point3F(),
5250 gfx::PointF(), gfx::Size(20, 20), true, false,
5253 root
->SetShouldFlattenTransform(false);
5254 root
->Set3dSortingContextId(1);
5255 render_surface
->SetDoubleSided(false);
5257 ExecuteCalculateDrawProperties(root
);
5259 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
5260 EXPECT_EQ(1u, render_surface_layer_list_impl()
5265 EXPECT_EQ(1u, render_surface_layer_list_impl()
5271 gfx::Transform rotation_transform
= identity_transform
;
5272 rotation_transform
.RotateAboutXAxis(180.0);
5274 render_surface
->SetTransform(rotation_transform
);
5276 ExecuteCalculateDrawProperties(root
);
5278 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
5279 EXPECT_EQ(0u, render_surface_layer_list_impl()
5286 TEST_F(LayerTreeHostCommonTest
, ClippedByScrollParent
) {
5287 // Checks that the simple case (being clipped by a scroll parent that would
5288 // have been processed before you anyhow) results in the right clips.
5291 // + scroll_parent_border
5292 // | + scroll_parent_clip
5293 // | + scroll_parent
5296 LayerImpl
* root
= root_layer();
5297 LayerImpl
* scroll_parent_border
= AddChildToRoot
<LayerImpl
>();
5298 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
5299 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
5300 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
5302 scroll_parent
->SetDrawsContent(true);
5303 scroll_child
->SetDrawsContent(true);
5304 scroll_parent_clip
->SetMasksToBounds(true);
5306 scroll_child
->SetScrollParent(scroll_parent
);
5307 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
5308 scroll_children
->insert(scroll_child
);
5309 scroll_parent
->SetScrollChildren(scroll_children
.release());
5311 gfx::Transform identity_transform
;
5312 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5313 gfx::PointF(), gfx::Size(50, 50), true, false,
5315 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
5316 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5317 true, false, false);
5318 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
5319 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5320 true, false, false);
5321 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
5322 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5323 true, false, false);
5324 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
5325 gfx::PointF(), gfx::Size(50, 50), true, false,
5328 ExecuteCalculateDrawProperties(root
);
5330 EXPECT_TRUE(root
->render_surface());
5332 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
5333 scroll_child
->clip_rect().ToString());
5334 EXPECT_TRUE(scroll_child
->is_clipped());
5337 TEST_F(LayerTreeHostCommonTest
, SingularTransformSubtreesDoNotDraw
) {
5338 LayerImpl
* root
= root_layer();
5339 root
->SetDrawsContent(true);
5340 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
5341 parent
->SetDrawsContent(true);
5342 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
5343 child
->SetDrawsContent(true);
5345 gfx::Transform identity_transform
;
5346 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5347 gfx::PointF(), gfx::Size(50, 50), true, true,
5349 SetLayerPropertiesForTesting(parent
, identity_transform
, gfx::Point3F(),
5350 gfx::PointF(), gfx::Size(30, 30), true, true,
5352 SetLayerPropertiesForTesting(child
, identity_transform
, gfx::Point3F(),
5353 gfx::PointF(), gfx::Size(20, 20), true, true,
5356 ExecuteCalculateDrawProperties(root
);
5358 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
5360 gfx::Transform singular_transform
;
5361 singular_transform
.Scale3d(
5362 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
5364 child
->SetTransform(singular_transform
);
5366 ExecuteCalculateDrawProperties(root
);
5368 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
5370 // Ensure that the entire subtree under a layer with singular transform does
5371 // not get rendered.
5372 parent
->SetTransform(singular_transform
);
5373 child
->SetTransform(identity_transform
);
5375 ExecuteCalculateDrawProperties(root
);
5377 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
5380 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollParent
) {
5381 // Checks that clipping by a scroll parent that follows you in paint order
5382 // still results in correct clipping.
5385 // + scroll_parent_border
5386 // + scroll_parent_clip
5390 LayerImpl
* root
= root_layer();
5391 LayerImpl
* scroll_parent_border
= AddChild
<LayerImpl
>(root
);
5392 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
5393 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
5394 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
5396 scroll_parent
->SetDrawsContent(true);
5397 scroll_child
->SetDrawsContent(true);
5399 scroll_parent_clip
->SetMasksToBounds(true);
5401 scroll_child
->SetScrollParent(scroll_parent
);
5402 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
5403 scroll_children
->insert(scroll_child
);
5404 scroll_parent
->SetScrollChildren(scroll_children
.release());
5406 gfx::Transform identity_transform
;
5407 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5408 gfx::PointF(), gfx::Size(50, 50), true, false,
5410 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
5411 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5412 true, false, false);
5413 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
5414 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5415 true, false, false);
5416 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
5417 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5418 true, false, false);
5419 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
5420 gfx::PointF(), gfx::Size(50, 50), true, false,
5423 ExecuteCalculateDrawProperties(root
);
5425 EXPECT_TRUE(root
->render_surface());
5427 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
5428 scroll_child
->clip_rect().ToString());
5429 EXPECT_TRUE(scroll_child
->is_clipped());
5432 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollGrandparent
) {
5433 // Checks that clipping by a scroll parent and scroll grandparent that follow
5434 // you in paint order still results in correct clipping.
5438 // + scroll_parent_border
5439 // | + scroll_parent_clip
5440 // | + scroll_parent
5441 // + scroll_grandparent_border
5442 // + scroll_grandparent_clip
5443 // + scroll_grandparent
5445 LayerImpl
* root
= root_layer();
5446 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
5447 LayerImpl
* scroll_parent_border
= AddChild
<LayerImpl
>(root
);
5448 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
5449 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
5450 LayerImpl
* scroll_grandparent_border
= AddChild
<LayerImpl
>(root
);
5451 LayerImpl
* scroll_grandparent_clip
=
5452 AddChild
<LayerImpl
>(scroll_grandparent_border
);
5453 LayerImpl
* scroll_grandparent
= AddChild
<LayerImpl
>(scroll_grandparent_clip
);
5455 scroll_parent
->SetDrawsContent(true);
5456 scroll_grandparent
->SetDrawsContent(true);
5457 scroll_child
->SetDrawsContent(true);
5459 scroll_parent_clip
->SetMasksToBounds(true);
5460 scroll_grandparent_clip
->SetMasksToBounds(true);
5462 scroll_child
->SetScrollParent(scroll_parent
);
5463 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
5464 scroll_children
->insert(scroll_child
);
5465 scroll_parent
->SetScrollChildren(scroll_children
.release());
5467 scroll_parent_border
->SetScrollParent(scroll_grandparent
);
5468 scroll_children
.reset(new std::set
<LayerImpl
*>);
5469 scroll_children
->insert(scroll_parent_border
);
5470 scroll_grandparent
->SetScrollChildren(scroll_children
.release());
5472 gfx::Transform identity_transform
;
5473 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5474 gfx::PointF(), gfx::Size(50, 50), true, false,
5476 SetLayerPropertiesForTesting(scroll_grandparent_border
, identity_transform
,
5477 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5478 true, false, false);
5479 SetLayerPropertiesForTesting(scroll_grandparent_clip
, identity_transform
,
5480 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5481 true, false, false);
5482 SetLayerPropertiesForTesting(scroll_grandparent
, identity_transform
,
5483 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5484 true, false, false);
5485 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
5486 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5487 true, false, false);
5488 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
5489 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5490 true, false, false);
5491 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
5492 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5493 true, false, false);
5494 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
5495 gfx::PointF(), gfx::Size(50, 50), true, false,
5498 ExecuteCalculateDrawProperties(root
);
5500 EXPECT_TRUE(root
->render_surface());
5502 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
5503 scroll_child
->clip_rect().ToString());
5504 EXPECT_TRUE(scroll_child
->is_clipped());
5506 // Despite the fact that we visited the above layers out of order to get the
5507 // correct clip, the layer lists should be unaffected.
5508 EXPECT_EQ(3u, root
->render_surface()->layer_list().size());
5509 EXPECT_EQ(scroll_child
, root
->render_surface()->layer_list().at(0));
5510 EXPECT_EQ(scroll_parent
, root
->render_surface()->layer_list().at(1));
5511 EXPECT_EQ(scroll_grandparent
, root
->render_surface()->layer_list().at(2));
5514 TEST_F(LayerTreeHostCommonTest
, OutOfOrderClippingRequiresRSLLSorting
) {
5515 // Ensures that even if we visit layers out of order, we still produce a
5516 // correctly ordered render surface layer list.
5519 // + scroll_parent_border
5520 // + scroll_parent_clip
5522 // + render_surface2
5523 // + scroll_grandparent_border
5524 // + scroll_grandparent_clip
5525 // + scroll_grandparent
5526 // + render_surface1
5528 LayerImpl
* root
= root_layer();
5529 root
->SetDrawsContent(true);
5531 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
5532 scroll_child
->SetDrawsContent(true);
5534 LayerImpl
* scroll_parent_border
= AddChild
<LayerImpl
>(root
);
5535 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
5536 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
5537 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(scroll_parent
);
5538 LayerImpl
* scroll_grandparent_border
= AddChild
<LayerImpl
>(root
);
5539 LayerImpl
* scroll_grandparent_clip
=
5540 AddChild
<LayerImpl
>(scroll_grandparent_border
);
5541 LayerImpl
* scroll_grandparent
= AddChild
<LayerImpl
>(scroll_grandparent_clip
);
5542 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(scroll_grandparent
);
5544 scroll_parent
->SetDrawsContent(true);
5545 render_surface1
->SetDrawsContent(true);
5546 scroll_grandparent
->SetDrawsContent(true);
5547 render_surface2
->SetDrawsContent(true);
5549 scroll_parent_clip
->SetMasksToBounds(true);
5550 scroll_grandparent_clip
->SetMasksToBounds(true);
5552 scroll_child
->SetScrollParent(scroll_parent
);
5553 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
5554 scroll_children
->insert(scroll_child
);
5555 scroll_parent
->SetScrollChildren(scroll_children
.release());
5557 scroll_parent_border
->SetScrollParent(scroll_grandparent
);
5558 scroll_children
.reset(new std::set
<LayerImpl
*>);
5559 scroll_children
->insert(scroll_parent_border
);
5560 scroll_grandparent
->SetScrollChildren(scroll_children
.release());
5562 gfx::Transform identity_transform
;
5563 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5564 gfx::PointF(), gfx::Size(50, 50), true, false,
5566 SetLayerPropertiesForTesting(scroll_grandparent_border
, identity_transform
,
5567 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5568 true, false, false);
5569 SetLayerPropertiesForTesting(scroll_grandparent_clip
, identity_transform
,
5570 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5571 true, false, false);
5572 SetLayerPropertiesForTesting(scroll_grandparent
, identity_transform
,
5573 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5574 true, false, false);
5575 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
5576 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5578 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
5579 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5580 true, false, false);
5581 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
5582 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5583 true, false, false);
5584 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
5585 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5586 true, false, false);
5587 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
5588 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5590 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
5591 gfx::PointF(), gfx::Size(50, 50), true, false,
5594 ExecuteCalculateDrawProperties(root
);
5596 EXPECT_TRUE(root
->render_surface());
5598 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
5599 scroll_child
->clip_rect().ToString());
5600 EXPECT_TRUE(scroll_child
->is_clipped());
5602 // Despite the fact that we had to process the layers out of order to get the
5603 // right clip, our render_surface_layer_list's order should be unaffected.
5604 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
5605 EXPECT_EQ(root
, render_surface_layer_list_impl()->at(0));
5606 EXPECT_EQ(render_surface2
, render_surface_layer_list_impl()->at(1));
5607 EXPECT_EQ(render_surface1
, render_surface_layer_list_impl()->at(2));
5608 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
5609 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
5610 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
5613 TEST_F(LayerTreeHostCommonTest
, FixedPositionWithInterveningRenderSurface
) {
5614 // Ensures that when we have a render surface between a fixed position layer
5615 // and its container, we compute the fixed position layer's draw transform
5616 // with respect to that intervening render surface, not with respect to its
5617 // container's render target.
5624 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5625 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface
=
5626 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5627 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
5628 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5629 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
5630 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5632 root
->AddChild(render_surface
);
5633 render_surface
->AddChild(fixed
);
5634 fixed
->AddChild(child
);
5636 root
->SetIsContainerForFixedPositionLayers(true);
5637 render_surface
->SetForceRenderSurface(true);
5639 LayerPositionConstraint constraint
;
5640 constraint
.set_is_fixed_position(true);
5641 fixed
->SetPositionConstraint(constraint
);
5643 SetLayerPropertiesForTesting(root
.get(), gfx::Transform(), gfx::Point3F(),
5644 gfx::PointF(), gfx::Size(50, 50), true, false);
5645 SetLayerPropertiesForTesting(render_surface
.get(), gfx::Transform(),
5646 gfx::Point3F(), gfx::PointF(7.f
, 9.f
),
5647 gfx::Size(50, 50), true, false);
5648 SetLayerPropertiesForTesting(fixed
.get(), gfx::Transform(), gfx::Point3F(),
5649 gfx::PointF(10.f
, 15.f
), gfx::Size(50, 50), true,
5651 SetLayerPropertiesForTesting(child
.get(), gfx::Transform(), gfx::Point3F(),
5652 gfx::PointF(1.f
, 2.f
), gfx::Size(50, 50), true,
5655 host()->SetRootLayer(root
);
5657 ExecuteCalculateDrawProperties(root
.get());
5659 TransformTree
& tree
= host()->property_trees()->transform_tree
;
5661 gfx::Transform expected_fixed_draw_transform
;
5662 expected_fixed_draw_transform
.Translate(10.f
, 15.f
);
5663 EXPECT_EQ(expected_fixed_draw_transform
,
5664 DrawTransformFromPropertyTrees(fixed
.get(), tree
));
5666 gfx::Transform expected_fixed_screen_space_transform
;
5667 expected_fixed_screen_space_transform
.Translate(17.f
, 24.f
);
5668 EXPECT_EQ(expected_fixed_screen_space_transform
,
5669 ScreenSpaceTransformFromPropertyTrees(fixed
.get(), tree
));
5671 gfx::Transform expected_child_draw_transform
;
5672 expected_child_draw_transform
.Translate(11.f
, 17.f
);
5673 EXPECT_EQ(expected_child_draw_transform
,
5674 DrawTransformFromPropertyTrees(child
.get(), tree
));
5676 gfx::Transform expected_child_screen_space_transform
;
5677 expected_child_screen_space_transform
.Translate(18.f
, 26.f
);
5678 EXPECT_EQ(expected_child_screen_space_transform
,
5679 ScreenSpaceTransformFromPropertyTrees(child
.get(), tree
));
5682 TEST_F(LayerTreeHostCommonTest
, ScrollCompensationWithRounding
) {
5683 // This test verifies that a scrolling layer that gets snapped to
5684 // integer coordinates doesn't move a fixed position child.
5691 FakeImplProxy proxy
;
5692 TestSharedBitmapManager shared_bitmap_manager
;
5693 TestTaskGraphRunner task_graph_runner
;
5694 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5695 &task_graph_runner
);
5696 host_impl
.CreatePendingTree();
5697 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
5698 scoped_ptr
<LayerImpl
> container
=
5699 LayerImpl::Create(host_impl
.active_tree(), 2);
5700 LayerImpl
* container_layer
= container
.get();
5701 scoped_ptr
<LayerImpl
> scroller
=
5702 LayerImpl::Create(host_impl
.active_tree(), 3);
5703 LayerImpl
* scroll_layer
= scroller
.get();
5704 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
5705 LayerImpl
* fixed_layer
= fixed
.get();
5707 container
->SetIsContainerForFixedPositionLayers(true);
5709 LayerPositionConstraint constraint
;
5710 constraint
.set_is_fixed_position(true);
5711 fixed
->SetPositionConstraint(constraint
);
5713 scroller
->SetScrollClipLayer(container
->id());
5715 gfx::Transform identity_transform
;
5716 gfx::Transform container_transform
;
5717 container_transform
.Translate3d(10.0, 20.0, 0.0);
5718 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
5720 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
5721 gfx::PointF(), gfx::Size(50, 50), true, false,
5723 SetLayerPropertiesForTesting(container
.get(), container_transform
,
5724 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5725 true, false, false);
5726 SetLayerPropertiesForTesting(scroller
.get(), identity_transform
,
5727 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5728 true, false, false);
5729 SetLayerPropertiesForTesting(fixed
.get(), identity_transform
, gfx::Point3F(),
5730 gfx::PointF(), gfx::Size(50, 50), true, false,
5733 scroller
->AddChild(fixed
.Pass());
5734 container
->AddChild(scroller
.Pass());
5735 root
->AddChild(container
.Pass());
5737 // Rounded to integers already.
5739 gfx::Vector2dF
scroll_delta(3.0, 5.0);
5740 scroll_layer
->SetScrollDelta(scroll_delta
);
5742 LayerImplList render_surface_layer_list
;
5743 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5744 root
.get(), root
->bounds(), &render_surface_layer_list
);
5745 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5747 EXPECT_TRANSFORMATION_MATRIX_EQ(
5748 container_layer
->draw_properties().screen_space_transform
,
5749 fixed_layer
->draw_properties().screen_space_transform
);
5751 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5753 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
5754 .screen_space_transform
.To2dTranslation(),
5755 container_offset
- scroll_delta
);
5758 // Scroll delta requiring rounding.
5760 gfx::Vector2dF
scroll_delta(4.1f
, 8.1f
);
5761 scroll_layer
->SetScrollDelta(scroll_delta
);
5763 gfx::Vector2dF
rounded_scroll_delta(4.f
, 8.f
);
5765 LayerImplList render_surface_layer_list
;
5766 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5767 root
.get(), root
->bounds(), &render_surface_layer_list
);
5768 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5770 EXPECT_TRANSFORMATION_MATRIX_EQ(
5771 container_layer
->draw_properties().screen_space_transform
,
5772 fixed_layer
->draw_properties().screen_space_transform
);
5774 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5776 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
5777 .screen_space_transform
.To2dTranslation(),
5778 container_offset
- rounded_scroll_delta
);
5781 // Scale is applied earlier in the tree.
5783 gfx::Transform scaled_container_transform
= container_transform
;
5784 scaled_container_transform
.Scale3d(3.0, 3.0, 1.0);
5785 container_layer
->SetTransform(scaled_container_transform
);
5787 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
5788 scroll_layer
->SetScrollDelta(scroll_delta
);
5790 LayerImplList render_surface_layer_list
;
5791 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5792 root
.get(), root
->bounds(), &render_surface_layer_list
);
5793 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5795 EXPECT_TRANSFORMATION_MATRIX_EQ(
5796 container_layer
->draw_properties().screen_space_transform
,
5797 fixed_layer
->draw_properties().screen_space_transform
);
5799 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5802 container_layer
->SetTransform(container_transform
);
5805 // Scale is applied on the scroll layer itself.
5807 gfx::Transform scale_transform
;
5808 scale_transform
.Scale3d(3.0, 3.0, 1.0);
5809 scroll_layer
->SetTransform(scale_transform
);
5811 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
5812 scroll_layer
->SetScrollDelta(scroll_delta
);
5814 LayerImplList render_surface_layer_list
;
5815 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5816 root
.get(), root
->bounds(), &render_surface_layer_list
);
5817 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5820 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5823 scroll_layer
->SetTransform(identity_transform
);
5827 TEST_F(LayerTreeHostCommonTest
,
5828 ScrollCompensationMainScrollOffsetFractionalPart
) {
5829 // This test verifies that a scrolling layer that has fractional scroll offset
5830 // from main doesn't move a fixed position child.
5837 FakeImplProxy proxy
;
5838 TestSharedBitmapManager shared_bitmap_manager
;
5839 TestTaskGraphRunner task_graph_runner
;
5840 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5841 &task_graph_runner
);
5842 host_impl
.CreatePendingTree();
5843 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
5844 scoped_ptr
<LayerImpl
> container
=
5845 LayerImpl::Create(host_impl
.active_tree(), 2);
5846 LayerImpl
* container_layer
= container
.get();
5847 scoped_ptr
<LayerImpl
> scroller
=
5848 LayerImpl::Create(host_impl
.active_tree(), 3);
5849 LayerImpl
* scroll_layer
= scroller
.get();
5850 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
5851 LayerImpl
* fixed_layer
= fixed
.get();
5853 container
->SetIsContainerForFixedPositionLayers(true);
5855 LayerPositionConstraint constraint
;
5856 constraint
.set_is_fixed_position(true);
5857 fixed
->SetPositionConstraint(constraint
);
5859 scroller
->SetScrollClipLayer(container
->id());
5861 gfx::Transform identity_transform
;
5862 gfx::Transform container_transform
;
5863 container_transform
.Translate3d(10.0, 20.0, 0.0);
5864 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
5866 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
5867 gfx::PointF(), gfx::Size(50, 50), true, false,
5869 SetLayerPropertiesForTesting(container
.get(), container_transform
,
5870 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5871 true, false, false);
5872 SetLayerPropertiesForTesting(scroller
.get(), identity_transform
,
5873 gfx::Point3F(), gfx::PointF(0.0, 0.0),
5874 gfx::Size(30, 30), true, false, false);
5876 gfx::ScrollOffset
scroll_offset(3.3, 4.2);
5877 gfx::Vector2dF
main_scroll_fractional_part(0.3f
, 0.2f
);
5878 gfx::Vector2dF
scroll_delta(0.1f
, 0.4f
);
5879 // Blink only uses the integer part of the scroll_offset for fixed
5881 SetLayerPropertiesForTesting(fixed
.get(), identity_transform
, gfx::Point3F(),
5882 gfx::PointF(3.0f
, 4.0f
), gfx::Size(50, 50), true,
5884 scroll_layer
->PushScrollOffsetFromMainThread(scroll_offset
);
5885 scroll_layer
->SetScrollDelta(scroll_delta
);
5886 scroll_layer
->SetScrollCompensationAdjustment(main_scroll_fractional_part
);
5888 scroller
->AddChild(fixed
.Pass());
5889 container
->AddChild(scroller
.Pass());
5890 root
->AddChild(container
.Pass());
5892 LayerImplList render_surface_layer_list
;
5893 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5894 root
.get(), root
->bounds(), &render_surface_layer_list
);
5895 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5897 EXPECT_TRANSFORMATION_MATRIX_EQ(
5898 container_layer
->draw_properties().screen_space_transform
,
5899 fixed_layer
->draw_properties().screen_space_transform
);
5901 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5904 gfx::ScrollOffset effective_scroll_offset
=
5905 ScrollOffsetWithDelta(scroll_offset
, scroll_delta
);
5906 gfx::Vector2d rounded_effective_scroll_offset
=
5907 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset
));
5909 scroll_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5910 container_offset
- rounded_effective_scroll_offset
);
5913 TEST_F(LayerTreeHostCommonTest
,
5914 ScrollSnappingWithAnimatedScreenSpaceTransform
) {
5915 // This test verifies that a scrolling layer whose screen space transform is
5916 // animating doesn't get snapped to integer coordinates.
5924 LayerImpl
* root
= root_layer();
5925 LayerImpl
* animated_layer
= AddChildToRoot
<FakePictureLayerImpl
>();
5926 LayerImpl
* surface
= AddChild
<LayerImpl
>(animated_layer
);
5927 LayerImpl
* container
= AddChild
<LayerImpl
>(surface
);
5928 LayerImpl
* scroller
= AddChild
<LayerImpl
>(container
);
5929 scroller
->SetScrollClipLayer(container
->id());
5930 scroller
->SetDrawsContent(true);
5932 gfx::Transform identity_transform
;
5933 gfx::Transform start_scale
;
5934 start_scale
.Scale(1.5f
, 1.5f
);
5935 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5936 gfx::PointF(), gfx::Size(50, 50), true, false,
5938 SetLayerPropertiesForTesting(animated_layer
, start_scale
, gfx::Point3F(),
5939 gfx::PointF(), gfx::Size(50, 50), true, false,
5941 SetLayerPropertiesForTesting(surface
, identity_transform
, gfx::Point3F(),
5942 gfx::PointF(), gfx::Size(50, 50), true, false,
5944 SetLayerPropertiesForTesting(container
, identity_transform
, gfx::Point3F(),
5945 gfx::PointF(), gfx::Size(50, 50), true, false,
5947 SetLayerPropertiesForTesting(scroller
, identity_transform
, gfx::Point3F(),
5948 gfx::PointF(), gfx::Size(100, 100), true, false,
5951 gfx::Transform end_scale
;
5952 end_scale
.Scale(2.f
, 2.f
);
5953 TransformOperations start_operations
;
5954 start_operations
.AppendMatrix(start_scale
);
5955 TransformOperations end_operations
;
5956 end_operations
.AppendMatrix(end_scale
);
5957 AddAnimatedTransformToLayer(animated_layer
, 1.0, start_operations
,
5960 gfx::Vector2dF
scroll_delta(5.f
, 9.f
);
5961 scroller
->SetScrollDelta(scroll_delta
);
5963 ExecuteCalculateDrawProperties(root
);
5965 gfx::Vector2dF
expected_draw_transform_translation(-7.5f
, -13.5f
);
5966 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation
,
5967 scroller
->draw_transform().To2dTranslation());
5970 class AnimationScaleFactorTrackingLayerImpl
: public LayerImpl
{
5972 static scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> Create(
5973 LayerTreeImpl
* tree_impl
,
5975 return make_scoped_ptr(
5976 new AnimationScaleFactorTrackingLayerImpl(tree_impl
, id
));
5979 ~AnimationScaleFactorTrackingLayerImpl() override
{}
5982 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl
* tree_impl
,
5984 : LayerImpl(tree_impl
, id
) {
5985 SetDrawsContent(true);
5989 TEST_F(LayerTreeHostCommonTest
, MaximumAnimationScaleFactor
) {
5990 FakeImplProxy proxy
;
5991 TestSharedBitmapManager shared_bitmap_manager
;
5992 TestTaskGraphRunner task_graph_runner
;
5993 LayerTreeSettings settings
;
5994 settings
.layer_transforms_should_scale_layer_contents
= true;
5995 FakeLayerTreeHostImpl
host_impl(settings
, &proxy
, &shared_bitmap_manager
,
5996 &task_graph_runner
);
5997 gfx::Transform identity_matrix
;
5998 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_parent
=
5999 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 1);
6000 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> parent
=
6001 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 2);
6002 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> child
=
6003 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 3);
6004 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_child
=
6005 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 4);
6007 AnimationScaleFactorTrackingLayerImpl
* parent_raw
= parent
.get();
6008 AnimationScaleFactorTrackingLayerImpl
* child_raw
= child
.get();
6009 AnimationScaleFactorTrackingLayerImpl
* grand_child_raw
= grand_child
.get();
6011 child
->AddChild(grand_child
.Pass());
6012 parent
->AddChild(child
.Pass());
6013 grand_parent
->AddChild(parent
.Pass());
6015 SetLayerPropertiesForTesting(grand_parent
.get(), identity_matrix
,
6016 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6018 SetLayerPropertiesForTesting(parent_raw
, identity_matrix
, gfx::Point3F(),
6019 gfx::PointF(), gfx::Size(1, 2), true, false,
6021 SetLayerPropertiesForTesting(child_raw
, identity_matrix
, gfx::Point3F(),
6022 gfx::PointF(), gfx::Size(1, 2), true, false,
6025 SetLayerPropertiesForTesting(grand_child_raw
, identity_matrix
, gfx::Point3F(),
6026 gfx::PointF(), gfx::Size(1, 2), true, false,
6029 ExecuteCalculateDrawProperties(grand_parent
.get());
6031 // No layers have animations.
6033 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6035 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6036 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6038 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6041 grand_parent
->draw_properties().starting_animation_contents_scale
);
6043 parent_raw
->draw_properties().starting_animation_contents_scale
);
6045 child_raw
->draw_properties().starting_animation_contents_scale
);
6048 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6050 TransformOperations translation
;
6051 translation
.AppendTranslate(1.f
, 2.f
, 3.f
);
6053 AddAnimatedTransformToLayer(
6054 parent_raw
, 1.0, TransformOperations(), translation
);
6056 // No layers have scale-affecting animations.
6058 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6060 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6061 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6063 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6066 grand_parent
->draw_properties().starting_animation_contents_scale
);
6068 parent_raw
->draw_properties().starting_animation_contents_scale
);
6070 child_raw
->draw_properties().starting_animation_contents_scale
);
6073 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6075 TransformOperations scale
;
6076 scale
.AppendScale(5.f
, 4.f
, 3.f
);
6078 AddAnimatedTransformToLayer(child_raw
, 1.0, TransformOperations(), scale
);
6079 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6080 ExecuteCalculateDrawProperties(grand_parent
.get());
6082 // Only |child| has a scale-affecting animation.
6084 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6086 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6087 EXPECT_EQ(5.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6089 5.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6092 grand_parent
->draw_properties().starting_animation_contents_scale
);
6094 parent_raw
->draw_properties().starting_animation_contents_scale
);
6096 child_raw
->draw_properties().starting_animation_contents_scale
);
6099 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6101 AddAnimatedTransformToLayer(
6102 grand_parent
.get(), 1.0, TransformOperations(), scale
);
6103 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6104 ExecuteCalculateDrawProperties(grand_parent
.get());
6106 // |grand_parent| and |child| have scale-affecting animations.
6108 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6110 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6111 // We don't support combining animated scales from two nodes; 0.f means
6112 // that the maximum scale could not be computed.
6113 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6115 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6118 grand_parent
->draw_properties().starting_animation_contents_scale
);
6120 parent_raw
->draw_properties().starting_animation_contents_scale
);
6122 child_raw
->draw_properties().starting_animation_contents_scale
);
6125 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6127 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
6128 parent_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6129 ExecuteCalculateDrawProperties(grand_parent
.get());
6131 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
6133 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6135 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6136 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6138 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6141 grand_parent
->draw_properties().starting_animation_contents_scale
);
6143 parent_raw
->draw_properties().starting_animation_contents_scale
);
6145 child_raw
->draw_properties().starting_animation_contents_scale
);
6148 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6150 grand_parent
->layer_animation_controller()->AbortAnimations(
6151 Animation::TRANSFORM
);
6152 parent_raw
->layer_animation_controller()->AbortAnimations(
6153 Animation::TRANSFORM
);
6154 child_raw
->layer_animation_controller()->AbortAnimations(
6155 Animation::TRANSFORM
);
6157 TransformOperations perspective
;
6158 perspective
.AppendPerspective(10.f
);
6160 AddAnimatedTransformToLayer(
6161 child_raw
, 1.0, TransformOperations(), perspective
);
6162 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6163 ExecuteCalculateDrawProperties(grand_parent
.get());
6165 // |child| has a scale-affecting animation but computing the maximum of this
6166 // animation is not supported.
6168 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6170 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6171 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6173 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6176 grand_parent
->draw_properties().starting_animation_contents_scale
);
6178 parent_raw
->draw_properties().starting_animation_contents_scale
);
6180 child_raw
->draw_properties().starting_animation_contents_scale
);
6183 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6185 child_raw
->layer_animation_controller()->AbortAnimations(
6186 Animation::TRANSFORM
);
6188 gfx::Transform scale_matrix
;
6189 scale_matrix
.Scale(1.f
, 2.f
);
6190 grand_parent
->SetTransform(scale_matrix
);
6191 parent_raw
->SetTransform(scale_matrix
);
6192 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6193 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
6194 ExecuteCalculateDrawProperties(grand_parent
.get());
6196 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
6197 // animation with maximum scale 5.f.
6199 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6201 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6203 child_raw
->draw_properties().maximum_animation_contents_scale
);
6206 grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6209 grand_parent
->draw_properties().starting_animation_contents_scale
);
6211 parent_raw
->draw_properties().starting_animation_contents_scale
);
6213 child_raw
->draw_properties().starting_animation_contents_scale
);
6216 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6218 gfx::Transform perspective_matrix
;
6219 perspective_matrix
.ApplyPerspectiveDepth(2.f
);
6220 child_raw
->SetTransform(perspective_matrix
);
6221 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6222 ExecuteCalculateDrawProperties(grand_parent
.get());
6224 // |child| has a transform that's neither a translation nor a scale.
6226 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6228 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6229 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6231 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6234 grand_parent
->draw_properties().starting_animation_contents_scale
);
6236 parent_raw
->draw_properties().starting_animation_contents_scale
);
6238 child_raw
->draw_properties().starting_animation_contents_scale
);
6241 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6243 parent_raw
->SetTransform(perspective_matrix
);
6244 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6245 ExecuteCalculateDrawProperties(grand_parent
.get());
6247 // |parent| and |child| have transforms that are neither translations nor
6250 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6252 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6253 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6255 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6258 grand_parent
->draw_properties().starting_animation_contents_scale
);
6260 parent_raw
->draw_properties().starting_animation_contents_scale
);
6262 child_raw
->draw_properties().starting_animation_contents_scale
);
6265 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6267 parent_raw
->SetTransform(identity_matrix
);
6268 child_raw
->SetTransform(identity_matrix
);
6269 grand_parent
->SetTransform(perspective_matrix
);
6270 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6272 ExecuteCalculateDrawProperties(grand_parent
.get());
6274 // |grand_parent| has a transform that's neither a translation nor a scale.
6276 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6278 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6279 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6281 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6284 grand_parent
->draw_properties().starting_animation_contents_scale
);
6286 parent_raw
->draw_properties().starting_animation_contents_scale
);
6288 child_raw
->draw_properties().starting_animation_contents_scale
);
6291 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6294 static int membership_id(LayerImpl
* layer
) {
6295 return layer
->draw_properties().last_drawn_render_surface_layer_list_id
;
6298 static void GatherDrawnLayers(LayerImplList
* rsll
,
6299 std::set
<LayerImpl
*>* drawn_layers
) {
6300 for (LayerIterator it
= LayerIterator::Begin(rsll
),
6301 end
= LayerIterator::End(rsll
);
6303 LayerImpl
* layer
= *it
;
6304 if (it
.represents_itself())
6305 drawn_layers
->insert(layer
);
6307 if (!it
.represents_contributing_render_surface())
6310 if (layer
->mask_layer())
6311 drawn_layers
->insert(layer
->mask_layer());
6312 if (layer
->replica_layer() && layer
->replica_layer()->mask_layer())
6313 drawn_layers
->insert(layer
->replica_layer()->mask_layer());
6317 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceLayerListMembership
) {
6318 FakeImplProxy proxy
;
6319 TestSharedBitmapManager shared_bitmap_manager
;
6320 TestTaskGraphRunner task_graph_runner
;
6321 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
6322 &task_graph_runner
);
6323 gfx::Transform identity_matrix
;
6325 scoped_ptr
<LayerImpl
> grand_parent
=
6326 LayerImpl::Create(host_impl
.active_tree(), 1);
6327 scoped_ptr
<LayerImpl
> parent
= LayerImpl::Create(host_impl
.active_tree(), 3);
6328 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 5);
6329 scoped_ptr
<LayerImpl
> grand_child1
=
6330 LayerImpl::Create(host_impl
.active_tree(), 7);
6331 scoped_ptr
<LayerImpl
> grand_child2
=
6332 LayerImpl::Create(host_impl
.active_tree(), 9);
6334 LayerImpl
* grand_parent_raw
= grand_parent
.get();
6335 LayerImpl
* parent_raw
= parent
.get();
6336 LayerImpl
* child_raw
= child
.get();
6337 LayerImpl
* grand_child1_raw
= grand_child1
.get();
6338 LayerImpl
* grand_child2_raw
= grand_child2
.get();
6340 child
->AddChild(grand_child1
.Pass());
6341 child
->AddChild(grand_child2
.Pass());
6342 parent
->AddChild(child
.Pass());
6343 grand_parent
->AddChild(parent
.Pass());
6345 SetLayerPropertiesForTesting(grand_parent_raw
, identity_matrix
,
6346 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6348 SetLayerPropertiesForTesting(parent_raw
, identity_matrix
, gfx::Point3F(),
6349 gfx::PointF(), gfx::Size(1, 2), true, false,
6352 SetLayerPropertiesForTesting(child_raw
, identity_matrix
, gfx::Point3F(),
6353 gfx::PointF(), gfx::Size(1, 2), true, false,
6356 SetLayerPropertiesForTesting(grand_child1_raw
, identity_matrix
,
6357 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6358 true, false, false);
6360 SetLayerPropertiesForTesting(grand_child2_raw
, identity_matrix
,
6361 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6362 true, false, false);
6364 // Start with nothing being drawn.
6365 ExecuteCalculateDrawProperties(grand_parent_raw
);
6366 int member_id
= render_surface_layer_list_count();
6368 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6369 EXPECT_NE(member_id
, membership_id(parent_raw
));
6370 EXPECT_NE(member_id
, membership_id(child_raw
));
6371 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6372 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6374 std::set
<LayerImpl
*> expected
;
6375 std::set
<LayerImpl
*> actual
;
6376 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6377 EXPECT_EQ(expected
, actual
);
6379 // If we force render surface, but none of the layers are in the layer list,
6380 // then this layer should not appear in RSLL.
6381 grand_child1_raw
->SetHasRenderSurface(true);
6382 grand_child1_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6384 ExecuteCalculateDrawProperties(grand_parent_raw
);
6385 member_id
= render_surface_layer_list_count();
6387 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6388 EXPECT_NE(member_id
, membership_id(parent_raw
));
6389 EXPECT_NE(member_id
, membership_id(child_raw
));
6390 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6391 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6395 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6396 EXPECT_EQ(expected
, actual
);
6398 // However, if we say that this layer also draws content, it will appear in
6400 grand_child1_raw
->SetDrawsContent(true);
6402 ExecuteCalculateDrawProperties(grand_parent_raw
);
6403 member_id
= render_surface_layer_list_count();
6405 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6406 EXPECT_NE(member_id
, membership_id(parent_raw
));
6407 EXPECT_NE(member_id
, membership_id(child_raw
));
6408 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
6409 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6412 expected
.insert(grand_child1_raw
);
6415 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6416 EXPECT_EQ(expected
, actual
);
6418 // Now child is forced to have a render surface, and one if its children draws
6420 grand_child1_raw
->SetDrawsContent(false);
6421 grand_child1_raw
->SetHasRenderSurface(false);
6422 grand_child1_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6423 child_raw
->SetHasRenderSurface(true);
6424 grand_child2_raw
->SetDrawsContent(true);
6426 ExecuteCalculateDrawProperties(grand_parent_raw
);
6427 member_id
= render_surface_layer_list_count();
6429 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6430 EXPECT_NE(member_id
, membership_id(parent_raw
));
6431 EXPECT_NE(member_id
, membership_id(child_raw
));
6432 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6433 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6436 expected
.insert(grand_child2_raw
);
6439 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6440 EXPECT_EQ(expected
, actual
);
6442 // Add a mask layer to child.
6443 child_raw
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6).Pass());
6444 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6446 ExecuteCalculateDrawProperties(grand_parent_raw
);
6447 member_id
= render_surface_layer_list_count();
6449 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6450 EXPECT_NE(member_id
, membership_id(parent_raw
));
6451 EXPECT_NE(member_id
, membership_id(child_raw
));
6452 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
6453 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6454 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6457 expected
.insert(grand_child2_raw
);
6458 expected
.insert(child_raw
->mask_layer());
6461 expected
.insert(grand_child2_raw
);
6462 expected
.insert(child_raw
->mask_layer());
6465 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6466 EXPECT_EQ(expected
, actual
);
6468 // Add replica mask layer.
6469 scoped_ptr
<LayerImpl
> replica_layer
=
6470 LayerImpl::Create(host_impl
.active_tree(), 20);
6471 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 21));
6472 child_raw
->SetReplicaLayer(replica_layer
.Pass());
6473 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6475 ExecuteCalculateDrawProperties(grand_parent_raw
);
6476 member_id
= render_surface_layer_list_count();
6478 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6479 EXPECT_NE(member_id
, membership_id(parent_raw
));
6480 EXPECT_NE(member_id
, membership_id(child_raw
));
6481 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
6482 EXPECT_EQ(member_id
, membership_id(child_raw
->replica_layer()->mask_layer()));
6483 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6484 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6487 expected
.insert(grand_child2_raw
);
6488 expected
.insert(child_raw
->mask_layer());
6489 expected
.insert(child_raw
->replica_layer()->mask_layer());
6492 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6493 EXPECT_EQ(expected
, actual
);
6495 child_raw
->TakeReplicaLayer();
6497 // With nothing drawing, we should have no layers.
6498 grand_child2_raw
->SetDrawsContent(false);
6500 ExecuteCalculateDrawProperties(grand_parent_raw
);
6501 member_id
= render_surface_layer_list_count();
6503 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6504 EXPECT_NE(member_id
, membership_id(parent_raw
));
6505 EXPECT_NE(member_id
, membership_id(child_raw
));
6506 EXPECT_NE(member_id
, membership_id(child_raw
->mask_layer()));
6507 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6508 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6512 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6513 EXPECT_EQ(expected
, actual
);
6515 // Child itself draws means that we should have the child and the mask in the
6517 child_raw
->SetDrawsContent(true);
6519 ExecuteCalculateDrawProperties(grand_parent_raw
);
6520 member_id
= render_surface_layer_list_count();
6522 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6523 EXPECT_NE(member_id
, membership_id(parent_raw
));
6524 EXPECT_EQ(member_id
, membership_id(child_raw
));
6525 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
6526 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6527 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6530 expected
.insert(child_raw
);
6531 expected
.insert(child_raw
->mask_layer());
6533 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6534 EXPECT_EQ(expected
, actual
);
6536 child_raw
->TakeMaskLayer();
6537 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6539 // Now everyone's a member!
6540 grand_parent_raw
->SetDrawsContent(true);
6541 parent_raw
->SetDrawsContent(true);
6542 child_raw
->SetDrawsContent(true);
6543 grand_child1_raw
->SetDrawsContent(true);
6544 grand_child2_raw
->SetDrawsContent(true);
6546 ExecuteCalculateDrawProperties(grand_parent_raw
);
6547 member_id
= render_surface_layer_list_count();
6549 EXPECT_EQ(member_id
, membership_id(grand_parent_raw
));
6550 EXPECT_EQ(member_id
, membership_id(parent_raw
));
6551 EXPECT_EQ(member_id
, membership_id(child_raw
));
6552 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
6553 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6556 expected
.insert(grand_parent_raw
);
6557 expected
.insert(parent_raw
);
6558 expected
.insert(child_raw
);
6559 expected
.insert(grand_child1_raw
);
6560 expected
.insert(grand_child2_raw
);
6563 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6564 EXPECT_EQ(expected
, actual
);
6567 TEST_F(LayerTreeHostCommonTest
, DrawPropertyScales
) {
6568 FakeImplProxy proxy
;
6569 TestSharedBitmapManager shared_bitmap_manager
;
6570 TestTaskGraphRunner task_graph_runner
;
6571 LayerTreeSettings settings
;
6572 settings
.layer_transforms_should_scale_layer_contents
= true;
6573 FakeLayerTreeHostImpl
host_impl(settings
, &proxy
, &shared_bitmap_manager
,
6574 &task_graph_runner
);
6576 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
6577 LayerImpl
* root_layer
= root
.get();
6578 scoped_ptr
<LayerImpl
> child1
= LayerImpl::Create(host_impl
.active_tree(), 2);
6579 LayerImpl
* child1_layer
= child1
.get();
6580 scoped_ptr
<LayerImpl
> child2
= LayerImpl::Create(host_impl
.active_tree(), 3);
6581 LayerImpl
* child2_layer
= child2
.get();
6583 root
->AddChild(child1
.Pass());
6584 root
->AddChild(child2
.Pass());
6585 root
->SetHasRenderSurface(true);
6587 gfx::Transform identity_matrix
, scale_transform_child1
,
6588 scale_transform_child2
;
6589 scale_transform_child1
.Scale(2, 3);
6590 scale_transform_child2
.Scale(4, 5);
6592 SetLayerPropertiesForTesting(root_layer
, identity_matrix
, gfx::Point3F(),
6593 gfx::PointF(), gfx::Size(1, 1), true, false,
6595 SetLayerPropertiesForTesting(child1_layer
, scale_transform_child1
,
6596 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
6599 child1_layer
->SetMaskLayer(
6600 LayerImpl::Create(host_impl
.active_tree(), 4).Pass());
6602 scoped_ptr
<LayerImpl
> replica_layer
=
6603 LayerImpl::Create(host_impl
.active_tree(), 5);
6604 replica_layer
->SetHasRenderSurface(true);
6605 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6));
6606 child1_layer
->SetReplicaLayer(replica_layer
.Pass());
6607 child1_layer
->SetHasRenderSurface(true);
6609 ExecuteCalculateDrawProperties(root_layer
);
6611 TransformOperations scale
;
6612 scale
.AppendScale(5.f
, 8.f
, 3.f
);
6614 AddAnimatedTransformToLayer(child2_layer
, 1.0, TransformOperations(), scale
);
6615 SetLayerPropertiesForTesting(child2_layer
, scale_transform_child2
,
6616 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
6619 ExecuteCalculateDrawProperties(root_layer
);
6621 EXPECT_FLOAT_EQ(1.f
, root_layer
->GetIdealContentsScale());
6622 EXPECT_FLOAT_EQ(3.f
, child1_layer
->GetIdealContentsScale());
6623 EXPECT_FLOAT_EQ(3.f
, child1_layer
->mask_layer()->GetIdealContentsScale());
6624 EXPECT_FLOAT_EQ(5.f
, child2_layer
->GetIdealContentsScale());
6627 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
6629 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
6630 EXPECT_FLOAT_EQ(0.f
,
6631 child1_layer
->mask_layer()
6633 .maximum_animation_contents_scale
);
6634 EXPECT_FLOAT_EQ(0.f
,
6635 child1_layer
->replica_layer()
6638 .maximum_animation_contents_scale
);
6640 8.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
6642 // Changing page-scale would affect ideal_contents_scale and
6643 // maximum_animation_contents_scale.
6645 float page_scale_factor
= 3.f
;
6646 float device_scale_factor
= 1.0f
;
6647 std::vector
<LayerImpl
*> render_surface_layer_list
;
6648 gfx::Size device_viewport_size
=
6649 gfx::Size(root_layer
->bounds().width() * device_scale_factor
,
6650 root_layer
->bounds().height() * device_scale_factor
);
6651 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6652 root_layer
, device_viewport_size
, &render_surface_layer_list
);
6654 inputs
.page_scale_factor
= page_scale_factor
;
6655 inputs
.can_adjust_raster_scales
= true;
6656 inputs
.page_scale_layer
= root_layer
;
6657 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6659 EXPECT_FLOAT_EQ(3.f
, root_layer
->GetIdealContentsScale());
6660 EXPECT_FLOAT_EQ(9.f
, child1_layer
->GetIdealContentsScale());
6661 EXPECT_FLOAT_EQ(9.f
, child1_layer
->mask_layer()->GetIdealContentsScale());
6664 child1_layer
->replica_layer()->mask_layer()->GetIdealContentsScale());
6665 EXPECT_FLOAT_EQ(15.f
, child2_layer
->GetIdealContentsScale());
6668 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
6670 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
6671 EXPECT_FLOAT_EQ(0.f
,
6672 child1_layer
->mask_layer()
6674 .maximum_animation_contents_scale
);
6675 EXPECT_FLOAT_EQ(0.f
,
6676 child1_layer
->replica_layer()
6679 .maximum_animation_contents_scale
);
6681 24.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
6683 // Changing device-scale would affect ideal_contents_scale and
6684 // maximum_animation_contents_scale.
6686 device_scale_factor
= 4.0f
;
6687 inputs
.device_scale_factor
= device_scale_factor
;
6688 inputs
.can_adjust_raster_scales
= true;
6689 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6691 EXPECT_FLOAT_EQ(12.f
, root_layer
->GetIdealContentsScale());
6692 EXPECT_FLOAT_EQ(36.f
, child1_layer
->GetIdealContentsScale());
6693 EXPECT_FLOAT_EQ(36.f
, child1_layer
->mask_layer()->GetIdealContentsScale());
6696 child1_layer
->replica_layer()->mask_layer()->GetIdealContentsScale());
6697 EXPECT_FLOAT_EQ(60.f
, child2_layer
->GetIdealContentsScale());
6700 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
6702 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
6703 EXPECT_FLOAT_EQ(0.f
,
6704 child1_layer
->mask_layer()
6706 .maximum_animation_contents_scale
);
6707 EXPECT_FLOAT_EQ(0.f
,
6708 child1_layer
->replica_layer()
6711 .maximum_animation_contents_scale
);
6713 96.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
6716 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInChildRenderSurface
) {
6717 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6718 SetLayerPropertiesForTesting(root
.get(),
6722 gfx::Size(768 / 2, 3000),
6725 root
->SetIsDrawable(true);
6727 scoped_refptr
<Layer
> clip
= Layer::Create(layer_settings());
6728 SetLayerPropertiesForTesting(clip
.get(),
6732 gfx::Size(768 / 2, 10000),
6735 clip
->SetMasksToBounds(true);
6737 scoped_refptr
<Layer
> content
= Layer::Create(layer_settings());
6738 SetLayerPropertiesForTesting(content
.get(),
6742 gfx::Size(768 / 2, 10000),
6745 content
->SetIsDrawable(true);
6746 content
->SetForceRenderSurface(true);
6748 root
->AddChild(clip
);
6749 clip
->AddChild(content
);
6751 host()->SetRootLayer(root
);
6753 gfx::Size
device_viewport_size(768, 582);
6754 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(host()->root_layer(),
6755 device_viewport_size
);
6756 inputs
.device_scale_factor
= 2.f
;
6757 inputs
.page_scale_factor
= 1.f
;
6758 inputs
.page_scale_layer
= NULL
;
6759 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6761 // Layers in the root render surface have their visible content rect clipped
6763 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
6764 root
->visible_rect_from_property_trees());
6766 // Layers drawing to a child render surface should still have their visible
6767 // content rect clipped by the viewport.
6768 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
6769 content
->visible_rect_from_property_trees());
6772 TEST_F(LayerTreeHostCommonTest
, BoundsDeltaAffectVisibleContentRect
) {
6773 FakeImplProxy proxy
;
6774 TestSharedBitmapManager shared_bitmap_manager
;
6775 TestTaskGraphRunner task_graph_runner
;
6776 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
6777 &task_graph_runner
);
6779 // Set two layers: the root layer clips it's child,
6780 // the child draws its content.
6782 gfx::Size root_size
= gfx::Size(300, 500);
6784 // Sublayer should be bigger than the root enlarged by bounds_delta.
6785 gfx::Size sublayer_size
= gfx::Size(300, 1000);
6787 // Device viewport accomidated the root and the top controls.
6788 gfx::Size device_viewport_size
= gfx::Size(300, 600);
6789 gfx::Transform identity_matrix
;
6791 host_impl
.SetViewportSize(device_viewport_size
);
6792 host_impl
.active_tree()->SetRootLayer(
6793 LayerImpl::Create(host_impl
.active_tree(), 1));
6795 LayerImpl
* root
= host_impl
.active_tree()->root_layer();
6796 SetLayerPropertiesForTesting(root
,
6804 root
->SetMasksToBounds(true);
6806 root
->AddChild(LayerImpl::Create(host_impl
.active_tree(), 2));
6808 LayerImpl
* sublayer
= root
->child_at(0);
6809 SetLayerPropertiesForTesting(sublayer
,
6817 sublayer
->SetDrawsContent(true);
6819 LayerImplList layer_impl_list
;
6820 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6821 root
, device_viewport_size
, &layer_impl_list
);
6823 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6824 EXPECT_EQ(gfx::Rect(root_size
), sublayer
->visible_layer_rect());
6826 root
->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
6827 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6829 gfx::Rect
affected_by_delta(0, 0, root_size
.width(),
6830 root_size
.height() + 50);
6831 EXPECT_EQ(affected_by_delta
, sublayer
->visible_layer_rect());
6834 TEST_F(LayerTreeHostCommonTest
, NodesAffectedByBoundsDeltaGetUpdated
) {
6835 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6836 scoped_refptr
<Layer
> inner_viewport_container_layer
=
6837 Layer::Create(layer_settings());
6838 scoped_refptr
<Layer
> inner_viewport_scroll_layer
=
6839 Layer::Create(layer_settings());
6840 scoped_refptr
<Layer
> outer_viewport_container_layer
=
6841 Layer::Create(layer_settings());
6842 scoped_refptr
<Layer
> outer_viewport_scroll_layer
=
6843 Layer::Create(layer_settings());
6845 root
->AddChild(inner_viewport_container_layer
);
6846 inner_viewport_container_layer
->AddChild(inner_viewport_scroll_layer
);
6847 inner_viewport_scroll_layer
->AddChild(outer_viewport_container_layer
);
6848 outer_viewport_container_layer
->AddChild(outer_viewport_scroll_layer
);
6850 inner_viewport_scroll_layer
->SetScrollClipLayerId(
6851 inner_viewport_container_layer
->id());
6852 outer_viewport_scroll_layer
->SetScrollClipLayerId(
6853 outer_viewport_container_layer
->id());
6855 inner_viewport_scroll_layer
->SetIsContainerForFixedPositionLayers(true);
6856 outer_viewport_scroll_layer
->SetIsContainerForFixedPositionLayers(true);
6858 host()->SetRootLayer(root
);
6859 host()->RegisterViewportLayers(nullptr, root
, inner_viewport_scroll_layer
,
6860 outer_viewport_scroll_layer
);
6862 scoped_refptr
<Layer
> fixed_to_inner
= Layer::Create(layer_settings());
6863 scoped_refptr
<Layer
> fixed_to_outer
= Layer::Create(layer_settings());
6865 inner_viewport_scroll_layer
->AddChild(fixed_to_inner
);
6866 outer_viewport_scroll_layer
->AddChild(fixed_to_outer
);
6868 LayerPositionConstraint fixed_to_right
;
6869 fixed_to_right
.set_is_fixed_position(true);
6870 fixed_to_right
.set_is_fixed_to_right_edge(true);
6872 fixed_to_inner
->SetPositionConstraint(fixed_to_right
);
6873 fixed_to_outer
->SetPositionConstraint(fixed_to_right
);
6875 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6877 TransformTree
& transform_tree
= host()->property_trees()->transform_tree
;
6878 EXPECT_TRUE(transform_tree
.HasNodesAffectedByInnerViewportBoundsDelta());
6879 EXPECT_TRUE(transform_tree
.HasNodesAffectedByOuterViewportBoundsDelta());
6881 LayerPositionConstraint fixed_to_left
;
6882 fixed_to_left
.set_is_fixed_position(true);
6883 fixed_to_inner
->SetPositionConstraint(fixed_to_left
);
6885 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6886 EXPECT_FALSE(transform_tree
.HasNodesAffectedByInnerViewportBoundsDelta());
6887 EXPECT_TRUE(transform_tree
.HasNodesAffectedByOuterViewportBoundsDelta());
6889 fixed_to_outer
->SetPositionConstraint(fixed_to_left
);
6891 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6892 EXPECT_FALSE(transform_tree
.HasNodesAffectedByInnerViewportBoundsDelta());
6893 EXPECT_FALSE(transform_tree
.HasNodesAffectedByOuterViewportBoundsDelta());
6896 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectForAnimatedLayer
) {
6897 const gfx::Transform identity_matrix
;
6898 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6899 scoped_refptr
<LayerWithForcedDrawsContent
> animated
=
6900 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6902 root
->AddChild(animated
);
6904 host()->SetRootLayer(root
);
6906 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
6907 gfx::PointF(), gfx::Size(100, 100), true, false);
6908 SetLayerPropertiesForTesting(animated
.get(), identity_matrix
, gfx::Point3F(),
6909 gfx::PointF(), gfx::Size(20, 20), true, false);
6911 root
->SetMasksToBounds(true);
6912 root
->SetForceRenderSurface(true);
6913 animated
->SetOpacity(0.f
);
6915 AddOpacityTransitionToController(animated
->layer_animation_controller(), 10.0,
6918 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6920 EXPECT_FALSE(animated
->visible_rect_from_property_trees().IsEmpty());
6923 TEST_F(LayerTreeHostCommonTest
,
6924 VisibleContentRectForAnimatedLayerWithSingularTransform
) {
6925 const gfx::Transform identity_matrix
;
6926 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6927 scoped_refptr
<Layer
> clip
= Layer::Create(layer_settings());
6928 scoped_refptr
<LayerWithForcedDrawsContent
> animated
=
6929 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6930 scoped_refptr
<LayerWithForcedDrawsContent
> surface
=
6931 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6932 scoped_refptr
<LayerWithForcedDrawsContent
> descendant_of_animation
=
6933 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6935 root
->AddChild(clip
);
6936 clip
->AddChild(animated
);
6937 animated
->AddChild(surface
);
6938 surface
->AddChild(descendant_of_animation
);
6940 clip
->SetMasksToBounds(true);
6941 surface
->SetForceRenderSurface(true);
6943 host()->SetRootLayer(root
);
6945 gfx::Transform uninvertible_matrix
;
6946 uninvertible_matrix
.Scale3d(6.f
, 6.f
, 0.f
);
6948 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
6949 gfx::PointF(), gfx::Size(100, 100), true, false);
6950 SetLayerPropertiesForTesting(clip
.get(), identity_matrix
, gfx::Point3F(),
6951 gfx::PointF(), gfx::Size(10, 10), true, false);
6952 SetLayerPropertiesForTesting(animated
.get(), uninvertible_matrix
,
6953 gfx::Point3F(), gfx::PointF(),
6954 gfx::Size(120, 120), true, false);
6955 SetLayerPropertiesForTesting(surface
.get(), identity_matrix
, gfx::Point3F(),
6956 gfx::PointF(), gfx::Size(100, 100), true, false);
6957 SetLayerPropertiesForTesting(descendant_of_animation
.get(), identity_matrix
,
6958 gfx::Point3F(), gfx::PointF(),
6959 gfx::Size(200, 200), true, false);
6961 TransformOperations start_transform_operations
;
6962 start_transform_operations
.AppendMatrix(uninvertible_matrix
);
6963 TransformOperations end_transform_operations
;
6965 AddAnimatedTransformToLayer(animated
.get(), 10.0, start_transform_operations
,
6966 end_transform_operations
);
6968 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6970 // The animated layer has a singular transform and maps to a non-empty rect in
6971 // clipped target space, so is treated as fully visible.
6972 EXPECT_EQ(gfx::Rect(120, 120), animated
->visible_rect_from_property_trees());
6974 // The singular transform on |animated| is flattened when inherited by
6975 // |surface|, and this happens to make it invertible.
6976 EXPECT_EQ(gfx::Rect(2, 2), surface
->visible_rect_from_property_trees());
6977 EXPECT_EQ(gfx::Rect(2, 2),
6978 descendant_of_animation
->visible_rect_from_property_trees());
6980 gfx::Transform zero_matrix
;
6981 zero_matrix
.Scale3d(0.f
, 0.f
, 0.f
);
6982 SetLayerPropertiesForTesting(animated
.get(), zero_matrix
, gfx::Point3F(),
6983 gfx::PointF(), gfx::Size(120, 120), true, false);
6985 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6987 // The animated layer maps to the empty rect in clipped target space, so is
6988 // treated as having an empty visible rect.
6989 EXPECT_EQ(gfx::Rect(), animated
->visible_rect_from_property_trees());
6991 // This time, flattening does not make |animated|'s transform invertible. This
6992 // means the clip cannot be projected into |surface|'s space, so we treat
6993 // |surface| and layers that draw into it as having empty visible rect.
6994 EXPECT_EQ(gfx::Rect(), surface
->visible_rect_from_property_trees());
6995 EXPECT_EQ(gfx::Rect(),
6996 descendant_of_animation
->visible_rect_from_property_trees());
6999 // Verify that having an animated filter (but no current filter, as these
7000 // are mutually exclusive) correctly creates a render surface.
7001 TEST_F(LayerTreeHostCommonTest
, AnimatedFilterCreatesRenderSurface
) {
7002 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7003 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7004 scoped_refptr
<Layer
> grandchild
= Layer::Create(layer_settings());
7005 root
->AddChild(child
);
7006 child
->AddChild(grandchild
);
7008 gfx::Transform identity_transform
;
7009 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7010 gfx::PointF(), gfx::Size(50, 50), true, false);
7011 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7012 gfx::PointF(), gfx::Size(50, 50), true, false);
7013 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7014 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7016 host()->SetRootLayer(root
);
7018 AddAnimatedFilterToLayer(child
.get(), 10.0, 0.1f
, 0.2f
);
7020 ExecuteCalculateDrawProperties(root
.get());
7022 EXPECT_TRUE(root
->has_render_surface());
7023 EXPECT_TRUE(child
->has_render_surface());
7024 EXPECT_FALSE(grandchild
->has_render_surface());
7026 EXPECT_TRUE(root
->filters().IsEmpty());
7027 EXPECT_TRUE(child
->filters().IsEmpty());
7028 EXPECT_TRUE(grandchild
->filters().IsEmpty());
7030 EXPECT_FALSE(root
->FilterIsAnimating());
7031 EXPECT_TRUE(child
->FilterIsAnimating());
7032 EXPECT_FALSE(grandchild
->FilterIsAnimating());
7035 // Verify that having a filter animation with a delayed start time creates a
7037 TEST_F(LayerTreeHostCommonTest
, DelayedFilterAnimationCreatesRenderSurface
) {
7038 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7039 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7040 scoped_refptr
<Layer
> grandchild
= Layer::Create(layer_settings());
7041 root
->AddChild(child
);
7042 child
->AddChild(grandchild
);
7044 gfx::Transform identity_transform
;
7045 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7046 gfx::PointF(), gfx::Size(50, 50), true, false);
7047 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7048 gfx::PointF(), gfx::Size(50, 50), true, false);
7049 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7050 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7052 host()->SetRootLayer(root
);
7054 scoped_ptr
<KeyframedFilterAnimationCurve
> curve(
7055 KeyframedFilterAnimationCurve::Create());
7056 FilterOperations start_filters
;
7057 start_filters
.Append(FilterOperation::CreateBrightnessFilter(0.1f
));
7058 FilterOperations end_filters
;
7059 end_filters
.Append(FilterOperation::CreateBrightnessFilter(0.3f
));
7061 FilterKeyframe::Create(base::TimeDelta(), start_filters
, nullptr));
7062 curve
->AddKeyframe(FilterKeyframe::Create(
7063 base::TimeDelta::FromMilliseconds(100), end_filters
, nullptr));
7064 scoped_ptr
<Animation
> animation
=
7065 Animation::Create(curve
.Pass(), 0, 1, Animation::FILTER
);
7066 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
7067 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7068 child
->layer_animation_controller()->AddAnimation(animation
.Pass());
7070 ExecuteCalculateDrawProperties(root
.get());
7072 EXPECT_TRUE(root
->has_render_surface());
7073 EXPECT_TRUE(child
->has_render_surface());
7074 EXPECT_FALSE(grandchild
->has_render_surface());
7076 EXPECT_TRUE(root
->filters().IsEmpty());
7077 EXPECT_TRUE(child
->filters().IsEmpty());
7078 EXPECT_TRUE(grandchild
->filters().IsEmpty());
7080 EXPECT_FALSE(root
->FilterIsAnimating());
7081 EXPECT_FALSE(root
->HasPotentiallyRunningFilterAnimation());
7082 EXPECT_FALSE(child
->FilterIsAnimating());
7083 EXPECT_TRUE(child
->HasPotentiallyRunningFilterAnimation());
7084 EXPECT_FALSE(grandchild
->FilterIsAnimating());
7085 EXPECT_FALSE(grandchild
->HasPotentiallyRunningFilterAnimation());
7088 // Ensures that the property tree code accounts for offsets between fixed
7089 // position layers and their respective containers.
7090 TEST_F(LayerTreeHostCommonTest
, PropertyTreesAccountForFixedParentOffset
) {
7091 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7092 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7093 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
7094 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7096 root
->AddChild(child
);
7097 child
->AddChild(grandchild
);
7099 gfx::Transform identity_transform
;
7100 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7101 gfx::PointF(), gfx::Size(50, 50), true, false);
7102 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7103 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7105 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7106 gfx::Point3F(), gfx::PointF(-1000, -1000),
7107 gfx::Size(50, 50), true, false);
7109 root
->SetMasksToBounds(true);
7110 root
->SetIsContainerForFixedPositionLayers(true);
7111 LayerPositionConstraint constraint
;
7112 constraint
.set_is_fixed_position(true);
7113 grandchild
->SetPositionConstraint(constraint
);
7115 root
->SetIsContainerForFixedPositionLayers(true);
7117 host()->SetRootLayer(root
);
7119 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7121 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7122 grandchild
->visible_rect_from_property_trees());
7125 // Ensures that the property tree code accounts for offsets between fixed
7126 // position containers and their transform tree parents, when a fixed position
7127 // layer's container is its layer tree parent, but this parent doesn't have its
7128 // own transform tree node.
7129 TEST_F(LayerTreeHostCommonTest
,
7130 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent
) {
7131 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7132 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7133 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
7134 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7136 root
->AddChild(child
);
7137 child
->AddChild(grandchild
);
7139 gfx::Transform identity_transform
;
7140 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7141 gfx::PointF(), gfx::Size(50, 50), true, false);
7142 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7143 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7145 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7146 gfx::Point3F(), gfx::PointF(-1000, -1000),
7147 gfx::Size(50, 50), true, false);
7149 root
->SetMasksToBounds(true);
7150 child
->SetIsContainerForFixedPositionLayers(true);
7151 LayerPositionConstraint constraint
;
7152 constraint
.set_is_fixed_position(true);
7153 grandchild
->SetPositionConstraint(constraint
);
7155 root
->SetIsContainerForFixedPositionLayers(true);
7157 host()->SetRootLayer(root
);
7159 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7161 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7162 grandchild
->visible_rect_from_property_trees());
7165 TEST_F(LayerTreeHostCommonTest
, CombineClipsUsingContentTarget
) {
7166 // In the following layer tree, the layer |box|'s render target is |surface|.
7167 // |surface| also creates a transform node. We want to combine clips for |box|
7168 // in the space of its target (i.e., |surface|), not its target's target. This
7169 // test ensures that happens.
7171 gfx::Transform rotate
;
7173 gfx::Transform identity
;
7175 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7176 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7177 gfx::PointF(), gfx::Size(2500, 1500), true,
7180 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7181 SetLayerPropertiesForTesting(frame_clip
.get(), identity
, gfx::Point3F(),
7182 gfx::PointF(), gfx::Size(2500, 1500), true,
7184 frame_clip
->SetMasksToBounds(true);
7186 scoped_refptr
<Layer
> rotated
= Layer::Create(layer_settings());
7187 SetLayerPropertiesForTesting(rotated
.get(), rotate
,
7188 gfx::Point3F(1250, 250, 0), gfx::PointF(),
7189 gfx::Size(2500, 500), true, false);
7191 scoped_refptr
<Layer
> surface
= Layer::Create(layer_settings());
7192 SetLayerPropertiesForTesting(surface
.get(), rotate
, gfx::Point3F(),
7193 gfx::PointF(), gfx::Size(2500, 500), true,
7195 surface
->SetOpacity(0.5);
7197 scoped_refptr
<LayerWithForcedDrawsContent
> container
=
7198 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7199 SetLayerPropertiesForTesting(container
.get(), identity
, gfx::Point3F(),
7200 gfx::PointF(), gfx::Size(300, 300), true, false);
7202 scoped_refptr
<LayerWithForcedDrawsContent
> box
=
7203 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7204 SetLayerPropertiesForTesting(box
.get(), identity
, gfx::Point3F(),
7205 gfx::PointF(), gfx::Size(100, 100), true, false);
7207 root
->AddChild(frame_clip
);
7208 frame_clip
->AddChild(rotated
);
7209 rotated
->AddChild(surface
);
7210 surface
->AddChild(container
);
7211 surface
->AddChild(box
);
7213 host()->SetRootLayer(root
);
7215 ExecuteCalculateDrawProperties(root
.get());
7218 TEST_F(LayerTreeHostCommonTest
, OnlyApplyFixedPositioningOnce
) {
7219 gfx::Transform identity
;
7220 gfx::Transform translate_z
;
7221 translate_z
.Translate3d(0, 0, 10);
7223 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7224 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7225 gfx::PointF(), gfx::Size(800, 800), true, false);
7226 root
->SetIsContainerForFixedPositionLayers(true);
7228 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7229 SetLayerPropertiesForTesting(frame_clip
.get(), translate_z
, gfx::Point3F(),
7230 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7232 frame_clip
->SetMasksToBounds(true);
7234 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
7235 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7236 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
7237 gfx::PointF(), gfx::Size(1000, 1000), true,
7240 LayerPositionConstraint constraint
;
7241 constraint
.set_is_fixed_position(true);
7242 fixed
->SetPositionConstraint(constraint
);
7244 root
->AddChild(frame_clip
);
7245 frame_clip
->AddChild(fixed
);
7247 host()->SetRootLayer(root
);
7249 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7251 gfx::Rect
expected(0, 0, 100, 100);
7252 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
7255 TEST_F(LayerTreeHostCommonTest
,
7256 PropertyTreesAccountForScrollCompensationAdjustment
) {
7257 gfx::Transform identity
;
7258 gfx::Transform translate_z
;
7259 translate_z
.Translate3d(0, 0, 10);
7261 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7262 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7263 gfx::PointF(), gfx::Size(800, 800), true, false);
7264 root
->SetIsContainerForFixedPositionLayers(true);
7266 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7267 SetLayerPropertiesForTesting(frame_clip
.get(), translate_z
, gfx::Point3F(),
7268 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7270 frame_clip
->SetMasksToBounds(true);
7272 scoped_refptr
<LayerWithForcedDrawsContent
> scroller
=
7273 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7274 SetLayerPropertiesForTesting(scroller
.get(), identity
, gfx::Point3F(),
7275 gfx::PointF(), gfx::Size(1000, 1000), true,
7278 scroller
->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f
, 0.7f
));
7279 scroller
->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7));
7280 scroller
->SetScrollClipLayerId(frame_clip
->id());
7282 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
7283 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7284 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
7285 gfx::PointF(), gfx::Size(50, 50), true, false);
7287 LayerPositionConstraint constraint
;
7288 constraint
.set_is_fixed_position(true);
7289 fixed
->SetPositionConstraint(constraint
);
7291 scoped_refptr
<LayerWithForcedDrawsContent
> fixed_child
=
7292 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7293 SetLayerPropertiesForTesting(fixed_child
.get(), identity
, gfx::Point3F(),
7294 gfx::PointF(), gfx::Size(10, 10), true, false);
7296 fixed_child
->SetPositionConstraint(constraint
);
7298 root
->AddChild(frame_clip
);
7299 frame_clip
->AddChild(scroller
);
7300 scroller
->AddChild(fixed
);
7301 fixed
->AddChild(fixed_child
);
7303 host()->SetRootLayer(root
);
7305 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7307 gfx::Rect
expected(0, 0, 50, 50);
7308 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
7310 expected
= gfx::Rect(0, 0, 10, 10);
7311 EXPECT_EQ(expected
, fixed_child
->visible_rect_from_property_trees());
7314 TEST_F(LayerTreeHostCommonTest
, FixedClipsShouldBeAssociatedWithTheRightNode
) {
7315 gfx::Transform identity
;
7317 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7318 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7319 gfx::PointF(), gfx::Size(800, 800), true, false);
7320 root
->SetIsContainerForFixedPositionLayers(true);
7322 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7323 SetLayerPropertiesForTesting(frame_clip
.get(), identity
, gfx::Point3F(),
7324 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7326 frame_clip
->SetMasksToBounds(true);
7328 scoped_refptr
<LayerWithForcedDrawsContent
> scroller
=
7329 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7330 SetLayerPropertiesForTesting(scroller
.get(), identity
, gfx::Point3F(),
7331 gfx::PointF(), gfx::Size(1000, 1000), true,
7334 scroller
->SetScrollOffset(gfx::ScrollOffset(100, 100));
7335 scroller
->SetScrollClipLayerId(frame_clip
->id());
7337 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
7338 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7339 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
7340 gfx::PointF(100, 100), gfx::Size(50, 50), true,
7343 LayerPositionConstraint constraint
;
7344 constraint
.set_is_fixed_position(true);
7345 fixed
->SetPositionConstraint(constraint
);
7346 fixed
->SetForceRenderSurface(true);
7347 fixed
->SetMasksToBounds(true);
7349 root
->AddChild(frame_clip
);
7350 frame_clip
->AddChild(scroller
);
7351 scroller
->AddChild(fixed
);
7353 host()->SetRootLayer(root
);
7355 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7357 gfx::Rect
expected(0, 0, 50, 50);
7358 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
7361 TEST_F(LayerTreeHostCommonTest
, ChangingAxisAlignmentTriggersRebuild
) {
7362 gfx::Transform identity
;
7363 gfx::Transform translate
;
7364 gfx::Transform rotate
;
7366 translate
.Translate(10, 10);
7369 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7370 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7371 gfx::PointF(), gfx::Size(800, 800), true, false);
7372 root
->SetIsContainerForFixedPositionLayers(true);
7374 host()->SetRootLayer(root
);
7376 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7377 EXPECT_FALSE(host()->property_trees()->needs_rebuild
);
7379 root
->SetTransform(translate
);
7380 EXPECT_FALSE(host()->property_trees()->needs_rebuild
);
7382 root
->SetTransform(rotate
);
7383 EXPECT_TRUE(host()->property_trees()->needs_rebuild
);
7386 TEST_F(LayerTreeHostCommonTest
, ChangeTransformOrigin
) {
7387 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7388 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7389 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7390 root
->AddChild(child
);
7392 host()->SetRootLayer(root
);
7394 gfx::Transform identity_matrix
;
7395 gfx::Transform scale_matrix
;
7396 scale_matrix
.Scale(2.f
, 2.f
);
7397 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
7398 gfx::PointF(), gfx::Size(100, 100), true, false);
7399 SetLayerPropertiesForTesting(child
.get(), scale_matrix
, gfx::Point3F(),
7400 gfx::PointF(), gfx::Size(10, 10), true, false);
7402 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7403 EXPECT_EQ(gfx::Rect(10, 10), child
->visible_rect_from_property_trees());
7405 child
->SetTransformOrigin(gfx::Point3F(10.f
, 10.f
, 10.f
));
7407 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7408 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child
->visible_rect_from_property_trees());
7411 TEST_F(LayerTreeHostCommonTest
, UpdateScrollChildPosition
) {
7412 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7413 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7414 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7415 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7416 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7418 root
->AddChild(scroll_child
);
7419 root
->AddChild(scroll_parent
);
7420 scroll_child
->SetScrollParent(scroll_parent
.get());
7421 scroll_parent
->SetScrollClipLayerId(root
->id());
7423 host()->SetRootLayer(root
);
7425 gfx::Transform identity_transform
;
7426 gfx::Transform scale
;
7427 scale
.Scale(2.f
, 2.f
);
7428 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7429 gfx::PointF(), gfx::Size(50, 50), true, false);
7430 SetLayerPropertiesForTesting(scroll_child
.get(), scale
, gfx::Point3F(),
7431 gfx::PointF(), gfx::Size(40, 40), true, false);
7432 SetLayerPropertiesForTesting(scroll_parent
.get(), identity_transform
,
7433 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7436 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7437 EXPECT_EQ(gfx::Rect(25, 25),
7438 scroll_child
->visible_rect_from_property_trees());
7440 scroll_child
->SetPosition(gfx::PointF(0, -10.f
));
7441 scroll_parent
->SetScrollOffset(gfx::ScrollOffset(0.f
, 10.f
));
7442 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7443 EXPECT_EQ(gfx::Rect(0, 5, 25, 25),
7444 scroll_child
->visible_rect_from_property_trees());
7447 static void CopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {
7450 TEST_F(LayerTreeHostCommonTest
, SkippingSubtreeMain
) {
7451 gfx::Transform identity
;
7452 FakeContentLayerClient client
;
7453 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7454 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7455 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7456 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
7457 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7458 scoped_refptr
<FakePictureLayer
> greatgrandchild(
7459 FakePictureLayer::Create(layer_settings(), &client
));
7460 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7461 gfx::PointF(), gfx::Size(100, 100), true, false);
7462 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7463 gfx::PointF(), gfx::Size(10, 10), true, false);
7464 SetLayerPropertiesForTesting(grandchild
.get(), identity
, gfx::Point3F(),
7465 gfx::PointF(), gfx::Size(10, 10), true, false);
7466 SetLayerPropertiesForTesting(greatgrandchild
.get(), identity
, gfx::Point3F(),
7467 gfx::PointF(), gfx::Size(10, 10), true, false);
7469 root
->AddChild(child
);
7470 child
->AddChild(grandchild
);
7471 grandchild
->AddChild(greatgrandchild
);
7473 host()->SetRootLayer(root
);
7475 // Check the non-skipped case.
7476 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7477 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7479 // Now we will reset the visible rect from property trees for the grandchild,
7480 // and we will configure |child| in several ways that should force the subtree
7481 // to be skipped. The visible content rect for |grandchild| should, therefore,
7483 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7484 gfx::Transform singular
;
7485 singular
.matrix().set(0, 0, 0);
7487 child
->SetTransform(singular
);
7488 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7489 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
7490 child
->SetTransform(identity
);
7492 child
->SetHideLayerAndSubtree(true);
7493 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7494 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
7495 child
->SetHideLayerAndSubtree(false);
7497 gfx::Transform zero_z_scale
;
7498 zero_z_scale
.Scale3d(1, 1, 0);
7499 child
->SetTransform(zero_z_scale
);
7501 // Add a transform animation with a start delay. Now, even though |child| has
7502 // a singular transform, the subtree should still get processed.
7503 int animation_id
= 0;
7504 scoped_ptr
<Animation
> animation
= Animation::Create(
7505 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1.0)).Pass(),
7506 animation_id
, 1, Animation::TRANSFORM
);
7507 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
7508 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7509 child
->AddAnimation(animation
.Pass());
7510 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7511 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7512 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7514 child
->RemoveAnimation(animation_id
);
7515 child
->SetTransform(identity
);
7516 child
->SetOpacity(0.f
);
7517 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7518 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
7520 // Now, even though child has zero opacity, we will configure |grandchild| and
7521 // |greatgrandchild| in several ways that should force the subtree to be
7522 // processed anyhow.
7523 greatgrandchild
->RequestCopyOfOutput(
7524 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback
)));
7525 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7526 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7527 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7529 // Add an opacity animation with a start delay.
7531 animation
= Animation::Create(
7532 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
7533 animation_id
, 1, Animation::OPACITY
);
7534 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
7535 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7536 child
->AddAnimation(animation
.Pass());
7537 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7538 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7541 TEST_F(LayerTreeHostCommonTest
, SkippingSubtreeImpl
) {
7542 FakeImplProxy proxy
;
7543 TestSharedBitmapManager shared_bitmap_manager
;
7544 TestTaskGraphRunner task_graph_runner
;
7545 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
7546 &task_graph_runner
);
7548 gfx::Transform identity
;
7549 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7550 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 2);
7551 scoped_ptr
<LayerImpl
> grandchild
=
7552 LayerImpl::Create(host_impl
.active_tree(), 3);
7554 scoped_ptr
<FakePictureLayerImpl
> greatgrandchild(
7555 FakePictureLayerImpl::Create(host_impl
.active_tree(), 4));
7557 child
->SetDrawsContent(true);
7558 grandchild
->SetDrawsContent(true);
7559 greatgrandchild
->SetDrawsContent(true);
7561 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7562 gfx::PointF(), gfx::Size(100, 100), true, false,
7564 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7565 gfx::PointF(), gfx::Size(10, 10), true, false,
7567 SetLayerPropertiesForTesting(grandchild
.get(), identity
, gfx::Point3F(),
7568 gfx::PointF(), gfx::Size(10, 10), true, false,
7570 SetLayerPropertiesForTesting(greatgrandchild
.get(), identity
, gfx::Point3F(),
7571 gfx::PointF(), gfx::Size(10, 10), true, false,
7574 LayerImpl
* child_ptr
= child
.get();
7575 LayerImpl
* grandchild_ptr
= grandchild
.get();
7576 LayerImpl
* greatgrandchild_ptr
= greatgrandchild
.get();
7578 grandchild
->AddChild(greatgrandchild
.Pass());
7579 child
->AddChild(grandchild
.Pass());
7580 root
->AddChild(child
.Pass());
7582 // Check the non-skipped case.
7583 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7584 EXPECT_EQ(gfx::Rect(10, 10),
7585 grandchild_ptr
->visible_rect_from_property_trees());
7587 // Now we will reset the visible rect from property trees for the grandchild,
7588 // and we will configure |child| in several ways that should force the subtree
7589 // to be skipped. The visible content rect for |grandchild| should, therefore,
7591 grandchild_ptr
->set_visible_rect_from_property_trees(gfx::Rect());
7592 gfx::Transform singular
;
7593 singular
.matrix().set(0, 0, 0);
7595 child_ptr
->SetTransform(singular
);
7596 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7597 EXPECT_EQ(gfx::Rect(0, 0),
7598 grandchild_ptr
->visible_rect_from_property_trees());
7599 child_ptr
->SetTransform(identity
);
7601 child_ptr
->SetHideLayerAndSubtree(true);
7602 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7603 EXPECT_EQ(gfx::Rect(0, 0),
7604 grandchild_ptr
->visible_rect_from_property_trees());
7605 child_ptr
->SetHideLayerAndSubtree(false);
7607 child_ptr
->SetOpacity(0.f
);
7608 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7609 EXPECT_EQ(gfx::Rect(0, 0),
7610 grandchild_ptr
->visible_rect_from_property_trees());
7612 // Now, even though child has zero opacity, we will configure |grandchild| and
7613 // |greatgrandchild| in several ways that should force the subtree to be
7614 // processed anyhow.
7615 ScopedPtrVector
<CopyOutputRequest
> requests
;
7616 requests
.push_back(CopyOutputRequest::CreateEmptyRequest());
7618 greatgrandchild_ptr
->PassCopyRequests(&requests
);
7619 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7620 EXPECT_EQ(gfx::Rect(10, 10),
7621 grandchild_ptr
->visible_rect_from_property_trees());
7624 TEST_F(LayerTreeHostCommonTest
, SkippingLayer
) {
7625 gfx::Transform identity
;
7626 FakeContentLayerClient client
;
7627 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7628 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7629 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7630 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7631 gfx::PointF(), gfx::Size(100, 100), true, false);
7632 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7633 gfx::PointF(), gfx::Size(10, 10), true, false);
7634 root
->AddChild(child
);
7636 host()->SetRootLayer(root
);
7638 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7639 EXPECT_EQ(gfx::Rect(10, 10), child
->visible_rect_from_property_trees());
7640 child
->set_visible_rect_from_property_trees(gfx::Rect());
7642 child
->SetHideLayerAndSubtree(true);
7643 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7644 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7645 child
->SetHideLayerAndSubtree(false);
7647 child
->SetBounds(gfx::Size());
7648 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7649 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7650 child
->SetBounds(gfx::Size(10, 10));
7652 gfx::Transform rotate
;
7653 child
->SetDoubleSided(false);
7654 rotate
.RotateAboutXAxis(180.f
);
7655 child
->SetTransform(rotate
);
7656 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7657 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7658 child
->SetDoubleSided(true);
7659 child
->SetTransform(identity
);
7661 child
->SetOpacity(0.f
);
7662 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7663 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7666 TEST_F(LayerTreeHostCommonTest
, LayerTreeRebuildTest
) {
7667 // Ensure that the treewalk in LayerTreeHostCommom::
7668 // PreCalculateMetaInformation happens when its required.
7669 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7670 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
7671 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7673 root
->AddChild(parent
);
7674 parent
->AddChild(child
);
7676 child
->SetClipParent(root
.get());
7678 gfx::Transform identity
;
7680 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7681 gfx::PointF(), gfx::Size(100, 100), true, false);
7682 SetLayerPropertiesForTesting(parent
.get(), identity
, gfx::Point3F(),
7683 gfx::PointF(), gfx::Size(100, 100), true, false);
7684 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7685 gfx::PointF(), gfx::Size(100, 100), true, false);
7687 host()->SetRootLayer(root
);
7689 ExecuteCalculateDrawProperties(root
.get());
7690 EXPECT_EQ(parent
->draw_properties().num_unclipped_descendants
, 1u);
7692 child
->RequestCopyOfOutput(
7693 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback
)));
7694 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
7695 ExecuteCalculateDrawProperties(root
.get());
7696 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
7699 TEST_F(LayerTreeHostCommonTest
, InputHandlersRecursiveUpdateTest
) {
7700 // Ensure that the treewalk in LayertreeHostCommon::
7701 // PreCalculateMetaInformation updates input handlers correctly.
7702 LayerImpl
* root
= root_layer();
7703 LayerImpl
* child
= AddChild
<LayerImpl
>(root
);
7705 gfx::Transform identity
;
7707 SetLayerPropertiesForTesting(root
, identity
, gfx::Point3F(), gfx::PointF(),
7708 gfx::Size(100, 100), true, false, true);
7709 SetLayerPropertiesForTesting(child
, identity
, gfx::Point3F(), gfx::PointF(),
7710 gfx::Size(100, 100), true, false, false);
7712 EXPECT_EQ(root
->draw_properties().layer_or_descendant_has_input_handler
,
7715 child
->SetHaveWheelEventHandlers(true);
7716 ExecuteCalculateDrawProperties(root
);
7717 EXPECT_EQ(root
->draw_properties().layer_or_descendant_has_input_handler
,
7720 child
->SetHaveWheelEventHandlers(false);
7721 ExecuteCalculateDrawProperties(root
);
7722 EXPECT_EQ(root
->draw_properties().layer_or_descendant_has_input_handler
,
7726 TEST_F(LayerTreeHostCommonTest
, ResetPropertyTreeIndices
) {
7727 gfx::Transform identity
;
7728 gfx::Transform translate_z
;
7729 translate_z
.Translate3d(0, 0, 10);
7731 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7732 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7733 gfx::PointF(), gfx::Size(800, 800), true, false);
7735 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7736 SetLayerPropertiesForTesting(child
.get(), translate_z
, gfx::Point3F(),
7737 gfx::PointF(), gfx::Size(100, 100), true, false);
7739 root
->AddChild(child
);
7741 host()->SetRootLayer(root
);
7743 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7744 EXPECT_NE(-1, child
->transform_tree_index());
7746 child
->RemoveFromParent();
7748 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7749 EXPECT_EQ(-1, child
->transform_tree_index());
7752 TEST_F(LayerTreeHostCommonTest
, ResetLayerDrawPropertiestest
) {
7753 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7754 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7756 root
->AddChild(child
);
7757 gfx::Transform identity
;
7759 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7760 gfx::PointF(), gfx::Size(100, 100), true, false);
7761 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7762 gfx::PointF(), gfx::Size(100, 100), true, false);
7764 host()->SetRootLayer(root
);
7766 EXPECT_FALSE(root
->layer_or_descendant_is_drawn());
7767 EXPECT_FALSE(root
->visited());
7768 EXPECT_FALSE(root
->sorted_for_recursion());
7769 EXPECT_FALSE(child
->layer_or_descendant_is_drawn());
7770 EXPECT_FALSE(child
->visited());
7771 EXPECT_FALSE(child
->sorted_for_recursion());
7773 root
->set_layer_or_descendant_is_drawn(true);
7774 root
->set_visited(true);
7775 root
->set_sorted_for_recursion(true);
7776 child
->set_layer_or_descendant_is_drawn(true);
7777 child
->set_visited(true);
7778 child
->set_sorted_for_recursion(true);
7780 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root
.get());
7782 EXPECT_FALSE(root
->layer_or_descendant_is_drawn());
7783 EXPECT_FALSE(root
->visited());
7784 EXPECT_FALSE(root
->sorted_for_recursion());
7785 EXPECT_FALSE(child
->layer_or_descendant_is_drawn());
7786 EXPECT_FALSE(child
->visited());
7787 EXPECT_FALSE(child
->sorted_for_recursion());
7790 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceClipsSubtree
) {
7791 // Ensure that a Clip Node is added when a render surface applies clip.
7792 LayerImpl
* root
= root_layer();
7793 LayerImpl
* significant_transform
= AddChildToRoot
<LayerImpl
>();
7794 LayerImpl
* layer_clips_subtree
= AddChild
<LayerImpl
>(significant_transform
);
7795 LayerImpl
* render_surface
= AddChild
<LayerImpl
>(layer_clips_subtree
);
7796 LayerImpl
* test_layer
= AddChild
<LayerImpl
>(render_surface
);
7798 const gfx::Transform identity_matrix
;
7799 // This transform should be a significant one so that a transform node is
7801 gfx::Transform transform1
;
7802 transform1
.RotateAboutYAxis(45);
7803 transform1
.RotateAboutXAxis(30);
7804 // This transform should be a 3d transform as we want the render surface
7805 // to flatten the transform
7806 gfx::Transform transform2
;
7807 transform2
.Translate3d(10, 10, 10);
7809 layer_clips_subtree
->SetMasksToBounds(true);
7810 test_layer
->SetDrawsContent(true);
7812 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
7813 gfx::PointF(), gfx::Size(30, 30), true, false,
7815 SetLayerPropertiesForTesting(significant_transform
, transform1
,
7816 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7817 true, false, false);
7818 SetLayerPropertiesForTesting(layer_clips_subtree
, identity_matrix
,
7819 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7820 true, false, false);
7821 SetLayerPropertiesForTesting(render_surface
, transform2
, gfx::Point3F(),
7822 gfx::PointF(), gfx::Size(30, 30), true, false,
7824 SetLayerPropertiesForTesting(test_layer
, identity_matrix
, gfx::Point3F(),
7825 gfx::PointF(), gfx::Size(30, 30), true, false,
7828 ExecuteCalculateDrawProperties(root
);
7830 TransformTree transform_tree
=
7831 root
->layer_tree_impl()->property_trees()->transform_tree
;
7832 TransformNode
* transform_node
=
7833 transform_tree
.Node(significant_transform
->transform_tree_index());
7834 EXPECT_EQ(transform_node
->owner_id
, significant_transform
->id());
7836 ClipTree clip_tree
= root
->layer_tree_impl()->property_trees()->clip_tree
;
7837 ClipNode
* clip_node
= clip_tree
.Node(render_surface
->clip_tree_index());
7838 EXPECT_TRUE(clip_node
->data
.inherit_parent_target_space_clip
);
7839 EXPECT_EQ(test_layer
->visible_rect_from_property_trees(), gfx::RectF(30, 21));
7842 TEST_F(LayerTreeHostCommonTest
, TransformOfParentClipNodeAncestorOfTarget
) {
7843 // Ensure that when parent clip node's transform is an ancestor of current
7844 // clip node's target, clip is 'projected' from parent space to current
7845 // target space and visible rects are calculated correctly.
7846 LayerImpl
* root
= root_layer();
7847 LayerImpl
* clip_layer
= AddChild
<LayerImpl
>(root
);
7848 LayerImpl
* target_layer
= AddChild
<LayerImpl
>(clip_layer
);
7849 LayerImpl
* test_layer
= AddChild
<LayerImpl
>(target_layer
);
7851 const gfx::Transform identity_matrix
;
7852 gfx::Transform transform
;
7853 transform
.RotateAboutYAxis(45);
7854 clip_layer
->SetMasksToBounds(true);
7855 target_layer
->SetMasksToBounds(true);
7856 test_layer
->SetDrawsContent(true);
7858 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
7859 gfx::PointF(), gfx::Size(30, 30), true, false,
7861 SetLayerPropertiesForTesting(clip_layer
, transform
, gfx::Point3F(),
7862 gfx::PointF(), gfx::Size(30, 30), true, false,
7864 SetLayerPropertiesForTesting(target_layer
, transform
, gfx::Point3F(),
7865 gfx::PointF(), gfx::Size(30, 30), true, false,
7867 SetLayerPropertiesForTesting(test_layer
, identity_matrix
, gfx::Point3F(),
7868 gfx::PointF(), gfx::Size(30, 30), true, false,
7870 ExecuteCalculateDrawProperties(root
);
7872 ClipTree clip_tree
= root
->layer_tree_impl()->property_trees()->clip_tree
;
7873 ClipNode
* clip_node
= clip_tree
.Node(target_layer
->clip_tree_index());
7874 EXPECT_EQ(clip_node
->data
.combined_clip
, gfx::RectF(30, 30));
7875 EXPECT_EQ(test_layer
->visible_rect_from_property_trees(), gfx::RectF(30, 30));
7878 TEST_F(LayerTreeHostCommonTest
,
7879 RenderSurfaceWithUnclippedDescendantsClipsSubtree
) {
7880 // Ensure clip rect is calculated correctly when render surface has unclipped
7882 LayerImpl
* root
= root_layer();
7883 LayerImpl
* clip_parent
= AddChildToRoot
<LayerImpl
>();
7884 LayerImpl
* between_clip_parent_and_child
= AddChild
<LayerImpl
>(clip_parent
);
7885 LayerImpl
* render_surface
=
7886 AddChild
<LayerImpl
>(between_clip_parent_and_child
);
7887 LayerImpl
* test_layer
= AddChild
<LayerImpl
>(render_surface
);
7889 const gfx::Transform identity_matrix
;
7890 gfx::Transform transform
;
7891 transform
.Translate(2.0, 2.0);
7893 test_layer
->SetDrawsContent(true);
7894 render_surface
->SetClipParent(clip_parent
);
7895 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
7896 gfx::PointF(), gfx::Size(30, 30), true, false,
7898 SetLayerPropertiesForTesting(clip_parent
, transform
, gfx::Point3F(),
7899 gfx::PointF(), gfx::Size(30, 30), true, false,
7901 SetLayerPropertiesForTesting(between_clip_parent_and_child
, transform
,
7902 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7903 true, false, false);
7904 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
7905 gfx::PointF(), gfx::Size(30, 30), true, false,
7907 SetLayerPropertiesForTesting(test_layer
, identity_matrix
, gfx::Point3F(),
7908 gfx::PointF(), gfx::Size(30, 30), true, false,
7911 ExecuteCalculateDrawProperties(root
);
7913 EXPECT_EQ(test_layer
->clip_rect(), gfx::RectF(-4, -4, 30, 30));