| 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 |
| 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 // TODO(ccameron): There is a bug in the single thread proxy where if |
| 1813 // the GL context is lost outside of the commit flow, then two (or more) |
| 1814 // commits follow instead of just one. The first commit will recreate |
| 1815 // the context, and the second serves no clear purpose. When that is |
| 1816 // fixed then this NOTREACHED can apply unconditionally. |
| 1817 if (HasImplThread()) |
| 1818 NOTREACHED(); |
| 1819 break; |
| 1820 case 8: |
| 1821 NOTREACHED(); |
| 1822 } |
| 1823 } |
| 1824 |
| 1825 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1826 LayerTreeHostContextTest::CommitCompleteOnThread(impl); |
| 1827 switch (time_step_) { |
| 1828 case 1: |
| 1829 // Sequence 1 (continued): |
| 1830 // The resources should have been recreated. |
| 1831 EXPECT_EQ(1, ui_resource_->resource_create_count); |
| 1832 // The "resource lost" callback wasn't called for the resource because |
| 1833 // the context was lost before the queue was processed. |
| 1834 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
| 1835 // Resource Id on the impl-side have been recreated as well. Note |
| 1836 // that the same UIResourceId persists after the context lost. |
| 1837 if (!layer_tree_host()->settings().impl_side_painting) |
| 1838 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 1839 PostSetNeedsCommitToMainThread(); |
| 1840 break; |
| 1841 case 3: |
| 1842 // Sequence 2 (continued): |
| 1843 if (!layer_tree_host()->settings().impl_side_painting) { |
| 1844 // The previous resource should have been deleted. |
| 1845 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); |
| 1846 // The second resource should have been created. |
| 1847 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_)); |
| 1848 } |
| 1849 // The "resource lost" callback wasn't called for the resource because |
| 1850 // the context was lost before the queue was processed. |
| 1851 EXPECT_EQ(1, ui_resource_->resource_create_count); |
| 1852 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
| 1853 break; |
| 1854 case 5: |
| 1855 // Sequence 3 (continued): |
| 1783 // Expect the resource callback to have been called once. | 1856 // Expect the resource callback to have been called once. |
| 1784 EXPECT_EQ(1, ui_resource_->resource_create_count); | 1857 EXPECT_EQ(1, ui_resource_->resource_create_count); |
| 1785 // No "resource lost" callbacks. | 1858 // No "resource lost" callbacks. |
| 1786 EXPECT_EQ(0, ui_resource_->lost_resource_count); | 1859 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
| 1787 if (!layer_tree_host()->settings().impl_side_painting) { | 1860 if (!layer_tree_host()->settings().impl_side_painting) { |
| 1788 // The UI resource id should not be valid | 1861 // The UI resource id should not be valid |
| 1789 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); | 1862 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); |
| 1790 } | 1863 } |
| 1791 PostSetNeedsCommitToMainThread(); | |
| 1792 break; | |
| 1793 case 6: | |
| 1794 ui_resource_.reset(); | |
| 1795 EndTest(); | |
| 1796 break; | 1864 break; |
| 1797 } | 1865 } |
| 1798 } | 1866 } |
| 1799 | 1867 |
| 1800 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1868 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1801 LayerTreeHostContextTest::DidActivateTreeOnThread(impl); | 1869 LayerTreeHostContextTest::DidActivateTreeOnThread(impl); |
| 1802 switch (time_step_) { | 1870 switch (time_step_) { |
| 1803 case 1: | 1871 case 1: |
| 1804 if (layer_tree_host()->settings().impl_side_painting) | 1872 if (layer_tree_host()->settings().impl_side_painting) |
| 1805 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1873 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 1806 break; | 1874 break; |
| 1807 case 3: | 1875 case 3: |
| 1808 if (layer_tree_host()->settings().impl_side_painting) { | 1876 if (layer_tree_host()->settings().impl_side_painting) { |
| 1809 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); | 1877 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); |
| 1810 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_)); | 1878 EXPECT_NE(0u, impl->ResourceIdForUIResource(test_id1_)); |
| 1811 } | 1879 } |
| 1812 break; | 1880 break; |
| 1813 case 5: | 1881 case 5: |
| 1814 if (layer_tree_host()->settings().impl_side_painting) | 1882 if (layer_tree_host()->settings().impl_side_painting) |
| 1815 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); | 1883 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id0_)); |
| 1816 break; | 1884 break; |
| 1817 } | 1885 } |
| 1886 |
| 1887 PostStepCompleteToMainThread(); |
| 1818 ++time_step_; | 1888 ++time_step_; |
| 1819 } | 1889 } |
| 1820 | 1890 |
| 1821 private: | 1891 private: |
| 1822 UIResourceId test_id0_; | 1892 UIResourceId test_id0_; |
| 1823 UIResourceId test_id1_; | 1893 UIResourceId test_id1_; |
| 1824 }; | 1894 }; |
| 1825 | 1895 |
| 1826 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeCommit); | 1896 SINGLE_AND_MULTI_THREAD_TEST_F(UIResourceLostBeforeCommit); |
| 1827 | 1897 |
| 1828 // Losing UI resource before the pending trees is activated but after the | 1898 // Losing UI resource before the pending trees is activated but after the |
| 1829 // commit. Impl-side-painting only. | 1899 // commit. Impl-side-painting only. |
| 1830 class UIResourceLostBeforeActivateTree : public UIResourceLostTest { | 1900 class UIResourceLostBeforeActivateTree : public UIResourceLostTest { |
| 1831 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1901 virtual void StepCompleteOnMainThread(int step) OVERRIDE { |
| 1832 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 1902 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
| 1833 switch (time_step_) { | 1903 switch (step) { |
| 1834 case 0: | 1904 case 0: |
| 1835 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); | 1905 ui_resource_ = FakeScopedUIResource::Create(layer_tree_host()); |
| 1836 PostSetNeedsCommitToMainThread(); | 1906 PostSetNeedsCommitToMainThread(); |
| 1837 break; | 1907 break; |
| 1838 case 2: | |
| 1839 PostSetNeedsCommitToMainThread(); | |
| 1840 break; | |
| 1841 case 3: | 1908 case 3: |
| 1842 test_id_ = ui_resource_->id(); | 1909 test_id_ = ui_resource_->id(); |
| 1843 ui_resource_.reset(); | 1910 ui_resource_.reset(); |
| 1844 PostSetNeedsCommitToMainThread(); | 1911 PostSetNeedsCommitToMainThread(); |
| 1845 break; | 1912 break; |
| 1913 case 5: |
| 1914 // Release resource before ending the test. |
| 1915 ui_resource_.reset(); |
| 1916 EndTest(); |
| 1917 break; |
| 1918 case 6: |
| 1919 // Make sure no extra commits happened. |
| 1920 NOTREACHED(); |
| 1921 } |
| 1922 } |
| 1923 |
| 1924 virtual void CommitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1925 LayerTreeHostContextTest::CommitCompleteOnThread(impl); |
| 1926 switch (time_step_) { |
| 1927 case 2: |
| 1928 PostSetNeedsCommitToMainThread(); |
| 1929 break; |
| 1846 case 4: | 1930 case 4: |
| 1847 PostSetNeedsCommitToMainThread(); | 1931 PostSetNeedsCommitToMainThread(); |
| 1848 break; | 1932 break; |
| 1849 case 5: | |
| 1850 EndTest(); | |
| 1851 break; | |
| 1852 } | 1933 } |
| 1853 } | 1934 } |
| 1854 | 1935 |
| 1855 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | 1936 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1856 switch (time_step_) { | 1937 switch (time_step_) { |
| 1857 case 0: | |
| 1858 break; | |
| 1859 case 1: | 1938 case 1: |
| 1860 // The resource creation callback has been called. | 1939 // The resource creation callback has been called. |
| 1861 EXPECT_EQ(1, ui_resource_->resource_create_count); | 1940 EXPECT_EQ(1, ui_resource_->resource_create_count); |
| 1862 // The resource is not yet lost (sanity check). | 1941 // The resource is not yet lost (sanity check). |
| 1863 EXPECT_EQ(0, ui_resource_->lost_resource_count); | 1942 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
| 1864 // The resource should not have been created yet on the impl-side. | 1943 // The resource should not have been created yet on the impl-side. |
| 1865 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1944 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 1866 LoseContext(); | 1945 LoseContext(); |
| 1867 break; | 1946 break; |
| 1868 case 3: | 1947 case 3: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1881 case 2: | 1960 case 2: |
| 1882 // The "lost resource" callback should have been called once. | 1961 // The "lost resource" callback should have been called once. |
| 1883 EXPECT_EQ(1, ui_resource_->lost_resource_count); | 1962 EXPECT_EQ(1, ui_resource_->lost_resource_count); |
| 1884 break; | 1963 break; |
| 1885 case 4: | 1964 case 4: |
| 1886 // The resource is deleted and should not be in the manager. Use | 1965 // The resource is deleted and should not be in the manager. Use |
| 1887 // test_id_ since ui_resource_ has been deleted. | 1966 // test_id_ since ui_resource_ has been deleted. |
| 1888 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id_)); | 1967 EXPECT_EQ(0u, impl->ResourceIdForUIResource(test_id_)); |
| 1889 break; | 1968 break; |
| 1890 } | 1969 } |
| 1970 |
| 1971 PostStepCompleteToMainThread(); |
| 1891 ++time_step_; | 1972 ++time_step_; |
| 1892 } | 1973 } |
| 1893 | 1974 |
| 1894 private: | 1975 private: |
| 1895 UIResourceId test_id_; | 1976 UIResourceId test_id_; |
| 1896 }; | 1977 }; |
| 1897 | 1978 |
| 1898 TEST_F(UIResourceLostBeforeActivateTree, | 1979 TEST_F(UIResourceLostBeforeActivateTree, |
| 1899 RunMultiThread_DirectRenderer_ImplSidePaint) { | 1980 RunMultiThread_DirectRenderer_ImplSidePaint) { |
| 1900 RunTest(true, false, true); | 1981 RunTest(true, false, true); |
| 1901 } | 1982 } |
| 1902 | 1983 |
| 1903 TEST_F(UIResourceLostBeforeActivateTree, | 1984 TEST_F(UIResourceLostBeforeActivateTree, |
| 1904 RunMultiThread_DelegatingRenderer_ImplSidePaint) { | 1985 RunMultiThread_DelegatingRenderer_ImplSidePaint) { |
| 1905 RunTest(true, true, true); | 1986 RunTest(true, true, true); |
| 1906 } | 1987 } |
| 1907 | 1988 |
| 1908 } // namespace | 1989 } // namespace |
| 1909 } // namespace cc | 1990 } // namespace cc |
| OLD | NEW |