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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 // there. | 69 // there. |
70 base::AutoLock lock(context3d_lock_); | 70 base::AutoLock lock(context3d_lock_); |
71 // For sanity-checking tests, they should only call this when the | 71 // For sanity-checking tests, they should only call this when the |
72 // context is not lost. | 72 // context is not lost. |
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_ = nullptr; | 76 context3d_ = nullptr; |
77 } | 77 } |
78 | 78 |
79 virtual std::unique_ptr<TestWebGraphicsContext3D> CreateContext3d() { | |
danakj
2016/10/06 20:50:35
Oh cool nothing overrides this anymore.
| |
80 return TestWebGraphicsContext3D::Create(); | |
81 } | |
82 | |
83 std::unique_ptr<TestCompositorFrameSink> CreateCompositorFrameSink( | 79 std::unique_ptr<TestCompositorFrameSink> CreateCompositorFrameSink( |
84 scoped_refptr<ContextProvider> compositor_context_provider, | 80 scoped_refptr<ContextProvider> compositor_context_provider, |
85 scoped_refptr<ContextProvider> worker_context_provider) override { | 81 scoped_refptr<ContextProvider> worker_context_provider) override { |
86 if (times_to_fail_create_) { | 82 base::AutoLock lock(context3d_lock_); |
87 --times_to_fail_create_; | |
88 ExpectCreateToFail(); | |
89 auto test_compositor_context_provider = TestContextProvider::Create(); | |
90 test_compositor_context_provider->UnboundTestContext3d() | |
91 ->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | |
92 GL_INNOCENT_CONTEXT_RESET_ARB); | |
93 compositor_context_provider = std::move(test_compositor_context_provider); | |
94 } | |
95 return LayerTreeTest::CreateCompositorFrameSink( | |
96 std::move(compositor_context_provider), | |
97 std::move(worker_context_provider)); | |
98 } | |
99 | 83 |
100 std::unique_ptr<OutputSurface> CreateDisplayOutputSurface( | 84 std::unique_ptr<TestWebGraphicsContext3D> context3d = |
danakj
2016/10/06 20:50:35
nit: compositor_context3d
sunnyps
2016/10/06 21:31:53
Done.
| |
101 scoped_refptr<ContextProvider> compositor_context_provider) override { | 85 TestWebGraphicsContext3D::Create(); |
102 std::unique_ptr<TestWebGraphicsContext3D> context3d = CreateContext3d(); | |
103 if (context_should_support_io_surface_) { | 86 if (context_should_support_io_surface_) { |
104 context3d->set_have_extension_io_surface(true); | 87 context3d->set_have_extension_io_surface(true); |
105 context3d->set_have_extension_egl_image(true); | 88 context3d->set_have_extension_egl_image(true); |
106 } | 89 } |
90 context3d_ = context3d.get(); | |
107 | 91 |
108 base::AutoLock lock(context3d_lock_); | 92 if (times_to_fail_create_) { |
109 context3d_ = context3d.get(); | 93 --times_to_fail_create_; |
110 return LayerTreeTest::CreateDisplayOutputSurface( | 94 ExpectCreateToFail(); |
111 TestContextProvider::Create(std::move(context3d))); | 95 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
96 GL_INNOCENT_CONTEXT_RESET_ARB); | |
97 } | |
98 | |
99 return LayerTreeTest::CreateCompositorFrameSink( | |
100 TestContextProvider::Create(std::move(context3d)), | |
101 std::move(worker_context_provider)); | |
112 } | 102 } |
113 | 103 |
114 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 104 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
115 LayerTreeHostImpl::FrameData* frame, | 105 LayerTreeHostImpl::FrameData* frame, |
116 DrawResult draw_result) override { | 106 DrawResult draw_result) override { |
117 if (draw_result == DRAW_ABORTED_MISSING_HIGH_RES_CONTENT) { | 107 if (draw_result == DRAW_ABORTED_MISSING_HIGH_RES_CONTENT) { |
118 // Only valid for single-threaded compositing, which activates | 108 // Only valid for single-threaded compositing, which activates |
119 // immediately and will try to draw again when content has finished. | 109 // immediately and will try to draw again when content has finished. |
120 DCHECK(!host_impl->task_runner_provider()->HasImplThread()); | 110 DCHECK(!host_impl->task_runner_provider()->HasImplThread()); |
121 return draw_result; | 111 return draw_result; |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 // This test uses Composite() which only exists for single thread. | 467 // This test uses Composite() which only exists for single thread. |
478 SINGLE_THREAD_TEST_F(MultipleCompositeDoesNotCreateCompositorFrameSink); | 468 SINGLE_THREAD_TEST_F(MultipleCompositeDoesNotCreateCompositorFrameSink); |
479 | 469 |
480 // This test makes sure that once a SingleThreadProxy issues a | 470 // This test makes sure that once a SingleThreadProxy issues a |
481 // DidFailToInitializeCompositorFrameSink, that future Composite calls will not | 471 // DidFailToInitializeCompositorFrameSink, that future Composite calls will not |
482 // trigger additional requests for output surfaces. | 472 // trigger additional requests for output surfaces. |
483 class FailedCreateDoesNotCreateExtraCompositorFrameSink | 473 class FailedCreateDoesNotCreateExtraCompositorFrameSink |
484 : public LayerTreeHostContextTest { | 474 : public LayerTreeHostContextTest { |
485 public: | 475 public: |
486 FailedCreateDoesNotCreateExtraCompositorFrameSink() | 476 FailedCreateDoesNotCreateExtraCompositorFrameSink() |
487 : LayerTreeHostContextTest(), num_requests_(0), has_failed_(false) {} | 477 : LayerTreeHostContextTest(), num_requests_(0), has_failed_(false) { |
478 times_to_fail_create_ = 1; | |
479 } | |
488 | 480 |
489 void InitializeSettings(LayerTreeSettings* settings) override { | 481 void InitializeSettings(LayerTreeSettings* settings) override { |
490 settings->single_thread_proxy_scheduler = false; | 482 settings->single_thread_proxy_scheduler = false; |
491 settings->use_zero_copy = true; | 483 settings->use_zero_copy = true; |
492 } | 484 } |
493 | 485 |
494 void RequestNewCompositorFrameSink() override { | 486 void RequestNewCompositorFrameSink() override { |
495 num_requests_++; | 487 num_requests_++; |
496 // There should be one initial request and then one request from | 488 // There should be one initial request and then one request from |
497 // the LayerTreeTest test hooks DidFailToInitializeCompositorFrameSink | 489 // the LayerTreeTest test hooks DidFailToInitializeCompositorFrameSink |
498 // (which is hard to skip). This second request is just ignored and is test | 490 // (which is hard to skip). This second request is just ignored and is test |
499 // cruft. | 491 // cruft. |
500 EXPECT_LE(num_requests_, 2); | 492 EXPECT_LE(num_requests_, 2); |
501 if (num_requests_ > 1) | 493 if (num_requests_ > 1) |
502 return; | 494 return; |
503 LayerTreeHostContextTest::RequestNewCompositorFrameSink(); | 495 LayerTreeHostContextTest::RequestNewCompositorFrameSink(); |
504 } | 496 } |
505 | 497 |
506 std::unique_ptr<TestCompositorFrameSink> CreateCompositorFrameSink( | |
507 scoped_refptr<ContextProvider> compositor_context_provider, | |
508 scoped_refptr<ContextProvider> worker_context_provider) override { | |
509 ExpectCreateToFail(); | |
510 auto test_compositor_context_provider = TestContextProvider::Create(); | |
511 test_compositor_context_provider->UnboundTestContext3d() | |
512 ->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | |
513 GL_INNOCENT_CONTEXT_RESET_ARB); | |
514 return LayerTreeTest::CreateCompositorFrameSink( | |
515 std::move(test_compositor_context_provider), | |
516 std::move(worker_context_provider)); | |
517 } | |
518 | |
519 void BeginTest() override { | 498 void BeginTest() override { |
520 // First composite tries to create a surface. | 499 // First composite tries to create a surface. |
521 layer_tree_host()->Composite(base::TimeTicks::FromInternalValue(1)); | 500 layer_tree_host()->Composite(base::TimeTicks::FromInternalValue(1)); |
522 EXPECT_EQ(num_requests_, 2); | 501 EXPECT_EQ(num_requests_, 2); |
523 EXPECT_TRUE(has_failed_); | 502 EXPECT_TRUE(has_failed_); |
524 | 503 |
525 // Second composite should not request or fail. | 504 // Second composite should not request or fail. |
526 layer_tree_host()->Composite(base::TimeTicks::FromInternalValue(2)); | 505 layer_tree_host()->Composite(base::TimeTicks::FromInternalValue(2)); |
527 EXPECT_EQ(num_requests_, 2); | 506 EXPECT_EQ(num_requests_, 2); |
528 EndTest(); | 507 EndTest(); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 LayerTreeHostContextTest::SetupTree(); | 701 LayerTreeHostContextTest::SetupTree(); |
723 } | 702 } |
724 | 703 |
725 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 704 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
726 | 705 |
727 void PostEvictTextures() { | 706 void PostEvictTextures() { |
728 if (HasImplThread()) { | 707 if (HasImplThread()) { |
729 ImplThreadTaskRunner()->PostTask( | 708 ImplThreadTaskRunner()->PostTask( |
730 FROM_HERE, | 709 FROM_HERE, |
731 base::Bind(&LayerTreeHostContextTestLostContextAndEvictTextures:: | 710 base::Bind(&LayerTreeHostContextTestLostContextAndEvictTextures:: |
732 EvictTexturesOnImplThread, | 711 EvictTexturesOnImplThread, |
733 base::Unretained(this))); | 712 base::Unretained(this))); |
734 } else { | 713 } else { |
735 DebugScopedSetImplThread impl(task_runner_provider()); | 714 DebugScopedSetImplThread impl(task_runner_provider()); |
736 EvictTexturesOnImplThread(); | 715 EvictTexturesOnImplThread(); |
737 } | 716 } |
738 } | 717 } |
739 | 718 |
740 void EvictTexturesOnImplThread() { | 719 void EvictTexturesOnImplThread() { |
741 impl_host_->EvictTexturesForTesting(); | 720 impl_host_->EvictTexturesForTesting(); |
742 | 721 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
899 bool lost) {} | 878 bool lost) {} |
900 | 879 |
901 void SetupTree() override { | 880 void SetupTree() override { |
902 gpu::gles2::GLES2Interface* gl = child_context_provider_->ContextGL(); | 881 gpu::gles2::GLES2Interface* gl = child_context_provider_->ContextGL(); |
903 | 882 |
904 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 883 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
905 | 884 |
906 std::unique_ptr<RenderPass> pass_for_quad = RenderPass::Create(); | 885 std::unique_ptr<RenderPass> pass_for_quad = RenderPass::Create(); |
907 pass_for_quad->SetNew( | 886 pass_for_quad->SetNew( |
908 // AppendOneOfEveryQuadType() makes a RenderPass quad with this id. | 887 // AppendOneOfEveryQuadType() makes a RenderPass quad with this id. |
909 RenderPassId(2, 1), | 888 RenderPassId(2, 1), gfx::Rect(0, 0, 10, 10), gfx::Rect(0, 0, 10, 10), |
910 gfx::Rect(0, 0, 10, 10), | |
911 gfx::Rect(0, 0, 10, 10), | |
912 gfx::Transform()); | 889 gfx::Transform()); |
913 | 890 |
914 std::unique_ptr<RenderPass> pass = RenderPass::Create(); | 891 std::unique_ptr<RenderPass> pass = RenderPass::Create(); |
915 pass->SetNew(RenderPassId(1, 1), | 892 pass->SetNew(RenderPassId(1, 1), gfx::Rect(0, 0, 10, 10), |
916 gfx::Rect(0, 0, 10, 10), | 893 gfx::Rect(0, 0, 10, 10), gfx::Transform()); |
917 gfx::Rect(0, 0, 10, 10), | |
918 gfx::Transform()); | |
919 gpu::SyncToken mailbox_sync_token; | 894 gpu::SyncToken mailbox_sync_token; |
920 AddOneOfEveryQuadType(pass.get(), child_resource_provider_.get(), | 895 AddOneOfEveryQuadType(pass.get(), child_resource_provider_.get(), |
921 RenderPassId(2, 1), &mailbox_sync_token); | 896 RenderPassId(2, 1), &mailbox_sync_token); |
922 | 897 |
923 frame_data->render_pass_list.push_back(std::move(pass_for_quad)); | 898 frame_data->render_pass_list.push_back(std::move(pass_for_quad)); |
924 frame_data->render_pass_list.push_back(std::move(pass)); | 899 frame_data->render_pass_list.push_back(std::move(pass)); |
925 | 900 |
926 ResourceId resource = child_resource_provider_->CreateResource( | 901 ResourceId resource = child_resource_provider_->CreateResource( |
927 gfx::Size(4, 4), ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888, | 902 gfx::Size(4, 4), ResourceProvider::TEXTURE_HINT_IMMUTABLE, RGBA_8888, |
928 gfx::ColorSpace()); | 903 gfx::ColorSpace()); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1191 void PostStepCompleteToMainThread() { | 1166 void PostStepCompleteToMainThread() { |
1192 task_runner_provider()->MainThreadTaskRunner()->PostTask( | 1167 task_runner_provider()->MainThreadTaskRunner()->PostTask( |
1193 FROM_HERE, | 1168 FROM_HERE, |
1194 base::Bind(&UIResourceLostTest::StepCompleteOnMainThreadInternal, | 1169 base::Bind(&UIResourceLostTest::StepCompleteOnMainThreadInternal, |
1195 base::Unretained(this), time_step_)); | 1170 base::Unretained(this), time_step_)); |
1196 } | 1171 } |
1197 | 1172 |
1198 void PostLoseContextToImplThread() { | 1173 void PostLoseContextToImplThread() { |
1199 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); | 1174 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); |
1200 ImplThreadTaskRunner()->PostTask( | 1175 ImplThreadTaskRunner()->PostTask( |
1201 FROM_HERE, | 1176 FROM_HERE, base::Bind(&LayerTreeHostContextTest::LoseContext, |
1202 base::Bind(&LayerTreeHostContextTest::LoseContext, | 1177 base::Unretained(this))); |
1203 base::Unretained(this))); | |
1204 } | 1178 } |
1205 | 1179 |
1206 protected: | 1180 protected: |
1207 int time_step_; | 1181 int time_step_; |
1208 std::unique_ptr<FakeScopedUIResource> ui_resource_; | 1182 std::unique_ptr<FakeScopedUIResource> ui_resource_; |
1209 | 1183 |
1210 private: | 1184 private: |
1211 void StepCompleteOnMainThreadInternal(int step) { | 1185 void StepCompleteOnMainThreadInternal(int step) { |
1212 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); | 1186 EXPECT_TRUE(layer_tree_host()->GetTaskRunnerProvider()->IsMainThread()); |
1213 StepCompleteOnMainThread(step); | 1187 StepCompleteOnMainThread(step); |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1584 private: | 1558 private: |
1585 std::unique_ptr<FakeScopedUIResource> ui_resource2_; | 1559 std::unique_ptr<FakeScopedUIResource> ui_resource2_; |
1586 std::unique_ptr<FakeScopedUIResource> ui_resource3_; | 1560 std::unique_ptr<FakeScopedUIResource> ui_resource3_; |
1587 }; | 1561 }; |
1588 | 1562 |
1589 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostEviction); | 1563 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostEviction); |
1590 | 1564 |
1591 class LayerTreeHostContextTestLoseAfterSendingBeginMainFrame | 1565 class LayerTreeHostContextTestLoseAfterSendingBeginMainFrame |
1592 : public LayerTreeHostContextTest { | 1566 : public LayerTreeHostContextTest { |
1593 protected: | 1567 protected: |
1594 void BeginTest() override { | 1568 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
1595 PostSetNeedsCommitToMainThread(); | |
1596 } | |
1597 | 1569 |
1598 void WillBeginMainFrame() override { | 1570 void WillBeginMainFrame() override { |
1599 // Don't begin a frame with a lost surface. | 1571 // Don't begin a frame with a lost surface. |
1600 EXPECT_FALSE(lost_); | 1572 EXPECT_FALSE(lost_); |
1601 | 1573 |
1602 if (deferred_) | 1574 if (deferred_) |
1603 return; | 1575 return; |
1604 deferred_ = true; | 1576 deferred_ = true; |
1605 | 1577 |
1606 // Defer commits before the BeginFrame completes, causing it to be delayed. | 1578 // Defer commits before the BeginFrame completes, causing it to be delayed. |
(...skipping 27 matching lines...) Expand all Loading... | |
1634 | 1606 |
1635 void AfterTest() override {} | 1607 void AfterTest() override {} |
1636 | 1608 |
1637 bool deferred_ = false; | 1609 bool deferred_ = false; |
1638 bool lost_ = true; | 1610 bool lost_ = true; |
1639 }; | 1611 }; |
1640 | 1612 |
1641 SINGLE_AND_MULTI_THREAD_TEST_F( | 1613 SINGLE_AND_MULTI_THREAD_TEST_F( |
1642 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); | 1614 LayerTreeHostContextTestLoseAfterSendingBeginMainFrame); |
1643 | 1615 |
1616 class LayerTreeHostContextTestLoseWorkerContextDuringPrepareTiles | |
1617 : public LayerTreeTest { | |
1618 protected: | |
1619 void SetupTree() override { | |
1620 // Paint non-solid color. | |
danakj
2016/10/06 20:50:35
client_.set_fill_with_nonsolid_color(true) is less
sunnyps
2016/10/06 21:31:53
Done.
| |
1621 SkPaint paint; | |
1622 paint.setColor(SkColorSetARGB(100, 80, 200, 200)); | |
1623 client_.add_draw_rect(gfx::Rect(5, 5), paint); | |
1624 | |
1625 scoped_refptr<FakePictureLayer> picture_layer = | |
1626 FakePictureLayer::Create(&client_); | |
1627 picture_layer->SetBounds(gfx::Size(10, 20)); | |
1628 client_.set_bounds(picture_layer->bounds()); | |
1629 layer_tree()->SetRootLayer(picture_layer); | |
1630 | |
1631 LayerTreeTest::SetupTree(); | |
1632 } | |
1633 | |
1634 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
1635 | |
1636 void WillPrepareTilesOnThread(LayerTreeHostImpl* host_impl) override { | |
1637 ContextProvider::ScopedContextLock scoped_context( | |
1638 host_impl->compositor_frame_sink()->worker_context_provider()); | |
1639 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); | |
1640 gl->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | |
danakj
2016/10/06 20:50:35
Can you leave some comments in this test saying wh
sunnyps
2016/10/06 21:31:53
Done.
| |
1641 GL_INNOCENT_CONTEXT_RESET_ARB); | |
1642 } | |
1643 | |
1644 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | |
1645 ++num_draws_; | |
1646 } | |
1647 | |
1648 void DidCommitAndDrawFrame() override { EndTest(); } | |
1649 | |
1650 void AfterTest() override { EXPECT_EQ(1, num_draws_); } | |
1651 | |
1652 FakeContentLayerClient client_; | |
1653 int num_draws_ = 0; | |
1654 }; | |
1655 | |
1656 MULTI_THREAD_TEST_F( | |
1657 LayerTreeHostContextTestLoseWorkerContextDuringPrepareTiles); | |
1658 | |
1644 } // namespace | 1659 } // namespace |
1645 } // namespace cc | 1660 } // namespace cc |
OLD | NEW |