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/debug/test_context_provider.h" | 8 #include "cc/debug/test_context_provider.h" |
9 #include "cc/debug/test_web_graphics_context_3d.h" | 9 #include "cc/debug/test_web_graphics_context_3d.h" |
10 #include "cc/layers/content_layer.h" | 10 #include "cc/layers/content_layer.h" |
(...skipping 1528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1539 // backtrack). | 1539 // backtrack). |
1540 EXPECT_EQ(1, scrollbar_layer_->update_count()); | 1540 EXPECT_EQ(1, scrollbar_layer_->update_count()); |
1541 LoseContext(); | 1541 LoseContext(); |
1542 break; | 1542 break; |
1543 case 2: | 1543 case 2: |
1544 // Second update, after the lost context, we should still upload 2 | 1544 // Second update, after the lost context, we should still upload 2 |
1545 // resources even if the contents haven't changed. | 1545 // resources even if the contents haven't changed. |
1546 EXPECT_EQ(2, scrollbar_layer_->update_count()); | 1546 EXPECT_EQ(2, scrollbar_layer_->update_count()); |
1547 EndTest(); | 1547 EndTest(); |
1548 break; | 1548 break; |
| 1549 case 3: |
| 1550 // Single thread proxy issues extra commits after context lost. |
| 1551 // http://crbug.com/287250 |
| 1552 if (HasImplThread()) |
| 1553 NOTREACHED(); |
| 1554 break; |
1549 default: | 1555 default: |
1550 NOTREACHED(); | 1556 NOTREACHED(); |
1551 } | 1557 } |
1552 } | 1558 } |
1553 | 1559 |
1554 private: | 1560 private: |
1555 int commits_; | 1561 int commits_; |
1556 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_; | 1562 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_; |
1557 }; | 1563 }; |
1558 | 1564 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1715 // Expects a valid UIResourceId. | 1721 // Expects a valid UIResourceId. |
1716 EXPECT_NE(0, ui_resource_->id()); | 1722 EXPECT_NE(0, ui_resource_->id()); |
1717 PostSetNeedsCommitToMainThread(); | 1723 PostSetNeedsCommitToMainThread(); |
1718 break; | 1724 break; |
1719 case 4: | 1725 case 4: |
1720 // Release resource before ending the test. | 1726 // Release resource before ending the test. |
1721 ui_resource_.reset(); | 1727 ui_resource_.reset(); |
1722 EndTest(); | 1728 EndTest(); |
1723 break; | 1729 break; |
1724 case 5: | 1730 case 5: |
1725 // Make sure no extra commits happened. | 1731 // Single thread proxy issues extra commits after context lost. |
| 1732 // http://crbug.com/287250 |
| 1733 if (HasImplThread()) |
| 1734 NOTREACHED(); |
| 1735 break; |
| 1736 case 6: |
1726 NOTREACHED(); | 1737 NOTREACHED(); |
1727 } | 1738 } |
1728 } | 1739 } |
1729 | 1740 |
1730 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { | 1741 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { |
1731 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 1742 LayerTreeHostContextTest::CommitCompleteOnThread(impl); |
1732 switch (time_step_) { | 1743 switch (time_step_) { |
1733 case 1: | 1744 case 1: |
1734 // The resource should have been created on LTHI after the commit. | 1745 // The resource should have been created on LTHI after the commit. |
1735 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1746 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1821 case 8: | 1832 case 8: |
1822 NOTREACHED(); | 1833 NOTREACHED(); |
1823 } | 1834 } |
1824 } | 1835 } |
1825 | 1836 |
1826 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { | 1837 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { |
1827 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 1838 LayerTreeHostContextTest::CommitCompleteOnThread(impl); |
1828 switch (time_step_) { | 1839 switch (time_step_) { |
1829 case 1: | 1840 case 1: |
1830 // Sequence 1 (continued): | 1841 // Sequence 1 (continued): |
1831 if (HasImplThread()) { | 1842 // The first context lost happens before the resources were created, |
1832 // The resources should have been recreated. | 1843 // and because it resulted in no resources being destroyed, it does not |
1833 EXPECT_EQ(2, ui_resource_->resource_create_count); | 1844 // trigger resource re-creation. |
1834 // The "resource lost" callback was called once for the resource in | 1845 EXPECT_EQ(1, ui_resource_->resource_create_count); |
1835 // the resource map. | 1846 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
1836 EXPECT_EQ(1, ui_resource_->lost_resource_count); | 1847 // Resource Id on the impl-side has been created. |
1837 } else { | |
1838 // The extra commit that happens at context lost in the single thread | |
1839 // proxy changes the timing so that the resource recreation callback | |
1840 // is skipped. | |
1841 // http://crbug.com/287250 | |
1842 EXPECT_EQ(1, ui_resource_->resource_create_count); | |
1843 EXPECT_EQ(0, ui_resource_->lost_resource_count); | |
1844 } | |
1845 // Resource Id on the impl-side have been recreated as well. Note | |
1846 // that the same UIResourceId persists after the context lost. | |
1847 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | |
1848 PostSetNeedsCommitToMainThread(); | 1848 PostSetNeedsCommitToMainThread(); |
1849 break; | 1849 break; |
1850 case 3: | 1850 case 3: |
1851 // Sequence 2 (continued): | 1851 // Sequence 2 (continued): |
1852 // The previous resource should have been deleted. | 1852 // The previous resource should have been deleted. |
1853 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); | 1853 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); |
1854 // The second resource should have been created. | |
1855 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_)); | |
1856 if (HasImplThread()) { | 1854 if (HasImplThread()) { |
1857 // The second resource called the resource callback once and since the | 1855 // The second resource should have been created. |
1858 // context is lost, a "resource lost" callback was also issued. | 1856 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_)); |
1859 EXPECT_EQ(2, ui_resource_->resource_create_count); | |
1860 EXPECT_EQ(1, ui_resource_->lost_resource_count); | |
1861 } else { | 1857 } else { |
1862 // The extra commit that happens at context lost in the single thread | 1858 // The extra commit that happens at context lost in the single thread |
1863 // proxy changes the timing so that the resource recreation callback | 1859 // proxy changes the timing so that the resource has been destroyed. |
1864 // is skipped. | |
1865 // http://crbug.com/287250 | 1860 // http://crbug.com/287250 |
1866 EXPECT_EQ(1, ui_resource_->resource_create_count); | 1861 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id1_)); |
1867 EXPECT_EQ(0, ui_resource_->lost_resource_count); | |
1868 } | 1862 } |
| 1863 // The second resource called the resource callback once and since the |
| 1864 // context is lost, a "resource lost" callback was also issued. |
| 1865 EXPECT_EQ(2, ui_resource_->resource_create_count); |
| 1866 EXPECT_EQ(1, ui_resource_->lost_resource_count); |
1869 break; | 1867 break; |
1870 case 5: | 1868 case 5: |
1871 // Sequence 3 (continued): | 1869 // Sequence 3 (continued): |
1872 // Expect the resource callback to have been called once. | 1870 // Expect the resource callback to have been called once. |
1873 EXPECT_EQ(1, ui_resource_->resource_create_count); | 1871 EXPECT_EQ(1, ui_resource_->resource_create_count); |
1874 // No "resource lost" callbacks. | 1872 // No "resource lost" callbacks. |
1875 EXPECT_EQ(0, ui_resource_->lost_resource_count); | 1873 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
1876 // The UI resource id should not be valid | 1874 // The UI resource id should not be valid |
1877 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); | 1875 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); |
1878 break; | 1876 break; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1970 TEST_F(UIResourceLostBeforeActivateTree, | 1968 TEST_F(UIResourceLostBeforeActivateTree, |
1971 RunMultiThread_DirectRenderer_ImplSidePaint) { | 1969 RunMultiThread_DirectRenderer_ImplSidePaint) { |
1972 RunTest(true, false, true); | 1970 RunTest(true, false, true); |
1973 } | 1971 } |
1974 | 1972 |
1975 TEST_F(UIResourceLostBeforeActivateTree, | 1973 TEST_F(UIResourceLostBeforeActivateTree, |
1976 RunMultiThread_DelegatingRenderer_ImplSidePaint) { | 1974 RunMultiThread_DelegatingRenderer_ImplSidePaint) { |
1977 RunTest(true, true, true); | 1975 RunTest(true, true, true); |
1978 } | 1976 } |
1979 | 1977 |
| 1978 // Resources evicted explicitly and by visibility changes. |
| 1979 class UIResourceLostEviction : public UIResourceLostTestSimple { |
| 1980 public: |
| 1981 virtual void StepCompleteOnMainThread(int step) OVERRIDE { |
| 1982 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
| 1983 switch (step) { |
| 1984 case 0: |
| 1985 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); |
| 1986 EXPECT_NE(0, ui_resource_->id()); |
| 1987 PostSetNeedsCommitToMainThread(); |
| 1988 break; |
| 1989 case 2: |
| 1990 // Make the tree not visible. |
| 1991 PostSetVisibleToMainThread(false); |
| 1992 break; |
| 1993 case 3: |
| 1994 // Release resource before ending the test. |
| 1995 ui_resource_.reset(); |
| 1996 EndTest(); |
| 1997 break; |
| 1998 case 4: |
| 1999 NOTREACHED(); |
| 2000 } |
| 2001 } |
| 2002 |
| 2003 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* impl, |
| 2004 bool visible) OVERRIDE { |
| 2005 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( |
| 2006 impl->output_surface()->context_provider()->Context3d()); |
| 2007 if (!visible) { |
| 2008 // All resources should have been evicted. |
| 2009 ASSERT_EQ(0u, context->NumTextures()); |
| 2010 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 2011 EXPECT_EQ(2, ui_resource_->resource_create_count); |
| 2012 EXPECT_EQ(1, ui_resource_->lost_resource_count); |
| 2013 // Drawing is disabled both because of the evicted resources and |
| 2014 // because the renderer is not visible. |
| 2015 EXPECT_FALSE(impl->CanDraw()); |
| 2016 // Make the renderer visible again. |
| 2017 PostSetVisibleToMainThread(true); |
| 2018 } |
| 2019 } |
| 2020 |
| 2021 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 2022 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( |
| 2023 impl->output_surface()->context_provider()->Context3d()); |
| 2024 LayerTreeHostContextTest::CommitCompleteOnThread(impl); |
| 2025 switch (time_step_) { |
| 2026 case 1: |
| 2027 // The resource should have been created on LTHI after the commit. |
| 2028 ASSERT_EQ(1u, context->NumTextures()); |
| 2029 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 2030 EXPECT_EQ(1, ui_resource_->resource_create_count); |
| 2031 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
| 2032 EXPECT_TRUE(impl->CanDraw()); |
| 2033 // Evict all UI resources. This will trigger a commit. |
| 2034 impl->DeleteAllUIResources(); |
| 2035 ASSERT_EQ(0u, context->NumTextures()); |
| 2036 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 2037 EXPECT_EQ(1, ui_resource_->resource_create_count); |
| 2038 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
| 2039 EXPECT_FALSE(impl->CanDraw()); |
| 2040 break; |
| 2041 case 2: |
| 2042 // The resource should have been recreated. |
| 2043 ASSERT_EQ(1u, context->NumTextures()); |
| 2044 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 2045 EXPECT_EQ(2, ui_resource_->resource_create_count); |
| 2046 EXPECT_EQ(1, ui_resource_->lost_resource_count); |
| 2047 EXPECT_TRUE(impl->CanDraw()); |
| 2048 break; |
| 2049 case 3: |
| 2050 // The resource should have been recreated after visibility was |
| 2051 // restored. |
| 2052 ASSERT_EQ(1u, context->NumTextures()); |
| 2053 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 2054 EXPECT_EQ(3, ui_resource_->resource_create_count); |
| 2055 EXPECT_EQ(2, ui_resource_->lost_resource_count); |
| 2056 EXPECT_TRUE(impl->CanDraw()); |
| 2057 break; |
| 2058 } |
| 2059 } |
| 2060 }; |
| 2061 |
| 2062 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostEviction); |
| 2063 |
1980 } // namespace | 2064 } // namespace |
1981 } // namespace cc | 2065 } // namespace cc |
OLD | NEW |