OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "cc/layers/content_layer.h" | 8 #include "cc/layers/content_layer.h" |
9 #include "cc/layers/delegated_frame_provider.h" | 9 #include "cc/layers/delegated_frame_provider.h" |
10 #include "cc/layers/delegated_frame_resource_collection.h" | 10 #include "cc/layers/delegated_frame_resource_collection.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "cc/resources/single_release_callback.h" | 21 #include "cc/resources/single_release_callback.h" |
22 #include "cc/test/fake_content_layer.h" | 22 #include "cc/test/fake_content_layer.h" |
23 #include "cc/test/fake_content_layer_client.h" | 23 #include "cc/test/fake_content_layer_client.h" |
24 #include "cc/test/fake_content_layer_impl.h" | 24 #include "cc/test/fake_content_layer_impl.h" |
25 #include "cc/test/fake_delegated_renderer_layer.h" | 25 #include "cc/test/fake_delegated_renderer_layer.h" |
26 #include "cc/test/fake_delegated_renderer_layer_impl.h" | 26 #include "cc/test/fake_delegated_renderer_layer_impl.h" |
27 #include "cc/test/fake_layer_tree_host_client.h" | 27 #include "cc/test/fake_layer_tree_host_client.h" |
28 #include "cc/test/fake_output_surface.h" | 28 #include "cc/test/fake_output_surface.h" |
29 #include "cc/test/fake_output_surface_client.h" | 29 #include "cc/test/fake_output_surface_client.h" |
30 #include "cc/test/fake_painted_scrollbar_layer.h" | 30 #include "cc/test/fake_painted_scrollbar_layer.h" |
31 #include "cc/test/fake_picture_layer.h" | |
32 #include "cc/test/fake_picture_layer_impl.h" | |
33 #include "cc/test/fake_scoped_ui_resource.h" | 31 #include "cc/test/fake_scoped_ui_resource.h" |
34 #include "cc/test/fake_scrollbar.h" | 32 #include "cc/test/fake_scrollbar.h" |
35 #include "cc/test/fake_video_frame_provider.h" | 33 #include "cc/test/fake_video_frame_provider.h" |
36 #include "cc/test/layer_tree_test.h" | 34 #include "cc/test/layer_tree_test.h" |
37 #include "cc/test/render_pass_test_common.h" | 35 #include "cc/test/render_pass_test_common.h" |
38 #include "cc/test/test_context_provider.h" | 36 #include "cc/test/test_context_provider.h" |
39 #include "cc/test/test_shared_bitmap_manager.h" | 37 #include "cc/test/test_shared_bitmap_manager.h" |
40 #include "cc/test/test_web_graphics_context_3d.h" | 38 #include "cc/test/test_web_graphics_context_3d.h" |
41 #include "cc/trees/layer_tree_host_impl.h" | 39 #include "cc/trees/layer_tree_host_impl.h" |
42 #include "cc/trees/layer_tree_impl.h" | 40 #include "cc/trees/layer_tree_impl.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 LayerTreeHostClientNotReadyDoesNotCreateOutputSurface); | 316 LayerTreeHostClientNotReadyDoesNotCreateOutputSurface); |
319 | 317 |
320 class LayerTreeHostContextTestLostContextSucceedsWithContent | 318 class LayerTreeHostContextTestLostContextSucceedsWithContent |
321 : public LayerTreeHostContextTestLostContextSucceeds { | 319 : public LayerTreeHostContextTestLostContextSucceeds { |
322 public: | 320 public: |
323 virtual void SetupTree() OVERRIDE { | 321 virtual void SetupTree() OVERRIDE { |
324 root_ = Layer::Create(); | 322 root_ = Layer::Create(); |
325 root_->SetBounds(gfx::Size(10, 10)); | 323 root_->SetBounds(gfx::Size(10, 10)); |
326 root_->SetIsDrawable(true); | 324 root_->SetIsDrawable(true); |
327 | 325 |
328 // Paint non-solid color. | 326 content_ = FakeContentLayer::Create(&client_); |
329 SkPaint paint; | 327 content_->SetBounds(gfx::Size(10, 10)); |
330 paint.setColor(SkColorSetARGB(100, 80, 200, 200)); | 328 content_->SetIsDrawable(true); |
331 client_.add_draw_rect(gfx::Rect(0, 0, 5, 5), paint); | |
332 | 329 |
333 if (layer_tree_host()->settings().impl_side_painting) | 330 root_->AddChild(content_); |
334 layer_ = FakePictureLayer::Create(&client_); | |
335 else | |
336 layer_ = FakeContentLayer::Create(&client_); | |
337 layer_->SetBounds(gfx::Size(10, 10)); | |
338 layer_->SetIsDrawable(true); | |
339 | |
340 root_->AddChild(layer_); | |
341 | 331 |
342 layer_tree_host()->SetRootLayer(root_); | 332 layer_tree_host()->SetRootLayer(root_); |
343 LayerTreeHostContextTest::SetupTree(); | 333 LayerTreeHostContextTest::SetupTree(); |
344 } | 334 } |
345 | 335 |
346 virtual void InvalidateAndSetNeedsCommit() OVERRIDE { | 336 virtual void InvalidateAndSetNeedsCommit() OVERRIDE { |
347 // Invalidate the render surface so we don't try to use a cached copy of the | 337 // Invalidate the render surface so we don't try to use a cached copy of the |
348 // surface. We want to make sure to test the drawing paths for drawing to | 338 // surface. We want to make sure to test the drawing paths for drawing to |
349 // a child surface. | 339 // a child surface. |
350 layer_->SetNeedsDisplay(); | 340 content_->SetNeedsDisplay(); |
351 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit(); | 341 LayerTreeHostContextTestLostContextSucceeds::InvalidateAndSetNeedsCommit(); |
352 } | 342 } |
353 | 343 |
354 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 344 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
355 if (!host_impl->settings().impl_side_painting) { | 345 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( |
356 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( | 346 host_impl->active_tree()->root_layer()->children()[0]); |
357 host_impl->active_tree()->root_layer()->children()[0]); | 347 // Even though the context was lost, we should have a resource. The |
358 // Even though the context was lost, we should have a resource. The | 348 // TestWebGraphicsContext3D ensures that this resource is created with |
359 // TestWebGraphicsContext3D ensures that this resource is created with | 349 // the active context. |
360 // the active context. | 350 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); |
361 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); | |
362 } else { | |
363 FakePictureLayerImpl* picture_impl = static_cast<FakePictureLayerImpl*>( | |
364 host_impl->active_tree()->root_layer()->children()[0]); | |
365 EXPECT_TRUE(picture_impl->HighResTiling()->TileAt(0, 0)->IsReadyToDraw()); | |
366 } | |
367 } | 351 } |
368 | 352 |
369 protected: | 353 protected: |
370 FakeContentLayerClient client_; | 354 FakeContentLayerClient client_; |
371 scoped_refptr<Layer> root_; | 355 scoped_refptr<Layer> root_; |
372 scoped_refptr<Layer> layer_; | 356 scoped_refptr<ContentLayer> content_; |
373 }; | 357 }; |
374 | 358 |
375 // This test uses TiledLayer and PictureLayer to check for a working context. | 359 // This test uses TiledLayer to check for a working context. |
376 SINGLE_AND_MULTI_THREAD_TEST_F( | 360 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( |
377 LayerTreeHostContextTestLostContextSucceedsWithContent); | 361 LayerTreeHostContextTestLostContextSucceedsWithContent); |
378 | 362 |
379 class LayerTreeHostContextTestCreateOutputSurfaceFails | 363 class LayerTreeHostContextTestCreateOutputSurfaceFails |
380 : public LayerTreeHostContextTest { | 364 : public LayerTreeHostContextTest { |
381 public: | 365 public: |
382 // Run a test that initially fails OutputSurface creation |times_to_fail| | 366 // Run a test that initially fails OutputSurface creation |times_to_fail| |
383 // times. If |expect_fallback_attempt| is |true|, an attempt to create a | 367 // times. If |expect_fallback_attempt| is |true|, an attempt to create a |
384 // fallback/software OutputSurface is expected to occur. | 368 // fallback/software OutputSurface is expected to occur. |
385 LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail, | 369 LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail, |
386 bool expect_fallback_attempt) | 370 bool expect_fallback_attempt) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 }; | 430 }; |
447 | 431 |
448 SINGLE_AND_MULTI_THREAD_TEST_F( | 432 SINGLE_AND_MULTI_THREAD_TEST_F( |
449 LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback); | 433 LayerTreeHostContextTestCreateOutputSurfaceFailsWithFallback); |
450 | 434 |
451 class LayerTreeHostContextTestLostContextAndEvictTextures | 435 class LayerTreeHostContextTestLostContextAndEvictTextures |
452 : public LayerTreeHostContextTest { | 436 : public LayerTreeHostContextTest { |
453 public: | 437 public: |
454 LayerTreeHostContextTestLostContextAndEvictTextures() | 438 LayerTreeHostContextTestLostContextAndEvictTextures() |
455 : LayerTreeHostContextTest(), | 439 : LayerTreeHostContextTest(), |
| 440 layer_(FakeContentLayer::Create(&client_)), |
456 impl_host_(0), | 441 impl_host_(0), |
457 num_commits_(0) {} | 442 num_commits_(0) {} |
458 | 443 |
459 virtual void SetupTree() OVERRIDE { | 444 virtual void SetupTree() OVERRIDE { |
460 if (layer_tree_host()->settings().impl_side_painting) { | 445 layer_->SetBounds(gfx::Size(10, 20)); |
461 picture_layer_ = FakePictureLayer::Create(&client_); | 446 layer_tree_host()->SetRootLayer(layer_); |
462 picture_layer_->SetBounds(gfx::Size(10, 20)); | |
463 layer_tree_host()->SetRootLayer(picture_layer_); | |
464 } else { | |
465 content_layer_ = FakeContentLayer::Create(&client_); | |
466 content_layer_->SetBounds(gfx::Size(10, 20)); | |
467 layer_tree_host()->SetRootLayer(content_layer_); | |
468 } | |
469 | |
470 LayerTreeHostContextTest::SetupTree(); | 447 LayerTreeHostContextTest::SetupTree(); |
471 } | 448 } |
472 | 449 |
473 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 450 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
474 | 451 |
475 void PostEvictTextures() { | 452 void PostEvictTextures() { |
476 if (HasImplThread()) { | 453 if (HasImplThread()) { |
477 ImplThreadTaskRunner()->PostTask( | 454 ImplThreadTaskRunner()->PostTask( |
478 FROM_HERE, | 455 FROM_HERE, |
479 base::Bind(&LayerTreeHostContextTestLostContextAndEvictTextures:: | 456 base::Bind(&LayerTreeHostContextTestLostContextAndEvictTextures:: |
480 EvictTexturesOnImplThread, | 457 EvictTexturesOnImplThread, |
481 base::Unretained(this))); | 458 base::Unretained(this))); |
482 } else { | 459 } else { |
483 DebugScopedSetImplThread impl(proxy()); | 460 DebugScopedSetImplThread impl(proxy()); |
484 EvictTexturesOnImplThread(); | 461 EvictTexturesOnImplThread(); |
485 } | 462 } |
486 } | 463 } |
487 | 464 |
488 void EvictTexturesOnImplThread() { | 465 void EvictTexturesOnImplThread() { |
489 impl_host_->EvictTexturesForTesting(); | 466 impl_host_->EvictTexturesForTesting(); |
490 if (impl_host_->settings().impl_side_painting) { | |
491 FakePictureLayerImpl* picture_impl = static_cast<FakePictureLayerImpl*>( | |
492 impl_host_->active_tree()->root_layer()->children()[0]); | |
493 EXPECT_FALSE( | |
494 picture_impl->HighResTiling()->TileAt(0, 0)->IsReadyToDraw()); | |
495 } | |
496 if (lose_after_evict_) | 467 if (lose_after_evict_) |
497 LoseContext(); | 468 LoseContext(); |
498 } | 469 } |
499 | 470 |
500 virtual void DidCommitAndDrawFrame() OVERRIDE { | 471 virtual void DidCommitAndDrawFrame() OVERRIDE { |
501 if (num_commits_ > 1) | 472 if (num_commits_ > 1) |
502 return; | 473 return; |
503 if (!layer_tree_host()->settings().impl_side_painting) { | 474 EXPECT_TRUE(layer_->HaveBackingAt(0, 0)); |
504 EXPECT_TRUE(content_layer_->HaveBackingAt(0, 0)); | |
505 } | |
506 PostEvictTextures(); | 475 PostEvictTextures(); |
507 } | 476 } |
508 | 477 |
509 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 478 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
510 if (impl->settings().impl_side_painting) { | 479 LayerTreeHostContextTest::CommitCompleteOnThread(impl); |
511 FakePictureLayerImpl* picture_impl = static_cast<FakePictureLayerImpl*>( | 480 if (num_commits_ > 1) |
512 impl->active_tree()->root_layer()->children()[0]); | 481 return; |
513 EXPECT_TRUE(picture_impl->HighResTiling()->TileAt(0, 0)->IsReadyToDraw()); | 482 ++num_commits_; |
514 } | 483 if (!lose_after_evict_) |
515 | 484 LoseContext(); |
516 impl_host_ = impl; | 485 impl_host_ = impl; |
517 } | 486 } |
518 | 487 |
519 virtual void DidInitializeOutputSurface() OVERRIDE { EndTest(); } | 488 virtual void DidInitializeOutputSurface() OVERRIDE { EndTest(); } |
520 | 489 |
521 virtual void AfterTest() OVERRIDE {} | 490 virtual void AfterTest() OVERRIDE {} |
522 | 491 |
523 protected: | 492 protected: |
524 bool lose_after_evict_; | 493 bool lose_after_evict_; |
525 FakeContentLayerClient client_; | 494 FakeContentLayerClient client_; |
526 scoped_refptr<FakeContentLayer> content_layer_; | 495 scoped_refptr<FakeContentLayer> layer_; |
527 scoped_refptr<FakePictureLayer> picture_layer_; | |
528 LayerTreeHostImpl* impl_host_; | 496 LayerTreeHostImpl* impl_host_; |
529 int num_commits_; | 497 int num_commits_; |
530 }; | 498 }; |
531 | 499 |
532 TEST_F(LayerTreeHostContextTestLostContextAndEvictTextures, | 500 TEST_F(LayerTreeHostContextTestLostContextAndEvictTextures, |
533 LoseAfterEvict_SingleThread_DirectRenderer) { | 501 LoseAfterEvict_SingleThread_DirectRenderer) { |
534 lose_after_evict_ = true; | 502 lose_after_evict_ = true; |
535 RunTest(false, false, false); | 503 RunTest(false, false, false); |
536 } | 504 } |
537 | 505 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 TEST_F(LayerTreeHostContextTestLostContextAndEvictTextures, | 561 TEST_F(LayerTreeHostContextTestLostContextAndEvictTextures, |
594 LoseBeforeEvict_MultiThread_DelegatingRenderer_ImplSidePaint) { | 562 LoseBeforeEvict_MultiThread_DelegatingRenderer_ImplSidePaint) { |
595 lose_after_evict_ = false; | 563 lose_after_evict_ = false; |
596 RunTest(true, true, true); | 564 RunTest(true, true, true); |
597 } | 565 } |
598 | 566 |
599 class LayerTreeHostContextTestLostContextWhileUpdatingResources | 567 class LayerTreeHostContextTestLostContextWhileUpdatingResources |
600 : public LayerTreeHostContextTest { | 568 : public LayerTreeHostContextTest { |
601 public: | 569 public: |
602 LayerTreeHostContextTestLostContextWhileUpdatingResources() | 570 LayerTreeHostContextTestLostContextWhileUpdatingResources() |
603 : num_children_(50), times_to_lose_on_end_query_(3) {} | 571 : parent_(FakeContentLayer::Create(&client_)), |
| 572 num_children_(50), |
| 573 times_to_lose_on_end_query_(3) {} |
604 | 574 |
605 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() OVERRIDE { | 575 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() OVERRIDE { |
606 scoped_ptr<TestWebGraphicsContext3D> context = | 576 scoped_ptr<TestWebGraphicsContext3D> context = |
607 LayerTreeHostContextTest::CreateContext3d(); | 577 LayerTreeHostContextTest::CreateContext3d(); |
608 if (times_to_lose_on_end_query_) { | 578 if (times_to_lose_on_end_query_) { |
609 --times_to_lose_on_end_query_; | 579 --times_to_lose_on_end_query_; |
610 context->set_times_end_query_succeeds(5); | 580 context->set_times_end_query_succeeds(5); |
611 } | 581 } |
612 return context.Pass(); | 582 return context.Pass(); |
613 } | 583 } |
614 | 584 |
615 virtual void SetupTree() OVERRIDE { | 585 virtual void SetupTree() OVERRIDE { |
616 if (layer_tree_host()->settings().impl_side_painting) | |
617 parent_ = FakePictureLayer::Create(&client_); | |
618 else | |
619 parent_ = FakeContentLayer::Create(&client_); | |
620 | |
621 parent_->SetBounds(gfx::Size(num_children_, 1)); | 586 parent_->SetBounds(gfx::Size(num_children_, 1)); |
622 | 587 |
623 for (int i = 0; i < num_children_; i++) { | 588 for (int i = 0; i < num_children_; i++) { |
624 scoped_refptr<Layer> child; | 589 scoped_refptr<FakeContentLayer> child = |
625 if (layer_tree_host()->settings().impl_side_painting) | 590 FakeContentLayer::Create(&client_); |
626 child = FakePictureLayer::Create(&client_); | |
627 else | |
628 child = FakeContentLayer::Create(&client_); | |
629 child->SetPosition(gfx::PointF(i, 0.f)); | 591 child->SetPosition(gfx::PointF(i, 0.f)); |
630 child->SetBounds(gfx::Size(1, 1)); | 592 child->SetBounds(gfx::Size(1, 1)); |
631 parent_->AddChild(child); | 593 parent_->AddChild(child); |
632 } | 594 } |
633 | 595 |
634 layer_tree_host()->SetRootLayer(parent_); | 596 layer_tree_host()->SetRootLayer(parent_); |
635 LayerTreeHostContextTest::SetupTree(); | 597 LayerTreeHostContextTest::SetupTree(); |
636 } | 598 } |
637 | 599 |
638 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 600 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
639 | 601 |
640 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 602 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
641 EXPECT_EQ(0, times_to_lose_on_end_query_); | 603 EXPECT_EQ(0, times_to_lose_on_end_query_); |
642 EndTest(); | 604 EndTest(); |
643 } | 605 } |
644 | 606 |
645 virtual void AfterTest() OVERRIDE { | 607 virtual void AfterTest() OVERRIDE { |
646 EXPECT_EQ(0, times_to_lose_on_end_query_); | 608 EXPECT_EQ(0, times_to_lose_on_end_query_); |
647 } | 609 } |
648 | 610 |
649 private: | 611 private: |
650 FakeContentLayerClient client_; | 612 FakeContentLayerClient client_; |
651 scoped_refptr<Layer> parent_; | 613 scoped_refptr<FakeContentLayer> parent_; |
652 int num_children_; | 614 int num_children_; |
653 int times_to_lose_on_end_query_; | 615 int times_to_lose_on_end_query_; |
654 }; | 616 }; |
655 | 617 |
656 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( | 618 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( |
657 LayerTreeHostContextTestLostContextWhileUpdatingResources); | 619 LayerTreeHostContextTestLostContextWhileUpdatingResources); |
658 | 620 |
659 class LayerTreeHostContextTestLayersNotified : public LayerTreeHostContextTest { | 621 class LayerTreeHostContextTestLayersNotified : public LayerTreeHostContextTest { |
660 public: | 622 public: |
661 LayerTreeHostContextTestLayersNotified() | 623 LayerTreeHostContextTestLayersNotified() |
662 : LayerTreeHostContextTest(), num_commits_(0) {} | 624 : LayerTreeHostContextTest(), num_commits_(0) {} |
663 | 625 |
664 virtual void SetupTree() OVERRIDE { | 626 virtual void SetupTree() OVERRIDE { |
665 if (layer_tree_host()->settings().impl_side_painting) { | 627 root_ = FakeContentLayer::Create(&client_); |
666 root_ = FakePictureLayer::Create(&client_); | 628 child_ = FakeContentLayer::Create(&client_); |
667 child_ = FakePictureLayer::Create(&client_); | 629 grandchild_ = FakeContentLayer::Create(&client_); |
668 grandchild_ = FakePictureLayer::Create(&client_); | |
669 } else { | |
670 root_ = FakeContentLayer::Create(&client_); | |
671 child_ = FakeContentLayer::Create(&client_); | |
672 grandchild_ = FakeContentLayer::Create(&client_); | |
673 } | |
674 | 630 |
675 root_->AddChild(child_); | 631 root_->AddChild(child_); |
676 child_->AddChild(grandchild_); | 632 child_->AddChild(grandchild_); |
677 | 633 |
678 layer_tree_host()->SetRootLayer(root_); | 634 layer_tree_host()->SetRootLayer(root_); |
679 LayerTreeHostContextTest::SetupTree(); | 635 LayerTreeHostContextTest::SetupTree(); |
680 } | 636 } |
681 | 637 |
682 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 638 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
683 | 639 |
684 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 640 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
685 LayerTreeHostContextTest::DidActivateTreeOnThread(host_impl); | 641 LayerTreeHostContextTest::DidActivateTreeOnThread(host_impl); |
686 | 642 |
687 FakePictureLayerImpl* root_picture = NULL; | 643 FakeContentLayerImpl* root = static_cast<FakeContentLayerImpl*>( |
688 FakePictureLayerImpl* child_picture = NULL; | 644 host_impl->active_tree()->root_layer()); |
689 FakePictureLayerImpl* grandchild_picture = NULL; | 645 FakeContentLayerImpl* child = |
690 FakeContentLayerImpl* root_content = NULL; | 646 static_cast<FakeContentLayerImpl*>(root->children()[0]); |
691 FakeContentLayerImpl* child_content = NULL; | 647 FakeContentLayerImpl* grandchild = |
692 FakeContentLayerImpl* grandchild_content = NULL; | 648 static_cast<FakeContentLayerImpl*>(child->children()[0]); |
693 | |
694 if (layer_tree_host()->settings().impl_side_painting) { | |
695 root_picture = static_cast<FakePictureLayerImpl*>( | |
696 host_impl->active_tree()->root_layer()); | |
697 child_picture = | |
698 static_cast<FakePictureLayerImpl*>(root_picture->children()[0]); | |
699 grandchild_picture = | |
700 static_cast<FakePictureLayerImpl*>(child_picture->children()[0]); | |
701 | |
702 } else { | |
703 root_content = static_cast<FakeContentLayerImpl*>( | |
704 host_impl->active_tree()->root_layer()); | |
705 child_content = | |
706 static_cast<FakeContentLayerImpl*>(root_content->children()[0]); | |
707 grandchild_content = | |
708 static_cast<FakeContentLayerImpl*>(child_content->children()[0]); | |
709 } | |
710 | 649 |
711 ++num_commits_; | 650 ++num_commits_; |
712 switch (num_commits_) { | 651 switch (num_commits_) { |
713 case 1: | 652 case 1: |
714 if (layer_tree_host()->settings().impl_side_painting) { | 653 EXPECT_EQ(0u, root->lost_output_surface_count()); |
715 EXPECT_EQ(0u, root_picture->release_resources_count()); | 654 EXPECT_EQ(0u, child->lost_output_surface_count()); |
716 EXPECT_EQ(0u, child_picture->release_resources_count()); | 655 EXPECT_EQ(0u, grandchild->lost_output_surface_count()); |
717 EXPECT_EQ(0u, grandchild_picture->release_resources_count()); | |
718 } else { | |
719 EXPECT_EQ(0u, root_content->lost_output_surface_count()); | |
720 EXPECT_EQ(0u, child_content->lost_output_surface_count()); | |
721 EXPECT_EQ(0u, grandchild_content->lost_output_surface_count()); | |
722 } | |
723 | |
724 // Lose the context and struggle to recreate it. | 656 // Lose the context and struggle to recreate it. |
725 LoseContext(); | 657 LoseContext(); |
726 times_to_fail_create_ = 1; | 658 times_to_fail_create_ = 1; |
727 break; | 659 break; |
728 case 2: | 660 case 2: |
729 if (layer_tree_host()->settings().impl_side_painting) { | 661 EXPECT_GE(1u, root->lost_output_surface_count()); |
730 EXPECT_TRUE(root_picture->release_resources_count()); | 662 EXPECT_GE(1u, child->lost_output_surface_count()); |
731 EXPECT_TRUE(child_picture->release_resources_count()); | 663 EXPECT_GE(1u, grandchild->lost_output_surface_count()); |
732 EXPECT_TRUE(grandchild_picture->release_resources_count()); | |
733 } else { | |
734 EXPECT_TRUE(root_content->lost_output_surface_count()); | |
735 EXPECT_TRUE(child_content->lost_output_surface_count()); | |
736 EXPECT_TRUE(grandchild_content->lost_output_surface_count()); | |
737 } | |
738 | |
739 EndTest(); | 664 EndTest(); |
740 break; | 665 break; |
741 default: | 666 default: |
742 NOTREACHED(); | 667 NOTREACHED(); |
743 } | 668 } |
744 } | 669 } |
745 | 670 |
746 virtual void AfterTest() OVERRIDE {} | 671 virtual void AfterTest() OVERRIDE {} |
747 | 672 |
748 private: | 673 private: |
749 int num_commits_; | 674 int num_commits_; |
750 | 675 |
751 FakeContentLayerClient client_; | 676 FakeContentLayerClient client_; |
752 scoped_refptr<Layer> root_; | 677 scoped_refptr<FakeContentLayer> root_; |
753 scoped_refptr<Layer> child_; | 678 scoped_refptr<FakeContentLayer> child_; |
754 scoped_refptr<Layer> grandchild_; | 679 scoped_refptr<FakeContentLayer> grandchild_; |
755 }; | 680 }; |
756 | 681 |
757 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLayersNotified); | 682 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestLayersNotified); |
758 | 683 |
759 class LayerTreeHostContextTestDontUseLostResources | 684 class LayerTreeHostContextTestDontUseLostResources |
760 : public LayerTreeHostContextTest { | 685 : public LayerTreeHostContextTest { |
761 public: | 686 public: |
762 LayerTreeHostContextTestDontUseLostResources() : lost_context_(false) { | 687 LayerTreeHostContextTestDontUseLostResources() : lost_context_(false) { |
763 context_should_support_io_surface_ = true; | 688 context_should_support_io_surface_ = true; |
764 | 689 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 scoped_refptr<Layer> root = Layer::Create(); | 747 scoped_refptr<Layer> root = Layer::Create(); |
823 root->SetBounds(gfx::Size(10, 10)); | 748 root->SetBounds(gfx::Size(10, 10)); |
824 root->SetIsDrawable(true); | 749 root->SetIsDrawable(true); |
825 | 750 |
826 scoped_refptr<FakeDelegatedRendererLayer> delegated = | 751 scoped_refptr<FakeDelegatedRendererLayer> delegated = |
827 FakeDelegatedRendererLayer::Create(delegated_frame_provider_.get()); | 752 FakeDelegatedRendererLayer::Create(delegated_frame_provider_.get()); |
828 delegated->SetBounds(gfx::Size(10, 10)); | 753 delegated->SetBounds(gfx::Size(10, 10)); |
829 delegated->SetIsDrawable(true); | 754 delegated->SetIsDrawable(true); |
830 root->AddChild(delegated); | 755 root->AddChild(delegated); |
831 | 756 |
832 scoped_refptr<Layer> layer; | 757 scoped_refptr<ContentLayer> content = ContentLayer::Create(&client_); |
833 if (layer_tree_host()->settings().impl_side_painting) | 758 content->SetBounds(gfx::Size(10, 10)); |
834 layer = PictureLayer::Create(&client_); | 759 content->SetIsDrawable(true); |
835 else | 760 root->AddChild(content); |
836 layer = ContentLayer::Create(&client_); | |
837 layer->SetBounds(gfx::Size(10, 10)); | |
838 layer->SetIsDrawable(true); | |
839 root->AddChild(layer); | |
840 | 761 |
841 scoped_refptr<TextureLayer> texture = TextureLayer::CreateForMailbox(NULL); | 762 scoped_refptr<TextureLayer> texture = TextureLayer::CreateForMailbox(NULL); |
842 texture->SetBounds(gfx::Size(10, 10)); | 763 texture->SetBounds(gfx::Size(10, 10)); |
843 texture->SetIsDrawable(true); | 764 texture->SetIsDrawable(true); |
844 texture->SetTextureMailbox( | 765 texture->SetTextureMailbox( |
845 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), | 766 TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point), |
846 SingleReleaseCallback::Create( | 767 SingleReleaseCallback::Create( |
847 base::Bind(&LayerTreeHostContextTestDontUseLostResources:: | 768 base::Bind(&LayerTreeHostContextTestDontUseLostResources:: |
848 EmptyReleaseCallback))); | 769 EmptyReleaseCallback))); |
849 root->AddChild(texture); | 770 root->AddChild(texture); |
850 | 771 |
851 scoped_refptr<Layer> mask; | 772 scoped_refptr<ContentLayer> mask = ContentLayer::Create(&client_); |
852 if (layer_tree_host()->settings().impl_side_painting) | |
853 mask = PictureLayer::Create(&client_); | |
854 else | |
855 mask = ContentLayer::Create(&client_); | |
856 mask->SetBounds(gfx::Size(10, 10)); | 773 mask->SetBounds(gfx::Size(10, 10)); |
857 | 774 |
858 scoped_refptr<Layer> layer_with_mask; | 775 scoped_refptr<ContentLayer> content_with_mask = |
859 if (layer_tree_host()->settings().impl_side_painting) | 776 ContentLayer::Create(&client_); |
860 layer_with_mask = PictureLayer::Create(&client_); | 777 content_with_mask->SetBounds(gfx::Size(10, 10)); |
861 else | 778 content_with_mask->SetIsDrawable(true); |
862 layer_with_mask = ContentLayer::Create(&client_); | 779 content_with_mask->SetMaskLayer(mask.get()); |
863 layer_with_mask->SetBounds(gfx::Size(10, 10)); | 780 root->AddChild(content_with_mask); |
864 layer_with_mask->SetIsDrawable(true); | |
865 layer_with_mask->SetMaskLayer(mask.get()); | |
866 root->AddChild(layer_with_mask); | |
867 | 781 |
868 scoped_refptr<VideoLayer> video_color = | 782 scoped_refptr<VideoLayer> video_color = |
869 VideoLayer::Create(&color_frame_provider_, media::VIDEO_ROTATION_0); | 783 VideoLayer::Create(&color_frame_provider_, media::VIDEO_ROTATION_0); |
870 video_color->SetBounds(gfx::Size(10, 10)); | 784 video_color->SetBounds(gfx::Size(10, 10)); |
871 video_color->SetIsDrawable(true); | 785 video_color->SetIsDrawable(true); |
872 root->AddChild(video_color); | 786 root->AddChild(video_color); |
873 | 787 |
874 scoped_refptr<VideoLayer> video_hw = | 788 scoped_refptr<VideoLayer> video_hw = |
875 VideoLayer::Create(&hw_frame_provider_, media::VIDEO_ROTATION_0); | 789 VideoLayer::Create(&hw_frame_provider_, media::VIDEO_ROTATION_0); |
876 video_hw->SetBounds(gfx::Size(10, 10)); | 790 video_hw->SetBounds(gfx::Size(10, 10)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 root->AddChild(io_surface); | 831 root->AddChild(io_surface); |
918 } | 832 } |
919 | 833 |
920 // Enable the hud. | 834 // Enable the hud. |
921 LayerTreeDebugState debug_state; | 835 LayerTreeDebugState debug_state; |
922 debug_state.show_property_changed_rects = true; | 836 debug_state.show_property_changed_rects = true; |
923 layer_tree_host()->SetDebugState(debug_state); | 837 layer_tree_host()->SetDebugState(debug_state); |
924 | 838 |
925 scoped_refptr<PaintedScrollbarLayer> scrollbar = | 839 scoped_refptr<PaintedScrollbarLayer> scrollbar = |
926 PaintedScrollbarLayer::Create( | 840 PaintedScrollbarLayer::Create( |
927 scoped_ptr<Scrollbar>(new FakeScrollbar).Pass(), layer->id()); | 841 scoped_ptr<Scrollbar>(new FakeScrollbar).Pass(), content->id()); |
928 scrollbar->SetBounds(gfx::Size(10, 10)); | 842 scrollbar->SetBounds(gfx::Size(10, 10)); |
929 scrollbar->SetIsDrawable(true); | 843 scrollbar->SetIsDrawable(true); |
930 root->AddChild(scrollbar); | 844 root->AddChild(scrollbar); |
931 | 845 |
932 layer_tree_host()->SetRootLayer(root); | 846 layer_tree_host()->SetRootLayer(root); |
933 LayerTreeHostContextTest::SetupTree(); | 847 LayerTreeHostContextTest::SetupTree(); |
934 } | 848 } |
935 | 849 |
936 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 850 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
937 | 851 |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1490 } | 1404 } |
1491 } | 1405 } |
1492 }; | 1406 }; |
1493 | 1407 |
1494 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostEviction); | 1408 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostEviction); |
1495 | 1409 |
1496 class LayerTreeHostContextTestSurfaceCreateCallback | 1410 class LayerTreeHostContextTestSurfaceCreateCallback |
1497 : public LayerTreeHostContextTest { | 1411 : public LayerTreeHostContextTest { |
1498 public: | 1412 public: |
1499 LayerTreeHostContextTestSurfaceCreateCallback() | 1413 LayerTreeHostContextTestSurfaceCreateCallback() |
1500 : LayerTreeHostContextTest() {} | 1414 : LayerTreeHostContextTest(), |
| 1415 layer_(FakeContentLayer::Create(&client_)) {} |
1501 | 1416 |
1502 virtual void SetupTree() OVERRIDE { | 1417 virtual void SetupTree() OVERRIDE { |
1503 if (layer_tree_host()->settings().impl_side_painting) { | 1418 layer_->SetBounds(gfx::Size(10, 20)); |
1504 picture_layer_ = FakePictureLayer::Create(&client_); | 1419 layer_tree_host()->SetRootLayer(layer_); |
1505 picture_layer_->SetBounds(gfx::Size(10, 20)); | |
1506 layer_tree_host()->SetRootLayer(picture_layer_); | |
1507 } else { | |
1508 content_layer_ = FakeContentLayer::Create(&client_); | |
1509 content_layer_->SetBounds(gfx::Size(10, 20)); | |
1510 layer_tree_host()->SetRootLayer(content_layer_); | |
1511 } | |
1512 | |
1513 LayerTreeHostContextTest::SetupTree(); | 1420 LayerTreeHostContextTest::SetupTree(); |
1514 } | 1421 } |
1515 | 1422 |
1516 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 1423 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
1517 | 1424 |
1518 virtual void DidCommit() OVERRIDE { | 1425 virtual void DidCommit() OVERRIDE { |
1519 switch (layer_tree_host()->source_frame_number()) { | 1426 switch (layer_tree_host()->source_frame_number()) { |
1520 case 1: | 1427 case 1: |
1521 if (layer_tree_host()->settings().impl_side_painting) | 1428 EXPECT_EQ(1u, layer_->output_surface_created_count()); |
1522 EXPECT_EQ(1u, picture_layer_->output_surface_created_count()); | |
1523 else | |
1524 EXPECT_EQ(1u, content_layer_->output_surface_created_count()); | |
1525 layer_tree_host()->SetNeedsCommit(); | 1429 layer_tree_host()->SetNeedsCommit(); |
1526 break; | 1430 break; |
1527 case 2: | 1431 case 2: |
1528 if (layer_tree_host()->settings().impl_side_painting) | 1432 EXPECT_EQ(1u, layer_->output_surface_created_count()); |
1529 EXPECT_EQ(1u, picture_layer_->output_surface_created_count()); | |
1530 else | |
1531 EXPECT_EQ(1u, content_layer_->output_surface_created_count()); | |
1532 layer_tree_host()->SetNeedsCommit(); | 1433 layer_tree_host()->SetNeedsCommit(); |
1533 break; | 1434 break; |
1534 case 3: | 1435 case 3: |
1535 if (layer_tree_host()->settings().impl_side_painting) | 1436 EXPECT_EQ(1u, layer_->output_surface_created_count()); |
1536 EXPECT_EQ(1u, picture_layer_->output_surface_created_count()); | |
1537 else | |
1538 EXPECT_EQ(1u, content_layer_->output_surface_created_count()); | |
1539 break; | 1437 break; |
1540 case 4: | 1438 case 4: |
1541 if (layer_tree_host()->settings().impl_side_painting) | 1439 EXPECT_EQ(2u, layer_->output_surface_created_count()); |
1542 EXPECT_EQ(2u, picture_layer_->output_surface_created_count()); | |
1543 else | |
1544 EXPECT_EQ(2u, content_layer_->output_surface_created_count()); | |
1545 layer_tree_host()->SetNeedsCommit(); | 1440 layer_tree_host()->SetNeedsCommit(); |
1546 break; | 1441 break; |
1547 } | 1442 } |
1548 } | 1443 } |
1549 | 1444 |
1550 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1445 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
1551 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 1446 LayerTreeHostContextTest::CommitCompleteOnThread(impl); |
1552 switch (LastCommittedSourceFrameNumber(impl)) { | 1447 switch (LastCommittedSourceFrameNumber(impl)) { |
1553 case 0: | 1448 case 0: |
1554 break; | 1449 break; |
1555 case 1: | 1450 case 1: |
1556 break; | 1451 break; |
1557 case 2: | 1452 case 2: |
1558 LoseContext(); | 1453 LoseContext(); |
1559 break; | 1454 break; |
1560 case 3: | 1455 case 3: |
1561 EndTest(); | 1456 EndTest(); |
1562 break; | 1457 break; |
1563 } | 1458 } |
1564 } | 1459 } |
1565 | 1460 |
1566 virtual void AfterTest() OVERRIDE {} | 1461 virtual void AfterTest() OVERRIDE {} |
1567 | 1462 |
1568 protected: | 1463 protected: |
1569 FakeContentLayerClient client_; | 1464 FakeContentLayerClient client_; |
1570 scoped_refptr<FakePictureLayer> picture_layer_; | 1465 scoped_refptr<FakeContentLayer> layer_; |
1571 scoped_refptr<FakeContentLayer> content_layer_; | |
1572 }; | 1466 }; |
1573 | 1467 |
1574 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); | 1468 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); |
1575 | 1469 |
1576 class LayerTreeHostContextTestLoseAfterSendingBeginMainFrame | 1470 class LayerTreeHostContextTestLoseAfterSendingBeginMainFrame |
1577 : public LayerTreeHostContextTest { | 1471 : public LayerTreeHostContextTest { |
1578 protected: | 1472 protected: |
1579 virtual void BeginTest() OVERRIDE { | 1473 virtual void BeginTest() OVERRIDE { |
1580 deferred_ = false; | 1474 deferred_ = false; |
1581 PostSetNeedsCommitToMainThread(); | 1475 PostSetNeedsCommitToMainThread(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1627 virtual void AfterTest() OVERRIDE {} | 1521 virtual void AfterTest() OVERRIDE {} |
1628 | 1522 |
1629 bool deferred_; | 1523 bool deferred_; |
1630 }; | 1524 }; |
1631 | 1525 |
1632 SINGLE_AND_MULTI_THREAD_TEST_F( | 1526 SINGLE_AND_MULTI_THREAD_TEST_F( |
1633 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); | 1527 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); |
1634 | 1528 |
1635 } // namespace | 1529 } // namespace |
1636 } // namespace cc | 1530 } // namespace cc |
OLD | NEW |