| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|    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  Loading... | 
|   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  Loading... | 
|  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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1474         // backtrack). |  1503         // backtrack). | 
|  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: |  | 
|  1485         // Single thread proxy issues extra commits after context lost. |  | 
|  1486         // http://crbug.com/287250 |  | 
|  1487         if (HasImplThread()) |  | 
|  1488           NOTREACHED(); |  | 
|  1489         break; |  | 
|  1490       default: |  1513       default: | 
|  1491         NOTREACHED(); |  1514         NOTREACHED(); | 
|  1492     } |  1515     } | 
|  1493   } |  1516   } | 
|  1494  |  1517  | 
|  1495  private: |  1518  private: | 
|  1496   int commits_; |  1519   int commits_; | 
|  1497   scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_; |  1520   scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_; | 
|  1498 }; |  1521 }; | 
|  1499  |  1522  | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
|  1523   void PostStepCompleteToMainThread() { |  1546   void PostStepCompleteToMainThread() { | 
|  1524     proxy()->MainThreadTaskRunner()->PostTask( |  1547     proxy()->MainThreadTaskRunner()->PostTask( | 
|  1525         FROM_HERE, |  1548         FROM_HERE, | 
|  1526         base::Bind(&UIResourceLostTest::StepCompleteOnMainThreadInternal, |  1549         base::Bind(&UIResourceLostTest::StepCompleteOnMainThreadInternal, | 
|  1527                    base::Unretained(this), |  1550                    base::Unretained(this), | 
|  1528                    time_step_)); |  1551                    time_step_)); | 
|  1529   } |  1552   } | 
|  1530  |  1553  | 
|  1531   void PostLoseContextToImplThread() { |  1554   void PostLoseContextToImplThread() { | 
|  1532     EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |  1555     EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 
|  1533     base::SingleThreadTaskRunner* task_runner = |  1556     ImplThreadTaskRunner()->PostTask( | 
|  1534         HasImplThread() ? ImplThreadTaskRunner() |  1557         FROM_HERE, | 
|  1535                         : base::MessageLoopProxy::current(); |  1558         base::Bind(&LayerTreeHostContextTest::LoseContext, | 
|  1536     task_runner->PostTask(FROM_HERE, |  1559                    base::Unretained(this))); | 
|  1537                           base::Bind(&LayerTreeHostContextTest::LoseContext, |  | 
|  1538                                      base::Unretained(this))); |  | 
|  1539   } |  1560   } | 
|  1540  |  1561  | 
|  1541  protected: |  1562  protected: | 
|  1542   int time_step_; |  1563   int time_step_; | 
|  1543   scoped_ptr<FakeScopedUIResource> ui_resource_; |  1564   scoped_ptr<FakeScopedUIResource> ui_resource_; | 
|  1544  |  1565  | 
|  1545  private: |  1566  private: | 
|  1546   void StepCompleteOnMainThreadInternal(int step) { |  1567   void StepCompleteOnMainThreadInternal(int step) { | 
|  1547     EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |  1568     EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 
|  1548     StepCompleteOnMainThread(step); |  1569     StepCompleteOnMainThread(step); | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1583         // Expects a valid UIResourceId. |  1604         // Expects a valid UIResourceId. | 
|  1584         EXPECT_NE(0, ui_resource_->id()); |  1605         EXPECT_NE(0, ui_resource_->id()); | 
|  1585         PostSetNeedsCommitToMainThread(); |  1606         PostSetNeedsCommitToMainThread(); | 
|  1586         break; |  1607         break; | 
|  1587       case 4: |  1608       case 4: | 
|  1588         // Release resource before ending the test. |  1609         // Release resource before ending the test. | 
|  1589         ui_resource_.reset(); |  1610         ui_resource_.reset(); | 
|  1590         EndTest(); |  1611         EndTest(); | 
|  1591         break; |  1612         break; | 
|  1592       case 5: |  1613       case 5: | 
|  1593         // Single thread proxy issues extra commits after context lost. |  1614         NOTREACHED(); | 
|  1594         // http://crbug.com/287250 |  | 
|  1595         if (HasImplThread()) |  | 
|  1596           NOTREACHED(); |  | 
|  1597         break; |  1615         break; | 
|  1598       case 6: |  | 
|  1599         NOTREACHED(); |  | 
|  1600     } |  1616     } | 
|  1601   } |  1617   } | 
|  1602  |  1618  | 
|  1603   virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { |  1619   virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { | 
|  1604     LayerTreeHostContextTest::CommitCompleteOnThread(impl); |  1620     LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 
|  1605     switch (time_step_) { |  1621     switch (time_step_) { | 
|  1606       case 1: |  1622       case 1: | 
|  1607         // The resource should have been created on LTHI after the commit. |  1623         // The resource should have been created on LTHI after the commit. | 
|  1608         EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |  1624         EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 
|  1609         PostSetNeedsCommitToMainThread(); |  1625         PostSetNeedsCommitToMainThread(); | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1677         layer_tree_host()->DeleteUIResource(test_id0_); |  1693         layer_tree_host()->DeleteUIResource(test_id0_); | 
|  1678         // Delete the resouce and then lose the context. |  1694         // Delete the resouce and then lose the context. | 
|  1679         PostLoseContextToImplThread(); |  1695         PostLoseContextToImplThread(); | 
|  1680         break; |  1696         break; | 
|  1681       case 5: |  1697       case 5: | 
|  1682         // Release resource before ending the test. |  1698         // Release resource before ending the test. | 
|  1683         ui_resource_.reset(); |  1699         ui_resource_.reset(); | 
|  1684         EndTest(); |  1700         EndTest(); | 
|  1685         break; |  1701         break; | 
|  1686       case 6: |  1702       case 6: | 
|  1687         // Single thread proxy issues extra commits after context lost. |  1703         NOTREACHED(); | 
|  1688         // http://crbug.com/287250 |  | 
|  1689         if (HasImplThread()) |  | 
|  1690           NOTREACHED(); |  | 
|  1691         break; |  1704         break; | 
|  1692       case 8: |  | 
|  1693         NOTREACHED(); |  | 
|  1694     } |  1705     } | 
|  1695   } |  1706   } | 
|  1696  |  1707  | 
|  1697   virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { |  1708   virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { | 
|  1698     LayerTreeHostContextTest::CommitCompleteOnThread(impl); |  1709     LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 
|  1699     switch (time_step_) { |  1710     switch (time_step_) { | 
|  1700       case 1: |  1711       case 1: | 
|  1701         // Sequence 1 (continued): |  1712         // Sequence 1 (continued): | 
|  1702         // The first context lost happens before the resources were created, |  1713         // The first context lost happens before the resources were created, | 
|  1703         // and because it resulted in no resources being destroyed, it does not |  1714         // and because it resulted in no resources being destroyed, it does not | 
|  1704         // trigger resource re-creation. |  1715         // trigger resource re-creation. | 
|  1705         EXPECT_EQ(1, ui_resource_->resource_create_count); |  1716         EXPECT_EQ(1, ui_resource_->resource_create_count); | 
|  1706         EXPECT_EQ(0, ui_resource_->lost_resource_count); |  1717         EXPECT_EQ(0, ui_resource_->lost_resource_count); | 
|  1707         // Resource Id on the impl-side has been created. |  1718         // Resource Id on the impl-side has been created. | 
|  1708         PostSetNeedsCommitToMainThread(); |  1719         PostSetNeedsCommitToMainThread(); | 
|  1709         break; |  1720         break; | 
|  1710       case 3: |  1721       case 3: | 
|  1711         // Sequence 2 (continued): |  1722         // Sequence 2 (continued): | 
|  1712         // The previous resource should have been deleted. |  1723         // The previous resource should have been deleted. | 
|  1713         EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); |  1724         EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); | 
|  1714         if (HasImplThread()) { |  1725         // The second resource should have been created. | 
|  1715           // The second resource should have been created. |  1726         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 |  1727         // The second resource called the resource callback once and since the | 
|  1724         // context is lost, a "resource lost" callback was also issued. |  1728         // context is lost, a "resource lost" callback was also issued. | 
|  1725         EXPECT_EQ(2, ui_resource_->resource_create_count); |  1729         EXPECT_EQ(2, ui_resource_->resource_create_count); | 
|  1726         EXPECT_EQ(1, ui_resource_->lost_resource_count); |  1730         EXPECT_EQ(1, ui_resource_->lost_resource_count); | 
|  1727         break; |  1731         break; | 
|  1728       case 5: |  1732       case 5: | 
|  1729         // Sequence 3 (continued): |  1733         // Sequence 3 (continued): | 
|  1730         // Expect the resource callback to have been called once. |  1734         // Expect the resource callback to have been called once. | 
|  1731         EXPECT_EQ(1, ui_resource_->resource_create_count); |  1735         EXPECT_EQ(1, ui_resource_->resource_create_count); | 
|  1732         // No "resource lost" callbacks. |  1736         // No "resource lost" callbacks. | 
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1978  |  1982  | 
|  1979  protected: |  1983  protected: | 
|  1980   FakeContentLayerClient client_; |  1984   FakeContentLayerClient client_; | 
|  1981   scoped_refptr<FakeContentLayer> layer_; |  1985   scoped_refptr<FakeContentLayer> layer_; | 
|  1982 }; |  1986 }; | 
|  1983  |  1987  | 
|  1984 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); |  1988 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); | 
|  1985  |  1989  | 
|  1986 }  // namespace |  1990 }  // namespace | 
|  1987 }  // namespace cc |  1991 }  // namespace cc | 
| OLD | NEW |