Chromium Code Reviews| 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 1619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1630 | 1630 |
| 1631 SINGLE_AND_MULTI_THREAD_TEST_F( | 1631 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1632 LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface); | 1632 LayerTreeHostTestCannotCreateIfCannotCreateOutputSurface); |
| 1633 | 1633 |
| 1634 class UIResourceLostTest : public LayerTreeHostContextTest { | 1634 class UIResourceLostTest : public LayerTreeHostContextTest { |
| 1635 public: | 1635 public: |
| 1636 UIResourceLostTest() : time_step_(0) {} | 1636 UIResourceLostTest() : time_step_(0) {} |
| 1637 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } | 1637 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 1638 virtual void AfterTest() OVERRIDE {} | 1638 virtual void AfterTest() OVERRIDE {} |
| 1639 | 1639 |
| 1640 // This is called on the main thread after each commit and | |
| 1641 // DidActivateTreeOnThread, with the value of time_step_ at the time | |
| 1642 // of the call to DidActivateTreeOnThread. Similar tests will do | |
| 1643 // work on the main thread in DidCommit but that is unsuitable because | |
| 1644 // the main thread work for these tests must happen after | |
| 1645 // DidActivateTreeOnThread, which happens after DidCommit with impl-side | |
| 1646 // painting. | |
| 1647 virtual void StepCompleteOnMainThread(int time_step) = 0; | |
| 1648 | |
| 1649 // Called after DidActivateTreeOnThread. If this is done during the commit, | |
| 1650 // the the call to StepCompleteOnMainThread will not occur until after | |
|
powei
2013/09/08 04:49:13
nit: double the
ccameron
2013/09/08 21:08:24
Done.
| |
| 1651 // the commit completes, because the main thread is blocked. | |
| 1652 void PostStepCompleteToMainThread() { | |
| 1653 proxy()->MainThreadTaskRunner()->PostTask( | |
| 1654 FROM_HERE, | |
| 1655 base::Bind( | |
| 1656 &UIResourceLostTest::StepCompleteOnMainThreadInternal, | |
| 1657 base::Unretained(this), | |
| 1658 time_step_)); | |
| 1659 } | |
| 1660 | |
| 1661 void PostLoseContextToImplThread() { | |
| 1662 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | |
| 1663 base::SingleThreadTaskRunner* task_runner = | |
| 1664 HasImplThread() ? ImplThreadTaskRunner() | |
| 1665 : base::MessageLoopProxy::current(); | |
| 1666 task_runner->PostTask( | |
| 1667 FROM_HERE, | |
| 1668 base::Bind( | |
| 1669 &LayerTreeHostContextTest::LoseContext, | |
| 1670 base::Unretained(this))); | |
| 1671 } | |
| 1672 | |
| 1640 protected: | 1673 protected: |
| 1641 int time_step_; | 1674 int time_step_; |
| 1642 scoped_ptr<FakeScopedUIResource> ui_resource_; | 1675 scoped_ptr<FakeScopedUIResource> ui_resource_; |
| 1676 | |
| 1677 private: | |
| 1678 void StepCompleteOnMainThreadInternal(int step) { | |
| 1679 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | |
| 1680 StepCompleteOnMainThread(step); | |
| 1681 } | |
| 1643 }; | 1682 }; |
| 1644 | 1683 |
| 1645 // Losing context after an UI resource has been created. | 1684 // Losing context after an UI resource has been created. |
| 1646 class UIResourceLostAfterCommit : public UIResourceLostTest { | 1685 class UIResourceLostAfterCommit : public UIResourceLostTest { |
| 1647 public: | 1686 public: |
| 1648 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1687 virtual void StepCompleteOnMainThread(int step) OVERRIDE { |
| 1649 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 1688 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
| 1650 switch (time_step_) { | 1689 switch (step) { |
| 1651 case 0: | 1690 case 0: |
| 1652 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); | 1691 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); |
| 1653 // Expects a valid UIResourceId. | 1692 // Expects a valid UIResourceId. |
| 1654 EXPECT_NE(0, ui_resource_->id()); | 1693 EXPECT_NE(0, ui_resource_->id()); |
| 1655 PostSetNeedsCommitToMainThread(); | 1694 PostSetNeedsCommitToMainThread(); |
| 1656 break; | 1695 break; |
| 1696 case 4: | |
| 1697 // Release resource before ending the test. | |
| 1698 ui_resource_.reset(); | |
| 1699 EndTest(); | |
| 1700 break; | |
| 1701 case 5: | |
| 1702 // Make sure no extra commits happened. | |
| 1703 NOTREACHED(); | |
| 1704 } | |
| 1705 } | |
| 1706 | |
| 1707 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
| 1708 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | |
| 1709 switch (time_step_) { | |
| 1657 case 1: | 1710 case 1: |
| 1658 // The resource should have been created on LTHI after the commit. | 1711 // The resource should have been created on LTHI after the commit. |
| 1659 if (!layer_tree_host()->settings().impl_side_painting) | 1712 if (!layer_tree_host()->settings().impl_side_painting) |
| 1660 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1713 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 1661 PostSetNeedsCommitToMainThread(); | 1714 PostSetNeedsCommitToMainThread(); |
| 1662 break; | 1715 break; |
| 1663 case 2: | 1716 case 2: |
| 1664 LoseContext(); | 1717 LoseContext(); |
| 1665 break; | 1718 break; |
| 1666 case 3: | 1719 case 3: |
| 1667 // The resources should have been recreated. The bitmap callback should | 1720 // The resources should have been recreated. The bitmap callback should |
| 1668 // have been called once with the resource_lost flag set to true. | 1721 // have been called once with the resource_lost flag set to true. |
| 1669 EXPECT_EQ(1, ui_resource_->lost_resource_count); | 1722 EXPECT_EQ(1, ui_resource_->lost_resource_count); |
| 1670 // Resource Id on the impl-side have been recreated as well. Note | 1723 // Resource Id on the impl-side have been recreated as well. Note |
| 1671 // that the same UIResourceId persists after the context lost. | 1724 // that the same UIResourceId persists after the context lost. |
| 1672 if (!layer_tree_host()->settings().impl_side_painting) | 1725 if (!layer_tree_host()->settings().impl_side_painting) |
| 1673 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1726 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 1674 PostSetNeedsCommitToMainThread(); | 1727 PostSetNeedsCommitToMainThread(); |
| 1675 break; | 1728 break; |
| 1676 case 4: | |
| 1677 // Release resource before ending test. | |
| 1678 ui_resource_.reset(); | |
| 1679 EndTest(); | |
| 1680 break; | |
| 1681 } | 1729 } |
| 1682 } | 1730 } |
| 1683 | 1731 |
| 1684 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1732 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1685 LayerTreeHostContextTest::DidActivateTreeOnThread(impl); | 1733 LayerTreeHostContextTest::DidActivateTreeOnThread(impl); |
| 1686 switch (time_step_) { | 1734 switch (time_step_) { |
| 1687 case 1: | 1735 case 1: |
| 1688 if (layer_tree_host()->settings().impl_side_painting) | 1736 if (layer_tree_host()->settings().impl_side_painting) |
| 1689 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1737 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 1690 break; | 1738 break; |
| 1691 case 3: | 1739 case 3: |
| 1692 if (layer_tree_host()->settings().impl_side_painting) | 1740 if (layer_tree_host()->settings().impl_side_painting) |
| 1693 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1741 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 1694 break; | 1742 break; |
| 1695 } | 1743 } |
| 1744 | |
| 1745 PostStepCompleteToMainThread(); | |
| 1696 ++time_step_; | 1746 ++time_step_; |
| 1697 } | 1747 } |
| 1698 }; | 1748 }; |
| 1699 | 1749 |
| 1700 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostAfterCommit); | 1750 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostAfterCommit); |
| 1701 | 1751 |
| 1702 // Losing context before UI resource requests can be commited. Three sequences | 1752 // Losing context before UI resource requests can be commited. Three sequences |
| 1703 // of creation/deletion are considered: | 1753 // of creation/deletion are considered: |
| 1704 // 1. Create one resource -> Context Lost => Expect the resource to have been | 1754 // 1. Create one resource -> Context Lost => Expect the resource to have been |
| 1705 // created. | 1755 // created. |
| 1706 // 2. Delete an exisiting resource (test_id0_) -> create a second resource | 1756 // 2. Delete an exisiting resource (test_id0_) -> create a second resource |
| 1707 // (test_id1_) -> Context Lost => Expect the test_id0_ to be removed and | 1757 // (test_id1_) -> Context Lost => Expect the test_id0_ to be removed and |
| 1708 // test_id1_ to have been created. | 1758 // test_id1_ to have been created. |
| 1709 // 3. Create one resource -> Delete that same resource -> Context Lost => Expect | 1759 // 3. Create one resource -> Delete that same resource -> Context Lost => Expect |
| 1710 // the resource to not exist in the manager. | 1760 // the resource to not exist in the manager. |
| 1711 class UIResourceLostBeforeCommit : public UIResourceLostTest { | 1761 class UIResourceLostBeforeCommit : public UIResourceLostTest { |
| 1712 public: | 1762 public: |
| 1713 UIResourceLostBeforeCommit() | 1763 UIResourceLostBeforeCommit() |
| 1714 : test_id0_(0), | 1764 : test_id0_(0), |
| 1715 test_id1_(0) {} | 1765 test_id1_(0) {} |
| 1716 | 1766 |
| 1717 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1767 virtual void StepCompleteOnMainThread(int step) OVERRIDE { |
| 1718 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 1768 switch (step) { |
| 1719 switch (time_step_) { | |
| 1720 case 0: | 1769 case 0: |
| 1721 // Sequence 1: | |
| 1722 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); | 1770 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); |
| 1723 LoseContext(); | 1771 // Lose the context on the impl thread before the commit. |
| 1724 // Resource Id on the impl-side should no longer be valid after | 1772 PostLoseContextToImplThread(); |
| 1725 // context is lost. | |
| 1726 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | |
| 1727 break; | |
| 1728 case 1: | |
| 1729 // The resources should have been recreated. | |
| 1730 EXPECT_EQ(2, ui_resource_->resource_create_count); | |
| 1731 // "resource lost" callback was called once for the resource in the | |
| 1732 // resource map. | |
| 1733 EXPECT_EQ(1, ui_resource_->lost_resource_count); | |
| 1734 // Resource Id on the impl-side have been recreated as well. Note | |
| 1735 // that the same UIResourceId persists after the context lost. | |
| 1736 if (!layer_tree_host()->settings().impl_side_painting) | |
| 1737 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | |
| 1738 PostSetNeedsCommitToMainThread(); | |
| 1739 break; | 1773 break; |
| 1740 case 2: | 1774 case 2: |
| 1741 // Sequence 2: | 1775 // Sequence 2: |
| 1742 // Currently one resource has been created. | 1776 // Currently one resource has been created. |
| 1743 test_id0_ = ui_resource_->id(); | 1777 test_id0_ = ui_resource_->id(); |
| 1744 // Delete this resource. | 1778 // Delete this resource. |
| 1745 ui_resource_.reset(); | 1779 ui_resource_.reset(); |
| 1746 // Create another resource. | 1780 // Create another resource. |
| 1747 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); | 1781 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); |
| 1748 test_id1_ = ui_resource_->id(); | 1782 test_id1_ = ui_resource_->id(); |
| 1749 // Sanity check that two resource creations return different ids. | 1783 // Sanity check that two resource creations return different ids. |
| 1750 EXPECT_NE(test_id0_, test_id1_); | 1784 EXPECT_NE(test_id0_, test_id1_); |
| 1751 // Lose the context before commit. | 1785 // Lose the context on the impl thread before the commit. |
| 1752 LoseContext(); | 1786 PostLoseContextToImplThread(); |
| 1753 break; | 1787 break; |
| 1754 case 3: | 1788 case 3: |
| 1755 if (!layer_tree_host()->settings().impl_side_painting) { | |
| 1756 // The previous resource should have been deleted. | |
| 1757 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); | |
| 1758 // The second resource should have been created. | |
| 1759 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_)); | |
| 1760 } | |
| 1761 | |
| 1762 // The second resource called the resource callback once and since the | |
| 1763 // context is lost, a "resource lost" callback was also issued. | |
| 1764 EXPECT_EQ(2, ui_resource_->resource_create_count); | |
| 1765 EXPECT_EQ(1, ui_resource_->lost_resource_count); | |
| 1766 // Clear the manager of resources. | 1789 // Clear the manager of resources. |
| 1767 ui_resource_.reset(); | 1790 ui_resource_.reset(); |
| 1768 PostSetNeedsCommitToMainThread(); | 1791 PostSetNeedsCommitToMainThread(); |
| 1769 break; | 1792 break; |
| 1770 case 4: | 1793 case 4: |
| 1771 // Sequence 3: | 1794 // Sequence 3: |
| 1772 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); | 1795 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); |
| 1773 test_id0_ = ui_resource_->id(); | 1796 test_id0_ = ui_resource_->id(); |
| 1774 // Sanity check the UIResourceId should not be 0. | 1797 // Sanity check the UIResourceId should not be 0. |
| 1775 EXPECT_NE(0, test_id0_); | 1798 EXPECT_NE(0, test_id0_); |
| 1776 // Usually ScopedUIResource are deleted from the manager in their | 1799 // Usually ScopedUIResource are deleted from the manager in their |
| 1777 // destructor (so usually ui_resource_.reset()). But here we need | 1800 // destructor (so usually ui_resource_.reset()). But here we need |
| 1778 // ui_resource_ for the next step, so call DeleteUIResource directly. | 1801 // ui_resource_ for the next step, so call DeleteUIResource directly. |
| 1779 layer_tree_host()->DeleteUIResource(test_id0_); | 1802 layer_tree_host()->DeleteUIResource(test_id0_); |
| 1780 LoseContext(); | 1803 // Delete the resouce and then lose the context. |
| 1804 PostLoseContextToImplThread(); | |
| 1781 break; | 1805 break; |
| 1782 case 5: | 1806 case 5: |
| 1807 // Release resource before ending the test. | |
| 1808 ui_resource_.reset(); | |
| 1809 EndTest(); | |
| 1810 break; | |
| 1811 case 6: | |
| 1812 // Single thread proxy issues extra commits after context lost. | |
| 1813 // http://crbug.com/287250 | |
| 1814 if (HasImplThread()) | |
| 1815 NOTREACHED(); | |
| 1816 break; | |
| 1817 case 8: | |
| 1818 NOTREACHED(); | |
| 1819 } | |
| 1820 } | |
| 1821 | |
| 1822 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
| 1823 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | |
| 1824 switch (time_step_) { | |
| 1825 case 1: | |
| 1826 // Sequence 1 (continued): | |
| 1827 if (HasImplThread()) { | |
| 1828 // The resources should have been recreated. | |
| 1829 EXPECT_EQ(2, ui_resource_->resource_create_count); | |
| 1830 // The "resource lost" callback was called once for the resource in | |
| 1831 // the resource map. | |
| 1832 EXPECT_EQ(1, ui_resource_->lost_resource_count); | |
| 1833 } else { | |
| 1834 // The extra commit that happens at context lost in the single thread | |
| 1835 // proxy changes the timing so that the resource recreation callback | |
| 1836 // is skipped. | |
| 1837 // http://crbug.com/287250 | |
| 1838 EXPECT_EQ(1, ui_resource_->resource_create_count); | |
| 1839 EXPECT_EQ(0, ui_resource_->lost_resource_count); | |
| 1840 } | |
| 1841 // Resource Id on the impl-side have been recreated as well. Note | |
| 1842 // that the same UIResourceId persists after the context lost. | |
| 1843 if (!layer_tree_host()->settings().impl_side_painting) | |
| 1844 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | |
| 1845 PostSetNeedsCommitToMainThread(); | |
| 1846 break; | |
| 1847 case 3: | |
| 1848 // Sequence 2 (continued): | |
| 1849 if (!layer_tree_host()->settings().impl_side_painting) { | |
| 1850 // The previous resource should have been deleted. | |
| 1851 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); | |
| 1852 // The second resource should have been created. | |
| 1853 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_)); | |
| 1854 } | |
| 1855 if (HasImplThread()) { | |
| 1856 // The second resource called the resource callback once and since the | |
| 1857 // context is lost, a "resource lost" callback was also issued. | |
| 1858 EXPECT_EQ(2, ui_resource_->resource_create_count); | |
| 1859 EXPECT_EQ(1, ui_resource_->lost_resource_count); | |
| 1860 } else { | |
| 1861 // The extra commit that happens at context lost in the single thread | |
| 1862 // proxy changes the timing so that the resource recreation callback | |
| 1863 // is skipped. | |
| 1864 // http://crbug.com/287250 | |
| 1865 EXPECT_EQ(1, ui_resource_->resource_create_count); | |
| 1866 EXPECT_EQ(0, ui_resource_->lost_resource_count); | |
| 1867 } | |
| 1868 break; | |
| 1869 case 5: | |
| 1870 // Sequence 3 (continued): | |
| 1783 // Expect the resource callback to have been called once. | 1871 // Expect the resource callback to have been called once. |
| 1784 EXPECT_EQ(1, ui_resource_->resource_create_count); | 1872 EXPECT_EQ(1, ui_resource_->resource_create_count); |
| 1785 // No "resource lost" callbacks. | 1873 // No "resource lost" callbacks. |
| 1786 EXPECT_EQ(0, ui_resource_->lost_resource_count); | 1874 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
| 1787 if (!layer_tree_host()->settings().impl_side_painting) { | 1875 if (!layer_tree_host()->settings().impl_side_painting) { |
| 1788 // The UI resource id should not be valid | 1876 // The UI resource id should not be valid |
| 1789 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); | 1877 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); |
| 1790 } | 1878 } |
| 1791 PostSetNeedsCommitToMainThread(); | |
| 1792 break; | |
| 1793 case 6: | |
| 1794 ui_resource_.reset(); | |
| 1795 EndTest(); | |
| 1796 break; | 1879 break; |
| 1797 } | 1880 } |
| 1798 } | 1881 } |
| 1799 | 1882 |
| 1800 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1883 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1801 LayerTreeHostContextTest::DidActivateTreeOnThread(impl); | 1884 LayerTreeHostContextTest::DidActivateTreeOnThread(impl); |
| 1802 switch (time_step_) { | 1885 switch (time_step_) { |
| 1803 case 1: | 1886 case 1: |
| 1804 if (layer_tree_host()->settings().impl_side_painting) | 1887 if (layer_tree_host()->settings().impl_side_painting) |
| 1805 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1888 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 1806 break; | 1889 break; |
| 1807 case 3: | 1890 case 3: |
| 1808 if (layer_tree_host()->settings().impl_side_painting) { | 1891 if (layer_tree_host()->settings().impl_side_painting) { |
| 1809 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); | 1892 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); |
| 1810 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_)); | 1893 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_)); |
| 1811 } | 1894 } |
| 1812 break; | 1895 break; |
| 1813 case 5: | 1896 case 5: |
| 1814 if (layer_tree_host()->settings().impl_side_painting) | 1897 if (layer_tree_host()->settings().impl_side_painting) |
| 1815 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); | 1898 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); |
| 1816 break; | 1899 break; |
| 1817 } | 1900 } |
| 1901 | |
| 1902 PostStepCompleteToMainThread(); | |
| 1818 ++time_step_; | 1903 ++time_step_; |
| 1819 } | 1904 } |
| 1820 | 1905 |
| 1821 private: | 1906 private: |
| 1822 UIResourceId test_id0_; | 1907 UIResourceId test_id0_; |
| 1823 UIResourceId test_id1_; | 1908 UIResourceId test_id1_; |
| 1824 }; | 1909 }; |
| 1825 | 1910 |
| 1826 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeCommit); | 1911 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeCommit); |
| 1827 | 1912 |
| 1828 // Losing UI resource before the pending trees is activated but after the | 1913 // Losing UI resource before the pending trees is activated but after the |
| 1829 // commit. Impl-side-painting only. | 1914 // commit. Impl-side-painting only. |
| 1830 class UIResourceLostBeforeActivateTree : public UIResourceLostTest { | 1915 class UIResourceLostBeforeActivateTree : public UIResourceLostTest { |
| 1831 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1916 virtual void StepCompleteOnMainThread(int step) OVERRIDE { |
| 1832 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 1917 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
| 1833 switch (time_step_) { | 1918 switch (step) { |
| 1834 case 0: | 1919 case 0: |
| 1835 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); | 1920 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); |
| 1836 PostSetNeedsCommitToMainThread(); | 1921 PostSetNeedsCommitToMainThread(); |
| 1837 break; | 1922 break; |
| 1838 case 2: | |
| 1839 PostSetNeedsCommitToMainThread(); | |
| 1840 break; | |
| 1841 case 3: | 1923 case 3: |
| 1842 test_id_ = ui_resource_->id(); | 1924 test_id_ = ui_resource_->id(); |
| 1843 ui_resource_.reset(); | 1925 ui_resource_.reset(); |
| 1844 PostSetNeedsCommitToMainThread(); | 1926 PostSetNeedsCommitToMainThread(); |
| 1845 break; | 1927 break; |
| 1928 case 5: | |
| 1929 // Release resource before ending the test. | |
| 1930 ui_resource_.reset(); | |
| 1931 EndTest(); | |
| 1932 break; | |
| 1933 case 6: | |
| 1934 // Make sure no extra commits happened. | |
| 1935 NOTREACHED(); | |
| 1936 } | |
| 1937 } | |
| 1938 | |
| 1939 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
| 1940 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | |
| 1941 switch (time_step_) { | |
| 1942 case 2: | |
| 1943 PostSetNeedsCommitToMainThread(); | |
| 1944 break; | |
| 1846 case 4: | 1945 case 4: |
| 1847 PostSetNeedsCommitToMainThread(); | 1946 PostSetNeedsCommitToMainThread(); |
| 1848 break; | 1947 break; |
| 1849 case 5: | |
| 1850 EndTest(); | |
| 1851 break; | |
| 1852 } | 1948 } |
| 1853 } | 1949 } |
| 1854 | 1950 |
| 1855 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1951 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1856 switch (time_step_) { | 1952 switch (time_step_) { |
| 1857 case 0: | |
| 1858 break; | |
| 1859 case 1: | 1953 case 1: |
| 1860 // The resource creation callback has been called. | 1954 // The resource creation callback has been called. |
| 1861 EXPECT_EQ(1, ui_resource_->resource_create_count); | 1955 EXPECT_EQ(1, ui_resource_->resource_create_count); |
| 1862 // The resource is not yet lost (sanity check). | 1956 // The resource is not yet lost (sanity check). |
| 1863 EXPECT_EQ(0, ui_resource_->lost_resource_count); | 1957 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
| 1864 // The resource should not have been created yet on the impl-side. | 1958 // The resource should not have been created yet on the impl-side. |
| 1865 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1959 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 1866 LoseContext(); | 1960 LoseContext(); |
| 1867 break; | 1961 break; |
| 1868 case 3: | 1962 case 3: |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1881 case 2: | 1975 case 2: |
| 1882 // The "lost resource" callback should have been called once. | 1976 // The "lost resource" callback should have been called once. |
| 1883 EXPECT_EQ(1, ui_resource_->lost_resource_count); | 1977 EXPECT_EQ(1, ui_resource_->lost_resource_count); |
| 1884 break; | 1978 break; |
| 1885 case 4: | 1979 case 4: |
| 1886 // The resource is deleted and should not be in the manager. Use | 1980 // The resource is deleted and should not be in the manager. Use |
| 1887 // test_id_ since ui_resource_ has been deleted. | 1981 // test_id_ since ui_resource_ has been deleted. |
| 1888 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id_)); | 1982 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id_)); |
| 1889 break; | 1983 break; |
| 1890 } | 1984 } |
| 1985 | |
| 1986 PostStepCompleteToMainThread(); | |
| 1891 ++time_step_; | 1987 ++time_step_; |
| 1892 } | 1988 } |
| 1893 | 1989 |
| 1894 private: | 1990 private: |
| 1895 UIResourceId test_id_; | 1991 UIResourceId test_id_; |
| 1896 }; | 1992 }; |
| 1897 | 1993 |
| 1898 TEST_F(UIResourceLostBeforeActivateTree, | 1994 TEST_F(UIResourceLostBeforeActivateTree, |
| 1899 RunMultiThread_DirectRenderer_ImplSidePaint) { | 1995 RunMultiThread_DirectRenderer_ImplSidePaint) { |
| 1900 RunTest(true, false, true); | 1996 RunTest(true, false, true); |
| 1901 } | 1997 } |
| 1902 | 1998 |
| 1903 TEST_F(UIResourceLostBeforeActivateTree, | 1999 TEST_F(UIResourceLostBeforeActivateTree, |
| 1904 RunMultiThread_DelegatingRenderer_ImplSidePaint) { | 2000 RunMultiThread_DelegatingRenderer_ImplSidePaint) { |
| 1905 RunTest(true, true, true); | 2001 RunTest(true, true, true); |
| 1906 } | 2002 } |
| 1907 | 2003 |
| 1908 } // namespace | 2004 } // namespace |
| 1909 } // namespace cc | 2005 } // namespace cc |
| OLD | NEW |