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

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

Issue 2387333003: cc: Set sync token on resource even if context is lost. (Closed)
Patch Set: danakj's review Created 4 years, 2 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/test/test_web_graphics_context_3d.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 <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
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() {
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 {
82 base::AutoLock lock(context3d_lock_);
83
84 std::unique_ptr<TestWebGraphicsContext3D> compositor_context3d =
85 TestWebGraphicsContext3D::Create();
86 if (context_should_support_io_surface_) {
87 compositor_context3d->set_have_extension_io_surface(true);
88 compositor_context3d->set_have_extension_egl_image(true);
89 }
90 context3d_ = compositor_context3d.get();
91
86 if (times_to_fail_create_) { 92 if (times_to_fail_create_) {
87 --times_to_fail_create_; 93 --times_to_fail_create_;
88 ExpectCreateToFail(); 94 ExpectCreateToFail();
89 auto test_compositor_context_provider = TestContextProvider::Create(); 95 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
90 test_compositor_context_provider->UnboundTestContext3d() 96 GL_INNOCENT_CONTEXT_RESET_ARB);
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
100 std::unique_ptr<OutputSurface> CreateDisplayOutputSurface(
101 scoped_refptr<ContextProvider> compositor_context_provider) override {
102 std::unique_ptr<TestWebGraphicsContext3D> context3d = CreateContext3d();
103 if (context_should_support_io_surface_) {
104 context3d->set_have_extension_io_surface(true);
105 context3d->set_have_extension_egl_image(true);
106 } 97 }
107 98
108 base::AutoLock lock(context3d_lock_); 99 return LayerTreeTest::CreateCompositorFrameSink(
109 context3d_ = context3d.get(); 100 TestContextProvider::Create(std::move(compositor_context3d)),
danakj 2016/10/06 22:59:59 Can you explicitly point out that the context is n
110 return LayerTreeTest::CreateDisplayOutputSurface( 101 std::move(worker_context_provider));
111 TestContextProvider::Create(std::move(context3d)));
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
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
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
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
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
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
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 // This test causes context loss on the worker context but not the compositor
1617 // context and checks that draw still occurs. The resources might be in a bad
1618 // state e.g. null sync tokens but that shouldn't cause the draw to fail.
danakj 2016/10/06 22:09:04 High level question, should we be looking for a GL
sunnyps 2016/10/06 22:29:21 In prod worker context loss implies compositor con
danakj 2016/10/06 22:47:42 They could be put into a share group (I thought I
1619 class LayerTreeHostContextTestLoseWorkerContextDuringPrepareTiles
1620 : public LayerTreeTest {
1621 protected:
1622 void SetupTree() override {
1623 SkPaint paint;
1624 client_.set_fill_with_nonsolid_color(true);
1625 client_.add_draw_rect(gfx::Rect(5, 5), paint);
1626
1627 scoped_refptr<FakePictureLayer> picture_layer =
1628 FakePictureLayer::Create(&client_);
1629 picture_layer->SetBounds(gfx::Size(10, 20));
1630 client_.set_bounds(picture_layer->bounds());
1631 layer_tree()->SetRootLayer(picture_layer);
1632
1633 LayerTreeTest::SetupTree();
1634 }
1635
1636 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
1637
1638 void WillPrepareTilesOnThread(LayerTreeHostImpl* host_impl) override {
1639 ContextProvider::ScopedContextLock scoped_context(
1640 host_impl->compositor_frame_sink()->worker_context_provider());
1641 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL();
1642 gl->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
1643 GL_INNOCENT_CONTEXT_RESET_ARB);
1644 }
1645
1646 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
1647 ++num_draws_;
1648 }
1649
1650 void DidCommitAndDrawFrame() override { EndTest(); }
1651
1652 void AfterTest() override { EXPECT_EQ(1, num_draws_); }
1653
1654 FakeContentLayerClient client_;
1655 int num_draws_ = 0;
1656 };
1657
1658 MULTI_THREAD_TEST_F(
1659 LayerTreeHostContextTestLoseWorkerContextDuringPrepareTiles);
1660
1644 } // namespace 1661 } // namespace
1645 } // namespace cc 1662 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/test_web_graphics_context_3d.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698