Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / cc / trees / layer_tree_host_common_unittest.cc
blob3d09a9132ba833dd5298fd13e6d61173988210b2
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"
7 #include <algorithm>
8 #include <set>
10 #include "cc/animation/keyframed_animation_curve.h"
11 #include "cc/animation/layer_animation_controller.h"
12 #include "cc/animation/transform_operations.h"
13 #include "cc/base/math_util.h"
14 #include "cc/layers/content_layer_client.h"
15 #include "cc/layers/layer.h"
16 #include "cc/layers/layer_client.h"
17 #include "cc/layers/layer_impl.h"
18 #include "cc/layers/layer_iterator.h"
19 #include "cc/layers/render_surface.h"
20 #include "cc/layers/render_surface_impl.h"
21 #include "cc/output/copy_output_request.h"
22 #include "cc/output/copy_output_result.h"
23 #include "cc/test/animation_test_common.h"
24 #include "cc/test/fake_content_layer_client.h"
25 #include "cc/test/fake_impl_proxy.h"
26 #include "cc/test/fake_layer_tree_host.h"
27 #include "cc/test/fake_layer_tree_host_impl.h"
28 #include "cc/test/fake_output_surface.h"
29 #include "cc/test/fake_picture_layer.h"
30 #include "cc/test/fake_picture_layer_impl.h"
31 #include "cc/test/geometry_test_utils.h"
32 #include "cc/test/layer_tree_host_common_test.h"
33 #include "cc/test/test_task_graph_runner.h"
34 #include "cc/trees/draw_property_utils.h"
35 #include "cc/trees/layer_tree_impl.h"
36 #include "cc/trees/proxy.h"
37 #include "cc/trees/single_thread_proxy.h"
38 #include "testing/gmock/include/gmock/gmock.h"
39 #include "testing/gtest/include/gtest/gtest.h"
40 #include "ui/gfx/geometry/quad_f.h"
41 #include "ui/gfx/geometry/vector2d_conversions.h"
42 #include "ui/gfx/transform.h"
44 namespace cc {
45 namespace {
47 class LayerWithForcedDrawsContent : public Layer {
48 public:
49 explicit LayerWithForcedDrawsContent(const LayerSettings& settings)
50 : Layer(settings) {}
52 bool DrawsContent() const override;
54 private:
55 ~LayerWithForcedDrawsContent() override {}
58 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
60 class MockContentLayerClient : public ContentLayerClient {
61 public:
62 MockContentLayerClient() {}
63 ~MockContentLayerClient() override {}
64 void PaintContents(SkCanvas* canvas,
65 const gfx::Rect& clip,
66 PaintingControlSetting picture_control) override {}
67 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
68 const gfx::Rect& clip,
69 PaintingControlSetting picture_control) override {
70 NOTIMPLEMENTED();
71 return nullptr;
73 bool FillsBoundsCompletely() const override { return false; }
74 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; }
77 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
78 do { \
79 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
80 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
81 } while (false)
83 #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
84 do { \
85 EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \
86 } while (false)
88 class LayerTreeSettingsScaleContent : public LayerTreeSettings {
89 public:
90 LayerTreeSettingsScaleContent() {
91 layer_transforms_should_scale_layer_contents = true;
95 class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTest {
96 public:
97 LayerTreeHostCommonScalingTest()
98 : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {}
101 TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
102 // Sanity check: For layers positioned at zero, with zero size,
103 // and with identity transforms, then the draw transform,
104 // screen space transform, and the hierarchy passed on to children
105 // layers should also be identity transforms.
107 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
108 scoped_refptr<Layer> child = Layer::Create(layer_settings());
109 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
110 parent->AddChild(child);
111 child->AddChild(grand_child);
113 host()->SetRootLayer(parent);
115 gfx::Transform identity_matrix;
116 SetLayerPropertiesForTesting(parent.get(),
117 identity_matrix,
118 gfx::Point3F(),
119 gfx::PointF(),
120 gfx::Size(100, 100),
121 true,
122 false);
123 SetLayerPropertiesForTesting(child.get(),
124 identity_matrix,
125 gfx::Point3F(),
126 gfx::PointF(),
127 gfx::Size(),
128 true,
129 false);
130 SetLayerPropertiesForTesting(grand_child.get(),
131 identity_matrix,
132 gfx::Point3F(),
133 gfx::PointF(),
134 gfx::Size(),
135 true,
136 false);
138 ExecuteCalculateDrawProperties(parent.get());
140 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
141 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
142 child->screen_space_transform());
143 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
144 grand_child->draw_transform());
145 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
146 grand_child->screen_space_transform());
149 TEST_F(LayerTreeHostCommonTest, DoNotSkipLayersWithHandlers) {
150 LayerImpl* parent = root_layer();
151 LayerImpl* child = AddChild<LayerImpl>(parent);
152 LayerImpl* grand_child = AddChild<LayerImpl>(child);
154 gfx::Transform identity_matrix;
155 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
156 gfx::PointF(), gfx::Size(100, 100), true, false,
157 true);
158 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
159 gfx::PointF(10, 10), gfx::Size(100, 100), true,
160 false, false);
161 // This would have previously caused us to skip our subtree, but this would be
162 // wrong; we need up-to-date draw properties to do hit testing on the layers
163 // with handlers.
164 child->SetOpacity(0.f);
165 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
166 gfx::PointF(10, 10), gfx::Size(100, 100), true,
167 false, false);
168 grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
170 ExecuteCalculateDrawProperties(parent);
172 // Check that we've computed draw properties for the subtree rooted at
173 // |child|.
174 EXPECT_FALSE(child->draw_transform().IsIdentity());
175 EXPECT_FALSE(grand_child->draw_transform().IsIdentity());
178 TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
179 gfx::Transform identity_matrix;
180 scoped_refptr<Layer> layer = Layer::Create(layer_settings());
182 scoped_refptr<Layer> root = Layer::Create(layer_settings());
183 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
184 gfx::PointF(), gfx::Size(1, 2), true, false);
185 root->AddChild(layer);
187 host()->SetRootLayer(root);
189 TransformTree& tree = host()->property_trees()->transform_tree;
191 // Case 2: Setting the bounds of the layer should not affect either the draw
192 // transform or the screenspace transform.
193 gfx::Transform translation_to_center;
194 translation_to_center.Translate(5.0, 6.0);
195 SetLayerPropertiesForTesting(layer.get(), identity_matrix, gfx::Point3F(),
196 gfx::PointF(), gfx::Size(10, 12), true, false);
197 ExecuteCalculateDrawProperties(root.get());
198 EXPECT_TRANSFORMATION_MATRIX_EQ(
199 identity_matrix, DrawTransformFromPropertyTrees(layer.get(), tree));
200 EXPECT_TRANSFORMATION_MATRIX_EQ(
201 identity_matrix,
202 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
204 // Case 3: The anchor point by itself (without a layer transform) should have
205 // no effect on the transforms.
206 SetLayerPropertiesForTesting(layer.get(), identity_matrix,
207 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
208 gfx::Size(10, 12), true, false);
209 ExecuteCalculateDrawProperties(root.get());
210 EXPECT_TRANSFORMATION_MATRIX_EQ(
211 identity_matrix, DrawTransformFromPropertyTrees(layer.get(), tree));
212 EXPECT_TRANSFORMATION_MATRIX_EQ(
213 identity_matrix,
214 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
216 // Case 4: A change in actual position affects both the draw transform and
217 // screen space transform.
218 gfx::Transform position_transform;
219 position_transform.Translate(0.f, 1.2f);
220 SetLayerPropertiesForTesting(
221 layer.get(), identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
222 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
223 ExecuteCalculateDrawProperties(root.get());
224 EXPECT_TRANSFORMATION_MATRIX_EQ(
225 position_transform, DrawTransformFromPropertyTrees(layer.get(), tree));
226 EXPECT_TRANSFORMATION_MATRIX_EQ(
227 position_transform,
228 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
230 // Case 5: In the correct sequence of transforms, the layer transform should
231 // pre-multiply the translation_to_center. This is easily tested by using a
232 // scale transform, because scale and translation are not commutative.
233 gfx::Transform layer_transform;
234 layer_transform.Scale3d(2.0, 2.0, 1.0);
235 SetLayerPropertiesForTesting(layer.get(), layer_transform, gfx::Point3F(),
236 gfx::PointF(), gfx::Size(10, 12), true, false);
237 ExecuteCalculateDrawProperties(root.get());
238 EXPECT_TRANSFORMATION_MATRIX_EQ(
239 layer_transform, DrawTransformFromPropertyTrees(layer.get(), tree));
240 EXPECT_TRANSFORMATION_MATRIX_EQ(
241 layer_transform,
242 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
244 // Case 6: The layer transform should occur with respect to the anchor point.
245 gfx::Transform translation_to_anchor;
246 translation_to_anchor.Translate(5.0, 0.0);
247 gfx::Transform expected_result =
248 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
249 SetLayerPropertiesForTesting(layer.get(), layer_transform,
250 gfx::Point3F(5.0f, 0.f, 0.f), gfx::PointF(),
251 gfx::Size(10, 12), true, false);
252 ExecuteCalculateDrawProperties(root.get());
253 EXPECT_TRANSFORMATION_MATRIX_EQ(
254 expected_result, DrawTransformFromPropertyTrees(layer.get(), tree));
255 EXPECT_TRANSFORMATION_MATRIX_EQ(
256 expected_result,
257 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
259 // Case 7: Verify that position pre-multiplies the layer transform. The
260 // current implementation of CalculateDrawProperties does this implicitly, but
261 // it is still worth testing to detect accidental regressions.
262 expected_result = position_transform * translation_to_anchor *
263 layer_transform * Inverse(translation_to_anchor);
264 SetLayerPropertiesForTesting(
265 layer.get(), layer_transform, gfx::Point3F(5.0f, 0.f, 0.f),
266 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
267 ExecuteCalculateDrawProperties(root.get());
268 EXPECT_TRANSFORMATION_MATRIX_EQ(
269 expected_result, DrawTransformFromPropertyTrees(layer.get(), tree));
270 EXPECT_TRANSFORMATION_MATRIX_EQ(
271 expected_result,
272 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
275 TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
276 const gfx::ScrollOffset kScrollOffset(50, 100);
277 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
278 const gfx::Vector2d kMaxScrollOffset(200, 200);
279 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
280 -kScrollOffset.y());
281 const float kPageScale = 0.888f;
282 const float kDeviceScale = 1.666f;
284 FakeImplProxy proxy;
285 TestSharedBitmapManager shared_bitmap_manager;
286 TestTaskGraphRunner task_graph_runner;
287 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
288 &task_graph_runner);
290 gfx::Transform identity_matrix;
291 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
292 LayerImpl::Create(host_impl.active_tree(), 1));
293 LayerImpl* sublayer = sublayer_scoped_ptr.get();
294 SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(),
295 gfx::PointF(), gfx::Size(500, 500), true, false,
296 false);
298 scoped_ptr<LayerImpl> scroll_layer_scoped_ptr(
299 LayerImpl::Create(host_impl.active_tree(), 2));
300 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
301 SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(),
302 gfx::PointF(), gfx::Size(10, 20), true, false,
303 false);
304 scoped_ptr<LayerImpl> clip_layer_scoped_ptr(
305 LayerImpl::Create(host_impl.active_tree(), 4));
306 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
308 scroll_layer->SetScrollClipLayer(clip_layer->id());
309 clip_layer->SetBounds(
310 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
311 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
312 scroll_layer->SetScrollClipLayer(clip_layer->id());
313 scroll_layer->SetScrollDelta(kScrollDelta);
314 gfx::Transform impl_transform;
315 scroll_layer->AddChild(sublayer_scoped_ptr.Pass());
316 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
317 clip_layer->AddChild(scroll_layer_scoped_ptr.Pass());
318 scroll_layer_raw_ptr->PushScrollOffsetFromMainThread(kScrollOffset);
320 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
321 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
322 gfx::PointF(), gfx::Size(3, 4), true, false,
323 false);
324 root->AddChild(clip_layer_scoped_ptr.Pass());
325 root->SetHasRenderSurface(true);
327 ExecuteCalculateDrawProperties(
328 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
329 gfx::Transform expected_transform = identity_matrix;
330 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
331 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() *
332 kPageScale * kDeviceScale),
333 MathUtil::Round(sub_layer_screen_position.y() *
334 kPageScale * kDeviceScale));
335 expected_transform.Scale(kPageScale * kDeviceScale,
336 kPageScale * kDeviceScale);
337 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
338 sublayer->draw_transform());
339 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
340 sublayer->screen_space_transform());
342 gfx::Transform arbitrary_translate;
343 const float kTranslateX = 10.6f;
344 const float kTranslateY = 20.6f;
345 arbitrary_translate.Translate(kTranslateX, kTranslateY);
346 SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate,
347 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
348 true, false, false);
349 ExecuteCalculateDrawProperties(
350 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
351 expected_transform.MakeIdentity();
352 expected_transform.Translate(
353 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
354 sub_layer_screen_position.x() * kPageScale *
355 kDeviceScale),
356 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
357 sub_layer_screen_position.y() * kPageScale *
358 kDeviceScale));
359 expected_transform.Scale(kPageScale * kDeviceScale,
360 kPageScale * kDeviceScale);
361 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
362 sublayer->draw_transform());
365 TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
366 gfx::Transform identity_matrix;
367 scoped_refptr<Layer> root = Layer::Create(layer_settings());
368 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
369 scoped_refptr<Layer> child = Layer::Create(layer_settings());
370 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
371 root->AddChild(parent);
372 parent->AddChild(child);
373 child->AddChild(grand_child);
375 host()->SetRootLayer(root);
377 // One-time setup of root layer
378 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
379 gfx::PointF(), gfx::Size(1, 2), true, false);
381 TransformTree& tree = host()->property_trees()->transform_tree;
383 // Case 1: parent's anchor point should not affect child or grand_child.
384 SetLayerPropertiesForTesting(parent.get(), identity_matrix,
385 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
386 gfx::Size(10, 12), true, false);
387 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
388 gfx::PointF(), gfx::Size(16, 18), true, false);
389 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
390 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78),
391 true, false);
392 ExecuteCalculateDrawProperties(root.get());
394 EXPECT_TRANSFORMATION_MATRIX_EQ(
395 identity_matrix, DrawTransformFromPropertyTrees(child.get(), tree));
396 EXPECT_TRANSFORMATION_MATRIX_EQ(
397 identity_matrix,
398 ScreenSpaceTransformFromPropertyTrees(child.get(), tree));
399 EXPECT_TRANSFORMATION_MATRIX_EQ(
400 identity_matrix, DrawTransformFromPropertyTrees(grand_child.get(), tree));
401 EXPECT_TRANSFORMATION_MATRIX_EQ(
402 identity_matrix,
403 ScreenSpaceTransformFromPropertyTrees(grand_child.get(), tree));
405 // Case 2: parent's position affects child and grand_child.
406 gfx::Transform parent_position_transform;
407 parent_position_transform.Translate(0.f, 1.2f);
408 SetLayerPropertiesForTesting(
409 parent.get(), identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
410 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
411 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
412 gfx::PointF(), gfx::Size(16, 18), true, false);
413 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
414 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78),
415 true, false);
416 ExecuteCalculateDrawProperties(root.get());
417 EXPECT_TRANSFORMATION_MATRIX_EQ(
418 parent_position_transform,
419 DrawTransformFromPropertyTrees(child.get(), tree));
420 EXPECT_TRANSFORMATION_MATRIX_EQ(
421 parent_position_transform,
422 ScreenSpaceTransformFromPropertyTrees(child.get(), tree));
423 EXPECT_TRANSFORMATION_MATRIX_EQ(
424 parent_position_transform,
425 DrawTransformFromPropertyTrees(grand_child.get(), tree));
426 EXPECT_TRANSFORMATION_MATRIX_EQ(
427 parent_position_transform,
428 ScreenSpaceTransformFromPropertyTrees(grand_child.get(), tree));
430 // Case 3: parent's local transform affects child and grandchild
431 gfx::Transform parent_layer_transform;
432 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
433 gfx::Transform parent_translation_to_anchor;
434 parent_translation_to_anchor.Translate(2.5, 3.0);
435 gfx::Transform parent_composite_transform =
436 parent_translation_to_anchor * parent_layer_transform *
437 Inverse(parent_translation_to_anchor);
438 SetLayerPropertiesForTesting(parent.get(), parent_layer_transform,
439 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
440 gfx::Size(10, 12), true, false);
441 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
442 gfx::PointF(), gfx::Size(16, 18), true, false);
443 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
444 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78),
445 true, false);
446 ExecuteCalculateDrawProperties(root.get());
447 EXPECT_TRANSFORMATION_MATRIX_EQ(
448 parent_composite_transform,
449 DrawTransformFromPropertyTrees(child.get(), tree));
450 EXPECT_TRANSFORMATION_MATRIX_EQ(
451 parent_composite_transform,
452 ScreenSpaceTransformFromPropertyTrees(child.get(), tree));
453 EXPECT_TRANSFORMATION_MATRIX_EQ(
454 parent_composite_transform,
455 DrawTransformFromPropertyTrees(grand_child.get(), tree));
456 EXPECT_TRANSFORMATION_MATRIX_EQ(
457 parent_composite_transform,
458 ScreenSpaceTransformFromPropertyTrees(grand_child.get(), tree));
461 TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
462 LayerImpl* root = root_layer();
463 LayerImpl* parent = AddChildToRoot<LayerImpl>();
464 LayerImpl* child = AddChild<LayerImpl>(parent);
465 LayerImpl* grand_child = AddChild<LayerImpl>(child);
466 grand_child->SetDrawsContent(true);
468 gfx::Transform identity_matrix;
469 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
470 gfx::PointF(), gfx::Size(1, 2), true, false,
471 true);
473 // Child is set up so that a new render surface should be created.
474 child->SetOpacity(0.5f);
476 gfx::Transform parent_layer_transform;
477 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
478 gfx::Transform parent_translation_to_anchor;
479 parent_translation_to_anchor.Translate(25.0, 30.0);
481 gfx::Transform parent_composite_transform =
482 parent_translation_to_anchor * parent_layer_transform *
483 Inverse(parent_translation_to_anchor);
484 gfx::Vector2dF parent_composite_scale =
485 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
486 1.f);
487 gfx::Transform surface_sublayer_transform;
488 surface_sublayer_transform.Scale(parent_composite_scale.x(),
489 parent_composite_scale.y());
490 gfx::Transform surface_sublayer_composite_transform =
491 parent_composite_transform * Inverse(surface_sublayer_transform);
493 SetLayerPropertiesForTesting(parent, parent_layer_transform,
494 gfx::Point3F(25.0f, 30.0f, 0.f), gfx::PointF(),
495 gfx::Size(100, 120), true, false, false);
496 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
497 gfx::PointF(), gfx::Size(16, 18), true, false,
498 true);
499 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
500 gfx::PointF(), gfx::Size(8, 10), true, false,
501 false);
502 ExecuteCalculateDrawProperties(root);
504 // Render surface should have been created now.
505 ASSERT_TRUE(child->render_surface());
506 ASSERT_EQ(child, child->render_target());
508 // The child layer's draw transform should refer to its new render surface.
509 // The screen-space transform, however, should still refer to the root.
510 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
511 child->draw_transform());
512 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
513 child->screen_space_transform());
515 // Because the grand_child is the only drawable content, the child's render
516 // surface will tighten its bounds to the grand_child. The scale at which the
517 // surface's subtree is drawn must be removed from the composite transform.
518 EXPECT_TRANSFORMATION_MATRIX_EQ(
519 surface_sublayer_composite_transform,
520 child->render_target()->render_surface()->draw_transform());
522 // The screen space is the same as the target since the child surface draws
523 // into the root.
524 EXPECT_TRANSFORMATION_MATRIX_EQ(
525 surface_sublayer_composite_transform,
526 child->render_target()->render_surface()->screen_space_transform());
529 TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
530 LayerImpl* root = root_layer();
531 LayerImpl* parent = AddChildToRoot<LayerImpl>();
532 LayerImpl* child = AddChild<LayerImpl>(parent);
533 LayerImpl* grand_child = AddChild<LayerImpl>(child);
534 grand_child->SetDrawsContent(true);
535 scoped_ptr<LayerImpl> child_replica =
536 LayerImpl::Create(host_impl()->active_tree(), 100);
538 // One-time setup of root layer
539 gfx::Transform identity_matrix;
540 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
541 gfx::PointF(), gfx::Size(1, 2), true, false,
542 true);
544 // Child is set up so that a new render surface should be created.
545 child->SetOpacity(0.5f);
547 gfx::Transform parent_layer_transform;
548 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
549 gfx::Transform parent_translation_to_anchor;
550 parent_translation_to_anchor.Translate(2.5, 3.0);
551 gfx::Transform parent_composite_transform =
552 parent_translation_to_anchor * parent_layer_transform *
553 Inverse(parent_translation_to_anchor);
554 gfx::Transform replica_layer_transform;
555 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
556 gfx::Vector2dF parent_composite_scale =
557 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
558 1.f);
559 gfx::Transform surface_sublayer_transform;
560 surface_sublayer_transform.Scale(parent_composite_scale.x(),
561 parent_composite_scale.y());
562 gfx::Transform replica_composite_transform =
563 parent_composite_transform * replica_layer_transform *
564 Inverse(surface_sublayer_transform);
565 child_replica->SetDrawsContent(true);
566 // Child's render surface should not exist yet.
567 ASSERT_FALSE(child->render_surface());
569 SetLayerPropertiesForTesting(parent, parent_layer_transform,
570 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
571 gfx::Size(10, 12), true, false, false);
572 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
573 gfx::PointF(), gfx::Size(16, 18), true, false,
574 true);
575 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
576 gfx::PointF(-0.5f, -0.5f), gfx::Size(1, 1), true,
577 false, false);
578 SetLayerPropertiesForTesting(child_replica.get(), replica_layer_transform,
579 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
580 false, false);
581 child->SetReplicaLayer(child_replica.Pass());
583 ExecuteCalculateDrawProperties(root);
585 // Render surface should have been created now.
586 ASSERT_TRUE(child->render_surface());
587 ASSERT_EQ(child, child->render_target());
589 EXPECT_TRANSFORMATION_MATRIX_EQ(
590 replica_composite_transform,
591 child->render_target()->render_surface()->replica_draw_transform());
592 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
593 child->render_target()
594 ->render_surface()
595 ->replica_screen_space_transform());
598 TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
599 // This test creates a more complex tree and verifies it all at once. This
600 // covers the following cases:
601 // - layers that are described w.r.t. a render surface: should have draw
602 // transforms described w.r.t. that surface
603 // - A render surface described w.r.t. an ancestor render surface: should
604 // have a draw transform described w.r.t. that ancestor surface
605 // - Replicas of a render surface are described w.r.t. the replica's
606 // transform around its anchor, along with the surface itself.
607 // - Sanity check on recursion: verify transforms of layers described w.r.t.
608 // a render surface that is described w.r.t. an ancestor render surface.
609 // - verifying that each layer has a reference to the correct render surface
610 // and render target values.
612 LayerImpl* root = root_layer();
613 LayerImpl* parent = AddChildToRoot<LayerImpl>();
614 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
615 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
616 LayerImpl* child_of_root = AddChild<LayerImpl>(parent);
617 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
618 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
619 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
620 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
621 grand_child_of_rs1->SetDrawsContent(true);
622 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
623 grand_child_of_rs2->SetDrawsContent(true);
625 scoped_ptr<LayerImpl> replica_of_rs1 =
626 LayerImpl::Create(host_impl()->active_tree(), 101);
627 scoped_ptr<LayerImpl> replica_of_rs2 =
628 LayerImpl::Create(host_impl()->active_tree(), 102);
630 // In combination with descendant draws content, opacity != 1 forces the layer
631 // to have a new render surface.
632 render_surface1->SetOpacity(0.5f);
633 render_surface2->SetOpacity(0.33f);
635 // One-time setup of root layer
636 gfx::Transform identity_matrix;
637 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
638 gfx::PointF(), gfx::Size(1, 2), true, false,
639 true);
641 // All layers in the tree are initialized with an anchor at .25 and a size of
642 // (10,10). matrix "A" is the composite layer transform used in all layers,
643 // Matrix "R" is the composite replica transform used in all replica layers.
644 gfx::Transform translation_to_anchor;
645 translation_to_anchor.Translate(2.5, 0.0);
646 gfx::Transform layer_transform;
647 layer_transform.Translate(1.0, 1.0);
648 gfx::Transform replica_layer_transform;
649 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
651 gfx::Transform A =
652 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
653 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
654 Inverse(translation_to_anchor);
656 gfx::Vector2dF surface1_parent_transform_scale =
657 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
658 gfx::Transform surface1_sublayer_transform;
659 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
660 surface1_parent_transform_scale.y());
662 // SS1 = transform given to the subtree of render_surface1
663 gfx::Transform SS1 = surface1_sublayer_transform;
664 // S1 = transform to move from render_surface1 pixels to the layer space of
665 // the owning layer
666 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
668 gfx::Vector2dF surface2_parent_transform_scale =
669 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
670 gfx::Transform surface2_sublayer_transform;
671 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
672 surface2_parent_transform_scale.y());
674 // SS2 = transform given to the subtree of render_surface2
675 gfx::Transform SS2 = surface2_sublayer_transform;
676 // S2 = transform to move from render_surface2 pixels to the layer space of
677 // the owning layer
678 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
680 SetLayerPropertiesForTesting(parent, layer_transform,
681 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
682 gfx::Size(10, 10), true, false, false);
683 SetLayerPropertiesForTesting(render_surface1, layer_transform,
684 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
685 gfx::Size(10, 10), true, false, true);
686 SetLayerPropertiesForTesting(render_surface2, layer_transform,
687 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
688 gfx::Size(10, 10), true, false, true);
689 SetLayerPropertiesForTesting(child_of_root, layer_transform,
690 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
691 gfx::Size(10, 10), true, false, false);
692 SetLayerPropertiesForTesting(child_of_rs1, layer_transform,
693 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
694 gfx::Size(10, 10), true, false, false);
695 SetLayerPropertiesForTesting(child_of_rs2, layer_transform,
696 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
697 gfx::Size(10, 10), true, false, false);
698 SetLayerPropertiesForTesting(grand_child_of_root, layer_transform,
699 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
700 gfx::Size(10, 10), true, false, false);
701 SetLayerPropertiesForTesting(grand_child_of_rs1, layer_transform,
702 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
703 gfx::Size(10, 10), true, false, false);
704 SetLayerPropertiesForTesting(grand_child_of_rs2, layer_transform,
705 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
706 gfx::Size(10, 10), true, false, false);
707 SetLayerPropertiesForTesting(replica_of_rs1.get(), replica_layer_transform,
708 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
709 gfx::Size(), true, false, false);
710 SetLayerPropertiesForTesting(replica_of_rs2.get(), replica_layer_transform,
711 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
712 gfx::Size(), true, false, false);
714 render_surface1->SetReplicaLayer(replica_of_rs1.Pass());
715 render_surface2->SetReplicaLayer(replica_of_rs2.Pass());
716 ExecuteCalculateDrawProperties(root);
718 // Only layers that are associated with render surfaces should have an actual
719 // RenderSurface() value.
720 ASSERT_TRUE(root->render_surface());
721 ASSERT_FALSE(child_of_root->render_surface());
722 ASSERT_FALSE(grand_child_of_root->render_surface());
724 ASSERT_TRUE(render_surface1->render_surface());
725 ASSERT_FALSE(child_of_rs1->render_surface());
726 ASSERT_FALSE(grand_child_of_rs1->render_surface());
728 ASSERT_TRUE(render_surface2->render_surface());
729 ASSERT_FALSE(child_of_rs2->render_surface());
730 ASSERT_FALSE(grand_child_of_rs2->render_surface());
732 // Verify all render target accessors
733 EXPECT_EQ(root, parent->render_target());
734 EXPECT_EQ(root, child_of_root->render_target());
735 EXPECT_EQ(root, grand_child_of_root->render_target());
737 EXPECT_EQ(render_surface1, render_surface1->render_target());
738 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
739 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
741 EXPECT_EQ(render_surface2, render_surface2->render_target());
742 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
743 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
745 // Verify layer draw transforms note that draw transforms are described with
746 // respect to the nearest ancestor render surface but screen space transforms
747 // are described with respect to the root.
748 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform());
749 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform());
750 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
751 grand_child_of_root->draw_transform());
753 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform());
754 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform());
755 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
756 grand_child_of_rs1->draw_transform());
758 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform());
759 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform());
760 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
761 grand_child_of_rs2->draw_transform());
763 // Verify layer screen-space transforms
765 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform());
766 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
767 child_of_root->screen_space_transform());
768 EXPECT_TRANSFORMATION_MATRIX_EQ(
769 A * A * A, grand_child_of_root->screen_space_transform());
771 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
772 render_surface1->screen_space_transform());
773 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
774 child_of_rs1->screen_space_transform());
775 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
776 grand_child_of_rs1->screen_space_transform());
778 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
779 render_surface2->screen_space_transform());
780 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
781 child_of_rs2->screen_space_transform());
782 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
783 grand_child_of_rs2->screen_space_transform());
785 // Verify render surface transforms.
787 // Draw transform of render surface 1 is described with respect to root.
788 EXPECT_TRANSFORMATION_MATRIX_EQ(
789 A * A * S1, render_surface1->render_surface()->draw_transform());
790 EXPECT_TRANSFORMATION_MATRIX_EQ(
791 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
792 EXPECT_TRANSFORMATION_MATRIX_EQ(
793 A * A * S1, render_surface1->render_surface()->screen_space_transform());
794 EXPECT_TRANSFORMATION_MATRIX_EQ(
795 A * R * S1,
796 render_surface1->render_surface()->replica_screen_space_transform());
797 // Draw transform of render surface 2 is described with respect to render
798 // surface 1.
799 EXPECT_TRANSFORMATION_MATRIX_EQ(
800 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
801 EXPECT_TRANSFORMATION_MATRIX_EQ(
802 SS1 * R * S2,
803 render_surface2->render_surface()->replica_draw_transform());
804 EXPECT_TRANSFORMATION_MATRIX_EQ(
805 A * A * A * S2,
806 render_surface2->render_surface()->screen_space_transform());
807 EXPECT_TRANSFORMATION_MATRIX_EQ(
808 A * A * R * S2,
809 render_surface2->render_surface()->replica_screen_space_transform());
811 // Sanity check. If these fail there is probably a bug in the test itself. It
812 // is expected that we correctly set up transforms so that the y-component of
813 // the screen-space transform encodes the "depth" of the layer in the tree.
814 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
815 EXPECT_FLOAT_EQ(2.0,
816 child_of_root->screen_space_transform().matrix().get(1, 3));
817 EXPECT_FLOAT_EQ(
818 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
820 EXPECT_FLOAT_EQ(2.0,
821 render_surface1->screen_space_transform().matrix().get(1, 3));
822 EXPECT_FLOAT_EQ(3.0,
823 child_of_rs1->screen_space_transform().matrix().get(1, 3));
824 EXPECT_FLOAT_EQ(
825 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
827 EXPECT_FLOAT_EQ(3.0,
828 render_surface2->screen_space_transform().matrix().get(1, 3));
829 EXPECT_FLOAT_EQ(4.0,
830 child_of_rs2->screen_space_transform().matrix().get(1, 3));
831 EXPECT_FLOAT_EQ(
832 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
835 TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
836 // For layers that flatten their subtree, there should be an orthographic
837 // projection (for x and y values) in the middle of the transform sequence.
838 // Note that the way the code is currently implemented, it is not expected to
839 // use a canonical orthographic projection.
841 LayerImpl* root = root_layer();
842 LayerImpl* child = AddChildToRoot<LayerImpl>();
843 LayerImpl* grand_child = AddChild<LayerImpl>(child);
844 grand_child->SetDrawsContent(true);
845 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
846 great_grand_child->SetDrawsContent(true);
848 gfx::Transform rotation_about_y_axis;
849 rotation_about_y_axis.RotateAboutYAxis(30.0);
851 const gfx::Transform identity_matrix;
852 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
853 gfx::PointF(), gfx::Size(100, 100), true, false,
854 true);
855 SetLayerPropertiesForTesting(child, rotation_about_y_axis, gfx::Point3F(),
856 gfx::PointF(), gfx::Size(10, 10), true, false,
857 true);
858 SetLayerPropertiesForTesting(grand_child, rotation_about_y_axis,
859 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
860 true, false, false);
861 SetLayerPropertiesForTesting(great_grand_child, identity_matrix,
862 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
863 true, false, false);
865 // No layers in this test should preserve 3d.
866 ASSERT_TRUE(root->should_flatten_transform());
867 ASSERT_TRUE(child->should_flatten_transform());
868 ASSERT_TRUE(grand_child->should_flatten_transform());
869 ASSERT_TRUE(great_grand_child->should_flatten_transform());
871 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
872 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
873 gfx::Transform expected_grand_child_draw_transform =
874 rotation_about_y_axis; // draws onto child's render surface
875 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
876 flattened_rotation_about_y.FlattenTo2d();
877 gfx::Transform expected_grand_child_screen_space_transform =
878 flattened_rotation_about_y * rotation_about_y_axis;
879 gfx::Transform expected_great_grand_child_draw_transform =
880 flattened_rotation_about_y;
881 gfx::Transform expected_great_grand_child_screen_space_transform =
882 flattened_rotation_about_y * flattened_rotation_about_y;
884 ExecuteCalculateDrawProperties(root);
886 // The child's draw transform should have been taken by its surface.
887 ASSERT_TRUE(child->render_surface());
888 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
889 child->render_surface()->draw_transform());
890 EXPECT_TRANSFORMATION_MATRIX_EQ(
891 expected_child_screen_space_transform,
892 child->render_surface()->screen_space_transform());
893 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
894 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
895 child->screen_space_transform());
896 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
897 grand_child->draw_transform());
898 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
899 grand_child->screen_space_transform());
900 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
901 great_grand_child->draw_transform());
902 EXPECT_TRANSFORMATION_MATRIX_EQ(
903 expected_great_grand_child_screen_space_transform,
904 great_grand_child->screen_space_transform());
907 TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) {
908 scoped_refptr<Layer> root = Layer::Create(layer_settings());
909 scoped_refptr<Layer> child = Layer::Create(layer_settings());
910 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
911 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
913 gfx::Transform child_transform;
914 child_transform.Translate(50.0, 50.0);
915 child_transform.RotateAboutZAxis(30.0);
917 gfx::Transform grand_child_transform;
918 grand_child_transform.RotateAboutYAxis(90.0);
920 const gfx::Transform identity_matrix;
921 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
922 gfx::PointF(), gfx::Size(200, 200), true, false);
923 SetLayerPropertiesForTesting(child.get(), child_transform, gfx::Point3F(),
924 gfx::PointF(), gfx::Size(10, 10), true, false);
925 SetLayerPropertiesForTesting(grand_child.get(), grand_child_transform,
926 gfx::Point3F(), gfx::PointF(),
927 gfx::Size(100, 100), true, false);
929 root->AddChild(child);
930 child->AddChild(grand_child);
931 grand_child->SetShouldFlattenTransform(false);
933 host()->SetRootLayer(root);
935 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
937 // Mapping grand_child's bounds to target space produces a non-empty rect
938 // that is fully contained within the target's bounds, so grand_child should
939 // be considered fully visible.
940 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
941 grand_child->visible_rect_from_property_trees());
944 TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
945 // A layer that is empty in one axis, but not the other, was accidentally
946 // skipping a necessary translation. Without that translation, the coordinate
947 // space of the layer's draw transform is incorrect.
949 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
950 // but if that layer becomes a render surface, then its draw transform is
951 // implicitly inherited by the rest of the subtree, which then is positioned
952 // incorrectly as a result.
954 scoped_refptr<Layer> root = Layer::Create(layer_settings());
955 scoped_refptr<Layer> child = Layer::Create(layer_settings());
956 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
957 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
959 // The child height is zero, but has non-zero width that should be accounted
960 // for while computing draw transforms.
961 const gfx::Transform identity_matrix;
962 SetLayerPropertiesForTesting(root.get(),
963 identity_matrix,
964 gfx::Point3F(),
965 gfx::PointF(),
966 gfx::Size(100, 100),
967 true,
968 false);
969 SetLayerPropertiesForTesting(child.get(),
970 identity_matrix,
971 gfx::Point3F(),
972 gfx::PointF(),
973 gfx::Size(10, 0),
974 true,
975 false);
976 SetLayerPropertiesForTesting(grand_child.get(),
977 identity_matrix,
978 gfx::Point3F(),
979 gfx::PointF(),
980 gfx::Size(10, 10),
981 true,
982 false);
984 root->AddChild(child);
985 child->AddChild(grand_child);
986 child->SetForceRenderSurface(true);
988 host()->SetRootLayer(root);
990 ExecuteCalculateDrawProperties(root.get());
992 ASSERT_TRUE(child->render_surface());
993 // This is the real test, the rest are sanity checks.
994 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
995 child->render_surface()->draw_transform());
996 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
997 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
998 grand_child->draw_transform());
1001 TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
1002 // Transformations applied at the root of the tree should be forwarded
1003 // to child layers instead of applied to the root RenderSurface.
1004 const gfx::Transform identity_matrix;
1005 LayerImpl* root = root_layer();
1006 root->SetDrawsContent(true);
1007 LayerImpl* child = AddChild<LayerImpl>(root);
1008 child->SetDrawsContent(true);
1010 child->SetScrollClipLayer(root->id());
1012 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1013 gfx::PointF(), gfx::Size(20, 20), true, false,
1014 true);
1015 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1016 gfx::PointF(), gfx::Size(20, 20), true, false,
1017 false);
1019 gfx::Transform translate;
1020 translate.Translate(50, 50);
1022 LayerImplList render_surface_layer_list_impl;
1023 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1024 root, root->bounds(), translate, &render_surface_layer_list_impl);
1025 inputs.property_trees->needs_rebuild = true;
1026 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1027 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1028 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1029 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1032 gfx::Transform scale;
1033 scale.Scale(2, 2);
1035 LayerImplList render_surface_layer_list_impl;
1036 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1037 root, root->bounds(), scale, &render_surface_layer_list_impl);
1038 inputs.property_trees->needs_rebuild = true;
1039 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1040 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1041 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1042 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1045 gfx::Transform rotate;
1046 rotate.Rotate(2);
1048 LayerImplList render_surface_layer_list_impl;
1049 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1050 root, root->bounds(), rotate, &render_surface_layer_list_impl);
1051 inputs.property_trees->needs_rebuild = true;
1052 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1053 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1054 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1055 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1058 gfx::Transform composite;
1059 composite.ConcatTransform(translate);
1060 composite.ConcatTransform(scale);
1061 composite.ConcatTransform(rotate);
1063 LayerImplList render_surface_layer_list_impl;
1064 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1065 root, root->bounds(), composite, &render_surface_layer_list_impl);
1066 inputs.property_trees->needs_rebuild = true;
1067 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1068 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1069 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1070 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1073 // Verify it composes correctly with device scale.
1074 float device_scale_factor = 1.5f;
1077 LayerImplList render_surface_layer_list_impl;
1078 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1079 root, root->bounds(), translate, &render_surface_layer_list_impl);
1080 inputs.device_scale_factor = device_scale_factor;
1081 inputs.property_trees->needs_rebuild = true;
1082 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1083 gfx::Transform device_scaled_translate = translate;
1084 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1085 EXPECT_EQ(device_scaled_translate,
1086 root->draw_properties().target_space_transform);
1087 EXPECT_EQ(device_scaled_translate,
1088 child->draw_properties().target_space_transform);
1089 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1092 // Verify it composes correctly with page scale.
1093 float page_scale_factor = 2.f;
1096 LayerImplList render_surface_layer_list_impl;
1097 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1098 root, root->bounds(), translate, &render_surface_layer_list_impl);
1099 inputs.page_scale_factor = page_scale_factor;
1100 inputs.page_scale_layer = root;
1101 inputs.property_trees->needs_rebuild = true;
1102 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1103 gfx::Transform page_scaled_translate = translate;
1104 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
1105 EXPECT_EQ(page_scaled_translate,
1106 root->draw_properties().target_space_transform);
1107 EXPECT_EQ(page_scaled_translate,
1108 child->draw_properties().target_space_transform);
1109 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1112 // Verify that it composes correctly with transforms directly on root layer.
1113 root->SetTransform(composite);
1116 LayerImplList render_surface_layer_list_impl;
1117 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1118 root, root->bounds(), composite, &render_surface_layer_list_impl);
1119 inputs.property_trees->needs_rebuild = true;
1120 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1121 gfx::Transform compositeSquared = composite;
1122 compositeSquared.ConcatTransform(composite);
1123 EXPECT_TRANSFORMATION_MATRIX_EQ(
1124 compositeSquared, root->draw_properties().target_space_transform);
1125 EXPECT_TRANSFORMATION_MATRIX_EQ(
1126 compositeSquared, child->draw_properties().target_space_transform);
1127 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1131 TEST_F(LayerTreeHostCommonTest,
1132 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
1133 LayerImpl* parent = root_layer();
1134 parent->SetMasksToBounds(true);
1135 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1136 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1137 child->SetDrawsContent(true);
1139 const gfx::Transform identity_matrix;
1140 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1141 gfx::PointF(), gfx::Size(10, 10), true, false,
1142 true);
1143 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1144 gfx::PointF(), gfx::Size(10, 10), true, false,
1145 true);
1146 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1147 gfx::PointF(30.f, 30.f), gfx::Size(10, 10), true,
1148 false, false);
1150 ExecuteCalculateDrawProperties(parent);
1152 // The child layer's content is entirely outside the parent's clip rect, so
1153 // the intermediate render surface should not be listed here, even if it was
1154 // forced to be created. Render surfaces without children or visible content
1155 // are unexpected at draw time (e.g. we might try to create a content texture
1156 // of size 0).
1157 ASSERT_TRUE(parent->render_surface());
1158 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
1161 TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
1162 LayerImpl* parent = root_layer();
1163 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
1164 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1165 child->SetDrawsContent(true);
1167 const gfx::Transform identity_matrix;
1168 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1169 gfx::PointF(), gfx::Size(10, 10), true, false,
1170 true);
1171 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1172 gfx::PointF(), gfx::Size(10, 10), true, false,
1173 false);
1174 render_surface1->SetOpacity(0.f);
1176 LayerImplList render_surface_layer_list;
1177 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1178 parent, parent->bounds(), &render_surface_layer_list);
1179 inputs.can_adjust_raster_scales = true;
1180 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1182 // Since the layer is transparent, render_surface1->render_surface() should
1183 // not have gotten added anywhere. Also, the drawable content rect should not
1184 // have been extended by the children.
1185 ASSERT_TRUE(parent->render_surface());
1186 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1187 EXPECT_EQ(1U, render_surface_layer_list.size());
1188 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1189 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1192 TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
1193 LayerImpl* parent = root_layer();
1194 LayerImpl* child = AddChild<LayerImpl>(parent);
1195 child->SetDrawsContent(true);
1197 const gfx::Transform identity_matrix;
1198 const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode;
1199 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1200 gfx::PointF(), gfx::Size(10, 10), true, false,
1201 true);
1202 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1203 gfx::PointF(), gfx::Size(10, 10), true, false,
1204 true);
1206 child->SetBlendMode(blend_mode);
1207 child->SetOpacity(0.5f);
1209 ExecuteCalculateDrawProperties(parent);
1211 // Since the child layer has a blend mode other than normal, it should get
1212 // its own render surface. Also, layer's draw_properties should contain the
1213 // default blend mode, since the render surface becomes responsible for
1214 // applying the blend mode.
1215 ASSERT_TRUE(child->render_surface());
1216 EXPECT_EQ(1.0f, child->draw_opacity());
1217 EXPECT_EQ(0.5f, child->render_surface()->draw_opacity());
1218 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode());
1221 TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
1222 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1223 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
1224 scoped_refptr<LayerWithForcedDrawsContent> child =
1225 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1226 render_surface1->SetForceRenderSurface(true);
1228 host()->SetRootLayer(parent);
1230 const gfx::Transform identity_matrix;
1231 SetLayerPropertiesForTesting(parent.get(),
1232 identity_matrix,
1233 gfx::Point3F(),
1234 gfx::PointF(),
1235 gfx::Size(10, 10),
1236 true,
1237 false);
1238 SetLayerPropertiesForTesting(render_surface1.get(),
1239 identity_matrix,
1240 gfx::Point3F(),
1241 gfx::PointF(),
1242 gfx::Size(10, 10),
1243 true,
1244 false);
1245 SetLayerPropertiesForTesting(child.get(),
1246 identity_matrix,
1247 gfx::Point3F(),
1248 gfx::PointF(),
1249 gfx::Size(10, 10),
1250 true,
1251 false);
1253 parent->AddChild(render_surface1);
1254 render_surface1->AddChild(child);
1256 // Sanity check before the actual test
1257 EXPECT_FALSE(parent->render_surface());
1258 EXPECT_FALSE(render_surface1->render_surface());
1261 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(parent.get(),
1262 parent->bounds());
1263 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1265 // The root layer always creates a render surface
1266 EXPECT_TRUE(parent->render_surface());
1267 EXPECT_TRUE(render_surface1->render_surface());
1271 render_surface1->SetForceRenderSurface(false);
1272 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(parent.get(),
1273 parent->bounds());
1274 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1275 EXPECT_TRUE(parent->render_surface());
1276 EXPECT_FALSE(render_surface1->render_surface());
1280 TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1281 // Render surfaces act as a flattening point for their subtree, so should
1282 // always flatten the target-to-screen space transform seen by descendants.
1284 LayerImpl* root = root_layer();
1285 LayerImpl* parent = AddChild<LayerImpl>(root);
1286 LayerImpl* child = AddChild<LayerImpl>(parent);
1287 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1289 child->SetDrawsContent(true);
1290 grand_child->SetDrawsContent(true);
1292 gfx::Transform rotation_about_y_axis;
1293 rotation_about_y_axis.RotateAboutYAxis(30.0);
1294 // Make |parent| have a render surface.
1295 parent->SetOpacity(0.9f);
1297 const gfx::Transform identity_matrix;
1298 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1299 gfx::PointF(), gfx::Size(100, 100), true, false,
1300 true);
1301 SetLayerPropertiesForTesting(parent, rotation_about_y_axis, gfx::Point3F(),
1302 gfx::PointF(), gfx::Size(10, 10), true, false,
1303 true);
1304 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1305 gfx::PointF(), gfx::Size(10, 10), true, false,
1306 false);
1307 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1308 gfx::PointF(), gfx::Size(10, 10), true, false,
1309 false);
1311 grand_child->SetShouldFlattenTransform(false);
1313 // Only grand_child should preserve 3d.
1314 EXPECT_TRUE(root->should_flatten_transform());
1315 EXPECT_TRUE(parent->should_flatten_transform());
1316 EXPECT_TRUE(child->should_flatten_transform());
1317 EXPECT_FALSE(grand_child->should_flatten_transform());
1319 gfx::Transform expected_child_draw_transform = identity_matrix;
1320 gfx::Transform expected_grand_child_draw_transform = identity_matrix;
1322 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1323 flattened_rotation_about_y.FlattenTo2d();
1325 ExecuteCalculateDrawProperties(root);
1327 EXPECT_TRUE(parent->render_surface());
1328 EXPECT_FALSE(child->render_surface());
1329 EXPECT_FALSE(grand_child->render_surface());
1331 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1332 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1333 grand_child->draw_transform());
1335 // The screen-space transform inherited by |child| and |grand_child| should
1336 // have been flattened at their render target. In particular, the fact that
1337 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1338 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
1339 child->screen_space_transform());
1340 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
1341 grand_child->screen_space_transform());
1344 TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
1345 // The entire subtree of layers that are outside the clip rect should be
1346 // culled away, and should not affect the render_surface_layer_list.
1348 // The test tree is set up as follows:
1349 // - all layers except the leaf_nodes are forced to be a new render surface
1350 // that have something to draw.
1351 // - parent is a large container layer.
1352 // - child has masksToBounds=true to cause clipping.
1353 // - grand_child is positioned outside of the child's bounds
1354 // - great_grand_child is also kept outside child's bounds.
1356 // In this configuration, grand_child and great_grand_child are completely
1357 // outside the clip rect, and they should never get scheduled on the list of
1358 // render surfaces.
1360 LayerImpl* parent = root_layer();
1361 LayerImpl* child = AddChildToRoot<LayerImpl>();
1362 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1363 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
1365 // leaf_node1 ensures that parent and child are kept on the
1366 // render_surface_layer_list, even though grand_child and great_grand_child
1367 // should be clipped.
1368 LayerImpl* leaf_node1 = AddChild<LayerImpl>(child);
1369 leaf_node1->SetDrawsContent(true);
1370 LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child);
1371 leaf_node2->SetDrawsContent(true);
1373 const gfx::Transform identity_matrix;
1375 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1376 gfx::PointF(), gfx::Size(500, 500), true, false,
1377 true);
1378 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1379 gfx::PointF(), gfx::Size(20, 20), true, false,
1380 true);
1381 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1382 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
1383 false, false);
1384 SetLayerPropertiesForTesting(great_grand_child, identity_matrix,
1385 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1386 true, false, false);
1387 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1388 gfx::PointF(), gfx::Size(500, 500), true, false,
1389 false);
1390 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1391 gfx::PointF(), gfx::Size(20, 20), true, false,
1392 false);
1394 child->SetMasksToBounds(true);
1395 child->SetOpacity(0.4f);
1396 grand_child->SetOpacity(0.5f);
1397 great_grand_child->SetOpacity(0.4f);
1399 ExecuteCalculateDrawProperties(parent);
1401 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
1402 EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id());
1403 EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id());
1406 TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
1407 // When a render surface has a clip rect, it is used to clip the content rect
1408 // of the surface.
1410 // The test tree is set up as follows:
1411 // - parent is a container layer that masksToBounds=true to cause clipping.
1412 // - child is a render surface, which has a clip rect set to the bounds of
1413 // the parent.
1414 // - grand_child is a render surface, and the only visible content in child.
1415 // It is positioned outside of the clip rect from parent.
1417 // In this configuration, grand_child should be outside the clipped
1418 // content rect of the child, making grand_child not appear in the
1419 // render_surface_layer_list.
1421 LayerImpl* parent = root_layer();
1422 LayerImpl* child = AddChildToRoot<LayerImpl>();
1423 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1424 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
1425 leaf_node->SetDrawsContent(true);
1427 const gfx::Transform identity_matrix;
1429 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1430 gfx::PointF(), gfx::Size(100, 100), true, false,
1431 true);
1432 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1433 gfx::PointF(), gfx::Size(20, 20), true, false,
1434 true);
1435 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1436 gfx::PointF(200.f, 200.f), gfx::Size(10, 10),
1437 true, false, true);
1438 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
1439 gfx::PointF(), gfx::Size(10, 10), true, false,
1440 false);
1442 parent->SetMasksToBounds(true);
1443 child->SetOpacity(0.4f);
1444 grand_child->SetOpacity(0.4f);
1446 ExecuteCalculateDrawProperties(parent);
1448 // We should cull child and grand_child from the
1449 // render_surface_layer_list.
1450 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
1451 EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id());
1454 TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
1455 // Layer's IsClipped() property is set to true when:
1456 // - the layer clips its subtree, e.g. masks to bounds,
1457 // - the layer is clipped by an ancestor that contributes to the same
1458 // render target,
1459 // - a surface is clipped by an ancestor that contributes to the same
1460 // render target.
1462 // In particular, for a layer that owns a render surface:
1463 // - the render surface inherits any clip from ancestors, and does NOT
1464 // pass that clipped status to the layer itself.
1465 // - but if the layer itself masks to bounds, it is considered clipped
1466 // and propagates the clip to the subtree.
1468 const gfx::Transform identity_matrix;
1469 scoped_refptr<Layer> root = Layer::Create(layer_settings());
1470 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1471 scoped_refptr<Layer> child1 = Layer::Create(layer_settings());
1472 scoped_refptr<Layer> child2 = Layer::Create(layer_settings());
1473 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
1474 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1475 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1476 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1477 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1478 root->AddChild(parent);
1479 parent->AddChild(child1);
1480 parent->AddChild(child2);
1481 child1->AddChild(grand_child);
1482 child2->AddChild(leaf_node2);
1483 grand_child->AddChild(leaf_node1);
1485 host()->SetRootLayer(root);
1487 child2->SetForceRenderSurface(true);
1489 SetLayerPropertiesForTesting(root.get(),
1490 identity_matrix,
1491 gfx::Point3F(),
1492 gfx::PointF(),
1493 gfx::Size(100, 100),
1494 true,
1495 false);
1496 SetLayerPropertiesForTesting(parent.get(),
1497 identity_matrix,
1498 gfx::Point3F(),
1499 gfx::PointF(),
1500 gfx::Size(100, 100),
1501 true,
1502 false);
1503 SetLayerPropertiesForTesting(child1.get(),
1504 identity_matrix,
1505 gfx::Point3F(),
1506 gfx::PointF(),
1507 gfx::Size(100, 100),
1508 true,
1509 false);
1510 SetLayerPropertiesForTesting(child2.get(),
1511 identity_matrix,
1512 gfx::Point3F(),
1513 gfx::PointF(),
1514 gfx::Size(100, 100),
1515 true,
1516 false);
1517 SetLayerPropertiesForTesting(grand_child.get(),
1518 identity_matrix,
1519 gfx::Point3F(),
1520 gfx::PointF(),
1521 gfx::Size(100, 100),
1522 true,
1523 false);
1524 SetLayerPropertiesForTesting(leaf_node1.get(),
1525 identity_matrix,
1526 gfx::Point3F(),
1527 gfx::PointF(),
1528 gfx::Size(100, 100),
1529 true,
1530 false);
1531 SetLayerPropertiesForTesting(leaf_node2.get(),
1532 identity_matrix,
1533 gfx::Point3F(),
1534 gfx::PointF(),
1535 gfx::Size(100, 100),
1536 true,
1537 false);
1539 // Case 1: nothing is clipped except the root render surface.
1541 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(root.get(),
1542 parent->bounds());
1543 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1545 ASSERT_TRUE(root->render_surface());
1546 ASSERT_TRUE(child2->render_surface());
1548 EXPECT_FALSE(root->is_clipped());
1549 EXPECT_FALSE(parent->is_clipped());
1550 EXPECT_FALSE(child1->is_clipped());
1551 EXPECT_FALSE(child2->is_clipped());
1552 EXPECT_FALSE(grand_child->is_clipped());
1553 EXPECT_FALSE(leaf_node1->is_clipped());
1554 EXPECT_FALSE(leaf_node2->is_clipped());
1557 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1558 // surface are clipped. But layers that contribute to child2's surface are
1559 // not clipped explicitly because child2's surface already accounts for
1560 // that clip.
1562 parent->SetMasksToBounds(true);
1563 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(root.get(),
1564 parent->bounds());
1565 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1567 ASSERT_TRUE(root->render_surface());
1568 ASSERT_TRUE(child2->render_surface());
1570 EXPECT_FALSE(root->is_clipped());
1571 EXPECT_TRUE(parent->is_clipped());
1572 EXPECT_TRUE(child1->is_clipped());
1573 EXPECT_FALSE(child2->is_clipped());
1574 EXPECT_TRUE(grand_child->is_clipped());
1575 EXPECT_TRUE(leaf_node1->is_clipped());
1576 EXPECT_FALSE(leaf_node2->is_clipped());
1579 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1580 // child2's render surface is not clipped.
1582 parent->SetMasksToBounds(false);
1583 child2->SetMasksToBounds(true);
1584 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(root.get(),
1585 parent->bounds());
1586 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1588 ASSERT_TRUE(root->render_surface());
1589 ASSERT_TRUE(child2->render_surface());
1591 EXPECT_FALSE(root->is_clipped());
1592 EXPECT_FALSE(parent->is_clipped());
1593 EXPECT_FALSE(child1->is_clipped());
1594 EXPECT_TRUE(child2->is_clipped());
1595 EXPECT_FALSE(grand_child->is_clipped());
1596 EXPECT_FALSE(leaf_node1->is_clipped());
1597 EXPECT_TRUE(leaf_node2->is_clipped());
1601 TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) {
1602 // This is identical to the IsClippedIsSetCorrectly test,
1603 // but tests render surfaces instead of the layers.
1605 const gfx::Transform identity_matrix;
1606 LayerImpl* root = root_layer();
1607 LayerImpl* parent = AddChild<LayerImpl>(root);
1608 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1609 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1610 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1611 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1612 leaf_node1->SetDrawsContent(true);
1613 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1614 leaf_node2->SetDrawsContent(true);
1616 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1617 gfx::PointF(), gfx::Size(100, 100), true, false,
1618 true);
1619 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1620 gfx::PointF(), gfx::Size(100, 100), true, false,
1621 false);
1622 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1623 gfx::PointF(), gfx::Size(100, 100), true, false,
1624 false);
1625 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1626 gfx::PointF(), gfx::Size(100, 100), true, false,
1627 true);
1628 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1629 gfx::PointF(), gfx::Size(100, 100), true, false,
1630 false);
1631 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1632 gfx::PointF(), gfx::Size(100, 100), true, false,
1633 false);
1634 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1635 gfx::PointF(), gfx::Size(100, 100), true, false,
1636 false);
1638 // Case 1: nothing is clipped except the root render surface.
1640 ExecuteCalculateDrawProperties(root);
1642 ASSERT_TRUE(root->render_surface());
1643 ASSERT_TRUE(child2->render_surface());
1645 EXPECT_FALSE(root->is_clipped());
1646 EXPECT_TRUE(root->render_surface()->is_clipped());
1647 EXPECT_FALSE(parent->is_clipped());
1648 EXPECT_FALSE(child1->is_clipped());
1649 EXPECT_FALSE(child2->is_clipped());
1650 EXPECT_FALSE(child2->render_surface()->is_clipped());
1651 EXPECT_FALSE(grand_child->is_clipped());
1652 EXPECT_FALSE(leaf_node1->is_clipped());
1653 EXPECT_FALSE(leaf_node2->is_clipped());
1656 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1657 // surface are clipped. But layers that contribute to child2's surface are
1658 // not clipped explicitly because child2's surface already accounts for
1659 // that clip.
1661 parent->SetMasksToBounds(true);
1663 parent->set_is_clipped(true);
1664 child1->set_is_clipped(true);
1665 grand_child->set_is_clipped(true);
1666 leaf_node1->set_is_clipped(true);
1667 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1669 ExecuteCalculateDrawProperties(root);
1671 ASSERT_TRUE(root->render_surface());
1672 ASSERT_TRUE(child2->render_surface());
1674 EXPECT_TRUE(root->render_surface()->is_clipped());
1675 EXPECT_TRUE(child2->render_surface()->is_clipped());
1677 parent->SetMasksToBounds(false);
1678 parent->set_is_clipped(false);
1679 child1->set_is_clipped(false);
1680 grand_child->set_is_clipped(false);
1681 leaf_node1->set_is_clipped(false);
1684 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1685 // child2's render surface is not clipped.
1687 child2->SetMasksToBounds(true);
1688 child2->set_is_clipped(true);
1689 leaf_node2->set_is_clipped(true);
1690 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1692 ExecuteCalculateDrawProperties(root);
1694 ASSERT_TRUE(root->render_surface());
1695 ASSERT_TRUE(child2->render_surface());
1697 EXPECT_FALSE(root->is_clipped());
1698 EXPECT_TRUE(root->render_surface()->is_clipped());
1699 EXPECT_FALSE(parent->is_clipped());
1700 EXPECT_FALSE(child1->is_clipped());
1701 EXPECT_TRUE(child2->is_clipped());
1702 EXPECT_FALSE(child2->render_surface()->is_clipped());
1703 EXPECT_FALSE(grand_child->is_clipped());
1704 EXPECT_FALSE(leaf_node1->is_clipped());
1705 EXPECT_TRUE(leaf_node2->is_clipped());
1709 TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
1710 // Verify that layers get the appropriate DrawableContentRect when their
1711 // parent masksToBounds is true.
1713 // grand_child1 - completely inside the region; DrawableContentRect should
1714 // be the layer rect expressed in target space.
1715 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1716 // will be the intersection of layer bounds and the mask region.
1717 // grand_child3 - partially clipped and masksToBounds; the
1718 // DrawableContentRect will still be the intersection of layer bounds and
1719 // the mask region.
1720 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1721 // be empty.
1723 const gfx::Transform identity_matrix;
1724 LayerImpl* parent = root_layer();
1725 LayerImpl* child = AddChild<LayerImpl>(parent);
1726 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
1727 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
1728 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
1729 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
1731 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1732 gfx::PointF(), gfx::Size(500, 500), true, false,
1733 true);
1734 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1735 gfx::PointF(), gfx::Size(20, 20), true, false,
1736 true);
1737 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
1738 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
1739 false, false);
1740 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
1741 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
1742 false, false);
1743 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
1744 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
1745 false, false);
1746 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
1747 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
1748 false, false);
1750 child->SetMasksToBounds(true);
1751 grand_child3->SetMasksToBounds(true);
1753 // Force child to be a render surface.
1754 child->SetOpacity(0.4f);
1756 ExecuteCalculateDrawProperties(parent);
1758 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
1759 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
1760 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
1761 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
1764 TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
1765 // Verify that render surfaces (and their layers) get the appropriate
1766 // clip rects when their parent masksToBounds is true.
1768 // Layers that own render surfaces (at least for now) do not inherit any
1769 // clipping; instead the surface will enforce the clip for the entire subtree.
1770 // They may still have a clip rect of their own layer bounds, however, if
1771 // masksToBounds was true.
1772 LayerImpl* parent = root_layer();
1773 LayerImpl* child = AddChildToRoot<LayerImpl>();
1774 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
1775 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
1776 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
1777 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
1778 // the leaf nodes ensure that these grand_children become render surfaces for
1779 // this test.
1780 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
1781 leaf_node1->SetDrawsContent(true);
1782 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
1783 leaf_node2->SetDrawsContent(true);
1784 LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3);
1785 leaf_node3->SetDrawsContent(true);
1786 LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4);
1787 leaf_node4->SetDrawsContent(true);
1789 const gfx::Transform identity_matrix;
1791 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1792 gfx::PointF(), gfx::Size(500, 500), true, false,
1793 true);
1794 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1795 gfx::PointF(), gfx::Size(20, 20), true, false,
1796 true);
1797 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
1798 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
1799 false, true);
1800 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
1801 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
1802 false, true);
1803 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
1804 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
1805 false, true);
1806 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
1807 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
1808 false, true);
1809 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1810 gfx::PointF(), gfx::Size(10, 10), true, false,
1811 false);
1812 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1813 gfx::PointF(), gfx::Size(10, 10), true, false,
1814 false);
1815 SetLayerPropertiesForTesting(leaf_node3, identity_matrix, gfx::Point3F(),
1816 gfx::PointF(), gfx::Size(10, 10), true, false,
1817 false);
1818 SetLayerPropertiesForTesting(leaf_node4, identity_matrix, gfx::Point3F(),
1819 gfx::PointF(), gfx::Size(10, 10), true, false,
1820 false);
1822 child->SetMasksToBounds(true);
1823 grand_child3->SetMasksToBounds(true);
1824 grand_child4->SetMasksToBounds(true);
1826 // Force everyone to be a render surface.
1827 child->SetOpacity(0.4f);
1828 grand_child1->SetOpacity(0.5f);
1829 grand_child2->SetOpacity(0.5f);
1830 grand_child3->SetOpacity(0.5f);
1831 grand_child4->SetOpacity(0.5f);
1833 ExecuteCalculateDrawProperties(parent);
1835 ASSERT_TRUE(grand_child1->render_surface());
1836 ASSERT_TRUE(grand_child2->render_surface());
1837 ASSERT_TRUE(grand_child3->render_surface());
1839 // Surfaces are clipped by their parent, but un-affected by the owning layer's
1840 // masksToBounds.
1841 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1842 grand_child1->render_surface()->clip_rect());
1843 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1844 grand_child2->render_surface()->clip_rect());
1845 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1846 grand_child3->render_surface()->clip_rect());
1849 TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
1850 LayerImpl* parent = root_layer();
1851 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1852 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
1853 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
1854 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
1855 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
1856 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
1857 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>();
1858 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
1860 grand_child_of_rs1->SetDrawsContent(true);
1861 grand_child_of_rs2->SetDrawsContent(true);
1863 gfx::Transform layer_transform;
1864 layer_transform.Translate(1.0, 1.0);
1866 SetLayerPropertiesForTesting(
1867 parent, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
1868 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
1869 SetLayerPropertiesForTesting(
1870 render_surface1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
1871 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
1872 SetLayerPropertiesForTesting(
1873 render_surface2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
1874 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
1875 SetLayerPropertiesForTesting(
1876 child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
1877 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
1878 SetLayerPropertiesForTesting(
1879 child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
1880 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
1881 SetLayerPropertiesForTesting(
1882 child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
1883 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
1884 SetLayerPropertiesForTesting(
1885 grand_child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
1886 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
1887 SetLayerPropertiesForTesting(
1888 grand_child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
1889 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
1890 SetLayerPropertiesForTesting(
1891 grand_child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
1892 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
1894 // Put an animated opacity on the render surface.
1895 AddOpacityTransitionToController(
1896 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
1898 // Also put an animated opacity on a layer without descendants.
1899 AddOpacityTransitionToController(
1900 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
1902 // Put a transform animation on the render surface.
1903 AddAnimatedTransformToController(
1904 render_surface2->layer_animation_controller(), 10.0, 30, 0);
1906 // Also put transform animations on grand_child_of_root, and
1907 // grand_child_of_rs2
1908 AddAnimatedTransformToController(
1909 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
1910 AddAnimatedTransformToController(
1911 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
1913 ExecuteCalculateDrawProperties(parent);
1915 // Only layers that are associated with render surfaces should have an actual
1916 // RenderSurface() value.
1917 ASSERT_TRUE(parent->render_surface());
1918 ASSERT_FALSE(child_of_root->render_surface());
1919 ASSERT_FALSE(grand_child_of_root->render_surface());
1921 ASSERT_TRUE(render_surface1->render_surface());
1922 ASSERT_FALSE(child_of_rs1->render_surface());
1923 ASSERT_FALSE(grand_child_of_rs1->render_surface());
1925 ASSERT_TRUE(render_surface2->render_surface());
1926 ASSERT_FALSE(child_of_rs2->render_surface());
1927 ASSERT_FALSE(grand_child_of_rs2->render_surface());
1929 // Verify all render target accessors
1930 EXPECT_EQ(parent, parent->render_target());
1931 EXPECT_EQ(parent, child_of_root->render_target());
1932 EXPECT_EQ(parent, grand_child_of_root->render_target());
1934 EXPECT_EQ(render_surface1, render_surface1->render_target());
1935 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
1936 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
1938 EXPECT_EQ(render_surface2, render_surface2->render_target());
1939 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
1940 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
1942 // Verify screen_space_transform_is_animating values
1943 EXPECT_FALSE(parent->screen_space_transform_is_animating());
1944 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
1945 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
1946 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
1947 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
1948 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
1949 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
1950 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
1951 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
1953 // Sanity check. If these fail there is probably a bug in the test itself.
1954 // It is expected that we correctly set up transforms so that the y-component
1955 // of the screen-space transform encodes the "depth" of the layer in the tree.
1956 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
1957 EXPECT_FLOAT_EQ(2.0,
1958 child_of_root->screen_space_transform().matrix().get(1, 3));
1959 EXPECT_FLOAT_EQ(
1960 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
1962 EXPECT_FLOAT_EQ(2.0,
1963 render_surface1->screen_space_transform().matrix().get(1, 3));
1964 EXPECT_FLOAT_EQ(3.0,
1965 child_of_rs1->screen_space_transform().matrix().get(1, 3));
1966 EXPECT_FLOAT_EQ(
1967 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
1969 EXPECT_FLOAT_EQ(3.0,
1970 render_surface2->screen_space_transform().matrix().get(1, 3));
1971 EXPECT_FLOAT_EQ(4.0,
1972 child_of_rs2->screen_space_transform().matrix().get(1, 3));
1973 EXPECT_FLOAT_EQ(
1974 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
1977 TEST_F(LayerTreeHostCommonTest,
1978 ScreenSpaceTransformIsAnimatingWithDelayedAnimation) {
1979 LayerImpl* parent = root_layer();
1980 LayerImpl* child = AddChild<LayerImpl>(parent);
1981 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1982 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
1984 parent->SetDrawsContent(true);
1985 child->SetDrawsContent(true);
1986 grand_child->SetDrawsContent(true);
1987 great_grand_child->SetDrawsContent(true);
1989 gfx::Transform identity;
1991 SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(),
1992 gfx::Size(10, 10), true, false, true);
1993 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
1994 gfx::Size(10, 10), true, false, false);
1995 SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(),
1996 gfx::PointF(), gfx::Size(10, 10), true, false,
1997 false);
1998 SetLayerPropertiesForTesting(great_grand_child, identity, gfx::Point3F(),
1999 gfx::PointF(), gfx::Size(10, 10), true, false,
2000 false);
2002 // Add a transform animation with a start delay to |grand_child|.
2003 scoped_ptr<Animation> animation = Animation::Create(
2004 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(), 0, 1,
2005 Animation::TRANSFORM);
2006 animation->set_fill_mode(Animation::FILL_MODE_NONE);
2007 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
2008 grand_child->layer_animation_controller()->AddAnimation(animation.Pass());
2010 ExecuteCalculateDrawProperties(parent);
2012 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2013 EXPECT_FALSE(child->screen_space_transform_is_animating());
2015 EXPECT_FALSE(grand_child->TransformIsAnimating());
2016 EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation());
2017 EXPECT_TRUE(grand_child->screen_space_transform_is_animating());
2018 EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating());
2021 TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
2022 // Test the calculateVisibleRect() function works correctly for identity
2023 // transforms.
2025 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2026 gfx::Transform layer_to_surface_transform;
2028 // Case 1: Layer is contained within the surface.
2029 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
2030 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
2031 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2032 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2033 EXPECT_EQ(expected, actual);
2035 // Case 2: Layer is outside the surface rect.
2036 layer_content_rect = gfx::Rect(120, 120, 30, 30);
2037 actual = LayerTreeHostCommon::CalculateVisibleRect(
2038 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2039 EXPECT_TRUE(actual.IsEmpty());
2041 // Case 3: Layer is partially overlapping the surface rect.
2042 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2043 expected = gfx::Rect(80, 80, 20, 20);
2044 actual = LayerTreeHostCommon::CalculateVisibleRect(
2045 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2046 EXPECT_EQ(expected, actual);
2049 TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
2050 // Test the calculateVisibleRect() function works correctly for scaling
2051 // transforms.
2053 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2054 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
2055 gfx::Transform layer_to_surface_transform;
2057 // Case 1: Layer is contained within the surface.
2058 layer_to_surface_transform.MakeIdentity();
2059 layer_to_surface_transform.Translate(10.0, 10.0);
2060 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
2061 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2062 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2063 EXPECT_EQ(expected, actual);
2065 // Case 2: Layer is outside the surface rect.
2066 layer_to_surface_transform.MakeIdentity();
2067 layer_to_surface_transform.Translate(120.0, 120.0);
2068 actual = LayerTreeHostCommon::CalculateVisibleRect(
2069 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2070 EXPECT_TRUE(actual.IsEmpty());
2072 // Case 3: Layer is partially overlapping the surface rect.
2073 layer_to_surface_transform.MakeIdentity();
2074 layer_to_surface_transform.Translate(80.0, 80.0);
2075 expected = gfx::Rect(0, 0, 20, 20);
2076 actual = LayerTreeHostCommon::CalculateVisibleRect(
2077 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2078 EXPECT_EQ(expected, actual);
2081 TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
2082 // Test the calculateVisibleRect() function works correctly for rotations
2083 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2084 // should return the g in the layer's space.
2086 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2087 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
2088 gfx::Transform layer_to_surface_transform;
2090 // Case 1: Layer is contained within the surface.
2091 layer_to_surface_transform.MakeIdentity();
2092 layer_to_surface_transform.Translate(50.0, 50.0);
2093 layer_to_surface_transform.Rotate(45.0);
2094 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
2095 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2096 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2097 EXPECT_EQ(expected, actual);
2099 // Case 2: Layer is outside the surface rect.
2100 layer_to_surface_transform.MakeIdentity();
2101 layer_to_surface_transform.Translate(-50.0, 0.0);
2102 layer_to_surface_transform.Rotate(45.0);
2103 actual = LayerTreeHostCommon::CalculateVisibleRect(
2104 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2105 EXPECT_TRUE(actual.IsEmpty());
2107 // Case 3: The layer is rotated about its top-left corner. In surface space,
2108 // the layer is oriented diagonally, with the left half outside of the render
2109 // surface. In this case, the g should still be the entire layer
2110 // (remember the g is computed in layer space); both the top-left
2111 // and bottom-right corners of the layer are still visible.
2112 layer_to_surface_transform.MakeIdentity();
2113 layer_to_surface_transform.Rotate(45.0);
2114 expected = gfx::Rect(0, 0, 30, 30);
2115 actual = LayerTreeHostCommon::CalculateVisibleRect(
2116 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2117 EXPECT_EQ(expected, actual);
2119 // Case 4: The layer is rotated about its top-left corner, and translated
2120 // upwards. In surface space, the layer is oriented diagonally, with only the
2121 // top corner of the surface overlapping the layer. In layer space, the render
2122 // surface overlaps the right side of the layer. The g should be
2123 // the layer's right half.
2124 layer_to_surface_transform.MakeIdentity();
2125 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2126 layer_to_surface_transform.Rotate(45.0);
2127 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
2128 actual = LayerTreeHostCommon::CalculateVisibleRect(
2129 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2130 EXPECT_EQ(expected, actual);
2133 TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
2134 // Test that the calculateVisibleRect() function works correctly for 3d
2135 // transforms.
2137 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2138 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
2139 gfx::Transform layer_to_surface_transform;
2141 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2142 // degrees, should be fully contained in the render surface.
2143 layer_to_surface_transform.MakeIdentity();
2144 layer_to_surface_transform.RotateAboutYAxis(45.0);
2145 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
2146 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2147 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2148 EXPECT_EQ(expected, actual);
2150 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2151 // degrees, but shifted to the side so only the right-half the layer would be
2152 // visible on the surface.
2153 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2154 SkMScalar half_width_of_rotated_layer =
2155 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
2156 layer_to_surface_transform.MakeIdentity();
2157 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
2158 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2159 // edge of the layer.
2160 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
2161 actual = LayerTreeHostCommon::CalculateVisibleRect(
2162 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2163 EXPECT_EQ(expected, actual);
2166 TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
2167 // Test the calculateVisibleRect() function works correctly when the layer has
2168 // a perspective projection onto the target surface.
2170 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2171 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
2172 gfx::Transform layer_to_surface_transform;
2174 // Case 1: Even though the layer is twice as large as the surface, due to
2175 // perspective foreshortening, the layer will fit fully in the surface when
2176 // its translated more than the perspective amount.
2177 layer_to_surface_transform.MakeIdentity();
2179 // The following sequence of transforms applies the perspective about the
2180 // center of the surface.
2181 layer_to_surface_transform.Translate(50.0, 50.0);
2182 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2183 layer_to_surface_transform.Translate(-50.0, -50.0);
2185 // This translate places the layer in front of the surface's projection plane.
2186 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2188 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
2189 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2190 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2191 EXPECT_EQ(expected, actual);
2193 // Case 2: same projection as before, except that the layer is also translated
2194 // to the side, so that only the right half of the layer should be visible.
2196 // Explanation of expected result: The perspective ratio is (z distance
2197 // between layer and camera origin) / (z distance between projection plane and
2198 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2199 // move a layer by translating -50 units in projected surface units (so that
2200 // only half of it is visible), then we would need to translate by (-36 / 9) *
2201 // -50 == -200 in the layer's units.
2202 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
2203 expected = gfx::Rect(gfx::Point(50, -50),
2204 gfx::Size(100, 200)); // The right half of the layer's
2205 // bounding rect.
2206 actual = LayerTreeHostCommon::CalculateVisibleRect(
2207 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2208 EXPECT_EQ(expected, actual);
2211 TEST_F(LayerTreeHostCommonTest,
2212 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
2213 // There is currently no explicit concept of an orthographic projection plane
2214 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2215 // are technically behind the surface in an orthographic world should not be
2216 // clipped when they are flattened to the surface.
2218 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2219 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
2220 gfx::Transform layer_to_surface_transform;
2222 // This sequence of transforms effectively rotates the layer about the y-axis
2223 // at the center of the layer.
2224 layer_to_surface_transform.MakeIdentity();
2225 layer_to_surface_transform.Translate(50.0, 0.0);
2226 layer_to_surface_transform.RotateAboutYAxis(45.0);
2227 layer_to_surface_transform.Translate(-50.0, 0.0);
2229 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
2230 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2231 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2232 EXPECT_EQ(expected, actual);
2235 TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
2236 // Test the calculateVisibleRect() function works correctly when projecting a
2237 // surface onto a layer, but the layer is partially behind the camera (not
2238 // just behind the projection plane). In this case, the cartesian coordinates
2239 // may seem to be valid, but actually they are not. The visible rect needs to
2240 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2241 // converting to cartesian coordinates.
2243 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2244 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
2245 gfx::Transform layer_to_surface_transform;
2247 // The layer is positioned so that the right half of the layer should be in
2248 // front of the camera, while the other half is behind the surface's
2249 // projection plane. The following sequence of transforms applies the
2250 // perspective and rotation about the center of the layer.
2251 layer_to_surface_transform.MakeIdentity();
2252 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2253 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2254 layer_to_surface_transform.RotateAboutYAxis(45.0);
2256 // Sanity check that this transform does indeed cause w < 0 when applying the
2257 // transform, otherwise this code is not testing the intended scenario.
2258 bool clipped;
2259 MathUtil::MapQuad(layer_to_surface_transform,
2260 gfx::QuadF(gfx::RectF(layer_content_rect)),
2261 &clipped);
2262 ASSERT_TRUE(clipped);
2264 int expected_x_position = 0;
2265 int expected_width = 10;
2266 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2267 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2268 EXPECT_EQ(expected_x_position, actual.x());
2269 EXPECT_EQ(expected_width, actual.width());
2272 TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
2273 // To determine visible rect in layer space, there needs to be an
2274 // un-projection from surface space to layer space. When the original
2275 // transform was a perspective projection that was clipped, it returns a rect
2276 // that encloses the clipped bounds. Un-projecting this new rect may require
2277 // clipping again.
2279 // This sequence of transforms causes one corner of the layer to protrude
2280 // across the w = 0 plane, and should be clipped.
2281 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2282 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
2283 gfx::Transform layer_to_surface_transform;
2284 layer_to_surface_transform.MakeIdentity();
2285 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2286 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2287 layer_to_surface_transform.RotateAboutYAxis(45.0);
2288 layer_to_surface_transform.RotateAboutXAxis(80.0);
2290 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2291 // code is not testing the intended scenario.
2292 bool clipped;
2293 gfx::RectF clipped_rect =
2294 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
2295 MathUtil::ProjectQuad(
2296 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2297 ASSERT_TRUE(clipped);
2299 // Only the corner of the layer is not visible on the surface because of being
2300 // clipped. But, the net result of rounding visible region to an axis-aligned
2301 // rect is that the entire layer should still be considered visible.
2302 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
2303 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2304 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2305 EXPECT_EQ(expected, actual);
2308 TEST_F(LayerTreeHostCommonTest,
2309 VisibleRectsForPositionedRootLayerClippedByViewport) {
2310 LayerImpl* root = root_layer();
2311 root->SetDrawsContent(true);
2313 gfx::Transform identity_matrix;
2314 // Root layer is positioned at (60, 70). The default device viewport size
2315 // is (0, 0, 100x100) in target space. So the root layer's visible rect
2316 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space.
2317 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2318 gfx::PointF(60, 70), gfx::Size(100, 100), true,
2319 false, true);
2320 ExecuteCalculateDrawProperties(root);
2322 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2323 root->render_surface()->DrawableContentRect());
2324 // In target space, not clipped.
2325 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
2326 // In layer space, clipped.
2327 EXPECT_EQ(gfx::Rect(0, 0, 40, 30), root->visible_layer_rect());
2330 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
2331 LayerImpl* root = root_layer();
2332 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>();
2333 child1_layer->SetDrawsContent(true);
2334 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>();
2335 child2_layer->SetDrawsContent(true);
2336 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>();
2337 child3_layer->SetDrawsContent(true);
2339 gfx::Transform identity_matrix;
2340 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2341 gfx::PointF(), gfx::Size(100, 100), true, false,
2342 true);
2343 SetLayerPropertiesForTesting(child1_layer, identity_matrix, gfx::Point3F(),
2344 gfx::PointF(), gfx::Size(50, 50), true, false,
2345 false);
2346 SetLayerPropertiesForTesting(child2_layer, identity_matrix, gfx::Point3F(),
2347 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2348 false, false);
2349 SetLayerPropertiesForTesting(child3_layer, identity_matrix, gfx::Point3F(),
2350 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2351 true, false, false);
2353 ExecuteCalculateDrawProperties(root);
2355 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2356 root->render_surface()->DrawableContentRect());
2357 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2359 // Layers that do not draw content should have empty visible_layer_rects.
2360 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2362 // layer visible_layer_rects are clipped by their target surface.
2363 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect());
2364 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect());
2365 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty());
2367 // layer drawable_content_rects are not clipped.
2368 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect());
2369 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect());
2370 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect());
2373 TEST_F(LayerTreeHostCommonTest,
2374 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
2375 LayerImpl* root = root_layer();
2376 LayerImpl* child = AddChildToRoot<LayerImpl>();
2377 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2378 grand_child1->SetDrawsContent(true);
2379 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2380 grand_child2->SetDrawsContent(true);
2381 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2382 grand_child3->SetDrawsContent(true);
2384 gfx::Transform identity_matrix;
2385 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2386 gfx::PointF(), gfx::Size(100, 100), true, false,
2387 true);
2388 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2389 gfx::PointF(), gfx::Size(100, 100), true, false,
2390 false);
2391 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2392 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2393 false, false);
2394 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2395 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2396 false, false);
2397 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
2398 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2399 true, false, false);
2401 child->SetMasksToBounds(true);
2402 ExecuteCalculateDrawProperties(root);
2404 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2405 root->render_surface()->DrawableContentRect());
2406 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2408 // Layers that do not draw content should have empty visible content rects.
2409 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2410 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect());
2412 // All grandchild visible content rects should be clipped by child.
2413 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect());
2414 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect());
2415 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty());
2417 // All grandchild DrawableContentRects should also be clipped by child.
2418 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
2419 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
2420 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2423 TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
2424 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2425 scoped_refptr<Layer> child = Layer::Create(layer_settings());
2426 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
2427 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2428 root->AddChild(child);
2429 child->AddChild(grand_child);
2431 host()->SetRootLayer(root);
2433 gfx::Transform identity_matrix;
2434 gfx::Transform child_scale_matrix;
2435 child_scale_matrix.Scale(0.25f, 0.25f);
2436 gfx::Transform grand_child_scale_matrix;
2437 grand_child_scale_matrix.Scale(0.246f, 0.246f);
2438 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2439 gfx::PointF(), gfx::Size(100, 100), true, false);
2440 SetLayerPropertiesForTesting(child.get(), child_scale_matrix, gfx::Point3F(),
2441 gfx::PointF(), gfx::Size(10, 10), true, false);
2442 SetLayerPropertiesForTesting(grand_child.get(), grand_child_scale_matrix,
2443 gfx::Point3F(), gfx::PointF(),
2444 gfx::Size(100, 100), true, false);
2446 child->SetMasksToBounds(true);
2447 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
2449 // The visible rect is expanded to integer coordinates in target space before
2450 // being projected back to layer space, where it is once again expanded to
2451 // integer coordinates.
2452 EXPECT_EQ(gfx::Rect(49, 49), grand_child->visible_rect_from_property_trees());
2455 TEST_F(LayerTreeHostCommonTest,
2456 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
2457 LayerImpl* root = root_layer();
2458 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
2459 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
2460 child1->SetDrawsContent(true);
2461 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
2462 child2->SetDrawsContent(true);
2463 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
2464 child3->SetDrawsContent(true);
2466 gfx::Transform identity_matrix;
2467 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2468 gfx::PointF(), gfx::Size(100, 100), true, false,
2469 true);
2470 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
2471 gfx::PointF(), gfx::Size(3, 4), true, false,
2472 true);
2473 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2474 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2475 false, false);
2476 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2477 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2478 false, false);
2479 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
2480 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2481 true, false, false);
2483 ExecuteCalculateDrawProperties(root);
2485 ASSERT_TRUE(render_surface->render_surface());
2487 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2488 root->render_surface()->DrawableContentRect());
2489 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2491 // Layers that do not draw content should have empty visible content rects.
2492 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2493 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
2495 // An unclipped surface grows its DrawableContentRect to include all drawable
2496 // regions of the subtree.
2497 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2498 render_surface->render_surface()->DrawableContentRect());
2500 // All layers that draw content into the unclipped surface are also unclipped.
2501 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
2502 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
2503 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
2505 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2506 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2507 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2510 TEST_F(LayerTreeHostCommonTest,
2511 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
2512 LayerImpl* root = root_layer();
2513 LayerImpl* child1 = AddChild<LayerImpl>(root);
2514 LayerImpl* child2 = AddChild<LayerImpl>(root);
2515 LayerImpl* child3 = AddChild<LayerImpl>(root);
2516 child1->SetDrawsContent(true);
2517 child2->SetDrawsContent(true);
2518 child3->SetDrawsContent(true);
2520 gfx::Transform identity_matrix;
2521 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2522 gfx::PointF(), gfx::Size(100, 100), true, false,
2523 true);
2524 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2525 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2526 false, false);
2527 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2528 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2529 false, false);
2530 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
2531 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2532 true, false, false);
2534 LayerImplList render_surface_layer_list_impl;
2535 // Now set the root render surface an empty clip.
2536 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
2537 root, gfx::Size(), &render_surface_layer_list_impl);
2539 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
2540 ASSERT_TRUE(root->render_surface());
2541 EXPECT_FALSE(root->is_clipped());
2543 gfx::Rect empty;
2544 EXPECT_EQ(empty, root->render_surface()->clip_rect());
2545 EXPECT_TRUE(root->render_surface()->is_clipped());
2547 // Visible content rect calculation will check if the target surface is
2548 // clipped or not. An empty clip rect does not indicate the render surface
2549 // is unclipped.
2550 EXPECT_EQ(empty, child1->visible_layer_rect());
2551 EXPECT_EQ(empty, child2->visible_layer_rect());
2552 EXPECT_EQ(empty, child3->visible_layer_rect());
2555 TEST_F(LayerTreeHostCommonTest,
2556 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
2557 LayerImpl* root = root_layer();
2558 LayerImpl* child = AddChildToRoot<LayerImpl>();
2559 child->SetDrawsContent(true);
2561 // Case 1: a truly degenerate matrix
2562 gfx::Transform identity_matrix;
2563 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2564 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2566 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2567 gfx::PointF(), gfx::Size(100, 100), true, false,
2568 true);
2569 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
2570 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2571 false, false);
2573 ExecuteCalculateDrawProperties(root);
2575 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
2576 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
2578 // Case 2: a matrix with flattened z, uninvertible and not visible according
2579 // to the CSS spec.
2580 uninvertible_matrix.MakeIdentity();
2581 uninvertible_matrix.matrix().set(2, 2, 0.0);
2582 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2584 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
2585 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2586 false, false);
2588 ExecuteCalculateDrawProperties(root);
2590 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
2591 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
2593 // Case 3: a matrix with flattened z, also uninvertible and not visible.
2594 uninvertible_matrix.MakeIdentity();
2595 uninvertible_matrix.Translate(500.0, 0.0);
2596 uninvertible_matrix.matrix().set(2, 2, 0.0);
2597 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2599 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
2600 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2601 false, false);
2603 ExecuteCalculateDrawProperties(root);
2605 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
2606 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
2609 TEST_F(LayerTreeHostCommonTest,
2610 VisibleContentRectForLayerWithUninvertibleDrawTransform) {
2611 LayerImpl* root = root_layer();
2612 LayerImpl* child = AddChildToRoot<LayerImpl>();
2613 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2614 child->SetDrawsContent(true);
2615 grand_child->SetDrawsContent(true);
2617 gfx::Transform identity_matrix;
2619 gfx::Transform perspective;
2620 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
2622 gfx::Transform rotation;
2623 rotation.RotateAboutYAxis(45.0);
2625 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2626 gfx::PointF(), gfx::Size(100, 100), true, false,
2627 true);
2628 SetLayerPropertiesForTesting(child, perspective, gfx::Point3F(),
2629 gfx::PointF(10.f, 10.f), gfx::Size(100, 100),
2630 false, true, false);
2631 SetLayerPropertiesForTesting(grand_child, rotation, gfx::Point3F(),
2632 gfx::PointF(), gfx::Size(100, 100), false, true,
2633 false);
2635 ExecuteCalculateDrawProperties(root);
2637 // Though all layers have invertible transforms, matrix multiplication using
2638 // floating-point math makes the draw transform uninvertible.
2639 EXPECT_FALSE(grand_child->draw_transform().IsInvertible());
2641 // CalcDrawProps only skips a subtree when a layer's own transform is
2642 // uninvertible, not when its draw transform is invertible, since CDP makes
2643 // skipping decisions before computing a layer's draw transform. Property
2644 // trees make skipping decisions after computing draw transforms, so could be
2645 // made to skip layers with an uninvertible draw transform (once CDP is
2646 // deleted).
2647 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
2648 grand_child->visible_layer_rect());
2651 TEST_F(LayerTreeHostCommonTest,
2652 OcclusionForLayerWithUninvertibleDrawTransform) {
2653 FakeImplProxy proxy;
2654 TestSharedBitmapManager shared_bitmap_manager;
2655 TestTaskGraphRunner task_graph_runner;
2656 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
2657 &task_graph_runner);
2658 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
2659 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2);
2660 scoped_ptr<LayerImpl> grand_child =
2661 LayerImpl::Create(host_impl.active_tree(), 3);
2662 scoped_ptr<LayerImpl> occluding_child =
2663 LayerImpl::Create(host_impl.active_tree(), 4);
2664 child->SetDrawsContent(true);
2665 grand_child->SetDrawsContent(true);
2666 occluding_child->SetDrawsContent(true);
2667 occluding_child->SetContentsOpaque(true);
2669 gfx::Transform identity_matrix;
2670 gfx::Transform perspective;
2671 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
2673 gfx::Transform rotation;
2674 rotation.RotateAboutYAxis(45.0);
2676 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2677 gfx::PointF(), gfx::Size(1000, 1000), true,
2678 false, true);
2679 SetLayerPropertiesForTesting(child.get(), perspective, gfx::Point3F(),
2680 gfx::PointF(10.f, 10.f), gfx::Size(300, 300),
2681 false, true, false);
2682 SetLayerPropertiesForTesting(grand_child.get(), rotation, gfx::Point3F(),
2683 gfx::PointF(), gfx::Size(200, 200), false, true,
2684 false);
2685 SetLayerPropertiesForTesting(occluding_child.get(), identity_matrix,
2686 gfx::Point3F(), gfx::PointF(),
2687 gfx::Size(200, 200), false, false, false);
2689 host_impl.SetViewportSize(root->bounds());
2691 child->AddChild(grand_child.Pass());
2692 root->AddChild(child.Pass());
2693 root->AddChild(occluding_child.Pass());
2694 host_impl.active_tree()->SetRootLayer(root.Pass());
2695 host_impl.InitializeRenderer(FakeOutputSurface::Create3d());
2696 bool update_lcd_text = false;
2697 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
2699 LayerImpl* grand_child_ptr =
2700 host_impl.active_tree()->root_layer()->children()[0]->children()[0];
2702 // Though all layers have invertible transforms, matrix multiplication using
2703 // floating-point math makes the draw transform uninvertible.
2704 EXPECT_FALSE(grand_child_ptr->draw_transform().IsInvertible());
2706 // Since |grand_child| has an uninvertible draw transform, it is treated as
2707 // unoccluded (even though |occluding_child| comes later in draw order, and
2708 // hence potentially occludes it).
2709 gfx::Rect layer_bounds = gfx::Rect(grand_child_ptr->bounds());
2710 EXPECT_EQ(
2711 layer_bounds,
2712 grand_child_ptr->draw_properties()
2713 .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds));
2716 TEST_F(LayerTreeHostCommonTest,
2717 SingularTransformDoesNotPreventClearingDrawProperties) {
2718 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2719 scoped_refptr<LayerWithForcedDrawsContent> child =
2720 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2721 root->AddChild(child);
2723 host()->SetRootLayer(root);
2725 gfx::Transform identity_matrix;
2726 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2727 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2729 SetLayerPropertiesForTesting(root.get(),
2730 uninvertible_matrix,
2731 gfx::Point3F(),
2732 gfx::PointF(),
2733 gfx::Size(100, 100),
2734 true,
2735 false);
2736 SetLayerPropertiesForTesting(child.get(),
2737 identity_matrix,
2738 gfx::Point3F(),
2739 gfx::PointF(5.f, 5.f),
2740 gfx::Size(50, 50),
2741 true,
2742 false);
2744 child->set_sorted_for_recursion(true);
2746 TransformOperations start_transform_operations;
2747 start_transform_operations.AppendScale(1.f, 0.f, 0.f);
2749 TransformOperations end_transform_operations;
2750 end_transform_operations.AppendScale(1.f, 1.f, 0.f);
2752 AddAnimatedTransformToLayer(
2753 root.get(), 10.0, start_transform_operations, end_transform_operations);
2755 EXPECT_TRUE(root->TransformIsAnimating());
2757 ExecuteCalculateDrawProperties(root.get());
2759 EXPECT_FALSE(child->sorted_for_recursion());
2762 TEST_F(LayerTreeHostCommonTest,
2763 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) {
2764 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2766 host()->SetRootLayer(root);
2768 gfx::Transform identity_matrix;
2769 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2770 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2772 SetLayerPropertiesForTesting(root.get(),
2773 uninvertible_matrix,
2774 gfx::Point3F(),
2775 gfx::PointF(),
2776 gfx::Size(100, 100),
2777 true,
2778 false);
2780 root->set_sorted_for_recursion(true);
2782 EXPECT_FALSE(root->TransformIsAnimating());
2784 ExecuteCalculateDrawProperties(root.get());
2786 EXPECT_FALSE(root->sorted_for_recursion());
2789 TEST_F(LayerTreeHostCommonTest,
2790 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
2791 LayerImpl* root = root_layer();
2792 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
2793 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
2794 child1->SetDrawsContent(true);
2795 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
2796 child2->SetDrawsContent(true);
2797 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
2798 child3->SetDrawsContent(true);
2800 gfx::Transform identity_matrix;
2801 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2802 gfx::PointF(), gfx::Size(100, 100), true, false,
2803 true);
2804 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
2805 gfx::PointF(), gfx::Size(3, 4), true, false,
2806 true);
2807 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2808 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2809 false, false);
2810 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2811 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2812 false, false);
2813 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
2814 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2815 true, false, false);
2817 root->SetMasksToBounds(true);
2819 ExecuteCalculateDrawProperties(root);
2821 ASSERT_TRUE(render_surface->render_surface());
2823 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2824 root->render_surface()->DrawableContentRect());
2825 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2827 // Layers that do not draw content should have empty visible content rects.
2828 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2829 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
2831 // A clipped surface grows its DrawableContentRect to include all drawable
2832 // regions of the subtree, but also gets clamped by the ancestor's clip.
2833 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
2834 render_surface->render_surface()->DrawableContentRect());
2836 // All layers that draw content into the surface have their visible content
2837 // rect clipped by the surface clip rect.
2838 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
2839 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
2840 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty());
2842 // But the DrawableContentRects are unclipped.
2843 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2844 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2845 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2848 TEST_F(LayerTreeHostCommonTest,
2849 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
2850 // Check that clipping does not propagate down surfaces.
2851 LayerImpl* root = root_layer();
2852 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
2853 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
2854 LayerImpl* child1 = AddChild<LayerImpl>(render_surface2);
2855 child1->SetDrawsContent(true);
2856 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
2857 child2->SetDrawsContent(true);
2858 LayerImpl* child3 = AddChild<LayerImpl>(render_surface2);
2859 child3->SetDrawsContent(true);
2861 gfx::Transform identity_matrix;
2862 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2863 gfx::PointF(), gfx::Size(100, 100), true, false,
2864 true);
2865 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
2866 gfx::PointF(), gfx::Size(3, 4), true, false,
2867 true);
2868 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
2869 gfx::PointF(), gfx::Size(7, 13), true, false,
2870 true);
2871 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2872 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2873 false, false);
2874 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2875 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2876 false, false);
2877 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
2878 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2879 true, false, false);
2881 root->SetMasksToBounds(true);
2883 ExecuteCalculateDrawProperties(root);
2885 ASSERT_TRUE(render_surface1->render_surface());
2886 ASSERT_TRUE(render_surface2->render_surface());
2888 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2889 root->render_surface()->DrawableContentRect());
2890 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2892 // Layers that do not draw content should have empty visible content rects.
2893 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2894 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
2895 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect());
2897 // A clipped surface grows its DrawableContentRect to include all drawable
2898 // regions of the subtree, but also gets clamped by the ancestor's clip.
2899 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
2900 render_surface1->render_surface()->DrawableContentRect());
2902 // render_surface1 lives in the "unclipped universe" of render_surface1, and
2903 // is only implicitly clipped by render_surface1's content rect. So,
2904 // render_surface2 grows to enclose all drawable content of its subtree.
2905 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2906 render_surface2->render_surface()->DrawableContentRect());
2908 // All layers that draw content into render_surface2 think they are unclipped.
2909 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
2910 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
2911 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
2913 // DrawableContentRects are also unclipped.
2914 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2915 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2916 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2919 TEST_F(LayerTreeHostCommonTest,
2920 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
2921 // Layers that have non-axis aligned bounds (due to transforms) have an
2922 // expanded, axis-aligned DrawableContentRect and visible content rect.
2923 LayerImpl* root = root_layer();
2924 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
2925 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
2926 child1->SetDrawsContent(true);
2928 gfx::Transform identity_matrix;
2929 gfx::Transform child_rotation;
2930 child_rotation.Rotate(45.0);
2931 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2932 gfx::PointF(), gfx::Size(100, 100), true, false,
2933 true);
2934 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
2935 gfx::PointF(), gfx::Size(3, 4), true, false,
2936 true);
2937 SetLayerPropertiesForTesting(
2938 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
2939 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
2941 ExecuteCalculateDrawProperties(root);
2943 ASSERT_TRUE(render_surface->render_surface());
2945 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2946 root->render_surface()->DrawableContentRect());
2947 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2949 // Layers that do not draw content should have empty visible content rects.
2950 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2951 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
2953 // The unclipped surface grows its DrawableContentRect to include all drawable
2954 // regions of the subtree.
2955 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
2956 gfx::Rect expected_surface_drawable_content =
2957 gfx::Rect(50 - diagonal_radius,
2958 50 - diagonal_radius,
2959 diagonal_radius * 2,
2960 diagonal_radius * 2);
2961 EXPECT_EQ(expected_surface_drawable_content,
2962 render_surface->render_surface()->DrawableContentRect());
2964 // All layers that draw content into the unclipped surface are also unclipped.
2965 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
2966 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
2969 TEST_F(LayerTreeHostCommonTest,
2970 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
2971 // Layers that have non-axis aligned bounds (due to transforms) have an
2972 // expanded, axis-aligned DrawableContentRect and visible content rect.
2973 LayerImpl* root = root_layer();
2974 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
2975 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
2976 child1->SetDrawsContent(true);
2978 gfx::Transform identity_matrix;
2979 gfx::Transform child_rotation;
2980 child_rotation.Rotate(45.0);
2981 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2982 gfx::PointF(), gfx::Size(50, 50), true, false,
2983 true);
2984 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
2985 gfx::PointF(), gfx::Size(3, 4), true, false,
2986 true);
2988 SetLayerPropertiesForTesting(
2989 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
2990 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
2992 root->SetMasksToBounds(true);
2994 ExecuteCalculateDrawProperties(root);
2996 ASSERT_TRUE(render_surface->render_surface());
2998 // The clipped surface clamps the DrawableContentRect that encloses the
2999 // rotated layer.
3000 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3001 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3002 50 - diagonal_radius,
3003 diagonal_radius * 2,
3004 diagonal_radius * 2);
3005 gfx::Rect expected_surface_drawable_content =
3006 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
3007 EXPECT_EQ(expected_surface_drawable_content,
3008 render_surface->render_surface()->DrawableContentRect());
3010 // On the clipped surface, only a quarter of the child1 is visible, but when
3011 // rotating it back to child1's content space, the actual enclosing rect ends
3012 // up covering the full left half of child1.
3014 // Given the floating point math, this number is a little bit fuzzy.
3015 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_layer_rect());
3017 // The child's DrawableContentRect is unclipped.
3018 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
3021 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
3022 LayerImpl* root = root_layer();
3023 FakePictureLayerImpl* render_surface1 =
3024 AddChildToRoot<FakePictureLayerImpl>();
3025 render_surface1->SetDrawsContent(true);
3026 FakePictureLayerImpl* render_surface2 =
3027 AddChild<FakePictureLayerImpl>(render_surface1);
3028 render_surface2->SetDrawsContent(true);
3029 FakePictureLayerImpl* child1 =
3030 AddChild<FakePictureLayerImpl>(render_surface2);
3031 child1->SetDrawsContent(true);
3032 FakePictureLayerImpl* child2 =
3033 AddChild<FakePictureLayerImpl>(render_surface2);
3034 child2->SetDrawsContent(true);
3035 FakePictureLayerImpl* child3 =
3036 AddChild<FakePictureLayerImpl>(render_surface2);
3037 child3->SetDrawsContent(true);
3039 gfx::Transform identity_matrix;
3040 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3041 gfx::PointF(), gfx::Size(100, 100), true, false,
3042 true);
3043 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3044 gfx::PointF(5.f, 5.f), gfx::Size(3, 4), true,
3045 false, true);
3046 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3047 gfx::PointF(5.f, 5.f), gfx::Size(7, 13), true,
3048 false, true);
3049 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3050 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3051 false, false);
3052 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3053 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3054 false, false);
3055 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3056 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3057 true, false, false);
3059 float device_scale_factor = 2.f;
3061 root->SetMasksToBounds(true);
3063 ExecuteCalculateDrawProperties(root, device_scale_factor);
3065 ASSERT_TRUE(render_surface1->render_surface());
3066 ASSERT_TRUE(render_surface2->render_surface());
3068 // drawable_content_rects for all layers and surfaces are scaled by
3069 // device_scale_factor.
3070 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
3071 root->render_surface()->DrawableContentRect());
3072 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3073 EXPECT_EQ(gfx::Rect(10, 10, 190, 190),
3074 render_surface1->render_surface()->DrawableContentRect());
3076 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3077 // is only implicitly clipped by render_surface1.
3078 EXPECT_EQ(gfx::Rect(10, 10, 350, 350),
3079 render_surface2->render_surface()->DrawableContentRect());
3081 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3082 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
3083 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
3085 // The root layer does not actually draw content of its own.
3086 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3088 // All layer visible content rects are not expressed in content space of each
3089 // layer, so they are not scaled by the device_scale_factor.
3090 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect());
3091 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect());
3092 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3093 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3094 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
3097 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
3098 // Verify the behavior of back-face culling when there are no preserve-3d
3099 // layers. Note that 3d transforms still apply in this case, but they are
3100 // "flattened" to each parent layer according to current W3C spec.
3102 const gfx::Transform identity_matrix;
3103 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
3104 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3105 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3106 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3107 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3108 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3109 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3110 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3111 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3112 scoped_refptr<LayerWithForcedDrawsContent>
3113 front_facing_child_of_front_facing_surface =
3114 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3115 scoped_refptr<LayerWithForcedDrawsContent>
3116 back_facing_child_of_front_facing_surface =
3117 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3118 scoped_refptr<LayerWithForcedDrawsContent>
3119 front_facing_child_of_back_facing_surface =
3120 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3121 scoped_refptr<LayerWithForcedDrawsContent>
3122 back_facing_child_of_back_facing_surface =
3123 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3125 parent->AddChild(front_facing_child);
3126 parent->AddChild(back_facing_child);
3127 parent->AddChild(front_facing_surface);
3128 parent->AddChild(back_facing_surface);
3129 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3130 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3131 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3132 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3134 host()->SetRootLayer(parent);
3136 // Nothing is double-sided
3137 front_facing_child->SetDoubleSided(false);
3138 back_facing_child->SetDoubleSided(false);
3139 front_facing_surface->SetDoubleSided(false);
3140 back_facing_surface->SetDoubleSided(false);
3141 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3142 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3143 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3144 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3146 gfx::Transform backface_matrix;
3147 backface_matrix.Translate(50.0, 50.0);
3148 backface_matrix.RotateAboutYAxis(180.0);
3149 backface_matrix.Translate(-50.0, -50.0);
3151 // Having a descendant and opacity will force these to have render surfaces.
3152 front_facing_surface->SetOpacity(0.5f);
3153 back_facing_surface->SetOpacity(0.5f);
3155 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3156 // these layers should blindly use their own local transforms to determine
3157 // back-face culling.
3158 SetLayerPropertiesForTesting(parent.get(),
3159 identity_matrix,
3160 gfx::Point3F(),
3161 gfx::PointF(),
3162 gfx::Size(100, 100),
3163 true,
3164 false);
3165 SetLayerPropertiesForTesting(front_facing_child.get(),
3166 identity_matrix,
3167 gfx::Point3F(),
3168 gfx::PointF(),
3169 gfx::Size(100, 100),
3170 true,
3171 false);
3172 SetLayerPropertiesForTesting(back_facing_child.get(),
3173 backface_matrix,
3174 gfx::Point3F(),
3175 gfx::PointF(),
3176 gfx::Size(100, 100),
3177 true,
3178 false);
3179 SetLayerPropertiesForTesting(front_facing_surface.get(),
3180 identity_matrix,
3181 gfx::Point3F(),
3182 gfx::PointF(),
3183 gfx::Size(100, 100),
3184 true,
3185 false);
3186 SetLayerPropertiesForTesting(back_facing_surface.get(),
3187 backface_matrix,
3188 gfx::Point3F(),
3189 gfx::PointF(),
3190 gfx::Size(100, 100),
3191 true,
3192 false);
3193 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3194 identity_matrix,
3195 gfx::Point3F(),
3196 gfx::PointF(),
3197 gfx::Size(100, 100),
3198 true,
3199 false);
3200 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3201 backface_matrix,
3202 gfx::Point3F(),
3203 gfx::PointF(),
3204 gfx::Size(100, 100),
3205 true,
3206 false);
3207 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3208 identity_matrix,
3209 gfx::Point3F(),
3210 gfx::PointF(),
3211 gfx::Size(100, 100),
3212 true,
3213 false);
3214 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3215 backface_matrix,
3216 gfx::Point3F(),
3217 gfx::PointF(),
3218 gfx::Size(100, 100),
3219 true,
3220 false);
3222 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
3224 // Verify which render surfaces were created.
3225 EXPECT_FALSE(front_facing_child->render_surface());
3226 EXPECT_FALSE(back_facing_child->render_surface());
3227 EXPECT_TRUE(front_facing_surface->render_surface());
3228 EXPECT_TRUE(back_facing_surface->render_surface());
3229 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3230 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3231 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3232 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3234 EXPECT_EQ(4u, update_layer_list().size());
3235 EXPECT_TRUE(UpdateLayerListContains(front_facing_child->id()));
3236 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
3237 EXPECT_TRUE(UpdateLayerListContains(
3238 front_facing_child_of_front_facing_surface->id()));
3239 EXPECT_TRUE(
3240 UpdateLayerListContains(front_facing_child_of_back_facing_surface->id()));
3243 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
3244 // Verify the behavior of back-face culling when preserves-3d transform style
3245 // is used.
3247 const gfx::Transform identity_matrix;
3248 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
3249 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3250 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3251 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3252 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3253 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3254 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3255 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3256 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3257 scoped_refptr<LayerWithForcedDrawsContent>
3258 front_facing_child_of_front_facing_surface =
3259 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3260 scoped_refptr<LayerWithForcedDrawsContent>
3261 back_facing_child_of_front_facing_surface =
3262 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3263 scoped_refptr<LayerWithForcedDrawsContent>
3264 front_facing_child_of_back_facing_surface =
3265 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3266 scoped_refptr<LayerWithForcedDrawsContent>
3267 back_facing_child_of_back_facing_surface =
3268 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3269 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
3270 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3271 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
3272 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3274 parent->AddChild(front_facing_child);
3275 parent->AddChild(back_facing_child);
3276 parent->AddChild(front_facing_surface);
3277 parent->AddChild(back_facing_surface);
3278 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3279 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3280 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3281 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3283 host()->SetRootLayer(parent);
3285 // Nothing is double-sided
3286 front_facing_child->SetDoubleSided(false);
3287 back_facing_child->SetDoubleSided(false);
3288 front_facing_surface->SetDoubleSided(false);
3289 back_facing_surface->SetDoubleSided(false);
3290 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3291 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3292 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3293 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3295 gfx::Transform backface_matrix;
3296 backface_matrix.Translate(50.0, 50.0);
3297 backface_matrix.RotateAboutYAxis(180.0);
3298 backface_matrix.Translate(-50.0, -50.0);
3300 // Opacity will not force creation of render surfaces in this case because of
3301 // the preserve-3d transform style. Instead, an example of when a surface
3302 // would be created with preserve-3d is when there is a replica layer.
3303 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3304 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3306 // Each surface creates its own new 3d rendering context (as defined by W3C
3307 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3308 // rendering context should use the transform with respect to that context.
3309 // This 3d rendering context occurs when (a) parent's transform style is flat
3310 // and (b) the layer's transform style is preserve-3d.
3311 SetLayerPropertiesForTesting(parent.get(),
3312 identity_matrix,
3313 gfx::Point3F(),
3314 gfx::PointF(),
3315 gfx::Size(100, 100),
3316 true,
3317 false); // parent transform style is flat.
3318 SetLayerPropertiesForTesting(front_facing_child.get(),
3319 identity_matrix,
3320 gfx::Point3F(),
3321 gfx::PointF(),
3322 gfx::Size(100, 100),
3323 true,
3324 false);
3325 SetLayerPropertiesForTesting(back_facing_child.get(),
3326 backface_matrix,
3327 gfx::Point3F(),
3328 gfx::PointF(),
3329 gfx::Size(100, 100),
3330 true,
3331 false);
3332 // surface transform style is preserve-3d.
3333 SetLayerPropertiesForTesting(front_facing_surface.get(),
3334 identity_matrix,
3335 gfx::Point3F(),
3336 gfx::PointF(),
3337 gfx::Size(100, 100),
3338 false,
3339 true);
3340 // surface transform style is preserve-3d.
3341 SetLayerPropertiesForTesting(back_facing_surface.get(),
3342 backface_matrix,
3343 gfx::Point3F(),
3344 gfx::PointF(),
3345 gfx::Size(100, 100),
3346 false,
3347 true);
3348 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3349 identity_matrix,
3350 gfx::Point3F(),
3351 gfx::PointF(),
3352 gfx::Size(100, 100),
3353 true,
3354 true);
3355 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3356 backface_matrix,
3357 gfx::Point3F(),
3358 gfx::PointF(),
3359 gfx::Size(100, 100),
3360 true,
3361 true);
3362 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3363 identity_matrix,
3364 gfx::Point3F(),
3365 gfx::PointF(),
3366 gfx::Size(100, 100),
3367 true,
3368 true);
3369 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3370 backface_matrix,
3371 gfx::Point3F(),
3372 gfx::PointF(),
3373 gfx::Size(100, 100),
3374 true,
3375 true);
3377 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
3379 // Verify which render surfaces were created and used.
3380 EXPECT_FALSE(front_facing_child->render_surface());
3381 EXPECT_FALSE(back_facing_child->render_surface());
3382 EXPECT_TRUE(front_facing_surface->render_surface());
3383 EXPECT_NE(back_facing_surface->render_target(), back_facing_surface);
3384 // We expect that a render_surface was created but not used.
3385 EXPECT_TRUE(back_facing_surface->render_surface());
3386 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3387 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3388 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3389 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3391 EXPECT_EQ(3u, update_layer_list().size());
3393 EXPECT_TRUE(UpdateLayerListContains(front_facing_child->id()));
3394 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
3395 EXPECT_TRUE(UpdateLayerListContains(
3396 front_facing_child_of_front_facing_surface->id()));
3399 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
3400 // Verify that layers are appropriately culled when their back face is showing
3401 // and they are not double sided, while animations are going on.
3403 // Layers that are animating do not get culled on the main thread, as their
3404 // transforms should be treated as "unknown" so we can not be sure that their
3405 // back face is really showing.
3406 const gfx::Transform identity_matrix;
3407 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
3408 scoped_refptr<LayerWithForcedDrawsContent> child =
3409 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3410 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
3411 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3412 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
3413 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3414 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
3415 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3416 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3417 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3419 parent->AddChild(child);
3420 parent->AddChild(animating_surface);
3421 animating_surface->AddChild(child_of_animating_surface);
3422 parent->AddChild(animating_child);
3423 parent->AddChild(child2);
3425 host()->SetRootLayer(parent);
3427 // Nothing is double-sided
3428 child->SetDoubleSided(false);
3429 child2->SetDoubleSided(false);
3430 animating_surface->SetDoubleSided(false);
3431 child_of_animating_surface->SetDoubleSided(false);
3432 animating_child->SetDoubleSided(false);
3434 gfx::Transform backface_matrix;
3435 backface_matrix.Translate(50.0, 50.0);
3436 backface_matrix.RotateAboutYAxis(180.0);
3437 backface_matrix.Translate(-50.0, -50.0);
3439 // Make our render surface.
3440 animating_surface->SetForceRenderSurface(true);
3442 // Animate the transform on the render surface.
3443 AddAnimatedTransformToController(
3444 animating_surface->layer_animation_controller(), 10.0, 30, 0);
3445 // This is just an animating layer, not a surface.
3446 AddAnimatedTransformToController(
3447 animating_child->layer_animation_controller(), 10.0, 30, 0);
3449 SetLayerPropertiesForTesting(parent.get(),
3450 identity_matrix,
3451 gfx::Point3F(),
3452 gfx::PointF(),
3453 gfx::Size(100, 100),
3454 true,
3455 false);
3456 SetLayerPropertiesForTesting(child.get(),
3457 backface_matrix,
3458 gfx::Point3F(),
3459 gfx::PointF(),
3460 gfx::Size(100, 100),
3461 true,
3462 false);
3463 SetLayerPropertiesForTesting(animating_surface.get(),
3464 backface_matrix,
3465 gfx::Point3F(),
3466 gfx::PointF(),
3467 gfx::Size(100, 100),
3468 true,
3469 false);
3470 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
3471 backface_matrix,
3472 gfx::Point3F(),
3473 gfx::PointF(),
3474 gfx::Size(100, 100),
3475 true,
3476 false);
3477 SetLayerPropertiesForTesting(animating_child.get(),
3478 backface_matrix,
3479 gfx::Point3F(),
3480 gfx::PointF(),
3481 gfx::Size(100, 100),
3482 true,
3483 false);
3484 SetLayerPropertiesForTesting(child2.get(),
3485 identity_matrix,
3486 gfx::Point3F(),
3487 gfx::PointF(),
3488 gfx::Size(100, 100),
3489 true,
3490 false);
3492 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(parent.get(),
3493 parent->bounds());
3494 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
3496 EXPECT_FALSE(child->render_surface());
3497 EXPECT_TRUE(animating_surface->render_surface());
3498 EXPECT_FALSE(child_of_animating_surface->render_surface());
3499 EXPECT_FALSE(animating_child->render_surface());
3500 EXPECT_FALSE(child2->render_surface());
3502 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
3504 EXPECT_EQ(4u, update_layer_list().size());
3506 // The non-animating child be culled from the layer list for the parent render
3507 // surface.
3508 EXPECT_TRUE(UpdateLayerListContains(animating_surface->id()));
3509 EXPECT_TRUE(UpdateLayerListContains(animating_child->id()));
3510 EXPECT_TRUE(UpdateLayerListContains(child2->id()));
3511 EXPECT_TRUE(UpdateLayerListContains(child_of_animating_surface->id()));
3513 EXPECT_FALSE(child2->visible_rect_from_property_trees().IsEmpty());
3515 // The animating layers should have a visible content rect that represents the
3516 // area of the front face that is within the viewport.
3517 EXPECT_EQ(animating_child->visible_rect_from_property_trees(),
3518 gfx::Rect(animating_child->bounds()));
3519 EXPECT_EQ(animating_surface->visible_rect_from_property_trees(),
3520 gfx::Rect(animating_surface->bounds()));
3521 // And layers in the subtree of the animating layer should have valid visible
3522 // content rects also.
3523 EXPECT_EQ(child_of_animating_surface->visible_rect_from_property_trees(),
3524 gfx::Rect(child_of_animating_surface->bounds()));
3527 TEST_F(LayerTreeHostCommonTest,
3528 BackFaceCullingWithPreserves3dForFlatteningSurface) {
3529 // Verify the behavior of back-face culling for a render surface that is
3530 // created when it flattens its subtree, and its parent has preserves-3d.
3532 const gfx::Transform identity_matrix;
3533 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
3534 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3535 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3536 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3537 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3538 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3539 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3540 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3541 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3543 parent->AddChild(front_facing_surface);
3544 parent->AddChild(back_facing_surface);
3545 front_facing_surface->AddChild(child1);
3546 back_facing_surface->AddChild(child2);
3548 host()->SetRootLayer(parent);
3550 // RenderSurfaces are not double-sided
3551 front_facing_surface->SetDoubleSided(false);
3552 back_facing_surface->SetDoubleSided(false);
3554 gfx::Transform backface_matrix;
3555 backface_matrix.Translate(50.0, 50.0);
3556 backface_matrix.RotateAboutYAxis(180.0);
3557 backface_matrix.Translate(-50.0, -50.0);
3559 SetLayerPropertiesForTesting(parent.get(),
3560 identity_matrix,
3561 gfx::Point3F(),
3562 gfx::PointF(),
3563 gfx::Size(100, 100),
3564 false,
3565 true); // parent transform style is preserve3d.
3566 SetLayerPropertiesForTesting(front_facing_surface.get(),
3567 identity_matrix,
3568 gfx::Point3F(),
3569 gfx::PointF(),
3570 gfx::Size(100, 100),
3571 true,
3572 true); // surface transform style is flat.
3573 SetLayerPropertiesForTesting(back_facing_surface.get(),
3574 backface_matrix,
3575 gfx::Point3F(),
3576 gfx::PointF(),
3577 gfx::Size(100, 100),
3578 true,
3579 true); // surface transform style is flat.
3580 SetLayerPropertiesForTesting(child1.get(),
3581 identity_matrix,
3582 gfx::Point3F(),
3583 gfx::PointF(),
3584 gfx::Size(100, 100),
3585 true,
3586 false);
3587 SetLayerPropertiesForTesting(child2.get(),
3588 identity_matrix,
3589 gfx::Point3F(),
3590 gfx::PointF(),
3591 gfx::Size(100, 100),
3592 true,
3593 false);
3595 front_facing_surface->Set3dSortingContextId(1);
3596 back_facing_surface->Set3dSortingContextId(1);
3598 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
3600 // Verify which render surfaces were created and used.
3601 EXPECT_TRUE(front_facing_surface->render_surface());
3603 // We expect the render surface to have been created, but remain unused.
3604 EXPECT_TRUE(back_facing_surface->render_surface());
3605 EXPECT_NE(back_facing_surface->render_target(),
3606 back_facing_surface); // because it should be culled
3607 EXPECT_FALSE(child1->render_surface());
3608 EXPECT_FALSE(child2->render_surface());
3610 EXPECT_EQ(2u, update_layer_list().size());
3611 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
3612 EXPECT_TRUE(UpdateLayerListContains(child1->id()));
3615 TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
3616 // Verify draw and screen space transforms of layers not in a surface.
3617 gfx::Transform identity_matrix;
3619 LayerImpl* parent = root_layer();
3620 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
3621 gfx::PointF(), gfx::Size(100, 100), false, true,
3622 true);
3624 LayerImpl* child = AddChildToRoot<LayerImpl>();
3625 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
3626 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
3627 true, false);
3629 LayerImpl* child_empty = AddChildToRoot<LayerImpl>();
3630 SetLayerPropertiesForTesting(child_empty, identity_matrix, gfx::Point3F(),
3631 gfx::PointF(2.f, 2.f), gfx::Size(), false, true,
3632 false);
3634 float device_scale_factor = 2.5f;
3635 gfx::Size viewport_size(100, 100);
3636 ExecuteCalculateDrawProperties(parent, device_scale_factor);
3638 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, parent);
3639 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child);
3640 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child_empty);
3642 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
3644 // Verify parent transforms
3645 gfx::Transform expected_parent_transform;
3646 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
3647 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
3648 parent->screen_space_transform());
3649 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
3650 parent->draw_transform());
3652 // Verify results of transformed parent rects
3653 gfx::RectF parent_bounds(parent->bounds());
3655 gfx::RectF parent_draw_rect =
3656 MathUtil::MapClippedRect(parent->draw_transform(), parent_bounds);
3657 gfx::RectF parent_screen_space_rect =
3658 MathUtil::MapClippedRect(parent->screen_space_transform(), parent_bounds);
3660 gfx::RectF expected_parent_draw_rect(parent->bounds());
3661 expected_parent_draw_rect.Scale(device_scale_factor);
3662 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
3663 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
3665 // Verify child and child_empty transforms. They should match.
3666 gfx::Transform expected_child_transform;
3667 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
3668 expected_child_transform.Translate(child->position().x(),
3669 child->position().y());
3670 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
3671 child->draw_transform());
3672 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
3673 child->screen_space_transform());
3674 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
3675 child_empty->draw_transform());
3676 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
3677 child_empty->screen_space_transform());
3679 // Verify results of transformed child and child_empty rects. They should
3680 // match.
3681 gfx::RectF child_bounds(child->bounds());
3683 gfx::RectF child_draw_rect =
3684 MathUtil::MapClippedRect(child->draw_transform(), child_bounds);
3685 gfx::RectF child_screen_space_rect =
3686 MathUtil::MapClippedRect(child->screen_space_transform(), child_bounds);
3688 gfx::RectF child_empty_draw_rect =
3689 MathUtil::MapClippedRect(child_empty->draw_transform(), child_bounds);
3690 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
3691 child_empty->screen_space_transform(), child_bounds);
3693 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
3694 expected_child_draw_rect.Scale(device_scale_factor);
3695 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
3696 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
3697 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
3698 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
3701 TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) {
3702 // Verify draw and screen space transforms of layers in a surface.
3703 gfx::Transform identity_matrix;
3704 gfx::Transform perspective_matrix;
3705 perspective_matrix.ApplyPerspectiveDepth(2.0);
3707 gfx::Transform scale_small_matrix;
3708 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
3710 LayerImpl* root = root_layer();
3711 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3712 gfx::PointF(), gfx::Size(100, 100), false, true,
3713 false);
3714 LayerImpl* parent = AddChildToRoot<LayerImpl>();
3715 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
3716 gfx::PointF(), gfx::Size(100, 100), false, true,
3717 false);
3719 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent);
3720 SetLayerPropertiesForTesting(perspective_surface,
3721 perspective_matrix * scale_small_matrix,
3722 gfx::Point3F(), gfx::PointF(2.f, 2.f),
3723 gfx::Size(10, 10), false, true, true);
3724 perspective_surface->SetDrawsContent(true);
3726 LayerImpl* scale_surface = AddChild<LayerImpl>(parent);
3727 SetLayerPropertiesForTesting(scale_surface, scale_small_matrix,
3728 gfx::Point3F(), gfx::PointF(2.f, 2.f),
3729 gfx::Size(10, 10), false, true, true);
3730 scale_surface->SetDrawsContent(true);
3732 float device_scale_factor = 2.5f;
3733 float page_scale_factor = 3.f;
3734 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
3735 root);
3737 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
3738 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor,
3739 perspective_surface);
3740 // Ideal scale is the max 2d scale component of the combined transform up to
3741 // the nearest render target. Here this includes the layer transform as well
3742 // as the device and page scale factors.
3743 gfx::Transform transform = scale_small_matrix;
3744 transform.Scale(device_scale_factor * page_scale_factor,
3745 device_scale_factor * page_scale_factor);
3746 gfx::Vector2dF scales =
3747 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
3748 float max_2d_scale = std::max(scales.x(), scales.y());
3749 EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface);
3751 // The ideal scale will draw 1:1 with its render target space along
3752 // the larger-scale axis.
3753 gfx::Vector2dF target_space_transform_scales =
3754 MathUtil::ComputeTransform2dScaleComponents(
3755 scale_surface->draw_properties().target_space_transform, 0.f);
3756 EXPECT_FLOAT_EQ(max_2d_scale,
3757 std::max(target_space_transform_scales.x(),
3758 target_space_transform_scales.y()));
3760 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
3762 gfx::Transform expected_parent_draw_transform;
3763 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
3764 device_scale_factor * page_scale_factor);
3765 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
3766 parent->draw_transform());
3768 // The scale for the perspective surface is not known, so it is rendered 1:1
3769 // with the screen, and then scaled during drawing.
3770 gfx::Transform expected_perspective_surface_draw_transform;
3771 expected_perspective_surface_draw_transform.Translate(
3772 device_scale_factor * page_scale_factor *
3773 perspective_surface->position().x(),
3774 device_scale_factor * page_scale_factor *
3775 perspective_surface->position().y());
3776 expected_perspective_surface_draw_transform.PreconcatTransform(
3777 perspective_matrix);
3778 expected_perspective_surface_draw_transform.PreconcatTransform(
3779 scale_small_matrix);
3780 gfx::Transform expected_perspective_surface_layer_draw_transform;
3781 expected_perspective_surface_layer_draw_transform.Scale(
3782 device_scale_factor * page_scale_factor,
3783 device_scale_factor * page_scale_factor);
3784 EXPECT_TRANSFORMATION_MATRIX_EQ(
3785 expected_perspective_surface_draw_transform,
3786 perspective_surface->render_surface()->draw_transform());
3787 EXPECT_TRANSFORMATION_MATRIX_EQ(
3788 expected_perspective_surface_layer_draw_transform,
3789 perspective_surface->draw_transform());
3792 TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) {
3793 gfx::Transform parent_scale_matrix;
3794 SkMScalar initial_parent_scale = 1.75;
3795 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
3797 gfx::Transform child_scale_matrix;
3798 SkMScalar initial_child_scale = 0.25;
3799 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
3801 LayerImpl* root = root_layer();
3802 root->SetBounds(gfx::Size(100, 100));
3804 LayerImpl* parent = AddChildToRoot<LayerImpl>();
3805 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
3806 gfx::PointF(), gfx::Size(100, 100), false, true,
3807 false);
3809 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
3810 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
3811 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
3812 true, false);
3814 float device_scale_factor = 2.5f;
3815 float page_scale_factor = 0.01f;
3818 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
3819 root);
3821 // The ideal scale is able to go below 1.
3822 float expected_ideal_scale =
3823 device_scale_factor * page_scale_factor * initial_parent_scale;
3824 EXPECT_LT(expected_ideal_scale, 1.f);
3825 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent);
3827 expected_ideal_scale = device_scale_factor * page_scale_factor *
3828 initial_parent_scale * initial_child_scale;
3829 EXPECT_LT(expected_ideal_scale, 1.f);
3830 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale);
3834 TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) {
3835 gfx::Transform parent_scale_matrix;
3836 SkMScalar initial_parent_scale = 1.75;
3837 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
3839 gfx::Transform child_scale_matrix;
3840 SkMScalar initial_child_scale = 1.25;
3841 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
3843 LayerImpl* root = root_layer();
3844 root->SetBounds(gfx::Size(100, 100));
3846 LayerImpl* parent = AddChildToRoot<LayerImpl>();
3847 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
3848 gfx::PointF(), gfx::Size(100, 100), false, true,
3849 false);
3851 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
3852 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
3853 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
3854 true, false);
3857 ExecuteCalculateDrawProperties(root);
3859 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent);
3860 // Animating layers compute ideal scale in the same way as when
3861 // they are static.
3862 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale,
3863 child_scale);
3867 TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
3868 gfx::Transform identity_matrix;
3870 LayerImpl* parent = root_layer();
3871 parent->SetDrawsContent(true);
3872 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
3873 gfx::PointF(), gfx::Size(30, 30), false, true,
3874 true);
3876 LayerImpl* child = AddChildToRoot<LayerImpl>();
3877 child->SetDrawsContent(true);
3878 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
3879 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
3880 true, true);
3882 gfx::Transform replica_transform;
3883 replica_transform.Scale(1.0, -1.0);
3885 scoped_ptr<LayerImpl> replica =
3886 LayerImpl::Create(host_impl()->active_tree(), 7);
3887 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(),
3888 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
3889 true, false);
3890 child->SetReplicaLayer(replica.Pass());
3892 // This layer should end up in the same surface as child, with the same draw
3893 // and screen space transforms.
3894 LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child);
3895 duplicate_child_non_owner->SetDrawsContent(true);
3896 SetLayerPropertiesForTesting(duplicate_child_non_owner, identity_matrix,
3897 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
3898 false, true, false);
3900 float device_scale_factor = 1.5f;
3901 ExecuteCalculateDrawProperties(parent, device_scale_factor);
3903 // We should have two render surfaces. The root's render surface and child's
3904 // render surface (it needs one because it has a replica layer).
3905 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
3907 gfx::Transform expected_parent_transform;
3908 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
3909 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
3910 parent->screen_space_transform());
3911 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
3912 parent->draw_transform());
3914 gfx::Transform expected_draw_transform;
3915 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
3916 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
3917 child->draw_transform());
3919 gfx::Transform expected_screen_space_transform;
3920 expected_screen_space_transform.Scale(device_scale_factor,
3921 device_scale_factor);
3922 expected_screen_space_transform.Translate(child->position().x(),
3923 child->position().y());
3924 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
3925 child->screen_space_transform());
3927 gfx::Transform expected_duplicate_child_draw_transform =
3928 child->draw_transform();
3929 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
3930 duplicate_child_non_owner->draw_transform());
3931 EXPECT_TRANSFORMATION_MATRIX_EQ(
3932 child->screen_space_transform(),
3933 duplicate_child_non_owner->screen_space_transform());
3934 EXPECT_EQ(child->drawable_content_rect(),
3935 duplicate_child_non_owner->drawable_content_rect());
3936 EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds());
3938 gfx::Transform expected_render_surface_draw_transform;
3939 expected_render_surface_draw_transform.Translate(
3940 device_scale_factor * child->position().x(),
3941 device_scale_factor * child->position().y());
3942 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
3943 child->render_surface()->draw_transform());
3945 gfx::Transform expected_surface_draw_transform;
3946 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
3947 device_scale_factor * 2.f);
3948 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
3949 child->render_surface()->draw_transform());
3951 gfx::Transform expected_surface_screen_space_transform;
3952 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
3953 device_scale_factor * 2.f);
3954 EXPECT_TRANSFORMATION_MATRIX_EQ(
3955 expected_surface_screen_space_transform,
3956 child->render_surface()->screen_space_transform());
3958 gfx::Transform expected_replica_draw_transform;
3959 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
3960 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
3961 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
3962 EXPECT_TRANSFORMATION_MATRIX_EQ(
3963 expected_replica_draw_transform,
3964 child->render_surface()->replica_draw_transform());
3966 gfx::Transform expected_replica_screen_space_transform;
3967 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
3968 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
3969 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
3970 EXPECT_TRANSFORMATION_MATRIX_EQ(
3971 expected_replica_screen_space_transform,
3972 child->render_surface()->replica_screen_space_transform());
3973 EXPECT_TRANSFORMATION_MATRIX_EQ(
3974 expected_replica_screen_space_transform,
3975 child->render_surface()->replica_screen_space_transform());
3978 TEST_F(LayerTreeHostCommonTest,
3979 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
3980 gfx::Transform identity_matrix;
3982 LayerImpl* parent = root_layer();
3983 parent->SetDrawsContent(true);
3984 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
3985 gfx::PointF(), gfx::Size(33, 31), false, true,
3986 true);
3988 LayerImpl* child = AddChildToRoot<LayerImpl>();
3989 child->SetDrawsContent(true);
3990 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
3991 gfx::PointF(), gfx::Size(13, 11), false, true,
3992 true);
3994 gfx::Transform replica_transform;
3995 replica_transform.Scale(1.0, -1.0);
3996 scoped_ptr<LayerImpl> replica =
3997 LayerImpl::Create(host_impl()->active_tree(), 7);
3998 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(),
3999 gfx::PointF(), gfx::Size(13, 11), false, true,
4000 false);
4001 child->SetReplicaLayer(replica.Pass());
4003 float device_scale_factor = 1.7f;
4004 ExecuteCalculateDrawProperties(parent, device_scale_factor);
4006 // We should have two render surfaces. The root's render surface and child's
4007 // render surface (it needs one because it has a replica layer).
4008 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
4010 gfx::Transform identity_transform;
4011 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
4012 child->render_surface()->draw_transform());
4013 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
4014 child->render_surface()->draw_transform());
4015 EXPECT_TRANSFORMATION_MATRIX_EQ(
4016 identity_transform, child->render_surface()->screen_space_transform());
4018 gfx::Transform expected_replica_draw_transform;
4019 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
4020 EXPECT_TRANSFORMATION_MATRIX_EQ(
4021 expected_replica_draw_transform,
4022 child->render_surface()->replica_draw_transform());
4024 gfx::Transform expected_replica_screen_space_transform;
4025 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
4026 EXPECT_TRANSFORMATION_MATRIX_EQ(
4027 expected_replica_screen_space_transform,
4028 child->render_surface()->replica_screen_space_transform());
4031 TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
4032 scoped_refptr<Layer> root = Layer::Create(layer_settings());
4033 scoped_refptr<Layer> child = Layer::Create(layer_settings());
4034 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
4035 scoped_refptr<Layer> mask_layer = Layer::Create(layer_settings());
4036 scoped_refptr<Layer> replica_layer = Layer::Create(layer_settings());
4038 grand_child->SetReplicaLayer(replica_layer.get());
4039 child->AddChild(grand_child.get());
4040 child->SetMaskLayer(mask_layer.get());
4041 root->AddChild(child.get());
4043 host()->SetRootLayer(root);
4045 int nonexistent_id = -1;
4046 EXPECT_EQ(root.get(),
4047 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
4048 EXPECT_EQ(child.get(),
4049 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
4050 EXPECT_EQ(
4051 grand_child.get(),
4052 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
4053 EXPECT_EQ(
4054 mask_layer.get(),
4055 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
4056 EXPECT_EQ(
4057 replica_layer.get(),
4058 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
4059 EXPECT_EQ(
4060 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
4063 TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
4064 scoped_refptr<Layer> root = Layer::Create(layer_settings());
4065 scoped_refptr<Layer> child = Layer::Create(layer_settings());
4066 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
4067 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4069 const gfx::Transform identity_matrix;
4070 SetLayerPropertiesForTesting(root.get(),
4071 identity_matrix,
4072 gfx::Point3F(),
4073 gfx::PointF(),
4074 gfx::Size(100, 100),
4075 true,
4076 false);
4077 SetLayerPropertiesForTesting(child.get(),
4078 identity_matrix,
4079 gfx::Point3F(),
4080 gfx::PointF(),
4081 gfx::Size(10, 10),
4082 true,
4083 false);
4084 SetLayerPropertiesForTesting(grand_child.get(),
4085 identity_matrix,
4086 gfx::Point3F(),
4087 gfx::PointF(),
4088 gfx::Size(10, 10),
4089 true,
4090 false);
4092 root->AddChild(child);
4093 child->AddChild(grand_child);
4094 child->SetOpacity(0.5f);
4096 host()->SetRootLayer(root);
4098 ExecuteCalculateDrawProperties(root.get());
4100 EXPECT_FALSE(child->render_surface());
4103 TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
4104 FakeImplProxy proxy;
4105 TestSharedBitmapManager shared_bitmap_manager;
4106 TestTaskGraphRunner task_graph_runner;
4107 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
4108 &task_graph_runner);
4109 host_impl.CreatePendingTree();
4110 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
4112 const gfx::Transform identity_matrix;
4113 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
4114 gfx::PointF(), gfx::Size(100, 100), true, false,
4115 false);
4116 root->SetDrawsContent(true);
4118 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
4119 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
4120 gfx::PointF(), gfx::Size(50, 50), true, false,
4121 false);
4122 child->SetDrawsContent(true);
4123 child->SetOpacity(0.0f);
4125 // Add opacity animation.
4126 AddOpacityTransitionToController(
4127 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
4129 root->AddChild(child.Pass());
4130 root->SetHasRenderSurface(true);
4132 LayerImplList render_surface_layer_list;
4133 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4134 root.get(), root->bounds(), &render_surface_layer_list);
4135 inputs.can_adjust_raster_scales = true;
4136 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4138 // We should have one render surface and two layers. The child
4139 // layer should be included even though it is transparent.
4140 ASSERT_EQ(1u, render_surface_layer_list.size());
4141 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
4144 using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
4145 class LCDTextTest : public LayerTreeHostCommonTestBase,
4146 public testing::TestWithParam<LCDTextTestParam> {
4147 public:
4148 LCDTextTest()
4149 : LayerTreeHostCommonTestBase(LayerTreeSettings()),
4150 host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_),
4151 root_(nullptr),
4152 child_(nullptr),
4153 grand_child_(nullptr) {}
4155 protected:
4156 void SetUp() override {
4157 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
4158 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
4160 scoped_ptr<LayerImpl> root_ptr =
4161 LayerImpl::Create(host_impl_.active_tree(), 1);
4162 scoped_ptr<LayerImpl> child_ptr =
4163 LayerImpl::Create(host_impl_.active_tree(), 2);
4164 scoped_ptr<LayerImpl> grand_child_ptr =
4165 LayerImpl::Create(host_impl_.active_tree(), 3);
4167 // Stash raw pointers to look at later.
4168 root_ = root_ptr.get();
4169 child_ = child_ptr.get();
4170 grand_child_ = grand_child_ptr.get();
4172 child_->AddChild(grand_child_ptr.Pass());
4173 root_->AddChild(child_ptr.Pass());
4174 host_impl_.active_tree()->SetRootLayer(root_ptr.Pass());
4176 root_->SetContentsOpaque(true);
4177 child_->SetContentsOpaque(true);
4178 grand_child_->SetContentsOpaque(true);
4180 root_->SetDrawsContent(true);
4181 child_->SetDrawsContent(true);
4182 grand_child_->SetDrawsContent(true);
4184 gfx::Transform identity_matrix;
4185 SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(),
4186 gfx::PointF(), gfx::Size(1, 1), true, false,
4187 true);
4188 SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(),
4189 gfx::PointF(), gfx::Size(1, 1), true, false,
4190 std::tr1::get<2>(GetParam()));
4191 SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(),
4192 gfx::PointF(), gfx::Size(1, 1), true, false,
4193 false);
4196 bool can_use_lcd_text_;
4197 bool layers_always_allowed_lcd_text_;
4199 FakeImplProxy proxy_;
4200 TestSharedBitmapManager shared_bitmap_manager_;
4201 TestTaskGraphRunner task_graph_runner_;
4202 FakeLayerTreeHostImpl host_impl_;
4204 LayerImpl* root_;
4205 LayerImpl* child_;
4206 LayerImpl* grand_child_;
4209 TEST_P(LCDTextTest, CanUseLCDText) {
4210 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
4211 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
4213 // Case 1: Identity transform.
4214 gfx::Transform identity_matrix;
4215 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4216 layers_always_allowed_lcd_text_);
4217 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4218 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4219 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4221 // Case 2: Integral translation.
4222 gfx::Transform integral_translation;
4223 integral_translation.Translate(1.0, 2.0);
4224 child_->SetTransform(integral_translation);
4225 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4226 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4227 layers_always_allowed_lcd_text_);
4228 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4229 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4230 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4232 // Case 3: Non-integral translation.
4233 gfx::Transform non_integral_translation;
4234 non_integral_translation.Translate(1.5, 2.5);
4235 child_->SetTransform(non_integral_translation);
4236 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4237 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4238 layers_always_allowed_lcd_text_);
4239 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4240 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4241 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4243 // Case 4: Rotation.
4244 gfx::Transform rotation;
4245 rotation.Rotate(10.0);
4246 child_->SetTransform(rotation);
4247 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4248 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4249 layers_always_allowed_lcd_text_);
4250 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4251 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4252 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4254 // Case 5: Scale.
4255 gfx::Transform scale;
4256 scale.Scale(2.0, 2.0);
4257 child_->SetTransform(scale);
4258 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4259 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4260 layers_always_allowed_lcd_text_);
4261 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4262 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4263 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4265 // Case 6: Skew.
4266 gfx::Transform skew;
4267 skew.SkewX(10.0);
4268 child_->SetTransform(skew);
4269 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4270 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4271 layers_always_allowed_lcd_text_);
4272 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4273 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4274 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4276 // Case 7: Translucent.
4277 child_->SetTransform(identity_matrix);
4278 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4279 child_->SetOpacity(0.5f);
4280 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4281 layers_always_allowed_lcd_text_);
4282 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4283 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4284 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4286 // Case 8: Sanity check: restore transform and opacity.
4287 child_->SetTransform(identity_matrix);
4288 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4289 child_->SetOpacity(1.f);
4290 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4291 layers_always_allowed_lcd_text_);
4292 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4293 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4294 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4296 // Case 9: Non-opaque content.
4297 child_->SetContentsOpaque(false);
4298 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4299 layers_always_allowed_lcd_text_);
4300 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4301 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4302 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4304 // Case 10: Sanity check: restore content opaqueness.
4305 child_->SetContentsOpaque(true);
4306 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4307 layers_always_allowed_lcd_text_);
4308 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4309 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4310 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4313 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
4314 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
4315 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
4317 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
4318 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4319 layers_always_allowed_lcd_text_);
4320 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4321 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4322 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4324 // Add opacity animation.
4325 child_->SetOpacity(0.9f);
4326 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4327 AddOpacityTransitionToController(
4328 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
4330 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4331 layers_always_allowed_lcd_text_);
4332 // Text LCD should be adjusted while animation is active.
4333 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4334 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4335 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4338 TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) {
4339 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
4340 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
4342 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
4343 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4344 layers_always_allowed_lcd_text_);
4345 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4346 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4347 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4349 // Mark contents non-opaque within the first animation frame.
4350 child_->SetContentsOpaque(false);
4351 AddOpacityTransitionToController(child_->layer_animation_controller(), 10.0,
4352 0.9f, 0.1f, false);
4354 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4355 layers_always_allowed_lcd_text_);
4356 // LCD text should be disabled for non-opaque layers even during animations.
4357 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4358 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4359 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4362 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
4363 LCDTextTest,
4364 testing::Combine(testing::Bool(),
4365 testing::Bool(),
4366 testing::Bool()));
4368 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
4369 FakeImplProxy proxy;
4370 TestSharedBitmapManager shared_bitmap_manager;
4371 TestTaskGraphRunner task_graph_runner;
4372 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
4373 &task_graph_runner);
4374 host_impl.CreatePendingTree();
4375 const gfx::Transform identity_matrix;
4377 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
4378 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
4379 gfx::PointF(), gfx::Size(50, 50), true, false,
4380 false);
4381 root->SetDrawsContent(true);
4383 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
4384 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
4385 gfx::PointF(), gfx::Size(40, 40), true, false,
4386 false);
4387 child->SetDrawsContent(true);
4389 scoped_ptr<LayerImpl> grand_child =
4390 LayerImpl::Create(host_impl.pending_tree(), 3);
4391 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
4392 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4393 true, false, false);
4394 grand_child->SetDrawsContent(true);
4395 grand_child->SetHideLayerAndSubtree(true);
4397 child->AddChild(grand_child.Pass());
4398 root->AddChild(child.Pass());
4399 root->SetHasRenderSurface(true);
4401 LayerImplList render_surface_layer_list;
4402 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4403 root.get(), root->bounds(), &render_surface_layer_list);
4404 inputs.can_adjust_raster_scales = true;
4405 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4407 // We should have one render surface and two layers. The grand child has
4408 // hidden itself.
4409 ASSERT_EQ(1u, render_surface_layer_list.size());
4410 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
4411 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
4412 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
4415 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
4416 FakeImplProxy proxy;
4417 TestSharedBitmapManager shared_bitmap_manager;
4418 TestTaskGraphRunner task_graph_runner;
4419 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
4420 &task_graph_runner);
4421 host_impl.CreatePendingTree();
4422 const gfx::Transform identity_matrix;
4424 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
4425 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
4426 gfx::PointF(), gfx::Size(50, 50), true, false,
4427 true);
4428 root->SetDrawsContent(true);
4430 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
4431 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
4432 gfx::PointF(), gfx::Size(40, 40), true, false,
4433 false);
4434 child->SetDrawsContent(true);
4435 child->SetHideLayerAndSubtree(true);
4437 scoped_ptr<LayerImpl> grand_child =
4438 LayerImpl::Create(host_impl.pending_tree(), 3);
4439 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
4440 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4441 true, false, false);
4442 grand_child->SetDrawsContent(true);
4444 child->AddChild(grand_child.Pass());
4445 root->AddChild(child.Pass());
4447 LayerImplList render_surface_layer_list;
4448 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4449 root.get(), root->bounds(), &render_surface_layer_list);
4450 inputs.can_adjust_raster_scales = true;
4451 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4453 // We should have one render surface and one layers. The child has
4454 // hidden itself and the grand child.
4455 ASSERT_EQ(1u, render_surface_layer_list.size());
4456 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4457 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
4460 void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
4462 TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
4463 FakeImplProxy proxy;
4464 TestSharedBitmapManager shared_bitmap_manager;
4465 TestTaskGraphRunner task_graph_runner;
4466 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
4467 &task_graph_runner);
4468 host_impl.CreatePendingTree();
4469 const gfx::Transform identity_matrix;
4471 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
4472 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
4473 gfx::PointF(), gfx::Size(50, 50), true, false,
4474 true);
4475 root->SetDrawsContent(true);
4477 scoped_ptr<LayerImpl> copy_grand_parent =
4478 LayerImpl::Create(host_impl.pending_tree(), 2);
4479 SetLayerPropertiesForTesting(copy_grand_parent.get(), identity_matrix,
4480 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
4481 true, false, false);
4482 copy_grand_parent->SetDrawsContent(true);
4483 LayerImpl* copy_grand_parent_layer = copy_grand_parent.get();
4485 scoped_ptr<LayerImpl> copy_parent =
4486 LayerImpl::Create(host_impl.pending_tree(), 3);
4487 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix,
4488 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4489 true, false, true);
4490 copy_parent->SetDrawsContent(true);
4491 LayerImpl* copy_parent_layer = copy_parent.get();
4493 scoped_ptr<LayerImpl> copy_request =
4494 LayerImpl::Create(host_impl.pending_tree(), 4);
4495 SetLayerPropertiesForTesting(copy_request.get(), identity_matrix,
4496 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4497 true, false, true);
4498 copy_request->SetDrawsContent(true);
4499 LayerImpl* copy_layer = copy_request.get();
4501 scoped_ptr<LayerImpl> copy_child =
4502 LayerImpl::Create(host_impl.pending_tree(), 5);
4503 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix,
4504 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4505 true, false, false);
4506 copy_child->SetDrawsContent(true);
4507 LayerImpl* copy_child_layer = copy_child.get();
4509 scoped_ptr<LayerImpl> copy_grand_parent_sibling_before =
4510 LayerImpl::Create(host_impl.pending_tree(), 6);
4511 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
4512 identity_matrix, gfx::Point3F(), gfx::PointF(),
4513 gfx::Size(40, 40), true, false, false);
4514 copy_grand_parent_sibling_before->SetDrawsContent(true);
4515 LayerImpl* copy_grand_parent_sibling_before_layer =
4516 copy_grand_parent_sibling_before.get();
4518 scoped_ptr<LayerImpl> copy_grand_parent_sibling_after =
4519 LayerImpl::Create(host_impl.pending_tree(), 7);
4520 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
4521 identity_matrix, gfx::Point3F(), gfx::PointF(),
4522 gfx::Size(40, 40), true, false, false);
4523 copy_grand_parent_sibling_after->SetDrawsContent(true);
4524 LayerImpl* copy_grand_parent_sibling_after_layer =
4525 copy_grand_parent_sibling_after.get();
4527 copy_request->AddChild(copy_child.Pass());
4528 copy_parent->AddChild(copy_request.Pass());
4529 copy_grand_parent->AddChild(copy_parent.Pass());
4530 root->AddChild(copy_grand_parent_sibling_before.Pass());
4531 root->AddChild(copy_grand_parent.Pass());
4532 root->AddChild(copy_grand_parent_sibling_after.Pass());
4534 // Hide the copy_grand_parent and its subtree. But make a copy request in that
4535 // hidden subtree on copy_layer.
4536 copy_grand_parent_layer->SetHideLayerAndSubtree(true);
4537 copy_grand_parent_sibling_before_layer->SetHideLayerAndSubtree(true);
4538 copy_grand_parent_sibling_after_layer->SetHideLayerAndSubtree(true);
4540 ScopedPtrVector<CopyOutputRequest> copy_requests;
4541 copy_requests.push_back(
4542 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
4543 copy_layer->PassCopyRequests(&copy_requests);
4544 EXPECT_TRUE(copy_layer->HasCopyRequest());
4546 LayerImplList render_surface_layer_list;
4547 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4548 root.get(), root->bounds(), &render_surface_layer_list);
4549 inputs.can_adjust_raster_scales = true;
4550 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4552 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
4553 EXPECT_TRUE(copy_grand_parent_layer->draw_properties()
4554 .layer_or_descendant_has_copy_request);
4555 EXPECT_TRUE(copy_parent_layer->draw_properties()
4556 .layer_or_descendant_has_copy_request);
4557 EXPECT_TRUE(
4558 copy_layer->draw_properties().layer_or_descendant_has_copy_request);
4559 EXPECT_FALSE(
4560 copy_child_layer->draw_properties().layer_or_descendant_has_copy_request);
4561 EXPECT_FALSE(copy_grand_parent_sibling_before_layer->draw_properties()
4562 .layer_or_descendant_has_copy_request);
4563 EXPECT_FALSE(copy_grand_parent_sibling_after_layer->draw_properties()
4564 .layer_or_descendant_has_copy_request);
4566 // We should have three render surfaces, one for the root, one for the parent
4567 // since it owns a surface, and one for the copy_layer.
4568 ASSERT_EQ(3u, render_surface_layer_list.size());
4569 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
4570 EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(1)->id());
4571 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
4573 // The root render surface should have 2 contributing layers. The
4574 // copy_grand_parent is hidden along with its siblings, but the copy_parent
4575 // will appear since something in its subtree needs to be drawn for a copy
4576 // request.
4577 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
4578 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
4579 EXPECT_EQ(copy_parent_layer->id(),
4580 root->render_surface()->layer_list().at(1)->id());
4582 // Nothing actually draws into the copy parent, so only the copy_layer will
4583 // appear in its list, since it needs to be drawn for the copy request.
4584 ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size());
4585 EXPECT_EQ(copy_layer->id(),
4586 copy_parent_layer->render_surface()->layer_list().at(0)->id());
4588 // The copy_layer's render surface should have two contributing layers.
4589 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
4590 EXPECT_EQ(copy_layer->id(),
4591 copy_layer->render_surface()->layer_list().at(0)->id());
4592 EXPECT_EQ(copy_child_layer->id(),
4593 copy_layer->render_surface()->layer_list().at(1)->id());
4596 TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
4597 FakeImplProxy proxy;
4598 TestSharedBitmapManager shared_bitmap_manager;
4599 TestTaskGraphRunner task_graph_runner;
4600 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
4601 &task_graph_runner);
4602 host_impl.CreatePendingTree();
4603 const gfx::Transform identity_matrix;
4605 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
4606 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
4607 gfx::PointF(), gfx::Size(50, 50), true, false,
4608 true);
4609 root->SetDrawsContent(true);
4611 scoped_ptr<LayerImpl> copy_parent =
4612 LayerImpl::Create(host_impl.pending_tree(), 2);
4613 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix,
4614 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
4615 false, false);
4616 copy_parent->SetDrawsContent(true);
4617 copy_parent->SetMasksToBounds(true);
4619 scoped_ptr<LayerImpl> copy_layer =
4620 LayerImpl::Create(host_impl.pending_tree(), 3);
4621 SetLayerPropertiesForTesting(copy_layer.get(), identity_matrix,
4622 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4623 true, false, true);
4624 copy_layer->SetDrawsContent(true);
4626 scoped_ptr<LayerImpl> copy_child =
4627 LayerImpl::Create(host_impl.pending_tree(), 4);
4628 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix,
4629 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4630 true, false, false);
4631 copy_child->SetDrawsContent(true);
4633 ScopedPtrVector<CopyOutputRequest> copy_requests;
4634 copy_requests.push_back(
4635 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
4636 copy_layer->PassCopyRequests(&copy_requests);
4637 EXPECT_TRUE(copy_layer->HasCopyRequest());
4639 copy_layer->AddChild(copy_child.Pass());
4640 copy_parent->AddChild(copy_layer.Pass());
4641 root->AddChild(copy_parent.Pass());
4643 LayerImplList render_surface_layer_list;
4644 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4645 root.get(), root->bounds(), &render_surface_layer_list);
4646 inputs.can_adjust_raster_scales = true;
4647 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4649 // We should have one render surface, as the others are clipped out.
4650 ASSERT_EQ(1u, render_surface_layer_list.size());
4651 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
4653 // The root render surface should only have 1 contributing layer, since the
4654 // other layers are empty/clipped away.
4655 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
4656 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
4659 TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
4660 FakeImplProxy proxy;
4661 TestSharedBitmapManager shared_bitmap_manager;
4662 TestTaskGraphRunner task_graph_runner;
4663 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
4664 &task_graph_runner);
4665 host_impl.CreatePendingTree();
4666 const gfx::Transform identity_matrix;
4668 scoped_refptr<Layer> root = Layer::Create(layer_settings());
4669 SetLayerPropertiesForTesting(root.get(),
4670 identity_matrix,
4671 gfx::Point3F(),
4672 gfx::PointF(),
4673 gfx::Size(50, 50),
4674 true,
4675 false);
4676 root->SetIsDrawable(true);
4678 // The surface is moved slightly outside of the viewport.
4679 scoped_refptr<Layer> surface = Layer::Create(layer_settings());
4680 SetLayerPropertiesForTesting(surface.get(),
4681 identity_matrix,
4682 gfx::Point3F(),
4683 gfx::PointF(-10, -20),
4684 gfx::Size(),
4685 true,
4686 false);
4687 surface->SetForceRenderSurface(true);
4689 scoped_refptr<Layer> surface_child = Layer::Create(layer_settings());
4690 SetLayerPropertiesForTesting(surface_child.get(),
4691 identity_matrix,
4692 gfx::Point3F(),
4693 gfx::PointF(),
4694 gfx::Size(50, 50),
4695 true,
4696 false);
4697 surface_child->SetIsDrawable(true);
4699 surface->AddChild(surface_child);
4700 root->AddChild(surface);
4702 host()->SetRootLayer(root);
4704 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(root.get(),
4705 root->bounds());
4706 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4708 // The visible_layer_rect for the |surface_child| should not be clipped by
4709 // the viewport.
4710 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
4711 surface_child->visible_rect_from_property_trees().ToString());
4714 TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
4715 // Ensure that a transform between the layer and its render surface is not a
4716 // problem. Constructs the following layer tree.
4718 // root (a render surface)
4719 // + render_surface
4720 // + clip_parent (scaled)
4721 // + intervening_clipping_layer
4722 // + clip_child
4724 // The render surface should be resized correctly and the clip child should
4725 // inherit the right clip rect.
4726 LayerImpl* root = root_layer();
4727 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
4728 LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface);
4729 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
4730 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
4731 clip_child->SetDrawsContent(true);
4732 clip_child->SetClipParent(clip_parent);
4733 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
4734 clip_children->insert(clip_child);
4735 clip_parent->SetClipChildren(clip_children.release());
4737 intervening->SetMasksToBounds(true);
4738 clip_parent->SetMasksToBounds(true);
4740 gfx::Transform scale_transform;
4741 scale_transform.Scale(2, 2);
4743 gfx::Transform identity_transform;
4745 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
4746 gfx::PointF(), gfx::Size(50, 50), true, false,
4747 true);
4748 SetLayerPropertiesForTesting(render_surface, identity_transform,
4749 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4750 true, false, true);
4751 SetLayerPropertiesForTesting(clip_parent, scale_transform, gfx::Point3F(),
4752 gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true,
4753 false, false);
4754 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
4755 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
4756 false, false);
4757 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
4758 gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true,
4759 false, false);
4761 ExecuteCalculateDrawProperties(root);
4763 ASSERT_TRUE(root->render_surface());
4764 ASSERT_TRUE(render_surface->render_surface());
4766 // Ensure that we've inherited our clip parent's clip and weren't affected
4767 // by the intervening clip layer.
4768 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
4769 clip_parent->clip_rect().ToString());
4770 ASSERT_EQ(clip_parent->clip_rect().ToString(),
4771 clip_child->clip_rect().ToString());
4772 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
4773 intervening->clip_rect().ToString());
4775 // Ensure that the render surface reports a content rect that has been grown
4776 // to accomodate for the clip child.
4777 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
4778 render_surface->render_surface()->content_rect().ToString());
4780 // The above check implies the two below, but they nicely demonstrate that
4781 // we've grown, despite the intervening layer's clip.
4782 ASSERT_TRUE(clip_parent->clip_rect().Contains(
4783 render_surface->render_surface()->content_rect()));
4784 ASSERT_FALSE(intervening->clip_rect().Contains(
4785 render_surface->render_surface()->content_rect()));
4788 TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
4789 // Ensure that intervening render surfaces are not a problem in the basic
4790 // case. In the following tree, both render surfaces should be resized to
4791 // accomodate for the clip child, despite an intervening clip.
4793 // root (a render surface)
4794 // + clip_parent (masks to bounds)
4795 // + render_surface1 (sets opacity)
4796 // + intervening (masks to bounds)
4797 // + render_surface2 (also sets opacity)
4798 // + clip_child
4800 LayerImpl* root = root_layer();
4801 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
4802 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
4803 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
4804 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
4805 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
4806 clip_child->SetDrawsContent(true);
4808 clip_child->SetClipParent(clip_parent);
4810 intervening->SetMasksToBounds(true);
4811 clip_parent->SetMasksToBounds(true);
4813 gfx::Transform translation_transform;
4814 translation_transform.Translate(2, 2);
4816 gfx::Transform identity_transform;
4817 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
4818 gfx::PointF(), gfx::Size(50, 50), true, false,
4819 true);
4820 SetLayerPropertiesForTesting(clip_parent, translation_transform,
4821 gfx::Point3F(), gfx::PointF(1.f, 1.f),
4822 gfx::Size(40, 40), true, false, false);
4823 SetLayerPropertiesForTesting(render_surface1, identity_transform,
4824 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4825 true, false, true);
4826 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
4827 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
4828 false, false);
4829 SetLayerPropertiesForTesting(render_surface2, identity_transform,
4830 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4831 true, false, true);
4832 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
4833 gfx::PointF(-10.f, -10.f), gfx::Size(60, 60),
4834 true, false, false);
4836 ExecuteCalculateDrawProperties(root);
4838 EXPECT_TRUE(root->render_surface());
4839 EXPECT_TRUE(render_surface1->render_surface());
4840 EXPECT_TRUE(render_surface2->render_surface());
4842 // Since the render surfaces could have expanded, they should not clip (their
4843 // bounds would no longer be reliable). We should resort to layer clipping
4844 // in this case.
4845 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4846 render_surface1->render_surface()->clip_rect().ToString());
4847 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
4848 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4849 render_surface2->render_surface()->clip_rect().ToString());
4850 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
4852 // NB: clip rects are in target space.
4853 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4854 render_surface1->clip_rect().ToString());
4855 EXPECT_TRUE(render_surface1->is_clipped());
4857 // This value is inherited from the clipping ancestor layer, 'intervening'.
4858 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
4859 render_surface2->clip_rect().ToString());
4860 EXPECT_TRUE(render_surface2->is_clipped());
4862 // The content rects of both render surfaces should both have expanded to
4863 // contain the clip child.
4864 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4865 render_surface1->render_surface()->content_rect().ToString());
4866 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
4867 render_surface2->render_surface()->content_rect().ToString());
4869 // The clip child should have inherited the clip parent's clip (projected to
4870 // the right space, of course), and should have the correctly sized visible
4871 // content rect.
4872 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
4873 clip_child->clip_rect().ToString());
4874 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
4875 clip_child->visible_layer_rect().ToString());
4876 EXPECT_TRUE(clip_child->is_clipped());
4879 TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
4880 // Ensure that intervening render surfaces are not a problem, even if there
4881 // is a scroll involved. Note, we do _not_ have to consider any other sort
4882 // of transform.
4884 // root (a render surface)
4885 // + clip_parent (masks to bounds)
4886 // + render_surface1 (sets opacity)
4887 // + intervening (masks to bounds AND scrolls)
4888 // + render_surface2 (also sets opacity)
4889 // + clip_child
4891 LayerImpl* root = root_layer();
4892 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
4893 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
4894 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
4895 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
4896 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
4897 clip_child->SetDrawsContent(true);
4899 clip_child->SetClipParent(clip_parent);
4901 intervening->SetMasksToBounds(true);
4902 clip_parent->SetMasksToBounds(true);
4903 intervening->SetScrollClipLayer(clip_parent->id());
4904 intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
4906 gfx::Transform translation_transform;
4907 translation_transform.Translate(2, 2);
4909 gfx::Transform identity_transform;
4910 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
4911 gfx::PointF(), gfx::Size(50, 50), true, false,
4912 true);
4913 SetLayerPropertiesForTesting(clip_parent, translation_transform,
4914 gfx::Point3F(), gfx::PointF(1.f, 1.f),
4915 gfx::Size(40, 40), true, false, false);
4916 SetLayerPropertiesForTesting(render_surface1, identity_transform,
4917 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4918 true, false, true);
4919 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
4920 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
4921 false, false);
4922 SetLayerPropertiesForTesting(render_surface2, identity_transform,
4923 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4924 true, false, true);
4925 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
4926 gfx::PointF(-10.f, -10.f), gfx::Size(60, 60),
4927 true, false, false);
4929 ExecuteCalculateDrawProperties(root);
4931 EXPECT_TRUE(root->render_surface());
4932 EXPECT_TRUE(render_surface1->render_surface());
4933 EXPECT_TRUE(render_surface2->render_surface());
4935 // Since the render surfaces could have expanded, they should not clip (their
4936 // bounds would no longer be reliable). We should resort to layer clipping
4937 // in this case.
4938 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4939 render_surface1->render_surface()->clip_rect().ToString());
4940 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
4941 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4942 render_surface2->render_surface()->clip_rect().ToString());
4943 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
4945 // NB: clip rects are in target space.
4946 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4947 render_surface1->clip_rect().ToString());
4948 EXPECT_TRUE(render_surface1->is_clipped());
4950 // This value is inherited from the clipping ancestor layer, 'intervening'.
4951 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
4952 render_surface2->clip_rect().ToString());
4953 EXPECT_TRUE(render_surface2->is_clipped());
4955 // The content rects of both render surfaces should both have expanded to
4956 // contain the clip child.
4957 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4958 render_surface1->render_surface()->content_rect().ToString());
4959 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
4960 render_surface2->render_surface()->content_rect().ToString());
4962 // The clip child should have inherited the clip parent's clip (projected to
4963 // the right space, of course), and should have the correctly sized visible
4964 // content rect.
4965 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
4966 clip_child->clip_rect().ToString());
4967 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
4968 clip_child->visible_layer_rect().ToString());
4969 EXPECT_TRUE(clip_child->is_clipped());
4972 TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
4973 // Ensures that descendants of the clip child inherit the correct clip.
4975 // root (a render surface)
4976 // + clip_parent (masks to bounds)
4977 // + intervening (masks to bounds)
4978 // + clip_child
4979 // + child
4981 LayerImpl* root = root_layer();
4982 LayerImpl* clip_parent = AddChild<LayerImpl>(root);
4983 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
4984 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
4985 LayerImpl* child = AddChild<LayerImpl>(clip_child);
4986 child->SetDrawsContent(true);
4988 clip_child->SetClipParent(clip_parent);
4989 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
4990 clip_children->insert(clip_child);
4991 clip_parent->SetClipChildren(clip_children.release());
4993 intervening->SetMasksToBounds(true);
4994 clip_parent->SetMasksToBounds(true);
4996 gfx::Transform identity_transform;
4997 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
4998 gfx::PointF(), gfx::Size(50, 50), true, false,
4999 true);
5000 SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(),
5001 gfx::PointF(), gfx::Size(40, 40), true, false,
5002 false);
5003 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5004 gfx::PointF(), gfx::Size(5, 5), true, false,
5005 false);
5006 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5007 gfx::PointF(), gfx::Size(60, 60), true, false,
5008 false);
5009 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
5010 gfx::PointF(), gfx::Size(60, 60), true, false,
5011 false);
5013 ExecuteCalculateDrawProperties(root);
5015 EXPECT_TRUE(root->render_surface());
5017 // Neither the clip child nor its descendant should have inherited the clip
5018 // from |intervening|.
5019 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5020 clip_child->clip_rect().ToString());
5021 EXPECT_TRUE(clip_child->is_clipped());
5022 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5023 child->visible_layer_rect().ToString());
5024 EXPECT_TRUE(child->is_clipped());
5027 TEST_F(LayerTreeHostCommonTest,
5028 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
5029 // Ensures that non-descendant clip children in the tree do not affect
5030 // render surfaces.
5032 // root (a render surface)
5033 // + clip_parent (masks to bounds)
5034 // + render_surface1
5035 // + clip_child
5036 // + render_surface2
5037 // + non_clip_child
5039 // In this example render_surface2 should be unaffected by clip_child.
5040 LayerImpl* root = root_layer();
5041 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5042 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5043 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
5044 clip_child->SetDrawsContent(true);
5045 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent);
5046 LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2);
5047 non_clip_child->SetDrawsContent(true);
5049 clip_child->SetClipParent(clip_parent);
5050 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
5051 clip_children->insert(clip_child);
5052 clip_parent->SetClipChildren(clip_children.release());
5054 clip_parent->SetMasksToBounds(true);
5055 render_surface1->SetMasksToBounds(true);
5057 gfx::Transform identity_transform;
5058 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5059 gfx::PointF(), gfx::Size(15, 15), true, false,
5060 true);
5061 SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(),
5062 gfx::PointF(), gfx::Size(10, 10), true, false,
5063 false);
5064 SetLayerPropertiesForTesting(render_surface1, identity_transform,
5065 gfx::Point3F(), gfx::PointF(5, 5),
5066 gfx::Size(5, 5), true, false, true);
5067 SetLayerPropertiesForTesting(render_surface2, identity_transform,
5068 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
5069 true, false, true);
5070 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5071 gfx::PointF(-1, 1), gfx::Size(10, 10), true,
5072 false, false);
5073 SetLayerPropertiesForTesting(non_clip_child, identity_transform,
5074 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
5075 true, false, false);
5077 ExecuteCalculateDrawProperties(root);
5079 EXPECT_TRUE(root->render_surface());
5080 EXPECT_TRUE(render_surface1->render_surface());
5081 EXPECT_TRUE(render_surface2->render_surface());
5083 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5084 render_surface1->clip_rect().ToString());
5085 EXPECT_TRUE(render_surface1->is_clipped());
5087 // The render surface should not clip (it has unclipped descendants), instead
5088 // it should rely on layer clipping.
5089 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5090 render_surface1->render_surface()->clip_rect().ToString());
5091 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
5093 // That said, it should have grown to accomodate the unclipped descendant.
5094 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
5095 render_surface1->render_surface()->content_rect().ToString());
5097 // This render surface should clip. It has no unclipped descendants.
5098 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5099 render_surface2->clip_rect().ToString());
5100 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
5102 // It also shouldn't have grown to accomodate the clip child.
5103 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5104 render_surface2->render_surface()->content_rect().ToString());
5106 // Sanity check our num_unclipped_descendants values.
5107 EXPECT_EQ(1u, render_surface1->num_unclipped_descendants());
5108 EXPECT_EQ(0u, render_surface2->num_unclipped_descendants());
5111 TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
5112 FakeImplProxy proxy;
5113 TestSharedBitmapManager shared_bitmap_manager;
5114 TestTaskGraphRunner task_graph_runner;
5115 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
5116 &task_graph_runner);
5117 scoped_ptr<LayerImpl> root =
5118 LayerImpl::Create(host_impl.active_tree(), 12345);
5119 scoped_ptr<LayerImpl> child1 =
5120 LayerImpl::Create(host_impl.active_tree(), 123456);
5121 scoped_ptr<LayerImpl> child2 =
5122 LayerImpl::Create(host_impl.active_tree(), 1234567);
5123 scoped_ptr<LayerImpl> child3 =
5124 LayerImpl::Create(host_impl.active_tree(), 12345678);
5126 gfx::Transform identity_matrix;
5127 gfx::Point3F transform_origin;
5128 gfx::PointF position;
5129 gfx::Size bounds(100, 100);
5130 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
5131 position, bounds, true, false, true);
5132 root->SetDrawsContent(true);
5134 // This layer structure normally forces render surface due to preserves3d
5135 // behavior.
5136 SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin,
5137 position, bounds, false, true, true);
5138 child1->SetDrawsContent(true);
5139 SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin,
5140 position, bounds, true, false, false);
5141 child2->SetDrawsContent(true);
5142 SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin,
5143 position, bounds, true, false, false);
5144 child3->SetDrawsContent(true);
5146 child2->Set3dSortingContextId(1);
5147 child3->Set3dSortingContextId(1);
5149 child2->AddChild(child3.Pass());
5150 child1->AddChild(child2.Pass());
5151 root->AddChild(child1.Pass());
5154 LayerImplList render_surface_layer_list;
5155 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get());
5156 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5157 root.get(), root->bounds(), &render_surface_layer_list);
5158 inputs.can_render_to_separate_surface = true;
5159 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5161 EXPECT_EQ(2u, render_surface_layer_list.size());
5163 int count_represents_target_render_surface = 0;
5164 int count_represents_contributing_render_surface = 0;
5165 int count_represents_itself = 0;
5166 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
5167 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
5168 it != end; ++it) {
5169 if (it.represents_target_render_surface())
5170 count_represents_target_render_surface++;
5171 if (it.represents_contributing_render_surface())
5172 count_represents_contributing_render_surface++;
5173 if (it.represents_itself())
5174 count_represents_itself++;
5177 // Two render surfaces.
5178 EXPECT_EQ(2, count_represents_target_render_surface);
5179 // Second render surface contributes to root render surface.
5180 EXPECT_EQ(1, count_represents_contributing_render_surface);
5181 // All 4 layers represent itself.
5182 EXPECT_EQ(4, count_represents_itself);
5186 LayerImplList render_surface_layer_list;
5187 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5188 root.get(), root->bounds(), &render_surface_layer_list);
5189 inputs.can_render_to_separate_surface = false;
5190 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5192 EXPECT_EQ(1u, render_surface_layer_list.size());
5194 int count_represents_target_render_surface = 0;
5195 int count_represents_contributing_render_surface = 0;
5196 int count_represents_itself = 0;
5197 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
5198 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
5199 it != end; ++it) {
5200 if (it.represents_target_render_surface())
5201 count_represents_target_render_surface++;
5202 if (it.represents_contributing_render_surface())
5203 count_represents_contributing_render_surface++;
5204 if (it.represents_itself())
5205 count_represents_itself++;
5208 // Only root layer has a render surface.
5209 EXPECT_EQ(1, count_represents_target_render_surface);
5210 // No layer contributes a render surface to root render surface.
5211 EXPECT_EQ(0, count_represents_contributing_render_surface);
5212 // All 4 layers represent itself.
5213 EXPECT_EQ(4, count_represents_itself);
5217 TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
5218 LayerImpl* root = root_layer();
5219 LayerImpl* render_surface = AddChild<LayerImpl>(root);
5220 LayerImpl* child = AddChild<LayerImpl>(render_surface);
5221 child->SetDrawsContent(true);
5223 gfx::Transform identity_transform;
5224 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5225 gfx::PointF(), gfx::Size(50, 50), true, false,
5226 true);
5227 SetLayerPropertiesForTesting(render_surface, identity_transform,
5228 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5229 false, true, true);
5230 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
5231 gfx::PointF(), gfx::Size(20, 20), true, false,
5232 false);
5234 root->SetShouldFlattenTransform(false);
5235 root->Set3dSortingContextId(1);
5236 render_surface->SetDoubleSided(false);
5238 ExecuteCalculateDrawProperties(root);
5240 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
5241 EXPECT_EQ(1u, render_surface_layer_list_impl()
5242 ->at(0)
5243 ->render_surface()
5244 ->layer_list()
5245 .size());
5246 EXPECT_EQ(1u, render_surface_layer_list_impl()
5247 ->at(1)
5248 ->render_surface()
5249 ->layer_list()
5250 .size());
5252 gfx::Transform rotation_transform = identity_transform;
5253 rotation_transform.RotateAboutXAxis(180.0);
5255 render_surface->SetTransform(rotation_transform);
5257 ExecuteCalculateDrawProperties(root);
5259 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
5260 EXPECT_EQ(0u, render_surface_layer_list_impl()
5261 ->at(0)
5262 ->render_surface()
5263 ->layer_list()
5264 .size());
5267 TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
5268 // Checks that the simple case (being clipped by a scroll parent that would
5269 // have been processed before you anyhow) results in the right clips.
5271 // + root
5272 // + scroll_parent_border
5273 // | + scroll_parent_clip
5274 // | + scroll_parent
5275 // + scroll_child
5277 LayerImpl* root = root_layer();
5278 LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>();
5279 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5280 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5281 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
5283 scroll_parent->SetDrawsContent(true);
5284 scroll_child->SetDrawsContent(true);
5285 scroll_parent_clip->SetMasksToBounds(true);
5287 scroll_child->SetScrollParent(scroll_parent);
5288 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
5289 scroll_children->insert(scroll_child);
5290 scroll_parent->SetScrollChildren(scroll_children.release());
5292 gfx::Transform identity_transform;
5293 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5294 gfx::PointF(), gfx::Size(50, 50), true, false,
5295 true);
5296 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
5297 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5298 true, false, false);
5299 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
5300 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5301 true, false, false);
5302 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
5303 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5304 true, false, false);
5305 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
5306 gfx::PointF(), gfx::Size(50, 50), true, false,
5307 false);
5309 ExecuteCalculateDrawProperties(root);
5311 EXPECT_TRUE(root->render_surface());
5313 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
5314 scroll_child->clip_rect().ToString());
5315 EXPECT_TRUE(scroll_child->is_clipped());
5318 TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
5319 LayerImpl* root = root_layer();
5320 root->SetDrawsContent(true);
5321 LayerImpl* parent = AddChildToRoot<LayerImpl>();
5322 parent->SetDrawsContent(true);
5323 LayerImpl* child = AddChild<LayerImpl>(parent);
5324 child->SetDrawsContent(true);
5326 gfx::Transform identity_transform;
5327 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5328 gfx::PointF(), gfx::Size(50, 50), true, true,
5329 true);
5330 SetLayerPropertiesForTesting(parent, identity_transform, gfx::Point3F(),
5331 gfx::PointF(), gfx::Size(30, 30), true, true,
5332 true);
5333 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
5334 gfx::PointF(), gfx::Size(20, 20), true, true,
5335 true);
5337 ExecuteCalculateDrawProperties(root);
5339 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
5341 gfx::Transform singular_transform;
5342 singular_transform.Scale3d(
5343 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
5345 child->SetTransform(singular_transform);
5347 ExecuteCalculateDrawProperties(root);
5349 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
5351 // Ensure that the entire subtree under a layer with singular transform does
5352 // not get rendered.
5353 parent->SetTransform(singular_transform);
5354 child->SetTransform(identity_transform);
5356 ExecuteCalculateDrawProperties(root);
5358 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
5361 TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
5362 // Checks that clipping by a scroll parent that follows you in paint order
5363 // still results in correct clipping.
5365 // + root
5366 // + scroll_parent_border
5367 // + scroll_parent_clip
5368 // + scroll_parent
5369 // + scroll_child
5371 LayerImpl* root = root_layer();
5372 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
5373 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5374 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5375 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
5377 scroll_parent->SetDrawsContent(true);
5378 scroll_child->SetDrawsContent(true);
5380 scroll_parent_clip->SetMasksToBounds(true);
5382 scroll_child->SetScrollParent(scroll_parent);
5383 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
5384 scroll_children->insert(scroll_child);
5385 scroll_parent->SetScrollChildren(scroll_children.release());
5387 gfx::Transform identity_transform;
5388 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5389 gfx::PointF(), gfx::Size(50, 50), true, false,
5390 true);
5391 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
5392 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5393 true, false, false);
5394 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
5395 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5396 true, false, false);
5397 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
5398 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5399 true, false, false);
5400 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
5401 gfx::PointF(), gfx::Size(50, 50), true, false,
5402 false);
5404 ExecuteCalculateDrawProperties(root);
5406 EXPECT_TRUE(root->render_surface());
5408 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
5409 scroll_child->clip_rect().ToString());
5410 EXPECT_TRUE(scroll_child->is_clipped());
5413 TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
5414 // Checks that clipping by a scroll parent and scroll grandparent that follow
5415 // you in paint order still results in correct clipping.
5417 // + root
5418 // + scroll_child
5419 // + scroll_parent_border
5420 // | + scroll_parent_clip
5421 // | + scroll_parent
5422 // + scroll_grandparent_border
5423 // + scroll_grandparent_clip
5424 // + scroll_grandparent
5426 LayerImpl* root = root_layer();
5427 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
5428 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
5429 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5430 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5431 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
5432 LayerImpl* scroll_grandparent_clip =
5433 AddChild<LayerImpl>(scroll_grandparent_border);
5434 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
5436 scroll_parent->SetDrawsContent(true);
5437 scroll_grandparent->SetDrawsContent(true);
5438 scroll_child->SetDrawsContent(true);
5440 scroll_parent_clip->SetMasksToBounds(true);
5441 scroll_grandparent_clip->SetMasksToBounds(true);
5443 scroll_child->SetScrollParent(scroll_parent);
5444 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
5445 scroll_children->insert(scroll_child);
5446 scroll_parent->SetScrollChildren(scroll_children.release());
5448 scroll_parent_border->SetScrollParent(scroll_grandparent);
5449 scroll_children.reset(new std::set<LayerImpl*>);
5450 scroll_children->insert(scroll_parent_border);
5451 scroll_grandparent->SetScrollChildren(scroll_children.release());
5453 gfx::Transform identity_transform;
5454 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5455 gfx::PointF(), gfx::Size(50, 50), true, false,
5456 true);
5457 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
5458 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5459 true, false, false);
5460 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
5461 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5462 true, false, false);
5463 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
5464 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5465 true, false, false);
5466 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
5467 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5468 true, false, false);
5469 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
5470 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5471 true, false, false);
5472 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
5473 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5474 true, false, false);
5475 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
5476 gfx::PointF(), gfx::Size(50, 50), true, false,
5477 false);
5479 ExecuteCalculateDrawProperties(root);
5481 EXPECT_TRUE(root->render_surface());
5483 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
5484 scroll_child->clip_rect().ToString());
5485 EXPECT_TRUE(scroll_child->is_clipped());
5487 // Despite the fact that we visited the above layers out of order to get the
5488 // correct clip, the layer lists should be unaffected.
5489 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
5490 EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0));
5491 EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1));
5492 EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2));
5495 TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
5496 // Ensures that even if we visit layers out of order, we still produce a
5497 // correctly ordered render surface layer list.
5498 // + root
5499 // + scroll_child
5500 // + scroll_parent_border
5501 // + scroll_parent_clip
5502 // + scroll_parent
5503 // + render_surface2
5504 // + scroll_grandparent_border
5505 // + scroll_grandparent_clip
5506 // + scroll_grandparent
5507 // + render_surface1
5509 LayerImpl* root = root_layer();
5510 root->SetDrawsContent(true);
5512 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
5513 scroll_child->SetDrawsContent(true);
5515 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
5516 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
5517 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
5518 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
5519 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
5520 LayerImpl* scroll_grandparent_clip =
5521 AddChild<LayerImpl>(scroll_grandparent_border);
5522 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
5523 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
5525 scroll_parent->SetDrawsContent(true);
5526 render_surface1->SetDrawsContent(true);
5527 scroll_grandparent->SetDrawsContent(true);
5528 render_surface2->SetDrawsContent(true);
5530 scroll_parent_clip->SetMasksToBounds(true);
5531 scroll_grandparent_clip->SetMasksToBounds(true);
5533 scroll_child->SetScrollParent(scroll_parent);
5534 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
5535 scroll_children->insert(scroll_child);
5536 scroll_parent->SetScrollChildren(scroll_children.release());
5538 scroll_parent_border->SetScrollParent(scroll_grandparent);
5539 scroll_children.reset(new std::set<LayerImpl*>);
5540 scroll_children->insert(scroll_parent_border);
5541 scroll_grandparent->SetScrollChildren(scroll_children.release());
5543 gfx::Transform identity_transform;
5544 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5545 gfx::PointF(), gfx::Size(50, 50), true, false,
5546 true);
5547 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
5548 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5549 true, false, false);
5550 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
5551 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5552 true, false, false);
5553 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
5554 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5555 true, false, false);
5556 SetLayerPropertiesForTesting(render_surface1, identity_transform,
5557 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5558 true, false, true);
5559 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
5560 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5561 true, false, false);
5562 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
5563 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5564 true, false, false);
5565 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
5566 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5567 true, false, false);
5568 SetLayerPropertiesForTesting(render_surface2, identity_transform,
5569 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5570 true, false, true);
5571 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
5572 gfx::PointF(), gfx::Size(50, 50), true, false,
5573 false);
5575 ExecuteCalculateDrawProperties(root);
5577 EXPECT_TRUE(root->render_surface());
5579 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
5580 scroll_child->clip_rect().ToString());
5581 EXPECT_TRUE(scroll_child->is_clipped());
5583 // Despite the fact that we had to process the layers out of order to get the
5584 // right clip, our render_surface_layer_list's order should be unaffected.
5585 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
5586 EXPECT_EQ(root, render_surface_layer_list_impl()->at(0));
5587 EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1));
5588 EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2));
5589 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
5590 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
5591 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
5594 TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
5595 // Ensures that when we have a render surface between a fixed position layer
5596 // and its container, we compute the fixed position layer's draw transform
5597 // with respect to that intervening render surface, not with respect to its
5598 // container's render target.
5600 // + root
5601 // + render_surface
5602 // + fixed
5603 // + child
5605 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5606 scoped_refptr<LayerWithForcedDrawsContent> render_surface =
5607 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5608 scoped_refptr<LayerWithForcedDrawsContent> fixed =
5609 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5610 scoped_refptr<LayerWithForcedDrawsContent> child =
5611 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5613 root->AddChild(render_surface);
5614 render_surface->AddChild(fixed);
5615 fixed->AddChild(child);
5617 root->SetIsContainerForFixedPositionLayers(true);
5618 render_surface->SetForceRenderSurface(true);
5620 LayerPositionConstraint constraint;
5621 constraint.set_is_fixed_position(true);
5622 fixed->SetPositionConstraint(constraint);
5624 SetLayerPropertiesForTesting(root.get(), gfx::Transform(), gfx::Point3F(),
5625 gfx::PointF(), gfx::Size(50, 50), true, false);
5626 SetLayerPropertiesForTesting(render_surface.get(), gfx::Transform(),
5627 gfx::Point3F(), gfx::PointF(7.f, 9.f),
5628 gfx::Size(50, 50), true, false);
5629 SetLayerPropertiesForTesting(fixed.get(), gfx::Transform(), gfx::Point3F(),
5630 gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true,
5631 false);
5632 SetLayerPropertiesForTesting(child.get(), gfx::Transform(), gfx::Point3F(),
5633 gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true,
5634 false);
5636 host()->SetRootLayer(root);
5638 ExecuteCalculateDrawProperties(root.get());
5640 TransformTree& tree = host()->property_trees()->transform_tree;
5642 gfx::Transform expected_fixed_draw_transform;
5643 expected_fixed_draw_transform.Translate(10.f, 15.f);
5644 EXPECT_EQ(expected_fixed_draw_transform,
5645 DrawTransformFromPropertyTrees(fixed.get(), tree));
5647 gfx::Transform expected_fixed_screen_space_transform;
5648 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
5649 EXPECT_EQ(expected_fixed_screen_space_transform,
5650 ScreenSpaceTransformFromPropertyTrees(fixed.get(), tree));
5652 gfx::Transform expected_child_draw_transform;
5653 expected_child_draw_transform.Translate(11.f, 17.f);
5654 EXPECT_EQ(expected_child_draw_transform,
5655 DrawTransformFromPropertyTrees(child.get(), tree));
5657 gfx::Transform expected_child_screen_space_transform;
5658 expected_child_screen_space_transform.Translate(18.f, 26.f);
5659 EXPECT_EQ(expected_child_screen_space_transform,
5660 ScreenSpaceTransformFromPropertyTrees(child.get(), tree));
5663 TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
5664 // This test verifies that a scrolling layer that gets snapped to
5665 // integer coordinates doesn't move a fixed position child.
5667 // + root
5668 // + container
5669 // + scroller
5670 // + fixed
5672 FakeImplProxy proxy;
5673 TestSharedBitmapManager shared_bitmap_manager;
5674 TestTaskGraphRunner task_graph_runner;
5675 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
5676 &task_graph_runner);
5677 host_impl.CreatePendingTree();
5678 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
5679 scoped_ptr<LayerImpl> container =
5680 LayerImpl::Create(host_impl.active_tree(), 2);
5681 LayerImpl* container_layer = container.get();
5682 scoped_ptr<LayerImpl> scroller =
5683 LayerImpl::Create(host_impl.active_tree(), 3);
5684 LayerImpl* scroll_layer = scroller.get();
5685 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
5686 LayerImpl* fixed_layer = fixed.get();
5688 container->SetIsContainerForFixedPositionLayers(true);
5690 LayerPositionConstraint constraint;
5691 constraint.set_is_fixed_position(true);
5692 fixed->SetPositionConstraint(constraint);
5694 scroller->SetScrollClipLayer(container->id());
5696 gfx::Transform identity_transform;
5697 gfx::Transform container_transform;
5698 container_transform.Translate3d(10.0, 20.0, 0.0);
5699 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
5701 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
5702 gfx::PointF(), gfx::Size(50, 50), true, false,
5703 true);
5704 SetLayerPropertiesForTesting(container.get(), container_transform,
5705 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5706 true, false, false);
5707 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
5708 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5709 true, false, false);
5710 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
5711 gfx::PointF(), gfx::Size(50, 50), true, false,
5712 false);
5714 scroller->AddChild(fixed.Pass());
5715 container->AddChild(scroller.Pass());
5716 root->AddChild(container.Pass());
5718 // Rounded to integers already.
5720 gfx::Vector2dF scroll_delta(3.0, 5.0);
5721 scroll_layer->SetScrollDelta(scroll_delta);
5723 LayerImplList render_surface_layer_list;
5724 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5725 root.get(), root->bounds(), &render_surface_layer_list);
5726 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5728 EXPECT_TRANSFORMATION_MATRIX_EQ(
5729 container_layer->draw_properties().screen_space_transform,
5730 fixed_layer->draw_properties().screen_space_transform);
5731 EXPECT_VECTOR_EQ(
5732 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
5733 container_offset);
5734 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
5735 .screen_space_transform.To2dTranslation(),
5736 container_offset - scroll_delta);
5739 // Scroll delta requiring rounding.
5741 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
5742 scroll_layer->SetScrollDelta(scroll_delta);
5744 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
5746 LayerImplList render_surface_layer_list;
5747 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5748 root.get(), root->bounds(), &render_surface_layer_list);
5749 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5751 EXPECT_TRANSFORMATION_MATRIX_EQ(
5752 container_layer->draw_properties().screen_space_transform,
5753 fixed_layer->draw_properties().screen_space_transform);
5754 EXPECT_VECTOR_EQ(
5755 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
5756 container_offset);
5757 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
5758 .screen_space_transform.To2dTranslation(),
5759 container_offset - rounded_scroll_delta);
5762 // Scale is applied earlier in the tree.
5764 gfx::Transform scaled_container_transform = container_transform;
5765 scaled_container_transform.Scale3d(3.0, 3.0, 1.0);
5766 container_layer->SetTransform(scaled_container_transform);
5768 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
5769 scroll_layer->SetScrollDelta(scroll_delta);
5771 LayerImplList render_surface_layer_list;
5772 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5773 root.get(), root->bounds(), &render_surface_layer_list);
5774 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5776 EXPECT_TRANSFORMATION_MATRIX_EQ(
5777 container_layer->draw_properties().screen_space_transform,
5778 fixed_layer->draw_properties().screen_space_transform);
5779 EXPECT_VECTOR_EQ(
5780 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
5781 container_offset);
5783 container_layer->SetTransform(container_transform);
5786 // Scale is applied on the scroll layer itself.
5788 gfx::Transform scale_transform;
5789 scale_transform.Scale3d(3.0, 3.0, 1.0);
5790 scroll_layer->SetTransform(scale_transform);
5792 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
5793 scroll_layer->SetScrollDelta(scroll_delta);
5795 LayerImplList render_surface_layer_list;
5796 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5797 root.get(), root->bounds(), &render_surface_layer_list);
5798 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5800 EXPECT_VECTOR_EQ(
5801 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
5802 container_offset);
5804 scroll_layer->SetTransform(identity_transform);
5808 TEST_F(LayerTreeHostCommonTest,
5809 ScrollCompensationMainScrollOffsetFractionalPart) {
5810 // This test verifies that a scrolling layer that has fractional scroll offset
5811 // from main doesn't move a fixed position child.
5813 // + root
5814 // + container
5815 // + scroller
5816 // + fixed
5818 FakeImplProxy proxy;
5819 TestSharedBitmapManager shared_bitmap_manager;
5820 TestTaskGraphRunner task_graph_runner;
5821 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
5822 &task_graph_runner);
5823 host_impl.CreatePendingTree();
5824 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
5825 scoped_ptr<LayerImpl> container =
5826 LayerImpl::Create(host_impl.active_tree(), 2);
5827 LayerImpl* container_layer = container.get();
5828 scoped_ptr<LayerImpl> scroller =
5829 LayerImpl::Create(host_impl.active_tree(), 3);
5830 LayerImpl* scroll_layer = scroller.get();
5831 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
5832 LayerImpl* fixed_layer = fixed.get();
5834 container->SetIsContainerForFixedPositionLayers(true);
5836 LayerPositionConstraint constraint;
5837 constraint.set_is_fixed_position(true);
5838 fixed->SetPositionConstraint(constraint);
5840 scroller->SetScrollClipLayer(container->id());
5842 gfx::Transform identity_transform;
5843 gfx::Transform container_transform;
5844 container_transform.Translate3d(10.0, 20.0, 0.0);
5845 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
5847 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
5848 gfx::PointF(), gfx::Size(50, 50), true, false,
5849 true);
5850 SetLayerPropertiesForTesting(container.get(), container_transform,
5851 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5852 true, false, false);
5853 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
5854 gfx::Point3F(), gfx::PointF(0.0, 0.0),
5855 gfx::Size(30, 30), true, false, false);
5857 gfx::ScrollOffset scroll_offset(3.3, 4.2);
5858 gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f);
5859 gfx::Vector2dF scroll_delta(0.1f, 0.4f);
5860 // Blink only uses the integer part of the scroll_offset for fixed
5861 // position layer.
5862 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
5863 gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true,
5864 false, false);
5865 scroll_layer->PushScrollOffsetFromMainThread(scroll_offset);
5866 scroll_layer->SetScrollDelta(scroll_delta);
5867 scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part);
5869 scroller->AddChild(fixed.Pass());
5870 container->AddChild(scroller.Pass());
5871 root->AddChild(container.Pass());
5873 LayerImplList render_surface_layer_list;
5874 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5875 root.get(), root->bounds(), &render_surface_layer_list);
5876 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5878 EXPECT_TRANSFORMATION_MATRIX_EQ(
5879 container_layer->draw_properties().screen_space_transform,
5880 fixed_layer->draw_properties().screen_space_transform);
5881 EXPECT_VECTOR_EQ(
5882 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
5883 container_offset);
5885 gfx::ScrollOffset effective_scroll_offset =
5886 ScrollOffsetWithDelta(scroll_offset, scroll_delta);
5887 gfx::Vector2d rounded_effective_scroll_offset =
5888 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset));
5889 EXPECT_VECTOR_EQ(
5890 scroll_layer->draw_properties().screen_space_transform.To2dTranslation(),
5891 container_offset - rounded_effective_scroll_offset);
5894 TEST_F(LayerTreeHostCommonTest,
5895 ScrollSnappingWithAnimatedScreenSpaceTransform) {
5896 // This test verifies that a scrolling layer whose screen space transform is
5897 // animating doesn't get snapped to integer coordinates.
5899 // + root
5900 // + animated layer
5901 // + surface
5902 // + container
5903 // + scroller
5905 LayerImpl* root = root_layer();
5906 LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>();
5907 LayerImpl* surface = AddChild<LayerImpl>(animated_layer);
5908 LayerImpl* container = AddChild<LayerImpl>(surface);
5909 LayerImpl* scroller = AddChild<LayerImpl>(container);
5910 scroller->SetScrollClipLayer(container->id());
5911 scroller->SetDrawsContent(true);
5913 gfx::Transform identity_transform;
5914 gfx::Transform start_scale;
5915 start_scale.Scale(1.5f, 1.5f);
5916 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5917 gfx::PointF(), gfx::Size(50, 50), true, false,
5918 true);
5919 SetLayerPropertiesForTesting(animated_layer, start_scale, gfx::Point3F(),
5920 gfx::PointF(), gfx::Size(50, 50), true, false,
5921 false);
5922 SetLayerPropertiesForTesting(surface, identity_transform, gfx::Point3F(),
5923 gfx::PointF(), gfx::Size(50, 50), true, false,
5924 true);
5925 SetLayerPropertiesForTesting(container, identity_transform, gfx::Point3F(),
5926 gfx::PointF(), gfx::Size(50, 50), true, false,
5927 false);
5928 SetLayerPropertiesForTesting(scroller, identity_transform, gfx::Point3F(),
5929 gfx::PointF(), gfx::Size(100, 100), true, false,
5930 false);
5932 gfx::Transform end_scale;
5933 end_scale.Scale(2.f, 2.f);
5934 TransformOperations start_operations;
5935 start_operations.AppendMatrix(start_scale);
5936 TransformOperations end_operations;
5937 end_operations.AppendMatrix(end_scale);
5938 AddAnimatedTransformToLayer(animated_layer, 1.0, start_operations,
5939 end_operations);
5941 gfx::Vector2dF scroll_delta(5.f, 9.f);
5942 scroller->SetScrollDelta(scroll_delta);
5944 ExecuteCalculateDrawProperties(root);
5946 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f);
5947 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation,
5948 scroller->draw_transform().To2dTranslation());
5951 class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
5952 public:
5953 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
5954 LayerTreeImpl* tree_impl,
5955 int id) {
5956 return make_scoped_ptr(
5957 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
5960 ~AnimationScaleFactorTrackingLayerImpl() override {}
5962 private:
5963 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
5964 int id)
5965 : LayerImpl(tree_impl, id) {
5966 SetDrawsContent(true);
5970 TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
5971 FakeImplProxy proxy;
5972 TestSharedBitmapManager shared_bitmap_manager;
5973 TestTaskGraphRunner task_graph_runner;
5974 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
5975 &task_graph_runner);
5976 gfx::Transform identity_matrix;
5977 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
5978 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
5979 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
5980 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
5981 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
5982 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
5983 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
5984 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
5986 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
5987 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
5988 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
5990 child->AddChild(grand_child.Pass());
5991 parent->AddChild(child.Pass());
5992 grand_parent->AddChild(parent.Pass());
5994 SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix,
5995 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
5996 true, false, true);
5997 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
5998 gfx::PointF(), gfx::Size(1, 2), true, false,
5999 false);
6000 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
6001 gfx::PointF(), gfx::Size(1, 2), true, false,
6002 false);
6004 SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(),
6005 gfx::PointF(), gfx::Size(1, 2), true, false,
6006 false);
6008 ExecuteCalculateDrawProperties(grand_parent.get());
6010 // No layers have animations.
6011 EXPECT_EQ(0.f,
6012 grand_parent->draw_properties().maximum_animation_contents_scale);
6013 EXPECT_EQ(0.f,
6014 parent_raw->draw_properties().maximum_animation_contents_scale);
6015 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6016 EXPECT_EQ(
6017 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6019 EXPECT_EQ(0.f,
6020 grand_parent->draw_properties().starting_animation_contents_scale);
6021 EXPECT_EQ(0.f,
6022 parent_raw->draw_properties().starting_animation_contents_scale);
6023 EXPECT_EQ(0.f,
6024 child_raw->draw_properties().starting_animation_contents_scale);
6025 EXPECT_EQ(
6026 0.f,
6027 grand_child_raw->draw_properties().starting_animation_contents_scale);
6029 TransformOperations translation;
6030 translation.AppendTranslate(1.f, 2.f, 3.f);
6032 AddAnimatedTransformToLayer(
6033 parent_raw, 1.0, TransformOperations(), translation);
6035 // No layers have scale-affecting animations.
6036 EXPECT_EQ(0.f,
6037 grand_parent->draw_properties().maximum_animation_contents_scale);
6038 EXPECT_EQ(0.f,
6039 parent_raw->draw_properties().maximum_animation_contents_scale);
6040 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6041 EXPECT_EQ(
6042 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6044 EXPECT_EQ(0.f,
6045 grand_parent->draw_properties().starting_animation_contents_scale);
6046 EXPECT_EQ(0.f,
6047 parent_raw->draw_properties().starting_animation_contents_scale);
6048 EXPECT_EQ(0.f,
6049 child_raw->draw_properties().starting_animation_contents_scale);
6050 EXPECT_EQ(
6051 0.f,
6052 grand_child_raw->draw_properties().starting_animation_contents_scale);
6054 TransformOperations scale;
6055 scale.AppendScale(5.f, 4.f, 3.f);
6057 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
6058 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
6059 ExecuteCalculateDrawProperties(grand_parent.get());
6061 // Only |child| has a scale-affecting animation.
6062 EXPECT_EQ(0.f,
6063 grand_parent->draw_properties().maximum_animation_contents_scale);
6064 EXPECT_EQ(0.f,
6065 parent_raw->draw_properties().maximum_animation_contents_scale);
6066 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale);
6067 EXPECT_EQ(
6068 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6070 EXPECT_EQ(0.f,
6071 grand_parent->draw_properties().starting_animation_contents_scale);
6072 EXPECT_EQ(0.f,
6073 parent_raw->draw_properties().starting_animation_contents_scale);
6074 EXPECT_EQ(1.f,
6075 child_raw->draw_properties().starting_animation_contents_scale);
6076 EXPECT_EQ(
6077 1.f,
6078 grand_child_raw->draw_properties().starting_animation_contents_scale);
6080 AddAnimatedTransformToLayer(
6081 grand_parent.get(), 1.0, TransformOperations(), scale);
6082 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
6083 ExecuteCalculateDrawProperties(grand_parent.get());
6085 // |grand_parent| and |child| have scale-affecting animations.
6086 EXPECT_EQ(5.f,
6087 grand_parent->draw_properties().maximum_animation_contents_scale);
6088 EXPECT_EQ(5.f,
6089 parent_raw->draw_properties().maximum_animation_contents_scale);
6090 // We don't support combining animated scales from two nodes; 0.f means
6091 // that the maximum scale could not be computed.
6092 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6093 EXPECT_EQ(
6094 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6096 EXPECT_EQ(1.f,
6097 grand_parent->draw_properties().starting_animation_contents_scale);
6098 EXPECT_EQ(1.f,
6099 parent_raw->draw_properties().starting_animation_contents_scale);
6100 EXPECT_EQ(0.f,
6101 child_raw->draw_properties().starting_animation_contents_scale);
6102 EXPECT_EQ(
6103 0.f,
6104 grand_child_raw->draw_properties().starting_animation_contents_scale);
6106 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
6107 parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
6108 ExecuteCalculateDrawProperties(grand_parent.get());
6110 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
6111 EXPECT_EQ(5.f,
6112 grand_parent->draw_properties().maximum_animation_contents_scale);
6113 EXPECT_EQ(0.f,
6114 parent_raw->draw_properties().maximum_animation_contents_scale);
6115 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6116 EXPECT_EQ(
6117 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6119 EXPECT_EQ(1.f,
6120 grand_parent->draw_properties().starting_animation_contents_scale);
6121 EXPECT_EQ(0.f,
6122 parent_raw->draw_properties().starting_animation_contents_scale);
6123 EXPECT_EQ(0.f,
6124 child_raw->draw_properties().starting_animation_contents_scale);
6125 EXPECT_EQ(
6126 0.f,
6127 grand_child_raw->draw_properties().starting_animation_contents_scale);
6129 grand_parent->layer_animation_controller()->AbortAnimations(
6130 Animation::TRANSFORM);
6131 parent_raw->layer_animation_controller()->AbortAnimations(
6132 Animation::TRANSFORM);
6133 child_raw->layer_animation_controller()->AbortAnimations(
6134 Animation::TRANSFORM);
6136 TransformOperations perspective;
6137 perspective.AppendPerspective(10.f);
6139 AddAnimatedTransformToLayer(
6140 child_raw, 1.0, TransformOperations(), perspective);
6141 ExecuteCalculateDrawProperties(grand_parent.get());
6143 // |child| has a scale-affecting animation but computing the maximum of this
6144 // animation is not supported.
6145 EXPECT_EQ(0.f,
6146 grand_parent->draw_properties().maximum_animation_contents_scale);
6147 EXPECT_EQ(0.f,
6148 parent_raw->draw_properties().maximum_animation_contents_scale);
6149 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6150 EXPECT_EQ(
6151 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6153 EXPECT_EQ(0.f,
6154 grand_parent->draw_properties().starting_animation_contents_scale);
6155 EXPECT_EQ(0.f,
6156 parent_raw->draw_properties().starting_animation_contents_scale);
6157 EXPECT_EQ(0.f,
6158 child_raw->draw_properties().starting_animation_contents_scale);
6159 EXPECT_EQ(
6160 0.f,
6161 grand_child_raw->draw_properties().starting_animation_contents_scale);
6163 child_raw->layer_animation_controller()->AbortAnimations(
6164 Animation::TRANSFORM);
6166 gfx::Transform scale_matrix;
6167 scale_matrix.Scale(1.f, 2.f);
6168 grand_parent->SetTransform(scale_matrix);
6169 parent_raw->SetTransform(scale_matrix);
6170 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
6171 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
6172 ExecuteCalculateDrawProperties(grand_parent.get());
6174 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
6175 // animation with maximum scale 5.f.
6176 EXPECT_EQ(0.f,
6177 grand_parent->draw_properties().maximum_animation_contents_scale);
6178 EXPECT_EQ(10.f,
6179 parent_raw->draw_properties().maximum_animation_contents_scale);
6180 EXPECT_EQ(10.f,
6181 child_raw->draw_properties().maximum_animation_contents_scale);
6182 EXPECT_EQ(
6183 10.f,
6184 grand_child_raw->draw_properties().maximum_animation_contents_scale);
6186 EXPECT_EQ(0.f,
6187 grand_parent->draw_properties().starting_animation_contents_scale);
6188 EXPECT_EQ(2.f,
6189 parent_raw->draw_properties().starting_animation_contents_scale);
6190 EXPECT_EQ(2.f,
6191 child_raw->draw_properties().starting_animation_contents_scale);
6192 EXPECT_EQ(
6193 2.f,
6194 grand_child_raw->draw_properties().starting_animation_contents_scale);
6196 gfx::Transform perspective_matrix;
6197 perspective_matrix.ApplyPerspectiveDepth(2.f);
6198 child_raw->SetTransform(perspective_matrix);
6199 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
6200 ExecuteCalculateDrawProperties(grand_parent.get());
6202 // |child| has a transform that's neither a translation nor a scale.
6203 EXPECT_EQ(0.f,
6204 grand_parent->draw_properties().maximum_animation_contents_scale);
6205 EXPECT_EQ(10.f,
6206 parent_raw->draw_properties().maximum_animation_contents_scale);
6207 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6208 EXPECT_EQ(
6209 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6211 EXPECT_EQ(0.f,
6212 grand_parent->draw_properties().starting_animation_contents_scale);
6213 EXPECT_EQ(2.f,
6214 parent_raw->draw_properties().starting_animation_contents_scale);
6215 EXPECT_EQ(0.f,
6216 child_raw->draw_properties().starting_animation_contents_scale);
6217 EXPECT_EQ(
6218 0.f,
6219 grand_child_raw->draw_properties().starting_animation_contents_scale);
6221 parent_raw->SetTransform(perspective_matrix);
6222 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
6223 ExecuteCalculateDrawProperties(grand_parent.get());
6225 // |parent| and |child| have transforms that are neither translations nor
6226 // scales.
6227 EXPECT_EQ(0.f,
6228 grand_parent->draw_properties().maximum_animation_contents_scale);
6229 EXPECT_EQ(0.f,
6230 parent_raw->draw_properties().maximum_animation_contents_scale);
6231 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6232 EXPECT_EQ(
6233 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6235 EXPECT_EQ(0.f,
6236 grand_parent->draw_properties().starting_animation_contents_scale);
6237 EXPECT_EQ(0.f,
6238 parent_raw->draw_properties().starting_animation_contents_scale);
6239 EXPECT_EQ(0.f,
6240 child_raw->draw_properties().starting_animation_contents_scale);
6241 EXPECT_EQ(
6242 0.f,
6243 grand_child_raw->draw_properties().starting_animation_contents_scale);
6245 parent_raw->SetTransform(identity_matrix);
6246 child_raw->SetTransform(identity_matrix);
6247 grand_parent->SetTransform(perspective_matrix);
6248 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
6250 ExecuteCalculateDrawProperties(grand_parent.get());
6252 // |grand_parent| has a transform that's neither a translation nor a scale.
6253 EXPECT_EQ(0.f,
6254 grand_parent->draw_properties().maximum_animation_contents_scale);
6255 EXPECT_EQ(0.f,
6256 parent_raw->draw_properties().maximum_animation_contents_scale);
6257 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6258 EXPECT_EQ(
6259 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6261 EXPECT_EQ(0.f,
6262 grand_parent->draw_properties().starting_animation_contents_scale);
6263 EXPECT_EQ(0.f,
6264 parent_raw->draw_properties().starting_animation_contents_scale);
6265 EXPECT_EQ(0.f,
6266 child_raw->draw_properties().starting_animation_contents_scale);
6267 EXPECT_EQ(
6268 0.f,
6269 grand_child_raw->draw_properties().starting_animation_contents_scale);
6272 static int membership_id(LayerImpl* layer) {
6273 return layer->draw_properties().last_drawn_render_surface_layer_list_id;
6276 static void GatherDrawnLayers(LayerImplList* rsll,
6277 std::set<LayerImpl*>* drawn_layers) {
6278 for (LayerIterator it = LayerIterator::Begin(rsll),
6279 end = LayerIterator::End(rsll);
6280 it != end; ++it) {
6281 LayerImpl* layer = *it;
6282 if (it.represents_itself())
6283 drawn_layers->insert(layer);
6285 if (!it.represents_contributing_render_surface())
6286 continue;
6288 if (layer->mask_layer())
6289 drawn_layers->insert(layer->mask_layer());
6290 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
6291 drawn_layers->insert(layer->replica_layer()->mask_layer());
6295 TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
6296 FakeImplProxy proxy;
6297 TestSharedBitmapManager shared_bitmap_manager;
6298 TestTaskGraphRunner task_graph_runner;
6299 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
6300 &task_graph_runner);
6301 gfx::Transform identity_matrix;
6303 scoped_ptr<LayerImpl> grand_parent =
6304 LayerImpl::Create(host_impl.active_tree(), 1);
6305 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3);
6306 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5);
6307 scoped_ptr<LayerImpl> grand_child1 =
6308 LayerImpl::Create(host_impl.active_tree(), 7);
6309 scoped_ptr<LayerImpl> grand_child2 =
6310 LayerImpl::Create(host_impl.active_tree(), 9);
6312 LayerImpl* grand_parent_raw = grand_parent.get();
6313 LayerImpl* parent_raw = parent.get();
6314 LayerImpl* child_raw = child.get();
6315 LayerImpl* grand_child1_raw = grand_child1.get();
6316 LayerImpl* grand_child2_raw = grand_child2.get();
6318 child->AddChild(grand_child1.Pass());
6319 child->AddChild(grand_child2.Pass());
6320 parent->AddChild(child.Pass());
6321 grand_parent->AddChild(parent.Pass());
6323 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
6324 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6325 true, false, true);
6326 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
6327 gfx::PointF(), gfx::Size(1, 2), true, false,
6328 false);
6330 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
6331 gfx::PointF(), gfx::Size(1, 2), true, false,
6332 false);
6334 SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix,
6335 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6336 true, false, false);
6338 SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix,
6339 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6340 true, false, false);
6342 // Start with nothing being drawn.
6343 ExecuteCalculateDrawProperties(grand_parent_raw);
6344 int member_id = render_surface_layer_list_count();
6346 EXPECT_NE(member_id, membership_id(grand_parent_raw));
6347 EXPECT_NE(member_id, membership_id(parent_raw));
6348 EXPECT_NE(member_id, membership_id(child_raw));
6349 EXPECT_NE(member_id, membership_id(grand_child1_raw));
6350 EXPECT_NE(member_id, membership_id(grand_child2_raw));
6352 std::set<LayerImpl*> expected;
6353 std::set<LayerImpl*> actual;
6354 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6355 EXPECT_EQ(expected, actual);
6357 // If we force render surface, but none of the layers are in the layer list,
6358 // then this layer should not appear in RSLL.
6359 grand_child1_raw->SetHasRenderSurface(true);
6360 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
6362 ExecuteCalculateDrawProperties(grand_parent_raw);
6363 member_id = render_surface_layer_list_count();
6365 EXPECT_NE(member_id, membership_id(grand_parent_raw));
6366 EXPECT_NE(member_id, membership_id(parent_raw));
6367 EXPECT_NE(member_id, membership_id(child_raw));
6368 EXPECT_NE(member_id, membership_id(grand_child1_raw));
6369 EXPECT_NE(member_id, membership_id(grand_child2_raw));
6371 expected.clear();
6372 actual.clear();
6373 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6374 EXPECT_EQ(expected, actual);
6376 // However, if we say that this layer also draws content, it will appear in
6377 // RSLL.
6378 grand_child1_raw->SetDrawsContent(true);
6380 ExecuteCalculateDrawProperties(grand_parent_raw);
6381 member_id = render_surface_layer_list_count();
6383 EXPECT_NE(member_id, membership_id(grand_parent_raw));
6384 EXPECT_NE(member_id, membership_id(parent_raw));
6385 EXPECT_NE(member_id, membership_id(child_raw));
6386 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
6387 EXPECT_NE(member_id, membership_id(grand_child2_raw));
6389 expected.clear();
6390 expected.insert(grand_child1_raw);
6392 actual.clear();
6393 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6394 EXPECT_EQ(expected, actual);
6396 // Now child is forced to have a render surface, and one if its children draws
6397 // content.
6398 grand_child1_raw->SetDrawsContent(false);
6399 grand_child1_raw->SetHasRenderSurface(false);
6400 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
6401 child_raw->SetHasRenderSurface(true);
6402 grand_child2_raw->SetDrawsContent(true);
6404 ExecuteCalculateDrawProperties(grand_parent_raw);
6405 member_id = render_surface_layer_list_count();
6407 EXPECT_NE(member_id, membership_id(grand_parent_raw));
6408 EXPECT_NE(member_id, membership_id(parent_raw));
6409 EXPECT_NE(member_id, membership_id(child_raw));
6410 EXPECT_NE(member_id, membership_id(grand_child1_raw));
6411 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
6413 expected.clear();
6414 expected.insert(grand_child2_raw);
6416 actual.clear();
6417 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6418 EXPECT_EQ(expected, actual);
6420 // Add a mask layer to child.
6421 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass());
6422 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
6424 ExecuteCalculateDrawProperties(grand_parent_raw);
6425 member_id = render_surface_layer_list_count();
6427 EXPECT_NE(member_id, membership_id(grand_parent_raw));
6428 EXPECT_NE(member_id, membership_id(parent_raw));
6429 EXPECT_NE(member_id, membership_id(child_raw));
6430 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
6431 EXPECT_NE(member_id, membership_id(grand_child1_raw));
6432 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
6434 expected.clear();
6435 expected.insert(grand_child2_raw);
6436 expected.insert(child_raw->mask_layer());
6438 expected.clear();
6439 expected.insert(grand_child2_raw);
6440 expected.insert(child_raw->mask_layer());
6442 actual.clear();
6443 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6444 EXPECT_EQ(expected, actual);
6446 // Add replica mask layer.
6447 scoped_ptr<LayerImpl> replica_layer =
6448 LayerImpl::Create(host_impl.active_tree(), 20);
6449 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21));
6450 child_raw->SetReplicaLayer(replica_layer.Pass());
6452 ExecuteCalculateDrawProperties(grand_parent_raw);
6453 member_id = render_surface_layer_list_count();
6455 EXPECT_NE(member_id, membership_id(grand_parent_raw));
6456 EXPECT_NE(member_id, membership_id(parent_raw));
6457 EXPECT_NE(member_id, membership_id(child_raw));
6458 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
6459 EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer()));
6460 EXPECT_NE(member_id, membership_id(grand_child1_raw));
6461 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
6463 expected.clear();
6464 expected.insert(grand_child2_raw);
6465 expected.insert(child_raw->mask_layer());
6466 expected.insert(child_raw->replica_layer()->mask_layer());
6468 actual.clear();
6469 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6470 EXPECT_EQ(expected, actual);
6472 child_raw->TakeReplicaLayer();
6474 // With nothing drawing, we should have no layers.
6475 grand_child2_raw->SetDrawsContent(false);
6477 ExecuteCalculateDrawProperties(grand_parent_raw);
6478 member_id = render_surface_layer_list_count();
6480 EXPECT_NE(member_id, membership_id(grand_parent_raw));
6481 EXPECT_NE(member_id, membership_id(parent_raw));
6482 EXPECT_NE(member_id, membership_id(child_raw));
6483 EXPECT_NE(member_id, membership_id(child_raw->mask_layer()));
6484 EXPECT_NE(member_id, membership_id(grand_child1_raw));
6485 EXPECT_NE(member_id, membership_id(grand_child2_raw));
6487 expected.clear();
6488 actual.clear();
6489 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6490 EXPECT_EQ(expected, actual);
6492 // Child itself draws means that we should have the child and the mask in the
6493 // list.
6494 child_raw->SetDrawsContent(true);
6496 ExecuteCalculateDrawProperties(grand_parent_raw);
6497 member_id = render_surface_layer_list_count();
6499 EXPECT_NE(member_id, membership_id(grand_parent_raw));
6500 EXPECT_NE(member_id, membership_id(parent_raw));
6501 EXPECT_EQ(member_id, membership_id(child_raw));
6502 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
6503 EXPECT_NE(member_id, membership_id(grand_child1_raw));
6504 EXPECT_NE(member_id, membership_id(grand_child2_raw));
6506 expected.clear();
6507 expected.insert(child_raw);
6508 expected.insert(child_raw->mask_layer());
6509 actual.clear();
6510 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6511 EXPECT_EQ(expected, actual);
6513 child_raw->TakeMaskLayer();
6514 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
6516 // Now everyone's a member!
6517 grand_parent_raw->SetDrawsContent(true);
6518 parent_raw->SetDrawsContent(true);
6519 child_raw->SetDrawsContent(true);
6520 grand_child1_raw->SetDrawsContent(true);
6521 grand_child2_raw->SetDrawsContent(true);
6523 ExecuteCalculateDrawProperties(grand_parent_raw);
6524 member_id = render_surface_layer_list_count();
6526 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
6527 EXPECT_EQ(member_id, membership_id(parent_raw));
6528 EXPECT_EQ(member_id, membership_id(child_raw));
6529 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
6530 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
6532 expected.clear();
6533 expected.insert(grand_parent_raw);
6534 expected.insert(parent_raw);
6535 expected.insert(child_raw);
6536 expected.insert(grand_child1_raw);
6537 expected.insert(grand_child2_raw);
6539 actual.clear();
6540 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
6541 EXPECT_EQ(expected, actual);
6544 TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
6545 FakeImplProxy proxy;
6546 TestSharedBitmapManager shared_bitmap_manager;
6547 TestTaskGraphRunner task_graph_runner;
6548 LayerTreeSettings settings;
6549 settings.layer_transforms_should_scale_layer_contents = true;
6550 FakeLayerTreeHostImpl host_impl(settings, &proxy, &shared_bitmap_manager,
6551 &task_graph_runner);
6553 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
6554 LayerImpl* root_layer = root.get();
6555 scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2);
6556 LayerImpl* child1_layer = child1.get();
6557 scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3);
6558 LayerImpl* child2_layer = child2.get();
6560 root->AddChild(child1.Pass());
6561 root->AddChild(child2.Pass());
6562 root->SetHasRenderSurface(true);
6564 gfx::Transform identity_matrix, scale_transform_child1,
6565 scale_transform_child2;
6566 scale_transform_child1.Scale(2, 3);
6567 scale_transform_child2.Scale(4, 5);
6569 SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(),
6570 gfx::PointF(), gfx::Size(1, 1), true, false,
6571 true);
6572 SetLayerPropertiesForTesting(child1_layer, scale_transform_child1,
6573 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
6574 false, false);
6576 child1_layer->SetMaskLayer(
6577 LayerImpl::Create(host_impl.active_tree(), 4).Pass());
6579 scoped_ptr<LayerImpl> replica_layer =
6580 LayerImpl::Create(host_impl.active_tree(), 5);
6581 replica_layer->SetHasRenderSurface(true);
6582 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
6583 child1_layer->SetReplicaLayer(replica_layer.Pass());
6584 child1_layer->SetHasRenderSurface(true);
6586 ExecuteCalculateDrawProperties(root_layer);
6588 TransformOperations scale;
6589 scale.AppendScale(5.f, 8.f, 3.f);
6591 AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale);
6592 SetLayerPropertiesForTesting(child2_layer, scale_transform_child2,
6593 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
6594 false, false);
6596 ExecuteCalculateDrawProperties(root_layer);
6598 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
6599 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
6600 EXPECT_FLOAT_EQ(3.f, child1_layer->mask_layer()->GetIdealContentsScale());
6601 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
6603 EXPECT_FLOAT_EQ(
6604 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
6605 EXPECT_FLOAT_EQ(
6606 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
6607 EXPECT_FLOAT_EQ(0.f,
6608 child1_layer->mask_layer()
6609 ->draw_properties()
6610 .maximum_animation_contents_scale);
6611 EXPECT_FLOAT_EQ(0.f,
6612 child1_layer->replica_layer()
6613 ->mask_layer()
6614 ->draw_properties()
6615 .maximum_animation_contents_scale);
6616 EXPECT_FLOAT_EQ(
6617 8.f, child2_layer->draw_properties().maximum_animation_contents_scale);
6619 // Changing page-scale would affect ideal_contents_scale and
6620 // maximum_animation_contents_scale.
6622 float page_scale_factor = 3.f;
6623 float device_scale_factor = 1.0f;
6624 std::vector<LayerImpl*> render_surface_layer_list;
6625 gfx::Size device_viewport_size =
6626 gfx::Size(root_layer->bounds().width() * device_scale_factor,
6627 root_layer->bounds().height() * device_scale_factor);
6628 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6629 root_layer, device_viewport_size, &render_surface_layer_list);
6631 inputs.page_scale_factor = page_scale_factor;
6632 inputs.can_adjust_raster_scales = true;
6633 inputs.page_scale_layer = root_layer;
6634 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6636 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
6637 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
6638 EXPECT_FLOAT_EQ(9.f, child1_layer->mask_layer()->GetIdealContentsScale());
6639 EXPECT_FLOAT_EQ(
6640 9.f,
6641 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
6642 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
6644 EXPECT_FLOAT_EQ(
6645 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
6646 EXPECT_FLOAT_EQ(
6647 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
6648 EXPECT_FLOAT_EQ(0.f,
6649 child1_layer->mask_layer()
6650 ->draw_properties()
6651 .maximum_animation_contents_scale);
6652 EXPECT_FLOAT_EQ(0.f,
6653 child1_layer->replica_layer()
6654 ->mask_layer()
6655 ->draw_properties()
6656 .maximum_animation_contents_scale);
6657 EXPECT_FLOAT_EQ(
6658 24.f, child2_layer->draw_properties().maximum_animation_contents_scale);
6660 // Changing device-scale would affect ideal_contents_scale and
6661 // maximum_animation_contents_scale.
6663 device_scale_factor = 4.0f;
6664 inputs.device_scale_factor = device_scale_factor;
6665 inputs.can_adjust_raster_scales = true;
6666 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6668 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
6669 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
6670 EXPECT_FLOAT_EQ(36.f, child1_layer->mask_layer()->GetIdealContentsScale());
6671 EXPECT_FLOAT_EQ(
6672 36.f,
6673 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
6674 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
6676 EXPECT_FLOAT_EQ(
6677 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
6678 EXPECT_FLOAT_EQ(
6679 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
6680 EXPECT_FLOAT_EQ(0.f,
6681 child1_layer->mask_layer()
6682 ->draw_properties()
6683 .maximum_animation_contents_scale);
6684 EXPECT_FLOAT_EQ(0.f,
6685 child1_layer->replica_layer()
6686 ->mask_layer()
6687 ->draw_properties()
6688 .maximum_animation_contents_scale);
6689 EXPECT_FLOAT_EQ(
6690 96.f, child2_layer->draw_properties().maximum_animation_contents_scale);
6693 TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
6694 scoped_refptr<Layer> root = Layer::Create(layer_settings());
6695 SetLayerPropertiesForTesting(root.get(),
6696 gfx::Transform(),
6697 gfx::Point3F(),
6698 gfx::PointF(),
6699 gfx::Size(768 / 2, 3000),
6700 true,
6701 false);
6702 root->SetIsDrawable(true);
6704 scoped_refptr<Layer> clip = Layer::Create(layer_settings());
6705 SetLayerPropertiesForTesting(clip.get(),
6706 gfx::Transform(),
6707 gfx::Point3F(),
6708 gfx::PointF(),
6709 gfx::Size(768 / 2, 10000),
6710 true,
6711 false);
6712 clip->SetMasksToBounds(true);
6714 scoped_refptr<Layer> content = Layer::Create(layer_settings());
6715 SetLayerPropertiesForTesting(content.get(),
6716 gfx::Transform(),
6717 gfx::Point3F(),
6718 gfx::PointF(),
6719 gfx::Size(768 / 2, 10000),
6720 true,
6721 false);
6722 content->SetIsDrawable(true);
6723 content->SetForceRenderSurface(true);
6725 root->AddChild(clip);
6726 clip->AddChild(content);
6728 host()->SetRootLayer(root);
6730 gfx::Size device_viewport_size(768, 582);
6731 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(host()->root_layer(),
6732 device_viewport_size);
6733 inputs.device_scale_factor = 2.f;
6734 inputs.page_scale_factor = 1.f;
6735 inputs.page_scale_layer = NULL;
6736 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6738 // Layers in the root render surface have their visible content rect clipped
6739 // by the viewport.
6740 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
6741 root->visible_rect_from_property_trees());
6743 // Layers drawing to a child render surface should still have their visible
6744 // content rect clipped by the viewport.
6745 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
6746 content->visible_rect_from_property_trees());
6749 TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
6750 FakeImplProxy proxy;
6751 TestSharedBitmapManager shared_bitmap_manager;
6752 TestTaskGraphRunner task_graph_runner;
6753 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
6754 &task_graph_runner);
6756 // Set two layers: the root layer clips it's child,
6757 // the child draws its content.
6759 gfx::Size root_size = gfx::Size(300, 500);
6761 // Sublayer should be bigger than the root enlarged by bounds_delta.
6762 gfx::Size sublayer_size = gfx::Size(300, 1000);
6764 // Device viewport accomidated the root and the top controls.
6765 gfx::Size device_viewport_size = gfx::Size(300, 600);
6766 gfx::Transform identity_matrix;
6768 host_impl.SetViewportSize(device_viewport_size);
6769 host_impl.active_tree()->SetRootLayer(
6770 LayerImpl::Create(host_impl.active_tree(), 1));
6772 LayerImpl* root = host_impl.active_tree()->root_layer();
6773 SetLayerPropertiesForTesting(root,
6774 identity_matrix,
6775 gfx::Point3F(),
6776 gfx::PointF(),
6777 root_size,
6778 false,
6779 false,
6780 true);
6781 root->SetMasksToBounds(true);
6783 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2));
6785 LayerImpl* sublayer = root->child_at(0);
6786 SetLayerPropertiesForTesting(sublayer,
6787 identity_matrix,
6788 gfx::Point3F(),
6789 gfx::PointF(),
6790 sublayer_size,
6791 false,
6792 false,
6793 false);
6794 sublayer->SetDrawsContent(true);
6796 LayerImplList layer_impl_list;
6797 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6798 root, device_viewport_size, &layer_impl_list);
6800 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6801 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
6803 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
6804 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6806 gfx::Rect affected_by_delta(0, 0, root_size.width(),
6807 root_size.height() + 50);
6808 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
6811 TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) {
6812 scoped_refptr<Layer> root = Layer::Create(layer_settings());
6813 scoped_refptr<Layer> inner_viewport_container_layer =
6814 Layer::Create(layer_settings());
6815 scoped_refptr<Layer> inner_viewport_scroll_layer =
6816 Layer::Create(layer_settings());
6817 scoped_refptr<Layer> outer_viewport_container_layer =
6818 Layer::Create(layer_settings());
6819 scoped_refptr<Layer> outer_viewport_scroll_layer =
6820 Layer::Create(layer_settings());
6822 root->AddChild(inner_viewport_container_layer);
6823 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer);
6824 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
6825 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
6827 inner_viewport_scroll_layer->SetScrollClipLayerId(
6828 inner_viewport_container_layer->id());
6829 outer_viewport_scroll_layer->SetScrollClipLayerId(
6830 outer_viewport_container_layer->id());
6832 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
6833 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
6835 host()->SetRootLayer(root);
6836 host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer,
6837 outer_viewport_scroll_layer);
6839 scoped_refptr<Layer> fixed_to_inner = Layer::Create(layer_settings());
6840 scoped_refptr<Layer> fixed_to_outer = Layer::Create(layer_settings());
6842 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
6843 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
6845 LayerPositionConstraint fixed_to_right;
6846 fixed_to_right.set_is_fixed_position(true);
6847 fixed_to_right.set_is_fixed_to_right_edge(true);
6849 fixed_to_inner->SetPositionConstraint(fixed_to_right);
6850 fixed_to_outer->SetPositionConstraint(fixed_to_right);
6852 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
6854 TransformTree& transform_tree = host()->property_trees()->transform_tree;
6855 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
6856 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
6858 LayerPositionConstraint fixed_to_left;
6859 fixed_to_left.set_is_fixed_position(true);
6860 fixed_to_inner->SetPositionConstraint(fixed_to_left);
6862 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
6863 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
6864 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
6866 fixed_to_outer->SetPositionConstraint(fixed_to_left);
6868 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
6869 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
6870 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
6873 TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
6874 const gfx::Transform identity_matrix;
6875 scoped_refptr<Layer> root = Layer::Create(layer_settings());
6876 scoped_refptr<LayerWithForcedDrawsContent> animated =
6877 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6879 root->AddChild(animated);
6881 host()->SetRootLayer(root);
6883 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
6884 gfx::PointF(), gfx::Size(100, 100), true, false);
6885 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
6886 gfx::PointF(), gfx::Size(20, 20), true, false);
6888 root->SetMasksToBounds(true);
6889 root->SetForceRenderSurface(true);
6890 animated->SetOpacity(0.f);
6892 AddOpacityTransitionToController(animated->layer_animation_controller(), 10.0,
6893 0.f, 1.f, false);
6895 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
6897 EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty());
6900 TEST_F(LayerTreeHostCommonTest,
6901 VisibleContentRectForAnimatedLayerWithSingularTransform) {
6902 const gfx::Transform identity_matrix;
6903 scoped_refptr<Layer> root = Layer::Create(layer_settings());
6904 scoped_refptr<Layer> clip = Layer::Create(layer_settings());
6905 scoped_refptr<LayerWithForcedDrawsContent> animated =
6906 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6907 scoped_refptr<LayerWithForcedDrawsContent> surface =
6908 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6909 scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation =
6910 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6912 root->AddChild(clip);
6913 clip->AddChild(animated);
6914 animated->AddChild(surface);
6915 surface->AddChild(descendant_of_animation);
6917 clip->SetMasksToBounds(true);
6918 surface->SetForceRenderSurface(true);
6920 host()->SetRootLayer(root);
6922 gfx::Transform uninvertible_matrix;
6923 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
6925 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
6926 gfx::PointF(), gfx::Size(100, 100), true, false);
6927 SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(),
6928 gfx::PointF(), gfx::Size(10, 10), true, false);
6929 SetLayerPropertiesForTesting(animated.get(), uninvertible_matrix,
6930 gfx::Point3F(), gfx::PointF(),
6931 gfx::Size(120, 120), true, false);
6932 SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(),
6933 gfx::PointF(), gfx::Size(100, 100), true, false);
6934 SetLayerPropertiesForTesting(descendant_of_animation.get(), identity_matrix,
6935 gfx::Point3F(), gfx::PointF(),
6936 gfx::Size(200, 200), true, false);
6938 TransformOperations start_transform_operations;
6939 start_transform_operations.AppendMatrix(uninvertible_matrix);
6940 TransformOperations end_transform_operations;
6942 AddAnimatedTransformToLayer(animated.get(), 10.0, start_transform_operations,
6943 end_transform_operations);
6945 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
6947 // The animated layer has a singular transform and maps to a non-empty rect in
6948 // clipped target space, so is treated as fully visible.
6949 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_rect_from_property_trees());
6951 // The singular transform on |animated| is flattened when inherited by
6952 // |surface|, and this happens to make it invertible.
6953 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_rect_from_property_trees());
6954 EXPECT_EQ(gfx::Rect(2, 2),
6955 descendant_of_animation->visible_rect_from_property_trees());
6957 gfx::Transform zero_matrix;
6958 zero_matrix.Scale3d(0.f, 0.f, 0.f);
6959 SetLayerPropertiesForTesting(animated.get(), zero_matrix, gfx::Point3F(),
6960 gfx::PointF(), gfx::Size(120, 120), true, false);
6962 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
6964 // The animated layer maps to the empty rect in clipped target space, so is
6965 // treated as having an empty visible rect.
6966 EXPECT_EQ(gfx::Rect(), animated->visible_rect_from_property_trees());
6968 // This time, flattening does not make |animated|'s transform invertible. This
6969 // means the clip cannot be projected into |surface|'s space, so we treat
6970 // |surface| and layers that draw into it as having empty visible rect.
6971 EXPECT_EQ(gfx::Rect(), surface->visible_rect_from_property_trees());
6972 EXPECT_EQ(gfx::Rect(),
6973 descendant_of_animation->visible_rect_from_property_trees());
6976 // Verify that having an animated filter (but no current filter, as these
6977 // are mutually exclusive) correctly creates a render surface.
6978 TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
6979 scoped_refptr<Layer> root = Layer::Create(layer_settings());
6980 scoped_refptr<Layer> child = Layer::Create(layer_settings());
6981 scoped_refptr<Layer> grandchild = Layer::Create(layer_settings());
6982 root->AddChild(child);
6983 child->AddChild(grandchild);
6985 gfx::Transform identity_transform;
6986 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
6987 gfx::PointF(), gfx::Size(50, 50), true, false);
6988 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
6989 gfx::PointF(), gfx::Size(50, 50), true, false);
6990 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
6991 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6992 true, false);
6993 host()->SetRootLayer(root);
6995 AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f);
6997 ExecuteCalculateDrawProperties(root.get());
6999 EXPECT_TRUE(root->render_surface());
7000 EXPECT_TRUE(child->render_surface());
7001 EXPECT_FALSE(grandchild->render_surface());
7003 EXPECT_TRUE(root->filters().IsEmpty());
7004 EXPECT_TRUE(child->filters().IsEmpty());
7005 EXPECT_TRUE(grandchild->filters().IsEmpty());
7007 EXPECT_FALSE(root->FilterIsAnimating());
7008 EXPECT_TRUE(child->FilterIsAnimating());
7009 EXPECT_FALSE(grandchild->FilterIsAnimating());
7012 // Verify that having a filter animation with a delayed start time creates a
7013 // render surface.
7014 TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) {
7015 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7016 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7017 scoped_refptr<Layer> grandchild = Layer::Create(layer_settings());
7018 root->AddChild(child);
7019 child->AddChild(grandchild);
7021 gfx::Transform identity_transform;
7022 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7023 gfx::PointF(), gfx::Size(50, 50), true, false);
7024 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
7025 gfx::PointF(), gfx::Size(50, 50), true, false);
7026 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
7027 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7028 true, false);
7029 host()->SetRootLayer(root);
7031 scoped_ptr<KeyframedFilterAnimationCurve> curve(
7032 KeyframedFilterAnimationCurve::Create());
7033 FilterOperations start_filters;
7034 start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f));
7035 FilterOperations end_filters;
7036 end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f));
7037 curve->AddKeyframe(
7038 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
7039 curve->AddKeyframe(FilterKeyframe::Create(
7040 base::TimeDelta::FromMilliseconds(100), end_filters, nullptr));
7041 scoped_ptr<Animation> animation =
7042 Animation::Create(curve.Pass(), 0, 1, Animation::FILTER);
7043 animation->set_fill_mode(Animation::FILL_MODE_NONE);
7044 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7045 child->layer_animation_controller()->AddAnimation(animation.Pass());
7047 ExecuteCalculateDrawProperties(root.get());
7049 EXPECT_TRUE(root->render_surface());
7050 EXPECT_TRUE(child->render_surface());
7051 EXPECT_FALSE(grandchild->render_surface());
7053 EXPECT_TRUE(root->filters().IsEmpty());
7054 EXPECT_TRUE(child->filters().IsEmpty());
7055 EXPECT_TRUE(grandchild->filters().IsEmpty());
7057 EXPECT_FALSE(root->FilterIsAnimating());
7058 EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation());
7059 EXPECT_FALSE(child->FilterIsAnimating());
7060 EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation());
7061 EXPECT_FALSE(grandchild->FilterIsAnimating());
7062 EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation());
7065 // Ensures that the property tree code accounts for offsets between fixed
7066 // position layers and their respective containers.
7067 TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
7068 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7069 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7070 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
7071 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7073 root->AddChild(child);
7074 child->AddChild(grandchild);
7076 gfx::Transform identity_transform;
7077 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7078 gfx::PointF(), gfx::Size(50, 50), true, false);
7079 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
7080 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7081 false);
7082 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
7083 gfx::Point3F(), gfx::PointF(-1000, -1000),
7084 gfx::Size(50, 50), true, false);
7086 root->SetMasksToBounds(true);
7087 root->SetIsContainerForFixedPositionLayers(true);
7088 LayerPositionConstraint constraint;
7089 constraint.set_is_fixed_position(true);
7090 grandchild->SetPositionConstraint(constraint);
7092 root->SetIsContainerForFixedPositionLayers(true);
7094 host()->SetRootLayer(root);
7096 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7098 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7099 grandchild->visible_rect_from_property_trees());
7102 // Ensures that the property tree code accounts for offsets between fixed
7103 // position containers and their transform tree parents, when a fixed position
7104 // layer's container is its layer tree parent, but this parent doesn't have its
7105 // own transform tree node.
7106 TEST_F(LayerTreeHostCommonTest,
7107 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
7108 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7109 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7110 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
7111 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7113 root->AddChild(child);
7114 child->AddChild(grandchild);
7116 gfx::Transform identity_transform;
7117 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7118 gfx::PointF(), gfx::Size(50, 50), true, false);
7119 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
7120 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7121 false);
7122 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
7123 gfx::Point3F(), gfx::PointF(-1000, -1000),
7124 gfx::Size(50, 50), true, false);
7126 root->SetMasksToBounds(true);
7127 child->SetIsContainerForFixedPositionLayers(true);
7128 LayerPositionConstraint constraint;
7129 constraint.set_is_fixed_position(true);
7130 grandchild->SetPositionConstraint(constraint);
7132 root->SetIsContainerForFixedPositionLayers(true);
7134 host()->SetRootLayer(root);
7136 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7138 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7139 grandchild->visible_rect_from_property_trees());
7142 TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) {
7143 // In the following layer tree, the layer |box|'s render target is |surface|.
7144 // |surface| also creates a transform node. We want to combine clips for |box|
7145 // in the space of its target (i.e., |surface|), not its target's target. This
7146 // test ensures that happens.
7148 gfx::Transform rotate;
7149 rotate.Rotate(5);
7150 gfx::Transform identity;
7152 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7153 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7154 gfx::PointF(), gfx::Size(2500, 1500), true,
7155 false);
7157 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
7158 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
7159 gfx::PointF(), gfx::Size(2500, 1500), true,
7160 false);
7161 frame_clip->SetMasksToBounds(true);
7163 scoped_refptr<Layer> rotated = Layer::Create(layer_settings());
7164 SetLayerPropertiesForTesting(rotated.get(), rotate,
7165 gfx::Point3F(1250, 250, 0), gfx::PointF(),
7166 gfx::Size(2500, 500), true, false);
7168 scoped_refptr<Layer> surface = Layer::Create(layer_settings());
7169 SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(),
7170 gfx::PointF(), gfx::Size(2500, 500), true,
7171 false);
7172 surface->SetOpacity(0.5);
7174 scoped_refptr<LayerWithForcedDrawsContent> container =
7175 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7176 SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(),
7177 gfx::PointF(), gfx::Size(300, 300), true, false);
7179 scoped_refptr<LayerWithForcedDrawsContent> box =
7180 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7181 SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(),
7182 gfx::PointF(), gfx::Size(100, 100), true, false);
7184 root->AddChild(frame_clip);
7185 frame_clip->AddChild(rotated);
7186 rotated->AddChild(surface);
7187 surface->AddChild(container);
7188 surface->AddChild(box);
7190 host()->SetRootLayer(root);
7192 ExecuteCalculateDrawProperties(root.get());
7195 TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
7196 gfx::Transform identity;
7197 gfx::Transform translate_z;
7198 translate_z.Translate3d(0, 0, 10);
7200 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7201 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7202 gfx::PointF(), gfx::Size(800, 800), true, false);
7203 root->SetIsContainerForFixedPositionLayers(true);
7205 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
7206 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
7207 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7208 false);
7209 frame_clip->SetMasksToBounds(true);
7211 scoped_refptr<LayerWithForcedDrawsContent> fixed =
7212 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7213 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
7214 gfx::PointF(), gfx::Size(1000, 1000), true,
7215 false);
7217 LayerPositionConstraint constraint;
7218 constraint.set_is_fixed_position(true);
7219 fixed->SetPositionConstraint(constraint);
7221 root->AddChild(frame_clip);
7222 frame_clip->AddChild(fixed);
7224 host()->SetRootLayer(root);
7226 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7228 gfx::Rect expected(0, 0, 100, 100);
7229 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
7232 TEST_F(LayerTreeHostCommonTest,
7233 PropertyTreesAccountForScrollCompensationAdjustment) {
7234 gfx::Transform identity;
7235 gfx::Transform translate_z;
7236 translate_z.Translate3d(0, 0, 10);
7238 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7239 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7240 gfx::PointF(), gfx::Size(800, 800), true, false);
7241 root->SetIsContainerForFixedPositionLayers(true);
7243 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
7244 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
7245 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7246 false);
7247 frame_clip->SetMasksToBounds(true);
7249 scoped_refptr<LayerWithForcedDrawsContent> scroller =
7250 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7251 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(),
7252 gfx::PointF(), gfx::Size(1000, 1000), true,
7253 false);
7255 scroller->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f, 0.7f));
7256 scroller->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7));
7257 scroller->SetScrollClipLayerId(frame_clip->id());
7259 scoped_refptr<LayerWithForcedDrawsContent> fixed =
7260 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7261 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
7262 gfx::PointF(), gfx::Size(50, 50), true, false);
7264 LayerPositionConstraint constraint;
7265 constraint.set_is_fixed_position(true);
7266 fixed->SetPositionConstraint(constraint);
7268 scoped_refptr<LayerWithForcedDrawsContent> fixed_child =
7269 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7270 SetLayerPropertiesForTesting(fixed_child.get(), identity, gfx::Point3F(),
7271 gfx::PointF(), gfx::Size(10, 10), true, false);
7273 fixed_child->SetPositionConstraint(constraint);
7275 root->AddChild(frame_clip);
7276 frame_clip->AddChild(scroller);
7277 scroller->AddChild(fixed);
7278 fixed->AddChild(fixed_child);
7280 host()->SetRootLayer(root);
7282 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7284 gfx::Rect expected(0, 0, 50, 50);
7285 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
7287 expected = gfx::Rect(0, 0, 10, 10);
7288 EXPECT_EQ(expected, fixed_child->visible_rect_from_property_trees());
7291 TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
7292 gfx::Transform identity;
7294 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7295 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7296 gfx::PointF(), gfx::Size(800, 800), true, false);
7297 root->SetIsContainerForFixedPositionLayers(true);
7299 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
7300 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
7301 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7302 false);
7303 frame_clip->SetMasksToBounds(true);
7305 scoped_refptr<LayerWithForcedDrawsContent> scroller =
7306 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7307 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(),
7308 gfx::PointF(), gfx::Size(1000, 1000), true,
7309 false);
7311 scroller->SetScrollOffset(gfx::ScrollOffset(100, 100));
7312 scroller->SetScrollClipLayerId(frame_clip->id());
7314 scoped_refptr<LayerWithForcedDrawsContent> fixed =
7315 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7316 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
7317 gfx::PointF(100, 100), gfx::Size(50, 50), true,
7318 false);
7320 LayerPositionConstraint constraint;
7321 constraint.set_is_fixed_position(true);
7322 fixed->SetPositionConstraint(constraint);
7323 fixed->SetForceRenderSurface(true);
7324 fixed->SetMasksToBounds(true);
7326 root->AddChild(frame_clip);
7327 frame_clip->AddChild(scroller);
7328 scroller->AddChild(fixed);
7330 host()->SetRootLayer(root);
7332 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7334 gfx::Rect expected(0, 0, 50, 50);
7335 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
7338 TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
7339 gfx::Transform identity;
7340 gfx::Transform translate;
7341 gfx::Transform rotate;
7343 translate.Translate(10, 10);
7344 rotate.Rotate(45);
7346 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7347 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7348 gfx::PointF(), gfx::Size(800, 800), true, false);
7349 root->SetIsContainerForFixedPositionLayers(true);
7351 host()->SetRootLayer(root);
7353 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7354 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
7356 root->SetTransform(translate);
7357 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
7359 root->SetTransform(rotate);
7360 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
7363 TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
7364 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7365 scoped_refptr<LayerWithForcedDrawsContent> child =
7366 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7367 root->AddChild(child);
7369 host()->SetRootLayer(root);
7371 gfx::Transform identity_matrix;
7372 gfx::Transform scale_matrix;
7373 scale_matrix.Scale(2.f, 2.f);
7374 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
7375 gfx::PointF(), gfx::Size(100, 100), true, false);
7376 SetLayerPropertiesForTesting(child.get(), scale_matrix, gfx::Point3F(),
7377 gfx::PointF(), gfx::Size(10, 10), true, false);
7379 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7380 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees());
7382 child->SetTransformOrigin(gfx::Point3F(10.f, 10.f, 10.f));
7384 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7385 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_rect_from_property_trees());
7388 TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
7389 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7390 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7391 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7392 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7393 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7395 root->AddChild(scroll_child);
7396 root->AddChild(scroll_parent);
7397 scroll_child->SetScrollParent(scroll_parent.get());
7398 scroll_parent->SetScrollClipLayerId(root->id());
7400 host()->SetRootLayer(root);
7402 gfx::Transform identity_transform;
7403 gfx::Transform scale;
7404 scale.Scale(2.f, 2.f);
7405 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7406 gfx::PointF(), gfx::Size(50, 50), true, false);
7407 SetLayerPropertiesForTesting(scroll_child.get(), scale, gfx::Point3F(),
7408 gfx::PointF(), gfx::Size(40, 40), true, false);
7409 SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform,
7410 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7411 true, false);
7413 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7414 EXPECT_EQ(gfx::Rect(25, 25),
7415 scroll_child->visible_rect_from_property_trees());
7417 scroll_child->SetPosition(gfx::PointF(0, -10.f));
7418 scroll_parent->SetScrollOffset(gfx::ScrollOffset(0.f, 10.f));
7419 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7420 EXPECT_EQ(gfx::Rect(0, 5, 25, 25),
7421 scroll_child->visible_rect_from_property_trees());
7424 static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {
7427 TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
7428 gfx::Transform identity;
7429 FakeContentLayerClient client;
7430 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7431 scoped_refptr<LayerWithForcedDrawsContent> child =
7432 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7433 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
7434 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7435 scoped_refptr<FakePictureLayer> greatgrandchild(
7436 FakePictureLayer::Create(layer_settings(), &client));
7437 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7438 gfx::PointF(), gfx::Size(100, 100), true, false);
7439 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
7440 gfx::PointF(), gfx::Size(10, 10), true, false);
7441 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
7442 gfx::PointF(), gfx::Size(10, 10), true, false);
7443 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
7444 gfx::PointF(), gfx::Size(10, 10), true, false);
7446 root->AddChild(child);
7447 child->AddChild(grandchild);
7448 grandchild->AddChild(greatgrandchild);
7450 host()->SetRootLayer(root);
7452 // Check the non-skipped case.
7453 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7454 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
7456 // Now we will reset the visible rect from property trees for the grandchild,
7457 // and we will configure |child| in several ways that should force the subtree
7458 // to be skipped. The visible content rect for |grandchild| should, therefore,
7459 // remain empty.
7460 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
7461 gfx::Transform singular;
7462 singular.matrix().set(0, 0, 0);
7464 child->SetTransform(singular);
7465 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7466 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
7467 child->SetTransform(identity);
7469 child->SetHideLayerAndSubtree(true);
7470 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7471 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
7472 child->SetHideLayerAndSubtree(false);
7474 gfx::Transform zero_z_scale;
7475 zero_z_scale.Scale3d(1, 1, 0);
7476 child->SetTransform(zero_z_scale);
7478 // Add a transform animation with a start delay. Now, even though |child| has
7479 // a singular transform, the subtree should still get processed.
7480 int animation_id = 0;
7481 scoped_ptr<Animation> animation = Animation::Create(
7482 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(),
7483 animation_id, 1, Animation::TRANSFORM);
7484 animation->set_fill_mode(Animation::FILL_MODE_NONE);
7485 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7486 child->AddAnimation(animation.Pass());
7487 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7488 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
7489 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
7491 child->RemoveAnimation(animation_id);
7492 child->SetTransform(identity);
7493 child->SetOpacity(0.f);
7494 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7495 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
7497 // Now, even though child has zero opacity, we will configure |grandchild| and
7498 // |greatgrandchild| in several ways that should force the subtree to be
7499 // processed anyhow.
7500 greatgrandchild->RequestCopyOfOutput(
7501 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
7502 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7503 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
7504 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
7506 // Add an opacity animation with a start delay.
7507 animation_id = 1;
7508 animation = Animation::Create(
7509 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
7510 animation_id, 1, Animation::OPACITY);
7511 animation->set_fill_mode(Animation::FILL_MODE_NONE);
7512 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7513 child->AddAnimation(animation.Pass());
7514 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7515 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
7518 TEST_F(LayerTreeHostCommonTest, SkippingSubtreeImpl) {
7519 FakeImplProxy proxy;
7520 TestSharedBitmapManager shared_bitmap_manager;
7521 TestTaskGraphRunner task_graph_runner;
7522 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
7523 &task_graph_runner);
7525 gfx::Transform identity;
7526 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7527 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2);
7528 scoped_ptr<LayerImpl> grandchild =
7529 LayerImpl::Create(host_impl.active_tree(), 3);
7531 scoped_ptr<FakePictureLayerImpl> greatgrandchild(
7532 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
7534 child->SetDrawsContent(true);
7535 grandchild->SetDrawsContent(true);
7536 greatgrandchild->SetDrawsContent(true);
7538 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7539 gfx::PointF(), gfx::Size(100, 100), true, false,
7540 true);
7541 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
7542 gfx::PointF(), gfx::Size(10, 10), true, false,
7543 false);
7544 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
7545 gfx::PointF(), gfx::Size(10, 10), true, false,
7546 false);
7547 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
7548 gfx::PointF(), gfx::Size(10, 10), true, false,
7549 true);
7551 LayerImpl* child_ptr = child.get();
7552 LayerImpl* grandchild_ptr = grandchild.get();
7553 LayerImpl* greatgrandchild_ptr = greatgrandchild.get();
7555 grandchild->AddChild(greatgrandchild.Pass());
7556 child->AddChild(grandchild.Pass());
7557 root->AddChild(child.Pass());
7559 // Check the non-skipped case.
7560 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7561 EXPECT_EQ(gfx::Rect(10, 10),
7562 grandchild_ptr->visible_rect_from_property_trees());
7564 // Now we will reset the visible rect from property trees for the grandchild,
7565 // and we will configure |child| in several ways that should force the subtree
7566 // to be skipped. The visible content rect for |grandchild| should, therefore,
7567 // remain empty.
7568 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect());
7569 gfx::Transform singular;
7570 singular.matrix().set(0, 0, 0);
7572 child_ptr->SetTransform(singular);
7573 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7574 EXPECT_EQ(gfx::Rect(0, 0),
7575 grandchild_ptr->visible_rect_from_property_trees());
7576 child_ptr->SetTransform(identity);
7578 child_ptr->SetHideLayerAndSubtree(true);
7579 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7580 EXPECT_EQ(gfx::Rect(0, 0),
7581 grandchild_ptr->visible_rect_from_property_trees());
7582 child_ptr->SetHideLayerAndSubtree(false);
7584 child_ptr->SetOpacity(0.f);
7585 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7586 EXPECT_EQ(gfx::Rect(0, 0),
7587 grandchild_ptr->visible_rect_from_property_trees());
7589 // Now, even though child has zero opacity, we will configure |grandchild| and
7590 // |greatgrandchild| in several ways that should force the subtree to be
7591 // processed anyhow.
7592 ScopedPtrVector<CopyOutputRequest> requests;
7593 requests.push_back(CopyOutputRequest::CreateEmptyRequest());
7595 greatgrandchild_ptr->PassCopyRequests(&requests);
7596 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7597 EXPECT_EQ(gfx::Rect(10, 10),
7598 grandchild_ptr->visible_rect_from_property_trees());
7601 TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
7602 gfx::Transform identity;
7603 FakeContentLayerClient client;
7604 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7605 scoped_refptr<LayerWithForcedDrawsContent> child =
7606 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7607 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7608 gfx::PointF(), gfx::Size(100, 100), true, false);
7609 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
7610 gfx::PointF(), gfx::Size(10, 10), true, false);
7611 root->AddChild(child);
7613 host()->SetRootLayer(root);
7615 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7616 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees());
7617 child->set_visible_rect_from_property_trees(gfx::Rect());
7619 child->SetHideLayerAndSubtree(true);
7620 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7621 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
7622 child->SetHideLayerAndSubtree(false);
7624 child->SetBounds(gfx::Size());
7625 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7626 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
7627 child->SetBounds(gfx::Size(10, 10));
7629 gfx::Transform rotate;
7630 child->SetDoubleSided(false);
7631 rotate.RotateAboutXAxis(180.f);
7632 child->SetTransform(rotate);
7633 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7634 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
7635 child->SetDoubleSided(true);
7636 child->SetTransform(identity);
7638 child->SetOpacity(0.f);
7639 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7640 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
7643 TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
7644 // Ensure that the treewalk in LayerTreeHostCommom::
7645 // PreCalculateMetaInformation happens when its required.
7646 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7647 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
7648 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7650 root->AddChild(parent);
7651 parent->AddChild(child);
7653 child->SetClipParent(root.get());
7655 gfx::Transform identity;
7657 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7658 gfx::PointF(), gfx::Size(100, 100), true, false);
7659 SetLayerPropertiesForTesting(parent.get(), identity, gfx::Point3F(),
7660 gfx::PointF(), gfx::Size(100, 100), true, false);
7661 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
7662 gfx::PointF(), gfx::Size(100, 100), true, false);
7664 host()->SetRootLayer(root);
7666 ExecuteCalculateDrawProperties(root.get());
7667 EXPECT_EQ(parent->draw_properties().num_unclipped_descendants, 1u);
7669 child->RequestCopyOfOutput(
7670 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
7671 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
7672 ExecuteCalculateDrawProperties(root.get());
7673 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
7676 TEST_F(LayerTreeHostCommonTest, InputHandlersRecursiveUpdateTest) {
7677 // Ensure that the treewalk in LayertreeHostCommon::
7678 // PreCalculateMetaInformation updates input handlers correctly.
7679 LayerImpl* root = root_layer();
7680 LayerImpl* child = AddChild<LayerImpl>(root);
7682 gfx::Transform identity;
7684 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
7685 gfx::Size(100, 100), true, false, true);
7686 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
7687 gfx::Size(100, 100), true, false, false);
7689 EXPECT_EQ(root->draw_properties().layer_or_descendant_has_input_handler,
7690 false);
7692 child->SetHaveWheelEventHandlers(true);
7693 ExecuteCalculateDrawProperties(root);
7694 EXPECT_EQ(root->draw_properties().layer_or_descendant_has_input_handler,
7695 true);
7697 child->SetHaveWheelEventHandlers(false);
7698 ExecuteCalculateDrawProperties(root);
7699 EXPECT_EQ(root->draw_properties().layer_or_descendant_has_input_handler,
7700 false);
7703 TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
7704 gfx::Transform identity;
7705 gfx::Transform translate_z;
7706 translate_z.Translate3d(0, 0, 10);
7708 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7709 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7710 gfx::PointF(), gfx::Size(800, 800), true, false);
7712 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7713 SetLayerPropertiesForTesting(child.get(), translate_z, gfx::Point3F(),
7714 gfx::PointF(), gfx::Size(100, 100), true, false);
7716 root->AddChild(child);
7718 host()->SetRootLayer(root);
7720 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7721 EXPECT_NE(-1, child->transform_tree_index());
7723 child->RemoveFromParent();
7725 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7726 EXPECT_EQ(-1, child->transform_tree_index());
7729 TEST_F(LayerTreeHostCommonTest, ResetLayerDrawPropertiestest) {
7730 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7731 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7733 root->AddChild(child);
7734 gfx::Transform identity;
7736 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7737 gfx::PointF(), gfx::Size(100, 100), true, false);
7738 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
7739 gfx::PointF(), gfx::Size(100, 100), true, false);
7741 host()->SetRootLayer(root);
7743 EXPECT_FALSE(root->layer_or_descendant_is_drawn());
7744 EXPECT_FALSE(root->visited());
7745 EXPECT_FALSE(root->sorted_for_recursion());
7746 EXPECT_FALSE(child->layer_or_descendant_is_drawn());
7747 EXPECT_FALSE(child->visited());
7748 EXPECT_FALSE(child->sorted_for_recursion());
7750 root->set_layer_or_descendant_is_drawn(true);
7751 root->set_visited(true);
7752 root->set_sorted_for_recursion(true);
7753 child->set_layer_or_descendant_is_drawn(true);
7754 child->set_visited(true);
7755 child->set_sorted_for_recursion(true);
7757 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root.get());
7759 EXPECT_FALSE(root->layer_or_descendant_is_drawn());
7760 EXPECT_FALSE(root->visited());
7761 EXPECT_FALSE(root->sorted_for_recursion());
7762 EXPECT_FALSE(child->layer_or_descendant_is_drawn());
7763 EXPECT_FALSE(child->visited());
7764 EXPECT_FALSE(child->sorted_for_recursion());
7767 TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) {
7768 // Ensure that a Clip Node is added when a render surface applies clip.
7769 LayerImpl* root = root_layer();
7770 LayerImpl* significant_transform = AddChildToRoot<LayerImpl>();
7771 LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform);
7772 LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree);
7773 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
7775 const gfx::Transform identity_matrix;
7776 // This transform should be a significant one so that a transform node is
7777 // formed for it.
7778 gfx::Transform transform1;
7779 transform1.RotateAboutYAxis(45);
7780 transform1.RotateAboutXAxis(30);
7781 // This transform should be a 3d transform as we want the render surface
7782 // to flatten the transform
7783 gfx::Transform transform2;
7784 transform2.Translate3d(10, 10, 10);
7786 layer_clips_subtree->SetMasksToBounds(true);
7787 test_layer->SetDrawsContent(true);
7789 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
7790 gfx::PointF(), gfx::Size(30, 30), true, false,
7791 true);
7792 SetLayerPropertiesForTesting(significant_transform, transform1,
7793 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7794 true, false, false);
7795 SetLayerPropertiesForTesting(layer_clips_subtree, identity_matrix,
7796 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7797 true, false, false);
7798 SetLayerPropertiesForTesting(render_surface, transform2, gfx::Point3F(),
7799 gfx::PointF(), gfx::Size(30, 30), true, false,
7800 true);
7801 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
7802 gfx::PointF(), gfx::Size(30, 30), true, false,
7803 false);
7805 ExecuteCalculateDrawProperties(root);
7807 TransformTree transform_tree =
7808 root->layer_tree_impl()->property_trees()->transform_tree;
7809 TransformNode* transform_node =
7810 transform_tree.Node(significant_transform->transform_tree_index());
7811 EXPECT_EQ(transform_node->owner_id, significant_transform->id());
7813 ClipTree clip_tree = root->layer_tree_impl()->property_trees()->clip_tree;
7814 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index());
7815 EXPECT_TRUE(clip_node->data.inherit_parent_target_space_clip);
7816 EXPECT_EQ(test_layer->visible_rect_from_property_trees(), gfx::RectF(30, 21));
7819 TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) {
7820 // Ensure that when parent clip node's transform is an ancestor of current
7821 // clip node's target, clip is 'projected' from parent space to current
7822 // target space and visible rects are calculated correctly.
7823 LayerImpl* root = root_layer();
7824 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
7825 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer);
7826 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer);
7828 const gfx::Transform identity_matrix;
7829 gfx::Transform transform;
7830 transform.RotateAboutYAxis(45);
7831 clip_layer->SetMasksToBounds(true);
7832 target_layer->SetMasksToBounds(true);
7833 test_layer->SetDrawsContent(true);
7835 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
7836 gfx::PointF(), gfx::Size(30, 30), true, false,
7837 true);
7838 SetLayerPropertiesForTesting(clip_layer, transform, gfx::Point3F(),
7839 gfx::PointF(), gfx::Size(30, 30), true, false,
7840 false);
7841 SetLayerPropertiesForTesting(target_layer, transform, gfx::Point3F(),
7842 gfx::PointF(), gfx::Size(30, 30), true, false,
7843 true);
7844 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
7845 gfx::PointF(), gfx::Size(30, 30), true, false,
7846 false);
7847 ExecuteCalculateDrawProperties(root);
7849 ClipTree clip_tree = root->layer_tree_impl()->property_trees()->clip_tree;
7850 ClipNode* clip_node = clip_tree.Node(target_layer->clip_tree_index());
7851 EXPECT_EQ(clip_node->data.combined_clip, gfx::RectF(30, 30));
7852 EXPECT_EQ(test_layer->visible_rect_from_property_trees(), gfx::RectF(30, 30));
7855 TEST_F(LayerTreeHostCommonTest,
7856 RenderSurfaceWithUnclippedDescendantsClipsSubtree) {
7857 // Ensure clip rect is calculated correctly when render surface has unclipped
7858 // descendants.
7859 LayerImpl* root = root_layer();
7860 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
7861 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent);
7862 LayerImpl* render_surface =
7863 AddChild<LayerImpl>(between_clip_parent_and_child);
7864 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
7866 const gfx::Transform identity_matrix;
7867 gfx::Transform transform;
7868 transform.Translate(2.0, 2.0);
7870 test_layer->SetDrawsContent(true);
7871 render_surface->SetClipParent(clip_parent);
7872 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
7873 gfx::PointF(), gfx::Size(30, 30), true, false,
7874 true);
7875 SetLayerPropertiesForTesting(clip_parent, transform, gfx::Point3F(),
7876 gfx::PointF(), gfx::Size(30, 30), true, false,
7877 false);
7878 SetLayerPropertiesForTesting(between_clip_parent_and_child, transform,
7879 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7880 true, false, false);
7881 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
7882 gfx::PointF(), gfx::Size(30, 30), true, false,
7883 true);
7884 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
7885 gfx::PointF(), gfx::Size(30, 30), true, false,
7886 false);
7888 ExecuteCalculateDrawProperties(root);
7890 EXPECT_EQ(test_layer->clip_rect(), gfx::RectF(-4, -4, 30, 30));
7893 } // namespace
7894 } // namespace cc