Task Manager: Remove goat teleporter.
[chromium-blink-merge.git] / cc / trees / layer_tree_host_unittest_occlusion.cc
blob3a572d352c2913d2db1eacac3d0895ad8796cab6
1 // Copyright 2012 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.h"
7 #include "cc/layers/layer.h"
8 #include "cc/output/copy_output_request.h"
9 #include "cc/output/copy_output_result.h"
10 #include "cc/test/layer_tree_test.h"
11 #include "cc/test/test_occlusion_tracker.h"
13 namespace cc {
14 namespace {
16 class TestLayer : public Layer {
17 public:
18 static scoped_refptr<TestLayer> Create() {
19 return make_scoped_refptr(new TestLayer());
22 virtual bool Update(ResourceUpdateQueue* update_queue,
23 const OcclusionTracker<Layer>* occlusion) OVERRIDE {
24 if (!occlusion)
25 return false;
27 const TestOcclusionTracker<Layer>* test_occlusion =
28 static_cast<const TestOcclusionTracker<Layer>*>(occlusion);
29 occlusion_ = UnionSimpleEnclosedRegions(
30 test_occlusion->occlusion_from_inside_target(),
31 test_occlusion->occlusion_from_outside_target());
32 return false;
35 const SimpleEnclosedRegion& occlusion() const { return occlusion_; }
36 const SimpleEnclosedRegion& expected_occlusion() const {
37 return expected_occlusion_;
39 void set_expected_occlusion(const gfx::Rect& occlusion) {
40 expected_occlusion_ = SimpleEnclosedRegion(occlusion);
43 private:
44 TestLayer() : Layer() {
45 SetIsDrawable(true);
47 virtual ~TestLayer() {}
49 SimpleEnclosedRegion occlusion_;
50 SimpleEnclosedRegion expected_occlusion_;
53 class LayerTreeHostOcclusionTest : public LayerTreeTest {
54 public:
55 LayerTreeHostOcclusionTest()
56 : root_(TestLayer::Create()),
57 child_(TestLayer::Create()),
58 child2_(TestLayer::Create()),
59 grand_child_(TestLayer::Create()),
60 mask_(TestLayer::Create()) {
63 virtual void BeginTest() OVERRIDE {
64 PostSetNeedsCommitToMainThread();
67 virtual void DidCommit() OVERRIDE {
68 TestLayer* root = static_cast<TestLayer*>(layer_tree_host()->root_layer());
69 VerifyOcclusion(root);
71 EndTest();
74 virtual void AfterTest() OVERRIDE {}
76 void VerifyOcclusion(TestLayer* layer) const {
77 EXPECT_EQ(layer->expected_occlusion().ToString(),
78 layer->occlusion().ToString());
80 for (size_t i = 0; i < layer->children().size(); ++i) {
81 TestLayer* child = static_cast<TestLayer*>(layer->children()[i].get());
82 VerifyOcclusion(child);
86 void SetLayerPropertiesForTesting(TestLayer* layer,
87 TestLayer* parent,
88 const gfx::Transform& transform,
89 const gfx::PointF& position,
90 const gfx::Size& bounds,
91 bool opaque) const {
92 layer->RemoveAllChildren();
93 if (parent)
94 parent->AddChild(layer);
95 layer->SetTransform(transform);
96 layer->SetPosition(position);
97 layer->SetBounds(bounds);
98 layer->SetContentsOpaque(opaque);
101 protected:
102 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
103 settings->minimum_occlusion_tracking_size = gfx::Size();
106 scoped_refptr<TestLayer> root_;
107 scoped_refptr<TestLayer> child_;
108 scoped_refptr<TestLayer> child2_;
109 scoped_refptr<TestLayer> grand_child_;
110 scoped_refptr<TestLayer> mask_;
112 gfx::Transform identity_matrix_;
116 class LayerTreeHostOcclusionTestOcclusionSurfaceClipping
117 : public LayerTreeHostOcclusionTest {
118 public:
119 virtual void SetupTree() OVERRIDE {
120 // The child layer is a surface and the grand_child is opaque, but clipped
121 // to the child and root
122 SetLayerPropertiesForTesting(
123 root_.get(), NULL, identity_matrix_,
124 gfx::PointF(0.f, 0.f), gfx::Size(200, 200), true);
125 SetLayerPropertiesForTesting(
126 child_.get(), root_.get(), identity_matrix_,
127 gfx::PointF(10.f, 10.f), gfx::Size(500, 500), false);
128 SetLayerPropertiesForTesting(
129 grand_child_.get(), child_.get(), identity_matrix_,
130 gfx::PointF(-10.f, -10.f), gfx::Size(20, 500), true);
132 child_->SetMasksToBounds(true);
133 child_->SetForceRenderSurface(true);
135 child_->set_expected_occlusion(gfx::Rect(0, 0, 10, 190));
136 root_->set_expected_occlusion(gfx::Rect(10, 10, 10, 190));
138 layer_tree_host()->SetRootLayer(root_);
139 LayerTreeTest::SetupTree();
143 SINGLE_AND_MULTI_THREAD_TEST_F(
144 LayerTreeHostOcclusionTestOcclusionSurfaceClipping);
146 class LayerTreeHostOcclusionTestOcclusionSurfaceClippingOpaque
147 : public LayerTreeHostOcclusionTest {
148 public:
149 virtual void SetupTree() OVERRIDE {
150 // If the child layer is opaque, then it adds to the occlusion seen by the
151 // root_.
152 SetLayerPropertiesForTesting(
153 root_.get(), NULL, identity_matrix_,
154 gfx::PointF(0.f, 0.f), gfx::Size(200, 200), true);
155 SetLayerPropertiesForTesting(
156 child_.get(), root_.get(), identity_matrix_,
157 gfx::PointF(10.f, 10.f), gfx::Size(500, 500), true);
158 SetLayerPropertiesForTesting(
159 grand_child_.get(), child_.get(), identity_matrix_,
160 gfx::PointF(-10.f, -10.f), gfx::Size(20, 500), true);
162 child_->SetMasksToBounds(true);
163 child_->SetForceRenderSurface(true);
165 child_->set_expected_occlusion(gfx::Rect(0, 0, 10, 190));
166 root_->set_expected_occlusion(gfx::Rect(10, 10, 190, 190));
168 layer_tree_host()->SetRootLayer(root_);
169 LayerTreeTest::SetupTree();
173 SINGLE_AND_MULTI_THREAD_TEST_F(
174 LayerTreeHostOcclusionTestOcclusionSurfaceClippingOpaque);
176 class LayerTreeHostOcclusionTestOcclusionTwoChildren
177 : public LayerTreeHostOcclusionTest {
178 public:
179 virtual void SetupTree() OVERRIDE {
180 // Add a second child to the root layer and the regions should merge
181 SetLayerPropertiesForTesting(
182 root_.get(), NULL, identity_matrix_,
183 gfx::PointF(0.f, 0.f), gfx::Size(200, 200), true);
184 SetLayerPropertiesForTesting(
185 child_.get(), root_.get(), identity_matrix_,
186 gfx::PointF(10.f, 10.f), gfx::Size(500, 500), false);
187 SetLayerPropertiesForTesting(
188 grand_child_.get(), child_.get(), identity_matrix_,
189 gfx::PointF(-10.f, -10.f), gfx::Size(20, 500), true);
190 SetLayerPropertiesForTesting(
191 child2_.get(), root_.get(), identity_matrix_,
192 gfx::PointF(20.f, 10.f), gfx::Size(10, 500), true);
194 child_->SetMasksToBounds(true);
195 child_->SetForceRenderSurface(true);
197 grand_child_->set_expected_occlusion(gfx::Rect(10, 0, 10, 190));
198 child_->set_expected_occlusion(gfx::Rect(0, 0, 20, 190));
199 root_->set_expected_occlusion(gfx::Rect(10, 10, 20, 190));
201 layer_tree_host()->SetRootLayer(root_);
202 LayerTreeTest::SetupTree();
206 SINGLE_AND_MULTI_THREAD_TEST_F(
207 LayerTreeHostOcclusionTestOcclusionTwoChildren);
209 class LayerTreeHostOcclusionTestOcclusionMask
210 : public LayerTreeHostOcclusionTest {
211 public:
212 virtual void SetupTree() OVERRIDE {
213 // If the child layer has a mask on it, then it shouldn't contribute to
214 // occlusion on stuff below it.
215 SetLayerPropertiesForTesting(
216 root_.get(), NULL, identity_matrix_,
217 gfx::PointF(0.f, 0.f), gfx::Size(200, 200), true);
218 SetLayerPropertiesForTesting(
219 child2_.get(), root_.get(), identity_matrix_,
220 gfx::PointF(10.f, 10.f), gfx::Size(500, 500), true);
221 SetLayerPropertiesForTesting(
222 child_.get(), root_.get(), identity_matrix_,
223 gfx::PointF(20.f, 20.f), gfx::Size(500, 500), true);
224 SetLayerPropertiesForTesting(
225 grand_child_.get(), child_.get(), identity_matrix_,
226 gfx::PointF(-10.f, -10.f), gfx::Size(500, 500), true);
228 child_->SetMasksToBounds(true);
229 child_->SetForceRenderSurface(true);
230 child_->SetMaskLayer(mask_.get());
232 child_->set_expected_occlusion(gfx::Rect(0, 0, 180, 180));
233 root_->set_expected_occlusion(gfx::Rect(10, 10, 190, 190));
235 layer_tree_host()->SetRootLayer(root_);
236 LayerTreeTest::SetupTree();
240 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestOcclusionMask);
242 class LayerTreeHostOcclusionTestOcclusionMaskBelowOcclusion
243 : public LayerTreeHostOcclusionTest {
244 public:
245 virtual void SetupTree() OVERRIDE {
246 // If the child layer with a mask is below child2, then child2 should
247 // contribute to occlusion on everything, and child shouldn't contribute
248 // to the root_.
249 SetLayerPropertiesForTesting(
250 root_.get(), NULL, identity_matrix_,
251 gfx::PointF(0.f, 0.f), gfx::Size(200, 200), true);
252 SetLayerPropertiesForTesting(
253 child_.get(), root_.get(), identity_matrix_,
254 gfx::PointF(10.f, 10.f), gfx::Size(500, 500), true);
255 SetLayerPropertiesForTesting(
256 grand_child_.get(), child_.get(), identity_matrix_,
257 gfx::PointF(-10.f, -10.f), gfx::Size(20, 500), true);
258 SetLayerPropertiesForTesting(
259 child2_.get(), root_.get(), identity_matrix_,
260 gfx::PointF(20.f, 10.f), gfx::Size(10, 500), true);
262 child_->SetMasksToBounds(true);
263 child_->SetForceRenderSurface(true);
264 child_->SetMaskLayer(mask_.get());
266 grand_child_->set_expected_occlusion(gfx::Rect(10, 0, 10, 190));
267 child_->set_expected_occlusion(gfx::Rect(0, 0, 20, 190));
268 root_->set_expected_occlusion(gfx::Rect(20, 10, 10, 190));
270 layer_tree_host()->SetRootLayer(root_);
271 LayerTreeTest::SetupTree();
275 SINGLE_AND_MULTI_THREAD_TEST_F(
276 LayerTreeHostOcclusionTestOcclusionMaskBelowOcclusion);
278 class LayerTreeHostOcclusionTestOcclusionOpacity
279 : public LayerTreeHostOcclusionTest {
280 public:
281 virtual void SetupTree() OVERRIDE {
282 // If the child layer has a non-opaque opacity, then it shouldn't
283 // contribute to occlusion on stuff below it
284 SetLayerPropertiesForTesting(
285 root_.get(), NULL, identity_matrix_,
286 gfx::PointF(0.f, 0.f), gfx::Size(200, 200), true);
287 SetLayerPropertiesForTesting(
288 child2_.get(), root_.get(), identity_matrix_,
289 gfx::PointF(20.f, 10.f), gfx::Size(10, 500), true);
290 SetLayerPropertiesForTesting(
291 child_.get(), root_.get(), identity_matrix_,
292 gfx::PointF(10.f, 10.f), gfx::Size(500, 500), true);
293 SetLayerPropertiesForTesting(
294 grand_child_.get(), child_.get(), identity_matrix_,
295 gfx::PointF(-10.f, -10.f), gfx::Size(20, 500), true);
297 child_->SetMasksToBounds(true);
298 child_->SetForceRenderSurface(true);
299 child_->SetOpacity(0.5f);
301 child_->set_expected_occlusion(gfx::Rect(0, 0, 10, 190));
302 root_->set_expected_occlusion(gfx::Rect(20, 10, 10, 190));
304 layer_tree_host()->SetRootLayer(root_);
305 LayerTreeTest::SetupTree();
309 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestOcclusionOpacity);
311 class LayerTreeHostOcclusionTestOcclusionOpacityBelowOcclusion
312 : public LayerTreeHostOcclusionTest {
313 public:
314 virtual void SetupTree() OVERRIDE {
315 // If the child layer with non-opaque opacity is below child2, then
316 // child2 should contribute to occlusion on everything, and child shouldn't
317 // contribute to the root_.
318 SetLayerPropertiesForTesting(
319 root_.get(), NULL, identity_matrix_,
320 gfx::PointF(0.f, 0.f), gfx::Size(200, 200), true);
321 SetLayerPropertiesForTesting(
322 child_.get(), root_.get(), identity_matrix_,
323 gfx::PointF(10.f, 10.f), gfx::Size(500, 500), true);
324 SetLayerPropertiesForTesting(
325 grand_child_.get(), child_.get(), identity_matrix_,
326 gfx::PointF(-10.f, -10.f), gfx::Size(20, 500), true);
327 SetLayerPropertiesForTesting(
328 child2_.get(), root_.get(), identity_matrix_,
329 gfx::PointF(20.f, 10.f), gfx::Size(10, 500), true);
331 child_->SetMasksToBounds(true);
332 child_->SetForceRenderSurface(true);
333 child_->SetOpacity(0.5f);
335 grand_child_->set_expected_occlusion(gfx::Rect(10, 0, 10, 190));
336 child_->set_expected_occlusion(gfx::Rect(0, 0, 20, 190));
337 root_->set_expected_occlusion(gfx::Rect(20, 10, 10, 190));
339 layer_tree_host()->SetRootLayer(root_);
340 LayerTreeTest::SetupTree();
344 SINGLE_AND_MULTI_THREAD_TEST_F(
345 LayerTreeHostOcclusionTestOcclusionOpacityBelowOcclusion);
347 class LayerTreeHostOcclusionTestOcclusionBlending
348 : public LayerTreeHostOcclusionTest {
349 public:
350 virtual void SetupTree() OVERRIDE {
351 // If the child layer has a blend mode, then it shouldn't
352 // contribute to occlusion on stuff below it
353 SetLayerPropertiesForTesting(
354 root_.get(), NULL, identity_matrix_,
355 gfx::PointF(0.f, 0.f), gfx::Size(200, 200), true);
356 SetLayerPropertiesForTesting(
357 child2_.get(), root_.get(), identity_matrix_,
358 gfx::PointF(20.f, 10.f), gfx::Size(10, 500), true);
359 SetLayerPropertiesForTesting(
360 child_.get(), root_.get(), identity_matrix_,
361 gfx::PointF(10.f, 10.f), gfx::Size(500, 500), true);
362 SetLayerPropertiesForTesting(
363 grand_child_.get(), child_.get(), identity_matrix_,
364 gfx::PointF(-10.f, -10.f), gfx::Size(20, 500), true);
366 child_->SetMasksToBounds(true);
367 child_->SetBlendMode(SkXfermode::kMultiply_Mode);
368 child_->SetForceRenderSurface(true);
370 child_->set_expected_occlusion(gfx::Rect(0, 0, 10, 190));
371 root_->set_expected_occlusion(gfx::Rect(20, 10, 10, 190));
373 layer_tree_host()->SetRootLayer(root_);
374 LayerTreeTest::SetupTree();
378 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestOcclusionBlending);
380 class LayerTreeHostOcclusionTestOcclusionBlendingBelowOcclusion
381 : public LayerTreeHostOcclusionTest {
382 public:
383 virtual void SetupTree() OVERRIDE {
384 // If the child layer with a blend mode is below child2, then
385 // child2 should contribute to occlusion on everything, and child shouldn't
386 // contribute to the root_.
387 SetLayerPropertiesForTesting(
388 root_.get(), NULL, identity_matrix_,
389 gfx::PointF(0.f, 0.f), gfx::Size(200, 200), true);
390 SetLayerPropertiesForTesting(
391 child_.get(), root_.get(), identity_matrix_,
392 gfx::PointF(10.f, 10.f), gfx::Size(500, 500), true);
393 SetLayerPropertiesForTesting(
394 grand_child_.get(), child_.get(), identity_matrix_,
395 gfx::PointF(-10.f, -10.f), gfx::Size(20, 500), true);
396 SetLayerPropertiesForTesting(
397 child2_.get(), root_.get(), identity_matrix_,
398 gfx::PointF(20.f, 10.f), gfx::Size(10, 500), true);
400 child_->SetMasksToBounds(true);
401 child_->SetBlendMode(SkXfermode::kMultiply_Mode);
403 grand_child_->set_expected_occlusion(gfx::Rect(10, 0, 10, 190));
404 child_->set_expected_occlusion(gfx::Rect(0, 0, 20, 190));
405 root_->set_expected_occlusion(gfx::Rect(20, 10, 10, 190));
407 layer_tree_host()->SetRootLayer(root_);
408 LayerTreeTest::SetupTree();
412 SINGLE_AND_MULTI_THREAD_TEST_F(
413 LayerTreeHostOcclusionTestOcclusionBlendingBelowOcclusion);
415 class LayerTreeHostOcclusionTestOcclusionOpacityFilter
416 : public LayerTreeHostOcclusionTest {
417 public:
418 virtual void SetupTree() OVERRIDE {
419 FilterOperations filters;
420 filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
422 // If the child layer has a filter that changes alpha values, and is below
423 // child2, then child2 should contribute to occlusion on everything,
424 // and child shouldn't contribute to the root
425 SetLayerPropertiesForTesting(
426 root_.get(), NULL, identity_matrix_,
427 gfx::PointF(0.f, 0.f), gfx::Size(200, 200), true);
428 SetLayerPropertiesForTesting(child_.get(),
429 root_.get(),
430 identity_matrix_,
431 gfx::PointF(0.f, 0.f),
432 gfx::Size(500, 500),
433 true);
434 SetLayerPropertiesForTesting(grand_child_.get(),
435 child_.get(),
436 identity_matrix_,
437 gfx::PointF(0.f, 0.f),
438 gfx::Size(500, 500),
439 true);
440 SetLayerPropertiesForTesting(child2_.get(),
441 root_.get(),
442 identity_matrix_,
443 gfx::PointF(10.f, 10.f),
444 gfx::Size(30, 30),
445 true);
447 child_->SetMasksToBounds(true);
448 child_->SetFilters(filters);
450 // child2_ occludes grand_child_, showing it does occlude inside child_'s
451 // subtree.
452 grand_child_->set_expected_occlusion(gfx::Rect(10, 10, 30, 30));
453 // grand_child_ occludes child_, showing there is more occlusion in
454 // child_'s subtree.
455 child_->set_expected_occlusion(gfx::Rect(0, 0, 200, 200));
456 // child2_'s occlusion reaches the root, but child_'s subtree does not.
457 root_->set_expected_occlusion(gfx::Rect(10, 10, 30, 30));
459 layer_tree_host()->SetRootLayer(root_);
460 LayerTreeTest::SetupTree();
464 SINGLE_AND_MULTI_THREAD_TEST_F(
465 LayerTreeHostOcclusionTestOcclusionOpacityFilter);
467 class LayerTreeHostOcclusionTestOcclusionBlurFilter
468 : public LayerTreeHostOcclusionTest {
469 public:
470 virtual void SetupTree() OVERRIDE {
471 gfx::Transform child_transform;
472 child_transform.Translate(250.0, 250.0);
473 child_transform.Rotate(90.0);
474 child_transform.Translate(-250.0, -250.0);
476 FilterOperations filters;
477 filters.Append(FilterOperation::CreateBlurFilter(10.f));
479 // If the child layer has a filter that moves pixels/changes alpha, and is
480 // below child2, then child should not inherit occlusion from outside its
481 // subtree, and should not contribute to the root
482 SetLayerPropertiesForTesting(
483 root_.get(), NULL, identity_matrix_,
484 gfx::PointF(0.f, 0.f), gfx::Size(200, 200), true);
485 SetLayerPropertiesForTesting(
486 child_.get(), root_.get(), child_transform,
487 gfx::PointF(30.f, 30.f), gfx::Size(500, 500), true);
488 SetLayerPropertiesForTesting(
489 grand_child_.get(), child_.get(), identity_matrix_,
490 gfx::PointF(10.f, 10.f), gfx::Size(500, 500), true);
491 SetLayerPropertiesForTesting(
492 child2_.get(), root_.get(), identity_matrix_,
493 gfx::PointF(10.f, 70.f), gfx::Size(500, 500), true);
495 child_->SetMasksToBounds(true);
496 child_->SetFilters(filters);
498 child_->set_expected_occlusion(gfx::Rect(10, 330, 160, 170));
499 root_->set_expected_occlusion(gfx::Rect(10, 70, 190, 130));
501 layer_tree_host()->SetRootLayer(root_);
502 LayerTreeTest::SetupTree();
506 SINGLE_AND_MULTI_THREAD_TEST_F(
507 LayerTreeHostOcclusionTestOcclusionBlurFilter);
509 class LayerTreeHostOcclusionTestOcclusionCopyRequest
510 : public LayerTreeHostOcclusionTest {
511 public:
512 static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
514 virtual void SetupTree() OVERRIDE {
515 // If the child layer has copy request, and is below child2,
516 // then child should not inherit occlusion from outside its subtree.
517 // The child layer will still receive occlusion from inside, and
518 // the root layer will recive occlusion from child.
519 SetLayerPropertiesForTesting(
520 root_.get(), NULL, identity_matrix_,
521 gfx::PointF(), gfx::Size(100, 100), true);
522 SetLayerPropertiesForTesting(
523 child_.get(), root_.get(), identity_matrix_,
524 gfx::PointF(), gfx::Size(75, 75), true);
525 SetLayerPropertiesForTesting(
526 grand_child_.get(), child_.get(), identity_matrix_,
527 gfx::PointF(), gfx::Size(75, 50), true);
528 SetLayerPropertiesForTesting(
529 child2_.get(), root_.get(), identity_matrix_,
530 gfx::PointF(0.f, 25.f), gfx::Size(75, 75), true);
532 child_->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest(
533 base::Bind(&CopyOutputCallback)));
534 EXPECT_TRUE(child_->HasCopyRequest());
536 child_->set_expected_occlusion(gfx::Rect(0, 0, 75, 50));
537 root_->set_expected_occlusion(gfx::Rect(0, 0, 75, 100));
539 layer_tree_host()->SetRootLayer(root_);
540 LayerTreeTest::SetupTree();
544 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestOcclusionCopyRequest);
546 class LayerTreeHostOcclusionTestOcclusionReplica
547 : public LayerTreeHostOcclusionTest {
548 public:
549 virtual void SetupTree() OVERRIDE {
550 // If the child layer has copy request, and is below child2,
551 // then child should not inherit occlusion from outside its subtree.
552 // The child layer will still receive occlusion from inside, and
553 // the root layer will recive occlusion from child.
554 SetLayerPropertiesForTesting(
555 root_.get(), NULL, identity_matrix_,
556 gfx::PointF(), gfx::Size(100, 100), true);
557 SetLayerPropertiesForTesting(
558 child_.get(), root_.get(), identity_matrix_,
559 gfx::PointF(), gfx::Size(75, 75), true);
560 SetLayerPropertiesForTesting(
561 grand_child_.get(), child_.get(), identity_matrix_,
562 gfx::PointF(), gfx::Size(75, 50), true);
563 SetLayerPropertiesForTesting(
564 child2_.get(), root_.get(), identity_matrix_,
565 gfx::PointF(0.f, 25.f), gfx::Size(75, 75), true);
567 scoped_refptr<Layer> replica_layer(Layer::Create());
568 child_->SetReplicaLayer(replica_layer.get());
569 EXPECT_TRUE(child_->has_replica());
571 child_->set_expected_occlusion(gfx::Rect(0, 0, 75, 50));
572 root_->set_expected_occlusion(gfx::Rect(0, 0, 75, 100));
574 layer_tree_host()->SetRootLayer(root_);
575 LayerTreeTest::SetupTree();
579 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestOcclusionReplica);
581 class LayerTreeHostOcclusionTestManySurfaces
582 : public LayerTreeHostOcclusionTest {
583 public:
584 virtual void SetupTree() OVERRIDE {
585 // We create enough RenderSurfaces that it will trigger Vector reallocation
586 // while computing occlusion.
587 std::vector<scoped_refptr<TestLayer> > layers;
588 int num_surfaces = 200;
589 int root_width = 400;
590 int root_height = 400;
592 for (int i = 0; i < num_surfaces; ++i) {
593 layers.push_back(TestLayer::Create());
594 if (i == 0) {
595 SetLayerPropertiesForTesting(
596 layers.back().get(), NULL, identity_matrix_,
597 gfx::PointF(0.f, 0.f),
598 gfx::Size(root_width, root_height), true);
599 } else {
600 SetLayerPropertiesForTesting(
601 layers.back().get(), layers[layers.size() - 2].get(),
602 identity_matrix_,
603 gfx::PointF(1.f, 1.f),
604 gfx::Size(root_width-i, root_height-i), true);
605 layers.back()->SetForceRenderSurface(true);
609 for (int i = 1; i < num_surfaces; ++i) {
610 scoped_refptr<TestLayer> child = TestLayer::Create();
611 SetLayerPropertiesForTesting(
612 child.get(), layers[i].get(), identity_matrix_,
613 gfx::PointF(0.f, 0.f), gfx::Size(root_width, root_height), false);
616 for (int i = 0; i < num_surfaces-1; ++i) {
617 gfx::Rect expected_occlusion(1, 1, root_width-i-1, root_height-i-1);
618 layers[i]->set_expected_occlusion(expected_occlusion);
621 layer_tree_host()->SetRootLayer(layers[0]);
622 LayerTreeTest::SetupTree();
626 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostOcclusionTestManySurfaces);
628 } // namespace
629 } // namespace cc