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

Side by Side Diff: cc/layer_tree_host_unittest.cc

Issue 11662003: cc: Put context-loss tests in layer_tree_host_unittest_context.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 80cols Created 7 years, 11 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
« no previous file with comments | « cc/layer_tree_host_impl_unittest.cc ('k') | cc/layer_tree_host_unittest_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 991 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 m_settings.maxPartialTextureUpdates = 0; 1002 m_settings.maxPartialTextureUpdates = 0;
1003 // Linear fade animator prevents scrollbars from drawing immediately. 1003 // Linear fade animator prevents scrollbars from drawing immediately.
1004 m_settings.useLinearFadeScrollbarAnimator = false; 1004 m_settings.useLinearFadeScrollbarAnimator = false;
1005 } 1005 }
1006 1006
1007 virtual void setupTree() OVERRIDE 1007 virtual void setupTree() OVERRIDE
1008 { 1008 {
1009 m_layer = FakeContentLayer::Create(&m_client); 1009 m_layer = FakeContentLayer::Create(&m_client);
1010 m_layer->setBounds(gfx::Size(10, 20)); 1010 m_layer->setBounds(gfx::Size(10, 20));
1011 1011
1012 m_scrollbar = FakeScrollbarLayer::Create(true, m_layer->id()); 1012 bool paint_scrollbar = true;
1013 bool has_thumb = false;
1014 m_scrollbar = FakeScrollbarLayer::Create(
1015 paint_scrollbar, has_thumb, m_layer->id());
1013 m_scrollbar->setPosition(gfx::Point(0, 10)); 1016 m_scrollbar->setPosition(gfx::Point(0, 10));
1014 m_scrollbar->setBounds(gfx::Size(10, 10)); 1017 m_scrollbar->setBounds(gfx::Size(10, 10));
1015 1018
1016 m_layer->addChild(m_scrollbar); 1019 m_layer->addChild(m_scrollbar);
1017 1020
1018 m_layerTreeHost->setRootLayer(m_layer); 1021 m_layerTreeHost->setRootLayer(m_layer);
1019 LayerTreeHostTest::setupTree(); 1022 LayerTreeHostTest::setupTree();
1020 } 1023 }
1021 1024
1022 virtual void beginTest() OVERRIDE 1025 virtual void beginTest() OVERRIDE
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 1126
1124 virtual void setupTree() OVERRIDE 1127 virtual void setupTree() OVERRIDE
1125 { 1128 {
1126 m_parent = FakeContentLayer::Create(&m_client); 1129 m_parent = FakeContentLayer::Create(&m_client);
1127 m_parent->setBounds(gfx::Size(10, 20)); 1130 m_parent->setBounds(gfx::Size(10, 20));
1128 1131
1129 m_child = FakeContentLayer::Create(&m_client); 1132 m_child = FakeContentLayer::Create(&m_client);
1130 m_child->setPosition(gfx::Point(0, 10)); 1133 m_child->setPosition(gfx::Point(0, 10));
1131 m_child->setBounds(gfx::Size(3, 10)); 1134 m_child->setBounds(gfx::Size(3, 10));
1132 1135
1133 m_scrollbarWithPaints = 1136 bool paint_scrollbar = true;
1134 FakeScrollbarLayer::Create(true, m_parent->id()); 1137 bool has_thumb = false;
1138 m_scrollbarWithPaints = FakeScrollbarLayer::Create(
1139 paint_scrollbar, has_thumb, m_parent->id());
1135 m_scrollbarWithPaints->setPosition(gfx::Point(3, 10)); 1140 m_scrollbarWithPaints->setPosition(gfx::Point(3, 10));
1136 m_scrollbarWithPaints->setBounds(gfx::Size(3, 10)); 1141 m_scrollbarWithPaints->setBounds(gfx::Size(3, 10));
1137 1142
1138 m_scrollbarWithoutPaints = 1143 paint_scrollbar = false;
1139 FakeScrollbarLayer::Create(false, m_parent->id()); 1144 m_scrollbarWithoutPaints = FakeScrollbarLayer::Create(
1145 paint_scrollbar, has_thumb, m_parent->id());
1140 m_scrollbarWithoutPaints->setPosition(gfx::Point(6, 10)); 1146 m_scrollbarWithoutPaints->setPosition(gfx::Point(6, 10));
1141 m_scrollbarWithoutPaints->setBounds(gfx::Size(3, 10)); 1147 m_scrollbarWithoutPaints->setBounds(gfx::Size(3, 10));
1142 1148
1143 m_parent->addChild(m_child); 1149 m_parent->addChild(m_child);
1144 m_parent->addChild(m_scrollbarWithPaints); 1150 m_parent->addChild(m_scrollbarWithPaints);
1145 m_parent->addChild(m_scrollbarWithoutPaints); 1151 m_parent->addChild(m_scrollbarWithoutPaints);
1146 1152
1147 m_layerTreeHost->setRootLayer(m_parent); 1153 m_layerTreeHost->setRootLayer(m_parent);
1148 LayerTreeHostTest::setupTree(); 1154 LayerTreeHostTest::setupTree();
1149 } 1155 }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 scoped_refptr<FakeScrollbarLayer> m_scrollbarWithPaints; 1305 scoped_refptr<FakeScrollbarLayer> m_scrollbarWithPaints;
1300 scoped_refptr<FakeScrollbarLayer> m_scrollbarWithoutPaints; 1306 scoped_refptr<FakeScrollbarLayer> m_scrollbarWithoutPaints;
1301 int m_numCommits; 1307 int m_numCommits;
1302 }; 1308 };
1303 1309
1304 TEST_F(LayerTreeHostTestAtomicCommitWithPartialUpdate, runMultiThread) 1310 TEST_F(LayerTreeHostTestAtomicCommitWithPartialUpdate, runMultiThread)
1305 { 1311 {
1306 runTest(true); 1312 runTest(true);
1307 } 1313 }
1308 1314
1309 // A loseOutputSurface(1) should lead to a didRecreateOutputSurface(true)
1310 class LayerTreeHostTestSetSingleLostContext : public LayerTreeHostTest {
1311 public:
1312 LayerTreeHostTestSetSingleLostContext()
1313 {
1314 }
1315
1316 virtual void beginTest() OVERRIDE
1317 {
1318 postSetNeedsCommitToMainThread();
1319 }
1320
1321 virtual void didCommitAndDrawFrame() OVERRIDE
1322 {
1323 m_layerTreeHost->loseOutputSurface(1);
1324 }
1325
1326 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE
1327 {
1328 EXPECT_TRUE(succeeded);
1329 endTest();
1330 }
1331
1332 virtual void afterTest() OVERRIDE
1333 {
1334 }
1335 };
1336
1337 TEST_F(LayerTreeHostTestSetSingleLostContext, runMultiThread)
1338 {
1339 runTest(true);
1340 }
1341
1342 // A loseOutputSurface(10) should lead to a didRecreateOutputSurface(false), and
1343 // a finishAllRendering() should not hang.
1344 class LayerTreeHostTestSetRepeatedLostContext : public LayerTreeHostTest {
1345 public:
1346 LayerTreeHostTestSetRepeatedLostContext()
1347 {
1348 }
1349
1350 virtual void beginTest() OVERRIDE
1351 {
1352 postSetNeedsCommitToMainThread();
1353 }
1354
1355 virtual void didCommitAndDrawFrame() OVERRIDE
1356 {
1357 m_layerTreeHost->loseOutputSurface(10);
1358 }
1359
1360 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE
1361 {
1362 EXPECT_FALSE(succeeded);
1363 m_layerTreeHost->finishAllRendering();
1364 endTest();
1365 }
1366
1367 virtual void afterTest() OVERRIDE
1368 {
1369 }
1370 };
1371
1372 TEST_F(LayerTreeHostTestSetRepeatedLostContext, runMultiThread)
1373 {
1374 runTest(true);
1375 }
1376
1377 class LayerTreeHostTestFinishAllRendering : public LayerTreeHostTest { 1315 class LayerTreeHostTestFinishAllRendering : public LayerTreeHostTest {
1378 public: 1316 public:
1379 LayerTreeHostTestFinishAllRendering() 1317 LayerTreeHostTestFinishAllRendering()
1380 : m_once(false) 1318 : m_once(false)
1381 , m_drawCount(0) 1319 , m_drawCount(0)
1382 { 1320 {
1383 } 1321 }
1384 1322
1385 virtual void beginTest() OVERRIDE 1323 virtual void beginTest() OVERRIDE
1386 { 1324 {
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 scoped_refptr<EvictionTestLayer> m_layer; 1680 scoped_refptr<EvictionTestLayer> m_layer;
1743 LayerTreeHostImpl* m_implForEvictTextures; 1681 LayerTreeHostImpl* m_implForEvictTextures;
1744 int m_numCommits; 1682 int m_numCommits;
1745 }; 1683 };
1746 1684
1747 TEST_F(LayerTreeHostTestEvictTextures, runMultiThread) 1685 TEST_F(LayerTreeHostTestEvictTextures, runMultiThread)
1748 { 1686 {
1749 runTest(true); 1687 runTest(true);
1750 } 1688 }
1751 1689
1752 class LayerTreeHostTestLostContextAfterEvictTextures : public LayerTreeHostTest {
1753 public:
1754 LayerTreeHostTestLostContextAfterEvictTextures()
1755 : m_layer(EvictionTestLayer::create())
1756 , m_implForEvictTextures(0)
1757 , m_numCommits(0)
1758 {
1759 }
1760
1761 virtual void beginTest() OVERRIDE
1762 {
1763 m_layerTreeHost->setRootLayer(m_layer);
1764 m_layerTreeHost->setViewportSize(gfx::Size(10, 20), gfx::Size(10, 20));
1765
1766 gfx::Transform identityMatrix;
1767 setLayerPropertiesForTesting(m_layer.get(), 0, identityMatrix, gfx::Poin tF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 20), true);
1768
1769 postSetNeedsCommitToMainThread();
1770 }
1771
1772 void postEvictTextures()
1773 {
1774 if (implThread()) {
1775 implThread()->postTask(base::Bind(&LayerTreeHostTestLostContextAfter EvictTextures::evictTexturesOnImplThread,
1776 base::Unretained(this)));
1777 } else {
1778 DebugScopedSetImplThread impl(proxy());
1779 evictTexturesOnImplThread();
1780 }
1781 }
1782
1783 void evictTexturesOnImplThread()
1784 {
1785 DCHECK(m_implForEvictTextures);
1786 m_implForEvictTextures->enforceManagedMemoryPolicy(ManagedMemoryPolicy(0 ));
1787 }
1788
1789 // Commit 1: Just commit and draw normally, then at the end, set ourselves
1790 // invisible (to prevent a commit that would recreate textures after
1791 // eviction, before the context recovery), and post a task that will evict
1792 // textures, then cause the context to be lost, and then set ourselves
1793 // visible again (to allow commits, since that's what causes context
1794 // recovery in single thread).
1795 virtual void didCommitAndDrawFrame() OVERRIDE
1796 {
1797 ++m_numCommits;
1798 switch (m_numCommits) {
1799 case 1:
1800 EXPECT_TRUE(m_layer->haveBackingTexture());
1801 m_layerTreeHost->setVisible(false);
1802 postEvictTextures();
1803 m_layerTreeHost->loseOutputSurface(1);
1804 m_layerTreeHost->setVisible(true);
1805 break;
1806 default:
1807 break;
1808 }
1809 }
1810
1811 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE
1812 {
1813 m_implForEvictTextures = impl;
1814 }
1815
1816 virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE
1817 {
1818 EXPECT_TRUE(succeeded);
1819 endTest();
1820 }
1821
1822 virtual void afterTest() OVERRIDE
1823 {
1824 }
1825
1826 private:
1827 FakeContentLayerClient m_client;
1828 scoped_refptr<EvictionTestLayer> m_layer;
1829 LayerTreeHostImpl* m_implForEvictTextures;
1830 int m_numCommits;
1831 };
1832
1833 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLostContextAfterEvictTextures)
1834
1835 class FakeWebGraphicsContext3DWithEndQueryCausingLostContext : public FakeWebGra phicsContext3D {
1836 public:
1837 static scoped_ptr<FakeWebGraphicsContext3DWithEndQueryCausingLostContext> cr eate(Attributes attrs)
1838 {
1839 return make_scoped_ptr(new FakeWebGraphicsContext3DWithEndQueryCausingLo stContext(attrs));
1840 }
1841
1842 virtual void setContextLostCallback(WebGraphicsContextLostCallback* callback ) { m_contextLostCallback = callback; }
1843 virtual bool isContextLost() { return m_isContextLost; }
1844
1845 virtual void beginQueryEXT(WebKit::WGC3Denum, WebKit::WebGLId) { }
1846 virtual void endQueryEXT(WebKit::WGC3Denum)
1847 {
1848 // Lose context.
1849 if (!m_isContextLost) {
1850 m_contextLostCallback->onContextLost();
1851 m_isContextLost = true;
1852 }
1853 }
1854 virtual void getQueryObjectuivEXT(WebKit::WebGLId, WebKit::WGC3Denum pname, WebKit::WGC3Duint* params)
1855 {
1856 // Context is lost. We need to behave as if result is available.
1857 if (pname == GL_QUERY_RESULT_AVAILABLE_EXT)
1858 *params = 1;
1859 }
1860
1861 private:
1862 explicit FakeWebGraphicsContext3DWithEndQueryCausingLostContext(Attributes a ttrs)
1863 : FakeWebGraphicsContext3D(attrs)
1864 , m_contextLostCallback(0)
1865 , m_isContextLost(false) { }
1866
1867 WebGraphicsContextLostCallback* m_contextLostCallback;
1868 bool m_isContextLost;
1869 };
1870
1871 class LayerTreeHostTestLostContextWhileUpdatingResources : public LayerTreeHostT est {
1872 public:
1873 LayerTreeHostTestLostContextWhileUpdatingResources()
1874 : m_parent(ContentLayerWithUpdateTracking::create(&m_client))
1875 , m_numChildren(50)
1876 {
1877 for (int i = 0; i < m_numChildren; i++)
1878 m_children.push_back(ContentLayerWithUpdateTracking::create(&m_clien t));
1879 }
1880
1881 virtual void beginTest()
1882 {
1883 m_layerTreeHost->setRootLayer(m_parent);
1884 m_layerTreeHost->setViewportSize(gfx::Size(m_numChildren, 1), gfx::Size( m_numChildren, 1));
1885
1886 gfx::Transform identityMatrix;
1887 setLayerPropertiesForTesting(m_parent.get(), 0, identityMatrix, gfx::Poi ntF(0, 0), gfx::PointF(0, 0), gfx::Size(m_numChildren, 1), true);
1888 for (int i = 0; i < m_numChildren; i++)
1889 setLayerPropertiesForTesting(m_children[i].get(), m_parent.get(), id entityMatrix, gfx::PointF(0, 0), gfx::PointF(i, 0), gfx::Size(1, 1), false);
1890
1891 postSetNeedsCommitToMainThread();
1892 }
1893
1894 virtual void commitCompleteOnThread(LayerTreeHostImpl* impl)
1895 {
1896 endTest();
1897 }
1898
1899 virtual void layout()
1900 {
1901 m_parent->setNeedsDisplay();
1902 for (int i = 0; i < m_numChildren; i++)
1903 m_children[i]->setNeedsDisplay();
1904 }
1905
1906 virtual void afterTest()
1907 {
1908 }
1909
1910 private:
1911 FakeContentLayerClient m_client;
1912 scoped_refptr<ContentLayerWithUpdateTracking> m_parent;
1913 int m_numChildren;
1914 std::vector<scoped_refptr<ContentLayerWithUpdateTracking> > m_children;
1915 };
1916
1917 TEST_F(LayerTreeHostTestLostContextWhileUpdatingResources, runMultiThread)
1918 {
1919 runTest(true);
1920 }
1921
1922 class LayerTreeHostTestContinuousCommit : public LayerTreeHostTest { 1690 class LayerTreeHostTestContinuousCommit : public LayerTreeHostTest {
1923 public: 1691 public:
1924 LayerTreeHostTestContinuousCommit() 1692 LayerTreeHostTestContinuousCommit()
1925 : m_numCommitComplete(0) 1693 : m_numCommitComplete(0)
1926 , m_numDrawLayers(0) 1694 , m_numDrawLayers(0)
1927 { 1695 {
1928 } 1696 }
1929 1697
1930 virtual void beginTest() OVERRIDE 1698 virtual void beginTest() OVERRIDE
1931 { 1699 {
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 LayerTreeSettings settings; 2013 LayerTreeSettings settings;
2246 settings.maxPartialTextureUpdates = 4; 2014 settings.maxPartialTextureUpdates = 4;
2247 2015
2248 scoped_ptr<LayerTreeHost> host = LayerTreeHost::create(&client, settings, sc oped_ptr<Thread>()); 2016 scoped_ptr<LayerTreeHost> host = LayerTreeHost::create(&client, settings, sc oped_ptr<Thread>());
2249 EXPECT_TRUE(host->initializeRendererIfNeeded()); 2017 EXPECT_TRUE(host->initializeRendererIfNeeded());
2250 EXPECT_EQ(0u, host->settings().maxPartialTextureUpdates); 2018 EXPECT_EQ(0u, host->settings().maxPartialTextureUpdates);
2251 } 2019 }
2252 2020
2253 } // namespace 2021 } // namespace
2254 } // namespace cc 2022 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_tree_host_impl_unittest.cc ('k') | cc/layer_tree_host_unittest_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698