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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 times_to_fail_recreate_(0), | 58 times_to_fail_recreate_(0), |
59 times_to_expect_create_failed_(0), | 59 times_to_expect_create_failed_(0), |
60 times_create_failed_(0), | 60 times_create_failed_(0), |
61 committed_at_least_once_(false), | 61 committed_at_least_once_(false), |
62 context_should_support_io_surface_(false), | 62 context_should_support_io_surface_(false), |
63 fallback_context_works_(false) { | 63 fallback_context_works_(false) { |
64 media::InitializeMediaLibraryForTesting(); | 64 media::InitializeMediaLibraryForTesting(); |
65 } | 65 } |
66 | 66 |
67 void LoseContext() { | 67 void LoseContext() { |
68 if (!context3d_) | |
danakj
2014/08/20 18:22:10
Is this still needed?
dneto
2014/08/20 19:15:20
Yes. Otherwise 6 tests crash with null ptr except
| |
69 return; | |
68 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 70 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
69 GL_INNOCENT_CONTEXT_RESET_ARB); | 71 GL_INNOCENT_CONTEXT_RESET_ARB); |
70 context3d_ = NULL; | 72 context3d_ = NULL; |
71 } | 73 } |
72 | 74 |
73 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() { | 75 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() { |
74 return TestWebGraphicsContext3D::Create(); | 76 return TestWebGraphicsContext3D::Create(); |
75 } | 77 } |
76 | 78 |
77 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) | 79 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
587 parent_->AddChild(child); | 589 parent_->AddChild(child); |
588 } | 590 } |
589 | 591 |
590 layer_tree_host()->SetRootLayer(parent_); | 592 layer_tree_host()->SetRootLayer(parent_); |
591 LayerTreeHostContextTest::SetupTree(); | 593 LayerTreeHostContextTest::SetupTree(); |
592 } | 594 } |
593 | 595 |
594 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 596 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
595 | 597 |
596 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 598 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
597 EXPECT_EQ(0, times_to_lose_on_end_query_); | 599 // In the multi-thread case, the scheduler sees the context loss and forces |
600 // re-creation of the output surface before any drawing is attempted. | |
601 // In the single-thread case, we still draw even if the context is lost | |
602 // during resource creation. The loss will be detected later. | |
603 if (HasImplThread()) | |
604 EXPECT_EQ(0, times_to_lose_on_end_query_); | |
598 EndTest(); | 605 EndTest(); |
599 } | 606 } |
600 | 607 |
601 virtual void AfterTest() OVERRIDE { | 608 virtual void AfterTest() OVERRIDE { |
609 // We have recovered from all context losses in both the single- and | |
610 // multi-threaded cases. | |
602 EXPECT_EQ(0, times_to_lose_on_end_query_); | 611 EXPECT_EQ(0, times_to_lose_on_end_query_); |
603 } | 612 } |
604 | 613 |
605 private: | 614 private: |
606 FakeContentLayerClient client_; | 615 FakeContentLayerClient client_; |
607 scoped_refptr<FakeContentLayer> parent_; | 616 scoped_refptr<FakeContentLayer> parent_; |
608 int num_children_; | 617 int num_children_; |
609 int times_to_lose_on_end_query_; | 618 int times_to_lose_on_end_query_; |
610 }; | 619 }; |
611 | 620 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
650 // Lose the context and struggle to recreate it. | 659 // Lose the context and struggle to recreate it. |
651 LoseContext(); | 660 LoseContext(); |
652 times_to_fail_create_ = 1; | 661 times_to_fail_create_ = 1; |
653 break; | 662 break; |
654 case 2: | 663 case 2: |
655 EXPECT_GE(1u, root->lost_output_surface_count()); | 664 EXPECT_GE(1u, root->lost_output_surface_count()); |
656 EXPECT_GE(1u, child->lost_output_surface_count()); | 665 EXPECT_GE(1u, child->lost_output_surface_count()); |
657 EXPECT_GE(1u, grandchild->lost_output_surface_count()); | 666 EXPECT_GE(1u, grandchild->lost_output_surface_count()); |
658 EndTest(); | 667 EndTest(); |
659 break; | 668 break; |
669 case 3: | |
danakj
2014/08/20 18:22:10
did you verify that you still need this extra case
dneto
2014/08/20 19:15:20
Yes, it's still needed.
| |
670 // The single thread proxy issues extra commits after context lost. | |
671 // http://crbug.com/287250 | |
672 if (HasImplThread()) | |
673 NOTREACHED(); | |
674 break; | |
660 default: | 675 default: |
661 NOTREACHED(); | 676 NOTREACHED(); |
662 } | 677 } |
663 } | 678 } |
664 | 679 |
665 virtual void AfterTest() OVERRIDE {} | 680 virtual void AfterTest() OVERRIDE {} |
666 | 681 |
667 private: | 682 private: |
668 int num_commits_; | 683 int num_commits_; |
669 | 684 |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
977 EXPECT_EQ(1, scrollbar_layer_->update_count()); | 992 EXPECT_EQ(1, scrollbar_layer_->update_count()); |
978 LoseContext(); | 993 LoseContext(); |
979 break; | 994 break; |
980 case 2: | 995 case 2: |
981 // Second update, after the lost context, we should still upload 2 | 996 // Second update, after the lost context, we should still upload 2 |
982 // resources even if the contents haven't changed. | 997 // resources even if the contents haven't changed. |
983 EXPECT_EQ(2, scrollbar_layer_->update_count()); | 998 EXPECT_EQ(2, scrollbar_layer_->update_count()); |
984 EndTest(); | 999 EndTest(); |
985 break; | 1000 break; |
986 case 3: | 1001 case 3: |
1002 case 4: | |
danakj
2014/08/20 18:22:10
did you verify that you still need this extra case
| |
987 // Single thread proxy issues extra commits after context lost. | 1003 // Single thread proxy issues extra commits after context lost. |
988 // http://crbug.com/287250 | 1004 // http://crbug.com/287250 |
989 if (HasImplThread()) | 1005 if (HasImplThread()) |
990 NOTREACHED(); | 1006 NOTREACHED(); |
991 break; | 1007 break; |
992 default: | 1008 default: |
993 NOTREACHED(); | 1009 NOTREACHED(); |
994 } | 1010 } |
995 } | 1011 } |
996 | 1012 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1090 // Release resource before ending the test. | 1106 // Release resource before ending the test. |
1091 ui_resource_.reset(); | 1107 ui_resource_.reset(); |
1092 EndTest(); | 1108 EndTest(); |
1093 break; | 1109 break; |
1094 case 5: | 1110 case 5: |
1095 // Single thread proxy issues extra commits after context lost. | 1111 // Single thread proxy issues extra commits after context lost. |
1096 // http://crbug.com/287250 | 1112 // http://crbug.com/287250 |
1097 if (HasImplThread()) | 1113 if (HasImplThread()) |
1098 NOTREACHED(); | 1114 NOTREACHED(); |
1099 break; | 1115 break; |
1100 case 6: | 1116 case 7: |
danakj
2014/08/20 18:22:10
case 6? or should case 6 be up with case 5?
dneto
2014/08/20 19:15:20
Single thread case does reach case 6, so changing
danakj
2014/08/20 19:19:12
Ah ok, since we don't reach 5 we won't reach 6, su
| |
1101 NOTREACHED(); | 1117 NOTREACHED(); |
1102 } | 1118 } |
1103 } | 1119 } |
1104 | 1120 |
1105 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { | 1121 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { |
1106 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 1122 LayerTreeHostContextTest::CommitCompleteOnThread(impl); |
1107 switch (time_step_) { | 1123 switch (time_step_) { |
1108 case 1: | 1124 case 1: |
1109 // The resource should have been created on LTHI after the commit. | 1125 // The resource should have been created on LTHI after the commit. |
1110 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1126 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
1111 PostSetNeedsCommitToMainThread(); | 1127 PostSetNeedsCommitToMainThread(); |
1112 break; | 1128 break; |
1113 case 2: | 1129 case 2: |
1114 LoseContext(); | 1130 LoseContext(); |
1115 break; | 1131 break; |
1116 case 3: | 1132 case 3: |
1117 // The resources should have been recreated. The bitmap callback should | 1133 if (HasImplThread()) |
1118 // have been called once with the resource_lost flag set to true. | 1134 CheckForLossRecoveryThenContinue(impl); |
1119 EXPECT_EQ(1, ui_resource_->lost_resource_count); | 1135 break; |
1120 // Resource Id on the impl-side have been recreated as well. Note | 1136 case 4: |
1121 // that the same UIResourceId persists after the context lost. | 1137 // In the single-threaded case, the layer tree host sees the |
1122 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1138 // loss one step later. |
1123 PostSetNeedsCommitToMainThread(); | 1139 if (!HasImplThread()) |
1140 CheckForLossRecoveryThenContinue(impl); | |
1124 break; | 1141 break; |
1125 } | 1142 } |
1126 } | 1143 } |
1144 | |
1145 void CheckForLossRecoveryThenContinue(LayerTreeHostImpl* impl) { | |
1146 // The resources should have been recreated. The bitmap callback should | |
1147 // have been called once with the resource_lost flag set to true. | |
1148 EXPECT_EQ(1, ui_resource_->lost_resource_count); | |
1149 // The resource id on the impl-side should have been recreated as well. | |
1150 // Note that the same UIResourceId persists after the context is lost. | |
1151 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | |
1152 PostSetNeedsCommitToMainThread(); | |
1153 } | |
1127 }; | 1154 }; |
1128 | 1155 |
1129 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostAfterCommit); | 1156 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostAfterCommit); |
1130 | 1157 |
1131 // Losing context before UI resource requests can be commited. Three sequences | 1158 // Losing context before UI resource requests can be commited. Three sequences |
1132 // of creation/deletion are considered: | 1159 // of creation/deletion are considered: |
1133 // 1. Create one resource -> Context Lost => Expect the resource to have been | 1160 // 1. Create one resource -> Context Lost => Expect the resource to have been |
1134 // created. | 1161 // created. |
1135 // 2. Delete an exisiting resource (test_id0_) -> create a second resource | 1162 // 2. Delete an exisiting resource (test_id0_) -> create a second resource |
1136 // (test_id1_) -> Context Lost => Expect the test_id0_ to be removed and | 1163 // (test_id1_) -> Context Lost => Expect the test_id0_ to be removed and |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1443 layer_tree_host()->SetNeedsCommit(); | 1470 layer_tree_host()->SetNeedsCommit(); |
1444 break; | 1471 break; |
1445 case 2: | 1472 case 2: |
1446 EXPECT_EQ(1u, layer_->output_surface_created_count()); | 1473 EXPECT_EQ(1u, layer_->output_surface_created_count()); |
1447 layer_tree_host()->SetNeedsCommit(); | 1474 layer_tree_host()->SetNeedsCommit(); |
1448 break; | 1475 break; |
1449 case 3: | 1476 case 3: |
1450 EXPECT_EQ(1u, layer_->output_surface_created_count()); | 1477 EXPECT_EQ(1u, layer_->output_surface_created_count()); |
1451 break; | 1478 break; |
1452 case 4: | 1479 case 4: |
1453 EXPECT_EQ(2u, layer_->output_surface_created_count()); | 1480 if (HasImplThread()) { |
1454 layer_tree_host()->SetNeedsCommit(); | 1481 EXPECT_EQ(2u, layer_->output_surface_created_count()); |
1482 layer_tree_host()->SetNeedsCommit(); | |
1483 } | |
1484 break; | |
1485 case 5: | |
1486 // The single thread proxy notices the context is lost after the commit | |
1487 // has completed. | |
1488 if (!HasImplThread()) { | |
1489 EXPECT_EQ(2u, layer_->output_surface_created_count()); | |
1490 layer_tree_host()->SetNeedsCommit(); | |
1491 } | |
1455 break; | 1492 break; |
1456 } | 1493 } |
1457 } | 1494 } |
1458 | 1495 |
1459 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1496 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
1460 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 1497 LayerTreeHostContextTest::CommitCompleteOnThread(impl); |
1461 switch (LastCommittedSourceFrameNumber(impl)) { | 1498 switch (LastCommittedSourceFrameNumber(impl)) { |
1462 case 0: | 1499 case 0: |
1463 break; | 1500 break; |
1464 case 1: | 1501 case 1: |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1535 virtual void AfterTest() OVERRIDE {} | 1572 virtual void AfterTest() OVERRIDE {} |
1536 | 1573 |
1537 bool deferred_; | 1574 bool deferred_; |
1538 }; | 1575 }; |
1539 | 1576 |
1540 // TODO(danakj): We don't use scheduler with SingleThreadProxy yet. | 1577 // TODO(danakj): We don't use scheduler with SingleThreadProxy yet. |
1541 MULTI_THREAD_TEST_F(LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); | 1578 MULTI_THREAD_TEST_F(LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); |
1542 | 1579 |
1543 } // namespace | 1580 } // namespace |
1544 } // namespace cc | 1581 } // namespace cc |
OLD | NEW |