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

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

Issue 134623005: Make SingleThreadProxy a SchedulerClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 6 years, 10 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 | Annotate | Revision Log
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 times_to_expect_create_failed_(0), 60 times_to_expect_create_failed_(0),
61 times_create_failed_(0), 61 times_create_failed_(0),
62 times_offscreen_created_(0), 62 times_offscreen_created_(0),
63 committed_at_least_once_(false), 63 committed_at_least_once_(false),
64 context_should_support_io_surface_(false), 64 context_should_support_io_surface_(false),
65 fallback_context_works_(false) { 65 fallback_context_works_(false) {
66 media::InitializeMediaLibraryForTesting(); 66 media::InitializeMediaLibraryForTesting();
67 } 67 }
68 68
69 void LoseContext() { 69 void LoseContext() {
70 context3d_->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 70 // For sanity-checking tests, they should only call this when the
71 GL_INNOCENT_CONTEXT_RESET_ARB); 71 // context is not lost.
72 CHECK(context3d_);
73
74 // Set the context3d_ member to null *before* calling lose context,
75 // as the single-threaded proxy may synchronously recreate the
76 // output surface, setting context3d_ back to not-NULL.
77 TestWebGraphicsContext3D* temp_context3d = context3d_;
72 context3d_ = NULL; 78 context3d_ = NULL;
79 temp_context3d->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
80 GL_INNOCENT_CONTEXT_RESET_ARB);
73 } 81 }
74 82
75 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() { 83 virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() {
76 return TestWebGraphicsContext3D::Create(); 84 return TestWebGraphicsContext3D::Create();
77 } 85 }
78 86
79 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) 87 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback)
80 OVERRIDE { 88 OVERRIDE {
81 if (times_to_fail_create_) { 89 if (times_to_fail_create_) {
82 --times_to_fail_create_; 90 --times_to_fail_create_;
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 // Run a test that initially fails OutputSurface creation |times_to_fail| 498 // Run a test that initially fails OutputSurface creation |times_to_fail|
491 // times. If |expect_fallback_attempt| is |true|, an attempt to create a 499 // times. If |expect_fallback_attempt| is |true|, an attempt to create a
492 // fallback/software OutputSurface is expected to occur. 500 // fallback/software OutputSurface is expected to occur.
493 LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail, 501 LayerTreeHostContextTestCreateOutputSurfaceFails(int times_to_fail,
494 bool expect_fallback_attempt, 502 bool expect_fallback_attempt,
495 bool expect_to_give_up) 503 bool expect_to_give_up)
496 : times_to_fail_(times_to_fail), 504 : times_to_fail_(times_to_fail),
497 expect_fallback_attempt_(expect_fallback_attempt), 505 expect_fallback_attempt_(expect_fallback_attempt),
498 expect_to_give_up_(expect_to_give_up), 506 expect_to_give_up_(expect_to_give_up),
499 did_attempt_fallback_(false), 507 did_attempt_fallback_(false),
500 times_initialized_(0) {} 508 times_initialized_(0) {
509 times_to_fail_create_ = times_to_fail_;
510 }
501 511
502 virtual void BeginTest() OVERRIDE { 512 virtual void BeginTest() OVERRIDE {
503 times_to_fail_create_ = times_to_fail_;
504 PostSetNeedsCommitToMainThread(); 513 PostSetNeedsCommitToMainThread();
505 } 514 }
506 515
507 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback) 516 virtual scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(bool fallback)
508 OVERRIDE { 517 OVERRIDE {
509 scoped_ptr<FakeOutputSurface> surface = 518 scoped_ptr<FakeOutputSurface> surface =
510 LayerTreeHostContextTest::CreateFakeOutputSurface(fallback); 519 LayerTreeHostContextTest::CreateFakeOutputSurface(fallback);
511 520
512 if (surface) 521 if (surface)
513 EXPECT_EQ(times_to_fail_, times_create_failed_); 522 EXPECT_EQ(times_to_fail_, times_create_failed_);
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 bool result) OVERRIDE { 1235 bool result) OVERRIDE {
1227 // We should only swap for the replacement commit. 1236 // We should only swap for the replacement commit.
1228 EXPECT_EQ(host_impl->active_tree()->source_frame_number(), 1); 1237 EXPECT_EQ(host_impl->active_tree()->source_frame_number(), 1);
1229 EndTest(); 1238 EndTest();
1230 } 1239 }
1231 1240
1232 private: 1241 private:
1233 int times_output_surface_created_; 1242 int times_output_surface_created_;
1234 }; 1243 };
1235 1244
1236 SINGLE_AND_MULTI_THREAD_TEST_F( 1245 // This test is only valid for the multi-threaded proxy. The single-threaded
1246 // case synchronously creates the first output surface (tested just below)
1247 // and so there is no way that a readback could happen during this time.
1248 MULTI_THREAD_TEST_F(
1237 LayerTreeHostContextTestCompositeAndReadbackBeforeOutputSurfaceInit); 1249 LayerTreeHostContextTestCompositeAndReadbackBeforeOutputSurfaceInit);
1238 1250
1251 class LayerTreeHostContextTestSingleThreadSynchronouslyCreatesOutputSurface
1252 : public LayerTreeHostContextTest {
1253 public:
1254 virtual void WillBeginTest() OVERRIDE {
1255 // Output surface should be synchronously created, to avoid any potential
1256 // readback issues before the first output surface is created.
1257 ASSERT_TRUE(layer_tree_host()->output_surface_lost());
1258 LayerTreeHostContextTest::WillBeginTest();
1259 ASSERT_FALSE(layer_tree_host()->output_surface_lost());
1260 }
1261
1262 virtual void BeginTest() OVERRIDE { EndTest(); }
1263 virtual void AfterTest() OVERRIDE {}
1264 };
1265 SINGLE_THREAD_TEST_F(
1266 LayerTreeHostContextTestSingleThreadSynchronouslyCreatesOutputSurface);
1267
1239 // This test verifies that losing an output surface during a 1268 // This test verifies that losing an output surface during a
1240 // simultaneous readback and forced redraw works and does not deadlock. 1269 // simultaneous readback and forced redraw works and does not deadlock.
1241 class LayerTreeHostContextTestLoseOutputSurfaceDuringReadbackAndForcedDraw 1270 class LayerTreeHostContextTestLoseOutputSurfaceDuringReadbackAndForcedDraw
1242 : public LayerTreeHostContextTest { 1271 : public LayerTreeHostContextTest {
1243 protected: 1272 protected:
1244 static const int kFirstOutputSurfaceInitSourceFrameNumber = 0; 1273 static const int kFirstOutputSurfaceInitSourceFrameNumber = 0;
1245 static const int kReadbackSourceFrameNumber = 1; 1274 static const int kReadbackSourceFrameNumber = 1;
1246 static const int kReadbackReplacementSourceFrameNumber = 2; 1275 static const int kReadbackReplacementSourceFrameNumber = 2;
1247 static const int kSecondOutputSurfaceInitSourceFrameNumber = 3; 1276 static const int kSecondOutputSurfaceInitSourceFrameNumber = 3;
1248 1277
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 EXPECT_EQ(1, scrollbar_layer_->update_count()); 1504 EXPECT_EQ(1, scrollbar_layer_->update_count());
1476 LoseContext(); 1505 LoseContext();
1477 break; 1506 break;
1478 case 2: 1507 case 2:
1479 // Second update, after the lost context, we should still upload 2 1508 // Second update, after the lost context, we should still upload 2
1480 // resources even if the contents haven't changed. 1509 // resources even if the contents haven't changed.
1481 EXPECT_EQ(2, scrollbar_layer_->update_count()); 1510 EXPECT_EQ(2, scrollbar_layer_->update_count());
1482 EndTest(); 1511 EndTest();
1483 break; 1512 break;
1484 case 3: 1513 case 3:
1485 // Single thread proxy issues extra commits after context lost. 1514 // Single thread proxy issues extra commits after context lost.
danakj 2014/02/19 20:42:39 How come these other cases aren't fixed by this CL
enne (OOO) 2014/02/20 00:35:44 Good catch. Done.
1486 // http://crbug.com/287250 1515 // http://crbug.com/287250
1487 if (HasImplThread()) 1516 if (HasImplThread())
1488 NOTREACHED(); 1517 NOTREACHED();
1489 break; 1518 break;
1490 default: 1519 default:
1491 NOTREACHED(); 1520 NOTREACHED();
1492 } 1521 }
1493 } 1522 }
1494 1523
1495 private: 1524 private:
(...skipping 27 matching lines...) Expand all
1523 void PostStepCompleteToMainThread() { 1552 void PostStepCompleteToMainThread() {
1524 proxy()->MainThreadTaskRunner()->PostTask( 1553 proxy()->MainThreadTaskRunner()->PostTask(
1525 FROM_HERE, 1554 FROM_HERE,
1526 base::Bind(&UIResourceLostTest::StepCompleteOnMainThreadInternal, 1555 base::Bind(&UIResourceLostTest::StepCompleteOnMainThreadInternal,
1527 base::Unretained(this), 1556 base::Unretained(this),
1528 time_step_)); 1557 time_step_));
1529 } 1558 }
1530 1559
1531 void PostLoseContextToImplThread() { 1560 void PostLoseContextToImplThread() {
1532 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); 1561 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread());
1533 base::SingleThreadTaskRunner* task_runner = 1562 ImplThreadTaskRunner()->PostTask(
1534 HasImplThread() ? ImplThreadTaskRunner() 1563 FROM_HERE,
1535 : base::MessageLoopProxy::current(); 1564 base::Bind(&LayerTreeHostContextTest::LoseContext,
1536 task_runner->PostTask(FROM_HERE, 1565 base::Unretained(this)));
1537 base::Bind(&LayerTreeHostContextTest::LoseContext,
1538 base::Unretained(this)));
1539 } 1566 }
1540 1567
1541 protected: 1568 protected:
1542 int time_step_; 1569 int time_step_;
1543 scoped_ptr<FakeScopedUIResource> ui_resource_; 1570 scoped_ptr<FakeScopedUIResource> ui_resource_;
1544 1571
1545 private: 1572 private:
1546 void StepCompleteOnMainThreadInternal(int step) { 1573 void StepCompleteOnMainThreadInternal(int step) {
1547 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); 1574 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread());
1548 StepCompleteOnMainThread(step); 1575 StepCompleteOnMainThread(step);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 layer_tree_host()->DeleteUIResource(test_id0_); 1704 layer_tree_host()->DeleteUIResource(test_id0_);
1678 // Delete the resouce and then lose the context. 1705 // Delete the resouce and then lose the context.
1679 PostLoseContextToImplThread(); 1706 PostLoseContextToImplThread();
1680 break; 1707 break;
1681 case 5: 1708 case 5:
1682 // Release resource before ending the test. 1709 // Release resource before ending the test.
1683 ui_resource_.reset(); 1710 ui_resource_.reset();
1684 EndTest(); 1711 EndTest();
1685 break; 1712 break;
1686 case 6: 1713 case 6:
1687 // Single thread proxy issues extra commits after context lost. 1714 NOTREACHED();
1688 // http://crbug.com/287250
1689 if (HasImplThread())
1690 NOTREACHED();
1691 break; 1715 break;
1692 case 8:
1693 NOTREACHED();
1694 } 1716 }
1695 } 1717 }
1696 1718
1697 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { 1719 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE {
1698 LayerTreeHostContextTest::CommitCompleteOnThread(impl); 1720 LayerTreeHostContextTest::CommitCompleteOnThread(impl);
1699 switch (time_step_) { 1721 switch (time_step_) {
1700 case 1: 1722 case 1:
1701 // Sequence 1 (continued): 1723 // Sequence 1 (continued):
1702 // The first context lost happens before the resources were created, 1724 // The first context lost happens before the resources were created,
1703 // and because it resulted in no resources being destroyed, it does not 1725 // and because it resulted in no resources being destroyed, it does not
1704 // trigger resource re-creation. 1726 // trigger resource re-creation.
1705 EXPECT_EQ(1, ui_resource_->resource_create_count); 1727 EXPECT_EQ(1, ui_resource_->resource_create_count);
1706 EXPECT_EQ(0, ui_resource_->lost_resource_count); 1728 EXPECT_EQ(0, ui_resource_->lost_resource_count);
1707 // Resource Id on the impl-side has been created. 1729 // Resource Id on the impl-side has been created.
1708 PostSetNeedsCommitToMainThread(); 1730 PostSetNeedsCommitToMainThread();
1709 break; 1731 break;
1710 case 3: 1732 case 3:
1711 // Sequence 2 (continued): 1733 // Sequence 2 (continued):
1712 // The previous resource should have been deleted. 1734 // The previous resource should have been deleted.
1713 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); 1735 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_));
1714 if (HasImplThread()) { 1736 // The second resource should have been created.
1715 // The second resource should have been created. 1737 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_));
1716 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_));
1717 } else {
1718 // The extra commit that happens at context lost in the single thread
1719 // proxy changes the timing so that the resource has been destroyed.
1720 // http://crbug.com/287250
1721 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id1_));
1722 }
1723 // The second resource called the resource callback once and since the 1738 // The second resource called the resource callback once and since the
1724 // context is lost, a "resource lost" callback was also issued. 1739 // context is lost, a "resource lost" callback was also issued.
1725 EXPECT_EQ(2, ui_resource_->resource_create_count); 1740 EXPECT_EQ(2, ui_resource_->resource_create_count);
1726 EXPECT_EQ(1, ui_resource_->lost_resource_count); 1741 EXPECT_EQ(1, ui_resource_->lost_resource_count);
1727 break; 1742 break;
1728 case 5: 1743 case 5:
1729 // Sequence 3 (continued): 1744 // Sequence 3 (continued):
1730 // Expect the resource callback to have been called once. 1745 // Expect the resource callback to have been called once.
1731 EXPECT_EQ(1, ui_resource_->resource_create_count); 1746 EXPECT_EQ(1, ui_resource_->resource_create_count);
1732 // No "resource lost" callbacks. 1747 // No "resource lost" callbacks.
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1978 1993
1979 protected: 1994 protected:
1980 FakeContentLayerClient client_; 1995 FakeContentLayerClient client_;
1981 scoped_refptr<FakeContentLayer> layer_; 1996 scoped_refptr<FakeContentLayer> layer_;
1982 }; 1997 };
1983 1998
1984 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); 1999 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback);
1985 2000
1986 } // namespace 2001 } // namespace
1987 } // namespace cc 2002 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698