Revert of Compute if a layer is clipped outside CalcDrawProps (patchset #9 id:160001...
[chromium-blink-merge.git] / cc / trees / layer_tree_host_common_unittest.cc
blob43e2bb02123438c9b2c85d1599dad230e475b3b4
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/layer_animation_controller.h"
11 #include "cc/animation/transform_operations.h"
12 #include "cc/base/math_util.h"
13 #include "cc/layers/content_layer_client.h"
14 #include "cc/layers/layer.h"
15 #include "cc/layers/layer_client.h"
16 #include "cc/layers/layer_impl.h"
17 #include "cc/layers/layer_iterator.h"
18 #include "cc/layers/render_surface.h"
19 #include "cc/layers/render_surface_impl.h"
20 #include "cc/output/copy_output_request.h"
21 #include "cc/output/copy_output_result.h"
22 #include "cc/test/animation_test_common.h"
23 #include "cc/test/fake_content_layer_client.h"
24 #include "cc/test/fake_impl_proxy.h"
25 #include "cc/test/fake_layer_tree_host.h"
26 #include "cc/test/fake_layer_tree_host_impl.h"
27 #include "cc/test/fake_picture_layer.h"
28 #include "cc/test/fake_picture_layer_impl.h"
29 #include "cc/test/geometry_test_utils.h"
30 #include "cc/test/layer_tree_host_common_test.h"
31 #include "cc/test/test_task_graph_runner.h"
32 #include "cc/trees/layer_tree_impl.h"
33 #include "cc/trees/proxy.h"
34 #include "cc/trees/single_thread_proxy.h"
35 #include "testing/gmock/include/gmock/gmock.h"
36 #include "testing/gtest/include/gtest/gtest.h"
37 #include "ui/gfx/geometry/quad_f.h"
38 #include "ui/gfx/geometry/vector2d_conversions.h"
39 #include "ui/gfx/transform.h"
41 namespace cc {
42 namespace {
44 class LayerWithForcedDrawsContent : public Layer {
45 public:
46 explicit LayerWithForcedDrawsContent(const LayerSettings& settings)
47 : Layer(settings) {}
49 bool DrawsContent() const override;
51 private:
52 ~LayerWithForcedDrawsContent() override {}
55 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
57 class MockContentLayerClient : public ContentLayerClient {
58 public:
59 MockContentLayerClient() {}
60 ~MockContentLayerClient() override {}
61 void PaintContents(SkCanvas* canvas,
62 const gfx::Rect& clip,
63 PaintingControlSetting picture_control) override {}
64 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
65 const gfx::Rect& clip,
66 PaintingControlSetting picture_control) override {
67 NOTIMPLEMENTED();
68 return nullptr;
70 bool FillsBoundsCompletely() const override { return false; }
73 scoped_refptr<FakePictureLayer> CreateDrawablePictureLayer(
74 const LayerSettings& settings,
75 ContentLayerClient* delegate) {
76 scoped_refptr<FakePictureLayer> to_return =
77 FakePictureLayer::Create(settings, delegate);
78 to_return->SetIsDrawable(true);
79 return to_return;
82 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
83 do { \
84 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
85 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
86 } while (false)
88 #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
89 do { \
90 EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \
91 } while (false)
93 class LayerTreeSettingsScaleContent : public LayerTreeSettings {
94 public:
95 LayerTreeSettingsScaleContent() {
96 layer_transforms_should_scale_layer_contents = true;
100 class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTest {
101 public:
102 LayerTreeHostCommonScalingTest()
103 : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {}
106 TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
107 // Sanity check: For layers positioned at zero, with zero size,
108 // and with identity transforms, then the draw transform,
109 // screen space transform, and the hierarchy passed on to children
110 // layers should also be identity transforms.
112 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
113 scoped_refptr<Layer> child = Layer::Create(layer_settings());
114 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
115 parent->AddChild(child);
116 child->AddChild(grand_child);
118 host()->SetRootLayer(parent);
120 gfx::Transform identity_matrix;
121 SetLayerPropertiesForTesting(parent.get(),
122 identity_matrix,
123 gfx::Point3F(),
124 gfx::PointF(),
125 gfx::Size(100, 100),
126 true,
127 false);
128 SetLayerPropertiesForTesting(child.get(),
129 identity_matrix,
130 gfx::Point3F(),
131 gfx::PointF(),
132 gfx::Size(),
133 true,
134 false);
135 SetLayerPropertiesForTesting(grand_child.get(),
136 identity_matrix,
137 gfx::Point3F(),
138 gfx::PointF(),
139 gfx::Size(),
140 true,
141 false);
143 ExecuteCalculateDrawProperties(parent.get());
145 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
146 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
147 child->screen_space_transform());
148 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
149 grand_child->draw_transform());
150 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
151 grand_child->screen_space_transform());
154 TEST_F(LayerTreeHostCommonTest, DoNotSkipLayersWithHandlers) {
155 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
156 scoped_refptr<Layer> child = Layer::Create(layer_settings());
157 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
158 parent->AddChild(child);
159 child->AddChild(grand_child);
161 host()->SetRootLayer(parent);
163 gfx::Transform identity_matrix;
164 SetLayerPropertiesForTesting(parent.get(),
165 identity_matrix,
166 gfx::Point3F(),
167 gfx::PointF(),
168 gfx::Size(100, 100),
169 true,
170 false);
171 SetLayerPropertiesForTesting(child.get(),
172 identity_matrix,
173 gfx::Point3F(),
174 gfx::PointF(10, 10),
175 gfx::Size(100, 100),
176 true,
177 false);
178 // This would have previously caused us to skip our subtree, but this would be
179 // wrong; we need up-to-date draw properties to do hit testing on the layers
180 // with handlers.
181 child->SetOpacity(0.f);
182 SetLayerPropertiesForTesting(grand_child.get(),
183 identity_matrix,
184 gfx::Point3F(),
185 gfx::PointF(10, 10),
186 gfx::Size(100, 100),
187 true,
188 false);
189 grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
191 ExecuteCalculateDrawProperties(parent.get());
193 // Check that we've computed draw properties for the subtree rooted at
194 // |child|.
195 EXPECT_FALSE(child->draw_transform().IsIdentity());
196 EXPECT_FALSE(grand_child->draw_transform().IsIdentity());
199 TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
200 gfx::Transform identity_matrix;
201 scoped_refptr<Layer> layer = Layer::Create(layer_settings());
203 scoped_refptr<Layer> root = Layer::Create(layer_settings());
204 SetLayerPropertiesForTesting(root.get(),
205 identity_matrix,
206 gfx::Point3F(),
207 gfx::PointF(),
208 gfx::Size(1, 2),
209 true,
210 false);
211 root->AddChild(layer);
213 host()->SetRootLayer(root);
215 // Case 2: Setting the bounds of the layer should not affect either the draw
216 // transform or the screenspace transform.
217 gfx::Transform translation_to_center;
218 translation_to_center.Translate(5.0, 6.0);
219 SetLayerPropertiesForTesting(layer.get(),
220 identity_matrix,
221 gfx::Point3F(),
222 gfx::PointF(),
223 gfx::Size(10, 12),
224 true,
225 false);
226 ExecuteCalculateDrawProperties(root.get());
227 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
228 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
229 layer->screen_space_transform());
231 // Case 3: The anchor point by itself (without a layer transform) should have
232 // no effect on the transforms.
233 SetLayerPropertiesForTesting(layer.get(),
234 identity_matrix,
235 gfx::Point3F(2.5f, 3.0f, 0.f),
236 gfx::PointF(),
237 gfx::Size(10, 12),
238 true,
239 false);
240 ExecuteCalculateDrawProperties(root.get());
241 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
242 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
243 layer->screen_space_transform());
245 // Case 4: A change in actual position affects both the draw transform and
246 // screen space transform.
247 gfx::Transform position_transform;
248 position_transform.Translate(0.f, 1.2f);
249 SetLayerPropertiesForTesting(layer.get(),
250 identity_matrix,
251 gfx::Point3F(2.5f, 3.0f, 0.f),
252 gfx::PointF(0.f, 1.2f),
253 gfx::Size(10, 12),
254 true,
255 false);
256 ExecuteCalculateDrawProperties(root.get());
257 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform());
258 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform,
259 layer->screen_space_transform());
261 // Case 5: In the correct sequence of transforms, the layer transform should
262 // pre-multiply the translation_to_center. This is easily tested by using a
263 // scale transform, because scale and translation are not commutative.
264 gfx::Transform layer_transform;
265 layer_transform.Scale3d(2.0, 2.0, 1.0);
266 SetLayerPropertiesForTesting(layer.get(),
267 layer_transform,
268 gfx::Point3F(),
269 gfx::PointF(),
270 gfx::Size(10, 12),
271 true,
272 false);
273 ExecuteCalculateDrawProperties(root.get());
274 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform());
275 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform,
276 layer->screen_space_transform());
278 // Case 6: The layer transform should occur with respect to the anchor point.
279 gfx::Transform translation_to_anchor;
280 translation_to_anchor.Translate(5.0, 0.0);
281 gfx::Transform expected_result =
282 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
283 SetLayerPropertiesForTesting(layer.get(),
284 layer_transform,
285 gfx::Point3F(5.0f, 0.f, 0.f),
286 gfx::PointF(),
287 gfx::Size(10, 12),
288 true,
289 false);
290 ExecuteCalculateDrawProperties(root.get());
291 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
292 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
293 layer->screen_space_transform());
295 // Case 7: Verify that position pre-multiplies the layer transform. The
296 // current implementation of CalculateDrawProperties does this implicitly, but
297 // it is still worth testing to detect accidental regressions.
298 expected_result = position_transform * translation_to_anchor *
299 layer_transform * Inverse(translation_to_anchor);
300 SetLayerPropertiesForTesting(layer.get(),
301 layer_transform,
302 gfx::Point3F(5.0f, 0.f, 0.f),
303 gfx::PointF(0.f, 1.2f),
304 gfx::Size(10, 12),
305 true,
306 false);
307 ExecuteCalculateDrawProperties(root.get());
308 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
309 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
310 layer->screen_space_transform());
313 TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
314 const gfx::ScrollOffset kScrollOffset(50, 100);
315 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
316 const gfx::Vector2d kMaxScrollOffset(200, 200);
317 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
318 -kScrollOffset.y());
319 const float kPageScale = 0.888f;
320 const float kDeviceScale = 1.666f;
322 FakeImplProxy proxy;
323 TestSharedBitmapManager shared_bitmap_manager;
324 TestTaskGraphRunner task_graph_runner;
325 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
326 &task_graph_runner);
328 gfx::Transform identity_matrix;
329 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
330 LayerImpl::Create(host_impl.active_tree(), 1));
331 LayerImpl* sublayer = sublayer_scoped_ptr.get();
332 SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(),
333 gfx::PointF(), gfx::Size(500, 500), true, false,
334 false);
336 scoped_ptr<LayerImpl> scroll_layer_scoped_ptr(
337 LayerImpl::Create(host_impl.active_tree(), 2));
338 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
339 SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(),
340 gfx::PointF(), gfx::Size(10, 20), true, false,
341 false);
342 scoped_ptr<LayerImpl> clip_layer_scoped_ptr(
343 LayerImpl::Create(host_impl.active_tree(), 4));
344 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
346 scroll_layer->SetScrollClipLayer(clip_layer->id());
347 clip_layer->SetBounds(
348 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
349 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
350 scroll_layer->SetScrollClipLayer(clip_layer->id());
351 scroll_layer->SetScrollDelta(kScrollDelta);
352 gfx::Transform impl_transform;
353 scroll_layer->AddChild(sublayer_scoped_ptr.Pass());
354 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
355 clip_layer->AddChild(scroll_layer_scoped_ptr.Pass());
356 scroll_layer_raw_ptr->PushScrollOffsetFromMainThread(kScrollOffset);
358 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
359 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
360 gfx::PointF(), gfx::Size(3, 4), true, false,
361 false);
362 root->AddChild(clip_layer_scoped_ptr.Pass());
363 root->SetHasRenderSurface(true);
365 ExecuteCalculateDrawProperties(
366 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
367 gfx::Transform expected_transform = identity_matrix;
368 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
369 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() *
370 kPageScale * kDeviceScale),
371 MathUtil::Round(sub_layer_screen_position.y() *
372 kPageScale * kDeviceScale));
373 expected_transform.Scale(kPageScale * kDeviceScale,
374 kPageScale * kDeviceScale);
375 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
376 sublayer->draw_transform());
377 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
378 sublayer->screen_space_transform());
380 gfx::Transform arbitrary_translate;
381 const float kTranslateX = 10.6f;
382 const float kTranslateY = 20.6f;
383 arbitrary_translate.Translate(kTranslateX, kTranslateY);
384 SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate,
385 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
386 true, false, false);
387 ExecuteCalculateDrawProperties(
388 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
389 expected_transform.MakeIdentity();
390 expected_transform.Translate(
391 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
392 sub_layer_screen_position.x() * kPageScale *
393 kDeviceScale),
394 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
395 sub_layer_screen_position.y() * kPageScale *
396 kDeviceScale));
397 expected_transform.Scale(kPageScale * kDeviceScale,
398 kPageScale * kDeviceScale);
399 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
400 sublayer->draw_transform());
403 TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
404 gfx::Transform identity_matrix;
405 scoped_refptr<Layer> root = Layer::Create(layer_settings());
406 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
407 scoped_refptr<Layer> child = Layer::Create(layer_settings());
408 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
409 root->AddChild(parent);
410 parent->AddChild(child);
411 child->AddChild(grand_child);
413 host()->SetRootLayer(root);
415 // One-time setup of root layer
416 SetLayerPropertiesForTesting(root.get(),
417 identity_matrix,
418 gfx::Point3F(),
419 gfx::PointF(),
420 gfx::Size(1, 2),
421 true,
422 false);
424 // Case 1: parent's anchor point should not affect child or grand_child.
425 SetLayerPropertiesForTesting(parent.get(),
426 identity_matrix,
427 gfx::Point3F(2.5f, 3.0f, 0.f),
428 gfx::PointF(),
429 gfx::Size(10, 12),
430 true,
431 false);
432 SetLayerPropertiesForTesting(child.get(),
433 identity_matrix,
434 gfx::Point3F(),
435 gfx::PointF(),
436 gfx::Size(16, 18),
437 true,
438 false);
439 SetLayerPropertiesForTesting(grand_child.get(),
440 identity_matrix,
441 gfx::Point3F(),
442 gfx::PointF(),
443 gfx::Size(76, 78),
444 true,
445 false);
446 ExecuteCalculateDrawProperties(root.get());
447 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
448 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
449 child->screen_space_transform());
450 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
451 grand_child->draw_transform());
452 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
453 grand_child->screen_space_transform());
455 // Case 2: parent's position affects child and grand_child.
456 gfx::Transform parent_position_transform;
457 parent_position_transform.Translate(0.f, 1.2f);
458 SetLayerPropertiesForTesting(parent.get(),
459 identity_matrix,
460 gfx::Point3F(2.5f, 3.0f, 0.f),
461 gfx::PointF(0.f, 1.2f),
462 gfx::Size(10, 12),
463 true,
464 false);
465 SetLayerPropertiesForTesting(child.get(),
466 identity_matrix,
467 gfx::Point3F(),
468 gfx::PointF(),
469 gfx::Size(16, 18),
470 true,
471 false);
472 SetLayerPropertiesForTesting(grand_child.get(),
473 identity_matrix,
474 gfx::Point3F(),
475 gfx::PointF(),
476 gfx::Size(76, 78),
477 true,
478 false);
479 ExecuteCalculateDrawProperties(root.get());
480 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
481 child->draw_transform());
482 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
483 child->screen_space_transform());
484 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
485 grand_child->draw_transform());
486 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
487 grand_child->screen_space_transform());
489 // Case 3: parent's local transform affects child and grandchild
490 gfx::Transform parent_layer_transform;
491 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
492 gfx::Transform parent_translation_to_anchor;
493 parent_translation_to_anchor.Translate(2.5, 3.0);
494 gfx::Transform parent_composite_transform =
495 parent_translation_to_anchor * parent_layer_transform *
496 Inverse(parent_translation_to_anchor);
497 SetLayerPropertiesForTesting(parent.get(),
498 parent_layer_transform,
499 gfx::Point3F(2.5f, 3.0f, 0.f),
500 gfx::PointF(),
501 gfx::Size(10, 12),
502 true,
503 false);
504 SetLayerPropertiesForTesting(child.get(),
505 identity_matrix,
506 gfx::Point3F(),
507 gfx::PointF(),
508 gfx::Size(16, 18),
509 true,
510 false);
511 SetLayerPropertiesForTesting(grand_child.get(),
512 identity_matrix,
513 gfx::Point3F(),
514 gfx::PointF(),
515 gfx::Size(76, 78),
516 true,
517 false);
518 ExecuteCalculateDrawProperties(root.get());
519 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
520 child->draw_transform());
521 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
522 child->screen_space_transform());
523 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
524 grand_child->draw_transform());
525 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
526 grand_child->screen_space_transform());
529 TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
530 scoped_refptr<Layer> root = Layer::Create(layer_settings());
531 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
532 scoped_refptr<Layer> child = Layer::Create(layer_settings());
533 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
534 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
535 root->AddChild(parent);
536 parent->AddChild(child);
537 child->AddChild(grand_child);
539 host()->SetRootLayer(root);
541 // One-time setup of root layer
542 gfx::Transform identity_matrix;
543 SetLayerPropertiesForTesting(root.get(),
544 identity_matrix,
545 gfx::Point3F(),
546 gfx::PointF(),
547 gfx::Size(1, 2),
548 true,
549 false);
551 // Child is set up so that a new render surface should be created.
552 child->SetOpacity(0.5f);
553 child->SetForceRenderSurface(true);
555 gfx::Transform parent_layer_transform;
556 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
557 gfx::Transform parent_translation_to_anchor;
558 parent_translation_to_anchor.Translate(25.0, 30.0);
560 gfx::Transform parent_composite_transform =
561 parent_translation_to_anchor * parent_layer_transform *
562 Inverse(parent_translation_to_anchor);
563 gfx::Vector2dF parent_composite_scale =
564 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
565 1.f);
566 gfx::Transform surface_sublayer_transform;
567 surface_sublayer_transform.Scale(parent_composite_scale.x(),
568 parent_composite_scale.y());
569 gfx::Transform surface_sublayer_composite_transform =
570 parent_composite_transform * Inverse(surface_sublayer_transform);
572 // Child's render surface should not exist yet.
573 ASSERT_FALSE(child->render_surface());
575 SetLayerPropertiesForTesting(parent.get(),
576 parent_layer_transform,
577 gfx::Point3F(25.0f, 30.0f, 0.f),
578 gfx::PointF(),
579 gfx::Size(100, 120),
580 true,
581 false);
582 SetLayerPropertiesForTesting(child.get(),
583 identity_matrix,
584 gfx::Point3F(),
585 gfx::PointF(),
586 gfx::Size(16, 18),
587 true,
588 false);
589 SetLayerPropertiesForTesting(grand_child.get(),
590 identity_matrix,
591 gfx::Point3F(),
592 gfx::PointF(),
593 gfx::Size(8, 10),
594 true,
595 false);
596 ExecuteCalculateDrawProperties(root.get());
598 // Render surface should have been created now.
599 ASSERT_TRUE(child->render_surface());
600 ASSERT_EQ(child.get(), child->render_target());
602 // The child layer's draw transform should refer to its new render surface.
603 // The screen-space transform, however, should still refer to the root.
604 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
605 child->draw_transform());
606 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
607 child->screen_space_transform());
609 // Because the grand_child is the only drawable content, the child's render
610 // surface will tighten its bounds to the grand_child. The scale at which the
611 // surface's subtree is drawn must be removed from the composite transform.
612 EXPECT_TRANSFORMATION_MATRIX_EQ(
613 surface_sublayer_composite_transform,
614 child->render_target()->render_surface()->draw_transform());
616 // The screen space is the same as the target since the child surface draws
617 // into the root.
618 EXPECT_TRANSFORMATION_MATRIX_EQ(
619 surface_sublayer_composite_transform,
620 child->render_target()->render_surface()->screen_space_transform());
623 TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
624 scoped_refptr<Layer> root = Layer::Create(layer_settings());
625 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
626 scoped_refptr<Layer> child = Layer::Create(layer_settings());
627 scoped_refptr<Layer> child_replica = Layer::Create(layer_settings());
628 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
629 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
630 root->AddChild(parent);
631 parent->AddChild(child);
632 child->AddChild(grand_child);
633 child->SetReplicaLayer(child_replica.get());
635 host()->SetRootLayer(root);
637 // One-time setup of root layer
638 gfx::Transform identity_matrix;
639 SetLayerPropertiesForTesting(root.get(),
640 identity_matrix,
641 gfx::Point3F(),
642 gfx::PointF(),
643 gfx::Size(1, 2),
644 true,
645 false);
647 // Child is set up so that a new render surface should be created.
648 child->SetOpacity(0.5f);
650 gfx::Transform parent_layer_transform;
651 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
652 gfx::Transform parent_translation_to_anchor;
653 parent_translation_to_anchor.Translate(2.5, 3.0);
654 gfx::Transform parent_composite_transform =
655 parent_translation_to_anchor * parent_layer_transform *
656 Inverse(parent_translation_to_anchor);
657 gfx::Transform replica_layer_transform;
658 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
659 gfx::Vector2dF parent_composite_scale =
660 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
661 1.f);
662 gfx::Transform surface_sublayer_transform;
663 surface_sublayer_transform.Scale(parent_composite_scale.x(),
664 parent_composite_scale.y());
665 gfx::Transform replica_composite_transform =
666 parent_composite_transform * replica_layer_transform *
667 Inverse(surface_sublayer_transform);
668 child_replica->SetIsDrawable(true);
669 // Child's render surface should not exist yet.
670 ASSERT_FALSE(child->render_surface());
672 SetLayerPropertiesForTesting(parent.get(),
673 parent_layer_transform,
674 gfx::Point3F(2.5f, 3.0f, 0.f),
675 gfx::PointF(),
676 gfx::Size(10, 12),
677 true,
678 false);
679 SetLayerPropertiesForTesting(child.get(),
680 identity_matrix,
681 gfx::Point3F(),
682 gfx::PointF(),
683 gfx::Size(16, 18),
684 true,
685 false);
686 SetLayerPropertiesForTesting(grand_child.get(),
687 identity_matrix,
688 gfx::Point3F(),
689 gfx::PointF(-0.5f, -0.5f),
690 gfx::Size(1, 1),
691 true,
692 false);
693 SetLayerPropertiesForTesting(child_replica.get(),
694 replica_layer_transform,
695 gfx::Point3F(),
696 gfx::PointF(),
697 gfx::Size(),
698 true,
699 false);
700 ExecuteCalculateDrawProperties(root.get());
702 // Render surface should have been created now.
703 ASSERT_TRUE(child->render_surface());
704 ASSERT_EQ(child.get(), child->render_target());
706 EXPECT_TRANSFORMATION_MATRIX_EQ(
707 replica_composite_transform,
708 child->render_target()->render_surface()->replica_draw_transform());
709 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
710 child->render_target()
711 ->render_surface()
712 ->replica_screen_space_transform());
715 TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
716 // This test creates a more complex tree and verifies it all at once. This
717 // covers the following cases:
718 // - layers that are described w.r.t. a render surface: should have draw
719 // transforms described w.r.t. that surface
720 // - A render surface described w.r.t. an ancestor render surface: should
721 // have a draw transform described w.r.t. that ancestor surface
722 // - Replicas of a render surface are described w.r.t. the replica's
723 // transform around its anchor, along with the surface itself.
724 // - Sanity check on recursion: verify transforms of layers described w.r.t.
725 // a render surface that is described w.r.t. an ancestor render surface.
726 // - verifying that each layer has a reference to the correct render surface
727 // and render target values.
729 scoped_refptr<Layer> root = Layer::Create(layer_settings());
730 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
731 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
732 scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings());
733 scoped_refptr<Layer> child_of_root = Layer::Create(layer_settings());
734 scoped_refptr<Layer> child_of_rs1 = Layer::Create(layer_settings());
735 scoped_refptr<Layer> child_of_rs2 = Layer::Create(layer_settings());
736 scoped_refptr<Layer> replica_of_rs1 = Layer::Create(layer_settings());
737 scoped_refptr<Layer> replica_of_rs2 = Layer::Create(layer_settings());
738 scoped_refptr<Layer> grand_child_of_root = Layer::Create(layer_settings());
739 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
740 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
741 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
742 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
743 root->AddChild(parent);
744 parent->AddChild(render_surface1);
745 parent->AddChild(child_of_root);
746 render_surface1->AddChild(child_of_rs1);
747 render_surface1->AddChild(render_surface2);
748 render_surface2->AddChild(child_of_rs2);
749 child_of_root->AddChild(grand_child_of_root);
750 child_of_rs1->AddChild(grand_child_of_rs1);
751 child_of_rs2->AddChild(grand_child_of_rs2);
752 render_surface1->SetReplicaLayer(replica_of_rs1.get());
753 render_surface2->SetReplicaLayer(replica_of_rs2.get());
755 host()->SetRootLayer(root);
757 // In combination with descendant draws content, opacity != 1 forces the layer
758 // to have a new render surface.
759 render_surface1->SetOpacity(0.5f);
760 render_surface2->SetOpacity(0.33f);
762 // One-time setup of root layer
763 gfx::Transform identity_matrix;
764 SetLayerPropertiesForTesting(root.get(),
765 identity_matrix,
766 gfx::Point3F(),
767 gfx::PointF(),
768 gfx::Size(1, 2),
769 true,
770 false);
772 // All layers in the tree are initialized with an anchor at .25 and a size of
773 // (10,10). matrix "A" is the composite layer transform used in all layers,
774 // Matrix "R" is the composite replica transform used in all replica layers.
775 gfx::Transform translation_to_anchor;
776 translation_to_anchor.Translate(2.5, 0.0);
777 gfx::Transform layer_transform;
778 layer_transform.Translate(1.0, 1.0);
779 gfx::Transform replica_layer_transform;
780 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
782 gfx::Transform A =
783 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
784 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
785 Inverse(translation_to_anchor);
787 gfx::Vector2dF surface1_parent_transform_scale =
788 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
789 gfx::Transform surface1_sublayer_transform;
790 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
791 surface1_parent_transform_scale.y());
793 // SS1 = transform given to the subtree of render_surface1
794 gfx::Transform SS1 = surface1_sublayer_transform;
795 // S1 = transform to move from render_surface1 pixels to the layer space of
796 // the owning layer
797 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
799 gfx::Vector2dF surface2_parent_transform_scale =
800 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
801 gfx::Transform surface2_sublayer_transform;
802 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
803 surface2_parent_transform_scale.y());
805 // SS2 = transform given to the subtree of render_surface2
806 gfx::Transform SS2 = surface2_sublayer_transform;
807 // S2 = transform to move from render_surface2 pixels to the layer space of
808 // the owning layer
809 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
811 SetLayerPropertiesForTesting(parent.get(),
812 layer_transform,
813 gfx::Point3F(2.5f, 0.f, 0.f),
814 gfx::PointF(),
815 gfx::Size(10, 10),
816 true,
817 false);
818 SetLayerPropertiesForTesting(render_surface1.get(),
819 layer_transform,
820 gfx::Point3F(2.5f, 0.f, 0.f),
821 gfx::PointF(),
822 gfx::Size(10, 10),
823 true,
824 false);
825 SetLayerPropertiesForTesting(render_surface2.get(),
826 layer_transform,
827 gfx::Point3F(2.5f, 0.f, 0.f),
828 gfx::PointF(),
829 gfx::Size(10, 10),
830 true,
831 false);
832 SetLayerPropertiesForTesting(child_of_root.get(),
833 layer_transform,
834 gfx::Point3F(2.5f, 0.f, 0.f),
835 gfx::PointF(),
836 gfx::Size(10, 10),
837 true,
838 false);
839 SetLayerPropertiesForTesting(child_of_rs1.get(),
840 layer_transform,
841 gfx::Point3F(2.5f, 0.f, 0.f),
842 gfx::PointF(),
843 gfx::Size(10, 10),
844 true,
845 false);
846 SetLayerPropertiesForTesting(child_of_rs2.get(),
847 layer_transform,
848 gfx::Point3F(2.5f, 0.f, 0.f),
849 gfx::PointF(),
850 gfx::Size(10, 10),
851 true,
852 false);
853 SetLayerPropertiesForTesting(grand_child_of_root.get(),
854 layer_transform,
855 gfx::Point3F(2.5f, 0.f, 0.f),
856 gfx::PointF(),
857 gfx::Size(10, 10),
858 true,
859 false);
860 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
861 layer_transform,
862 gfx::Point3F(2.5f, 0.f, 0.f),
863 gfx::PointF(),
864 gfx::Size(10, 10),
865 true,
866 false);
867 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
868 layer_transform,
869 gfx::Point3F(2.5f, 0.f, 0.f),
870 gfx::PointF(),
871 gfx::Size(10, 10),
872 true,
873 false);
874 SetLayerPropertiesForTesting(replica_of_rs1.get(),
875 replica_layer_transform,
876 gfx::Point3F(2.5f, 0.f, 0.f),
877 gfx::PointF(),
878 gfx::Size(),
879 true,
880 false);
881 SetLayerPropertiesForTesting(replica_of_rs2.get(),
882 replica_layer_transform,
883 gfx::Point3F(2.5f, 0.f, 0.f),
884 gfx::PointF(),
885 gfx::Size(),
886 true,
887 false);
889 ExecuteCalculateDrawProperties(root.get());
891 // Only layers that are associated with render surfaces should have an actual
892 // RenderSurface() value.
893 ASSERT_TRUE(root->render_surface());
894 ASSERT_FALSE(child_of_root->render_surface());
895 ASSERT_FALSE(grand_child_of_root->render_surface());
897 ASSERT_TRUE(render_surface1->render_surface());
898 ASSERT_FALSE(child_of_rs1->render_surface());
899 ASSERT_FALSE(grand_child_of_rs1->render_surface());
901 ASSERT_TRUE(render_surface2->render_surface());
902 ASSERT_FALSE(child_of_rs2->render_surface());
903 ASSERT_FALSE(grand_child_of_rs2->render_surface());
905 // Verify all render target accessors
906 EXPECT_EQ(root.get(), parent->render_target());
907 EXPECT_EQ(root.get(), child_of_root->render_target());
908 EXPECT_EQ(root.get(), grand_child_of_root->render_target());
910 EXPECT_EQ(render_surface1.get(), render_surface1->render_target());
911 EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target());
912 EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target());
914 EXPECT_EQ(render_surface2.get(), render_surface2->render_target());
915 EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target());
916 EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target());
918 // Verify layer draw transforms note that draw transforms are described with
919 // respect to the nearest ancestor render surface but screen space transforms
920 // are described with respect to the root.
921 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform());
922 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform());
923 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
924 grand_child_of_root->draw_transform());
926 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform());
927 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform());
928 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
929 grand_child_of_rs1->draw_transform());
931 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform());
932 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform());
933 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
934 grand_child_of_rs2->draw_transform());
936 // Verify layer screen-space transforms
938 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform());
939 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
940 child_of_root->screen_space_transform());
941 EXPECT_TRANSFORMATION_MATRIX_EQ(
942 A * A * A, grand_child_of_root->screen_space_transform());
944 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
945 render_surface1->screen_space_transform());
946 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
947 child_of_rs1->screen_space_transform());
948 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
949 grand_child_of_rs1->screen_space_transform());
951 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
952 render_surface2->screen_space_transform());
953 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
954 child_of_rs2->screen_space_transform());
955 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
956 grand_child_of_rs2->screen_space_transform());
958 // Verify render surface transforms.
960 // Draw transform of render surface 1 is described with respect to root.
961 EXPECT_TRANSFORMATION_MATRIX_EQ(
962 A * A * S1, render_surface1->render_surface()->draw_transform());
963 EXPECT_TRANSFORMATION_MATRIX_EQ(
964 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
965 EXPECT_TRANSFORMATION_MATRIX_EQ(
966 A * A * S1, render_surface1->render_surface()->screen_space_transform());
967 EXPECT_TRANSFORMATION_MATRIX_EQ(
968 A * R * S1,
969 render_surface1->render_surface()->replica_screen_space_transform());
970 // Draw transform of render surface 2 is described with respect to render
971 // surface 1.
972 EXPECT_TRANSFORMATION_MATRIX_EQ(
973 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
974 EXPECT_TRANSFORMATION_MATRIX_EQ(
975 SS1 * R * S2,
976 render_surface2->render_surface()->replica_draw_transform());
977 EXPECT_TRANSFORMATION_MATRIX_EQ(
978 A * A * A * S2,
979 render_surface2->render_surface()->screen_space_transform());
980 EXPECT_TRANSFORMATION_MATRIX_EQ(
981 A * A * R * S2,
982 render_surface2->render_surface()->replica_screen_space_transform());
984 // Sanity check. If these fail there is probably a bug in the test itself. It
985 // is expected that we correctly set up transforms so that the y-component of
986 // the screen-space transform encodes the "depth" of the layer in the tree.
987 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
988 EXPECT_FLOAT_EQ(2.0,
989 child_of_root->screen_space_transform().matrix().get(1, 3));
990 EXPECT_FLOAT_EQ(
991 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
993 EXPECT_FLOAT_EQ(2.0,
994 render_surface1->screen_space_transform().matrix().get(1, 3));
995 EXPECT_FLOAT_EQ(3.0,
996 child_of_rs1->screen_space_transform().matrix().get(1, 3));
997 EXPECT_FLOAT_EQ(
998 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
1000 EXPECT_FLOAT_EQ(3.0,
1001 render_surface2->screen_space_transform().matrix().get(1, 3));
1002 EXPECT_FLOAT_EQ(4.0,
1003 child_of_rs2->screen_space_transform().matrix().get(1, 3));
1004 EXPECT_FLOAT_EQ(
1005 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
1008 TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
1009 // For layers that flatten their subtree, there should be an orthographic
1010 // projection (for x and y values) in the middle of the transform sequence.
1011 // Note that the way the code is currently implemented, it is not expected to
1012 // use a canonical orthographic projection.
1014 scoped_refptr<Layer> root = Layer::Create(layer_settings());
1015 scoped_refptr<Layer> child = Layer::Create(layer_settings());
1016 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1017 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1018 scoped_refptr<LayerWithForcedDrawsContent> great_grand_child =
1019 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1021 gfx::Transform rotation_about_y_axis;
1022 rotation_about_y_axis.RotateAboutYAxis(30.0);
1024 const gfx::Transform identity_matrix;
1025 SetLayerPropertiesForTesting(root.get(),
1026 identity_matrix,
1027 gfx::Point3F(),
1028 gfx::PointF(),
1029 gfx::Size(100, 100),
1030 true,
1031 false);
1032 SetLayerPropertiesForTesting(child.get(),
1033 rotation_about_y_axis,
1034 gfx::Point3F(),
1035 gfx::PointF(),
1036 gfx::Size(10, 10),
1037 true,
1038 false);
1039 SetLayerPropertiesForTesting(grand_child.get(),
1040 rotation_about_y_axis,
1041 gfx::Point3F(),
1042 gfx::PointF(),
1043 gfx::Size(10, 10),
1044 true,
1045 false);
1046 SetLayerPropertiesForTesting(great_grand_child.get(), identity_matrix,
1047 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1048 true, false);
1050 root->AddChild(child);
1051 child->AddChild(grand_child);
1052 grand_child->AddChild(great_grand_child);
1053 child->SetForceRenderSurface(true);
1055 host()->SetRootLayer(root);
1057 // No layers in this test should preserve 3d.
1058 ASSERT_TRUE(root->should_flatten_transform());
1059 ASSERT_TRUE(child->should_flatten_transform());
1060 ASSERT_TRUE(grand_child->should_flatten_transform());
1061 ASSERT_TRUE(great_grand_child->should_flatten_transform());
1063 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1064 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1065 gfx::Transform expected_grand_child_draw_transform =
1066 rotation_about_y_axis; // draws onto child's render surface
1067 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1068 flattened_rotation_about_y.FlattenTo2d();
1069 gfx::Transform expected_grand_child_screen_space_transform =
1070 flattened_rotation_about_y * rotation_about_y_axis;
1071 gfx::Transform expected_great_grand_child_draw_transform =
1072 flattened_rotation_about_y;
1073 gfx::Transform expected_great_grand_child_screen_space_transform =
1074 flattened_rotation_about_y * flattened_rotation_about_y;
1076 ExecuteCalculateDrawProperties(root.get());
1078 // The child's draw transform should have been taken by its surface.
1079 ASSERT_TRUE(child->render_surface());
1080 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1081 child->render_surface()->draw_transform());
1082 EXPECT_TRANSFORMATION_MATRIX_EQ(
1083 expected_child_screen_space_transform,
1084 child->render_surface()->screen_space_transform());
1085 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1086 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
1087 child->screen_space_transform());
1088 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
1089 grand_child->draw_transform());
1090 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
1091 grand_child->screen_space_transform());
1092 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
1093 great_grand_child->draw_transform());
1094 EXPECT_TRANSFORMATION_MATRIX_EQ(
1095 expected_great_grand_child_screen_space_transform,
1096 great_grand_child->screen_space_transform());
1099 TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
1100 // A layer that is empty in one axis, but not the other, was accidentally
1101 // skipping a necessary translation. Without that translation, the coordinate
1102 // space of the layer's draw transform is incorrect.
1104 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1105 // but if that layer becomes a render surface, then its draw transform is
1106 // implicitly inherited by the rest of the subtree, which then is positioned
1107 // incorrectly as a result.
1109 scoped_refptr<Layer> root = Layer::Create(layer_settings());
1110 scoped_refptr<Layer> child = Layer::Create(layer_settings());
1111 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1112 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1114 // The child height is zero, but has non-zero width that should be accounted
1115 // for while computing draw transforms.
1116 const gfx::Transform identity_matrix;
1117 SetLayerPropertiesForTesting(root.get(),
1118 identity_matrix,
1119 gfx::Point3F(),
1120 gfx::PointF(),
1121 gfx::Size(100, 100),
1122 true,
1123 false);
1124 SetLayerPropertiesForTesting(child.get(),
1125 identity_matrix,
1126 gfx::Point3F(),
1127 gfx::PointF(),
1128 gfx::Size(10, 0),
1129 true,
1130 false);
1131 SetLayerPropertiesForTesting(grand_child.get(),
1132 identity_matrix,
1133 gfx::Point3F(),
1134 gfx::PointF(),
1135 gfx::Size(10, 10),
1136 true,
1137 false);
1139 root->AddChild(child);
1140 child->AddChild(grand_child);
1141 child->SetForceRenderSurface(true);
1143 host()->SetRootLayer(root);
1145 ExecuteCalculateDrawProperties(root.get());
1147 ASSERT_TRUE(child->render_surface());
1148 // This is the real test, the rest are sanity checks.
1149 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1150 child->render_surface()->draw_transform());
1151 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1152 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1153 grand_child->draw_transform());
1156 TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
1157 // Transformations applied at the root of the tree should be forwarded
1158 // to child layers instead of applied to the root RenderSurface.
1159 const gfx::Transform identity_matrix;
1160 scoped_refptr<LayerWithForcedDrawsContent> root =
1161 new LayerWithForcedDrawsContent(layer_settings());
1162 scoped_refptr<LayerWithForcedDrawsContent> child =
1163 new LayerWithForcedDrawsContent(layer_settings());
1164 child->SetScrollClipLayerId(root->id());
1165 root->AddChild(child);
1167 host()->SetRootLayer(root);
1169 SetLayerPropertiesForTesting(root.get(),
1170 identity_matrix,
1171 gfx::Point3F(),
1172 gfx::PointF(),
1173 gfx::Size(20, 20),
1174 true,
1175 false);
1176 SetLayerPropertiesForTesting(child.get(),
1177 identity_matrix,
1178 gfx::Point3F(),
1179 gfx::PointF(),
1180 gfx::Size(20, 20),
1181 true,
1182 false);
1184 gfx::Transform translate;
1185 translate.Translate(50, 50);
1187 RenderSurfaceLayerList render_surface_layer_list;
1188 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1189 root.get(), root->bounds(), translate, &render_surface_layer_list);
1190 inputs.can_adjust_raster_scales = true;
1191 inputs.property_trees->needs_rebuild = true;
1192 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1193 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1194 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1195 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1198 gfx::Transform scale;
1199 scale.Scale(2, 2);
1201 RenderSurfaceLayerList render_surface_layer_list;
1202 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1203 root.get(), root->bounds(), scale, &render_surface_layer_list);
1204 inputs.can_adjust_raster_scales = true;
1205 inputs.property_trees->needs_rebuild = true;
1206 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1207 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1208 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1209 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1212 gfx::Transform rotate;
1213 rotate.Rotate(2);
1215 RenderSurfaceLayerList render_surface_layer_list;
1216 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1217 root.get(), root->bounds(), rotate, &render_surface_layer_list);
1218 inputs.can_adjust_raster_scales = true;
1219 inputs.property_trees->needs_rebuild = true;
1220 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1221 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1222 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1223 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1226 gfx::Transform composite;
1227 composite.ConcatTransform(translate);
1228 composite.ConcatTransform(scale);
1229 composite.ConcatTransform(rotate);
1231 RenderSurfaceLayerList render_surface_layer_list;
1232 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1233 root.get(), root->bounds(), composite, &render_surface_layer_list);
1234 inputs.can_adjust_raster_scales = true;
1235 inputs.property_trees->needs_rebuild = true;
1236 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1237 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1238 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1239 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1242 // Verify it composes correctly with device scale.
1243 float device_scale_factor = 1.5f;
1246 RenderSurfaceLayerList render_surface_layer_list;
1247 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1248 root.get(), root->bounds(), translate, &render_surface_layer_list);
1249 inputs.device_scale_factor = device_scale_factor;
1250 inputs.can_adjust_raster_scales = true;
1251 inputs.property_trees->needs_rebuild = true;
1252 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1253 gfx::Transform device_scaled_translate = translate;
1254 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1255 EXPECT_EQ(device_scaled_translate,
1256 root->draw_properties().target_space_transform);
1257 EXPECT_EQ(device_scaled_translate,
1258 child->draw_properties().target_space_transform);
1259 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1262 // Verify it composes correctly with page scale.
1263 float page_scale_factor = 2.f;
1266 RenderSurfaceLayerList render_surface_layer_list;
1267 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1268 root.get(), root->bounds(), translate, &render_surface_layer_list);
1269 inputs.page_scale_factor = page_scale_factor;
1270 inputs.page_scale_layer = root.get();
1271 inputs.can_adjust_raster_scales = true;
1272 inputs.property_trees->needs_rebuild = true;
1273 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1274 gfx::Transform page_scaled_translate = translate;
1275 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
1276 EXPECT_EQ(page_scaled_translate,
1277 root->draw_properties().target_space_transform);
1278 EXPECT_EQ(page_scaled_translate,
1279 child->draw_properties().target_space_transform);
1280 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1283 // Verify that it composes correctly with transforms directly on root layer.
1284 root->SetTransform(composite);
1287 RenderSurfaceLayerList render_surface_layer_list;
1288 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1289 root.get(), root->bounds(), composite, &render_surface_layer_list);
1290 inputs.can_adjust_raster_scales = true;
1291 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1292 gfx::Transform compositeSquared = composite;
1293 compositeSquared.ConcatTransform(composite);
1294 EXPECT_TRANSFORMATION_MATRIX_EQ(
1295 compositeSquared, root->draw_properties().target_space_transform);
1296 EXPECT_TRANSFORMATION_MATRIX_EQ(
1297 compositeSquared, child->draw_properties().target_space_transform);
1298 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1302 TEST_F(LayerTreeHostCommonTest,
1303 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
1304 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1305 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
1306 scoped_refptr<LayerWithForcedDrawsContent> child =
1307 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1309 host()->SetRootLayer(parent);
1311 const gfx::Transform identity_matrix;
1312 SetLayerPropertiesForTesting(parent.get(),
1313 identity_matrix,
1314 gfx::Point3F(),
1315 gfx::PointF(),
1316 gfx::Size(10, 10),
1317 true,
1318 false);
1319 SetLayerPropertiesForTesting(render_surface1.get(),
1320 identity_matrix,
1321 gfx::Point3F(),
1322 gfx::PointF(),
1323 gfx::Size(10, 10),
1324 true,
1325 false);
1326 SetLayerPropertiesForTesting(child.get(),
1327 identity_matrix,
1328 gfx::Point3F(),
1329 gfx::PointF(30.f, 30.f),
1330 gfx::Size(10, 10),
1331 true,
1332 false);
1334 parent->AddChild(render_surface1);
1335 parent->SetMasksToBounds(true);
1336 render_surface1->AddChild(child);
1337 render_surface1->SetForceRenderSurface(true);
1339 RenderSurfaceLayerList render_surface_layer_list;
1340 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1341 parent.get(),
1342 parent->bounds(),
1343 gfx::Transform(),
1344 &render_surface_layer_list);
1345 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1347 // The child layer's content is entirely outside the parent's clip rect, so
1348 // the intermediate render surface should not be listed here, even if it was
1349 // forced to be created. Render surfaces without children or visible content
1350 // are unexpected at draw time (e.g. we might try to create a content texture
1351 // of size 0).
1352 ASSERT_TRUE(parent->render_surface());
1353 EXPECT_EQ(1U, render_surface_layer_list.size());
1356 TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
1357 LayerImpl* parent = root_layer();
1358 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
1359 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1360 child->SetDrawsContent(true);
1362 const gfx::Transform identity_matrix;
1363 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1364 gfx::PointF(), gfx::Size(10, 10), true, false,
1365 true);
1366 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1367 gfx::PointF(), gfx::Size(10, 10), true, false,
1368 false);
1369 render_surface1->SetOpacity(0.f);
1371 LayerImplList render_surface_layer_list;
1372 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1373 parent, parent->bounds(), &render_surface_layer_list);
1374 inputs.can_adjust_raster_scales = true;
1375 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1377 // Since the layer is transparent, render_surface1->render_surface() should
1378 // not have gotten added anywhere. Also, the drawable content rect should not
1379 // have been extended by the children.
1380 ASSERT_TRUE(parent->render_surface());
1381 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1382 EXPECT_EQ(1U, render_surface_layer_list.size());
1383 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1384 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1387 TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
1388 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1389 scoped_refptr<LayerWithForcedDrawsContent> child =
1390 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1392 host()->SetRootLayer(parent);
1394 const gfx::Transform identity_matrix;
1395 const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode;
1396 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
1397 gfx::PointF(), gfx::Size(10, 10), true, false);
1399 parent->AddChild(child);
1400 child->SetBlendMode(blend_mode);
1402 RenderSurfaceLayerList render_surface_layer_list;
1403 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1404 parent.get(), parent->bounds(), &render_surface_layer_list);
1405 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1407 // Since the child layer has a blend mode other than normal, it should get
1408 // its own render surface. Also, layer's draw_properties should contain the
1409 // default blend mode, since the render surface becomes responsible for
1410 // applying the blend mode.
1411 ASSERT_TRUE(child->render_surface());
1412 EXPECT_EQ(1U, child->render_surface()->layer_list().size());
1413 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_properties().blend_mode);
1416 TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
1417 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1418 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
1419 scoped_refptr<LayerWithForcedDrawsContent> child =
1420 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1421 render_surface1->SetForceRenderSurface(true);
1423 host()->SetRootLayer(parent);
1425 const gfx::Transform identity_matrix;
1426 SetLayerPropertiesForTesting(parent.get(),
1427 identity_matrix,
1428 gfx::Point3F(),
1429 gfx::PointF(),
1430 gfx::Size(10, 10),
1431 true,
1432 false);
1433 SetLayerPropertiesForTesting(render_surface1.get(),
1434 identity_matrix,
1435 gfx::Point3F(),
1436 gfx::PointF(),
1437 gfx::Size(10, 10),
1438 true,
1439 false);
1440 SetLayerPropertiesForTesting(child.get(),
1441 identity_matrix,
1442 gfx::Point3F(),
1443 gfx::PointF(),
1444 gfx::Size(10, 10),
1445 true,
1446 false);
1448 parent->AddChild(render_surface1);
1449 render_surface1->AddChild(child);
1451 // Sanity check before the actual test
1452 EXPECT_FALSE(parent->render_surface());
1453 EXPECT_FALSE(render_surface1->render_surface());
1456 RenderSurfaceLayerList render_surface_layer_list;
1457 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1458 parent.get(), parent->bounds(), &render_surface_layer_list);
1459 inputs.can_adjust_raster_scales = true;
1460 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1462 // The root layer always creates a render surface
1463 EXPECT_TRUE(parent->render_surface());
1464 EXPECT_TRUE(render_surface1->render_surface());
1465 EXPECT_EQ(2U, render_surface_layer_list.size());
1469 RenderSurfaceLayerList render_surface_layer_list;
1470 render_surface1->SetForceRenderSurface(false);
1471 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1472 parent.get(), parent->bounds(), &render_surface_layer_list);
1473 inputs.can_adjust_raster_scales = true;
1474 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1475 EXPECT_TRUE(parent->render_surface());
1476 EXPECT_FALSE(render_surface1->render_surface());
1477 EXPECT_EQ(1U, render_surface_layer_list.size());
1481 TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1482 // Render surfaces act as a flattening point for their subtree, so should
1483 // always flatten the target-to-screen space transform seen by descendants.
1485 scoped_refptr<Layer> root = Layer::Create(layer_settings());
1486 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1487 scoped_refptr<LayerWithForcedDrawsContent> child =
1488 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1489 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1490 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1492 gfx::Transform rotation_about_y_axis;
1493 rotation_about_y_axis.RotateAboutYAxis(30.0);
1494 // Make |parent| have a render surface.
1495 parent->SetOpacity(0.9f);
1497 const gfx::Transform identity_matrix;
1498 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
1499 gfx::PointF(), gfx::Size(100, 100), true, false);
1500 SetLayerPropertiesForTesting(parent.get(), rotation_about_y_axis,
1501 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1502 true, false);
1503 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
1504 gfx::PointF(), gfx::Size(10, 10), true, false);
1505 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
1506 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1507 true, false);
1509 root->AddChild(parent);
1510 parent->AddChild(child);
1511 child->AddChild(grand_child);
1513 grand_child->SetShouldFlattenTransform(false);
1515 host()->SetRootLayer(root);
1517 // Only grand_child should preserve 3d.
1518 EXPECT_TRUE(root->should_flatten_transform());
1519 EXPECT_TRUE(parent->should_flatten_transform());
1520 EXPECT_TRUE(child->should_flatten_transform());
1521 EXPECT_FALSE(grand_child->should_flatten_transform());
1523 gfx::Transform expected_child_draw_transform = identity_matrix;
1524 gfx::Transform expected_grand_child_draw_transform = identity_matrix;
1526 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1527 flattened_rotation_about_y.FlattenTo2d();
1529 ExecuteCalculateDrawProperties(root.get());
1531 EXPECT_TRUE(parent->render_surface());
1532 EXPECT_FALSE(child->render_surface());
1533 EXPECT_FALSE(grand_child->render_surface());
1535 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1536 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1537 grand_child->draw_transform());
1539 // The screen-space transform inherited by |child| and |grand_child| should
1540 // have been flattened at their render target. In particular, the fact that
1541 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1542 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
1543 child->screen_space_transform());
1544 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
1545 grand_child->screen_space_transform());
1548 TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
1549 // The entire subtree of layers that are outside the clip rect should be
1550 // culled away, and should not affect the render_surface_layer_list.
1552 // The test tree is set up as follows:
1553 // - all layers except the leaf_nodes are forced to be a new render surface
1554 // that have something to draw.
1555 // - parent is a large container layer.
1556 // - child has masksToBounds=true to cause clipping.
1557 // - grand_child is positioned outside of the child's bounds
1558 // - great_grand_child is also kept outside child's bounds.
1560 // In this configuration, grand_child and great_grand_child are completely
1561 // outside the clip rect, and they should never get scheduled on the list of
1562 // render surfaces.
1565 const gfx::Transform identity_matrix;
1566 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1567 scoped_refptr<Layer> child = Layer::Create(layer_settings());
1568 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
1569 scoped_refptr<Layer> great_grand_child = Layer::Create(layer_settings());
1570 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1571 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1572 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1573 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1574 parent->AddChild(child);
1575 child->AddChild(grand_child);
1576 grand_child->AddChild(great_grand_child);
1578 host()->SetRootLayer(parent);
1580 // leaf_node1 ensures that parent and child are kept on the
1581 // render_surface_layer_list, even though grand_child and great_grand_child
1582 // should be clipped.
1583 child->AddChild(leaf_node1);
1584 great_grand_child->AddChild(leaf_node2);
1586 SetLayerPropertiesForTesting(parent.get(),
1587 identity_matrix,
1588 gfx::Point3F(),
1589 gfx::PointF(),
1590 gfx::Size(500, 500),
1591 true,
1592 false);
1593 SetLayerPropertiesForTesting(child.get(),
1594 identity_matrix,
1595 gfx::Point3F(),
1596 gfx::PointF(),
1597 gfx::Size(20, 20),
1598 true,
1599 false);
1600 SetLayerPropertiesForTesting(grand_child.get(),
1601 identity_matrix,
1602 gfx::Point3F(),
1603 gfx::PointF(45.f, 45.f),
1604 gfx::Size(10, 10),
1605 true,
1606 false);
1607 SetLayerPropertiesForTesting(great_grand_child.get(),
1608 identity_matrix,
1609 gfx::Point3F(),
1610 gfx::PointF(),
1611 gfx::Size(10, 10),
1612 true,
1613 false);
1614 SetLayerPropertiesForTesting(leaf_node1.get(),
1615 identity_matrix,
1616 gfx::Point3F(),
1617 gfx::PointF(),
1618 gfx::Size(500, 500),
1619 true,
1620 false);
1621 SetLayerPropertiesForTesting(leaf_node2.get(),
1622 identity_matrix,
1623 gfx::Point3F(),
1624 gfx::PointF(),
1625 gfx::Size(20, 20),
1626 true,
1627 false);
1629 child->SetMasksToBounds(true);
1630 child->SetOpacity(0.4f);
1631 child->SetForceRenderSurface(true);
1632 grand_child->SetOpacity(0.5f);
1633 great_grand_child->SetOpacity(0.4f);
1635 RenderSurfaceLayerList render_surface_layer_list;
1636 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1637 parent.get(), parent->bounds(), &render_surface_layer_list);
1638 inputs.can_adjust_raster_scales = true;
1639 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1641 ASSERT_EQ(2U, render_surface_layer_list.size());
1642 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1643 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
1646 TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
1647 // When a render surface has a clip rect, it is used to clip the content rect
1648 // of the surface. When the render surface is animating its transforms, then
1649 // the content rect's position in the clip rect is not defined on the main
1650 // thread, and its content rect should not be clipped.
1652 // The test tree is set up as follows:
1653 // - parent is a container layer that masksToBounds=true to cause clipping.
1654 // - child is a render surface, which has a clip rect set to the bounds of
1655 // the parent.
1656 // - grand_child is a render surface, and the only visible content in child.
1657 // It is positioned outside of the clip rect from parent.
1659 // In this configuration, grand_child should be outside the clipped
1660 // content rect of the child, making grand_child not appear in the
1661 // render_surface_layer_list. However, when we place an animation on the
1662 // child, this clipping should be avoided and we should keep the grand_child
1663 // in the render_surface_layer_list.
1665 const gfx::Transform identity_matrix;
1666 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1667 scoped_refptr<Layer> child = Layer::Create(layer_settings());
1668 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
1669 scoped_refptr<LayerWithForcedDrawsContent> leaf_node =
1670 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1671 parent->AddChild(child);
1672 child->AddChild(grand_child);
1673 grand_child->AddChild(leaf_node);
1675 host()->SetRootLayer(parent);
1677 SetLayerPropertiesForTesting(parent.get(),
1678 identity_matrix,
1679 gfx::Point3F(),
1680 gfx::PointF(),
1681 gfx::Size(100, 100),
1682 true,
1683 false);
1684 SetLayerPropertiesForTesting(child.get(),
1685 identity_matrix,
1686 gfx::Point3F(),
1687 gfx::PointF(),
1688 gfx::Size(20, 20),
1689 true,
1690 false);
1691 SetLayerPropertiesForTesting(grand_child.get(),
1692 identity_matrix,
1693 gfx::Point3F(),
1694 gfx::PointF(200.f, 200.f),
1695 gfx::Size(10, 10),
1696 true,
1697 false);
1698 SetLayerPropertiesForTesting(leaf_node.get(),
1699 identity_matrix,
1700 gfx::Point3F(),
1701 gfx::PointF(),
1702 gfx::Size(10, 10),
1703 true,
1704 false);
1706 parent->SetMasksToBounds(true);
1707 child->SetOpacity(0.4f);
1708 child->SetForceRenderSurface(true);
1709 grand_child->SetOpacity(0.4f);
1710 grand_child->SetForceRenderSurface(true);
1713 RenderSurfaceLayerList render_surface_layer_list;
1714 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1715 parent.get(), parent->bounds(), &render_surface_layer_list);
1716 inputs.can_adjust_raster_scales = true;
1717 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1719 // Without an animation, we should cull child and grand_child from the
1720 // render_surface_layer_list.
1721 ASSERT_EQ(1U, render_surface_layer_list.size());
1722 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1725 // Now put an animating transform on child.
1726 AddAnimatedTransformToController(
1727 child->layer_animation_controller(), 10.0, 30, 0);
1730 RenderSurfaceLayerList render_surface_layer_list;
1731 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1732 parent.get(), parent->bounds(), &render_surface_layer_list);
1733 inputs.can_adjust_raster_scales = true;
1734 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1736 // With an animating transform, we should keep child and grand_child in the
1737 // render_surface_layer_list.
1738 ASSERT_EQ(3U, render_surface_layer_list.size());
1739 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1740 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
1741 EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id());
1745 TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
1746 // Layer's IsClipped() property is set to true when:
1747 // - the layer clips its subtree, e.g. masks to bounds,
1748 // - the layer is clipped by an ancestor that contributes to the same
1749 // render target,
1750 // - a surface is clipped by an ancestor that contributes to the same
1751 // render target.
1753 // In particular, for a layer that owns a render surface:
1754 // - the render surface inherits any clip from ancestors, and does NOT
1755 // pass that clipped status to the layer itself.
1756 // - but if the layer itself masks to bounds, it is considered clipped
1757 // and propagates the clip to the subtree.
1759 const gfx::Transform identity_matrix;
1760 scoped_refptr<Layer> root = Layer::Create(layer_settings());
1761 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1762 scoped_refptr<Layer> child1 = Layer::Create(layer_settings());
1763 scoped_refptr<Layer> child2 = Layer::Create(layer_settings());
1764 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
1765 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1766 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1767 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1768 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1769 root->AddChild(parent);
1770 parent->AddChild(child1);
1771 parent->AddChild(child2);
1772 child1->AddChild(grand_child);
1773 child2->AddChild(leaf_node2);
1774 grand_child->AddChild(leaf_node1);
1776 host()->SetRootLayer(root);
1778 child2->SetForceRenderSurface(true);
1780 SetLayerPropertiesForTesting(root.get(),
1781 identity_matrix,
1782 gfx::Point3F(),
1783 gfx::PointF(),
1784 gfx::Size(100, 100),
1785 true,
1786 false);
1787 SetLayerPropertiesForTesting(parent.get(),
1788 identity_matrix,
1789 gfx::Point3F(),
1790 gfx::PointF(),
1791 gfx::Size(100, 100),
1792 true,
1793 false);
1794 SetLayerPropertiesForTesting(child1.get(),
1795 identity_matrix,
1796 gfx::Point3F(),
1797 gfx::PointF(),
1798 gfx::Size(100, 100),
1799 true,
1800 false);
1801 SetLayerPropertiesForTesting(child2.get(),
1802 identity_matrix,
1803 gfx::Point3F(),
1804 gfx::PointF(),
1805 gfx::Size(100, 100),
1806 true,
1807 false);
1808 SetLayerPropertiesForTesting(grand_child.get(),
1809 identity_matrix,
1810 gfx::Point3F(),
1811 gfx::PointF(),
1812 gfx::Size(100, 100),
1813 true,
1814 false);
1815 SetLayerPropertiesForTesting(leaf_node1.get(),
1816 identity_matrix,
1817 gfx::Point3F(),
1818 gfx::PointF(),
1819 gfx::Size(100, 100),
1820 true,
1821 false);
1822 SetLayerPropertiesForTesting(leaf_node2.get(),
1823 identity_matrix,
1824 gfx::Point3F(),
1825 gfx::PointF(),
1826 gfx::Size(100, 100),
1827 true,
1828 false);
1830 // Case 1: nothing is clipped except the root render surface.
1832 RenderSurfaceLayerList render_surface_layer_list;
1833 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1834 root.get(), parent->bounds(), &render_surface_layer_list);
1835 inputs.can_adjust_raster_scales = true;
1836 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1838 ASSERT_TRUE(root->render_surface());
1839 ASSERT_TRUE(child2->render_surface());
1841 EXPECT_FALSE(root->is_clipped());
1842 EXPECT_TRUE(root->render_surface()->is_clipped());
1843 EXPECT_FALSE(parent->is_clipped());
1844 EXPECT_FALSE(child1->is_clipped());
1845 EXPECT_FALSE(child2->is_clipped());
1846 EXPECT_FALSE(child2->render_surface()->is_clipped());
1847 EXPECT_FALSE(grand_child->is_clipped());
1848 EXPECT_FALSE(leaf_node1->is_clipped());
1849 EXPECT_FALSE(leaf_node2->is_clipped());
1852 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1853 // surface are clipped. But layers that contribute to child2's surface are
1854 // not clipped explicitly because child2's surface already accounts for
1855 // that clip.
1857 RenderSurfaceLayerList render_surface_layer_list;
1858 parent->SetMasksToBounds(true);
1859 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1860 root.get(), parent->bounds(), &render_surface_layer_list);
1861 inputs.can_adjust_raster_scales = true;
1862 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1864 ASSERT_TRUE(root->render_surface());
1865 ASSERT_TRUE(child2->render_surface());
1867 EXPECT_FALSE(root->is_clipped());
1868 EXPECT_TRUE(root->render_surface()->is_clipped());
1869 EXPECT_TRUE(parent->is_clipped());
1870 EXPECT_TRUE(child1->is_clipped());
1871 EXPECT_FALSE(child2->is_clipped());
1872 EXPECT_TRUE(child2->render_surface()->is_clipped());
1873 EXPECT_TRUE(grand_child->is_clipped());
1874 EXPECT_TRUE(leaf_node1->is_clipped());
1875 EXPECT_FALSE(leaf_node2->is_clipped());
1878 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1879 // child2's render surface is not clipped.
1881 RenderSurfaceLayerList render_surface_layer_list;
1882 parent->SetMasksToBounds(false);
1883 child2->SetMasksToBounds(true);
1884 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1885 root.get(), parent->bounds(), &render_surface_layer_list);
1886 inputs.can_adjust_raster_scales = true;
1887 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1889 ASSERT_TRUE(root->render_surface());
1890 ASSERT_TRUE(child2->render_surface());
1892 EXPECT_FALSE(root->is_clipped());
1893 EXPECT_TRUE(root->render_surface()->is_clipped());
1894 EXPECT_FALSE(parent->is_clipped());
1895 EXPECT_FALSE(child1->is_clipped());
1896 EXPECT_TRUE(child2->is_clipped());
1897 EXPECT_FALSE(child2->render_surface()->is_clipped());
1898 EXPECT_FALSE(grand_child->is_clipped());
1899 EXPECT_FALSE(leaf_node1->is_clipped());
1900 EXPECT_TRUE(leaf_node2->is_clipped());
1904 TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
1905 // Verify that layers get the appropriate DrawableContentRect when their
1906 // parent masksToBounds is true.
1908 // grand_child1 - completely inside the region; DrawableContentRect should
1909 // be the layer rect expressed in target space.
1910 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1911 // will be the intersection of layer bounds and the mask region.
1912 // grand_child3 - partially clipped and masksToBounds; the
1913 // DrawableContentRect will still be the intersection of layer bounds and
1914 // the mask region.
1915 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1916 // be empty.
1919 const gfx::Transform identity_matrix;
1920 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1921 scoped_refptr<Layer> child = Layer::Create(layer_settings());
1922 scoped_refptr<Layer> grand_child1 = Layer::Create(layer_settings());
1923 scoped_refptr<Layer> grand_child2 = Layer::Create(layer_settings());
1924 scoped_refptr<Layer> grand_child3 = Layer::Create(layer_settings());
1925 scoped_refptr<Layer> grand_child4 = Layer::Create(layer_settings());
1927 parent->AddChild(child);
1928 child->AddChild(grand_child1);
1929 child->AddChild(grand_child2);
1930 child->AddChild(grand_child3);
1931 child->AddChild(grand_child4);
1933 host()->SetRootLayer(parent);
1935 SetLayerPropertiesForTesting(parent.get(),
1936 identity_matrix,
1937 gfx::Point3F(),
1938 gfx::PointF(),
1939 gfx::Size(500, 500),
1940 true,
1941 false);
1942 SetLayerPropertiesForTesting(child.get(),
1943 identity_matrix,
1944 gfx::Point3F(),
1945 gfx::PointF(),
1946 gfx::Size(20, 20),
1947 true,
1948 false);
1949 SetLayerPropertiesForTesting(grand_child1.get(),
1950 identity_matrix,
1951 gfx::Point3F(),
1952 gfx::PointF(5.f, 5.f),
1953 gfx::Size(10, 10),
1954 true,
1955 false);
1956 SetLayerPropertiesForTesting(grand_child2.get(),
1957 identity_matrix,
1958 gfx::Point3F(),
1959 gfx::PointF(15.f, 15.f),
1960 gfx::Size(10, 10),
1961 true,
1962 false);
1963 SetLayerPropertiesForTesting(grand_child3.get(),
1964 identity_matrix,
1965 gfx::Point3F(),
1966 gfx::PointF(15.f, 15.f),
1967 gfx::Size(10, 10),
1968 true,
1969 false);
1970 SetLayerPropertiesForTesting(grand_child4.get(),
1971 identity_matrix,
1972 gfx::Point3F(),
1973 gfx::PointF(45.f, 45.f),
1974 gfx::Size(10, 10),
1975 true,
1976 false);
1978 child->SetMasksToBounds(true);
1979 grand_child3->SetMasksToBounds(true);
1981 // Force everyone to be a render surface.
1982 child->SetOpacity(0.4f);
1983 grand_child1->SetOpacity(0.5f);
1984 grand_child2->SetOpacity(0.5f);
1985 grand_child3->SetOpacity(0.5f);
1986 grand_child4->SetOpacity(0.5f);
1988 RenderSurfaceLayerList render_surface_layer_list;
1989 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1990 parent.get(), parent->bounds(), &render_surface_layer_list);
1991 inputs.can_adjust_raster_scales = true;
1992 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1994 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
1995 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
1996 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
1997 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2000 TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
2001 // Verify that render surfaces (and their layers) get the appropriate
2002 // clip rects when their parent masksToBounds is true.
2004 // Layers that own render surfaces (at least for now) do not inherit any
2005 // clipping; instead the surface will enforce the clip for the entire subtree.
2006 // They may still have a clip rect of their own layer bounds, however, if
2007 // masksToBounds was true.
2008 const gfx::Transform identity_matrix;
2009 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
2010 scoped_refptr<Layer> child = Layer::Create(layer_settings());
2011 scoped_refptr<Layer> grand_child1 = Layer::Create(layer_settings());
2012 scoped_refptr<Layer> grand_child2 = Layer::Create(layer_settings());
2013 scoped_refptr<Layer> grand_child3 = Layer::Create(layer_settings());
2014 scoped_refptr<Layer> grand_child4 = Layer::Create(layer_settings());
2015 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
2016 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2017 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
2018 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2019 scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 =
2020 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2021 scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 =
2022 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2024 parent->AddChild(child);
2025 child->AddChild(grand_child1);
2026 child->AddChild(grand_child2);
2027 child->AddChild(grand_child3);
2028 child->AddChild(grand_child4);
2030 host()->SetRootLayer(parent);
2032 // the leaf nodes ensure that these grand_children become render surfaces for
2033 // this test.
2034 grand_child1->AddChild(leaf_node1);
2035 grand_child2->AddChild(leaf_node2);
2036 grand_child3->AddChild(leaf_node3);
2037 grand_child4->AddChild(leaf_node4);
2039 SetLayerPropertiesForTesting(parent.get(),
2040 identity_matrix,
2041 gfx::Point3F(),
2042 gfx::PointF(),
2043 gfx::Size(500, 500),
2044 true,
2045 false);
2046 SetLayerPropertiesForTesting(child.get(),
2047 identity_matrix,
2048 gfx::Point3F(),
2049 gfx::PointF(),
2050 gfx::Size(20, 20),
2051 true,
2052 false);
2053 SetLayerPropertiesForTesting(grand_child1.get(),
2054 identity_matrix,
2055 gfx::Point3F(),
2056 gfx::PointF(5.f, 5.f),
2057 gfx::Size(10, 10),
2058 true,
2059 false);
2060 SetLayerPropertiesForTesting(grand_child2.get(),
2061 identity_matrix,
2062 gfx::Point3F(),
2063 gfx::PointF(15.f, 15.f),
2064 gfx::Size(10, 10),
2065 true,
2066 false);
2067 SetLayerPropertiesForTesting(grand_child3.get(),
2068 identity_matrix,
2069 gfx::Point3F(),
2070 gfx::PointF(15.f, 15.f),
2071 gfx::Size(10, 10),
2072 true,
2073 false);
2074 SetLayerPropertiesForTesting(grand_child4.get(),
2075 identity_matrix,
2076 gfx::Point3F(),
2077 gfx::PointF(45.f, 45.f),
2078 gfx::Size(10, 10),
2079 true,
2080 false);
2081 SetLayerPropertiesForTesting(leaf_node1.get(),
2082 identity_matrix,
2083 gfx::Point3F(),
2084 gfx::PointF(),
2085 gfx::Size(10, 10),
2086 true,
2087 false);
2088 SetLayerPropertiesForTesting(leaf_node2.get(),
2089 identity_matrix,
2090 gfx::Point3F(),
2091 gfx::PointF(),
2092 gfx::Size(10, 10),
2093 true,
2094 false);
2095 SetLayerPropertiesForTesting(leaf_node3.get(),
2096 identity_matrix,
2097 gfx::Point3F(),
2098 gfx::PointF(),
2099 gfx::Size(10, 10),
2100 true,
2101 false);
2102 SetLayerPropertiesForTesting(leaf_node4.get(),
2103 identity_matrix,
2104 gfx::Point3F(),
2105 gfx::PointF(),
2106 gfx::Size(10, 10),
2107 true,
2108 false);
2110 child->SetMasksToBounds(true);
2111 grand_child3->SetMasksToBounds(true);
2112 grand_child4->SetMasksToBounds(true);
2114 // Force everyone to be a render surface.
2115 child->SetOpacity(0.4f);
2116 child->SetForceRenderSurface(true);
2117 grand_child1->SetOpacity(0.5f);
2118 grand_child1->SetForceRenderSurface(true);
2119 grand_child2->SetOpacity(0.5f);
2120 grand_child2->SetForceRenderSurface(true);
2121 grand_child3->SetOpacity(0.5f);
2122 grand_child3->SetForceRenderSurface(true);
2123 grand_child4->SetOpacity(0.5f);
2124 grand_child4->SetForceRenderSurface(true);
2126 RenderSurfaceLayerList render_surface_layer_list;
2127 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2128 parent.get(), parent->bounds(), &render_surface_layer_list);
2129 inputs.can_adjust_raster_scales = true;
2130 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
2131 ASSERT_TRUE(grand_child1->render_surface());
2132 ASSERT_TRUE(grand_child2->render_surface());
2133 ASSERT_TRUE(grand_child3->render_surface());
2135 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2136 // masksToBounds.
2137 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2138 grand_child1->render_surface()->clip_rect());
2139 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2140 grand_child2->render_surface()->clip_rect());
2141 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2142 grand_child3->render_surface()->clip_rect());
2145 TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
2146 LayerImpl* parent = root_layer();
2147 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
2148 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
2149 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
2150 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
2151 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
2152 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
2153 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>();
2154 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
2156 grand_child_of_rs1->SetDrawsContent(true);
2157 grand_child_of_rs2->SetDrawsContent(true);
2159 gfx::Transform layer_transform;
2160 layer_transform.Translate(1.0, 1.0);
2162 SetLayerPropertiesForTesting(
2163 parent, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2164 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2165 SetLayerPropertiesForTesting(
2166 render_surface1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2167 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2168 SetLayerPropertiesForTesting(
2169 render_surface2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2170 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2171 SetLayerPropertiesForTesting(
2172 child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2173 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2174 SetLayerPropertiesForTesting(
2175 child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2176 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2177 SetLayerPropertiesForTesting(
2178 child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2179 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2180 SetLayerPropertiesForTesting(
2181 grand_child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2182 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2183 SetLayerPropertiesForTesting(
2184 grand_child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2185 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2186 SetLayerPropertiesForTesting(
2187 grand_child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2188 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2190 // Put an animated opacity on the render surface.
2191 AddOpacityTransitionToController(
2192 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2194 // Also put an animated opacity on a layer without descendants.
2195 AddOpacityTransitionToController(
2196 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2198 // Put a transform animation on the render surface.
2199 AddAnimatedTransformToController(
2200 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2202 // Also put transform animations on grand_child_of_root, and
2203 // grand_child_of_rs2
2204 AddAnimatedTransformToController(
2205 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2206 AddAnimatedTransformToController(
2207 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2209 ExecuteCalculateDrawProperties(parent);
2211 // Only layers that are associated with render surfaces should have an actual
2212 // RenderSurface() value.
2213 ASSERT_TRUE(parent->render_surface());
2214 ASSERT_FALSE(child_of_root->render_surface());
2215 ASSERT_FALSE(grand_child_of_root->render_surface());
2217 ASSERT_TRUE(render_surface1->render_surface());
2218 ASSERT_FALSE(child_of_rs1->render_surface());
2219 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2221 ASSERT_TRUE(render_surface2->render_surface());
2222 ASSERT_FALSE(child_of_rs2->render_surface());
2223 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2225 // Verify all render target accessors
2226 EXPECT_EQ(parent, parent->render_target());
2227 EXPECT_EQ(parent, child_of_root->render_target());
2228 EXPECT_EQ(parent, grand_child_of_root->render_target());
2230 EXPECT_EQ(render_surface1, render_surface1->render_target());
2231 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
2232 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
2234 EXPECT_EQ(render_surface2, render_surface2->render_target());
2235 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
2236 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
2238 // Verify draw_opacity_is_animating values
2239 EXPECT_FALSE(parent->draw_opacity_is_animating());
2240 EXPECT_FALSE(child_of_root->draw_opacity_is_animating());
2241 EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating());
2242 EXPECT_FALSE(render_surface1->draw_opacity_is_animating());
2243 EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating());
2244 EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating());
2245 EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating());
2246 EXPECT_FALSE(render_surface2->draw_opacity_is_animating());
2247 EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating());
2248 EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating());
2249 EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating());
2251 // Verify draw_transform_is_animating values
2252 EXPECT_FALSE(parent->draw_transform_is_animating());
2253 EXPECT_FALSE(child_of_root->draw_transform_is_animating());
2254 EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating());
2255 EXPECT_FALSE(render_surface1->draw_transform_is_animating());
2256 EXPECT_FALSE(render_surface1->render_surface()
2257 ->target_surface_transforms_are_animating());
2258 EXPECT_FALSE(child_of_rs1->draw_transform_is_animating());
2259 EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating());
2260 EXPECT_FALSE(render_surface2->draw_transform_is_animating());
2261 EXPECT_TRUE(render_surface2->render_surface()
2262 ->target_surface_transforms_are_animating());
2263 EXPECT_FALSE(child_of_rs2->draw_transform_is_animating());
2264 EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating());
2266 // Verify screen_space_transform_is_animating values
2267 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2268 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2269 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2270 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
2271 EXPECT_FALSE(render_surface1->render_surface()
2272 ->screen_space_transforms_are_animating());
2273 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2274 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2275 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2276 EXPECT_TRUE(render_surface2->render_surface()
2277 ->screen_space_transforms_are_animating());
2278 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2279 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2281 // Sanity check. If these fail there is probably a bug in the test itself.
2282 // It is expected that we correctly set up transforms so that the y-component
2283 // of the screen-space transform encodes the "depth" of the layer in the tree.
2284 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
2285 EXPECT_FLOAT_EQ(2.0,
2286 child_of_root->screen_space_transform().matrix().get(1, 3));
2287 EXPECT_FLOAT_EQ(
2288 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
2290 EXPECT_FLOAT_EQ(2.0,
2291 render_surface1->screen_space_transform().matrix().get(1, 3));
2292 EXPECT_FLOAT_EQ(3.0,
2293 child_of_rs1->screen_space_transform().matrix().get(1, 3));
2294 EXPECT_FLOAT_EQ(
2295 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
2297 EXPECT_FLOAT_EQ(3.0,
2298 render_surface2->screen_space_transform().matrix().get(1, 3));
2299 EXPECT_FLOAT_EQ(4.0,
2300 child_of_rs2->screen_space_transform().matrix().get(1, 3));
2301 EXPECT_FLOAT_EQ(
2302 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
2305 TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
2306 // Test the calculateVisibleRect() function works correctly for identity
2307 // transforms.
2309 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2310 gfx::Transform layer_to_surface_transform;
2312 // Case 1: Layer is contained within the surface.
2313 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
2314 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
2315 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2316 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2317 EXPECT_EQ(expected, actual);
2319 // Case 2: Layer is outside the surface rect.
2320 layer_content_rect = gfx::Rect(120, 120, 30, 30);
2321 actual = LayerTreeHostCommon::CalculateVisibleRect(
2322 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2323 EXPECT_TRUE(actual.IsEmpty());
2325 // Case 3: Layer is partially overlapping the surface rect.
2326 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2327 expected = gfx::Rect(80, 80, 20, 20);
2328 actual = LayerTreeHostCommon::CalculateVisibleRect(
2329 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2330 EXPECT_EQ(expected, actual);
2333 TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
2334 // Test the calculateVisibleRect() function works correctly for scaling
2335 // transforms.
2337 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2338 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
2339 gfx::Transform layer_to_surface_transform;
2341 // Case 1: Layer is contained within the surface.
2342 layer_to_surface_transform.MakeIdentity();
2343 layer_to_surface_transform.Translate(10.0, 10.0);
2344 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
2345 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2346 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2347 EXPECT_EQ(expected, actual);
2349 // Case 2: Layer is outside the surface rect.
2350 layer_to_surface_transform.MakeIdentity();
2351 layer_to_surface_transform.Translate(120.0, 120.0);
2352 actual = LayerTreeHostCommon::CalculateVisibleRect(
2353 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2354 EXPECT_TRUE(actual.IsEmpty());
2356 // Case 3: Layer is partially overlapping the surface rect.
2357 layer_to_surface_transform.MakeIdentity();
2358 layer_to_surface_transform.Translate(80.0, 80.0);
2359 expected = gfx::Rect(0, 0, 20, 20);
2360 actual = LayerTreeHostCommon::CalculateVisibleRect(
2361 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2362 EXPECT_EQ(expected, actual);
2365 TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
2366 // Test the calculateVisibleRect() function works correctly for rotations
2367 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2368 // should return the g in the layer's space.
2370 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2371 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
2372 gfx::Transform layer_to_surface_transform;
2374 // Case 1: Layer is contained within the surface.
2375 layer_to_surface_transform.MakeIdentity();
2376 layer_to_surface_transform.Translate(50.0, 50.0);
2377 layer_to_surface_transform.Rotate(45.0);
2378 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
2379 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2380 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2381 EXPECT_EQ(expected, actual);
2383 // Case 2: Layer is outside the surface rect.
2384 layer_to_surface_transform.MakeIdentity();
2385 layer_to_surface_transform.Translate(-50.0, 0.0);
2386 layer_to_surface_transform.Rotate(45.0);
2387 actual = LayerTreeHostCommon::CalculateVisibleRect(
2388 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2389 EXPECT_TRUE(actual.IsEmpty());
2391 // Case 3: The layer is rotated about its top-left corner. In surface space,
2392 // the layer is oriented diagonally, with the left half outside of the render
2393 // surface. In this case, the g should still be the entire layer
2394 // (remember the g is computed in layer space); both the top-left
2395 // and bottom-right corners of the layer are still visible.
2396 layer_to_surface_transform.MakeIdentity();
2397 layer_to_surface_transform.Rotate(45.0);
2398 expected = gfx::Rect(0, 0, 30, 30);
2399 actual = LayerTreeHostCommon::CalculateVisibleRect(
2400 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2401 EXPECT_EQ(expected, actual);
2403 // Case 4: The layer is rotated about its top-left corner, and translated
2404 // upwards. In surface space, the layer is oriented diagonally, with only the
2405 // top corner of the surface overlapping the layer. In layer space, the render
2406 // surface overlaps the right side of the layer. The g should be
2407 // the layer's right half.
2408 layer_to_surface_transform.MakeIdentity();
2409 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2410 layer_to_surface_transform.Rotate(45.0);
2411 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
2412 actual = LayerTreeHostCommon::CalculateVisibleRect(
2413 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2414 EXPECT_EQ(expected, actual);
2417 TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
2418 // Test that the calculateVisibleRect() function works correctly for 3d
2419 // transforms.
2421 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2422 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
2423 gfx::Transform layer_to_surface_transform;
2425 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2426 // degrees, should be fully contained in the render surface.
2427 layer_to_surface_transform.MakeIdentity();
2428 layer_to_surface_transform.RotateAboutYAxis(45.0);
2429 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
2430 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2431 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2432 EXPECT_EQ(expected, actual);
2434 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2435 // degrees, but shifted to the side so only the right-half the layer would be
2436 // visible on the surface.
2437 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2438 SkMScalar half_width_of_rotated_layer =
2439 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
2440 layer_to_surface_transform.MakeIdentity();
2441 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
2442 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2443 // edge of the layer.
2444 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
2445 actual = LayerTreeHostCommon::CalculateVisibleRect(
2446 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2447 EXPECT_EQ(expected, actual);
2450 TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
2451 // Test the calculateVisibleRect() function works correctly when the layer has
2452 // a perspective projection onto the target surface.
2454 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2455 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
2456 gfx::Transform layer_to_surface_transform;
2458 // Case 1: Even though the layer is twice as large as the surface, due to
2459 // perspective foreshortening, the layer will fit fully in the surface when
2460 // its translated more than the perspective amount.
2461 layer_to_surface_transform.MakeIdentity();
2463 // The following sequence of transforms applies the perspective about the
2464 // center of the surface.
2465 layer_to_surface_transform.Translate(50.0, 50.0);
2466 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2467 layer_to_surface_transform.Translate(-50.0, -50.0);
2469 // This translate places the layer in front of the surface's projection plane.
2470 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2472 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
2473 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2474 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2475 EXPECT_EQ(expected, actual);
2477 // Case 2: same projection as before, except that the layer is also translated
2478 // to the side, so that only the right half of the layer should be visible.
2480 // Explanation of expected result: The perspective ratio is (z distance
2481 // between layer and camera origin) / (z distance between projection plane and
2482 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2483 // move a layer by translating -50 units in projected surface units (so that
2484 // only half of it is visible), then we would need to translate by (-36 / 9) *
2485 // -50 == -200 in the layer's units.
2486 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
2487 expected = gfx::Rect(gfx::Point(50, -50),
2488 gfx::Size(100, 200)); // The right half of the layer's
2489 // bounding rect.
2490 actual = LayerTreeHostCommon::CalculateVisibleRect(
2491 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2492 EXPECT_EQ(expected, actual);
2495 TEST_F(LayerTreeHostCommonTest,
2496 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
2497 // There is currently no explicit concept of an orthographic projection plane
2498 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2499 // are technically behind the surface in an orthographic world should not be
2500 // clipped when they are flattened to the surface.
2502 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2503 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
2504 gfx::Transform layer_to_surface_transform;
2506 // This sequence of transforms effectively rotates the layer about the y-axis
2507 // at the center of the layer.
2508 layer_to_surface_transform.MakeIdentity();
2509 layer_to_surface_transform.Translate(50.0, 0.0);
2510 layer_to_surface_transform.RotateAboutYAxis(45.0);
2511 layer_to_surface_transform.Translate(-50.0, 0.0);
2513 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
2514 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2515 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2516 EXPECT_EQ(expected, actual);
2519 TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
2520 // Test the calculateVisibleRect() function works correctly when projecting a
2521 // surface onto a layer, but the layer is partially behind the camera (not
2522 // just behind the projection plane). In this case, the cartesian coordinates
2523 // may seem to be valid, but actually they are not. The visible rect needs to
2524 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2525 // converting to cartesian coordinates.
2527 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2528 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
2529 gfx::Transform layer_to_surface_transform;
2531 // The layer is positioned so that the right half of the layer should be in
2532 // front of the camera, while the other half is behind the surface's
2533 // projection plane. The following sequence of transforms applies the
2534 // perspective and rotation about the center of the layer.
2535 layer_to_surface_transform.MakeIdentity();
2536 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2537 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2538 layer_to_surface_transform.RotateAboutYAxis(45.0);
2540 // Sanity check that this transform does indeed cause w < 0 when applying the
2541 // transform, otherwise this code is not testing the intended scenario.
2542 bool clipped;
2543 MathUtil::MapQuad(layer_to_surface_transform,
2544 gfx::QuadF(gfx::RectF(layer_content_rect)),
2545 &clipped);
2546 ASSERT_TRUE(clipped);
2548 int expected_x_position = 0;
2549 int expected_width = 10;
2550 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2551 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2552 EXPECT_EQ(expected_x_position, actual.x());
2553 EXPECT_EQ(expected_width, actual.width());
2556 TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
2557 // To determine visible rect in layer space, there needs to be an
2558 // un-projection from surface space to layer space. When the original
2559 // transform was a perspective projection that was clipped, it returns a rect
2560 // that encloses the clipped bounds. Un-projecting this new rect may require
2561 // clipping again.
2563 // This sequence of transforms causes one corner of the layer to protrude
2564 // across the w = 0 plane, and should be clipped.
2565 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2566 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
2567 gfx::Transform layer_to_surface_transform;
2568 layer_to_surface_transform.MakeIdentity();
2569 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2570 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2571 layer_to_surface_transform.RotateAboutYAxis(45.0);
2572 layer_to_surface_transform.RotateAboutXAxis(80.0);
2574 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2575 // code is not testing the intended scenario.
2576 bool clipped;
2577 gfx::RectF clipped_rect =
2578 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
2579 MathUtil::ProjectQuad(
2580 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2581 ASSERT_TRUE(clipped);
2583 // Only the corner of the layer is not visible on the surface because of being
2584 // clipped. But, the net result of rounding visible region to an axis-aligned
2585 // rect is that the entire layer should still be considered visible.
2586 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
2587 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2588 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2589 EXPECT_EQ(expected, actual);
2592 TEST_F(LayerTreeHostCommonTest,
2593 VisibleRectsForPositionedRootLayerClippedByViewport) {
2594 scoped_refptr<Layer> root =
2595 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2596 host()->SetRootLayer(root);
2598 gfx::Transform identity_matrix;
2599 // Root layer is positioned at (60, 70). The default device viewport size
2600 // is (0, 0, 100x100) in target space. So the root layer's visible rect
2601 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space.
2602 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2603 gfx::PointF(60, 70), gfx::Size(100, 100), true,
2604 false);
2605 ExecuteCalculateDrawProperties(root.get());
2607 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2608 root->render_surface()->DrawableContentRect());
2609 // In target space, not clipped.
2610 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
2611 // In layer space, clipped.
2612 EXPECT_EQ(gfx::Rect(0, 0, 40, 30), root->visible_layer_rect());
2615 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
2616 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2617 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2618 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2619 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2620 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2621 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2622 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2623 root->AddChild(child1);
2624 root->AddChild(child2);
2625 root->AddChild(child3);
2627 host()->SetRootLayer(root);
2629 gfx::Transform identity_matrix;
2630 SetLayerPropertiesForTesting(root.get(),
2631 identity_matrix,
2632 gfx::Point3F(),
2633 gfx::PointF(),
2634 gfx::Size(100, 100),
2635 true,
2636 false);
2637 SetLayerPropertiesForTesting(child1.get(),
2638 identity_matrix,
2639 gfx::Point3F(),
2640 gfx::PointF(),
2641 gfx::Size(50, 50),
2642 true,
2643 false);
2644 SetLayerPropertiesForTesting(child2.get(),
2645 identity_matrix,
2646 gfx::Point3F(),
2647 gfx::PointF(75.f, 75.f),
2648 gfx::Size(50, 50),
2649 true,
2650 false);
2651 SetLayerPropertiesForTesting(child3.get(),
2652 identity_matrix,
2653 gfx::Point3F(),
2654 gfx::PointF(125.f, 125.f),
2655 gfx::Size(50, 50),
2656 true,
2657 false);
2659 ExecuteCalculateDrawProperties(root.get());
2661 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2662 root->render_surface()->DrawableContentRect());
2663 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2665 // Layers that do not draw content should have empty visible_layer_rects.
2666 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2668 // layer visible_layer_rects are clipped by their target surface.
2669 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
2670 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
2671 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty());
2673 // layer drawable_content_rects are not clipped.
2674 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect());
2675 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2676 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2679 TEST_F(LayerTreeHostCommonTest,
2680 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
2681 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2682 scoped_refptr<Layer> child = Layer::Create(layer_settings());
2683 scoped_refptr<LayerWithForcedDrawsContent> grand_child1 =
2684 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2685 scoped_refptr<LayerWithForcedDrawsContent> grand_child2 =
2686 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2687 scoped_refptr<LayerWithForcedDrawsContent> grand_child3 =
2688 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2689 root->AddChild(child);
2690 child->AddChild(grand_child1);
2691 child->AddChild(grand_child2);
2692 child->AddChild(grand_child3);
2694 host()->SetRootLayer(root);
2696 gfx::Transform identity_matrix;
2697 SetLayerPropertiesForTesting(root.get(),
2698 identity_matrix,
2699 gfx::Point3F(),
2700 gfx::PointF(),
2701 gfx::Size(100, 100),
2702 true,
2703 false);
2704 SetLayerPropertiesForTesting(child.get(),
2705 identity_matrix,
2706 gfx::Point3F(),
2707 gfx::PointF(),
2708 gfx::Size(100, 100),
2709 true,
2710 false);
2711 SetLayerPropertiesForTesting(grand_child1.get(),
2712 identity_matrix,
2713 gfx::Point3F(),
2714 gfx::PointF(5.f, 5.f),
2715 gfx::Size(50, 50),
2716 true,
2717 false);
2718 SetLayerPropertiesForTesting(grand_child2.get(),
2719 identity_matrix,
2720 gfx::Point3F(),
2721 gfx::PointF(75.f, 75.f),
2722 gfx::Size(50, 50),
2723 true,
2724 false);
2725 SetLayerPropertiesForTesting(grand_child3.get(),
2726 identity_matrix,
2727 gfx::Point3F(),
2728 gfx::PointF(125.f, 125.f),
2729 gfx::Size(50, 50),
2730 true,
2731 false);
2733 child->SetMasksToBounds(true);
2734 ExecuteCalculateDrawProperties(root.get());
2736 ASSERT_FALSE(child->render_surface());
2738 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2739 root->render_surface()->DrawableContentRect());
2740 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2742 // Layers that do not draw content should have empty visible content rects.
2743 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2744 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect());
2746 // All grandchild visible content rects should be clipped by child.
2747 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect());
2748 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect());
2749 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty());
2751 // All grandchild DrawableContentRects should also be clipped by child.
2752 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
2753 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
2754 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2757 TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
2758 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2759 scoped_refptr<Layer> child = Layer::Create(layer_settings());
2760 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
2761 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2762 root->AddChild(child);
2763 child->AddChild(grand_child);
2765 host()->SetRootLayer(root);
2767 gfx::Transform identity_matrix;
2768 gfx::Transform child_scale_matrix;
2769 child_scale_matrix.Scale(0.25f, 0.25f);
2770 gfx::Transform grand_child_scale_matrix;
2771 grand_child_scale_matrix.Scale(0.246f, 0.246f);
2772 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2773 gfx::PointF(), gfx::Size(100, 100), true, false);
2774 SetLayerPropertiesForTesting(child.get(), child_scale_matrix, gfx::Point3F(),
2775 gfx::PointF(), gfx::Size(10, 10), true, false);
2776 SetLayerPropertiesForTesting(grand_child.get(), grand_child_scale_matrix,
2777 gfx::Point3F(), gfx::PointF(),
2778 gfx::Size(100, 100), true, false);
2780 child->SetMasksToBounds(true);
2781 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
2783 // The visible rect is expanded to integer coordinates in target space before
2784 // being projected back to layer space, where it is once again expanded to
2785 // integer coordinates.
2786 EXPECT_EQ(gfx::Rect(49, 49), grand_child->visible_rect_from_property_trees());
2789 TEST_F(LayerTreeHostCommonTest,
2790 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
2791 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2792 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
2793 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2794 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2795 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2796 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2797 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2798 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2799 root->AddChild(render_surface1);
2800 render_surface1->AddChild(child1);
2801 render_surface1->AddChild(child2);
2802 render_surface1->AddChild(child3);
2804 host()->SetRootLayer(root);
2806 gfx::Transform identity_matrix;
2807 SetLayerPropertiesForTesting(root.get(),
2808 identity_matrix,
2809 gfx::Point3F(),
2810 gfx::PointF(),
2811 gfx::Size(100, 100),
2812 true,
2813 false);
2814 SetLayerPropertiesForTesting(render_surface1.get(),
2815 identity_matrix,
2816 gfx::Point3F(),
2817 gfx::PointF(),
2818 gfx::Size(3, 4),
2819 true,
2820 false);
2821 SetLayerPropertiesForTesting(child1.get(),
2822 identity_matrix,
2823 gfx::Point3F(),
2824 gfx::PointF(5.f, 5.f),
2825 gfx::Size(50, 50),
2826 true,
2827 false);
2828 SetLayerPropertiesForTesting(child2.get(),
2829 identity_matrix,
2830 gfx::Point3F(),
2831 gfx::PointF(75.f, 75.f),
2832 gfx::Size(50, 50),
2833 true,
2834 false);
2835 SetLayerPropertiesForTesting(child3.get(),
2836 identity_matrix,
2837 gfx::Point3F(),
2838 gfx::PointF(125.f, 125.f),
2839 gfx::Size(50, 50),
2840 true,
2841 false);
2843 render_surface1->SetForceRenderSurface(true);
2844 ExecuteCalculateDrawProperties(root.get());
2846 ASSERT_TRUE(render_surface1->render_surface());
2848 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2849 root->render_surface()->DrawableContentRect());
2850 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
2852 // Layers that do not draw content should have empty visible content rects.
2853 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2854 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
2856 // An unclipped surface grows its DrawableContentRect to include all drawable
2857 // regions of the subtree.
2858 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2859 render_surface1->render_surface()->DrawableContentRect());
2861 // All layers that draw content into the unclipped surface are also unclipped.
2862 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
2863 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
2864 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
2866 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2867 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2868 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
2871 TEST_F(LayerTreeHostCommonTest,
2872 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
2873 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2874 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2875 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2876 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2877 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2878 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2879 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2880 root->AddChild(child1);
2881 root->AddChild(child2);
2882 root->AddChild(child3);
2884 host()->SetRootLayer(root);
2886 gfx::Transform identity_matrix;
2887 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2888 gfx::PointF(), gfx::Size(100, 100), true, false);
2889 SetLayerPropertiesForTesting(child1.get(), identity_matrix, gfx::Point3F(),
2890 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2891 false);
2892 SetLayerPropertiesForTesting(child2.get(), identity_matrix, gfx::Point3F(),
2893 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2894 false);
2895 SetLayerPropertiesForTesting(child3.get(), identity_matrix, gfx::Point3F(),
2896 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2897 true, false);
2899 RenderSurfaceLayerList render_surface_layer_list;
2900 // Now set the root render surface an empty clip.
2901 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2902 root.get(), gfx::Size(), &render_surface_layer_list);
2904 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
2905 ASSERT_TRUE(root->render_surface());
2906 EXPECT_FALSE(root->is_clipped());
2908 gfx::Rect empty;
2909 EXPECT_EQ(empty, root->render_surface()->clip_rect());
2910 EXPECT_TRUE(root->render_surface()->is_clipped());
2912 // Visible content rect calculation will check if the target surface is
2913 // clipped or not. An empty clip rect does not indicate the render surface
2914 // is unclipped.
2915 EXPECT_EQ(empty, child1->visible_layer_rect());
2916 EXPECT_EQ(empty, child2->visible_layer_rect());
2917 EXPECT_EQ(empty, child3->visible_layer_rect());
2920 TEST_F(LayerTreeHostCommonTest,
2921 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
2922 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2923 scoped_refptr<LayerWithForcedDrawsContent> child =
2924 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2925 root->AddChild(child);
2927 host()->SetRootLayer(root);
2929 // Case 1: a truly degenerate matrix
2930 gfx::Transform identity_matrix;
2931 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2932 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2934 SetLayerPropertiesForTesting(root.get(),
2935 identity_matrix,
2936 gfx::Point3F(),
2937 gfx::PointF(),
2938 gfx::Size(100, 100),
2939 true,
2940 false);
2941 SetLayerPropertiesForTesting(child.get(),
2942 uninvertible_matrix,
2943 gfx::Point3F(),
2944 gfx::PointF(5.f, 5.f),
2945 gfx::Size(50, 50),
2946 true,
2947 false);
2949 ExecuteCalculateDrawProperties(root.get());
2951 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
2952 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
2954 // Case 2: a matrix with flattened z, uninvertible and not visible according
2955 // to the CSS spec.
2956 uninvertible_matrix.MakeIdentity();
2957 uninvertible_matrix.matrix().set(2, 2, 0.0);
2958 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2960 SetLayerPropertiesForTesting(child.get(),
2961 uninvertible_matrix,
2962 gfx::Point3F(),
2963 gfx::PointF(5.f, 5.f),
2964 gfx::Size(50, 50),
2965 true,
2966 false);
2968 ExecuteCalculateDrawProperties(root.get());
2970 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
2971 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
2973 // Case 3: a matrix with flattened z, also uninvertible and not visible.
2974 uninvertible_matrix.MakeIdentity();
2975 uninvertible_matrix.Translate(500.0, 0.0);
2976 uninvertible_matrix.matrix().set(2, 2, 0.0);
2977 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2979 SetLayerPropertiesForTesting(child.get(),
2980 uninvertible_matrix,
2981 gfx::Point3F(),
2982 gfx::PointF(5.f, 5.f),
2983 gfx::Size(50, 50),
2984 true,
2985 false);
2987 ExecuteCalculateDrawProperties(root.get());
2989 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
2990 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
2993 TEST_F(LayerTreeHostCommonTest,
2994 SingularTransformDoesNotPreventClearingDrawProperties) {
2995 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2996 scoped_refptr<LayerWithForcedDrawsContent> child =
2997 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2998 root->AddChild(child);
3000 host()->SetRootLayer(root);
3002 gfx::Transform identity_matrix;
3003 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3004 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3006 SetLayerPropertiesForTesting(root.get(),
3007 uninvertible_matrix,
3008 gfx::Point3F(),
3009 gfx::PointF(),
3010 gfx::Size(100, 100),
3011 true,
3012 false);
3013 SetLayerPropertiesForTesting(child.get(),
3014 identity_matrix,
3015 gfx::Point3F(),
3016 gfx::PointF(5.f, 5.f),
3017 gfx::Size(50, 50),
3018 true,
3019 false);
3021 child->set_sorted_for_recursion(true);
3023 TransformOperations start_transform_operations;
3024 start_transform_operations.AppendScale(1.f, 0.f, 0.f);
3026 TransformOperations end_transform_operations;
3027 end_transform_operations.AppendScale(1.f, 1.f, 0.f);
3029 AddAnimatedTransformToLayer(
3030 root.get(), 10.0, start_transform_operations, end_transform_operations);
3032 EXPECT_TRUE(root->TransformIsAnimating());
3034 ExecuteCalculateDrawProperties(root.get());
3036 EXPECT_FALSE(child->sorted_for_recursion());
3039 TEST_F(LayerTreeHostCommonTest,
3040 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) {
3041 scoped_refptr<Layer> root = Layer::Create(layer_settings());
3043 host()->SetRootLayer(root);
3045 gfx::Transform identity_matrix;
3046 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3047 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3049 SetLayerPropertiesForTesting(root.get(),
3050 uninvertible_matrix,
3051 gfx::Point3F(),
3052 gfx::PointF(),
3053 gfx::Size(100, 100),
3054 true,
3055 false);
3057 root->set_sorted_for_recursion(true);
3059 EXPECT_FALSE(root->TransformIsAnimating());
3061 ExecuteCalculateDrawProperties(root.get());
3063 EXPECT_FALSE(root->sorted_for_recursion());
3066 TEST_F(LayerTreeHostCommonTest,
3067 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
3068 scoped_refptr<Layer> root = Layer::Create(layer_settings());
3069 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
3070 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3071 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3072 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3073 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3074 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3075 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3076 root->AddChild(render_surface1);
3077 render_surface1->AddChild(child1);
3078 render_surface1->AddChild(child2);
3079 render_surface1->AddChild(child3);
3081 host()->SetRootLayer(root);
3083 gfx::Transform identity_matrix;
3084 SetLayerPropertiesForTesting(root.get(),
3085 identity_matrix,
3086 gfx::Point3F(),
3087 gfx::PointF(),
3088 gfx::Size(100, 100),
3089 true,
3090 false);
3091 SetLayerPropertiesForTesting(render_surface1.get(),
3092 identity_matrix,
3093 gfx::Point3F(),
3094 gfx::PointF(),
3095 gfx::Size(3, 4),
3096 true,
3097 false);
3098 SetLayerPropertiesForTesting(child1.get(),
3099 identity_matrix,
3100 gfx::Point3F(),
3101 gfx::PointF(5.f, 5.f),
3102 gfx::Size(50, 50),
3103 true,
3104 false);
3105 SetLayerPropertiesForTesting(child2.get(),
3106 identity_matrix,
3107 gfx::Point3F(),
3108 gfx::PointF(75.f, 75.f),
3109 gfx::Size(50, 50),
3110 true,
3111 false);
3112 SetLayerPropertiesForTesting(child3.get(),
3113 identity_matrix,
3114 gfx::Point3F(),
3115 gfx::PointF(125.f, 125.f),
3116 gfx::Size(50, 50),
3117 true,
3118 false);
3120 root->SetMasksToBounds(true);
3121 render_surface1->SetForceRenderSurface(true);
3122 ExecuteCalculateDrawProperties(root.get());
3124 ASSERT_TRUE(render_surface1->render_surface());
3126 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3127 root->render_surface()->DrawableContentRect());
3128 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3130 // Layers that do not draw content should have empty visible content rects.
3131 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3132 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
3134 // A clipped surface grows its DrawableContentRect to include all drawable
3135 // regions of the subtree, but also gets clamped by the ancestor's clip.
3136 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3137 render_surface1->render_surface()->DrawableContentRect());
3139 // All layers that draw content into the surface have their visible content
3140 // rect clipped by the surface clip rect.
3141 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3142 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3143 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty());
3145 // But the DrawableContentRects are unclipped.
3146 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3147 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3148 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3151 TEST_F(LayerTreeHostCommonTest,
3152 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
3153 // Check that clipping does not propagate down surfaces.
3154 scoped_refptr<Layer> root = Layer::Create(layer_settings());
3155 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
3156 scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings());
3157 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3158 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3159 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3160 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3161 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3162 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3163 root->AddChild(render_surface1);
3164 render_surface1->AddChild(render_surface2);
3165 render_surface2->AddChild(child1);
3166 render_surface2->AddChild(child2);
3167 render_surface2->AddChild(child3);
3169 host()->SetRootLayer(root);
3171 gfx::Transform identity_matrix;
3172 SetLayerPropertiesForTesting(root.get(),
3173 identity_matrix,
3174 gfx::Point3F(),
3175 gfx::PointF(),
3176 gfx::Size(100, 100),
3177 true,
3178 false);
3179 SetLayerPropertiesForTesting(render_surface1.get(),
3180 identity_matrix,
3181 gfx::Point3F(),
3182 gfx::PointF(),
3183 gfx::Size(3, 4),
3184 true,
3185 false);
3186 SetLayerPropertiesForTesting(render_surface2.get(),
3187 identity_matrix,
3188 gfx::Point3F(),
3189 gfx::PointF(),
3190 gfx::Size(7, 13),
3191 true,
3192 false);
3193 SetLayerPropertiesForTesting(child1.get(),
3194 identity_matrix,
3195 gfx::Point3F(),
3196 gfx::PointF(5.f, 5.f),
3197 gfx::Size(50, 50),
3198 true,
3199 false);
3200 SetLayerPropertiesForTesting(child2.get(),
3201 identity_matrix,
3202 gfx::Point3F(),
3203 gfx::PointF(75.f, 75.f),
3204 gfx::Size(50, 50),
3205 true,
3206 false);
3207 SetLayerPropertiesForTesting(child3.get(),
3208 identity_matrix,
3209 gfx::Point3F(),
3210 gfx::PointF(125.f, 125.f),
3211 gfx::Size(50, 50),
3212 true,
3213 false);
3215 root->SetMasksToBounds(true);
3216 render_surface1->SetForceRenderSurface(true);
3217 render_surface2->SetForceRenderSurface(true);
3218 ExecuteCalculateDrawProperties(root.get());
3220 ASSERT_TRUE(render_surface1->render_surface());
3221 ASSERT_TRUE(render_surface2->render_surface());
3223 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3224 root->render_surface()->DrawableContentRect());
3225 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3227 // Layers that do not draw content should have empty visible content rects.
3228 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3229 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
3230 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect());
3232 // A clipped surface grows its DrawableContentRect to include all drawable
3233 // regions of the subtree, but also gets clamped by the ancestor's clip.
3234 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3235 render_surface1->render_surface()->DrawableContentRect());
3237 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3238 // is only implicitly clipped by render_surface1's content rect. So,
3239 // render_surface2 grows to enclose all drawable content of its subtree.
3240 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
3241 render_surface2->render_surface()->DrawableContentRect());
3243 // All layers that draw content into render_surface2 think they are unclipped.
3244 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3245 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3246 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
3248 // DrawableContentRects are also unclipped.
3249 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3250 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3251 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
3254 TEST_F(LayerTreeHostCommonTest,
3255 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
3256 // Layers that have non-axis aligned bounds (due to transforms) have an
3257 // expanded, axis-aligned DrawableContentRect and visible content rect.
3259 scoped_refptr<Layer> root = Layer::Create(layer_settings());
3260 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
3261 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3262 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3263 root->AddChild(render_surface1);
3264 render_surface1->AddChild(child1);
3266 host()->SetRootLayer(root);
3268 gfx::Transform identity_matrix;
3269 gfx::Transform child_rotation;
3270 child_rotation.Rotate(45.0);
3271 SetLayerPropertiesForTesting(root.get(),
3272 identity_matrix,
3273 gfx::Point3F(),
3274 gfx::PointF(),
3275 gfx::Size(100, 100),
3276 true,
3277 false);
3278 SetLayerPropertiesForTesting(render_surface1.get(),
3279 identity_matrix,
3280 gfx::Point3F(),
3281 gfx::PointF(),
3282 gfx::Size(3, 4),
3283 true,
3284 false);
3285 SetLayerPropertiesForTesting(child1.get(),
3286 child_rotation,
3287 gfx::Point3F(25, 25, 0.f),
3288 gfx::PointF(25.f, 25.f),
3289 gfx::Size(50, 50),
3290 true,
3291 false);
3293 render_surface1->SetForceRenderSurface(true);
3294 ExecuteCalculateDrawProperties(root.get());
3296 ASSERT_TRUE(render_surface1->render_surface());
3298 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3299 root->render_surface()->DrawableContentRect());
3300 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
3302 // Layers that do not draw content should have empty visible content rects.
3303 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3304 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
3306 // The unclipped surface grows its DrawableContentRect to include all drawable
3307 // regions of the subtree.
3308 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3309 gfx::Rect expected_surface_drawable_content =
3310 gfx::Rect(50 - diagonal_radius,
3311 50 - diagonal_radius,
3312 diagonal_radius * 2,
3313 diagonal_radius * 2);
3314 EXPECT_EQ(expected_surface_drawable_content,
3315 render_surface1->render_surface()->DrawableContentRect());
3317 // All layers that draw content into the unclipped surface are also unclipped.
3318 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3319 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
3322 TEST_F(LayerTreeHostCommonTest,
3323 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
3324 // Layers that have non-axis aligned bounds (due to transforms) have an
3325 // expanded, axis-aligned DrawableContentRect and visible content rect.
3327 scoped_refptr<Layer> root = Layer::Create(layer_settings());
3328 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
3329 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3330 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3331 root->AddChild(render_surface1);
3332 render_surface1->AddChild(child1);
3334 host()->SetRootLayer(root);
3336 gfx::Transform identity_matrix;
3337 gfx::Transform child_rotation;
3338 child_rotation.Rotate(45.0);
3339 SetLayerPropertiesForTesting(root.get(),
3340 identity_matrix,
3341 gfx::Point3F(),
3342 gfx::PointF(),
3343 gfx::Size(50, 50),
3344 true,
3345 false);
3346 SetLayerPropertiesForTesting(render_surface1.get(),
3347 identity_matrix,
3348 gfx::Point3F(),
3349 gfx::PointF(),
3350 gfx::Size(3, 4),
3351 true,
3352 false);
3354 SetLayerPropertiesForTesting(child1.get(),
3355 child_rotation,
3356 gfx::Point3F(25, 25, 0.f),
3357 gfx::PointF(25.f, 25.f),
3358 gfx::Size(50, 50),
3359 true,
3360 false);
3362 root->SetMasksToBounds(true);
3363 render_surface1->SetForceRenderSurface(true);
3364 ExecuteCalculateDrawProperties(root.get());
3366 ASSERT_TRUE(render_surface1->render_surface());
3368 // The clipped surface clamps the DrawableContentRect that encloses the
3369 // rotated layer.
3370 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3371 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3372 50 - diagonal_radius,
3373 diagonal_radius * 2,
3374 diagonal_radius * 2);
3375 gfx::Rect expected_surface_drawable_content =
3376 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
3377 EXPECT_EQ(expected_surface_drawable_content,
3378 render_surface1->render_surface()->DrawableContentRect());
3380 // On the clipped surface, only a quarter of the child1 is visible, but when
3381 // rotating it back to child1's content space, the actual enclosing rect ends
3382 // up covering the full left half of child1.
3384 // Given the floating point math, this number is a little bit fuzzy.
3385 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_layer_rect());
3387 // The child's DrawableContentRect is unclipped.
3388 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
3391 TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
3392 MockContentLayerClient client;
3394 scoped_refptr<Layer> root = Layer::Create(layer_settings());
3395 scoped_refptr<FakePictureLayer> render_surface1 =
3396 CreateDrawablePictureLayer(layer_settings(), &client);
3397 scoped_refptr<FakePictureLayer> render_surface2 =
3398 CreateDrawablePictureLayer(layer_settings(), &client);
3399 scoped_refptr<FakePictureLayer> child1 =
3400 CreateDrawablePictureLayer(layer_settings(), &client);
3401 scoped_refptr<FakePictureLayer> child2 =
3402 CreateDrawablePictureLayer(layer_settings(), &client);
3403 scoped_refptr<FakePictureLayer> child3 =
3404 CreateDrawablePictureLayer(layer_settings(), &client);
3405 root->AddChild(render_surface1);
3406 render_surface1->AddChild(render_surface2);
3407 render_surface2->AddChild(child1);
3408 render_surface2->AddChild(child2);
3409 render_surface2->AddChild(child3);
3411 host()->SetRootLayer(root);
3413 gfx::Transform identity_matrix;
3414 SetLayerPropertiesForTesting(root.get(),
3415 identity_matrix,
3416 gfx::Point3F(),
3417 gfx::PointF(),
3418 gfx::Size(100, 100),
3419 true,
3420 false);
3421 SetLayerPropertiesForTesting(render_surface1.get(),
3422 identity_matrix,
3423 gfx::Point3F(),
3424 gfx::PointF(5.f, 5.f),
3425 gfx::Size(3, 4),
3426 true,
3427 false);
3428 SetLayerPropertiesForTesting(render_surface2.get(),
3429 identity_matrix,
3430 gfx::Point3F(),
3431 gfx::PointF(5.f, 5.f),
3432 gfx::Size(7, 13),
3433 true,
3434 false);
3435 SetLayerPropertiesForTesting(child1.get(),
3436 identity_matrix,
3437 gfx::Point3F(),
3438 gfx::PointF(5.f, 5.f),
3439 gfx::Size(50, 50),
3440 true,
3441 false);
3442 SetLayerPropertiesForTesting(child2.get(),
3443 identity_matrix,
3444 gfx::Point3F(),
3445 gfx::PointF(75.f, 75.f),
3446 gfx::Size(50, 50),
3447 true,
3448 false);
3449 SetLayerPropertiesForTesting(child3.get(),
3450 identity_matrix,
3451 gfx::Point3F(),
3452 gfx::PointF(125.f, 125.f),
3453 gfx::Size(50, 50),
3454 true,
3455 false);
3457 float device_scale_factor = 2.f;
3459 root->SetMasksToBounds(true);
3460 render_surface1->SetForceRenderSurface(true);
3461 render_surface2->SetForceRenderSurface(true);
3462 ExecuteCalculateDrawProperties(root.get(), device_scale_factor);
3464 ASSERT_TRUE(render_surface1->render_surface());
3465 ASSERT_TRUE(render_surface2->render_surface());
3467 // drawable_content_rects for all layers and surfaces are scaled by
3468 // device_scale_factor.
3469 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
3470 root->render_surface()->DrawableContentRect());
3471 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3472 EXPECT_EQ(gfx::Rect(10, 10, 190, 190),
3473 render_surface1->render_surface()->DrawableContentRect());
3475 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3476 // is only implicitly clipped by render_surface1.
3477 EXPECT_EQ(gfx::Rect(10, 10, 350, 350),
3478 render_surface2->render_surface()->DrawableContentRect());
3480 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3481 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
3482 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
3484 // The root layer does not actually draw content of its own.
3485 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3487 // All layer visible content rects are not expressed in content space of each
3488 // layer, so they are not scaled by the device_scale_factor.
3489 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect());
3490 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect());
3491 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3492 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3493 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
3496 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
3497 // Verify the behavior of back-face culling when there are no preserve-3d
3498 // layers. Note that 3d transforms still apply in this case, but they are
3499 // "flattened" to each parent layer according to current W3C spec.
3501 const gfx::Transform identity_matrix;
3502 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
3503 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3504 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3505 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3506 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3507 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3508 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3509 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3510 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3511 scoped_refptr<LayerWithForcedDrawsContent>
3512 front_facing_child_of_front_facing_surface =
3513 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3514 scoped_refptr<LayerWithForcedDrawsContent>
3515 back_facing_child_of_front_facing_surface =
3516 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3517 scoped_refptr<LayerWithForcedDrawsContent>
3518 front_facing_child_of_back_facing_surface =
3519 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3520 scoped_refptr<LayerWithForcedDrawsContent>
3521 back_facing_child_of_back_facing_surface =
3522 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3524 parent->AddChild(front_facing_child);
3525 parent->AddChild(back_facing_child);
3526 parent->AddChild(front_facing_surface);
3527 parent->AddChild(back_facing_surface);
3528 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3529 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3530 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3531 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3533 host()->SetRootLayer(parent);
3535 // Nothing is double-sided
3536 front_facing_child->SetDoubleSided(false);
3537 back_facing_child->SetDoubleSided(false);
3538 front_facing_surface->SetDoubleSided(false);
3539 back_facing_surface->SetDoubleSided(false);
3540 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3541 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3542 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3543 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3545 gfx::Transform backface_matrix;
3546 backface_matrix.Translate(50.0, 50.0);
3547 backface_matrix.RotateAboutYAxis(180.0);
3548 backface_matrix.Translate(-50.0, -50.0);
3550 // Having a descendant and opacity will force these to have render surfaces.
3551 front_facing_surface->SetOpacity(0.5f);
3552 back_facing_surface->SetOpacity(0.5f);
3554 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3555 // these layers should blindly use their own local transforms to determine
3556 // back-face culling.
3557 SetLayerPropertiesForTesting(parent.get(),
3558 identity_matrix,
3559 gfx::Point3F(),
3560 gfx::PointF(),
3561 gfx::Size(100, 100),
3562 true,
3563 false);
3564 SetLayerPropertiesForTesting(front_facing_child.get(),
3565 identity_matrix,
3566 gfx::Point3F(),
3567 gfx::PointF(),
3568 gfx::Size(100, 100),
3569 true,
3570 false);
3571 SetLayerPropertiesForTesting(back_facing_child.get(),
3572 backface_matrix,
3573 gfx::Point3F(),
3574 gfx::PointF(),
3575 gfx::Size(100, 100),
3576 true,
3577 false);
3578 SetLayerPropertiesForTesting(front_facing_surface.get(),
3579 identity_matrix,
3580 gfx::Point3F(),
3581 gfx::PointF(),
3582 gfx::Size(100, 100),
3583 true,
3584 false);
3585 SetLayerPropertiesForTesting(back_facing_surface.get(),
3586 backface_matrix,
3587 gfx::Point3F(),
3588 gfx::PointF(),
3589 gfx::Size(100, 100),
3590 true,
3591 false);
3592 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3593 identity_matrix,
3594 gfx::Point3F(),
3595 gfx::PointF(),
3596 gfx::Size(100, 100),
3597 true,
3598 false);
3599 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3600 backface_matrix,
3601 gfx::Point3F(),
3602 gfx::PointF(),
3603 gfx::Size(100, 100),
3604 true,
3605 false);
3606 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3607 identity_matrix,
3608 gfx::Point3F(),
3609 gfx::PointF(),
3610 gfx::Size(100, 100),
3611 true,
3612 false);
3613 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3614 backface_matrix,
3615 gfx::Point3F(),
3616 gfx::PointF(),
3617 gfx::Size(100, 100),
3618 true,
3619 false);
3621 RenderSurfaceLayerList render_surface_layer_list;
3622 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3623 parent.get(), parent->bounds(), &render_surface_layer_list);
3624 inputs.can_adjust_raster_scales = true;
3625 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
3627 // Verify which render surfaces were created.
3628 EXPECT_FALSE(front_facing_child->render_surface());
3629 EXPECT_FALSE(back_facing_child->render_surface());
3630 EXPECT_TRUE(front_facing_surface->render_surface());
3631 EXPECT_TRUE(back_facing_surface->render_surface());
3632 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3633 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3634 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3635 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3637 // Verify the render_surface_layer_list.
3638 ASSERT_EQ(3u, render_surface_layer_list.size());
3639 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3640 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
3641 // Even though the back facing surface LAYER gets culled, the other
3642 // descendants should still be added, so the SURFACE should not be culled.
3643 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id());
3645 // Verify root surface's layer list.
3646 ASSERT_EQ(
3648 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3649 EXPECT_EQ(front_facing_child->id(),
3650 render_surface_layer_list.at(0)
3651 ->render_surface()
3652 ->layer_list()
3653 .at(0)
3654 ->id());
3655 EXPECT_EQ(front_facing_surface->id(),
3656 render_surface_layer_list.at(0)
3657 ->render_surface()
3658 ->layer_list()
3659 .at(1)
3660 ->id());
3661 EXPECT_EQ(back_facing_surface->id(),
3662 render_surface_layer_list.at(0)
3663 ->render_surface()
3664 ->layer_list()
3665 .at(2)
3666 ->id());
3668 // Verify front_facing_surface's layer list.
3669 ASSERT_EQ(
3671 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3672 EXPECT_EQ(front_facing_surface->id(),
3673 render_surface_layer_list.at(1)
3674 ->render_surface()
3675 ->layer_list()
3676 .at(0)
3677 ->id());
3678 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3679 render_surface_layer_list.at(1)
3680 ->render_surface()
3681 ->layer_list()
3682 .at(1)
3683 ->id());
3685 // Verify back_facing_surface's layer list; its own layer should be culled
3686 // from the surface list.
3687 ASSERT_EQ(
3689 render_surface_layer_list.at(2)->render_surface()->layer_list().size());
3690 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
3691 render_surface_layer_list.at(2)
3692 ->render_surface()
3693 ->layer_list()
3694 .at(0)
3695 ->id());
3698 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
3699 // Verify the behavior of back-face culling when preserves-3d transform style
3700 // is used.
3702 const gfx::Transform identity_matrix;
3703 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
3704 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3705 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3706 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3707 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3708 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3709 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3710 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3711 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3712 scoped_refptr<LayerWithForcedDrawsContent>
3713 front_facing_child_of_front_facing_surface =
3714 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3715 scoped_refptr<LayerWithForcedDrawsContent>
3716 back_facing_child_of_front_facing_surface =
3717 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3718 scoped_refptr<LayerWithForcedDrawsContent>
3719 front_facing_child_of_back_facing_surface =
3720 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3721 scoped_refptr<LayerWithForcedDrawsContent>
3722 back_facing_child_of_back_facing_surface =
3723 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3724 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
3725 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3726 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
3727 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3729 parent->AddChild(front_facing_child);
3730 parent->AddChild(back_facing_child);
3731 parent->AddChild(front_facing_surface);
3732 parent->AddChild(back_facing_surface);
3733 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3734 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3735 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3736 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3738 host()->SetRootLayer(parent);
3740 // Nothing is double-sided
3741 front_facing_child->SetDoubleSided(false);
3742 back_facing_child->SetDoubleSided(false);
3743 front_facing_surface->SetDoubleSided(false);
3744 back_facing_surface->SetDoubleSided(false);
3745 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3746 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3747 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3748 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3750 gfx::Transform backface_matrix;
3751 backface_matrix.Translate(50.0, 50.0);
3752 backface_matrix.RotateAboutYAxis(180.0);
3753 backface_matrix.Translate(-50.0, -50.0);
3755 // Opacity will not force creation of render surfaces in this case because of
3756 // the preserve-3d transform style. Instead, an example of when a surface
3757 // would be created with preserve-3d is when there is a replica layer.
3758 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3759 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3761 // Each surface creates its own new 3d rendering context (as defined by W3C
3762 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3763 // rendering context should use the transform with respect to that context.
3764 // This 3d rendering context occurs when (a) parent's transform style is flat
3765 // and (b) the layer's transform style is preserve-3d.
3766 SetLayerPropertiesForTesting(parent.get(),
3767 identity_matrix,
3768 gfx::Point3F(),
3769 gfx::PointF(),
3770 gfx::Size(100, 100),
3771 true,
3772 false); // parent transform style is flat.
3773 SetLayerPropertiesForTesting(front_facing_child.get(),
3774 identity_matrix,
3775 gfx::Point3F(),
3776 gfx::PointF(),
3777 gfx::Size(100, 100),
3778 true,
3779 false);
3780 SetLayerPropertiesForTesting(back_facing_child.get(),
3781 backface_matrix,
3782 gfx::Point3F(),
3783 gfx::PointF(),
3784 gfx::Size(100, 100),
3785 true,
3786 false);
3787 // surface transform style is preserve-3d.
3788 SetLayerPropertiesForTesting(front_facing_surface.get(),
3789 identity_matrix,
3790 gfx::Point3F(),
3791 gfx::PointF(),
3792 gfx::Size(100, 100),
3793 false,
3794 true);
3795 // surface transform style is preserve-3d.
3796 SetLayerPropertiesForTesting(back_facing_surface.get(),
3797 backface_matrix,
3798 gfx::Point3F(),
3799 gfx::PointF(),
3800 gfx::Size(100, 100),
3801 false,
3802 true);
3803 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3804 identity_matrix,
3805 gfx::Point3F(),
3806 gfx::PointF(),
3807 gfx::Size(100, 100),
3808 true,
3809 true);
3810 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3811 backface_matrix,
3812 gfx::Point3F(),
3813 gfx::PointF(),
3814 gfx::Size(100, 100),
3815 true,
3816 true);
3817 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3818 identity_matrix,
3819 gfx::Point3F(),
3820 gfx::PointF(),
3821 gfx::Size(100, 100),
3822 true,
3823 true);
3824 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3825 backface_matrix,
3826 gfx::Point3F(),
3827 gfx::PointF(),
3828 gfx::Size(100, 100),
3829 true,
3830 true);
3832 RenderSurfaceLayerList render_surface_layer_list;
3833 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3834 parent.get(), parent->bounds(), &render_surface_layer_list);
3835 inputs.can_adjust_raster_scales = true;
3836 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
3838 // Verify which render surfaces were created and used.
3839 EXPECT_FALSE(front_facing_child->render_surface());
3840 EXPECT_FALSE(back_facing_child->render_surface());
3841 EXPECT_TRUE(front_facing_surface->render_surface());
3842 EXPECT_NE(back_facing_surface->render_target(), back_facing_surface);
3843 // We expect that a render_surface was created but not used.
3844 EXPECT_TRUE(back_facing_surface->render_surface());
3845 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3846 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3847 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3848 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3850 // Verify the render_surface_layer_list. The back-facing surface should be
3851 // culled.
3852 ASSERT_EQ(2u, render_surface_layer_list.size());
3853 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3854 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
3856 // Verify root surface's layer list.
3857 ASSERT_EQ(
3859 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3860 EXPECT_EQ(front_facing_child->id(),
3861 render_surface_layer_list.at(0)
3862 ->render_surface()->layer_list().at(0)->id());
3863 EXPECT_EQ(front_facing_surface->id(),
3864 render_surface_layer_list.at(0)
3865 ->render_surface()->layer_list().at(1)->id());
3867 // Verify front_facing_surface's layer list.
3868 ASSERT_EQ(
3870 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3871 EXPECT_EQ(front_facing_surface->id(),
3872 render_surface_layer_list.at(1)
3873 ->render_surface()->layer_list().at(0)->id());
3874 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3875 render_surface_layer_list.at(1)
3876 ->render_surface()->layer_list().at(1)->id());
3879 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
3880 // Verify that layers are appropriately culled when their back face is showing
3881 // and they are not double sided, while animations are going on.
3883 // Layers that are animating do not get culled on the main thread, as their
3884 // transforms should be treated as "unknown" so we can not be sure that their
3885 // back face is really showing.
3886 const gfx::Transform identity_matrix;
3887 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
3888 scoped_refptr<LayerWithForcedDrawsContent> child =
3889 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3890 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
3891 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3892 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
3893 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3894 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
3895 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3896 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3897 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3899 parent->AddChild(child);
3900 parent->AddChild(animating_surface);
3901 animating_surface->AddChild(child_of_animating_surface);
3902 parent->AddChild(animating_child);
3903 parent->AddChild(child2);
3905 host()->SetRootLayer(parent);
3907 // Nothing is double-sided
3908 child->SetDoubleSided(false);
3909 child2->SetDoubleSided(false);
3910 animating_surface->SetDoubleSided(false);
3911 child_of_animating_surface->SetDoubleSided(false);
3912 animating_child->SetDoubleSided(false);
3914 gfx::Transform backface_matrix;
3915 backface_matrix.Translate(50.0, 50.0);
3916 backface_matrix.RotateAboutYAxis(180.0);
3917 backface_matrix.Translate(-50.0, -50.0);
3919 // Make our render surface.
3920 animating_surface->SetForceRenderSurface(true);
3922 // Animate the transform on the render surface.
3923 AddAnimatedTransformToController(
3924 animating_surface->layer_animation_controller(), 10.0, 30, 0);
3925 // This is just an animating layer, not a surface.
3926 AddAnimatedTransformToController(
3927 animating_child->layer_animation_controller(), 10.0, 30, 0);
3929 SetLayerPropertiesForTesting(parent.get(),
3930 identity_matrix,
3931 gfx::Point3F(),
3932 gfx::PointF(),
3933 gfx::Size(100, 100),
3934 true,
3935 false);
3936 SetLayerPropertiesForTesting(child.get(),
3937 backface_matrix,
3938 gfx::Point3F(),
3939 gfx::PointF(),
3940 gfx::Size(100, 100),
3941 true,
3942 false);
3943 SetLayerPropertiesForTesting(animating_surface.get(),
3944 backface_matrix,
3945 gfx::Point3F(),
3946 gfx::PointF(),
3947 gfx::Size(100, 100),
3948 true,
3949 false);
3950 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
3951 backface_matrix,
3952 gfx::Point3F(),
3953 gfx::PointF(),
3954 gfx::Size(100, 100),
3955 true,
3956 false);
3957 SetLayerPropertiesForTesting(animating_child.get(),
3958 backface_matrix,
3959 gfx::Point3F(),
3960 gfx::PointF(),
3961 gfx::Size(100, 100),
3962 true,
3963 false);
3964 SetLayerPropertiesForTesting(child2.get(),
3965 identity_matrix,
3966 gfx::Point3F(),
3967 gfx::PointF(),
3968 gfx::Size(100, 100),
3969 true,
3970 false);
3972 RenderSurfaceLayerList render_surface_layer_list;
3973 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3974 parent.get(), parent->bounds(), &render_surface_layer_list);
3975 inputs.can_adjust_raster_scales = true;
3976 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
3978 EXPECT_FALSE(child->render_surface());
3979 EXPECT_TRUE(animating_surface->render_surface());
3980 EXPECT_FALSE(child_of_animating_surface->render_surface());
3981 EXPECT_FALSE(animating_child->render_surface());
3982 EXPECT_FALSE(child2->render_surface());
3984 // Verify that the animating_child and child_of_animating_surface were not
3985 // culled, but that child was.
3986 ASSERT_EQ(2u, render_surface_layer_list.size());
3987 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3988 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
3990 // The non-animating child be culled from the layer list for the parent render
3991 // surface.
3992 ASSERT_EQ(
3994 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3995 EXPECT_EQ(animating_surface->id(),
3996 render_surface_layer_list.at(0)
3997 ->render_surface()->layer_list().at(0)->id());
3998 EXPECT_EQ(animating_child->id(),
3999 render_surface_layer_list.at(0)
4000 ->render_surface()->layer_list().at(1)->id());
4001 EXPECT_EQ(child2->id(),
4002 render_surface_layer_list.at(0)
4003 ->render_surface()->layer_list().at(2)->id());
4005 ASSERT_EQ(
4007 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4008 EXPECT_EQ(animating_surface->id(),
4009 render_surface_layer_list.at(1)
4010 ->render_surface()->layer_list().at(0)->id());
4011 EXPECT_EQ(child_of_animating_surface->id(),
4012 render_surface_layer_list.at(1)
4013 ->render_surface()->layer_list().at(1)->id());
4015 EXPECT_FALSE(child2->visible_layer_rect().IsEmpty());
4017 // The animating layers should have a visible content rect that represents the
4018 // area of the front face that is within the viewport.
4019 EXPECT_EQ(animating_child->visible_layer_rect(),
4020 gfx::Rect(animating_child->bounds()));
4021 EXPECT_EQ(animating_surface->visible_layer_rect(),
4022 gfx::Rect(animating_surface->bounds()));
4023 // And layers in the subtree of the animating layer should have valid visible
4024 // content rects also.
4025 EXPECT_EQ(child_of_animating_surface->visible_layer_rect(),
4026 gfx::Rect(child_of_animating_surface->bounds()));
4029 TEST_F(LayerTreeHostCommonTest,
4030 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4031 // Verify the behavior of back-face culling for a render surface that is
4032 // created when it flattens its subtree, and its parent has preserves-3d.
4034 const gfx::Transform identity_matrix;
4035 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
4036 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
4037 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4038 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
4039 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4040 scoped_refptr<LayerWithForcedDrawsContent> child1 =
4041 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4042 scoped_refptr<LayerWithForcedDrawsContent> child2 =
4043 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4045 parent->AddChild(front_facing_surface);
4046 parent->AddChild(back_facing_surface);
4047 front_facing_surface->AddChild(child1);
4048 back_facing_surface->AddChild(child2);
4050 host()->SetRootLayer(parent);
4052 // RenderSurfaces are not double-sided
4053 front_facing_surface->SetDoubleSided(false);
4054 back_facing_surface->SetDoubleSided(false);
4056 gfx::Transform backface_matrix;
4057 backface_matrix.Translate(50.0, 50.0);
4058 backface_matrix.RotateAboutYAxis(180.0);
4059 backface_matrix.Translate(-50.0, -50.0);
4061 SetLayerPropertiesForTesting(parent.get(),
4062 identity_matrix,
4063 gfx::Point3F(),
4064 gfx::PointF(),
4065 gfx::Size(100, 100),
4066 false,
4067 true); // parent transform style is preserve3d.
4068 SetLayerPropertiesForTesting(front_facing_surface.get(),
4069 identity_matrix,
4070 gfx::Point3F(),
4071 gfx::PointF(),
4072 gfx::Size(100, 100),
4073 true,
4074 true); // surface transform style is flat.
4075 SetLayerPropertiesForTesting(back_facing_surface.get(),
4076 backface_matrix,
4077 gfx::Point3F(),
4078 gfx::PointF(),
4079 gfx::Size(100, 100),
4080 true,
4081 true); // surface transform style is flat.
4082 SetLayerPropertiesForTesting(child1.get(),
4083 identity_matrix,
4084 gfx::Point3F(),
4085 gfx::PointF(),
4086 gfx::Size(100, 100),
4087 true,
4088 false);
4089 SetLayerPropertiesForTesting(child2.get(),
4090 identity_matrix,
4091 gfx::Point3F(),
4092 gfx::PointF(),
4093 gfx::Size(100, 100),
4094 true,
4095 false);
4097 front_facing_surface->Set3dSortingContextId(1);
4098 back_facing_surface->Set3dSortingContextId(1);
4100 RenderSurfaceLayerList render_surface_layer_list;
4101 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4102 parent.get(), parent->bounds(), &render_surface_layer_list);
4103 inputs.can_adjust_raster_scales = true;
4104 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4106 // Verify which render surfaces were created and used.
4107 EXPECT_TRUE(front_facing_surface->render_surface());
4109 // We expect the render surface to have been created, but remain unused.
4110 EXPECT_TRUE(back_facing_surface->render_surface());
4111 EXPECT_NE(back_facing_surface->render_target(),
4112 back_facing_surface); // because it should be culled
4113 EXPECT_FALSE(child1->render_surface());
4114 EXPECT_FALSE(child2->render_surface());
4116 // Verify the render_surface_layer_list. The back-facing surface should be
4117 // culled.
4118 ASSERT_EQ(2u, render_surface_layer_list.size());
4119 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4120 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
4122 // Verify root surface's layer list.
4123 ASSERT_EQ(
4125 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4126 EXPECT_EQ(front_facing_surface->id(),
4127 render_surface_layer_list.at(0)
4128 ->render_surface()->layer_list().at(0)->id());
4130 // Verify front_facing_surface's layer list.
4131 ASSERT_EQ(
4133 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4134 EXPECT_EQ(front_facing_surface->id(),
4135 render_surface_layer_list.at(1)
4136 ->render_surface()->layer_list().at(0)->id());
4137 EXPECT_EQ(child1->id(),
4138 render_surface_layer_list.at(1)
4139 ->render_surface()->layer_list().at(1)->id());
4142 TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
4143 // Verify draw and screen space transforms of layers not in a surface.
4144 gfx::Transform identity_matrix;
4146 LayerImpl* parent = root_layer();
4147 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4148 gfx::PointF(), gfx::Size(100, 100), false, true,
4149 true);
4151 LayerImpl* child = AddChildToRoot<LayerImpl>();
4152 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4153 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4154 true, false);
4156 LayerImpl* child_empty = AddChildToRoot<LayerImpl>();
4157 SetLayerPropertiesForTesting(child_empty, identity_matrix, gfx::Point3F(),
4158 gfx::PointF(2.f, 2.f), gfx::Size(), false, true,
4159 false);
4161 float device_scale_factor = 2.5f;
4162 gfx::Size viewport_size(100, 100);
4163 ExecuteCalculateDrawProperties(parent, device_scale_factor);
4165 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, parent);
4166 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child);
4167 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child_empty);
4169 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
4171 // Verify parent transforms
4172 gfx::Transform expected_parent_transform;
4173 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
4174 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4175 parent->screen_space_transform());
4176 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4177 parent->draw_transform());
4179 // Verify results of transformed parent rects
4180 gfx::RectF parent_bounds(parent->bounds());
4182 gfx::RectF parent_draw_rect =
4183 MathUtil::MapClippedRect(parent->draw_transform(), parent_bounds);
4184 gfx::RectF parent_screen_space_rect =
4185 MathUtil::MapClippedRect(parent->screen_space_transform(), parent_bounds);
4187 gfx::RectF expected_parent_draw_rect(parent->bounds());
4188 expected_parent_draw_rect.Scale(device_scale_factor);
4189 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4190 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
4192 // Verify child and child_empty transforms. They should match.
4193 gfx::Transform expected_child_transform;
4194 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4195 expected_child_transform.Translate(child->position().x(),
4196 child->position().y());
4197 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4198 child->draw_transform());
4199 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4200 child->screen_space_transform());
4201 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4202 child_empty->draw_transform());
4203 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4204 child_empty->screen_space_transform());
4206 // Verify results of transformed child and child_empty rects. They should
4207 // match.
4208 gfx::RectF child_bounds(child->bounds());
4210 gfx::RectF child_draw_rect =
4211 MathUtil::MapClippedRect(child->draw_transform(), child_bounds);
4212 gfx::RectF child_screen_space_rect =
4213 MathUtil::MapClippedRect(child->screen_space_transform(), child_bounds);
4215 gfx::RectF child_empty_draw_rect =
4216 MathUtil::MapClippedRect(child_empty->draw_transform(), child_bounds);
4217 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
4218 child_empty->screen_space_transform(), child_bounds);
4220 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
4221 expected_child_draw_rect.Scale(device_scale_factor);
4222 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4223 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
4224 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
4225 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
4228 TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) {
4229 // Verify draw and screen space transforms of layers in a surface.
4230 gfx::Transform identity_matrix;
4231 gfx::Transform perspective_matrix;
4232 perspective_matrix.ApplyPerspectiveDepth(2.0);
4234 gfx::Transform scale_small_matrix;
4235 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
4237 LayerImpl* root = root_layer();
4238 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4239 gfx::PointF(), gfx::Size(100, 100), false, true,
4240 false);
4241 LayerImpl* parent = AddChildToRoot<LayerImpl>();
4242 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4243 gfx::PointF(), gfx::Size(100, 100), false, true,
4244 false);
4246 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent);
4247 SetLayerPropertiesForTesting(perspective_surface,
4248 perspective_matrix * scale_small_matrix,
4249 gfx::Point3F(), gfx::PointF(2.f, 2.f),
4250 gfx::Size(10, 10), false, true, true);
4251 perspective_surface->SetDrawsContent(true);
4253 LayerImpl* scale_surface = AddChild<LayerImpl>(parent);
4254 SetLayerPropertiesForTesting(scale_surface, scale_small_matrix,
4255 gfx::Point3F(), gfx::PointF(2.f, 2.f),
4256 gfx::Size(10, 10), false, true, true);
4257 scale_surface->SetDrawsContent(true);
4259 float device_scale_factor = 2.5f;
4260 float page_scale_factor = 3.f;
4261 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4262 root);
4264 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4265 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor,
4266 perspective_surface);
4267 // Ideal scale is the max 2d scale component of the combined transform up to
4268 // the nearest render target. Here this includes the layer transform as well
4269 // as the device and page scale factors.
4270 gfx::Transform transform = scale_small_matrix;
4271 transform.Scale(device_scale_factor * page_scale_factor,
4272 device_scale_factor * page_scale_factor);
4273 gfx::Vector2dF scales =
4274 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4275 float max_2d_scale = std::max(scales.x(), scales.y());
4276 EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface);
4278 // The ideal scale will draw 1:1 with its render target space along
4279 // the larger-scale axis.
4280 gfx::Vector2dF target_space_transform_scales =
4281 MathUtil::ComputeTransform2dScaleComponents(
4282 scale_surface->draw_properties().target_space_transform, 0.f);
4283 EXPECT_FLOAT_EQ(max_2d_scale,
4284 std::max(target_space_transform_scales.x(),
4285 target_space_transform_scales.y()));
4287 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
4289 gfx::Transform expected_parent_draw_transform;
4290 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4291 device_scale_factor * page_scale_factor);
4292 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
4293 parent->draw_transform());
4295 // The scale for the perspective surface is not known, so it is rendered 1:1
4296 // with the screen, and then scaled during drawing.
4297 gfx::Transform expected_perspective_surface_draw_transform;
4298 expected_perspective_surface_draw_transform.Translate(
4299 device_scale_factor * page_scale_factor *
4300 perspective_surface->position().x(),
4301 device_scale_factor * page_scale_factor *
4302 perspective_surface->position().y());
4303 expected_perspective_surface_draw_transform.PreconcatTransform(
4304 perspective_matrix);
4305 expected_perspective_surface_draw_transform.PreconcatTransform(
4306 scale_small_matrix);
4307 gfx::Transform expected_perspective_surface_layer_draw_transform;
4308 expected_perspective_surface_layer_draw_transform.Scale(
4309 device_scale_factor * page_scale_factor,
4310 device_scale_factor * page_scale_factor);
4311 EXPECT_TRANSFORMATION_MATRIX_EQ(
4312 expected_perspective_surface_draw_transform,
4313 perspective_surface->render_surface()->draw_transform());
4314 EXPECT_TRANSFORMATION_MATRIX_EQ(
4315 expected_perspective_surface_layer_draw_transform,
4316 perspective_surface->draw_transform());
4319 TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) {
4320 gfx::Transform parent_scale_matrix;
4321 SkMScalar initial_parent_scale = 1.75;
4322 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4324 gfx::Transform child_scale_matrix;
4325 SkMScalar initial_child_scale = 0.25;
4326 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4328 LayerImpl* root = root_layer();
4329 root->SetBounds(gfx::Size(100, 100));
4331 LayerImpl* parent = AddChildToRoot<LayerImpl>();
4332 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
4333 gfx::PointF(), gfx::Size(100, 100), false, true,
4334 false);
4336 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
4337 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
4338 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4339 true, false);
4341 float device_scale_factor = 2.5f;
4342 float page_scale_factor = 0.01f;
4345 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4346 root);
4348 // The ideal scale is able to go below 1.
4349 float expected_ideal_scale =
4350 device_scale_factor * page_scale_factor * initial_parent_scale;
4351 EXPECT_LT(expected_ideal_scale, 1.f);
4352 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent);
4354 expected_ideal_scale = device_scale_factor * page_scale_factor *
4355 initial_parent_scale * initial_child_scale;
4356 EXPECT_LT(expected_ideal_scale, 1.f);
4357 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale);
4361 TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) {
4362 gfx::Transform parent_scale_matrix;
4363 SkMScalar initial_parent_scale = 1.75;
4364 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4366 gfx::Transform child_scale_matrix;
4367 SkMScalar initial_child_scale = 1.25;
4368 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4370 LayerImpl* root = root_layer();
4371 root->SetBounds(gfx::Size(100, 100));
4373 LayerImpl* parent = AddChildToRoot<LayerImpl>();
4374 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
4375 gfx::PointF(), gfx::Size(100, 100), false, true,
4376 false);
4378 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
4379 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
4380 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4381 true, false);
4384 ExecuteCalculateDrawProperties(root);
4386 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent);
4387 // Animating layers compute ideal scale in the same way as when
4388 // they are static.
4389 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale,
4390 child_scale);
4394 TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
4395 MockContentLayerClient delegate;
4396 gfx::Transform identity_matrix;
4398 scoped_refptr<FakePictureLayer> parent =
4399 CreateDrawablePictureLayer(layer_settings(), &delegate);
4400 SetLayerPropertiesForTesting(parent.get(),
4401 identity_matrix,
4402 gfx::Point3F(),
4403 gfx::PointF(),
4404 gfx::Size(30, 30),
4405 false,
4406 true);
4408 scoped_refptr<FakePictureLayer> child =
4409 CreateDrawablePictureLayer(layer_settings(), &delegate);
4410 SetLayerPropertiesForTesting(child.get(),
4411 identity_matrix,
4412 gfx::Point3F(),
4413 gfx::PointF(2.f, 2.f),
4414 gfx::Size(10, 10),
4415 false,
4416 true);
4418 gfx::Transform replica_transform;
4419 replica_transform.Scale(1.0, -1.0);
4420 scoped_refptr<FakePictureLayer> replica =
4421 CreateDrawablePictureLayer(layer_settings(), &delegate);
4422 SetLayerPropertiesForTesting(replica.get(),
4423 replica_transform,
4424 gfx::Point3F(),
4425 gfx::PointF(2.f, 2.f),
4426 gfx::Size(10, 10),
4427 false,
4428 true);
4430 // This layer should end up in the same surface as child, with the same draw
4431 // and screen space transforms.
4432 scoped_refptr<FakePictureLayer> duplicate_child_non_owner =
4433 CreateDrawablePictureLayer(layer_settings(), &delegate);
4434 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
4435 identity_matrix,
4436 gfx::Point3F(),
4437 gfx::PointF(),
4438 gfx::Size(10, 10),
4439 false,
4440 true);
4442 parent->AddChild(child);
4443 child->AddChild(duplicate_child_non_owner);
4444 child->SetReplicaLayer(replica.get());
4446 host()->SetRootLayer(parent);
4448 RenderSurfaceLayerList render_surface_layer_list;
4450 float device_scale_factor = 1.5f;
4451 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4452 parent.get(), parent->bounds(), &render_surface_layer_list);
4453 inputs.device_scale_factor = device_scale_factor;
4454 inputs.can_adjust_raster_scales = true;
4455 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4457 // We should have two render surfaces. The root's render surface and child's
4458 // render surface (it needs one because it has a replica layer).
4459 EXPECT_EQ(2u, render_surface_layer_list.size());
4461 gfx::Transform expected_parent_transform;
4462 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
4463 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4464 parent->screen_space_transform());
4465 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4466 parent->draw_transform());
4468 gfx::Transform expected_draw_transform;
4469 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
4470 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
4471 child->draw_transform());
4473 gfx::Transform expected_screen_space_transform;
4474 expected_screen_space_transform.Scale(device_scale_factor,
4475 device_scale_factor);
4476 expected_screen_space_transform.Translate(child->position().x(),
4477 child->position().y());
4478 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
4479 child->screen_space_transform());
4481 gfx::Transform expected_duplicate_child_draw_transform =
4482 child->draw_transform();
4483 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
4484 duplicate_child_non_owner->draw_transform());
4485 EXPECT_TRANSFORMATION_MATRIX_EQ(
4486 child->screen_space_transform(),
4487 duplicate_child_non_owner->screen_space_transform());
4488 EXPECT_EQ(child->drawable_content_rect(),
4489 duplicate_child_non_owner->drawable_content_rect());
4490 EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds());
4492 gfx::Transform expected_render_surface_draw_transform;
4493 expected_render_surface_draw_transform.Translate(
4494 device_scale_factor * child->position().x(),
4495 device_scale_factor * child->position().y());
4496 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
4497 child->render_surface()->draw_transform());
4499 gfx::Transform expected_surface_draw_transform;
4500 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
4501 device_scale_factor * 2.f);
4502 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
4503 child->render_surface()->draw_transform());
4505 gfx::Transform expected_surface_screen_space_transform;
4506 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
4507 device_scale_factor * 2.f);
4508 EXPECT_TRANSFORMATION_MATRIX_EQ(
4509 expected_surface_screen_space_transform,
4510 child->render_surface()->screen_space_transform());
4512 gfx::Transform expected_replica_draw_transform;
4513 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
4514 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
4515 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
4516 EXPECT_TRANSFORMATION_MATRIX_EQ(
4517 expected_replica_draw_transform,
4518 child->render_surface()->replica_draw_transform());
4520 gfx::Transform expected_replica_screen_space_transform;
4521 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
4522 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
4523 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
4524 EXPECT_TRANSFORMATION_MATRIX_EQ(
4525 expected_replica_screen_space_transform,
4526 child->render_surface()->replica_screen_space_transform());
4527 EXPECT_TRANSFORMATION_MATRIX_EQ(
4528 expected_replica_screen_space_transform,
4529 child->render_surface()->replica_screen_space_transform());
4532 TEST_F(LayerTreeHostCommonTest,
4533 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
4534 MockContentLayerClient delegate;
4535 gfx::Transform identity_matrix;
4537 scoped_refptr<FakePictureLayer> parent =
4538 CreateDrawablePictureLayer(layer_settings(), &delegate);
4539 SetLayerPropertiesForTesting(parent.get(),
4540 identity_matrix,
4541 gfx::Point3F(),
4542 gfx::PointF(),
4543 gfx::Size(33, 31),
4544 false,
4545 true);
4547 scoped_refptr<FakePictureLayer> child =
4548 CreateDrawablePictureLayer(layer_settings(), &delegate);
4549 SetLayerPropertiesForTesting(child.get(),
4550 identity_matrix,
4551 gfx::Point3F(),
4552 gfx::PointF(),
4553 gfx::Size(13, 11),
4554 false,
4555 true);
4557 gfx::Transform replica_transform;
4558 replica_transform.Scale(1.0, -1.0);
4559 scoped_refptr<FakePictureLayer> replica =
4560 CreateDrawablePictureLayer(layer_settings(), &delegate);
4561 SetLayerPropertiesForTesting(replica.get(),
4562 replica_transform,
4563 gfx::Point3F(),
4564 gfx::PointF(),
4565 gfx::Size(13, 11),
4566 false,
4567 true);
4569 parent->AddChild(child);
4570 child->SetReplicaLayer(replica.get());
4572 host()->SetRootLayer(parent);
4574 float device_scale_factor = 1.7f;
4576 RenderSurfaceLayerList render_surface_layer_list;
4577 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4578 parent.get(), parent->bounds(), &render_surface_layer_list);
4579 inputs.device_scale_factor = device_scale_factor;
4580 inputs.can_adjust_raster_scales = true;
4581 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4583 // We should have two render surfaces. The root's render surface and child's
4584 // render surface (it needs one because it has a replica layer).
4585 EXPECT_EQ(2u, render_surface_layer_list.size());
4587 gfx::Transform identity_transform;
4588 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
4589 child->render_surface()->draw_transform());
4590 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
4591 child->render_surface()->draw_transform());
4592 EXPECT_TRANSFORMATION_MATRIX_EQ(
4593 identity_transform, child->render_surface()->screen_space_transform());
4595 gfx::Transform expected_replica_draw_transform;
4596 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
4597 EXPECT_TRANSFORMATION_MATRIX_EQ(
4598 expected_replica_draw_transform,
4599 child->render_surface()->replica_draw_transform());
4601 gfx::Transform expected_replica_screen_space_transform;
4602 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
4603 EXPECT_TRANSFORMATION_MATRIX_EQ(
4604 expected_replica_screen_space_transform,
4605 child->render_surface()->replica_screen_space_transform());
4608 TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
4609 scoped_refptr<Layer> root = Layer::Create(layer_settings());
4610 scoped_refptr<Layer> child = Layer::Create(layer_settings());
4611 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
4612 scoped_refptr<Layer> mask_layer = Layer::Create(layer_settings());
4613 scoped_refptr<Layer> replica_layer = Layer::Create(layer_settings());
4615 grand_child->SetReplicaLayer(replica_layer.get());
4616 child->AddChild(grand_child.get());
4617 child->SetMaskLayer(mask_layer.get());
4618 root->AddChild(child.get());
4620 host()->SetRootLayer(root);
4622 int nonexistent_id = -1;
4623 EXPECT_EQ(root.get(),
4624 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
4625 EXPECT_EQ(child.get(),
4626 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
4627 EXPECT_EQ(
4628 grand_child.get(),
4629 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
4630 EXPECT_EQ(
4631 mask_layer.get(),
4632 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
4633 EXPECT_EQ(
4634 replica_layer.get(),
4635 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
4636 EXPECT_EQ(
4637 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
4640 TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
4641 scoped_refptr<Layer> root = Layer::Create(layer_settings());
4642 scoped_refptr<Layer> child = Layer::Create(layer_settings());
4643 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
4644 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4646 const gfx::Transform identity_matrix;
4647 SetLayerPropertiesForTesting(root.get(),
4648 identity_matrix,
4649 gfx::Point3F(),
4650 gfx::PointF(),
4651 gfx::Size(100, 100),
4652 true,
4653 false);
4654 SetLayerPropertiesForTesting(child.get(),
4655 identity_matrix,
4656 gfx::Point3F(),
4657 gfx::PointF(),
4658 gfx::Size(10, 10),
4659 true,
4660 false);
4661 SetLayerPropertiesForTesting(grand_child.get(),
4662 identity_matrix,
4663 gfx::Point3F(),
4664 gfx::PointF(),
4665 gfx::Size(10, 10),
4666 true,
4667 false);
4669 root->AddChild(child);
4670 child->AddChild(grand_child);
4671 child->SetOpacity(0.5f);
4673 host()->SetRootLayer(root);
4675 ExecuteCalculateDrawProperties(root.get());
4677 EXPECT_FALSE(child->render_surface());
4680 TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
4681 FakeImplProxy proxy;
4682 TestSharedBitmapManager shared_bitmap_manager;
4683 TestTaskGraphRunner task_graph_runner;
4684 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
4685 &task_graph_runner);
4686 host_impl.CreatePendingTree();
4687 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
4689 const gfx::Transform identity_matrix;
4690 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
4691 gfx::PointF(), gfx::Size(100, 100), true, false,
4692 false);
4693 root->SetDrawsContent(true);
4695 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
4696 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
4697 gfx::PointF(), gfx::Size(50, 50), true, false,
4698 false);
4699 child->SetDrawsContent(true);
4700 child->SetOpacity(0.0f);
4702 // Add opacity animation.
4703 AddOpacityTransitionToController(
4704 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
4706 root->AddChild(child.Pass());
4707 root->SetHasRenderSurface(true);
4709 LayerImplList render_surface_layer_list;
4710 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
4711 root.get(), root->bounds(), &render_surface_layer_list);
4712 inputs.can_adjust_raster_scales = true;
4713 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4715 // We should have one render surface and two layers. The child
4716 // layer should be included even though it is transparent.
4717 ASSERT_EQ(1u, render_surface_layer_list.size());
4718 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
4721 using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
4722 class LCDTextTest : public LayerTreeHostCommonTestBase,
4723 public testing::TestWithParam<LCDTextTestParam> {
4724 public:
4725 LCDTextTest()
4726 : LayerTreeHostCommonTestBase(LayerTreeSettings()),
4727 host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_),
4728 root_(nullptr),
4729 child_(nullptr),
4730 grand_child_(nullptr) {}
4732 protected:
4733 void SetUp() override {
4734 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
4735 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
4737 scoped_ptr<LayerImpl> root_ptr =
4738 LayerImpl::Create(host_impl_.active_tree(), 1);
4739 scoped_ptr<LayerImpl> child_ptr =
4740 LayerImpl::Create(host_impl_.active_tree(), 2);
4741 scoped_ptr<LayerImpl> grand_child_ptr =
4742 LayerImpl::Create(host_impl_.active_tree(), 3);
4744 // Stash raw pointers to look at later.
4745 root_ = root_ptr.get();
4746 child_ = child_ptr.get();
4747 grand_child_ = grand_child_ptr.get();
4749 child_->AddChild(grand_child_ptr.Pass());
4750 root_->AddChild(child_ptr.Pass());
4751 host_impl_.active_tree()->SetRootLayer(root_ptr.Pass());
4753 root_->SetContentsOpaque(true);
4754 child_->SetContentsOpaque(true);
4755 grand_child_->SetContentsOpaque(true);
4757 root_->SetDrawsContent(true);
4758 child_->SetDrawsContent(true);
4759 grand_child_->SetDrawsContent(true);
4761 gfx::Transform identity_matrix;
4762 SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(),
4763 gfx::PointF(), gfx::Size(1, 1), true, false,
4764 true);
4765 SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(),
4766 gfx::PointF(), gfx::Size(1, 1), true, false,
4767 std::tr1::get<2>(GetParam()));
4768 SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(),
4769 gfx::PointF(), gfx::Size(1, 1), true, false,
4770 false);
4773 bool can_use_lcd_text_;
4774 bool layers_always_allowed_lcd_text_;
4776 FakeImplProxy proxy_;
4777 TestSharedBitmapManager shared_bitmap_manager_;
4778 TestTaskGraphRunner task_graph_runner_;
4779 FakeLayerTreeHostImpl host_impl_;
4781 LayerImpl* root_;
4782 LayerImpl* child_;
4783 LayerImpl* grand_child_;
4786 TEST_P(LCDTextTest, CanUseLCDText) {
4787 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
4788 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
4790 // Case 1: Identity transform.
4791 gfx::Transform identity_matrix;
4792 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4793 layers_always_allowed_lcd_text_);
4794 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4795 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4796 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4798 // Case 2: Integral translation.
4799 gfx::Transform integral_translation;
4800 integral_translation.Translate(1.0, 2.0);
4801 child_->SetTransform(integral_translation);
4802 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4803 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4804 layers_always_allowed_lcd_text_);
4805 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4806 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4807 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4809 // Case 3: Non-integral translation.
4810 gfx::Transform non_integral_translation;
4811 non_integral_translation.Translate(1.5, 2.5);
4812 child_->SetTransform(non_integral_translation);
4813 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4814 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4815 layers_always_allowed_lcd_text_);
4816 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4817 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4818 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4820 // Case 4: Rotation.
4821 gfx::Transform rotation;
4822 rotation.Rotate(10.0);
4823 child_->SetTransform(rotation);
4824 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4825 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4826 layers_always_allowed_lcd_text_);
4827 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4828 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4829 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4831 // Case 5: Scale.
4832 gfx::Transform scale;
4833 scale.Scale(2.0, 2.0);
4834 child_->SetTransform(scale);
4835 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4836 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4837 layers_always_allowed_lcd_text_);
4838 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4839 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4840 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4842 // Case 6: Skew.
4843 gfx::Transform skew;
4844 skew.SkewX(10.0);
4845 child_->SetTransform(skew);
4846 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4847 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4848 layers_always_allowed_lcd_text_);
4849 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4850 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4851 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4853 // Case 7: Translucent.
4854 child_->SetTransform(identity_matrix);
4855 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4856 child_->SetOpacity(0.5f);
4857 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4858 layers_always_allowed_lcd_text_);
4859 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4860 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4861 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4863 // Case 8: Sanity check: restore transform and opacity.
4864 child_->SetTransform(identity_matrix);
4865 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4866 child_->SetOpacity(1.f);
4867 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4868 layers_always_allowed_lcd_text_);
4869 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4870 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4871 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4873 // Case 9: Non-opaque content.
4874 child_->SetContentsOpaque(false);
4875 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4876 layers_always_allowed_lcd_text_);
4877 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4878 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4879 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4881 // Case 10: Sanity check: restore content opaqueness.
4882 child_->SetContentsOpaque(true);
4883 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4884 layers_always_allowed_lcd_text_);
4885 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4886 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4887 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4890 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
4891 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
4892 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
4894 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
4895 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4896 layers_always_allowed_lcd_text_);
4897 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4898 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4899 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4901 // Add opacity animation.
4902 child_->SetOpacity(0.9f);
4903 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
4904 AddOpacityTransitionToController(
4905 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
4907 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4908 layers_always_allowed_lcd_text_);
4909 // Text LCD should be adjusted while animation is active.
4910 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4911 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4912 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
4915 TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) {
4916 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
4917 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
4919 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
4920 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4921 layers_always_allowed_lcd_text_);
4922 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4923 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
4924 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4926 // Mark contents non-opaque within the first animation frame.
4927 child_->SetContentsOpaque(false);
4928 AddOpacityTransitionToController(child_->layer_animation_controller(), 10.0,
4929 0.9f, 0.1f, false);
4931 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
4932 layers_always_allowed_lcd_text_);
4933 // LCD text should be disabled for non-opaque layers even during animations.
4934 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
4935 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
4936 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
4939 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
4940 LCDTextTest,
4941 testing::Combine(testing::Bool(),
4942 testing::Bool(),
4943 testing::Bool()));
4945 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
4946 FakeImplProxy proxy;
4947 TestSharedBitmapManager shared_bitmap_manager;
4948 TestTaskGraphRunner task_graph_runner;
4949 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
4950 &task_graph_runner);
4951 host_impl.CreatePendingTree();
4952 const gfx::Transform identity_matrix;
4954 scoped_refptr<Layer> root = Layer::Create(layer_settings());
4955 SetLayerPropertiesForTesting(root.get(),
4956 identity_matrix,
4957 gfx::Point3F(),
4958 gfx::PointF(),
4959 gfx::Size(50, 50),
4960 true,
4961 false);
4962 root->SetIsDrawable(true);
4964 scoped_refptr<Layer> child = Layer::Create(layer_settings());
4965 SetLayerPropertiesForTesting(child.get(),
4966 identity_matrix,
4967 gfx::Point3F(),
4968 gfx::PointF(),
4969 gfx::Size(40, 40),
4970 true,
4971 false);
4972 child->SetIsDrawable(true);
4974 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
4975 SetLayerPropertiesForTesting(grand_child.get(),
4976 identity_matrix,
4977 gfx::Point3F(),
4978 gfx::PointF(),
4979 gfx::Size(30, 30),
4980 true,
4981 false);
4982 grand_child->SetIsDrawable(true);
4983 grand_child->SetHideLayerAndSubtree(true);
4985 child->AddChild(grand_child);
4986 root->AddChild(child);
4988 host()->SetRootLayer(root);
4990 RenderSurfaceLayerList render_surface_layer_list;
4991 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4992 root.get(), root->bounds(), &render_surface_layer_list);
4993 inputs.can_adjust_raster_scales = true;
4994 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4996 // We should have one render surface and two layers. The grand child has
4997 // hidden itself.
4998 ASSERT_EQ(1u, render_surface_layer_list.size());
4999 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
5000 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
5001 EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id());
5004 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
5005 FakeImplProxy proxy;
5006 TestSharedBitmapManager shared_bitmap_manager;
5007 TestTaskGraphRunner task_graph_runner;
5008 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
5009 &task_graph_runner);
5010 host_impl.CreatePendingTree();
5011 const gfx::Transform identity_matrix;
5013 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5014 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5015 gfx::PointF(), gfx::Size(50, 50), true, false,
5016 false);
5017 root->SetDrawsContent(true);
5019 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
5020 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5021 gfx::PointF(), gfx::Size(40, 40), true, false,
5022 false);
5023 child->SetDrawsContent(true);
5025 scoped_ptr<LayerImpl> grand_child =
5026 LayerImpl::Create(host_impl.pending_tree(), 3);
5027 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
5028 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5029 true, false, false);
5030 grand_child->SetDrawsContent(true);
5031 grand_child->SetHideLayerAndSubtree(true);
5033 child->AddChild(grand_child.Pass());
5034 root->AddChild(child.Pass());
5035 root->SetHasRenderSurface(true);
5037 LayerImplList render_surface_layer_list;
5038 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5039 root.get(), root->bounds(), &render_surface_layer_list);
5040 inputs.can_adjust_raster_scales = true;
5041 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5043 // We should have one render surface and two layers. The grand child has
5044 // hidden itself.
5045 ASSERT_EQ(1u, render_surface_layer_list.size());
5046 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
5047 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
5048 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
5051 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) {
5052 FakeImplProxy proxy;
5053 TestSharedBitmapManager shared_bitmap_manager;
5054 TestTaskGraphRunner task_graph_runner;
5055 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
5056 &task_graph_runner);
5057 host_impl.CreatePendingTree();
5058 const gfx::Transform identity_matrix;
5060 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5061 SetLayerPropertiesForTesting(root.get(),
5062 identity_matrix,
5063 gfx::Point3F(),
5064 gfx::PointF(),
5065 gfx::Size(50, 50),
5066 true,
5067 false);
5068 root->SetIsDrawable(true);
5070 scoped_refptr<Layer> child = Layer::Create(layer_settings());
5071 SetLayerPropertiesForTesting(child.get(),
5072 identity_matrix,
5073 gfx::Point3F(),
5074 gfx::PointF(),
5075 gfx::Size(40, 40),
5076 true,
5077 false);
5078 child->SetIsDrawable(true);
5079 child->SetHideLayerAndSubtree(true);
5081 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
5082 SetLayerPropertiesForTesting(grand_child.get(),
5083 identity_matrix,
5084 gfx::Point3F(),
5085 gfx::PointF(),
5086 gfx::Size(30, 30),
5087 true,
5088 false);
5089 grand_child->SetIsDrawable(true);
5091 child->AddChild(grand_child);
5092 root->AddChild(child);
5094 host()->SetRootLayer(root);
5096 RenderSurfaceLayerList render_surface_layer_list;
5097 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5098 root.get(), root->bounds(), &render_surface_layer_list);
5099 inputs.can_adjust_raster_scales = true;
5100 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5102 // We should have one render surface and one layers. The child has
5103 // hidden itself and the grand child.
5104 ASSERT_EQ(1u, render_surface_layer_list.size());
5105 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5106 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
5109 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
5110 FakeImplProxy proxy;
5111 TestSharedBitmapManager shared_bitmap_manager;
5112 TestTaskGraphRunner task_graph_runner;
5113 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
5114 &task_graph_runner);
5115 host_impl.CreatePendingTree();
5116 const gfx::Transform identity_matrix;
5118 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5119 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5120 gfx::PointF(), gfx::Size(50, 50), true, false,
5121 true);
5122 root->SetDrawsContent(true);
5124 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
5125 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5126 gfx::PointF(), gfx::Size(40, 40), true, false,
5127 false);
5128 child->SetDrawsContent(true);
5129 child->SetHideLayerAndSubtree(true);
5131 scoped_ptr<LayerImpl> grand_child =
5132 LayerImpl::Create(host_impl.pending_tree(), 3);
5133 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
5134 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5135 true, false, false);
5136 grand_child->SetDrawsContent(true);
5138 child->AddChild(grand_child.Pass());
5139 root->AddChild(child.Pass());
5141 LayerImplList render_surface_layer_list;
5142 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
5143 root.get(), root->bounds(), &render_surface_layer_list);
5144 inputs.can_adjust_raster_scales = true;
5145 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5147 // We should have one render surface and one layers. The child has
5148 // hidden itself and the grand child.
5149 ASSERT_EQ(1u, render_surface_layer_list.size());
5150 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5151 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
5154 void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
5156 TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
5157 FakeImplProxy proxy;
5158 TestSharedBitmapManager shared_bitmap_manager;
5159 TestTaskGraphRunner task_graph_runner;
5160 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
5161 &task_graph_runner);
5162 host_impl.CreatePendingTree();
5163 const gfx::Transform identity_matrix;
5165 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5166 SetLayerPropertiesForTesting(root.get(),
5167 identity_matrix,
5168 gfx::Point3F(),
5169 gfx::PointF(),
5170 gfx::Size(50, 50),
5171 true,
5172 false);
5173 root->SetIsDrawable(true);
5175 scoped_refptr<Layer> copy_grand_parent = Layer::Create(layer_settings());
5176 SetLayerPropertiesForTesting(copy_grand_parent.get(),
5177 identity_matrix,
5178 gfx::Point3F(),
5179 gfx::PointF(),
5180 gfx::Size(40, 40),
5181 true,
5182 false);
5183 copy_grand_parent->SetIsDrawable(true);
5185 scoped_refptr<Layer> copy_parent = Layer::Create(layer_settings());
5186 SetLayerPropertiesForTesting(copy_parent.get(),
5187 identity_matrix,
5188 gfx::Point3F(),
5189 gfx::PointF(),
5190 gfx::Size(30, 30),
5191 true,
5192 false);
5193 copy_parent->SetIsDrawable(true);
5194 copy_parent->SetForceRenderSurface(true);
5196 scoped_refptr<Layer> copy_layer = Layer::Create(layer_settings());
5197 SetLayerPropertiesForTesting(copy_layer.get(),
5198 identity_matrix,
5199 gfx::Point3F(),
5200 gfx::PointF(),
5201 gfx::Size(20, 20),
5202 true,
5203 false);
5204 copy_layer->SetIsDrawable(true);
5206 scoped_refptr<Layer> copy_child = Layer::Create(layer_settings());
5207 SetLayerPropertiesForTesting(copy_child.get(),
5208 identity_matrix,
5209 gfx::Point3F(),
5210 gfx::PointF(),
5211 gfx::Size(20, 20),
5212 true,
5213 false);
5214 copy_child->SetIsDrawable(true);
5216 scoped_refptr<Layer> copy_grand_parent_sibling_before =
5217 Layer::Create(layer_settings());
5218 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
5219 identity_matrix,
5220 gfx::Point3F(),
5221 gfx::PointF(),
5222 gfx::Size(40, 40),
5223 true,
5224 false);
5225 copy_grand_parent_sibling_before->SetIsDrawable(true);
5227 scoped_refptr<Layer> copy_grand_parent_sibling_after =
5228 Layer::Create(layer_settings());
5229 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
5230 identity_matrix,
5231 gfx::Point3F(),
5232 gfx::PointF(),
5233 gfx::Size(40, 40),
5234 true,
5235 false);
5236 copy_grand_parent_sibling_after->SetIsDrawable(true);
5238 copy_layer->AddChild(copy_child);
5239 copy_parent->AddChild(copy_layer);
5240 copy_grand_parent->AddChild(copy_parent);
5241 root->AddChild(copy_grand_parent_sibling_before);
5242 root->AddChild(copy_grand_parent);
5243 root->AddChild(copy_grand_parent_sibling_after);
5245 host()->SetRootLayer(root);
5247 // Hide the copy_grand_parent and its subtree. But make a copy request in that
5248 // hidden subtree on copy_layer.
5249 copy_grand_parent->SetHideLayerAndSubtree(true);
5250 copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true);
5251 copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true);
5252 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
5253 base::Bind(&EmptyCopyOutputCallback)));
5254 EXPECT_TRUE(copy_layer->HasCopyRequest());
5256 RenderSurfaceLayerList render_surface_layer_list;
5257 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5258 root.get(), root->bounds(), &render_surface_layer_list);
5259 inputs.can_adjust_raster_scales = true;
5260 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5262 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
5263 EXPECT_TRUE(copy_grand_parent->draw_properties().
5264 layer_or_descendant_has_copy_request);
5265 EXPECT_TRUE(copy_parent->draw_properties().
5266 layer_or_descendant_has_copy_request);
5267 EXPECT_TRUE(copy_layer->draw_properties().
5268 layer_or_descendant_has_copy_request);
5269 EXPECT_FALSE(copy_child->draw_properties().
5270 layer_or_descendant_has_copy_request);
5271 EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties().
5272 layer_or_descendant_has_copy_request);
5273 EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties().
5274 layer_or_descendant_has_copy_request);
5276 // We should have three render surfaces, one for the root, one for the parent
5277 // since it owns a surface, and one for the copy_layer.
5278 ASSERT_EQ(3u, render_surface_layer_list.size());
5279 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
5280 EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id());
5281 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
5283 // The root render surface should have 2 contributing layers. The
5284 // copy_grand_parent is hidden along with its siblings, but the copy_parent
5285 // will appear since something in its subtree needs to be drawn for a copy
5286 // request.
5287 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
5288 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
5289 EXPECT_EQ(copy_parent->id(),
5290 root->render_surface()->layer_list().at(1)->id());
5292 // Nothing actually draws into the copy parent, so only the copy_layer will
5293 // appear in its list, since it needs to be drawn for the copy request.
5294 ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size());
5295 EXPECT_EQ(copy_layer->id(),
5296 copy_parent->render_surface()->layer_list().at(0)->id());
5298 // The copy_layer's render surface should have two contributing layers.
5299 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
5300 EXPECT_EQ(copy_layer->id(),
5301 copy_layer->render_surface()->layer_list().at(0)->id());
5302 EXPECT_EQ(copy_child->id(),
5303 copy_layer->render_surface()->layer_list().at(1)->id());
5306 TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
5307 FakeImplProxy proxy;
5308 TestSharedBitmapManager shared_bitmap_manager;
5309 TestTaskGraphRunner task_graph_runner;
5310 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
5311 &task_graph_runner);
5312 host_impl.CreatePendingTree();
5313 const gfx::Transform identity_matrix;
5315 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5316 SetLayerPropertiesForTesting(root.get(),
5317 identity_matrix,
5318 gfx::Point3F(),
5319 gfx::PointF(),
5320 gfx::Size(50, 50),
5321 true,
5322 false);
5323 root->SetIsDrawable(true);
5325 scoped_refptr<Layer> copy_parent = Layer::Create(layer_settings());
5326 SetLayerPropertiesForTesting(copy_parent.get(),
5327 identity_matrix,
5328 gfx::Point3F(),
5329 gfx::PointF(),
5330 gfx::Size(),
5331 true,
5332 false);
5333 copy_parent->SetIsDrawable(true);
5334 copy_parent->SetMasksToBounds(true);
5336 scoped_refptr<Layer> copy_layer = Layer::Create(layer_settings());
5337 SetLayerPropertiesForTesting(copy_layer.get(),
5338 identity_matrix,
5339 gfx::Point3F(),
5340 gfx::PointF(),
5341 gfx::Size(30, 30),
5342 true,
5343 false);
5344 copy_layer->SetIsDrawable(true);
5346 scoped_refptr<Layer> copy_child = Layer::Create(layer_settings());
5347 SetLayerPropertiesForTesting(copy_child.get(),
5348 identity_matrix,
5349 gfx::Point3F(),
5350 gfx::PointF(),
5351 gfx::Size(20, 20),
5352 true,
5353 false);
5354 copy_child->SetIsDrawable(true);
5356 copy_layer->AddChild(copy_child);
5357 copy_parent->AddChild(copy_layer);
5358 root->AddChild(copy_parent);
5360 host()->SetRootLayer(root);
5362 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
5363 base::Bind(&EmptyCopyOutputCallback)));
5364 EXPECT_TRUE(copy_layer->HasCopyRequest());
5366 RenderSurfaceLayerList render_surface_layer_list;
5367 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5368 root.get(), root->bounds(), &render_surface_layer_list);
5369 inputs.can_adjust_raster_scales = true;
5370 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5372 // We should have one render surface, as the others are clipped out.
5373 ASSERT_EQ(1u, render_surface_layer_list.size());
5374 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
5376 // The root render surface should only have 1 contributing layer, since the
5377 // other layers are empty/clipped away.
5378 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
5379 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
5382 TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
5383 FakeImplProxy proxy;
5384 TestSharedBitmapManager shared_bitmap_manager;
5385 TestTaskGraphRunner task_graph_runner;
5386 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
5387 &task_graph_runner);
5388 host_impl.CreatePendingTree();
5389 const gfx::Transform identity_matrix;
5391 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5392 SetLayerPropertiesForTesting(root.get(),
5393 identity_matrix,
5394 gfx::Point3F(),
5395 gfx::PointF(),
5396 gfx::Size(50, 50),
5397 true,
5398 false);
5399 root->SetIsDrawable(true);
5401 // The surface is moved slightly outside of the viewport.
5402 scoped_refptr<Layer> surface = Layer::Create(layer_settings());
5403 SetLayerPropertiesForTesting(surface.get(),
5404 identity_matrix,
5405 gfx::Point3F(),
5406 gfx::PointF(-10, -20),
5407 gfx::Size(),
5408 true,
5409 false);
5410 surface->SetForceRenderSurface(true);
5412 scoped_refptr<Layer> surface_child = Layer::Create(layer_settings());
5413 SetLayerPropertiesForTesting(surface_child.get(),
5414 identity_matrix,
5415 gfx::Point3F(),
5416 gfx::PointF(),
5417 gfx::Size(50, 50),
5418 true,
5419 false);
5420 surface_child->SetIsDrawable(true);
5422 surface->AddChild(surface_child);
5423 root->AddChild(surface);
5425 host()->SetRootLayer(root);
5427 RenderSurfaceLayerList render_surface_layer_list;
5428 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5429 root.get(), root->bounds(), &render_surface_layer_list);
5430 inputs.can_adjust_raster_scales = true;
5431 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5433 // The visible_layer_rect for the |surface_child| should not be clipped by
5434 // the viewport.
5435 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
5436 surface_child->visible_layer_rect().ToString());
5439 TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
5440 // Ensure that a transform between the layer and its render surface is not a
5441 // problem. Constructs the following layer tree.
5443 // root (a render surface)
5444 // + render_surface
5445 // + clip_parent (scaled)
5446 // + intervening_clipping_layer
5447 // + clip_child
5449 // The render surface should be resized correctly and the clip child should
5450 // inherit the right clip rect.
5451 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5452 scoped_refptr<Layer> render_surface = Layer::Create(layer_settings());
5453 scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings());
5454 scoped_refptr<Layer> intervening = Layer::Create(layer_settings());
5455 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
5456 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5458 root->AddChild(render_surface);
5459 render_surface->AddChild(clip_parent);
5460 clip_parent->AddChild(intervening);
5461 intervening->AddChild(clip_child);
5463 clip_child->SetClipParent(clip_parent.get());
5465 intervening->SetMasksToBounds(true);
5466 clip_parent->SetMasksToBounds(true);
5468 render_surface->SetForceRenderSurface(true);
5470 gfx::Transform scale_transform;
5471 scale_transform.Scale(2, 2);
5473 gfx::Transform identity_transform;
5475 SetLayerPropertiesForTesting(root.get(),
5476 identity_transform,
5477 gfx::Point3F(),
5478 gfx::PointF(),
5479 gfx::Size(50, 50),
5480 true,
5481 false);
5482 SetLayerPropertiesForTesting(render_surface.get(),
5483 identity_transform,
5484 gfx::Point3F(),
5485 gfx::PointF(),
5486 gfx::Size(10, 10),
5487 true,
5488 false);
5489 SetLayerPropertiesForTesting(clip_parent.get(),
5490 scale_transform,
5491 gfx::Point3F(),
5492 gfx::PointF(1.f, 1.f),
5493 gfx::Size(10, 10),
5494 true,
5495 false);
5496 SetLayerPropertiesForTesting(intervening.get(),
5497 identity_transform,
5498 gfx::Point3F(),
5499 gfx::PointF(1.f, 1.f),
5500 gfx::Size(5, 5),
5501 true,
5502 false);
5503 SetLayerPropertiesForTesting(clip_child.get(),
5504 identity_transform,
5505 gfx::Point3F(),
5506 gfx::PointF(1.f, 1.f),
5507 gfx::Size(10, 10),
5508 true,
5509 false);
5511 host()->SetRootLayer(root);
5513 ExecuteCalculateDrawProperties(root.get());
5515 ASSERT_TRUE(root->render_surface());
5516 ASSERT_TRUE(render_surface->render_surface());
5518 // Ensure that we've inherited our clip parent's clip and weren't affected
5519 // by the intervening clip layer.
5520 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
5521 clip_parent->clip_rect().ToString());
5522 ASSERT_EQ(clip_parent->clip_rect().ToString(),
5523 clip_child->clip_rect().ToString());
5524 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
5525 intervening->clip_rect().ToString());
5527 // Ensure that the render surface reports a content rect that has been grown
5528 // to accomodate for the clip child.
5529 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
5530 render_surface->render_surface()->content_rect().ToString());
5532 // The above check implies the two below, but they nicely demonstrate that
5533 // we've grown, despite the intervening layer's clip.
5534 ASSERT_TRUE(clip_parent->clip_rect().Contains(
5535 render_surface->render_surface()->content_rect()));
5536 ASSERT_FALSE(intervening->clip_rect().Contains(
5537 render_surface->render_surface()->content_rect()));
5540 TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
5541 // Ensure that intervening render surfaces are not a problem in the basic
5542 // case. In the following tree, both render surfaces should be resized to
5543 // accomodate for the clip child, despite an intervening clip.
5545 // root (a render surface)
5546 // + clip_parent (masks to bounds)
5547 // + render_surface1 (sets opacity)
5548 // + intervening (masks to bounds)
5549 // + render_surface2 (also sets opacity)
5550 // + clip_child
5552 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5553 scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings());
5554 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
5555 scoped_refptr<Layer> intervening = Layer::Create(layer_settings());
5556 scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings());
5557 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
5558 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5560 root->AddChild(clip_parent);
5561 clip_parent->AddChild(render_surface1);
5562 render_surface1->AddChild(intervening);
5563 intervening->AddChild(render_surface2);
5564 render_surface2->AddChild(clip_child);
5566 clip_child->SetClipParent(clip_parent.get());
5568 intervening->SetMasksToBounds(true);
5569 clip_parent->SetMasksToBounds(true);
5571 render_surface1->SetForceRenderSurface(true);
5572 render_surface2->SetForceRenderSurface(true);
5574 gfx::Transform translation_transform;
5575 translation_transform.Translate(2, 2);
5577 gfx::Transform identity_transform;
5578 SetLayerPropertiesForTesting(root.get(),
5579 identity_transform,
5580 gfx::Point3F(),
5581 gfx::PointF(),
5582 gfx::Size(50, 50),
5583 true,
5584 false);
5585 SetLayerPropertiesForTesting(clip_parent.get(),
5586 translation_transform,
5587 gfx::Point3F(),
5588 gfx::PointF(1.f, 1.f),
5589 gfx::Size(40, 40),
5590 true,
5591 false);
5592 SetLayerPropertiesForTesting(render_surface1.get(),
5593 identity_transform,
5594 gfx::Point3F(),
5595 gfx::PointF(),
5596 gfx::Size(10, 10),
5597 true,
5598 false);
5599 SetLayerPropertiesForTesting(intervening.get(),
5600 identity_transform,
5601 gfx::Point3F(),
5602 gfx::PointF(1.f, 1.f),
5603 gfx::Size(5, 5),
5604 true,
5605 false);
5606 SetLayerPropertiesForTesting(render_surface2.get(),
5607 identity_transform,
5608 gfx::Point3F(),
5609 gfx::PointF(),
5610 gfx::Size(10, 10),
5611 true,
5612 false);
5613 SetLayerPropertiesForTesting(clip_child.get(),
5614 identity_transform,
5615 gfx::Point3F(),
5616 gfx::PointF(-10.f, -10.f),
5617 gfx::Size(60, 60),
5618 true,
5619 false);
5621 host()->SetRootLayer(root);
5623 ExecuteCalculateDrawProperties(root.get());
5625 EXPECT_TRUE(root->render_surface());
5626 EXPECT_TRUE(render_surface1->render_surface());
5627 EXPECT_TRUE(render_surface2->render_surface());
5629 // Since the render surfaces could have expanded, they should not clip (their
5630 // bounds would no longer be reliable). We should resort to layer clipping
5631 // in this case.
5632 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5633 render_surface1->render_surface()->clip_rect().ToString());
5634 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
5635 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5636 render_surface2->render_surface()->clip_rect().ToString());
5637 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5639 // NB: clip rects are in target space.
5640 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5641 render_surface1->clip_rect().ToString());
5642 EXPECT_TRUE(render_surface1->is_clipped());
5644 // This value is inherited from the clipping ancestor layer, 'intervening'.
5645 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5646 render_surface2->clip_rect().ToString());
5647 EXPECT_TRUE(render_surface2->is_clipped());
5649 // The content rects of both render surfaces should both have expanded to
5650 // contain the clip child.
5651 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5652 render_surface1->render_surface()->content_rect().ToString());
5653 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
5654 render_surface2->render_surface()->content_rect().ToString());
5656 // The clip child should have inherited the clip parent's clip (projected to
5657 // the right space, of course), and should have the correctly sized visible
5658 // content rect.
5659 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
5660 clip_child->clip_rect().ToString());
5661 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
5662 clip_child->visible_layer_rect().ToString());
5663 EXPECT_TRUE(clip_child->is_clipped());
5666 TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
5667 // Ensure that intervening render surfaces are not a problem, even if there
5668 // is a scroll involved. Note, we do _not_ have to consider any other sort
5669 // of transform.
5671 // root (a render surface)
5672 // + clip_parent (masks to bounds)
5673 // + render_surface1 (sets opacity)
5674 // + intervening (masks to bounds AND scrolls)
5675 // + render_surface2 (also sets opacity)
5676 // + clip_child
5678 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5679 scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings());
5680 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
5681 scoped_refptr<Layer> intervening = Layer::Create(layer_settings());
5682 scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings());
5683 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
5684 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5686 root->AddChild(clip_parent);
5687 clip_parent->AddChild(render_surface1);
5688 render_surface1->AddChild(intervening);
5689 intervening->AddChild(render_surface2);
5690 render_surface2->AddChild(clip_child);
5692 clip_child->SetClipParent(clip_parent.get());
5694 intervening->SetMasksToBounds(true);
5695 clip_parent->SetMasksToBounds(true);
5696 intervening->SetScrollClipLayerId(clip_parent->id());
5697 intervening->SetScrollOffset(gfx::ScrollOffset(3, 3));
5699 render_surface1->SetForceRenderSurface(true);
5700 render_surface2->SetForceRenderSurface(true);
5702 gfx::Transform translation_transform;
5703 translation_transform.Translate(2, 2);
5705 gfx::Transform identity_transform;
5706 SetLayerPropertiesForTesting(root.get(),
5707 identity_transform,
5708 gfx::Point3F(),
5709 gfx::PointF(),
5710 gfx::Size(50, 50),
5711 true,
5712 false);
5713 SetLayerPropertiesForTesting(clip_parent.get(),
5714 translation_transform,
5715 gfx::Point3F(),
5716 gfx::PointF(1.f, 1.f),
5717 gfx::Size(40, 40),
5718 true,
5719 false);
5720 SetLayerPropertiesForTesting(render_surface1.get(),
5721 identity_transform,
5722 gfx::Point3F(),
5723 gfx::PointF(),
5724 gfx::Size(10, 10),
5725 true,
5726 false);
5727 SetLayerPropertiesForTesting(intervening.get(),
5728 identity_transform,
5729 gfx::Point3F(),
5730 gfx::PointF(1.f, 1.f),
5731 gfx::Size(5, 5),
5732 true,
5733 false);
5734 SetLayerPropertiesForTesting(render_surface2.get(),
5735 identity_transform,
5736 gfx::Point3F(),
5737 gfx::PointF(),
5738 gfx::Size(10, 10),
5739 true,
5740 false);
5741 SetLayerPropertiesForTesting(clip_child.get(),
5742 identity_transform,
5743 gfx::Point3F(),
5744 gfx::PointF(-10.f, -10.f),
5745 gfx::Size(60, 60),
5746 true,
5747 false);
5749 host()->SetRootLayer(root);
5751 ExecuteCalculateDrawProperties(root.get());
5753 EXPECT_TRUE(root->render_surface());
5754 EXPECT_TRUE(render_surface1->render_surface());
5755 EXPECT_TRUE(render_surface2->render_surface());
5757 // Since the render surfaces could have expanded, they should not clip (their
5758 // bounds would no longer be reliable). We should resort to layer clipping
5759 // in this case.
5760 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5761 render_surface1->render_surface()->clip_rect().ToString());
5762 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
5763 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5764 render_surface2->render_surface()->clip_rect().ToString());
5765 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5767 // NB: clip rects are in target space.
5768 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5769 render_surface1->clip_rect().ToString());
5770 EXPECT_TRUE(render_surface1->is_clipped());
5772 // This value is inherited from the clipping ancestor layer, 'intervening'.
5773 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
5774 render_surface2->clip_rect().ToString());
5775 EXPECT_TRUE(render_surface2->is_clipped());
5777 // The content rects of both render surfaces should both have expanded to
5778 // contain the clip child.
5779 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5780 render_surface1->render_surface()->content_rect().ToString());
5781 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
5782 render_surface2->render_surface()->content_rect().ToString());
5784 // The clip child should have inherited the clip parent's clip (projected to
5785 // the right space, of course), and should have the correctly sized visible
5786 // content rect.
5787 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
5788 clip_child->clip_rect().ToString());
5789 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
5790 clip_child->visible_layer_rect().ToString());
5791 EXPECT_TRUE(clip_child->is_clipped());
5794 TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
5795 // Ensures that descendants of the clip child inherit the correct clip.
5797 // root (a render surface)
5798 // + clip_parent (masks to bounds)
5799 // + intervening (masks to bounds)
5800 // + clip_child
5801 // + child
5803 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5804 scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings());
5805 scoped_refptr<Layer> intervening = Layer::Create(layer_settings());
5806 scoped_refptr<Layer> clip_child = Layer::Create(layer_settings());
5807 scoped_refptr<LayerWithForcedDrawsContent> child =
5808 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5810 root->AddChild(clip_parent);
5811 clip_parent->AddChild(intervening);
5812 intervening->AddChild(clip_child);
5813 clip_child->AddChild(child);
5815 clip_child->SetClipParent(clip_parent.get());
5817 intervening->SetMasksToBounds(true);
5818 clip_parent->SetMasksToBounds(true);
5820 gfx::Transform identity_transform;
5821 SetLayerPropertiesForTesting(root.get(),
5822 identity_transform,
5823 gfx::Point3F(),
5824 gfx::PointF(),
5825 gfx::Size(50, 50),
5826 true,
5827 false);
5828 SetLayerPropertiesForTesting(clip_parent.get(),
5829 identity_transform,
5830 gfx::Point3F(),
5831 gfx::PointF(),
5832 gfx::Size(40, 40),
5833 true,
5834 false);
5835 SetLayerPropertiesForTesting(intervening.get(),
5836 identity_transform,
5837 gfx::Point3F(),
5838 gfx::PointF(),
5839 gfx::Size(5, 5),
5840 true,
5841 false);
5842 SetLayerPropertiesForTesting(clip_child.get(),
5843 identity_transform,
5844 gfx::Point3F(),
5845 gfx::PointF(),
5846 gfx::Size(60, 60),
5847 true,
5848 false);
5849 SetLayerPropertiesForTesting(child.get(),
5850 identity_transform,
5851 gfx::Point3F(),
5852 gfx::PointF(),
5853 gfx::Size(60, 60),
5854 true,
5855 false);
5857 host()->SetRootLayer(root);
5859 ExecuteCalculateDrawProperties(root.get());
5861 EXPECT_TRUE(root->render_surface());
5863 // Neither the clip child nor its descendant should have inherited the clip
5864 // from |intervening|.
5865 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5866 clip_child->clip_rect().ToString());
5867 EXPECT_TRUE(clip_child->is_clipped());
5868 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5869 child->visible_layer_rect().ToString());
5870 EXPECT_TRUE(child->is_clipped());
5873 TEST_F(LayerTreeHostCommonTest,
5874 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
5875 // Ensures that non-descendant clip children in the tree do not affect
5876 // render surfaces.
5878 // root (a render surface)
5879 // + clip_parent (masks to bounds)
5880 // + render_surface1
5881 // + clip_child
5882 // + render_surface2
5883 // + non_clip_child
5885 // In this example render_surface2 should be unaffected by clip_child.
5886 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5887 scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings());
5888 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
5889 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
5890 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5891 scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings());
5892 scoped_refptr<LayerWithForcedDrawsContent> non_clip_child =
5893 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5895 root->AddChild(clip_parent);
5896 clip_parent->AddChild(render_surface1);
5897 render_surface1->AddChild(clip_child);
5898 clip_parent->AddChild(render_surface2);
5899 render_surface2->AddChild(non_clip_child);
5901 clip_child->SetClipParent(clip_parent.get());
5903 clip_parent->SetMasksToBounds(true);
5904 render_surface1->SetMasksToBounds(true);
5906 gfx::Transform identity_transform;
5907 SetLayerPropertiesForTesting(root.get(),
5908 identity_transform,
5909 gfx::Point3F(),
5910 gfx::PointF(),
5911 gfx::Size(15, 15),
5912 true,
5913 false);
5914 SetLayerPropertiesForTesting(clip_parent.get(),
5915 identity_transform,
5916 gfx::Point3F(),
5917 gfx::PointF(),
5918 gfx::Size(10, 10),
5919 true,
5920 false);
5921 SetLayerPropertiesForTesting(render_surface1.get(),
5922 identity_transform,
5923 gfx::Point3F(),
5924 gfx::PointF(5, 5),
5925 gfx::Size(5, 5),
5926 true,
5927 false);
5928 SetLayerPropertiesForTesting(render_surface2.get(),
5929 identity_transform,
5930 gfx::Point3F(),
5931 gfx::PointF(),
5932 gfx::Size(5, 5),
5933 true,
5934 false);
5935 SetLayerPropertiesForTesting(clip_child.get(),
5936 identity_transform,
5937 gfx::Point3F(),
5938 gfx::PointF(-1, 1),
5939 gfx::Size(10, 10),
5940 true,
5941 false);
5942 SetLayerPropertiesForTesting(non_clip_child.get(),
5943 identity_transform,
5944 gfx::Point3F(),
5945 gfx::PointF(),
5946 gfx::Size(5, 5),
5947 true,
5948 false);
5950 render_surface1->SetForceRenderSurface(true);
5951 render_surface2->SetForceRenderSurface(true);
5953 host()->SetRootLayer(root);
5955 ExecuteCalculateDrawProperties(root.get());
5957 EXPECT_TRUE(root->render_surface());
5958 EXPECT_TRUE(render_surface1->render_surface());
5959 EXPECT_TRUE(render_surface2->render_surface());
5961 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5962 render_surface1->clip_rect().ToString());
5963 EXPECT_TRUE(render_surface1->is_clipped());
5965 // The render surface should not clip (it has unclipped descendants), instead
5966 // it should rely on layer clipping.
5967 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5968 render_surface1->render_surface()->clip_rect().ToString());
5969 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
5971 // That said, it should have grown to accomodate the unclipped descendant.
5972 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
5973 render_surface1->render_surface()->content_rect().ToString());
5975 // This render surface should clip. It has no unclipped descendants.
5976 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5977 render_surface2->clip_rect().ToString());
5978 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
5980 // It also shouldn't have grown to accomodate the clip child.
5981 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5982 render_surface2->render_surface()->content_rect().ToString());
5984 // Sanity check our num_unclipped_descendants values.
5985 EXPECT_EQ(1u, render_surface1->num_unclipped_descendants());
5986 EXPECT_EQ(0u, render_surface2->num_unclipped_descendants());
5989 TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
5990 FakeImplProxy proxy;
5991 TestSharedBitmapManager shared_bitmap_manager;
5992 TestTaskGraphRunner task_graph_runner;
5993 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
5994 &task_graph_runner);
5995 scoped_ptr<LayerImpl> root =
5996 LayerImpl::Create(host_impl.active_tree(), 12345);
5997 scoped_ptr<LayerImpl> child1 =
5998 LayerImpl::Create(host_impl.active_tree(), 123456);
5999 scoped_ptr<LayerImpl> child2 =
6000 LayerImpl::Create(host_impl.active_tree(), 1234567);
6001 scoped_ptr<LayerImpl> child3 =
6002 LayerImpl::Create(host_impl.active_tree(), 12345678);
6004 gfx::Transform identity_matrix;
6005 gfx::Point3F transform_origin;
6006 gfx::PointF position;
6007 gfx::Size bounds(100, 100);
6008 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
6009 position, bounds, true, false, true);
6010 root->SetDrawsContent(true);
6012 // This layer structure normally forces render surface due to preserves3d
6013 // behavior.
6014 SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin,
6015 position, bounds, false, true, true);
6016 child1->SetDrawsContent(true);
6017 SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin,
6018 position, bounds, true, false, false);
6019 child2->SetDrawsContent(true);
6020 SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin,
6021 position, bounds, true, false, false);
6022 child3->SetDrawsContent(true);
6024 child2->Set3dSortingContextId(1);
6025 child3->Set3dSortingContextId(1);
6027 child2->AddChild(child3.Pass());
6028 child1->AddChild(child2.Pass());
6029 root->AddChild(child1.Pass());
6032 LayerImplList render_surface_layer_list;
6033 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get());
6034 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6035 root.get(), root->bounds(), &render_surface_layer_list);
6036 inputs.can_render_to_separate_surface = true;
6037 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6039 EXPECT_EQ(2u, render_surface_layer_list.size());
6041 int count_represents_target_render_surface = 0;
6042 int count_represents_contributing_render_surface = 0;
6043 int count_represents_itself = 0;
6044 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6045 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
6046 it != end; ++it) {
6047 if (it.represents_target_render_surface())
6048 count_represents_target_render_surface++;
6049 if (it.represents_contributing_render_surface())
6050 count_represents_contributing_render_surface++;
6051 if (it.represents_itself())
6052 count_represents_itself++;
6055 // Two render surfaces.
6056 EXPECT_EQ(2, count_represents_target_render_surface);
6057 // Second render surface contributes to root render surface.
6058 EXPECT_EQ(1, count_represents_contributing_render_surface);
6059 // All 4 layers represent itself.
6060 EXPECT_EQ(4, count_represents_itself);
6064 LayerImplList render_surface_layer_list;
6065 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6066 root.get(), root->bounds(), &render_surface_layer_list);
6067 inputs.can_render_to_separate_surface = false;
6068 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6070 EXPECT_EQ(1u, render_surface_layer_list.size());
6072 int count_represents_target_render_surface = 0;
6073 int count_represents_contributing_render_surface = 0;
6074 int count_represents_itself = 0;
6075 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6076 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
6077 it != end; ++it) {
6078 if (it.represents_target_render_surface())
6079 count_represents_target_render_surface++;
6080 if (it.represents_contributing_render_surface())
6081 count_represents_contributing_render_surface++;
6082 if (it.represents_itself())
6083 count_represents_itself++;
6086 // Only root layer has a render surface.
6087 EXPECT_EQ(1, count_represents_target_render_surface);
6088 // No layer contributes a render surface to root render surface.
6089 EXPECT_EQ(0, count_represents_contributing_render_surface);
6090 // All 4 layers represent itself.
6091 EXPECT_EQ(4, count_represents_itself);
6095 TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
6096 LayerImpl* root = root_layer();
6097 LayerImpl* render_surface = AddChild<LayerImpl>(root);
6098 LayerImpl* child = AddChild<LayerImpl>(render_surface);
6099 child->SetDrawsContent(true);
6101 gfx::Transform identity_transform;
6102 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6103 gfx::PointF(), gfx::Size(50, 50), true, false,
6104 true);
6105 SetLayerPropertiesForTesting(render_surface, identity_transform,
6106 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6107 false, true, true);
6108 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
6109 gfx::PointF(), gfx::Size(20, 20), true, false,
6110 false);
6112 root->SetShouldFlattenTransform(false);
6113 root->Set3dSortingContextId(1);
6114 render_surface->SetDoubleSided(false);
6116 ExecuteCalculateDrawProperties(root);
6118 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
6119 EXPECT_EQ(1u, render_surface_layer_list_impl()
6120 ->at(0)
6121 ->render_surface()
6122 ->layer_list()
6123 .size());
6124 EXPECT_EQ(1u, render_surface_layer_list_impl()
6125 ->at(1)
6126 ->render_surface()
6127 ->layer_list()
6128 .size());
6130 gfx::Transform rotation_transform = identity_transform;
6131 rotation_transform.RotateAboutXAxis(180.0);
6133 render_surface->SetTransform(rotation_transform);
6135 ExecuteCalculateDrawProperties(root);
6137 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6138 EXPECT_EQ(0u, render_surface_layer_list_impl()
6139 ->at(0)
6140 ->render_surface()
6141 ->layer_list()
6142 .size());
6145 TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
6146 // Checks that the simple case (being clipped by a scroll parent that would
6147 // have been processed before you anyhow) results in the right clips.
6149 // + root
6150 // + scroll_parent_border
6151 // | + scroll_parent_clip
6152 // | + scroll_parent
6153 // + scroll_child
6155 scoped_refptr<Layer> root = Layer::Create(layer_settings());
6156 scoped_refptr<Layer> scroll_parent_border = Layer::Create(layer_settings());
6157 scoped_refptr<Layer> scroll_parent_clip = Layer::Create(layer_settings());
6158 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
6159 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6160 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
6161 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6163 root->AddChild(scroll_child);
6165 root->AddChild(scroll_parent_border);
6166 scroll_parent_border->AddChild(scroll_parent_clip);
6167 scroll_parent_clip->AddChild(scroll_parent);
6169 scroll_parent_clip->SetMasksToBounds(true);
6171 scroll_child->SetScrollParent(scroll_parent.get());
6173 gfx::Transform identity_transform;
6174 SetLayerPropertiesForTesting(root.get(),
6175 identity_transform,
6176 gfx::Point3F(),
6177 gfx::PointF(),
6178 gfx::Size(50, 50),
6179 true,
6180 false);
6181 SetLayerPropertiesForTesting(scroll_parent_border.get(),
6182 identity_transform,
6183 gfx::Point3F(),
6184 gfx::PointF(),
6185 gfx::Size(40, 40),
6186 true,
6187 false);
6188 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
6189 identity_transform,
6190 gfx::Point3F(),
6191 gfx::PointF(),
6192 gfx::Size(30, 30),
6193 true,
6194 false);
6195 SetLayerPropertiesForTesting(scroll_parent.get(),
6196 identity_transform,
6197 gfx::Point3F(),
6198 gfx::PointF(),
6199 gfx::Size(50, 50),
6200 true,
6201 false);
6202 SetLayerPropertiesForTesting(scroll_child.get(),
6203 identity_transform,
6204 gfx::Point3F(),
6205 gfx::PointF(),
6206 gfx::Size(50, 50),
6207 true,
6208 false);
6210 host()->SetRootLayer(root);
6212 ExecuteCalculateDrawProperties(root.get());
6214 EXPECT_TRUE(root->render_surface());
6216 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
6217 scroll_child->clip_rect().ToString());
6218 EXPECT_TRUE(scroll_child->is_clipped());
6221 TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
6222 scoped_refptr<LayerWithForcedDrawsContent> root =
6223 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6224 scoped_refptr<LayerWithForcedDrawsContent> parent =
6225 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6226 scoped_refptr<LayerWithForcedDrawsContent> child =
6227 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6229 root->AddChild(parent);
6230 parent->AddChild(child);
6232 gfx::Transform identity_transform;
6233 SetLayerPropertiesForTesting(root.get(),
6234 identity_transform,
6235 gfx::Point3F(),
6236 gfx::PointF(),
6237 gfx::Size(50, 50),
6238 true,
6239 true);
6240 root->SetForceRenderSurface(true);
6241 SetLayerPropertiesForTesting(parent.get(),
6242 identity_transform,
6243 gfx::Point3F(),
6244 gfx::PointF(),
6245 gfx::Size(30, 30),
6246 true,
6247 true);
6248 parent->SetForceRenderSurface(true);
6249 SetLayerPropertiesForTesting(child.get(),
6250 identity_transform,
6251 gfx::Point3F(),
6252 gfx::PointF(),
6253 gfx::Size(20, 20),
6254 true,
6255 true);
6256 child->SetForceRenderSurface(true);
6258 host()->SetRootLayer(root);
6260 ExecuteCalculateDrawProperties(root.get());
6262 EXPECT_EQ(3u, render_surface_layer_list()->size());
6264 gfx::Transform singular_transform;
6265 singular_transform.Scale3d(
6266 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
6268 child->SetTransform(singular_transform);
6270 ExecuteCalculateDrawProperties(root.get());
6272 EXPECT_EQ(2u, render_surface_layer_list()->size());
6274 // Ensure that the entire subtree under a layer with singular transform does
6275 // not get rendered.
6276 parent->SetTransform(singular_transform);
6277 child->SetTransform(identity_transform);
6279 ExecuteCalculateDrawProperties(root.get());
6281 EXPECT_EQ(1u, render_surface_layer_list()->size());
6284 TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
6285 // Checks that clipping by a scroll parent that follows you in paint order
6286 // still results in correct clipping.
6288 // + root
6289 // + scroll_parent_border
6290 // + scroll_parent_clip
6291 // + scroll_parent
6292 // + scroll_child
6294 LayerImpl* root = root_layer();
6295 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6296 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6297 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6298 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6300 scroll_parent->SetDrawsContent(true);
6301 scroll_child->SetDrawsContent(true);
6303 scroll_parent_clip->SetMasksToBounds(true);
6305 scroll_child->SetScrollParent(scroll_parent);
6306 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6307 scroll_children->insert(scroll_child);
6308 scroll_parent->SetScrollChildren(scroll_children.release());
6310 gfx::Transform identity_transform;
6311 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6312 gfx::PointF(), gfx::Size(50, 50), true, false,
6313 true);
6314 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6315 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6316 true, false, false);
6317 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6318 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6319 true, false, false);
6320 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6321 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6322 true, false, false);
6323 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6324 gfx::PointF(), gfx::Size(50, 50), true, false,
6325 false);
6327 ExecuteCalculateDrawProperties(root);
6329 EXPECT_TRUE(root->render_surface());
6331 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
6332 scroll_child->clip_rect().ToString());
6333 EXPECT_TRUE(scroll_child->is_clipped());
6336 TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
6337 // Checks that clipping by a scroll parent and scroll grandparent that follow
6338 // you in paint order still results in correct clipping.
6340 // + root
6341 // + scroll_child
6342 // + scroll_parent_border
6343 // | + scroll_parent_clip
6344 // | + scroll_parent
6345 // + scroll_grandparent_border
6346 // + scroll_grandparent_clip
6347 // + scroll_grandparent
6349 LayerImpl* root = root_layer();
6350 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6351 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6352 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6353 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6354 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6355 LayerImpl* scroll_grandparent_clip =
6356 AddChild<LayerImpl>(scroll_grandparent_border);
6357 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
6359 scroll_parent->SetDrawsContent(true);
6360 scroll_grandparent->SetDrawsContent(true);
6361 scroll_child->SetDrawsContent(true);
6363 scroll_parent_clip->SetMasksToBounds(true);
6364 scroll_grandparent_clip->SetMasksToBounds(true);
6366 scroll_child->SetScrollParent(scroll_parent);
6367 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6368 scroll_children->insert(scroll_child);
6369 scroll_parent->SetScrollChildren(scroll_children.release());
6371 scroll_parent_border->SetScrollParent(scroll_grandparent);
6372 scroll_children.reset(new std::set<LayerImpl*>);
6373 scroll_children->insert(scroll_parent_border);
6374 scroll_grandparent->SetScrollChildren(scroll_children.release());
6376 gfx::Transform identity_transform;
6377 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6378 gfx::PointF(), gfx::Size(50, 50), true, false,
6379 true);
6380 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
6381 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6382 true, false, false);
6383 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
6384 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6385 true, false, false);
6386 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
6387 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6388 true, false, false);
6389 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6390 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6391 true, false, false);
6392 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6393 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6394 true, false, false);
6395 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6396 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6397 true, false, false);
6398 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6399 gfx::PointF(), gfx::Size(50, 50), true, false,
6400 false);
6402 ExecuteCalculateDrawProperties(root);
6404 EXPECT_TRUE(root->render_surface());
6406 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
6407 scroll_child->clip_rect().ToString());
6408 EXPECT_TRUE(scroll_child->is_clipped());
6410 // Despite the fact that we visited the above layers out of order to get the
6411 // correct clip, the layer lists should be unaffected.
6412 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
6413 EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0));
6414 EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1));
6415 EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2));
6418 TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
6419 // Ensures that even if we visit layers out of order, we still produce a
6420 // correctly ordered render surface layer list.
6421 // + root
6422 // + scroll_child
6423 // + scroll_parent_border
6424 // + scroll_parent_clip
6425 // + scroll_parent
6426 // + render_surface2
6427 // + scroll_grandparent_border
6428 // + scroll_grandparent_clip
6429 // + scroll_grandparent
6430 // + render_surface1
6432 LayerImpl* root = root_layer();
6433 root->SetDrawsContent(true);
6435 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6436 scroll_child->SetDrawsContent(true);
6438 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6439 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6440 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6441 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
6442 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6443 LayerImpl* scroll_grandparent_clip =
6444 AddChild<LayerImpl>(scroll_grandparent_border);
6445 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
6446 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
6448 scroll_parent->SetDrawsContent(true);
6449 render_surface1->SetDrawsContent(true);
6450 scroll_grandparent->SetDrawsContent(true);
6451 render_surface2->SetDrawsContent(true);
6453 scroll_parent_clip->SetMasksToBounds(true);
6454 scroll_grandparent_clip->SetMasksToBounds(true);
6456 scroll_child->SetScrollParent(scroll_parent);
6457 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6458 scroll_children->insert(scroll_child);
6459 scroll_parent->SetScrollChildren(scroll_children.release());
6461 scroll_parent_border->SetScrollParent(scroll_grandparent);
6462 scroll_children.reset(new std::set<LayerImpl*>);
6463 scroll_children->insert(scroll_parent_border);
6464 scroll_grandparent->SetScrollChildren(scroll_children.release());
6466 gfx::Transform identity_transform;
6467 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6468 gfx::PointF(), gfx::Size(50, 50), true, false,
6469 true);
6470 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
6471 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6472 true, false, false);
6473 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
6474 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6475 true, false, false);
6476 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
6477 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6478 true, false, false);
6479 SetLayerPropertiesForTesting(render_surface1, identity_transform,
6480 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6481 true, false, true);
6482 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6483 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6484 true, false, false);
6485 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6486 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6487 true, false, false);
6488 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6489 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6490 true, false, false);
6491 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6492 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6493 true, false, true);
6494 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6495 gfx::PointF(), gfx::Size(50, 50), true, false,
6496 false);
6498 ExecuteCalculateDrawProperties(root);
6500 EXPECT_TRUE(root->render_surface());
6502 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
6503 scroll_child->clip_rect().ToString());
6504 EXPECT_TRUE(scroll_child->is_clipped());
6506 // Despite the fact that we had to process the layers out of order to get the
6507 // right clip, our render_surface_layer_list's order should be unaffected.
6508 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6509 EXPECT_EQ(root, render_surface_layer_list_impl()->at(0));
6510 EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1));
6511 EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2));
6512 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
6513 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
6514 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
6517 TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
6518 // Ensures that when we have a render surface between a fixed position layer
6519 // and its container, we compute the fixed position layer's draw transform
6520 // with respect to that intervening render surface, not with respect to its
6521 // container's render target.
6523 // + root
6524 // + render_surface
6525 // + fixed
6526 // + child
6528 scoped_refptr<Layer> root = Layer::Create(layer_settings());
6529 scoped_refptr<LayerWithForcedDrawsContent> render_surface =
6530 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6531 scoped_refptr<LayerWithForcedDrawsContent> fixed =
6532 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6533 scoped_refptr<LayerWithForcedDrawsContent> child =
6534 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6536 root->AddChild(render_surface);
6537 render_surface->AddChild(fixed);
6538 fixed->AddChild(child);
6540 root->SetIsContainerForFixedPositionLayers(true);
6541 render_surface->SetForceRenderSurface(true);
6543 LayerPositionConstraint constraint;
6544 constraint.set_is_fixed_position(true);
6545 fixed->SetPositionConstraint(constraint);
6547 SetLayerPropertiesForTesting(root.get(), gfx::Transform(), gfx::Point3F(),
6548 gfx::PointF(), gfx::Size(50, 50), true, false);
6549 SetLayerPropertiesForTesting(render_surface.get(), gfx::Transform(),
6550 gfx::Point3F(), gfx::PointF(7.f, 9.f),
6551 gfx::Size(50, 50), true, false);
6552 SetLayerPropertiesForTesting(fixed.get(), gfx::Transform(), gfx::Point3F(),
6553 gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true,
6554 false);
6555 SetLayerPropertiesForTesting(child.get(), gfx::Transform(), gfx::Point3F(),
6556 gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true,
6557 false);
6559 host()->SetRootLayer(root);
6561 ExecuteCalculateDrawProperties(root.get());
6563 gfx::Transform expected_fixed_draw_transform;
6564 expected_fixed_draw_transform.Translate(10.f, 15.f);
6565 EXPECT_EQ(expected_fixed_draw_transform, fixed->draw_transform());
6567 gfx::Transform expected_fixed_screen_space_transform;
6568 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
6569 EXPECT_EQ(expected_fixed_screen_space_transform,
6570 fixed->screen_space_transform());
6572 gfx::Transform expected_child_draw_transform;
6573 expected_child_draw_transform.Translate(11.f, 17.f);
6574 EXPECT_EQ(expected_child_draw_transform, child->draw_transform());
6576 gfx::Transform expected_child_screen_space_transform;
6577 expected_child_screen_space_transform.Translate(18.f, 26.f);
6578 EXPECT_EQ(expected_child_screen_space_transform,
6579 child->screen_space_transform());
6582 TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
6583 // This test verifies that a scrolling layer that gets snapped to
6584 // integer coordinates doesn't move a fixed position child.
6586 // + root
6587 // + container
6588 // + scroller
6589 // + fixed
6591 FakeImplProxy proxy;
6592 TestSharedBitmapManager shared_bitmap_manager;
6593 TestTaskGraphRunner task_graph_runner;
6594 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
6595 &task_graph_runner);
6596 host_impl.CreatePendingTree();
6597 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
6598 scoped_ptr<LayerImpl> container =
6599 LayerImpl::Create(host_impl.active_tree(), 2);
6600 LayerImpl* container_layer = container.get();
6601 scoped_ptr<LayerImpl> scroller =
6602 LayerImpl::Create(host_impl.active_tree(), 3);
6603 LayerImpl* scroll_layer = scroller.get();
6604 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
6605 LayerImpl* fixed_layer = fixed.get();
6607 container->SetIsContainerForFixedPositionLayers(true);
6609 LayerPositionConstraint constraint;
6610 constraint.set_is_fixed_position(true);
6611 fixed->SetPositionConstraint(constraint);
6613 scroller->SetScrollClipLayer(container->id());
6615 gfx::Transform identity_transform;
6616 gfx::Transform container_transform;
6617 container_transform.Translate3d(10.0, 20.0, 0.0);
6618 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
6620 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
6621 gfx::PointF(), gfx::Size(50, 50), true, false,
6622 true);
6623 SetLayerPropertiesForTesting(container.get(), container_transform,
6624 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6625 true, false, false);
6626 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
6627 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6628 true, false, false);
6629 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
6630 gfx::PointF(), gfx::Size(50, 50), true, false,
6631 false);
6633 scroller->AddChild(fixed.Pass());
6634 container->AddChild(scroller.Pass());
6635 root->AddChild(container.Pass());
6637 // Rounded to integers already.
6639 gfx::Vector2dF scroll_delta(3.0, 5.0);
6640 scroll_layer->SetScrollDelta(scroll_delta);
6642 LayerImplList render_surface_layer_list;
6643 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6644 root.get(), root->bounds(), &render_surface_layer_list);
6645 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6647 EXPECT_TRANSFORMATION_MATRIX_EQ(
6648 container_layer->draw_properties().screen_space_transform,
6649 fixed_layer->draw_properties().screen_space_transform);
6650 EXPECT_VECTOR_EQ(
6651 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6652 container_offset);
6653 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6654 .screen_space_transform.To2dTranslation(),
6655 container_offset - scroll_delta);
6658 // Scroll delta requiring rounding.
6660 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
6661 scroll_layer->SetScrollDelta(scroll_delta);
6663 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
6665 LayerImplList render_surface_layer_list;
6666 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6667 root.get(), root->bounds(), &render_surface_layer_list);
6668 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6670 EXPECT_TRANSFORMATION_MATRIX_EQ(
6671 container_layer->draw_properties().screen_space_transform,
6672 fixed_layer->draw_properties().screen_space_transform);
6673 EXPECT_VECTOR_EQ(
6674 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6675 container_offset);
6676 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6677 .screen_space_transform.To2dTranslation(),
6678 container_offset - rounded_scroll_delta);
6681 // Scale is applied earlier in the tree.
6683 gfx::Transform scaled_container_transform = container_transform;
6684 scaled_container_transform.Scale3d(3.0, 3.0, 1.0);
6685 container_layer->SetTransform(scaled_container_transform);
6687 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
6688 scroll_layer->SetScrollDelta(scroll_delta);
6690 LayerImplList render_surface_layer_list;
6691 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6692 root.get(), root->bounds(), &render_surface_layer_list);
6693 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6695 EXPECT_TRANSFORMATION_MATRIX_EQ(
6696 container_layer->draw_properties().screen_space_transform,
6697 fixed_layer->draw_properties().screen_space_transform);
6698 EXPECT_VECTOR_EQ(
6699 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6700 container_offset);
6702 container_layer->SetTransform(container_transform);
6705 // Scale is applied on the scroll layer itself.
6707 gfx::Transform scale_transform;
6708 scale_transform.Scale3d(3.0, 3.0, 1.0);
6709 scroll_layer->SetTransform(scale_transform);
6711 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
6712 scroll_layer->SetScrollDelta(scroll_delta);
6714 LayerImplList render_surface_layer_list;
6715 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6716 root.get(), root->bounds(), &render_surface_layer_list);
6717 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6719 EXPECT_VECTOR_EQ(
6720 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6721 container_offset);
6723 scroll_layer->SetTransform(identity_transform);
6727 TEST_F(LayerTreeHostCommonTest,
6728 ScrollCompensationMainScrollOffsetFractionalPart) {
6729 // This test verifies that a scrolling layer that has fractional scroll offset
6730 // from main doesn't move a fixed position child.
6732 // + root
6733 // + container
6734 // + scroller
6735 // + fixed
6737 FakeImplProxy proxy;
6738 TestSharedBitmapManager shared_bitmap_manager;
6739 TestTaskGraphRunner task_graph_runner;
6740 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
6741 &task_graph_runner);
6742 host_impl.CreatePendingTree();
6743 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
6744 scoped_ptr<LayerImpl> container =
6745 LayerImpl::Create(host_impl.active_tree(), 2);
6746 LayerImpl* container_layer = container.get();
6747 scoped_ptr<LayerImpl> scroller =
6748 LayerImpl::Create(host_impl.active_tree(), 3);
6749 LayerImpl* scroll_layer = scroller.get();
6750 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
6751 LayerImpl* fixed_layer = fixed.get();
6753 container->SetIsContainerForFixedPositionLayers(true);
6755 LayerPositionConstraint constraint;
6756 constraint.set_is_fixed_position(true);
6757 fixed->SetPositionConstraint(constraint);
6759 scroller->SetScrollClipLayer(container->id());
6761 gfx::Transform identity_transform;
6762 gfx::Transform container_transform;
6763 container_transform.Translate3d(10.0, 20.0, 0.0);
6764 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
6766 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
6767 gfx::PointF(), gfx::Size(50, 50), true, false,
6768 true);
6769 SetLayerPropertiesForTesting(container.get(), container_transform,
6770 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6771 true, false, false);
6772 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
6773 gfx::Point3F(), gfx::PointF(0.0, 0.0),
6774 gfx::Size(30, 30), true, false, false);
6776 gfx::ScrollOffset scroll_offset(3.3, 4.2);
6777 gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f);
6778 gfx::Vector2dF scroll_delta(0.1f, 0.4f);
6779 // Blink only uses the integer part of the scroll_offset for fixed
6780 // position layer.
6781 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
6782 gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true,
6783 false, false);
6784 scroll_layer->PushScrollOffsetFromMainThread(scroll_offset);
6785 scroll_layer->SetScrollDelta(scroll_delta);
6786 scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part);
6788 scroller->AddChild(fixed.Pass());
6789 container->AddChild(scroller.Pass());
6790 root->AddChild(container.Pass());
6792 LayerImplList render_surface_layer_list;
6793 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6794 root.get(), root->bounds(), &render_surface_layer_list);
6795 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6797 EXPECT_TRANSFORMATION_MATRIX_EQ(
6798 container_layer->draw_properties().screen_space_transform,
6799 fixed_layer->draw_properties().screen_space_transform);
6800 EXPECT_VECTOR_EQ(
6801 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6802 container_offset);
6804 gfx::ScrollOffset effective_scroll_offset =
6805 ScrollOffsetWithDelta(scroll_offset, scroll_delta);
6806 gfx::Vector2d rounded_effective_scroll_offset =
6807 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset));
6808 EXPECT_VECTOR_EQ(
6809 scroll_layer->draw_properties().screen_space_transform.To2dTranslation(),
6810 container_offset - rounded_effective_scroll_offset);
6813 class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
6814 public:
6815 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
6816 LayerTreeImpl* tree_impl,
6817 int id) {
6818 return make_scoped_ptr(
6819 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
6822 ~AnimationScaleFactorTrackingLayerImpl() override {}
6824 private:
6825 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
6826 int id)
6827 : LayerImpl(tree_impl, id) {
6828 SetDrawsContent(true);
6832 TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
6833 FakeImplProxy proxy;
6834 TestSharedBitmapManager shared_bitmap_manager;
6835 TestTaskGraphRunner task_graph_runner;
6836 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
6837 &task_graph_runner);
6838 gfx::Transform identity_matrix;
6839 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
6840 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
6841 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
6842 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
6843 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
6844 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
6845 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
6846 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
6848 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
6849 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
6850 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
6852 child->AddChild(grand_child.Pass());
6853 parent->AddChild(child.Pass());
6854 grand_parent->AddChild(parent.Pass());
6856 SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix,
6857 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6858 true, false, true);
6859 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
6860 gfx::PointF(), gfx::Size(1, 2), true, false,
6861 false);
6862 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
6863 gfx::PointF(), gfx::Size(1, 2), true, false,
6864 false);
6866 SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(),
6867 gfx::PointF(), gfx::Size(1, 2), true, false,
6868 false);
6870 ExecuteCalculateDrawProperties(grand_parent.get());
6872 // No layers have animations.
6873 EXPECT_EQ(0.f,
6874 grand_parent->draw_properties().maximum_animation_contents_scale);
6875 EXPECT_EQ(0.f,
6876 parent_raw->draw_properties().maximum_animation_contents_scale);
6877 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6878 EXPECT_EQ(
6879 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6881 TransformOperations translation;
6882 translation.AppendTranslate(1.f, 2.f, 3.f);
6884 AddAnimatedTransformToLayer(
6885 parent_raw, 1.0, TransformOperations(), translation);
6887 // No layers have scale-affecting animations.
6888 EXPECT_EQ(0.f,
6889 grand_parent->draw_properties().maximum_animation_contents_scale);
6890 EXPECT_EQ(0.f,
6891 parent_raw->draw_properties().maximum_animation_contents_scale);
6892 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6893 EXPECT_EQ(
6894 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6896 TransformOperations scale;
6897 scale.AppendScale(5.f, 4.f, 3.f);
6899 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
6900 ExecuteCalculateDrawProperties(grand_parent.get());
6902 // Only |child| has a scale-affecting animation.
6903 EXPECT_EQ(0.f,
6904 grand_parent->draw_properties().maximum_animation_contents_scale);
6905 EXPECT_EQ(0.f,
6906 parent_raw->draw_properties().maximum_animation_contents_scale);
6907 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale);
6908 EXPECT_EQ(
6909 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6911 AddAnimatedTransformToLayer(
6912 grand_parent.get(), 1.0, TransformOperations(), scale);
6913 ExecuteCalculateDrawProperties(grand_parent.get());
6915 // |grand_parent| and |child| have scale-affecting animations.
6916 EXPECT_EQ(5.f,
6917 grand_parent->draw_properties().maximum_animation_contents_scale);
6918 EXPECT_EQ(5.f,
6919 parent_raw->draw_properties().maximum_animation_contents_scale);
6920 // We don't support combining animated scales from two nodes; 0.f means
6921 // that the maximum scale could not be computed.
6922 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6923 EXPECT_EQ(
6924 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6926 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
6927 ExecuteCalculateDrawProperties(grand_parent.get());
6929 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
6930 EXPECT_EQ(5.f,
6931 grand_parent->draw_properties().maximum_animation_contents_scale);
6932 EXPECT_EQ(0.f,
6933 parent_raw->draw_properties().maximum_animation_contents_scale);
6934 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6935 EXPECT_EQ(
6936 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6938 grand_parent->layer_animation_controller()->AbortAnimations(
6939 Animation::TRANSFORM);
6940 parent_raw->layer_animation_controller()->AbortAnimations(
6941 Animation::TRANSFORM);
6942 child_raw->layer_animation_controller()->AbortAnimations(
6943 Animation::TRANSFORM);
6945 TransformOperations perspective;
6946 perspective.AppendPerspective(10.f);
6948 AddAnimatedTransformToLayer(
6949 child_raw, 1.0, TransformOperations(), perspective);
6950 ExecuteCalculateDrawProperties(grand_parent.get());
6952 // |child| has a scale-affecting animation but computing the maximum of this
6953 // animation is not supported.
6954 EXPECT_EQ(0.f,
6955 grand_parent->draw_properties().maximum_animation_contents_scale);
6956 EXPECT_EQ(0.f,
6957 parent_raw->draw_properties().maximum_animation_contents_scale);
6958 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6959 EXPECT_EQ(
6960 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
6962 child_raw->layer_animation_controller()->AbortAnimations(
6963 Animation::TRANSFORM);
6965 gfx::Transform scale_matrix;
6966 scale_matrix.Scale(1.f, 2.f);
6967 grand_parent->SetTransform(scale_matrix);
6968 parent_raw->SetTransform(scale_matrix);
6969 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
6970 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
6971 ExecuteCalculateDrawProperties(grand_parent.get());
6973 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
6974 // animation with maximum scale 5.f.
6975 EXPECT_EQ(0.f,
6976 grand_parent->draw_properties().maximum_animation_contents_scale);
6977 EXPECT_EQ(10.f,
6978 parent_raw->draw_properties().maximum_animation_contents_scale);
6979 EXPECT_EQ(10.f,
6980 child_raw->draw_properties().maximum_animation_contents_scale);
6981 EXPECT_EQ(
6982 10.f,
6983 grand_child_raw->draw_properties().maximum_animation_contents_scale);
6985 gfx::Transform perspective_matrix;
6986 perspective_matrix.ApplyPerspectiveDepth(2.f);
6987 child_raw->SetTransform(perspective_matrix);
6988 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
6989 ExecuteCalculateDrawProperties(grand_parent.get());
6991 // |child| has a transform that's neither a translation nor a scale.
6992 EXPECT_EQ(0.f,
6993 grand_parent->draw_properties().maximum_animation_contents_scale);
6994 EXPECT_EQ(10.f,
6995 parent_raw->draw_properties().maximum_animation_contents_scale);
6996 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6997 EXPECT_EQ(
6998 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
7000 parent_raw->SetTransform(perspective_matrix);
7001 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
7002 ExecuteCalculateDrawProperties(grand_parent.get());
7004 // |parent| and |child| have transforms that are neither translations nor
7005 // scales.
7006 EXPECT_EQ(0.f,
7007 grand_parent->draw_properties().maximum_animation_contents_scale);
7008 EXPECT_EQ(0.f,
7009 parent_raw->draw_properties().maximum_animation_contents_scale);
7010 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7011 EXPECT_EQ(
7012 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
7014 parent_raw->SetTransform(identity_matrix);
7015 child_raw->SetTransform(identity_matrix);
7016 grand_parent->SetTransform(perspective_matrix);
7017 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
7019 ExecuteCalculateDrawProperties(grand_parent.get());
7021 // |grand_parent| has a transform that's neither a translation nor a scale.
7022 EXPECT_EQ(0.f,
7023 grand_parent->draw_properties().maximum_animation_contents_scale);
7024 EXPECT_EQ(0.f,
7025 parent_raw->draw_properties().maximum_animation_contents_scale);
7026 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7027 EXPECT_EQ(
7028 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
7031 static int membership_id(LayerImpl* layer) {
7032 return layer->draw_properties().last_drawn_render_surface_layer_list_id;
7035 static void GatherDrawnLayers(LayerImplList* rsll,
7036 std::set<LayerImpl*>* drawn_layers) {
7037 for (LayerIterator it = LayerIterator::Begin(rsll),
7038 end = LayerIterator::End(rsll);
7039 it != end; ++it) {
7040 LayerImpl* layer = *it;
7041 if (it.represents_itself())
7042 drawn_layers->insert(layer);
7044 if (!it.represents_contributing_render_surface())
7045 continue;
7047 if (layer->mask_layer())
7048 drawn_layers->insert(layer->mask_layer());
7049 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
7050 drawn_layers->insert(layer->replica_layer()->mask_layer());
7054 TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
7055 FakeImplProxy proxy;
7056 TestSharedBitmapManager shared_bitmap_manager;
7057 TestTaskGraphRunner task_graph_runner;
7058 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
7059 &task_graph_runner);
7060 gfx::Transform identity_matrix;
7062 scoped_ptr<LayerImpl> grand_parent =
7063 LayerImpl::Create(host_impl.active_tree(), 1);
7064 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3);
7065 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5);
7066 scoped_ptr<LayerImpl> grand_child1 =
7067 LayerImpl::Create(host_impl.active_tree(), 7);
7068 scoped_ptr<LayerImpl> grand_child2 =
7069 LayerImpl::Create(host_impl.active_tree(), 9);
7071 LayerImpl* grand_parent_raw = grand_parent.get();
7072 LayerImpl* parent_raw = parent.get();
7073 LayerImpl* child_raw = child.get();
7074 LayerImpl* grand_child1_raw = grand_child1.get();
7075 LayerImpl* grand_child2_raw = grand_child2.get();
7077 child->AddChild(grand_child1.Pass());
7078 child->AddChild(grand_child2.Pass());
7079 parent->AddChild(child.Pass());
7080 grand_parent->AddChild(parent.Pass());
7082 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
7083 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7084 true, false, true);
7085 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
7086 gfx::PointF(), gfx::Size(1, 2), true, false,
7087 false);
7089 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
7090 gfx::PointF(), gfx::Size(1, 2), true, false,
7091 false);
7093 SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix,
7094 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7095 true, false, false);
7097 SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix,
7098 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7099 true, false, false);
7101 // Start with nothing being drawn.
7102 ExecuteCalculateDrawProperties(grand_parent_raw);
7103 int member_id = render_surface_layer_list_count();
7105 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7106 EXPECT_NE(member_id, membership_id(parent_raw));
7107 EXPECT_NE(member_id, membership_id(child_raw));
7108 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7109 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7111 std::set<LayerImpl*> expected;
7112 std::set<LayerImpl*> actual;
7113 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7114 EXPECT_EQ(expected, actual);
7116 // If we force render surface, but none of the layers are in the layer list,
7117 // then this layer should not appear in RSLL.
7118 grand_child1_raw->SetHasRenderSurface(true);
7120 ExecuteCalculateDrawProperties(grand_parent_raw);
7121 member_id = render_surface_layer_list_count();
7123 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7124 EXPECT_NE(member_id, membership_id(parent_raw));
7125 EXPECT_NE(member_id, membership_id(child_raw));
7126 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7127 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7129 expected.clear();
7130 actual.clear();
7131 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7132 EXPECT_EQ(expected, actual);
7134 // However, if we say that this layer also draws content, it will appear in
7135 // RSLL.
7136 grand_child1_raw->SetDrawsContent(true);
7138 ExecuteCalculateDrawProperties(grand_parent_raw);
7139 member_id = render_surface_layer_list_count();
7141 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7142 EXPECT_NE(member_id, membership_id(parent_raw));
7143 EXPECT_NE(member_id, membership_id(child_raw));
7144 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
7145 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7147 expected.clear();
7148 expected.insert(grand_child1_raw);
7150 actual.clear();
7151 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7152 EXPECT_EQ(expected, actual);
7154 // Now child is forced to have a render surface, and one if its children draws
7155 // content.
7156 grand_child1_raw->SetDrawsContent(false);
7157 grand_child1_raw->SetHasRenderSurface(false);
7158 child_raw->SetHasRenderSurface(true);
7159 grand_child2_raw->SetDrawsContent(true);
7161 ExecuteCalculateDrawProperties(grand_parent_raw);
7162 member_id = render_surface_layer_list_count();
7164 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7165 EXPECT_NE(member_id, membership_id(parent_raw));
7166 EXPECT_NE(member_id, membership_id(child_raw));
7167 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7168 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7170 expected.clear();
7171 expected.insert(grand_child2_raw);
7173 actual.clear();
7174 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7175 EXPECT_EQ(expected, actual);
7177 // Add a mask layer to child.
7178 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass());
7180 ExecuteCalculateDrawProperties(grand_parent_raw);
7181 member_id = render_surface_layer_list_count();
7183 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7184 EXPECT_NE(member_id, membership_id(parent_raw));
7185 EXPECT_NE(member_id, membership_id(child_raw));
7186 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
7187 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7188 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7190 expected.clear();
7191 expected.insert(grand_child2_raw);
7192 expected.insert(child_raw->mask_layer());
7194 expected.clear();
7195 expected.insert(grand_child2_raw);
7196 expected.insert(child_raw->mask_layer());
7198 actual.clear();
7199 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7200 EXPECT_EQ(expected, actual);
7202 // Add replica mask layer.
7203 scoped_ptr<LayerImpl> replica_layer =
7204 LayerImpl::Create(host_impl.active_tree(), 20);
7205 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21));
7206 child_raw->SetReplicaLayer(replica_layer.Pass());
7208 ExecuteCalculateDrawProperties(grand_parent_raw);
7209 member_id = render_surface_layer_list_count();
7211 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7212 EXPECT_NE(member_id, membership_id(parent_raw));
7213 EXPECT_NE(member_id, membership_id(child_raw));
7214 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
7215 EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer()));
7216 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7217 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7219 expected.clear();
7220 expected.insert(grand_child2_raw);
7221 expected.insert(child_raw->mask_layer());
7222 expected.insert(child_raw->replica_layer()->mask_layer());
7224 actual.clear();
7225 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7226 EXPECT_EQ(expected, actual);
7228 child_raw->TakeReplicaLayer();
7230 // With nothing drawing, we should have no layers.
7231 grand_child2_raw->SetDrawsContent(false);
7233 ExecuteCalculateDrawProperties(grand_parent_raw);
7234 member_id = render_surface_layer_list_count();
7236 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7237 EXPECT_NE(member_id, membership_id(parent_raw));
7238 EXPECT_NE(member_id, membership_id(child_raw));
7239 EXPECT_NE(member_id, membership_id(child_raw->mask_layer()));
7240 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7241 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7243 expected.clear();
7244 actual.clear();
7245 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7246 EXPECT_EQ(expected, actual);
7248 // Child itself draws means that we should have the child and the mask in the
7249 // list.
7250 child_raw->SetDrawsContent(true);
7252 ExecuteCalculateDrawProperties(grand_parent_raw);
7253 member_id = render_surface_layer_list_count();
7255 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7256 EXPECT_NE(member_id, membership_id(parent_raw));
7257 EXPECT_EQ(member_id, membership_id(child_raw));
7258 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
7259 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7260 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7262 expected.clear();
7263 expected.insert(child_raw);
7264 expected.insert(child_raw->mask_layer());
7265 actual.clear();
7266 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7267 EXPECT_EQ(expected, actual);
7269 child_raw->TakeMaskLayer();
7271 // Now everyone's a member!
7272 grand_parent_raw->SetDrawsContent(true);
7273 parent_raw->SetDrawsContent(true);
7274 child_raw->SetDrawsContent(true);
7275 grand_child1_raw->SetDrawsContent(true);
7276 grand_child2_raw->SetDrawsContent(true);
7278 ExecuteCalculateDrawProperties(grand_parent_raw);
7279 member_id = render_surface_layer_list_count();
7281 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
7282 EXPECT_EQ(member_id, membership_id(parent_raw));
7283 EXPECT_EQ(member_id, membership_id(child_raw));
7284 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
7285 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7287 expected.clear();
7288 expected.insert(grand_parent_raw);
7289 expected.insert(parent_raw);
7290 expected.insert(child_raw);
7291 expected.insert(grand_child1_raw);
7292 expected.insert(grand_child2_raw);
7294 actual.clear();
7295 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7296 EXPECT_EQ(expected, actual);
7299 TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
7300 FakeImplProxy proxy;
7301 TestSharedBitmapManager shared_bitmap_manager;
7302 TestTaskGraphRunner task_graph_runner;
7303 LayerTreeSettings settings;
7304 settings.layer_transforms_should_scale_layer_contents = true;
7305 FakeLayerTreeHostImpl host_impl(settings, &proxy, &shared_bitmap_manager,
7306 &task_graph_runner);
7308 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7309 LayerImpl* root_layer = root.get();
7310 scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2);
7311 LayerImpl* child1_layer = child1.get();
7312 scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3);
7313 LayerImpl* child2_layer = child2.get();
7315 root->AddChild(child1.Pass());
7316 root->AddChild(child2.Pass());
7317 root->SetHasRenderSurface(true);
7319 gfx::Transform identity_matrix, scale_transform_child1,
7320 scale_transform_child2;
7321 scale_transform_child1.Scale(2, 3);
7322 scale_transform_child2.Scale(4, 5);
7324 SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(),
7325 gfx::PointF(), gfx::Size(1, 1), true, false,
7326 true);
7327 SetLayerPropertiesForTesting(child1_layer, scale_transform_child1,
7328 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
7329 false, false);
7331 child1_layer->SetMaskLayer(
7332 LayerImpl::Create(host_impl.active_tree(), 4).Pass());
7334 scoped_ptr<LayerImpl> replica_layer =
7335 LayerImpl::Create(host_impl.active_tree(), 5);
7336 replica_layer->SetHasRenderSurface(true);
7337 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
7338 child1_layer->SetReplicaLayer(replica_layer.Pass());
7339 child1_layer->SetHasRenderSurface(true);
7341 ExecuteCalculateDrawProperties(root_layer);
7343 TransformOperations scale;
7344 scale.AppendScale(5.f, 8.f, 3.f);
7346 AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale);
7347 SetLayerPropertiesForTesting(child2_layer, scale_transform_child2,
7348 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
7349 false, false);
7351 ExecuteCalculateDrawProperties(root_layer);
7353 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
7354 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
7355 EXPECT_FLOAT_EQ(3.f, child1_layer->mask_layer()->GetIdealContentsScale());
7356 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
7358 EXPECT_FLOAT_EQ(
7359 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
7360 EXPECT_FLOAT_EQ(
7361 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
7362 EXPECT_FLOAT_EQ(0.f,
7363 child1_layer->mask_layer()
7364 ->draw_properties()
7365 .maximum_animation_contents_scale);
7366 EXPECT_FLOAT_EQ(0.f,
7367 child1_layer->replica_layer()
7368 ->mask_layer()
7369 ->draw_properties()
7370 .maximum_animation_contents_scale);
7371 EXPECT_FLOAT_EQ(
7372 8.f, child2_layer->draw_properties().maximum_animation_contents_scale);
7374 // Changing page-scale would affect ideal_contents_scale and
7375 // maximum_animation_contents_scale.
7377 float page_scale_factor = 3.f;
7378 float device_scale_factor = 1.0f;
7379 std::vector<LayerImpl*> render_surface_layer_list;
7380 gfx::Size device_viewport_size =
7381 gfx::Size(root_layer->bounds().width() * device_scale_factor,
7382 root_layer->bounds().height() * device_scale_factor);
7383 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7384 root_layer, device_viewport_size, &render_surface_layer_list);
7386 inputs.page_scale_factor = page_scale_factor;
7387 inputs.can_adjust_raster_scales = true;
7388 inputs.page_scale_layer = root_layer;
7389 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7391 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
7392 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
7393 EXPECT_FLOAT_EQ(9.f, child1_layer->mask_layer()->GetIdealContentsScale());
7394 EXPECT_FLOAT_EQ(
7395 9.f,
7396 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
7397 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
7399 EXPECT_FLOAT_EQ(
7400 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
7401 EXPECT_FLOAT_EQ(
7402 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
7403 EXPECT_FLOAT_EQ(0.f,
7404 child1_layer->mask_layer()
7405 ->draw_properties()
7406 .maximum_animation_contents_scale);
7407 EXPECT_FLOAT_EQ(0.f,
7408 child1_layer->replica_layer()
7409 ->mask_layer()
7410 ->draw_properties()
7411 .maximum_animation_contents_scale);
7412 EXPECT_FLOAT_EQ(
7413 24.f, child2_layer->draw_properties().maximum_animation_contents_scale);
7415 // Changing device-scale would affect ideal_contents_scale and
7416 // maximum_animation_contents_scale.
7418 device_scale_factor = 4.0f;
7419 inputs.device_scale_factor = device_scale_factor;
7420 inputs.can_adjust_raster_scales = true;
7421 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7423 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
7424 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
7425 EXPECT_FLOAT_EQ(36.f, child1_layer->mask_layer()->GetIdealContentsScale());
7426 EXPECT_FLOAT_EQ(
7427 36.f,
7428 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
7429 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
7431 EXPECT_FLOAT_EQ(
7432 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
7433 EXPECT_FLOAT_EQ(
7434 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
7435 EXPECT_FLOAT_EQ(0.f,
7436 child1_layer->mask_layer()
7437 ->draw_properties()
7438 .maximum_animation_contents_scale);
7439 EXPECT_FLOAT_EQ(0.f,
7440 child1_layer->replica_layer()
7441 ->mask_layer()
7442 ->draw_properties()
7443 .maximum_animation_contents_scale);
7444 EXPECT_FLOAT_EQ(
7445 96.f, child2_layer->draw_properties().maximum_animation_contents_scale);
7448 TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
7449 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7450 SetLayerPropertiesForTesting(root.get(),
7451 gfx::Transform(),
7452 gfx::Point3F(),
7453 gfx::PointF(),
7454 gfx::Size(768 / 2, 3000),
7455 true,
7456 false);
7457 root->SetIsDrawable(true);
7459 scoped_refptr<Layer> clip = Layer::Create(layer_settings());
7460 SetLayerPropertiesForTesting(clip.get(),
7461 gfx::Transform(),
7462 gfx::Point3F(),
7463 gfx::PointF(),
7464 gfx::Size(768 / 2, 10000),
7465 true,
7466 false);
7467 clip->SetMasksToBounds(true);
7469 scoped_refptr<Layer> content = Layer::Create(layer_settings());
7470 SetLayerPropertiesForTesting(content.get(),
7471 gfx::Transform(),
7472 gfx::Point3F(),
7473 gfx::PointF(),
7474 gfx::Size(768 / 2, 10000),
7475 true,
7476 false);
7477 content->SetIsDrawable(true);
7478 content->SetForceRenderSurface(true);
7480 root->AddChild(clip);
7481 clip->AddChild(content);
7483 host()->SetRootLayer(root);
7485 gfx::Size device_viewport_size(768, 582);
7486 RenderSurfaceLayerList render_surface_layer_list;
7487 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7488 host()->root_layer(), device_viewport_size, &render_surface_layer_list);
7489 inputs.device_scale_factor = 2.f;
7490 inputs.page_scale_factor = 1.f;
7491 inputs.page_scale_layer = NULL;
7492 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7494 // Layers in the root render surface have their visible content rect clipped
7495 // by the viewport.
7496 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect());
7498 // Layers drawing to a child render surface should still have their visible
7499 // content rect clipped by the viewport.
7500 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect());
7503 TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
7504 FakeImplProxy proxy;
7505 TestSharedBitmapManager shared_bitmap_manager;
7506 TestTaskGraphRunner task_graph_runner;
7507 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
7508 &task_graph_runner);
7510 // Set two layers: the root layer clips it's child,
7511 // the child draws its content.
7513 gfx::Size root_size = gfx::Size(300, 500);
7515 // Sublayer should be bigger than the root enlarged by bounds_delta.
7516 gfx::Size sublayer_size = gfx::Size(300, 1000);
7518 // Device viewport accomidated the root and the top controls.
7519 gfx::Size device_viewport_size = gfx::Size(300, 600);
7520 gfx::Transform identity_matrix;
7522 host_impl.SetViewportSize(device_viewport_size);
7523 host_impl.active_tree()->SetRootLayer(
7524 LayerImpl::Create(host_impl.active_tree(), 1));
7526 LayerImpl* root = host_impl.active_tree()->root_layer();
7527 SetLayerPropertiesForTesting(root,
7528 identity_matrix,
7529 gfx::Point3F(),
7530 gfx::PointF(),
7531 root_size,
7532 false,
7533 false,
7534 true);
7535 root->SetMasksToBounds(true);
7537 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2));
7539 LayerImpl* sublayer = root->child_at(0);
7540 SetLayerPropertiesForTesting(sublayer,
7541 identity_matrix,
7542 gfx::Point3F(),
7543 gfx::PointF(),
7544 sublayer_size,
7545 false,
7546 false,
7547 false);
7548 sublayer->SetDrawsContent(true);
7550 LayerImplList layer_impl_list;
7551 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7552 root, device_viewport_size, &layer_impl_list);
7554 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7556 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
7558 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
7560 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7562 gfx::Rect affected_by_delta(0, 0, root_size.width(),
7563 root_size.height() + 50);
7564 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
7567 TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) {
7568 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7569 scoped_refptr<Layer> inner_viewport_container_layer =
7570 Layer::Create(layer_settings());
7571 scoped_refptr<Layer> inner_viewport_scroll_layer =
7572 Layer::Create(layer_settings());
7573 scoped_refptr<Layer> outer_viewport_container_layer =
7574 Layer::Create(layer_settings());
7575 scoped_refptr<Layer> outer_viewport_scroll_layer =
7576 Layer::Create(layer_settings());
7578 root->AddChild(inner_viewport_container_layer);
7579 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer);
7580 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
7581 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
7583 inner_viewport_scroll_layer->SetScrollClipLayerId(
7584 inner_viewport_container_layer->id());
7585 outer_viewport_scroll_layer->SetScrollClipLayerId(
7586 outer_viewport_container_layer->id());
7588 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
7589 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
7591 host()->SetRootLayer(root);
7592 host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer,
7593 outer_viewport_scroll_layer);
7595 scoped_refptr<Layer> fixed_to_inner = Layer::Create(layer_settings());
7596 scoped_refptr<Layer> fixed_to_outer = Layer::Create(layer_settings());
7598 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
7599 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
7601 LayerPositionConstraint fixed_to_right;
7602 fixed_to_right.set_is_fixed_position(true);
7603 fixed_to_right.set_is_fixed_to_right_edge(true);
7605 fixed_to_inner->SetPositionConstraint(fixed_to_right);
7606 fixed_to_outer->SetPositionConstraint(fixed_to_right);
7608 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7610 TransformTree& transform_tree = host()->property_trees()->transform_tree;
7611 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
7612 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
7614 LayerPositionConstraint fixed_to_left;
7615 fixed_to_left.set_is_fixed_position(true);
7616 fixed_to_inner->SetPositionConstraint(fixed_to_left);
7618 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7619 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
7620 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
7622 fixed_to_outer->SetPositionConstraint(fixed_to_left);
7624 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7625 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
7626 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
7629 TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
7630 const gfx::Transform identity_matrix;
7631 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7632 scoped_refptr<LayerWithForcedDrawsContent> animated =
7633 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7635 root->AddChild(animated);
7637 host()->SetRootLayer(root);
7639 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
7640 gfx::PointF(), gfx::Size(100, 100), true, false);
7641 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
7642 gfx::PointF(), gfx::Size(20, 20), true, false);
7644 root->SetMasksToBounds(true);
7645 root->SetForceRenderSurface(true);
7646 animated->SetOpacity(0.f);
7648 AddOpacityTransitionToController(animated->layer_animation_controller(), 10.0,
7649 0.f, 1.f, false);
7651 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7653 EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty());
7656 TEST_F(LayerTreeHostCommonTest,
7657 VisibleContentRectForAnimatedLayerWithSingularTransform) {
7658 const gfx::Transform identity_matrix;
7659 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7660 scoped_refptr<Layer> clip = Layer::Create(layer_settings());
7661 scoped_refptr<LayerWithForcedDrawsContent> animated =
7662 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7663 scoped_refptr<LayerWithForcedDrawsContent> surface =
7664 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7665 scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation =
7666 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7668 root->AddChild(clip);
7669 clip->AddChild(animated);
7670 animated->AddChild(surface);
7671 surface->AddChild(descendant_of_animation);
7673 clip->SetMasksToBounds(true);
7674 surface->SetForceRenderSurface(true);
7676 host()->SetRootLayer(root);
7678 gfx::Transform uninvertible_matrix;
7679 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
7681 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
7682 gfx::PointF(), gfx::Size(100, 100), true, false);
7683 SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(),
7684 gfx::PointF(), gfx::Size(10, 10), true, false);
7685 SetLayerPropertiesForTesting(animated.get(), uninvertible_matrix,
7686 gfx::Point3F(), gfx::PointF(),
7687 gfx::Size(120, 120), true, false);
7688 SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(),
7689 gfx::PointF(), gfx::Size(100, 100), true, false);
7690 SetLayerPropertiesForTesting(descendant_of_animation.get(), identity_matrix,
7691 gfx::Point3F(), gfx::PointF(),
7692 gfx::Size(200, 200), true, false);
7694 TransformOperations start_transform_operations;
7695 start_transform_operations.AppendMatrix(uninvertible_matrix);
7696 TransformOperations end_transform_operations;
7698 AddAnimatedTransformToLayer(animated.get(), 10.0, start_transform_operations,
7699 end_transform_operations);
7701 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7703 // The animated layer has a singular transform and maps to a non-empty rect in
7704 // clipped target space, so is treated as fully visible.
7705 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_rect_from_property_trees());
7707 // The singular transform on |animated| is flattened when inherited by
7708 // |surface|, and this happens to make it invertible.
7709 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_rect_from_property_trees());
7710 EXPECT_EQ(gfx::Rect(2, 2),
7711 descendant_of_animation->visible_rect_from_property_trees());
7713 gfx::Transform zero_matrix;
7714 zero_matrix.Scale3d(0.f, 0.f, 0.f);
7715 SetLayerPropertiesForTesting(animated.get(), zero_matrix, gfx::Point3F(),
7716 gfx::PointF(), gfx::Size(120, 120), true, false);
7718 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7720 // The animated layer maps to the empty rect in clipped target space, so is
7721 // treated as having an empty visible rect.
7722 EXPECT_EQ(gfx::Rect(), animated->visible_rect_from_property_trees());
7724 // This time, flattening does not make |animated|'s transform invertible. This
7725 // means the clip cannot be projected into |surface|'s space, so we treat
7726 // |surface| and layers that draw into it as fully visible.
7727 EXPECT_EQ(gfx::Rect(100, 100), surface->visible_rect_from_property_trees());
7728 EXPECT_EQ(gfx::Rect(200, 200),
7729 descendant_of_animation->visible_rect_from_property_trees());
7732 // Verify that having an animated filter (but no current filter, as these
7733 // are mutually exclusive) correctly creates a render surface.
7734 TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
7735 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7736 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7737 scoped_refptr<Layer> grandchild = Layer::Create(layer_settings());
7738 root->AddChild(child);
7739 child->AddChild(grandchild);
7741 gfx::Transform identity_transform;
7742 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7743 gfx::PointF(), gfx::Size(50, 50), true, false);
7744 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
7745 gfx::PointF(), gfx::Size(50, 50), true, false);
7746 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
7747 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7748 true, false);
7749 host()->SetRootLayer(root);
7751 AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f);
7753 ExecuteCalculateDrawProperties(root.get());
7755 EXPECT_TRUE(root->render_surface());
7756 EXPECT_TRUE(child->render_surface());
7757 EXPECT_FALSE(grandchild->render_surface());
7759 EXPECT_TRUE(root->filters().IsEmpty());
7760 EXPECT_TRUE(child->filters().IsEmpty());
7761 EXPECT_TRUE(grandchild->filters().IsEmpty());
7763 EXPECT_FALSE(root->FilterIsAnimating());
7764 EXPECT_TRUE(child->FilterIsAnimating());
7765 EXPECT_FALSE(grandchild->FilterIsAnimating());
7768 // Ensures that the property tree code accounts for offsets between fixed
7769 // position layers and their respective containers.
7770 TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
7771 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7772 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7773 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
7774 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7776 root->AddChild(child);
7777 child->AddChild(grandchild);
7779 gfx::Transform identity_transform;
7780 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7781 gfx::PointF(), gfx::Size(50, 50), true, false);
7782 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
7783 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7784 false);
7785 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
7786 gfx::Point3F(), gfx::PointF(-1000, -1000),
7787 gfx::Size(50, 50), true, false);
7789 root->SetMasksToBounds(true);
7790 root->SetIsContainerForFixedPositionLayers(true);
7791 LayerPositionConstraint constraint;
7792 constraint.set_is_fixed_position(true);
7793 grandchild->SetPositionConstraint(constraint);
7795 root->SetIsContainerForFixedPositionLayers(true);
7797 host()->SetRootLayer(root);
7799 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7801 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7802 grandchild->visible_rect_from_property_trees());
7805 // Ensures that the property tree code accounts for offsets between fixed
7806 // position containers and their transform tree parents, when a fixed position
7807 // layer's container is its layer tree parent, but this parent doesn't have its
7808 // own transform tree node.
7809 TEST_F(LayerTreeHostCommonTest,
7810 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
7811 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7812 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7813 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
7814 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7816 root->AddChild(child);
7817 child->AddChild(grandchild);
7819 gfx::Transform identity_transform;
7820 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7821 gfx::PointF(), gfx::Size(50, 50), true, false);
7822 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
7823 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7824 false);
7825 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
7826 gfx::Point3F(), gfx::PointF(-1000, -1000),
7827 gfx::Size(50, 50), true, false);
7829 root->SetMasksToBounds(true);
7830 child->SetIsContainerForFixedPositionLayers(true);
7831 LayerPositionConstraint constraint;
7832 constraint.set_is_fixed_position(true);
7833 grandchild->SetPositionConstraint(constraint);
7835 root->SetIsContainerForFixedPositionLayers(true);
7837 host()->SetRootLayer(root);
7839 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7841 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7842 grandchild->visible_rect_from_property_trees());
7845 TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) {
7846 // In the following layer tree, the layer |box|'s render target is |surface|.
7847 // |surface| also creates a transform node. We want to combine clips for |box|
7848 // in the space of its target (i.e., |surface|), not its target's target. This
7849 // test ensures that happens.
7851 gfx::Transform rotate;
7852 rotate.Rotate(5);
7853 gfx::Transform identity;
7855 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7856 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7857 gfx::PointF(), gfx::Size(2500, 1500), true,
7858 false);
7860 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
7861 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
7862 gfx::PointF(), gfx::Size(2500, 1500), true,
7863 false);
7864 frame_clip->SetMasksToBounds(true);
7866 scoped_refptr<Layer> rotated = Layer::Create(layer_settings());
7867 SetLayerPropertiesForTesting(rotated.get(), rotate,
7868 gfx::Point3F(1250, 250, 0), gfx::PointF(),
7869 gfx::Size(2500, 500), true, false);
7871 scoped_refptr<Layer> surface = Layer::Create(layer_settings());
7872 SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(),
7873 gfx::PointF(), gfx::Size(2500, 500), true,
7874 false);
7875 surface->SetOpacity(0.5);
7877 scoped_refptr<LayerWithForcedDrawsContent> container =
7878 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7879 SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(),
7880 gfx::PointF(), gfx::Size(300, 300), true, false);
7882 scoped_refptr<LayerWithForcedDrawsContent> box =
7883 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7884 SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(),
7885 gfx::PointF(), gfx::Size(100, 100), true, false);
7887 root->AddChild(frame_clip);
7888 frame_clip->AddChild(rotated);
7889 rotated->AddChild(surface);
7890 surface->AddChild(container);
7891 surface->AddChild(box);
7893 host()->SetRootLayer(root);
7895 ExecuteCalculateDrawProperties(root.get());
7898 TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
7899 gfx::Transform identity;
7900 gfx::Transform translate_z;
7901 translate_z.Translate3d(0, 0, 10);
7903 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7904 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7905 gfx::PointF(), gfx::Size(800, 800), true, false);
7906 root->SetIsContainerForFixedPositionLayers(true);
7908 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
7909 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
7910 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7911 false);
7912 frame_clip->SetMasksToBounds(true);
7914 scoped_refptr<LayerWithForcedDrawsContent> fixed =
7915 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7916 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
7917 gfx::PointF(), gfx::Size(1000, 1000), true,
7918 false);
7920 LayerPositionConstraint constraint;
7921 constraint.set_is_fixed_position(true);
7922 fixed->SetPositionConstraint(constraint);
7924 root->AddChild(frame_clip);
7925 frame_clip->AddChild(fixed);
7927 host()->SetRootLayer(root);
7929 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7931 gfx::Rect expected(0, 0, 100, 100);
7932 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
7935 TEST_F(LayerTreeHostCommonTest,
7936 PropertyTreesAccountForScrollCompensationAdjustment) {
7937 gfx::Transform identity;
7938 gfx::Transform translate_z;
7939 translate_z.Translate3d(0, 0, 10);
7941 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7942 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7943 gfx::PointF(), gfx::Size(800, 800), true, false);
7944 root->SetIsContainerForFixedPositionLayers(true);
7946 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
7947 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
7948 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7949 false);
7950 frame_clip->SetMasksToBounds(true);
7952 scoped_refptr<LayerWithForcedDrawsContent> scroller =
7953 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7954 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(),
7955 gfx::PointF(), gfx::Size(1000, 1000), true,
7956 false);
7958 scroller->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f, 0.7f));
7959 scroller->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7));
7960 scroller->SetScrollClipLayerId(frame_clip->id());
7962 scoped_refptr<LayerWithForcedDrawsContent> fixed =
7963 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7964 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
7965 gfx::PointF(), gfx::Size(50, 50), true, false);
7967 LayerPositionConstraint constraint;
7968 constraint.set_is_fixed_position(true);
7969 fixed->SetPositionConstraint(constraint);
7971 scoped_refptr<LayerWithForcedDrawsContent> fixed_child =
7972 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7973 SetLayerPropertiesForTesting(fixed_child.get(), identity, gfx::Point3F(),
7974 gfx::PointF(), gfx::Size(10, 10), true, false);
7976 fixed_child->SetPositionConstraint(constraint);
7978 root->AddChild(frame_clip);
7979 frame_clip->AddChild(scroller);
7980 scroller->AddChild(fixed);
7981 fixed->AddChild(fixed_child);
7983 host()->SetRootLayer(root);
7985 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7987 gfx::Rect expected(0, 0, 50, 50);
7988 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
7990 expected = gfx::Rect(0, 0, 10, 10);
7991 EXPECT_EQ(expected, fixed_child->visible_rect_from_property_trees());
7994 TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
7995 gfx::Transform identity;
7997 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7998 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
7999 gfx::PointF(), gfx::Size(800, 800), true, false);
8000 root->SetIsContainerForFixedPositionLayers(true);
8002 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
8003 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
8004 gfx::PointF(500, 100), gfx::Size(100, 100), true,
8005 false);
8006 frame_clip->SetMasksToBounds(true);
8008 scoped_refptr<LayerWithForcedDrawsContent> scroller =
8009 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8010 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(),
8011 gfx::PointF(), gfx::Size(1000, 1000), true,
8012 false);
8014 scroller->SetScrollOffset(gfx::ScrollOffset(100, 100));
8015 scroller->SetScrollClipLayerId(frame_clip->id());
8017 scoped_refptr<LayerWithForcedDrawsContent> fixed =
8018 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8019 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
8020 gfx::PointF(100, 100), gfx::Size(50, 50), true,
8021 false);
8023 LayerPositionConstraint constraint;
8024 constraint.set_is_fixed_position(true);
8025 fixed->SetPositionConstraint(constraint);
8026 fixed->SetForceRenderSurface(true);
8027 fixed->SetMasksToBounds(true);
8029 root->AddChild(frame_clip);
8030 frame_clip->AddChild(scroller);
8031 scroller->AddChild(fixed);
8033 host()->SetRootLayer(root);
8035 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8037 gfx::Rect expected(0, 0, 50, 50);
8038 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
8041 TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
8042 gfx::Transform identity;
8043 gfx::Transform translate;
8044 gfx::Transform rotate;
8046 translate.Translate(10, 10);
8047 rotate.Rotate(45);
8049 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8050 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8051 gfx::PointF(), gfx::Size(800, 800), true, false);
8052 root->SetIsContainerForFixedPositionLayers(true);
8054 host()->SetRootLayer(root);
8056 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8057 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
8059 root->SetTransform(translate);
8060 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
8062 root->SetTransform(rotate);
8063 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
8066 TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
8067 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8068 scoped_refptr<LayerWithForcedDrawsContent> child =
8069 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8070 root->AddChild(child);
8072 host()->SetRootLayer(root);
8074 gfx::Transform identity_matrix;
8075 gfx::Transform scale_matrix;
8076 scale_matrix.Scale(2.f, 2.f);
8077 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8078 gfx::PointF(), gfx::Size(100, 100), true, false);
8079 SetLayerPropertiesForTesting(child.get(), scale_matrix, gfx::Point3F(),
8080 gfx::PointF(), gfx::Size(10, 10), true, false);
8082 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8083 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees());
8085 child->SetTransformOrigin(gfx::Point3F(10.f, 10.f, 10.f));
8087 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8088 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_rect_from_property_trees());
8091 TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
8092 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8093 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
8094 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8095 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
8096 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8098 root->AddChild(scroll_child);
8099 root->AddChild(scroll_parent);
8100 scroll_child->SetScrollParent(scroll_parent.get());
8101 scroll_parent->SetScrollClipLayerId(root->id());
8103 host()->SetRootLayer(root);
8105 gfx::Transform identity_transform;
8106 gfx::Transform scale;
8107 scale.Scale(2.f, 2.f);
8108 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8109 gfx::PointF(), gfx::Size(50, 50), true, false);
8110 SetLayerPropertiesForTesting(scroll_child.get(), scale, gfx::Point3F(),
8111 gfx::PointF(), gfx::Size(40, 40), true, false);
8112 SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform,
8113 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
8114 true, false);
8116 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8117 EXPECT_EQ(gfx::Rect(25, 25),
8118 scroll_child->visible_rect_from_property_trees());
8120 scroll_child->SetPosition(gfx::PointF(0, -10.f));
8121 scroll_parent->SetScrollOffset(gfx::ScrollOffset(0.f, 10.f));
8122 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8123 EXPECT_EQ(gfx::Rect(0, 5, 25, 25),
8124 scroll_child->visible_rect_from_property_trees());
8127 static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {
8130 TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
8131 gfx::Transform identity;
8132 FakeContentLayerClient client;
8133 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8134 scoped_refptr<LayerWithForcedDrawsContent> child =
8135 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8136 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
8137 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8138 scoped_refptr<FakePictureLayer> greatgrandchild(
8139 FakePictureLayer::Create(layer_settings(), &client));
8140 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8141 gfx::PointF(), gfx::Size(100, 100), true, false);
8142 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8143 gfx::PointF(), gfx::Size(10, 10), true, false);
8144 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8145 gfx::PointF(), gfx::Size(10, 10), true, false);
8146 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
8147 gfx::PointF(), gfx::Size(10, 10), true, false);
8149 root->AddChild(child);
8150 child->AddChild(grandchild);
8151 grandchild->AddChild(greatgrandchild);
8153 host()->SetRootLayer(root);
8155 // Check the non-skipped case.
8156 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8157 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
8159 // Now we will reset the visible rect from property trees for the grandchild,
8160 // and we will configure |child| in several ways that should force the subtree
8161 // to be skipped. The visible content rect for |grandchild| should, therefore,
8162 // remain empty.
8163 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
8164 gfx::Transform singular;
8165 singular.matrix().set(0, 0, 0);
8167 child->SetTransform(singular);
8168 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8169 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
8170 child->SetTransform(identity);
8172 child->SetHideLayerAndSubtree(true);
8173 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8174 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
8175 child->SetHideLayerAndSubtree(false);
8177 child->SetOpacity(0.f);
8178 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8179 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
8181 // Now, even though child has zero opacity, we will configure |grandchild| and
8182 // |greatgrandchild| in several ways that should force the subtree to be
8183 // processed anyhow.
8184 grandchild->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10)));
8185 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8186 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
8187 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
8188 grandchild->SetTouchEventHandlerRegion(Region());
8189 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8190 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
8191 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
8193 greatgrandchild->RequestCopyOfOutput(
8194 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8195 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8196 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
8199 TEST_F(LayerTreeHostCommonTest, SkippingSubtreeImpl) {
8200 FakeImplProxy proxy;
8201 TestSharedBitmapManager shared_bitmap_manager;
8202 TestTaskGraphRunner task_graph_runner;
8203 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager,
8204 &task_graph_runner);
8206 gfx::Transform identity;
8207 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
8208 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2);
8209 scoped_ptr<LayerImpl> grandchild =
8210 LayerImpl::Create(host_impl.active_tree(), 3);
8212 scoped_ptr<FakePictureLayerImpl> greatgrandchild(
8213 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
8215 child->SetDrawsContent(true);
8216 grandchild->SetDrawsContent(true);
8217 greatgrandchild->SetDrawsContent(true);
8219 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8220 gfx::PointF(), gfx::Size(100, 100), true, false,
8221 true);
8222 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8223 gfx::PointF(), gfx::Size(10, 10), true, false,
8224 false);
8225 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8226 gfx::PointF(), gfx::Size(10, 10), true, false,
8227 false);
8228 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
8229 gfx::PointF(), gfx::Size(10, 10), true, false,
8230 true);
8232 LayerImpl* child_ptr = child.get();
8233 LayerImpl* grandchild_ptr = grandchild.get();
8234 LayerImpl* greatgrandchild_ptr = greatgrandchild.get();
8236 grandchild->AddChild(greatgrandchild.Pass());
8237 child->AddChild(grandchild.Pass());
8238 root->AddChild(child.Pass());
8240 // Check the non-skipped case.
8241 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8242 EXPECT_EQ(gfx::Rect(10, 10),
8243 grandchild_ptr->visible_rect_from_property_trees());
8245 // Now we will reset the visible rect from property trees for the grandchild,
8246 // and we will configure |child| in several ways that should force the subtree
8247 // to be skipped. The visible content rect for |grandchild| should, therefore,
8248 // remain empty.
8249 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect());
8250 gfx::Transform singular;
8251 singular.matrix().set(0, 0, 0);
8253 child_ptr->SetTransform(singular);
8254 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8255 EXPECT_EQ(gfx::Rect(0, 0),
8256 grandchild_ptr->visible_rect_from_property_trees());
8257 child_ptr->SetTransform(identity);
8259 child_ptr->SetHideLayerAndSubtree(true);
8260 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8261 EXPECT_EQ(gfx::Rect(0, 0),
8262 grandchild_ptr->visible_rect_from_property_trees());
8263 child_ptr->SetHideLayerAndSubtree(false);
8265 child_ptr->SetOpacity(0.f);
8266 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8267 EXPECT_EQ(gfx::Rect(0, 0),
8268 grandchild_ptr->visible_rect_from_property_trees());
8270 // Now, even though child has zero opacity, we will configure |grandchild| and
8271 // |greatgrandchild| in several ways that should force the subtree to be
8272 // processed anyhow.
8273 grandchild_ptr->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10)));
8274 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8275 EXPECT_EQ(gfx::Rect(10, 10),
8276 grandchild_ptr->visible_rect_from_property_trees());
8277 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect());
8278 grandchild_ptr->SetTouchEventHandlerRegion(Region());
8279 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8280 EXPECT_EQ(gfx::Rect(0, 0),
8281 grandchild_ptr->visible_rect_from_property_trees());
8282 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect());
8284 ScopedPtrVector<CopyOutputRequest> requests;
8285 requests.push_back(CopyOutputRequest::CreateEmptyRequest());
8287 greatgrandchild_ptr->PassCopyRequests(&requests);
8288 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8289 EXPECT_EQ(gfx::Rect(10, 10),
8290 grandchild_ptr->visible_rect_from_property_trees());
8293 TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
8294 gfx::Transform identity;
8295 FakeContentLayerClient client;
8296 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8297 scoped_refptr<LayerWithForcedDrawsContent> child =
8298 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8299 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8300 gfx::PointF(), gfx::Size(100, 100), true, false);
8301 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8302 gfx::PointF(), gfx::Size(10, 10), true, false);
8303 root->AddChild(child);
8305 host()->SetRootLayer(root);
8307 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8308 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees());
8309 child->set_visible_rect_from_property_trees(gfx::Rect());
8311 child->SetHideLayerAndSubtree(true);
8312 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8313 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
8314 child->SetHideLayerAndSubtree(false);
8316 child->SetBounds(gfx::Size());
8317 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8318 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
8319 child->SetBounds(gfx::Size(10, 10));
8321 gfx::Transform rotate;
8322 child->SetDoubleSided(false);
8323 rotate.RotateAboutXAxis(180.f);
8324 child->SetTransform(rotate);
8325 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8326 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
8327 child->SetDoubleSided(true);
8328 child->SetTransform(identity);
8330 child->SetOpacity(0.f);
8331 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8332 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
8335 TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
8336 // Ensure that the treewalk in LayerTreeHostCommom::
8337 // PreCalculateMetaInformation happens when its required.
8338 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8339 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
8340 scoped_refptr<Layer> child = Layer::Create(layer_settings());
8342 root->AddChild(parent);
8343 parent->AddChild(child);
8345 child->SetClipParent(root.get());
8347 gfx::Transform identity;
8349 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8350 gfx::PointF(), gfx::Size(100, 100), true, false);
8351 SetLayerPropertiesForTesting(parent.get(), identity, gfx::Point3F(),
8352 gfx::PointF(), gfx::Size(100, 100), true, false);
8353 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8354 gfx::PointF(), gfx::Size(100, 100), true, false);
8356 host()->SetRootLayer(root);
8358 ExecuteCalculateDrawProperties(root.get());
8359 EXPECT_EQ(parent->draw_properties().num_unclipped_descendants, 1u);
8361 // Ensure the dynamic update to input handlers happens.
8362 child->SetHaveWheelEventHandlers(true);
8363 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_input_handler);
8364 ExecuteCalculateDrawProperties(root.get());
8365 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_input_handler);
8367 child->SetHaveWheelEventHandlers(false);
8368 EXPECT_FALSE(root->draw_properties().layer_or_descendant_has_input_handler);
8369 ExecuteCalculateDrawProperties(root.get());
8370 EXPECT_FALSE(root->draw_properties().layer_or_descendant_has_input_handler);
8372 child->RequestCopyOfOutput(
8373 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
8374 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
8375 ExecuteCalculateDrawProperties(root.get());
8376 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
8379 TEST_F(LayerTreeHostCommonTest, InputHandlersRecursiveUpdateTest) {
8380 // Ensure that the treewalk in LayertreeHostCommon::
8381 // PreCalculateMetaInformation updates input handlers correctly.
8382 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8383 scoped_refptr<Layer> child = Layer::Create(layer_settings());
8385 root->AddChild(child);
8387 child->SetHaveWheelEventHandlers(true);
8389 gfx::Transform identity;
8391 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8392 gfx::PointF(), gfx::Size(100, 100), true, false);
8393 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8394 gfx::PointF(), gfx::Size(100, 100), true, false);
8396 host()->SetRootLayer(root);
8398 EXPECT_EQ(root->num_layer_or_descendants_with_input_handler(), 0);
8399 ExecuteCalculateDrawProperties(root.get());
8400 EXPECT_EQ(root->num_layer_or_descendants_with_input_handler(), 1);
8401 child->SetHaveWheelEventHandlers(false);
8402 EXPECT_EQ(root->num_layer_or_descendants_with_input_handler(), 0);
8405 TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
8406 gfx::Transform identity;
8407 gfx::Transform translate_z;
8408 translate_z.Translate3d(0, 0, 10);
8410 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8411 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8412 gfx::PointF(), gfx::Size(800, 800), true, false);
8414 scoped_refptr<Layer> child = Layer::Create(layer_settings());
8415 SetLayerPropertiesForTesting(child.get(), translate_z, gfx::Point3F(),
8416 gfx::PointF(), gfx::Size(100, 100), true, false);
8418 root->AddChild(child);
8420 host()->SetRootLayer(root);
8422 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8423 EXPECT_NE(-1, child->transform_tree_index());
8425 child->RemoveFromParent();
8427 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8428 EXPECT_EQ(-1, child->transform_tree_index());
8431 TEST_F(LayerTreeHostCommonTest, ResetLayerDrawPropertiestest) {
8432 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8433 scoped_refptr<Layer> child = Layer::Create(layer_settings());
8435 root->AddChild(child);
8436 gfx::Transform identity;
8438 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8439 gfx::PointF(), gfx::Size(100, 100), true, false);
8440 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8441 gfx::PointF(), gfx::Size(100, 100), true, false);
8443 host()->SetRootLayer(root);
8445 EXPECT_FALSE(root->layer_or_descendant_is_drawn());
8446 EXPECT_FALSE(root->visited());
8447 EXPECT_FALSE(root->sorted_for_recursion());
8448 EXPECT_FALSE(child->layer_or_descendant_is_drawn());
8449 EXPECT_FALSE(child->visited());
8450 EXPECT_FALSE(child->sorted_for_recursion());
8452 root->set_layer_or_descendant_is_drawn(true);
8453 root->set_visited(true);
8454 root->set_sorted_for_recursion(true);
8455 child->set_layer_or_descendant_is_drawn(true);
8456 child->set_visited(true);
8457 child->set_sorted_for_recursion(true);
8459 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root.get());
8461 EXPECT_FALSE(root->layer_or_descendant_is_drawn());
8462 EXPECT_FALSE(root->visited());
8463 EXPECT_FALSE(root->sorted_for_recursion());
8464 EXPECT_FALSE(child->layer_or_descendant_is_drawn());
8465 EXPECT_FALSE(child->visited());
8466 EXPECT_FALSE(child->sorted_for_recursion());
8469 } // namespace
8470 } // namespace cc