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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "cc/layers/heads_up_display_layer.h" | 9 #include "cc/layers/heads_up_display_layer.h" |
10 #include "cc/layers/layer_impl.h" | 10 #include "cc/layers/layer_impl.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 CHECK(context3d_); | 73 CHECK(context3d_); |
74 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 74 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
75 GL_INNOCENT_CONTEXT_RESET_ARB); | 75 GL_INNOCENT_CONTEXT_RESET_ARB); |
76 context3d_ = NULL; | 76 context3d_ = NULL; |
77 } | 77 } |
78 | 78 |
79 virtual std::unique_ptr<TestWebGraphicsContext3D> CreateContext3d() { | 79 virtual std::unique_ptr<TestWebGraphicsContext3D> CreateContext3d() { |
80 return TestWebGraphicsContext3D::Create(); | 80 return TestWebGraphicsContext3D::Create(); |
81 } | 81 } |
82 | 82 |
83 std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { | 83 std::unique_ptr<OutputSurface> CreateOutputSurface() override { |
84 if (times_to_fail_create_) { | 84 if (times_to_fail_create_) { |
85 --times_to_fail_create_; | 85 --times_to_fail_create_; |
86 ExpectCreateToFail(); | 86 ExpectCreateToFail(); |
87 return base::WrapUnique(new FailureOutputSurface(delegating_renderer())); | 87 return base::WrapUnique(new FailureOutputSurface(delegating_renderer())); |
88 } | 88 } |
89 | 89 |
90 std::unique_ptr<TestWebGraphicsContext3D> context3d = CreateContext3d(); | 90 std::unique_ptr<TestWebGraphicsContext3D> context3d = CreateContext3d(); |
91 base::AutoLock lock(context3d_lock_); | 91 base::AutoLock lock(context3d_lock_); |
92 context3d_ = context3d.get(); | 92 context3d_ = context3d.get(); |
93 | 93 |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 LayerTreeHostImpl::FrameData* frame, | 1055 LayerTreeHostImpl::FrameData* frame, |
1056 DrawResult draw_result) override { | 1056 DrawResult draw_result) override { |
1057 if (host_impl->active_tree()->source_frame_number() == 2) { | 1057 if (host_impl->active_tree()->source_frame_number() == 2) { |
1058 // Lose the context during draw on the second commit. This will cause | 1058 // Lose the context during draw on the second commit. This will cause |
1059 // a third commit to recover. | 1059 // a third commit to recover. |
1060 context3d_->set_times_bind_texture_succeeds(0); | 1060 context3d_->set_times_bind_texture_succeeds(0); |
1061 } | 1061 } |
1062 return draw_result; | 1062 return draw_result; |
1063 } | 1063 } |
1064 | 1064 |
1065 std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { | 1065 std::unique_ptr<OutputSurface> CreateOutputSurface() override { |
1066 // This will get called twice: | 1066 // This will get called twice: |
1067 // First when we create the initial output surface... | 1067 // First when we create the initial output surface... |
1068 if (layer_tree_host()->source_frame_number() > 0) { | 1068 if (layer_tree_host()->source_frame_number() > 0) { |
1069 // ... and then again after we forced the context to be lost. | 1069 // ... and then again after we forced the context to be lost. |
1070 lost_context_ = true; | 1070 lost_context_ = true; |
1071 } | 1071 } |
1072 return LayerTreeHostContextTest::CreateFakeOutputSurface(); | 1072 return LayerTreeHostContextTest::CreateOutputSurface(); |
1073 } | 1073 } |
1074 | 1074 |
1075 void DidCommitAndDrawFrame() override { | 1075 void DidCommitAndDrawFrame() override { |
1076 ASSERT_TRUE(layer_tree_host()->hud_layer()); | 1076 ASSERT_TRUE(layer_tree_host()->hud_layer()); |
1077 // End the test once we know the 3nd frame drew. | 1077 // End the test once we know the 3nd frame drew. |
1078 if (layer_tree_host()->source_frame_number() < 5) { | 1078 if (layer_tree_host()->source_frame_number() < 5) { |
1079 layer_tree_host()->root_layer()->SetNeedsDisplay(); | 1079 layer_tree_host()->root_layer()->SetNeedsDisplay(); |
1080 layer_tree_host()->SetNeedsCommit(); | 1080 layer_tree_host()->SetNeedsCommit(); |
1081 } else { | 1081 } else { |
1082 EndTest(); | 1082 EndTest(); |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 ui_resource_ = nullptr; | 1500 ui_resource_ = nullptr; |
1501 EndTest(); | 1501 EndTest(); |
1502 break; | 1502 break; |
1503 case 4: | 1503 case 4: |
1504 NOTREACHED(); | 1504 NOTREACHED(); |
1505 } | 1505 } |
1506 } | 1506 } |
1507 | 1507 |
1508 void DidSetVisibleOnImplTree(LayerTreeHostImpl* impl, bool visible) override { | 1508 void DidSetVisibleOnImplTree(LayerTreeHostImpl* impl, bool visible) override { |
1509 if (!visible) { | 1509 if (!visible) { |
1510 TestWebGraphicsContext3D* context = TestContext(); | |
1511 // All resources should have been evicted. | 1510 // All resources should have been evicted. |
1512 ASSERT_EQ(0u, context->NumTextures()); | 1511 ASSERT_EQ(0u, context3d_->NumTextures()); |
1513 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1512 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
1514 EXPECT_EQ(2, ui_resource_->resource_create_count); | 1513 EXPECT_EQ(2, ui_resource_->resource_create_count); |
1515 EXPECT_EQ(1, ui_resource_->lost_resource_count); | 1514 EXPECT_EQ(1, ui_resource_->lost_resource_count); |
1516 // Drawing is disabled both because of the evicted resources and | 1515 // Drawing is disabled both because of the evicted resources and |
1517 // because the renderer is not visible. | 1516 // because the renderer is not visible. |
1518 EXPECT_FALSE(impl->CanDraw()); | 1517 EXPECT_FALSE(impl->CanDraw()); |
1519 // Make the renderer visible again. | 1518 // Make the renderer visible again. |
1520 PostSetVisibleToMainThread(true); | 1519 PostSetVisibleToMainThread(true); |
1521 } | 1520 } |
1522 } | 1521 } |
1523 | 1522 |
1524 void StepCompleteOnImplThread(LayerTreeHostImpl* impl) override { | 1523 void StepCompleteOnImplThread(LayerTreeHostImpl* impl) override { |
1525 TestWebGraphicsContext3D* context = TestContext(); | |
1526 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 1524 LayerTreeHostContextTest::CommitCompleteOnThread(impl); |
1527 switch (time_step_) { | 1525 switch (time_step_) { |
1528 case 1: | 1526 case 1: |
1529 // The resource should have been created on LTHI after the commit. | 1527 // The resource should have been created on LTHI after the commit. |
1530 ASSERT_EQ(1u, context->NumTextures()); | 1528 ASSERT_EQ(1u, context3d_->NumTextures()); |
1531 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1529 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
1532 EXPECT_EQ(1, ui_resource_->resource_create_count); | 1530 EXPECT_EQ(1, ui_resource_->resource_create_count); |
1533 EXPECT_EQ(0, ui_resource_->lost_resource_count); | 1531 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
1534 EXPECT_TRUE(impl->CanDraw()); | 1532 EXPECT_TRUE(impl->CanDraw()); |
1535 // Evict all UI resources. This will trigger a commit. | 1533 // Evict all UI resources. This will trigger a commit. |
1536 impl->EvictAllUIResources(); | 1534 impl->EvictAllUIResources(); |
1537 ASSERT_EQ(0u, context->NumTextures()); | 1535 ASSERT_EQ(0u, context3d_->NumTextures()); |
1538 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1536 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
1539 EXPECT_EQ(1, ui_resource_->resource_create_count); | 1537 EXPECT_EQ(1, ui_resource_->resource_create_count); |
1540 EXPECT_EQ(0, ui_resource_->lost_resource_count); | 1538 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
1541 EXPECT_FALSE(impl->CanDraw()); | 1539 EXPECT_FALSE(impl->CanDraw()); |
1542 break; | 1540 break; |
1543 case 2: | 1541 case 2: |
1544 // The resource should have been recreated. | 1542 // The resource should have been recreated. |
1545 ASSERT_EQ(1u, context->NumTextures()); | 1543 ASSERT_EQ(1u, context3d_->NumTextures()); |
1546 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1544 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
1547 EXPECT_EQ(2, ui_resource_->resource_create_count); | 1545 EXPECT_EQ(2, ui_resource_->resource_create_count); |
1548 EXPECT_EQ(1, ui_resource_->lost_resource_count); | 1546 EXPECT_EQ(1, ui_resource_->lost_resource_count); |
1549 EXPECT_TRUE(impl->CanDraw()); | 1547 EXPECT_TRUE(impl->CanDraw()); |
1550 break; | 1548 break; |
1551 case 3: | 1549 case 3: |
1552 // The resource should have been recreated after visibility was | 1550 // The resource should have been recreated after visibility was |
1553 // restored. | 1551 // restored. |
1554 ASSERT_EQ(1u, context->NumTextures()); | 1552 ASSERT_EQ(1u, context3d_->NumTextures()); |
1555 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1553 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
1556 EXPECT_EQ(3, ui_resource_->resource_create_count); | 1554 EXPECT_EQ(3, ui_resource_->resource_create_count); |
1557 EXPECT_EQ(2, ui_resource_->lost_resource_count); | 1555 EXPECT_EQ(2, ui_resource_->lost_resource_count); |
1558 EXPECT_TRUE(impl->CanDraw()); | 1556 EXPECT_TRUE(impl->CanDraw()); |
1559 break; | 1557 break; |
1560 } | 1558 } |
1561 } | 1559 } |
1562 }; | 1560 }; |
1563 | 1561 |
1564 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostEviction); | 1562 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostEviction); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1603 void AfterTest() override {} | 1601 void AfterTest() override {} |
1604 | 1602 |
1605 bool deferred_; | 1603 bool deferred_; |
1606 }; | 1604 }; |
1607 | 1605 |
1608 SINGLE_AND_MULTI_THREAD_TEST_F( | 1606 SINGLE_AND_MULTI_THREAD_TEST_F( |
1609 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); | 1607 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); |
1610 | 1608 |
1611 } // namespace | 1609 } // namespace |
1612 } // namespace cc | 1610 } // namespace cc |
OLD | NEW |