| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/layer_tree_host.h" | 5 #include "cc/layer_tree_host.h" |
| 6 | 6 |
| 7 #include "base/synchronization/lock.h" | 7 #include "base/synchronization/lock.h" |
| 8 #include "cc/content_layer.h" | 8 #include "cc/content_layer.h" |
| 9 #include "cc/content_layer_client.h" | 9 #include "cc/content_layer_client.h" |
| 10 #include "cc/layer_impl.h" | 10 #include "cc/layer_impl.h" |
| (...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 scoped_refptr<ContentLayerWithUpdateTracking> m_parent; | 1228 scoped_refptr<ContentLayerWithUpdateTracking> m_parent; |
| 1229 scoped_refptr<ContentLayerWithUpdateTracking> m_child; | 1229 scoped_refptr<ContentLayerWithUpdateTracking> m_child; |
| 1230 int m_numCommits; | 1230 int m_numCommits; |
| 1231 }; | 1231 }; |
| 1232 | 1232 |
| 1233 TEST_F(LayerTreeHostTestAtomicCommitWithPartialUpdate, runMultiThread) | 1233 TEST_F(LayerTreeHostTestAtomicCommitWithPartialUpdate, runMultiThread) |
| 1234 { | 1234 { |
| 1235 runTest(true); | 1235 runTest(true); |
| 1236 } | 1236 } |
| 1237 | 1237 |
| 1238 // A loseOutputSurface(1) should lead to a didRecreateOutputSurface(true) | |
| 1239 class LayerTreeHostTestSetSingleLostContext : public LayerTreeHostTest { | |
| 1240 public: | |
| 1241 LayerTreeHostTestSetSingleLostContext() | |
| 1242 { | |
| 1243 } | |
| 1244 | |
| 1245 virtual void beginTest() OVERRIDE | |
| 1246 { | |
| 1247 postSetNeedsCommitToMainThread(); | |
| 1248 } | |
| 1249 | |
| 1250 virtual void didCommitAndDrawFrame() OVERRIDE | |
| 1251 { | |
| 1252 m_layerTreeHost->loseOutputSurface(1); | |
| 1253 } | |
| 1254 | |
| 1255 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE | |
| 1256 { | |
| 1257 EXPECT_TRUE(succeeded); | |
| 1258 endTest(); | |
| 1259 } | |
| 1260 | |
| 1261 virtual void afterTest() OVERRIDE | |
| 1262 { | |
| 1263 } | |
| 1264 }; | |
| 1265 | |
| 1266 TEST_F(LayerTreeHostTestSetSingleLostContext, runMultiThread) | |
| 1267 { | |
| 1268 runTest(true); | |
| 1269 } | |
| 1270 | |
| 1271 // A loseOutputSurface(10) should lead to a didRecreateOutputSurface(false), and | |
| 1272 // a finishAllRendering() should not hang. | |
| 1273 class LayerTreeHostTestSetRepeatedLostContext : public LayerTreeHostTest { | |
| 1274 public: | |
| 1275 LayerTreeHostTestSetRepeatedLostContext() | |
| 1276 { | |
| 1277 } | |
| 1278 | |
| 1279 virtual void beginTest() OVERRIDE | |
| 1280 { | |
| 1281 postSetNeedsCommitToMainThread(); | |
| 1282 } | |
| 1283 | |
| 1284 virtual void didCommitAndDrawFrame() OVERRIDE | |
| 1285 { | |
| 1286 m_layerTreeHost->loseOutputSurface(10); | |
| 1287 } | |
| 1288 | |
| 1289 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE | |
| 1290 { | |
| 1291 EXPECT_FALSE(succeeded); | |
| 1292 m_layerTreeHost->finishAllRendering(); | |
| 1293 endTest(); | |
| 1294 } | |
| 1295 | |
| 1296 virtual void afterTest() OVERRIDE | |
| 1297 { | |
| 1298 } | |
| 1299 }; | |
| 1300 | |
| 1301 TEST_F(LayerTreeHostTestSetRepeatedLostContext, runMultiThread) | |
| 1302 { | |
| 1303 runTest(true); | |
| 1304 } | |
| 1305 | |
| 1306 class LayerTreeHostTestFinishAllRendering : public LayerTreeHostTest { | 1238 class LayerTreeHostTestFinishAllRendering : public LayerTreeHostTest { |
| 1307 public: | 1239 public: |
| 1308 LayerTreeHostTestFinishAllRendering() | 1240 LayerTreeHostTestFinishAllRendering() |
| 1309 : m_once(false) | 1241 : m_once(false) |
| 1310 , m_drawCount(0) | 1242 , m_drawCount(0) |
| 1311 { | 1243 { |
| 1312 } | 1244 } |
| 1313 | 1245 |
| 1314 virtual void beginTest() OVERRIDE | 1246 virtual void beginTest() OVERRIDE |
| 1315 { | 1247 { |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1671 scoped_refptr<EvictionTestLayer> m_layer; | 1603 scoped_refptr<EvictionTestLayer> m_layer; |
| 1672 LayerTreeHostImpl* m_implForEvictTextures; | 1604 LayerTreeHostImpl* m_implForEvictTextures; |
| 1673 int m_numCommits; | 1605 int m_numCommits; |
| 1674 }; | 1606 }; |
| 1675 | 1607 |
| 1676 TEST_F(LayerTreeHostTestEvictTextures, runMultiThread) | 1608 TEST_F(LayerTreeHostTestEvictTextures, runMultiThread) |
| 1677 { | 1609 { |
| 1678 runTest(true); | 1610 runTest(true); |
| 1679 } | 1611 } |
| 1680 | 1612 |
| 1681 class LayerTreeHostTestLostContextAfterEvictTextures : public LayerTreeHostTest
{ | |
| 1682 public: | |
| 1683 LayerTreeHostTestLostContextAfterEvictTextures() | |
| 1684 : m_layer(EvictionTestLayer::create()) | |
| 1685 , m_implForEvictTextures(0) | |
| 1686 , m_numCommits(0) | |
| 1687 { | |
| 1688 } | |
| 1689 | |
| 1690 virtual void beginTest() OVERRIDE | |
| 1691 { | |
| 1692 m_layerTreeHost->setRootLayer(m_layer); | |
| 1693 m_layerTreeHost->setViewportSize(gfx::Size(10, 20), gfx::Size(10, 20)); | |
| 1694 | |
| 1695 gfx::Transform identityMatrix; | |
| 1696 setLayerPropertiesForTesting(m_layer.get(), 0, identityMatrix, gfx::Poin
tF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 20), true); | |
| 1697 | |
| 1698 postSetNeedsCommitToMainThread(); | |
| 1699 } | |
| 1700 | |
| 1701 void postEvictTextures() | |
| 1702 { | |
| 1703 if (implThread()) { | |
| 1704 implThread()->postTask(base::Bind(&LayerTreeHostTestLostContextAfter
EvictTextures::evictTexturesOnImplThread, | |
| 1705 base::Unretained(this))); | |
| 1706 } else { | |
| 1707 DebugScopedSetImplThread impl(proxy()); | |
| 1708 evictTexturesOnImplThread(); | |
| 1709 } | |
| 1710 } | |
| 1711 | |
| 1712 void evictTexturesOnImplThread() | |
| 1713 { | |
| 1714 DCHECK(m_implForEvictTextures); | |
| 1715 m_implForEvictTextures->enforceManagedMemoryPolicy(ManagedMemoryPolicy(0
)); | |
| 1716 } | |
| 1717 | |
| 1718 // Commit 1: Just commit and draw normally, then at the end, set ourselves | |
| 1719 // invisible (to prevent a commit that would recreate textures after | |
| 1720 // eviction, before the context recovery), and post a task that will evict | |
| 1721 // textures, then cause the context to be lost, and then set ourselves | |
| 1722 // visible again (to allow commits, since that's what causes context | |
| 1723 // recovery in single thread). | |
| 1724 virtual void didCommitAndDrawFrame() OVERRIDE | |
| 1725 { | |
| 1726 ++m_numCommits; | |
| 1727 switch (m_numCommits) { | |
| 1728 case 1: | |
| 1729 EXPECT_TRUE(m_layer->haveBackingTexture()); | |
| 1730 m_layerTreeHost->setVisible(false); | |
| 1731 postEvictTextures(); | |
| 1732 m_layerTreeHost->loseOutputSurface(1); | |
| 1733 m_layerTreeHost->setVisible(true); | |
| 1734 break; | |
| 1735 default: | |
| 1736 break; | |
| 1737 } | |
| 1738 } | |
| 1739 | |
| 1740 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | |
| 1741 { | |
| 1742 m_implForEvictTextures = impl; | |
| 1743 } | |
| 1744 | |
| 1745 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE | |
| 1746 { | |
| 1747 EXPECT_TRUE(succeeded); | |
| 1748 endTest(); | |
| 1749 } | |
| 1750 | |
| 1751 virtual void afterTest() OVERRIDE | |
| 1752 { | |
| 1753 } | |
| 1754 | |
| 1755 private: | |
| 1756 FakeContentLayerClient m_client; | |
| 1757 scoped_refptr<EvictionTestLayer> m_layer; | |
| 1758 LayerTreeHostImpl* m_implForEvictTextures; | |
| 1759 int m_numCommits; | |
| 1760 }; | |
| 1761 | |
| 1762 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLostContextAfterEvictTextures) | |
| 1763 | |
| 1764 class FakeWebGraphicsContext3DWithEndQueryCausingLostContext : public FakeWebGra
phicsContext3D { | |
| 1765 public: | |
| 1766 static scoped_ptr<FakeWebGraphicsContext3DWithEndQueryCausingLostContext> cr
eate(Attributes attrs) | |
| 1767 { | |
| 1768 return make_scoped_ptr(new FakeWebGraphicsContext3DWithEndQueryCausingLo
stContext(attrs)); | |
| 1769 } | |
| 1770 | |
| 1771 virtual void setContextLostCallback(WebGraphicsContextLostCallback* callback
) { m_contextLostCallback = callback; } | |
| 1772 virtual bool isContextLost() { return m_isContextLost; } | |
| 1773 | |
| 1774 virtual void beginQueryEXT(WebKit::WGC3Denum, WebKit::WebGLId) { } | |
| 1775 virtual void endQueryEXT(WebKit::WGC3Denum) | |
| 1776 { | |
| 1777 // Lose context. | |
| 1778 if (!m_isContextLost) { | |
| 1779 m_contextLostCallback->onContextLost(); | |
| 1780 m_isContextLost = true; | |
| 1781 } | |
| 1782 } | |
| 1783 virtual void getQueryObjectuivEXT(WebKit::WebGLId, WebKit::WGC3Denum pname,
WebKit::WGC3Duint* params) | |
| 1784 { | |
| 1785 // Context is lost. We need to behave as if result is available. | |
| 1786 if (pname == GL_QUERY_RESULT_AVAILABLE_EXT) | |
| 1787 *params = 1; | |
| 1788 } | |
| 1789 | |
| 1790 private: | |
| 1791 explicit FakeWebGraphicsContext3DWithEndQueryCausingLostContext(Attributes a
ttrs) | |
| 1792 : FakeWebGraphicsContext3D(attrs) | |
| 1793 , m_contextLostCallback(0) | |
| 1794 , m_isContextLost(false) { } | |
| 1795 | |
| 1796 WebGraphicsContextLostCallback* m_contextLostCallback; | |
| 1797 bool m_isContextLost; | |
| 1798 }; | |
| 1799 | |
| 1800 class LayerTreeHostTestLostContextWhileUpdatingResources : public LayerTreeHostT
est { | |
| 1801 public: | |
| 1802 LayerTreeHostTestLostContextWhileUpdatingResources() | |
| 1803 : m_parent(ContentLayerWithUpdateTracking::create(&m_client)) | |
| 1804 , m_numChildren(50) | |
| 1805 { | |
| 1806 for (int i = 0; i < m_numChildren; i++) | |
| 1807 m_children.push_back(ContentLayerWithUpdateTracking::create(&m_clien
t)); | |
| 1808 } | |
| 1809 | |
| 1810 virtual void beginTest() | |
| 1811 { | |
| 1812 m_layerTreeHost->setRootLayer(m_parent); | |
| 1813 m_layerTreeHost->setViewportSize(gfx::Size(m_numChildren, 1), gfx::Size(
m_numChildren, 1)); | |
| 1814 | |
| 1815 gfx::Transform identityMatrix; | |
| 1816 setLayerPropertiesForTesting(m_parent.get(), 0, identityMatrix, gfx::Poi
ntF(0, 0), gfx::PointF(0, 0), gfx::Size(m_numChildren, 1), true); | |
| 1817 for (int i = 0; i < m_numChildren; i++) | |
| 1818 setLayerPropertiesForTesting(m_children[i].get(), m_parent.get(), id
entityMatrix, gfx::PointF(0, 0), gfx::PointF(i, 0), gfx::Size(1, 1), false); | |
| 1819 | |
| 1820 postSetNeedsCommitToMainThread(); | |
| 1821 } | |
| 1822 | |
| 1823 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) | |
| 1824 { | |
| 1825 endTest(); | |
| 1826 } | |
| 1827 | |
| 1828 virtual void layout() | |
| 1829 { | |
| 1830 m_parent->setNeedsDisplay(); | |
| 1831 for (int i = 0; i < m_numChildren; i++) | |
| 1832 m_children[i]->setNeedsDisplay(); | |
| 1833 } | |
| 1834 | |
| 1835 virtual void afterTest() | |
| 1836 { | |
| 1837 } | |
| 1838 | |
| 1839 private: | |
| 1840 FakeContentLayerClient m_client; | |
| 1841 scoped_refptr<ContentLayerWithUpdateTracking> m_parent; | |
| 1842 int m_numChildren; | |
| 1843 std::vector<scoped_refptr<ContentLayerWithUpdateTracking> > m_children; | |
| 1844 }; | |
| 1845 | |
| 1846 TEST_F(LayerTreeHostTestLostContextWhileUpdatingResources, runMultiThread) | |
| 1847 { | |
| 1848 runTest(true); | |
| 1849 } | |
| 1850 | |
| 1851 class LayerTreeHostTestContinuousCommit : public LayerTreeHostTest { | 1613 class LayerTreeHostTestContinuousCommit : public LayerTreeHostTest { |
| 1852 public: | 1614 public: |
| 1853 LayerTreeHostTestContinuousCommit() | 1615 LayerTreeHostTestContinuousCommit() |
| 1854 : m_numCommitComplete(0) | 1616 : m_numCommitComplete(0) |
| 1855 , m_numDrawLayers(0) | 1617 , m_numDrawLayers(0) |
| 1856 { | 1618 { |
| 1857 } | 1619 } |
| 1858 | 1620 |
| 1859 virtual void beginTest() OVERRIDE | 1621 virtual void beginTest() OVERRIDE |
| 1860 { | 1622 { |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2174 LayerTreeSettings settings; | 1936 LayerTreeSettings settings; |
| 2175 settings.maxPartialTextureUpdates = 4; | 1937 settings.maxPartialTextureUpdates = 4; |
| 2176 | 1938 |
| 2177 scoped_ptr<LayerTreeHost> host = LayerTreeHost::create(&client, settings, sc
oped_ptr<Thread>()); | 1939 scoped_ptr<LayerTreeHost> host = LayerTreeHost::create(&client, settings, sc
oped_ptr<Thread>()); |
| 2178 EXPECT_TRUE(host->initializeRendererIfNeeded()); | 1940 EXPECT_TRUE(host->initializeRendererIfNeeded()); |
| 2179 EXPECT_EQ(0u, host->settings().maxPartialTextureUpdates); | 1941 EXPECT_EQ(0u, host->settings().maxPartialTextureUpdates); |
| 2180 } | 1942 } |
| 2181 | 1943 |
| 2182 } // namespace | 1944 } // namespace |
| 2183 } // namespace cc | 1945 } // namespace cc |
| OLD | NEW |