Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: cc/trees/layer_tree_host_unittest_context.cc

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

Powered by Google App Engine
This is Rietveld 408576698